diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/.travis.yml index 639fe101..87479c6f 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/.travis.yml +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/.travis.yml @@ -3,11 +3,14 @@ language: go go: - "1.12.x" +env: + - GO111MODULE=on TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" + script: - make test - make lint - - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io.yaml" TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" make integration - - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io_bench.yaml" TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" TSDB_BENCH_INGEST_CONFIG="$TRAVIS_BUILD_DIR/test/benchmark/testdata/tsdb-bench-test-config-ci.yaml" make bench + - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io.yaml" make integration + - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io_bench.yaml" TSDB_BENCH_INGEST_CONFIG="$TRAVIS_BUILD_DIR/test/benchmark/testdata/tsdb-bench-test-config-ci.yaml" make bench before_deploy: - GOOS=linux GOARCH=amd64 make build diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile index 008af0f8..443362b0 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile @@ -3,6 +3,7 @@ BUILD_FOLDER = "/go" attempts=15 git_project = "v3io-tsdb" git_project_user = "v3io" +git_project_upstream_user = "v3io" git_deploy_user = "iguazio-prod-git-user" git_deploy_user_token = "iguazio-prod-git-user-token" git_deploy_user_private_key = "iguazio-prod-git-user-private-key" @@ -14,7 +15,7 @@ def build_v3io_tsdb(TAG_VERSION) { def git_project = 'v3io-tsdb' stage('prepare sources') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { git(changelog: false, credentialsId: git_deploy_user_private_key, poll: false, url: "git@github.com:${git_project_user}/${git_project}.git") sh("git checkout ${TAG_VERSION}") } @@ -23,11 +24,11 @@ def build_v3io_tsdb(TAG_VERSION) { stage("build ${git_project} binaries in dood") { container('golang') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ - GOOS=linux GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin - GOOS=darwin GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin - GOOS=windows GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=linux GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=darwin GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=windows GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin ls -la /go/bin """ } @@ -59,35 +60,68 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { def git_project = 'tsdb-nuclio' stage('prepare sources') { container('jnlp') { - if(!fileExists("${BUILD_FOLDER}/src/github.com/v3io/${git_project}")) { - sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/v3io/${git_project}") + if (!fileExists("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}")) { + sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project_upstream_user}/${git_project}") } - if ( "${internal_status}" == "unstable" ) { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + if ("${internal_status}" == "unstable") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout development") } } else { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout master") } } - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { - sh """ - rm -rf functions/ingest/vendor/github.com/v3io/v3io-tsdb functions/query/vendor/github.com/v3io/v3io-tsdb - git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/ingest/vendor/github.com/v3io/v3io-tsdb - cd functions/ingest/vendor/github.com/v3io/v3io-tsdb - git checkout ${V3IO_TSDB_VERSION} - rm -rf .git vendor/github.com/nuclio vendor/github.com/v3io/frames/vendor/golang.org/x/net - cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project} - cp -R functions/ingest/vendor/github.com/v3io/v3io-tsdb functions/query/vendor/github.com/v3io/v3io-tsdb - """ - } } + parallel( + 'update tsdb in ingest': { + container('jnlp') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh """ + rm -rf functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + cd functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git checkout ${V3IO_TSDB_VERSION} + """ + } + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}/functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb") { + sh """ + GO111MODULE=on go mod vendor + rm -rf .git vendor/github.com/nuclio vendor/github.com/${git_project_upstream_user}/frames/vendor/golang.org/x/net vendor/golang.org/x/net + """ + } + } + }, + 'update tsdb in query': { + container('jnlp') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh """ + rm -rf functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + cd functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git checkout ${V3IO_TSDB_VERSION} + """ + } + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}/functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb") { + sh """ + GO111MODULE=on go mod vendor + rm -rf .git vendor/github.com/nuclio vendor/github.com/${git_project_upstream_user}/frames/vendor/golang.org/x/net vendor/golang.org/x/net + """ + } + } + } + ) } stage('git push') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ git config --global user.email '${GIT_USERNAME}@iguazio.com' git config --global user.name '${GIT_USERNAME}' @@ -96,7 +130,7 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { git add functions/ingest/vendor/github.com functions/query/vendor/github.com; """ try { - sh("git commit -am 'Updated TSDB to ${V3IO_TSDB_VERSION}'") + sh("git commit -m 'Updated TSDB to ${V3IO_TSDB_VERSION}'") } catch (err) { echo "Can not commit" } @@ -112,6 +146,9 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { } } } + container('golang') { + sh("rm -rf ${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") + } } } } @@ -126,33 +163,37 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { stage('prepare sources') { container('jnlp') { - if(!fileExists("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}")) { - sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project}/${git_project}") + if (!fileExists("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}")) { + sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project_upstream_user}/${git_project}") } - if ( "${internal_status}" == "unstable" ) { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + if ("${internal_status}" == "unstable") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout development") } } else { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout master") } } - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { - sh """ - rm -rf vendor/github.com/v3io/v3io-tsdb/ - git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git vendor/github.com/v3io/v3io-tsdb - cd vendor/github.com/v3io/v3io-tsdb - git checkout ${V3IO_TSDB_VERSION} - rm -rf .git vendor/github.com/${git_project} vendor/github.com/v3io/frames/vendor/golang.org/x/net - """ + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + if("${git_project_user}" != "${git_project_upstream_user}") { + sh("GO111MODULE=on go mod edit -replace github.com/${git_project_upstream_user}/v3io-tsdb=github.com/${git_project_user}/v3io-tsdb@${V3IO_TSDB_VERSION}") + sh("GO111MODULE=on go get") + } else { + sh("GO111MODULE=on go get github.com/${git_project_user}/v3io-tsdb@${V3IO_TSDB_VERSION}") + } + sh("GO111MODULE=on go mod vendor") } } } stage('git push') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ git config --global user.email '${GIT_USERNAME}@iguazio.com' git config --global user.name '${GIT_USERNAME}' @@ -161,7 +202,7 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { git add vendor/github.com; """ try { - sh("git commit -am 'Updated TSDB to ${V3IO_TSDB_VERSION}'") + sh("git commit -m 'Updated TSDB to ${V3IO_TSDB_VERSION}'") } catch (err) { echo "Can not commit" } @@ -177,6 +218,9 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { } } } + container('golang') { + sh("rm -rf ${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") + } } } } @@ -206,9 +250,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") if (github.check_tag_expiration(git_project, git_project_user, MAIN_TAG_VERSION, GIT_TOKEN)) { parallel( 'v3io-tsdb': { - podTemplate(label: "v3io-tsdb-${label}", inheritFrom: "${git_project}-${label}", containers: [ - containerTemplate(name: 'golang', image: 'golang:1.11') - ]) { + podTemplate(label: "v3io-tsdb-${label}", inheritFrom: "jnlp-docker-golang") { node("v3io-tsdb-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') @@ -219,7 +261,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") } }, 'tsdb-nuclio': { - podTemplate(label: "v3io-tsdb-nuclio-${label}", inheritFrom: "${git_project}-${label}") { + podTemplate(label: "v3io-tsdb-nuclio-${label}", inheritFrom: "jnlp-docker") { node("v3io-tsdb-nuclio-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') @@ -259,7 +301,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") } }, 'prometheus': { - podTemplate(label: "v3io-tsdb-prometheus-${label}", inheritFrom: "${git_project}-${label}") { + podTemplate(label: "v3io-tsdb-prometheus-${label}", inheritFrom: "jnlp-docker") { node("v3io-tsdb-prometheus-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.mod b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.mod new file mode 100644 index 00000000..0becd8c3 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.mod @@ -0,0 +1,35 @@ +module github.com/v3io/v3io-tsdb + +go 1.12 + +require ( + github.com/cespare/xxhash v1.1.0 + github.com/cpuguy83/go-md2man v1.0.8 // indirect + github.com/ghodss/yaml v1.0.0 + github.com/imdario/mergo v0.3.7 + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/nuclio/logger v0.0.1 + github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 + github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 + github.com/nuclio/zap v0.0.2 + github.com/pkg/errors v0.8.1 + github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a + github.com/russross/blackfriday v1.5.2+incompatible // indirect + github.com/spf13/cobra v0.0.3 + github.com/spf13/pflag v1.0.3 // indirect + github.com/stretchr/testify v1.3.0 + github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 + github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 + github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 + golang.org/x/net v0.0.0-20181114220301-adae6a3d119a // indirect + golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect + golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 // indirect + google.golang.org/grpc v1.17.0 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect +) + +replace ( + github.com/xwb1989/sqlparser => github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 + labix.org/v2/mgo => github.com/go-mgo/mgo v0.0.0-20180705113738-7446a0344b7872c067b3d6e1b7642571eafbae17 + launchpad.net/gocheck => github.com/go-check/check v0.0.0-20180628173108-788fd78401277ebd861206a03c884797c6ec5541 +) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.sum b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.sum new file mode 100644 index 00000000..88dd27e0 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/go.sum @@ -0,0 +1,125 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cpuguy83/go-md2man v1.0.8 h1:DwoNytLphI8hzS2Af4D0dfaEaiSq2bN05mEm4R6vf8M= +github.com/cpuguy83/go-md2man v1.0.8/go.mod h1:N6JayAiVKtlHSnuTCeuLSQVs75hb8q+dYQLjr7cDsKY= +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/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8= +github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM= +github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +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/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/nuclio/logger v0.0.0-20180410162335-ccc5ab971395/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo= +github.com/nuclio/logger v0.0.1 h1:e+vT/Ug65RC+u0QX2J+lq3P57ZBwJ1ZA6Q2LCEcViwE= +github.com/nuclio/logger v0.0.1/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo= +github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 h1:wSCJEH8mUQ3VTyUukbYdxmi0UMmB14Lu1GOlNOs0dWY= +github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324/go.mod h1:NqMgotiF6Y0Ho4+i5AvJhH3FRKAyL4IMaMv/eoUOkKQ= +github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 h1:OubDnFViat46haboYrm/rMyMcmctrAjJ+eFJGh4qXSA= +github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37/go.mod h1:aO4cdrk1L42/y4l7IPeNAcY+9bb060Sjpr56+LiTmMc= +github.com/nuclio/zap v0.0.0-20180228181516-4a2bd2f9ef28/go.mod h1:SUxPsgePvlyjx6c5MtGdB50pf0IQThtlyLwISLboeuc= +github.com/nuclio/zap v0.0.2 h1:rY5PkMOl8CTkqRqIPuxziBiKK6Mq/8oEurfgRnNtqf0= +github.com/nuclio/zap v0.0.2/go.mod h1:SUxPsgePvlyjx6c5MtGdB50pf0IQThtlyLwISLboeuc= +github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8 h1:1N/m7VjDY1Pd30Uwv6bLttZVFQm3n8RUK9Ylf2J+4a4= +github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8/go.mod h1:6FWOCx06uh50GClv8S2cfk3asqTJs3qq3ZNRtLZE77I= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +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/prometheus v2.5.0+incompatible h1:7QPitgO2kOFG8ecuRn9O/4L9+10He72rVRJvMXrE9Hg= +github.com/prometheus/prometheus v2.5.0+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/russross/blackfriday v1.5.2+incompatible h1:/YIL6L1Deczl4O/cQ7ZVdrdKwuB6y7EWpw9LkD8xofE= +github.com/russross/blackfriday v1.5.2+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 h1:Y/ABiIlS3tqLHsj0DZkkpMyvdoCmU1nwgQ0On6n6imk= +github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15/go.mod h1:6aKW4Wl4A+gQhXH0JRCVOLgwvcrLyk+fqEpemuie094= +github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 h1:myF4tU/HdFWU1UzMdf16cHRbownzsyvL7VKIHqkrSvo= +github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871/go.mod h1:QD2Bo64oyTWzeV8RFehXS0hZEDFgOK99/h2a6ErRu6E= +github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 h1:NJc63wM25iS+ci5z7LVwjWD4QM0QpTQw/fovKzatss0= +github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2/go.mod h1:GXYcR9MxgfbE3BJdkXki5EclvtS8Nxu2RQNLA8hMMog= +github.com/v3io/v3io-tsdb v0.0.0-20190328071546-4e85f3df2d205fc7368d54184bb2ceff949ab4bd/go.mod h1:A+5yKC16QxLf+Fy5v7VvIxSw+jwsKHLhUS7dCYFDLAA= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco= +github.com/valyala/fasthttp v1.0.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 h1:x6rhz8Y9CjbgQkccRGmELH6K+LJj7tOoh3XWeC1yaQM= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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 h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/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-20181026203630-95b1ffbd15a5 h1:x6r4Jo0KNzOOzYd8lbcRsqjuqEASK6ob3auvWYM4/8U= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 h1:mzjBh+S5frKOsOBobWIMAbXavqjmgO17k/2puhcFR94= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9 h1:26lptpu+T60F849wXfTQMz9ecFf6nTQM0J1JjLSga5U= +google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.16.0 h1:dz5IJGuC2BB7qXR5AyHNwAUBhZscK2xVez7mznh72sY= +google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= +google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +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.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go index ac93cd49..94c6f11d 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go @@ -6,15 +6,23 @@ import ( ) type AggregationParams struct { - colName string // column name ("v" in timeseries) - aggrMask AggrType // the sum of aggregates (or between all aggregates) - rollupTime int64 // time per bucket (cell in the array) - Interval int64 // requested (query) aggregation step - buckets int // number of buckets in the array - overlapWindows []int // a list of overlapping windows (* interval), e.g. last 1hr, 6hr, 12hr, 24hr + colName string // column name ("v" in timeseries) + aggrMask AggrType // the sum of aggregates (or between all aggregates) + rollupTime int64 // time per bucket (cell in the array) + Interval int64 // requested (query) aggregation step + buckets int // number of buckets in the array + overlapWindows []int // a list of overlapping windows (* interval), e.g. last 1hr, 6hr, 12hr, 24hr + aggregationWindow int64 // a time window on which to calculate the aggregation per Interval + disableClientAggregation bool + useServerAggregateCoefficient int } -func NewAggregationParams(functions, col string, buckets int, interval, rollupTime int64, windows []int) (*AggregationParams, error) { +func NewAggregationParams(functions, col string, + buckets int, + interval, aggregationWindow, rollupTime int64, + windows []int, + disableClientAggregation bool, + useServerAggregateCoefficient int) (*AggregationParams, error) { aggregatesList := strings.Split(functions, ",") aggrMask, _, err := AggregatesFromStringListWithCount(aggregatesList) @@ -23,12 +31,15 @@ func NewAggregationParams(functions, col string, buckets int, interval, rollupTi } newAggregateSeries := AggregationParams{ - aggrMask: aggrMask, - colName: col, - buckets: buckets, - rollupTime: rollupTime, - Interval: interval, - overlapWindows: windows, + aggrMask: aggrMask, + colName: col, + buckets: buckets, + rollupTime: rollupTime, + aggregationWindow: aggregationWindow, + Interval: interval, + overlapWindows: windows, + disableClientAggregation: disableClientAggregation, + useServerAggregateCoefficient: useServerAggregateCoefficient, } return &newAggregateSeries, nil @@ -42,7 +53,8 @@ func (as *AggregationParams) CanAggregate(partitionAggr AggrType) bool { // if interval and rollup are not even divisors we need higher resolution (3x) to smooth the graph // when we add linear/spline graph projection we can reduce back to 1x return ((aggrMask & partitionAggr) == aggrMask) && - as.Interval >= as.rollupTime && (as.Interval%as.rollupTime == 0 || as.Interval/as.rollupTime > 3) + (as.Interval/as.rollupTime > int64(as.useServerAggregateCoefficient) || (as.Interval == as.rollupTime && as.disableClientAggregation)) && + (as.aggregationWindow == 0 || as.aggregationWindow >= as.rollupTime) } func (as *AggregationParams) GetAggrMask() AggrType { @@ -53,6 +65,14 @@ func (as *AggregationParams) GetRollupTime() int64 { return as.rollupTime } +func (as *AggregationParams) GetAggregationWindow() int64 { + return as.aggregationWindow +} + +func (as *AggregationParams) HasAggregationWindow() bool { + return as.aggregationWindow > 0 +} + func (as *AggregationParams) toAttrName(aggr AggrType) string { return fmt.Sprintf("_%v_%v", as.colName, aggr.String()) } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go index 8b9a83b0..94900869 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go @@ -58,6 +58,7 @@ type chunkStore struct { performanceReporter *performance.MetricReporter curChunk int + nextTid int64 lastTid int64 chunks [2]*attrAppender @@ -142,6 +143,7 @@ func (cs *chunkStore) getChunksState(mc *MetricsCache, metric *MetricState) (boo if !cs.isAggr() { cs.chunks[0].initialize(part, t) } + cs.nextTid = t cs.aggrList = aggregate.NewAggregatesList(part.AggrType()) // TODO: if policy to merge w old chunks needs to get prev chunk, vs restart appender @@ -214,10 +216,9 @@ func (cs *chunkStore) processGetResp(mc *MetricsCache, metric *MetricState, resp if cs.chunks[0].inRange(maxTime) && !mc.cfg.OverrideOld { cs.chunks[0].state |= chunkStateMerge } - - // Set Last TableId - indicate that there is no need to create metric object - cs.lastTid = cs.chunks[0].partition.GetStartTime() } + // Set Last TableId - indicate that there is no need to create metric object + cs.lastTid = cs.nextTid } // Append data to the right chunk and table based on the time and state @@ -255,6 +256,7 @@ func (cs *chunkStore) chunkByTime(t int64, isVariantEncoding bool) *attrAppender } nextPart, _ := part.NextPart(t) cur.initialize(nextPart, t) + cs.nextTid = t cur.appender = app cs.curChunk = cs.curChunk ^ 1 diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go deleted file mode 100644 index 1248852e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package appender - -import ( - "testing" -) - -func TestStore(t *testing.T) { - - //store := NewChunkStore() - //store.state = storeStateReady - //store.Append(1521531613002, 1.1) - //store.Append(1521531613002+3500000, 2.1) - - //lset := labels.Labels{labels.Label{Name: "__name__", Value: "http_req"}, - // labels.Label{Name: "method", Value: "post"}} - - //exp, tid := store.writeChunks(lset) - //println(exp, tid) - //store.ProcessWriteResp() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go index 21cb7cf1..e53810d6 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go @@ -33,6 +33,8 @@ import ( "github.com/pkg/errors" ) +var defaultDisableNginxMitigation = true + const ( V3ioConfigEnvironmentVariable = "V3IO_TSDB_CONFIG" DefaultConfigurationFileName = "v3io-tsdb-config.yaml" @@ -48,15 +50,16 @@ const ( defaultMinimumChunkSize = 200 // bytes defaultMaximumChunkSize = 32000 // bytes - DefaultShardingBucketsCount = 8 - DefaultStorageClass = "local" - DefaultIngestionRate = "" - DefaultAggregates = "" // no aggregates by default - DefaultAggregationGranularity = "1h" - DefaultLayerRetentionTime = "1y" - DefaultSampleRetentionTime = 0 - DefaultLogLevel = "info" - DefaultVerboseLevel = "debug" + DefaultShardingBucketsCount = 8 + DefaultStorageClass = "local" + DefaultIngestionRate = "" + DefaultAggregates = "" // no aggregates by default + DefaultAggregationGranularity = "1h" + DefaultLayerRetentionTime = "1y" + DefaultSampleRetentionTime = 0 + DefaultLogLevel = "info" + DefaultVerboseLevel = "debug" + DefaultUseServerAggregateCoefficient = 3 // KV attribute names MaxTimeAttrName = "_maxtime" @@ -137,8 +140,6 @@ type V3ioConfig struct { // Number of parallel V3IO worker routines for queries; // default = the minimum value between 8 and Workers QryWorkers int `json:"qryWorkers"` - // Max uncommitted (delayed) samples allowed per metric - MaxBehind int `json:"maxBehind"` // Override last chunk; by default, an append from the last point is attempted upon restart OverrideOld bool `json:"overrideOld"` // Default timeout duration, in seconds; default = 3,600 seconds (1 hour) @@ -163,7 +164,12 @@ type V3ioConfig struct { // Build Info BuildInfo *BuildInfo `json:"buildInfo,omitempty"` // Override nginx bug - DisableNginxMitigation bool `json:"disableNginxMitigation,omitempty"` + DisableNginxMitigation *bool `json:"disableNginxMitigation,omitempty"` + // explicitly always use client aggregation + UsePreciseAggregations bool `json:"usePreciseAggregations,omitempty"` + // Coefficient to decide whether or not to use server aggregates optimization + // use server aggregations if ` / > UseServerAggregateCoefficient` + UseServerAggregateCoefficient int `json:"useServerAggregateCoefficient,omitempty"` } type MetricsReporterConfig struct { @@ -276,6 +282,11 @@ func GetOrLoadFromStruct(cfg *V3ioConfig) (*V3ioConfig, error) { return instance, nil } +// Eagerly reloads TSDB configuration. Note: not thread-safe +func UpdateConfig(path string) { + instance, failure = loadConfig(path) +} + // Update the defaults when using an existing configuration structure (custom configuration) func WithDefaults(cfg *V3ioConfig) *V3ioConfig { initDefaults(cfg) @@ -417,4 +428,12 @@ func initDefaults(cfg *V3ioConfig) { if cfg.ShardingBucketsCount == 0 { cfg.ShardingBucketsCount = DefaultShardingBucketsCount } + + if cfg.UseServerAggregateCoefficient == 0 { + cfg.UseServerAggregateCoefficient = DefaultUseServerAggregateCoefficient + } + + if cfg.DisableNginxMitigation == nil { + cfg.DisableNginxMitigation = &defaultDisableNginxMitigation + } } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go index 4f1f2985..e7836faf 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go @@ -1,3 +1,5 @@ +// +build unit + package config import ( diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go index cde2c401..fe5a9c6a 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go @@ -4,6 +4,8 @@ import ( "encoding/csv" "fmt" "io" + "strconv" + "time" "github.com/pkg/errors" "github.com/v3io/v3io-tsdb/pkg/chunkenc" @@ -45,6 +47,13 @@ func (f textFormatter) Write(out io.Writer, set utils.SeriesSet) error { return nil } +func (f textFormatter) timeString(t int64) string { + if f.cfg.TimeFormat == "" { + return strconv.Itoa(int(t)) + } + return time.Unix(t/1000, 0).Format(f.cfg.TimeFormat) +} + type csvFormatter struct { baseFormatter } @@ -61,7 +70,7 @@ func (f csvFormatter) Write(out io.Writer, set utils.SeriesSet) error { for iter.Next() { t, v := iter.At() - writer.Write([]string{name, labelStr, fmt.Sprintf("%.6f", v), f.timeString(t)}) + _ = writer.Write([]string{name, labelStr, fmt.Sprintf("%.6f", v), strconv.FormatInt(t, 10)}) } if iter.Err() != nil { diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go index fee148fe..95a19506 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go @@ -3,7 +3,6 @@ package formatter import ( "fmt" "io" - "strconv" "strings" "time" @@ -43,16 +42,9 @@ type baseFormatter struct { cfg *FormatterConfig } -func (f baseFormatter) timeString(t int64) string { - if f.cfg.TimeFormat == "" { - return strconv.Itoa(int(t)) - } - return time.Unix(t/1000, 0).UTC().Format(f.cfg.TimeFormat) -} - func labelsToStr(labels utils.Labels) (string, string) { name := "" - lbls := []string{} + var lbls []string for _, lbl := range labels { if lbl.Name == "__name__" { name = lbl.Value diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go index bd9f3288..0532fd8d 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go @@ -30,7 +30,6 @@ import ( "sync" "github.com/pkg/errors" - "github.com/prometheus/prometheus/pkg/labels" "github.com/v3io/v3io-go-http" "github.com/v3io/v3io-tsdb/internal/pkg/performance" "github.com/v3io/v3io-tsdb/pkg/aggregate" @@ -362,7 +361,7 @@ func (p *DBPartition) GetMetricPath(name string, hash uint64, labelNames []strin } else { var namelessLabelNames []string for _, l := range labelNames { - if l != labels.MetricName { + if l != config.PrometheusMetricNameAttribute { namelessLabelNames = append(namelessLabelNames, l) } } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go index 6ff8d357..3484f820 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go @@ -12,7 +12,7 @@ import ( // Chunk-list series iterator type RawChunkIterator struct { - mint, maxt int64 + mint, maxt, aggregationWindow int64 chunks []chunkenc.Chunk encoding chunkenc.Encoding @@ -33,8 +33,16 @@ func newRawChunkIterator(queryResult *qryResults, log logger.Logger) utils.Serie maxt = int64(maxTime.(int)) } + var aggregationWindow int64 + if queryResult.query.aggregationParams != nil { + aggregationWindow = queryResult.query.aggregationParams.GetAggregationWindow() + } newIterator := RawChunkIterator{ - mint: queryResult.query.mint, maxt: maxt, log: log.GetChild("rawChunkIterator"), encoding: queryResult.encoding} + mint: queryResult.query.mint, + maxt: maxt, + aggregationWindow: aggregationWindow, + log: log.GetChild("rawChunkIterator"), + encoding: queryResult.encoding} newIterator.AddChunks(queryResult) @@ -56,8 +64,8 @@ func (it *RawChunkIterator) Seek(t int64) bool { } // Seek to the first valid value after t - if t < it.mint { - t = it.mint + if t < it.mint-it.aggregationWindow { + t = it.mint - it.aggregationWindow } // Check the first element @@ -115,7 +123,7 @@ func (it *RawChunkIterator) Next() bool { it.updatePrevPoint() if it.iter.Next() { t, _ := it.iter.At() - if t < it.mint { + if t < it.mint-it.aggregationWindow { if !it.Seek(it.mint) { return false } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go index 35ab857c..dda274a8 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go @@ -124,12 +124,11 @@ func aggregateClientAggregates(ctx *selectQueryContext, res *qryResults) { it := newRawChunkIterator(res, ctx.logger) for it.Next() { t, v := it.At() - currentCell := (t - ctx.queryParams.From) / res.query.aggregationParams.Interval - for _, col := range res.frame.columns { - if col.GetColumnSpec().metric == res.name { - _ = res.frame.setDataAt(col.Name(), int(currentCell), v) - } + if res.query.aggregationParams.HasAggregationWindow() { + windowAggregation(ctx, res, t, v) + } else { + intervalAggregation(ctx, res, t, v) } } } @@ -155,8 +154,8 @@ func aggregateServerAggregates(ctx *selectQueryContext, res *qryResults) { val := binary.LittleEndian.Uint64(bytes[i : i+8]) currentValueIndex := (i - 16) / 8 - // Calculate the last time in the current cell - currentValueTime := partitionStartTime + int64(currentValueIndex)*rollupInterval + (rollupInterval - 1) + // Calculate server side aggregate bucket by its median time + currentValueTime := partitionStartTime + int64(currentValueIndex)*rollupInterval + rollupInterval/2 currentCell := (currentValueTime - ctx.queryParams.From) / res.query.aggregationParams.Interval var floatVal float64 @@ -165,7 +164,18 @@ func aggregateServerAggregates(ctx *selectQueryContext, res *qryResults) { } else { floatVal = math.Float64frombits(val) } - _ = res.frame.setDataAt(col.Name(), int(currentCell), floatVal) + + bottomMargin := res.query.aggregationParams.Interval + if res.query.aggregationParams.HasAggregationWindow() { + bottomMargin = res.query.aggregationParams.GetAggregationWindow() + } + if currentValueTime >= ctx.queryParams.From-bottomMargin && currentValueTime <= ctx.queryParams.To+res.query.aggregationParams.Interval { + if !res.query.aggregationParams.HasAggregationWindow() { + _ = res.frame.setDataAt(col.Name(), int(currentCell), floatVal) + } else { + windowAggregationWithServerAggregates(ctx, res, col, currentValueTime, floatVal) + } + } } } } @@ -186,24 +196,28 @@ func downsampleRawData(ctx *selectQueryContext, res *qryResults, } for currCell := 0; currCell < col.Len(); currCell++ { currCellTime := int64(currCell)*ctx.queryParams.Step + ctx.queryParams.From - if it.Seek(currCellTime) { - t, v := it.At() - tCellIndex := (t - ctx.queryParams.From) / ctx.queryParams.Step - if t == currCellTime { - _ = res.frame.setDataAt(col.Name(), int(currCell), v) - } else if tCellIndex == int64(currCell) { - prevT, prevV := it.PeakBack() - - // In case it's the first point in the partition use the last point of the previous partition for the interpolation - if prevT == 0 { - prevT = previousPartitionLastTime - prevV = previousPartitionLastValue - } - interpolatedT, interpolatedV := col.GetInterpolationFunction()(prevT, t, currCellTime, prevV, v) + prev, err := col.getBuilder().At(currCell) + + // Only update a cell if it hasn't been set yet + if prev == nil || err != nil { + if it.Seek(currCellTime) { + t, v := it.At() + if t == currCellTime { + _ = res.frame.setDataAt(col.Name(), int(currCell), v) + } else { + prevT, prevV := it.PeakBack() + + // In case it's the first point in the partition use the last point of the previous partition for the interpolation + if prevT == 0 { + prevT = previousPartitionLastTime + prevV = previousPartitionLastValue + } + interpolatedT, interpolatedV := col.GetInterpolationFunction()(prevT, t, currCellTime, prevV, v) - // Check if the interpolation was successful in terms of exceeding tolerance - if !(interpolatedT == 0 && interpolatedV == 0) { - _ = res.frame.setDataAt(col.Name(), int(currCell), interpolatedV) + // Check if the interpolation was successful in terms of exceeding tolerance + if !(interpolatedT == 0 && interpolatedV == 0) { + _ = res.frame.setDataAt(col.Name(), int(currCell), interpolatedV) + } } } } @@ -263,3 +277,66 @@ func aggregateClientAggregatesCrossSeries(ctx *selectQueryContext, res *qryResul lastT, lastV := it.At() return lastT, lastV, nil } + +func intervalAggregation(ctx *selectQueryContext, res *qryResults, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, false) + aggregateAllColumns(res, currentCell, v) +} + +func windowAggregation(ctx *selectQueryContext, res *qryResults, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, true) + aggregationWindow := res.query.aggregationParams.GetAggregationWindow() + + if aggregationWindow > res.query.aggregationParams.Interval { + currentCellTime := ctx.queryParams.From + currentCell*res.query.aggregationParams.Interval + maximumAffectedTime := t + aggregationWindow + numAffectedCells := (maximumAffectedTime-currentCellTime)/res.query.aggregationParams.Interval + 1 // +1 to include the current cell + + for i := int64(0); i < numAffectedCells; i++ { + aggregateAllColumns(res, currentCell+i, v) + } + } else if aggregationWindow < res.query.aggregationParams.Interval { + if t+aggregationWindow >= ctx.queryParams.From+currentCell*res.query.aggregationParams.Interval { + aggregateAllColumns(res, currentCell, v) + } + } else { + aggregateAllColumns(res, currentCell, v) + } +} + +func windowAggregationWithServerAggregates(ctx *selectQueryContext, res *qryResults, column Column, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, true) + + aggregationWindow := res.query.aggregationParams.GetAggregationWindow() + if aggregationWindow > res.query.aggregationParams.Interval { + currentCellTime := ctx.queryParams.From + currentCell*res.query.aggregationParams.Interval + maxAffectedTime := t + aggregationWindow + numAffectedCells := (maxAffectedTime-currentCellTime)/res.query.aggregationParams.Interval + 1 // +1 to include the current cell + + for i := int64(0); i < numAffectedCells; i++ { + _ = res.frame.setDataAt(column.Name(), int(currentCell+i), v) + } + } else { + _ = res.frame.setDataAt(column.Name(), int(currentCell), v) + } +} + +func getRelativeCell(time, beginning, interval int64, roundUp bool) int64 { + cell := (time - beginning) / interval + + if roundUp && (time-beginning)%interval > 0 { + cell++ + } + + return cell +} + +// Set data to all aggregated columns for the given metric +func aggregateAllColumns(res *qryResults, cell int64, value float64) { + for _, col := range res.frame.columns { + colSpec := col.GetColumnSpec() + if colSpec.metric == res.name && colSpec.function != 0 { + _ = res.frame.setDataAt(col.Name(), int(cell), value) + } + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go index 7aadc1ba..60acb589 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go @@ -433,9 +433,11 @@ func (d *dataFrame) rawSeriesToColumns() { seriesTodefaultValue := make([]interface{}, len(d.rawColumns)) currentTime := int64(math.MaxInt64) nextTime := int64(math.MaxInt64) + seriesHasMoreData := make([]bool, len(d.rawColumns)) for i, rawSeries := range d.rawColumns { if rawSeries.Iterator().Next() { + seriesHasMoreData[i] = true t, _ := rawSeries.Iterator().At() if t < nextTime { nextTime = t @@ -479,20 +481,19 @@ func (d *dataFrame) rawSeriesToColumns() { t, v = iter.At() } - hasMoreData := true if t == currentTime { columns[seriesIndex].Append(v) if iter.Next() { t, _ = iter.At() } else { nonExhaustedIterators-- - hasMoreData = false + seriesHasMoreData[seriesIndex] = false } } else { columns[seriesIndex].Append(seriesTodefaultValue[seriesIndex]) } - if hasMoreData && t < nextTime { + if seriesHasMoreData[seriesIndex] && t < nextTime { nextTime = t } } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go index 468c957f..5029bc18 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go @@ -1,3 +1,5 @@ +// +build unit + /* Copyright 2018 Iguazio Systems Ltd. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go new file mode 100644 index 00000000..075eb02d --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go @@ -0,0 +1,715 @@ +// +build integration + +package pqueriertest + +import ( + "math" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testClientAggregatesSuite struct { + basicQueryTestSuite +} + +func TestClientAggregatesSuite(t *testing.T) { + suite.Run(t, new(testClientAggregatesSuite)) +} + +func (suite *testClientAggregatesSuite) TestQueryAggregateWithNameWildcard() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedData := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData, "diskio": expectedData} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Functions: "max,min,sum", Step: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + aggr := set.At().Labels().Get(aggregate.AggregateLabel) + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expectedData)*len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestQueryAggregateWithFilterOnMetricName() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedData := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Functions: "max", Step: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), Filter: "_name=='cpu'"} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + aggr := set.At().Labels().Get(aggregate.AggregateLabel) + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartitionNonConcreteAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, + "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "avg,stdvar", + Step: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartitionOneStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 25*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 20*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 12*tsdbtest.DaysInMillis, 30}, + {suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 40}, + {suite.basicQueryTime + 20*tsdbtest.DaysInMillis, 50}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"count": {{Time: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, Value: 5}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "count", + Step: 0, + From: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + 21*tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestGetEmptyResponse() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "i dont exist", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestSelectAggregatesByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "max"}, {Metric: "cpu", Function: "min"}, {Metric: "cpu", Function: "sum"}}, + Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestSelectAggregatesAndRawByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "": {{suite.basicQueryTime, 10}, {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu"}}, + Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestQueryAllData() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 2 * 60 * 1000, + From: 0, + To: math.MaxInt64} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestAggregatesWithZeroStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 40}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "sum": {{Time: suite.basicQueryTime, Value: 100}}, + "count": {{Time: suite.basicQueryTime, Value: 4}}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 4, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestUsePreciseAggregationsConfig() { + suite.v3ioConfig.UsePreciseAggregations = true + defer func() { suite.v3ioConfig.UsePreciseAggregations = false }() + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter.") + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "max": {{Time: suite.basicQueryTime, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier v2.") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.NoError(err, "failed to exeute query,") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(3, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go new file mode 100644 index 00000000..bdff56eb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go @@ -0,0 +1,559 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testCrossSeriesAggregatesSuite struct { + basicQueryTestSuite +} + +func TestCrossSeriesAggregatesSuite(t *testing.T) { + suite.Run(t, new(testCrossSeriesAggregatesSuite)) +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesTimesFallsOnStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 20}, + {Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 60}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesWithInterpolation() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 40}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartitionExactlyOnStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, + {Time: suite.basicQueryTime, Value: 50}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 100}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}, + "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, + {Time: suite.basicQueryTime, Value: 25}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartitionWithInterpolation() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 3*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 21}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 21}, + {Time: suite.basicQueryTime, Value: 50}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 61}}, + "count": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime, Value: 2}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 2}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 1}}, + "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 10.5}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 10.5}, + {Time: suite.basicQueryTime, Value: 25}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30.5}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu)),count_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesWithInterpolationOverTolerance() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 5 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime + selectParams.To = suite.basicQueryTime + 10*tsdbtest.MinuteInMillis + for i := 0; i < len(selectParams.RequestedColumns); i++ { + selectParams.RequestedColumns[i].InterpolationTolerance = tsdbtest.MinuteInMillis + } + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "max": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,max_all,count_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go new file mode 100644 index 00000000..2e4066f3 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go @@ -0,0 +1,626 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "math" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/frames" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testSelectDataframeSuite struct { + basicQueryTestSuite +} + +func TestSelectDataframeSuite(t *testing.T) { + suite.Run(t, new(testSelectDataframeSuite)) +} + +func (suite *testSelectDataframeSuite) TestAggregatesWithZeroStepSelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string]tsdbtest.DataPoint{"max": {Time: suite.basicQueryTime, Value: 40}, + "min": {Time: suite.basicQueryTime, Value: 10}, + "sum": {Time: suite.basicQueryTime, Value: 100}, + "count": {Time: suite.basicQueryTime, Value: 4}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 1, indexCol.Len()) + t, err := indexCol.TimeAt(0) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), suite.basicQueryTime, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + suite.Require().Equal(1, col.Len()) + currentColAggregate := strings.Split(col.Name(), "(")[0] + f, err := col.FloatAt(0) + assert.NoError(suite.T(), err) + suite.Require().Equal(expected[currentColAggregate].Value, f) + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestEmptyRawDataSelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 10*tsdbtest.MinuteInMillis, To: suite.basicQueryTime - 1*tsdbtest.MinuteInMillis} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + suite.Require().Equal(0, frame.Indices()[0].Len()) + + for _, colName := range frame.Names() { + col, _ := frame.Column(colName) + assert.Equal(suite.T(), 0, col.Len()) + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) Test2Series1EmptySelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 10}}}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"cpu": ingestedData, + "diskio": {{suite.basicQueryTime, math.NaN()}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), math.NaN()}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params, _, _ := pquerier.ParseQuery("select cpu,diskio") + params.From = suite.basicQueryTime + params.To = suite.basicQueryTime + 4*tsdbtest.MinuteInMillis + + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), len(ingestedData), indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), ingestedData[i].Time, t.UnixNano()/int64(time.Millisecond)) + } + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + assert.Equal(suite.T(), len(ingestedData), col.Len()) + for i := 0; i < col.Len(); i++ { + currentExpected := expected[col.Name()][i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + assert.Equal(suite.T(), currentExpected, f) + } + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestStringAndFloatMetricsDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter") + + metricName1 := "cpu" + metricName2 := "log" + labels := utils.LabelsFromStringList("os", "linux") + labelsWithName := append(labels, utils.LabelsFromStringList("__name__", metricName2)...) + + expectedTimeColumn := []int64{suite.basicQueryTime, suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis} + logData := []interface{}{"a", "b", "c"} + expectedColumns := map[string][]interface{}{metricName1: {10.0, 20.0, 30.0}, + metricName2: logData} + appender, err := adapter.Appender() + suite.NoError(err, "failed to create v3io appender") + + ref, err := appender.Add(labelsWithName, expectedTimeColumn[0], logData[0]) + suite.NoError(err, "failed to add data to the TSDB appender") + for i := 1; i < len(expectedTimeColumn); i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], logData[i]) + } + + _, err = appender.WaitForCompletion(0) + suite.NoError(err, "failed to wait for TSDB append completion") + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier") + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} + iter, err := querierV2.SelectDataFrame(params) + suite.NoError(err, "failed to execute query") + + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().Equal(expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + var v interface{} + + column, err := frame.Column(columnName) + suite.NoError(err) + if column.DType() == frames.FloatType { + v, _ = column.FloatAt(i) + } else if column.DType() == frames.StringType { + v, _ = column.StringAt(i) + } else { + suite.Fail(fmt.Sprintf("column type is not as expected: %v", column.DType())) + } + + suite.Require().Equal(expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) + } + } + } +} + +func (suite *testSelectDataframeSuite) TestQueryDataFrameMultipleMetricsWithMultipleLabelSets() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}} + ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, + {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{ + fmt.Sprintf("%v-%v", metricName1, "linux"): {{suite.basicQueryTime, 10}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, math.NaN()}}, + fmt.Sprintf("%v-%v", metricName2, "linux"): {{suite.basicQueryTime, math.NaN()}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}}, + fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData3}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 2, indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", metricName1, "linux")][i].Time, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + currentExpectedData := expectedData[fmt.Sprintf("%v-%v", col.Name(), frame.Labels()["os"])] + assert.Equal(suite.T(), len(currentExpectedData), col.Len()) + currentExpected := currentExpectedData[i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + assert.Equal(suite.T(), currentExpected, f) + } + } + } + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestSelectDataframeAggregationsMetricsHaveBigGaps() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} + + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu1", + Labels: labels1, + Data: ingestedData1}, + tsdbtest.Metric{ + Name: "cpu2", + Labels: labels1, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} + expected := map[string][]float64{"count(cpu1)": {1, 1, math.NaN()}, + "count(cpu2)": {math.NaN(), math.NaN(), 1}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{ + Functions: "count", + Step: int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var dataFrameCount int + for set.NextFrame() { + dataFrameCount++ + frame, err := set.GetFrame() + suite.Require().NoError(err) + suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") + suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") + + indexCol := frame.Indices()[0] + + for i := 0; i < len(expected); i++ { + t, err := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().NoError(err) + suite.Require().Equal(expectedTime[i], timeMillis) + + for _, currName := range frame.Names() { + currCol, err := frame.Column(currName) + suite.Require().NoError(err) + currVal, err := currCol.FloatAt(i) + + suite.Require().NoError(err) + if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { + suite.Require().Equal(expected[currName][i], currVal) + } + } + } + } + + suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestSelectDataframeDaownsampleMetricsHaveBigGaps() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} + + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu1", + Labels: labels1, + Data: ingestedData1}, + tsdbtest.Metric{ + Name: "cpu2", + Labels: labels1, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis - 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis - 1*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis - 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis - 1*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis} + expected := map[string][]float64{"cpu1": {10, 20, 20, 20, math.NaN(), math.NaN(), math.NaN()}, + "cpu2": {math.NaN(), math.NaN(), math.NaN(), math.NaN(), 30, 30, 30}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{ + Step: int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var dataFrameCount int + for set.NextFrame() { + dataFrameCount++ + frame, err := set.GetFrame() + suite.Require().NoError(err) + suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") + suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") + + indexCol := frame.Indices()[0] + + for i := 0; i < len(expected); i++ { + t, err := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().NoError(err) + suite.Require().Equal(expectedTime[i], timeMillis) + + for _, currName := range frame.Names() { + currCol, err := frame.Column(currName) + suite.Require().NoError(err) + currVal, err := currCol.FloatAt(i) + + suite.Require().NoError(err) + if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { + suite.Require().Equal(expected[currName][i], currVal) + } + } + } + } + + suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestQueryDataFrameMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter") + + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 15}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 18}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 22}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 26}} + + expectedData := map[string][]tsdbtest.DataPoint{ + metricName1: {{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 15}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 18}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, math.NaN()}}, + metricName2: {{suite.basicQueryTime, math.NaN()}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 22}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 26}}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.SelectDataFrame(params) + suite.NoError(err, "failed to exeute query") + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 6, indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + suite.Require().Equal(expectedData[metricName1][i].Time, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + currentExpectedData := expectedData[col.Name()] + suite.Require().Equal(len(currentExpectedData), col.Len()) + currentExpected := currentExpectedData[i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + suite.Require().Equal(currentExpected, f) + } + } + } + } + + suite.Require().Equal(1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go new file mode 100644 index 00000000..72d2f7ac --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go @@ -0,0 +1,183 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testDownsampleSuite struct { + basicQueryTestSuite +} + +func TestDownsampleSuite(t *testing.T) { + suite.Run(t, new(testDownsampleSuite)) +} + +func (suite *testDownsampleSuite) TestDownSampleNotReturningAggrAttr() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + labels := set.At().Labels() + suite.Require().Empty(labels.Get(aggregate.AggregateLabel)) + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testDownsampleSuite) TestRawDataSinglePartitionWithDownSample() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 8*tsdbtest.MinuteInMillis, 40}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Step: 2 * int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testDownsampleSuite) TestRawDataDownSampleMultiPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T23:40:00Z"), 10}, + {suite.toMillis("2018-11-18T23:59:00Z"), 20}, + {suite.toMillis("2018-11-19T00:20:00Z"), 30}, + {suite.toMillis("2018-11-19T02:40:00Z"), 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T22:00:00Z"), 10}, + {suite.toMillis("2018-11-19T00:00:00Z"), 30}, + {suite.toMillis("2018-11-19T02:00:00Z"), 40}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, + Step: 2 * int64(tsdbtest.HoursInMillis), + From: suite.toMillis("2018-11-18T22:00:00Z"), + To: suite.toMillis("2018-11-19T4:00:00Z")} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go new file mode 100644 index 00000000..c5f2bf44 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go @@ -0,0 +1,208 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type getLabelSetsSuite struct { + suite.Suite + v3ioConfig *config.V3ioConfig + suiteTimestamp int64 + basicQueryTime int64 +} + +func TestGetLabelSetsSuite(t *testing.T) { + suite.Run(t, new(getLabelSetsSuite)) +} + +func (suite *getLabelSetsSuite) SetupSuite() { + v3ioConfig, err := tsdbtest.LoadV3ioConfig() + if err != nil { + suite.T().Fatalf("unable to load configuration. Error: %v", err) + } + + suite.v3ioConfig = v3ioConfig + suite.suiteTimestamp = time.Now().Unix() + suite.basicQueryTime, err = tsdbtest.DateStringToMillis("2018-07-21T10:00:00Z") + suite.NoError(err) +} + +func (suite *getLabelSetsSuite) SetupTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) +} + +func (suite *getLabelSetsSuite) TearDownTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + if !suite.T().Failed() { + tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) + } +} + +func (suite *getLabelSetsSuite) TestGetLabels() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsAllMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "diskio")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsAllSpecificMetric() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsWithFilter() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "os=='linux'") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go new file mode 100644 index 00000000..2d58da27 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go @@ -0,0 +1,68 @@ +// +build integration + +/* +Copyright 2018 Iguazio Systems Ltd. + +Licensed under the Apache License, Version 2.0 (the "License") with +an addition restriction as set forth herein. You may not use this +file except in compliance with the License. You may obtain a copy of +the License at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied. See the License for the specific language governing +permissions and limitations under the License. + +In addition, you may not use the software for any purposes that are +illegal under applicable law, and the grant of the foregoing license +under the Apache 2.0 license is conditioned upon your compliance with +such restriction. +*/ + +package pqueriertest + +import ( + "fmt" + "time" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" +) + +type basicQueryTestSuite struct { + suite.Suite + v3ioConfig *config.V3ioConfig + suiteTimestamp int64 + basicQueryTime int64 +} + +func (suite *basicQueryTestSuite) toMillis(date string) int64 { + time, err := tsdbtest.DateStringToMillis(date) + suite.NoError(err) + return time +} + +func (suite *basicQueryTestSuite) SetupSuite() { + v3ioConfig, err := tsdbtest.LoadV3ioConfig() + if err != nil { + suite.T().Fatalf("unable to load configuration. Error: %v", err) + } + + suite.v3ioConfig = v3ioConfig + suite.suiteTimestamp = time.Now().Unix() + suite.basicQueryTime = suite.toMillis("2018-07-21T21:40:00Z") +} + +func (suite *basicQueryTestSuite) SetupTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) +} + +func (suite *basicQueryTestSuite) TearDownTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + if !suite.T().Failed() { + tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go new file mode 100644 index 00000000..ef562e67 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go @@ -0,0 +1,273 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testSQLSyntaxQuerySuite struct { + basicQueryTestSuite +} + +func TestSQLSyntaxQuerySuite(t *testing.T) { + suite.Run(t, new(testSQLSyntaxQuerySuite)) +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByOneLabelSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") + labels2 := utils.LabelsFromStringList("os", "mac", "region", "europe") + labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas") + labels4 := utils.LabelsFromStringList("os", "linux", "region", "asia") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels3, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels4, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string]map[string][]tsdbtest.DataPoint{ + "linux": { + "sum": {{Time: suite.basicQueryTime, Value: 30}}, + "count": {{Time: suite.basicQueryTime, Value: 3}}}, + "mac": { + "sum": {{Time: suite.basicQueryTime, Value: 10}}, + "count": {{Time: suite.basicQueryTime, Value: 1}}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: "os"} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "failed to exeute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + groupByValue := set.At().Labels().Get("os") + suite.Require().NoError(err) + + suite.Require().Equal(expected[groupByValue][agg], data, "queried data does not match expected") + } + + suite.Require().Equal(4, seriesCount, "series count didn't match expected") +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByMultipleLabelsSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "1") + labels2 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "2") + labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas", "version", "3") + labels4 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "1") + labels5 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "2") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels3, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels4, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels5, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + groupBy := []string{"os", "region"} + expected := map[string]map[string][]tsdbtest.DataPoint{ + "linux-europe": { + "sum": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}}, + "linux-americas": { + "sum": {{Time: suite.basicQueryTime, Value: 10}}, + "count": {{Time: suite.basicQueryTime, Value: 1}}}, + "mac-asia": { + "sum": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: strings.Join(groupBy, ",")} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "failed to exeute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + var groupByValue []string + for _, label := range groupBy { + groupByValue = append(groupByValue, set.At().Labels().Get(label)) + } + labelsStr := strings.Join(groupByValue, "-") + + suite.Require().NoError(err) + + suite.Require().Equal(expected[labelsStr][agg], data, "queried data does not match expected") + } + + suite.Require().Equal(6, seriesCount, "series count didn't match expected") +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByNotExistingLabel() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: "something that does not exist"} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected fail but continued normally") + } +} + +func (suite *testSQLSyntaxQuerySuite) TestAggregateSeriesWithAlias() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedResult := 40.0 + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + aliasName := "iguaz" + params, _, _ := pquerier.ParseQuery(fmt.Sprintf("select max(cpu) as %v", aliasName)) + + params.From = suite.basicQueryTime + params.To = suite.basicQueryTime + int64(numberOfEvents*eventsInterval) + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + assert.Equal(suite.T(), 1, len(data), "queried data does not match expected") + assert.Equal(suite.T(), expectedResult, data[0].Value, "queried data does not match expected") + + seriesName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + suite.Equal(aliasName, seriesName) + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go new file mode 100644 index 00000000..7070f3b7 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go @@ -0,0 +1,634 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "math" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testRawQuerySuite struct { + basicQueryTestSuite +} + +func TestRawQuerySuite(t *testing.T) { + suite.Run(t, new(testRawQuerySuite)) +} + +func (suite *testRawQuerySuite) TestRawDataSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestRawDataMultiplePartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 3*eventsInterval, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestFilterOnLabel() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 3*eventsInterval, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Filter: "os=='linux'", + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestQueryWithBadTimeParameters() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), To: suite.basicQueryTime} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected to get error but no error was returned") + } +} + +func (suite *testRawQuerySuite) TestQueryMetricWithDashInTheName() { // IG-8585 + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cool-cpu", + Labels: labels1, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected an error but finish succesfully") + } +} + +func (suite *testRawQuerySuite) TestSelectRawDataByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := ingestedData + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestRawDataMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 4*eventsInterval, 40}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 3*eventsInterval, 30}, + {suite.basicQueryTime + 4*eventsInterval, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{metricName1: ingestData1, metricName2: ingestData2} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData[name], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDataFrameRawDataMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedTimeColumn := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 5*tsdbtest.DaysInMillis, + suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, suite.basicQueryTime + 4*tsdbtest.MinuteInMillis} + expectedColumns := map[string][]float64{metricName1: {10, math.NaN(), 20, 30, math.NaN(), 40}, + metricName2: {math.NaN(), 10, math.NaN(), 20, 30, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + iter, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] // in tsdb we have only one index + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + column, err := frame.Column(columnName) + suite.NoError(err) + v, _ := column.FloatAt(i) + + expected := expectedColumns[column.Name()][i] + + // assert can not compare NaN, so we need to check it manually + if !(math.IsNaN(expected) && math.IsNaN(v)) { + assert.Equal(suite.T(), expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) + } + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestQueryMultipleMetricsWithMultipleLabelSets() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} + ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, + {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{fmt.Sprintf("%v-%v", metricName1, "linux"): ingestData1, + fmt.Sprintf("%v-%v", metricName2, "linux"): ingestData2, + fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData3}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + os := set.At().Labels().Get("os") + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", name, os)], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDifferentLabelSetsInDifferentPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels2 := utils.LabelsFromStringList("os", "mac") + + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 40}, + {suite.basicQueryTime, 40}} + + expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDifferentMetricsInDifferentPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 10}, + {suite.basicQueryTime, 40}} + + expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{ + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go new file mode 100644 index 00000000..d9e5e0ea --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go @@ -0,0 +1,384 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testServerAggregatesSuite struct { + basicQueryTestSuite +} + +func TestServerAggregatesSuite(t *testing.T) { + suite.Run(t, new(testServerAggregatesSuite)) +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 100}}, + "min": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 10}}, + "max": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesSinglePartitionNegativeValues() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, -10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), -20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, -30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, -40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -100}}, + "min": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -40}}, + "max": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -10}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + firstStepTime := suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis + secondStepTime := suite.basicQueryTime - 1*tsdbtest.HoursInMillis + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 90}}, + "min": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 20}}, + "max": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 40}}, + "sqr": {{Time: firstStepTime, Value: 100}, {Time: secondStepTime, Value: 2900}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min,sqr", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesMultiPartitionNonConcreteAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + firstStepTime := suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis + secondStepTime := suite.basicQueryTime - 1*tsdbtest.HoursInMillis + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: firstStepTime, Value: 11}, {Time: secondStepTime, Value: 30}}, + "stdvar": {{Time: firstStepTime, Value: 2}, {Time: secondStepTime, Value: 100}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "avg,stdvar", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestSelectServerAggregatesAndRawByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 100}}, + "": {{suite.basicQueryTime - 4*tsdbtest.HoursInMillis, 10}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu", Interpolator: "next", InterpolationTolerance: 5 * tsdbtest.HoursInMillis}}, + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestAggregatesWithDisabledClientAggregation() { + suite.v3ioConfig.DisableClientAggr = true + defer func() { suite.v3ioConfig.DisableClientAggr = false }() + + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime - tsdbtest.HoursInMillis, Value: 30}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "avg", From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + currentExpected, ok := expected[agg] + suite.Require().Equal(true, ok, "got unexpected aggregate result") + assert.Equal(suite.T(), currentExpected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go new file mode 100644 index 00000000..3afd50b2 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go @@ -0,0 +1,153 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testVariantTypeSuite struct { + basicQueryTestSuite +} + +func TestVariantTypeSuite(t *testing.T) { + suite.Run(t, new(testVariantTypeSuite)) +} + +func (suite *testVariantTypeSuite) TestVariantTypeQueryWithDataFrame() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + metricName := "log" + labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) + + dataToIngest := []string{"a", "b", "c", "d", "e"} + numberOfEvents := len(dataToIngest) + var expectedTimeColumn []int64 + for i := 0; i < numberOfEvents; i++ { + expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) + } + + appender, err := adapter.Appender() + if err != nil { + suite.T().Fatalf("failed to create v3io appender. reason: %s", err) + } + + ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) + if err != nil { + suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) + } + for i := 1; i < numberOfEvents; i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) + } + + if _, err := appender.WaitForCompletion(0); err != nil { + suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, + From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + iter, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] // in tsdb we have only one index + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + column, err := frame.Column(columnName) + suite.NoError(err) + v, _ := column.StringAt(i) + + expected := dataToIngest[i] + + assert.Equal(suite.T(), expected, v, "column %v does not match at index %v", column.Name(), i) + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testVariantTypeSuite) TestVariantTypeQueryWithSeries() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + metricName := "log" + labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) + + dataToIngest := []string{"a", "b", "c", "d", "e"} + numberOfEvents := len(dataToIngest) + var expectedTimeColumn []int64 + for i := 0; i < numberOfEvents; i++ { + expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) + } + + appender, err := adapter.Appender() + if err != nil { + suite.T().Fatalf("failed to create v3io appender. reason: %s", err) + } + + ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) + if err != nil { + suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) + } + for i := 1; i < numberOfEvents; i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) + } + + if _, err := appender.WaitForCompletion(0); err != nil { + suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, + From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + iter, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.Next() { + seriesCount++ + iter := iter.At().Iterator() + var i int + for iter.Next() { + t, v := iter.AtString() + assert.Equal(suite.T(), expectedTimeColumn[i], t, "time does not match at index %v", i) + assert.Equal(suite.T(), dataToIngest[i], v, "value does not match at index %v", i) + i++ + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go new file mode 100644 index 00000000..a8943199 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go @@ -0,0 +1,479 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testWindowAggregationSuite struct { + basicQueryTestSuite +} + +func TestWindowAggregationSuite(t *testing.T) { + suite.Run(t, new(testWindowAggregationSuite)) +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowBiggerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 390}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 6 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowSmallerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 120}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 170}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowEqualToStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 300}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowExceedsPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestedData := []tsdbtest.DataPoint{{Time: suite.toMillis("2018-07-19T23:50:00Z"), Value: 1}, + {Time: suite.toMillis("2018-07-19T23:55:00Z"), Value: 2}, + {Time: suite.toMillis("2018-07-19T23:57:00Z"), Value: 3}, + {Time: suite.toMillis("2018-07-20T00:10:00Z"), Value: 4}, + {Time: suite.toMillis("2018-07-20T00:20:00Z"), Value: 5}, + {Time: suite.toMillis("2018-07-20T00:30:00Z"), Value: 6}, + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.toMillis("2018-07-20T00:10:00Z"), Value: 10}, + {Time: suite.toMillis("2018-07-20T00:20:00Z"), Value: 15}, + {Time: suite.toMillis("2018-07-20T00:30:00Z"), Value: 15}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 10 * tsdbtest.MinuteInMillis, + AggregationWindow: 30 * tsdbtest.MinuteInMillis, + From: suite.toMillis("2018-07-20T00:10:00Z"), + To: suite.toMillis("2018-07-20T00:30:00Z")} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowBiggerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.HoursInMillis, Value: 350}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.HoursInMillis, + AggregationWindow: 6 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowEqualToStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.HoursInMillis, Value: 300}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.HoursInMillis, + AggregationWindow: 5 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowEqualToRollupInterval() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 1*tsdbtest.HoursInMillis, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.HoursInMillis, Value: 20}, + {Time: suite.basicQueryTime + 3*tsdbtest.HoursInMillis, Value: 30}, + {Time: suite.basicQueryTime + 4*tsdbtest.HoursInMillis, Value: 40}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 50}, + {Time: suite.basicQueryTime + 6*tsdbtest.HoursInMillis, Value: 60}, + {Time: suite.basicQueryTime + 7*tsdbtest.HoursInMillis, Value: 70}, + {Time: suite.basicQueryTime + 8*tsdbtest.HoursInMillis, Value: 80}, + {Time: suite.basicQueryTime + 9*tsdbtest.HoursInMillis, Value: 90}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 1 * tsdbtest.HoursInMillis, + AggregationWindow: 1 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go index 17649b45..b1c4dc85 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go @@ -39,21 +39,26 @@ type V3ioQuerier struct { } type SelectParams struct { - Name string - Functions string - From, To, Step int64 - Windows []int - Filter string - RequestedColumns []RequestedColumn - GroupBy string + Name string + Functions string + From, To, Step int64 + Windows []int + Filter string + RequestedColumns []RequestedColumn + GroupBy string + AggregationWindow int64 + UseOnlyClientAggr bool disableAllAggr bool disableClientAggr bool } -func (s *SelectParams) getRequestedColumns() []RequestedColumn { +func (s *SelectParams) getRequestedColumns() ([]RequestedColumn, error) { + if err := s.validateSelectParams(); err != nil { + return nil, err + } if s.RequestedColumns != nil { - return s.RequestedColumns + return s.RequestedColumns, nil } functions := strings.Split(s.Functions, ",") metricNames := strings.Split(s.Name, ",") @@ -68,14 +73,43 @@ func (s *SelectParams) getRequestedColumns() []RequestedColumn { index++ } } - return columns + return columns, nil +} + +func (s *SelectParams) validateSelectParams() error { + if s.UseOnlyClientAggr && s.disableClientAggr { + return errors.New("can not query, both `useOnlyClientAggr` and `disableClientAggr` flags are set") + } + + if s.RequestedColumns == nil { + functions := strings.Split(s.Functions, ",") + functionMap := make(map[string]bool, len(functions)) + for _, function := range functions { + trimmed := strings.TrimSpace(function) + if functionMap[trimmed] { + return fmt.Errorf("function '%v' was requested multiple time", trimmed) + } + functionMap[trimmed] = true + } + } else { + functionMap := make(map[string]bool, len(s.RequestedColumns)) + for _, col := range s.RequestedColumns { + trimmed := strings.TrimSpace(col.Function) + key := fmt.Sprintf("%v-%v", col.Metric, trimmed) + if functionMap[key] { + return fmt.Errorf("function '%v' for metric '%v' was requested multiple time", trimmed, col.Metric) + } + functionMap[key] = true + } + } + + return nil } func (q *V3ioQuerier) SelectProm(params *SelectParams, noAggr bool) (utils.SeriesSet, error) { params.disableClientAggr = true params.disableAllAggr = noAggr - iter, err := q.baseSelectQry(params, false) if err != nil || iter == nil { return utils.NullSeriesSet{}, err @@ -122,11 +156,17 @@ func (q *V3ioQuerier) baseSelectQry(params *SelectParams, showAggregateLabel boo return nil, errors.New("Query workers num must be a power of 2 and > 0 !") } + // If the config is set to use only client configuration override the query parameter. + if q.cfg.UsePreciseAggregations { + params.UseOnlyClientAggr = true + } + selectContext := selectQueryContext{ container: q.container, logger: q.logger, workers: q.cfg.QryWorkers, showAggregateLabel: showAggregateLabel, + v3ioConfig: q.cfg, } q.logger.Debug("Select query:\n\tMetric: %s\n\tStart Time: %s (%d)\n\tEnd Time: %s (%d)\n\tFunction: %s\n\t"+ @@ -138,7 +178,8 @@ func (q *V3ioQuerier) baseSelectQry(params *SelectParams, showAggregateLabel boo q.performanceReporter.WithTimer("QueryTimer", func() { params.Filter = strings.Replace(params.Filter, config.PrometheusMetricNameAttribute, config.MetricNameAttrName, -1) - parts := q.partitionMngr.PartsForRange(params.From, params.To, true) + // Get all partitions containing data relevant to the query. If the Aggregation Window parameter is specified take it in account. + parts := q.partitionMngr.PartsForRange(params.From-params.AggregationWindow, params.To, true) if len(parts) == 0 { return } @@ -174,6 +215,11 @@ func (q *V3ioQuerier) LabelValues(labelKey string) (result []string, err error) return } +// Stub +func (q *V3ioQuerier) LabelNames() ([]string, error) { + return nil, nil +} + func (q *V3ioQuerier) getMetricNames() ([]string, error) { input := v3io.GetItemsInput{ Path: filepath.Join(q.cfg.TablePath, config.NamesDirectory) + "/", // Need a trailing slash diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go deleted file mode 100644 index bcc17853..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go +++ /dev/null @@ -1,3490 +0,0 @@ -// +build integration - -/* -Copyright 2018 Iguazio Systems Ltd. - -Licensed under the Apache License, Version 2.0 (the "License") with -an addition restriction as set forth herein. You may not use this -file except in compliance with the License. You may obtain a copy of -the License at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. - -In addition, you may not use the software for any purposes that are -illegal under applicable law, and the grant of the foregoing license -under the Apache 2.0 license is conditioned upon your compliance with -such restriction. -*/ - -package pquerier_test - -import ( - "fmt" - "math" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - "github.com/v3io/frames" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/pquerier" - "github.com/v3io/v3io-tsdb/pkg/tsdb" - "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type testQuerySuite struct { - suite.Suite - v3ioConfig *config.V3ioConfig - suiteTimestamp int64 - basicQueryTime int64 -} - -func (suite *testQuerySuite) SetupSuite() { - v3ioConfig, err := tsdbtest.LoadV3ioConfig() - if err != nil { - suite.T().Fatalf("unable to load configuration. Error: %v", err) - } - - suite.v3ioConfig = v3ioConfig - suite.suiteTimestamp = time.Now().Unix() - suite.basicQueryTime = suite.toMillis("2018-07-21T21:40:00Z") -} - -func (suite *testQuerySuite) SetupTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) -} - -func (suite *testQuerySuite) TearDownTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - if !suite.T().Failed() { - tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) - } -} - -func (suite *testQuerySuite) TestRawDataSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataMultiplePartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 3*eventsInterval, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestFilterOnLabel() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 3*eventsInterval, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Filter: "os=='linux'", - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryWithBadTimeParameters() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), To: suite.basicQueryTime} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected to get error but no error was returned") - } -} - -func (suite *testQuerySuite) TestQueryMetricWithDashInTheName() { // IG-8585 - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cool-cpu", - Labels: labels1, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected an error but finish succesfully") - } -} - -func (suite *testQuerySuite) TestQueryAggregateWithNameWildcard() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedData := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData, "diskio": expectedData} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Functions: "max,min,sum", Step: 2 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - aggr := set.At().Labels().Get(aggregate.AggregateLabel) - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expectedData)*len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryAggregateWithFilterOnMetricName() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedData := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Functions: "max", Step: 2 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), Filter: "_name=='cpu'"} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - aggr := set.At().Labels().Get(aggregate.AggregateLabel) - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDownSampleNotReturningAggrAttr() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - labels := set.At().Labels() - suite.Require().Empty(labels.Get(aggregate.AggregateLabel)) - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataSinglePartitionWithDownSample() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 8*tsdbtest.MinuteInMillis, 40}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataDownSampleMultiPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T23:40:00Z"), 10}, - {suite.toMillis("2018-11-18T23:59:00Z"), 20}, - {suite.toMillis("2018-11-19T00:20:00Z"), 30}, - {suite.toMillis("2018-11-19T02:40:00Z"), 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T22:00:00Z"), 10}, - {suite.toMillis("2018-11-19T00:00:00Z"), 30}, - {suite.toMillis("2018-11-19T02:00:00Z"), 40}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, - Step: 2 * int64(tsdbtest.HoursInMillis), - From: suite.toMillis("2018-11-18T22:00:00Z"), - To: suite.toMillis("2018-11-19T4:00:00Z")} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "max": {{Time: suite.basicQueryTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesWithQueryIntervalSameAsAggrGranularity() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - baseTime := suite.toMillis("2018-07-21T21:00:00Z") - ingestedData := []tsdbtest.DataPoint{{baseTime, 10}, - {int64(baseTime + tsdbtest.MinuteInMillis), 20}, - {baseTime + 2*tsdbtest.MinuteInMillis, 30}, - {baseTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: baseTime, Value: 100}}, - "min": {{Time: baseTime, Value: 10}}, - "max": {{Time: baseTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: baseTime, To: baseTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesSinglePartitionNegativeValues() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, -10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), -20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, -30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, -40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: -100}}, - "min": {{Time: suite.basicQueryTime, Value: -40}}, - "max": {{Time: suite.basicQueryTime, Value: -10}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}, - "sqr": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 100}, {Time: suite.basicQueryTime, Value: 2900}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesMultiPartitionNonConcreteAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, - "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "avg,stdvar", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,max,min", - Step: 5 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartitionNonConcreteAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, - "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "avg,stdvar", - Step: 5 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartitionOneStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 25*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 20*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 12*tsdbtest.DaysInMillis, 30}, - {suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 40}, - {suite.basicQueryTime + 20*tsdbtest.DaysInMillis, 50}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"count": {{Time: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, Value: 5}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "count", - Step: 0, - From: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + 21*tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGetEmptyResponse() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "i dont exist", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectAggregatesByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "max"}, {Metric: "cpu", Function: "min"}, {Metric: "cpu", Function: "sum"}}, - Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectRawDataByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := ingestedData - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectAggregatesAndRawByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "": {{suite.basicQueryTime, 10}, {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu"}}, - Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectServerAggregatesAndRawByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, - "": {{suite.basicQueryTime, 10}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu", Interpolator: "next"}}, - Step: 60 * tsdbtest.MinuteInMillis, From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataMultipleMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 4*eventsInterval, 40}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 3*eventsInterval, 30}, - {suite.basicQueryTime + 4*eventsInterval, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{metricName1: ingestData1, metricName2: ingestData2} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData[name], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDataFrameRawDataMultipleMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedTimeColumn := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 5*tsdbtest.DaysInMillis, - suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, - suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, suite.basicQueryTime + 4*tsdbtest.MinuteInMillis} - expectedColumns := map[string][]float64{metricName1: {10, math.NaN(), 20, 30, math.NaN(), 40}, - metricName2: {math.NaN(), 10, math.NaN(), 20, 30, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - iter, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] // in tsdb we have only one index - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - column, err := frame.Column(columnName) - suite.NoError(err) - v, _ := column.FloatAt(i) - - expected := expectedColumns[column.Name()][i] - - // assert can not compare NaN, so we need to check it manually - if !(math.IsNaN(expected) && math.IsNaN(v)) { - assert.Equal(suite.T(), expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) - } - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryAllData() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,max,min", - Step: 2 * 60 * 1000, - From: 0, - To: math.MaxInt64} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestVariantTypeQueryWithDataFrame() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - metricName := "log" - labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) - - dataToIngest := []string{"a", "b", "c", "d", "e"} - numberOfEvents := len(dataToIngest) - var expectedTimeColumn []int64 - for i := 0; i < numberOfEvents; i++ { - expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) - } - - appender, err := adapter.Appender() - if err != nil { - suite.T().Fatalf("failed to create v3io appender. reason: %s", err) - } - - ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) - if err != nil { - suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) - } - for i := 1; i < numberOfEvents; i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) - } - - if _, err := appender.WaitForCompletion(0); err != nil { - suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, - From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - iter, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] // in tsdb we have only one index - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - column, err := frame.Column(columnName) - suite.NoError(err) - v, _ := column.StringAt(i) - - expected := dataToIngest[i] - - assert.Equal(suite.T(), expected, v, "column %v does not match at index %v", column.Name(), i) - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestVariantTypeQueryWithSeries() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - metricName := "log" - labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) - - dataToIngest := []string{"a", "b", "c", "d", "e"} - numberOfEvents := len(dataToIngest) - var expectedTimeColumn []int64 - for i := 0; i < numberOfEvents; i++ { - expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) - } - - appender, err := adapter.Appender() - if err != nil { - suite.T().Fatalf("failed to create v3io appender. reason: %s", err) - } - - ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) - if err != nil { - suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) - } - for i := 1; i < numberOfEvents; i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) - } - - if _, err := appender.WaitForCompletion(0); err != nil { - suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, - From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - iter, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.Next() { - seriesCount++ - iter := iter.At().Iterator() - var i int - for iter.Next() { - t, v := iter.AtString() - assert.Equal(suite.T(), expectedTimeColumn[i], t, "time does not match at index %v", i) - assert.Equal(suite.T(), dataToIngest[i], v, "value does not match at index %v", i) - i++ - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "max": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,max_all,count_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByOneLabelSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") - labels2 := utils.LabelsFromStringList("os", "mac", "region", "europe") - labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas") - labels4 := utils.LabelsFromStringList("os", "linux", "region", "asia") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels3, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels4, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string]map[string][]tsdbtest.DataPoint{ - "linux": { - "sum": {{Time: suite.basicQueryTime, Value: 30}}, - "count": {{Time: suite.basicQueryTime, Value: 3}}}, - "mac": { - "sum": {{Time: suite.basicQueryTime, Value: 10}}, - "count": {{Time: suite.basicQueryTime, Value: 1}}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: "os"} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "failed to exeute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - groupByValue := set.At().Labels().Get("os") - suite.Require().NoError(err) - - suite.Require().Equal(expected[groupByValue][agg], data, "queried data does not match expected") - } - - suite.Require().Equal(4, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByMultipleLabelsSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "1") - labels2 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "2") - labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas", "version", "3") - labels4 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "1") - labels5 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "2") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels3, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels4, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels5, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - groupBy := []string{"os", "region"} - expected := map[string]map[string][]tsdbtest.DataPoint{ - "linux-europe": { - "sum": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}}, - "linux-americas": { - "sum": {{Time: suite.basicQueryTime, Value: 10}}, - "count": {{Time: suite.basicQueryTime, Value: 1}}}, - "mac-asia": { - "sum": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: strings.Join(groupBy, ",")} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "failed to exeute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - var groupByValue []string - for _, label := range groupBy { - groupByValue = append(groupByValue, set.At().Labels().Get(label)) - } - labelsStr := strings.Join(groupByValue, "-") - - suite.Require().NoError(err) - - suite.Require().Equal(expected[labelsStr][agg], data, "queried data does not match expected") - } - - suite.Require().Equal(6, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByNotExistingLabel() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: "something that does not exist"} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected fail but continued normally") - } -} - -func (suite *testQuerySuite) TestAggregatesWithZeroStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 40}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "sum": {{Time: suite.basicQueryTime, Value: 100}}, - "count": {{Time: suite.basicQueryTime, Value: 4}}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 4, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregatesWithZeroStepSelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string]tsdbtest.DataPoint{"max": {Time: suite.basicQueryTime, Value: 40}, - "min": {Time: suite.basicQueryTime, Value: 10}, - "sum": {Time: suite.basicQueryTime, Value: 100}, - "count": {Time: suite.basicQueryTime, Value: 4}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), 1, indexCol.Len()) - t, err := indexCol.TimeAt(0) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), suite.basicQueryTime, t.UnixNano()/int64(time.Millisecond)) - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - suite.Require().Equal(1, col.Len()) - currentColAggregate := strings.Split(col.Name(), "(")[0] - f, err := col.FloatAt(0) - assert.NoError(suite.T(), err) - suite.Require().Equal(expected[currentColAggregate].Value, f) - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestEmptyRawDataSelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 10*tsdbtest.MinuteInMillis, To: suite.basicQueryTime - 1*tsdbtest.MinuteInMillis} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - suite.Require().Equal(0, frame.Indices()[0].Len()) - - for _, colName := range frame.Names() { - col, _ := frame.Column(colName) - assert.Equal(suite.T(), 0, col.Len()) - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) Test2Series1EmptySelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 10}}}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"cpu": ingestedData, - "diskio": {{suite.basicQueryTime, math.NaN()}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), math.NaN()}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params, _, _ := pquerier.ParseQuery("select cpu,diskio") - params.From = suite.basicQueryTime - params.To = suite.basicQueryTime + 4*tsdbtest.MinuteInMillis - - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), len(ingestedData), indexCol.Len()) - for i := 0; i < indexCol.Len(); i++ { - t, err := indexCol.TimeAt(i) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), ingestedData[i].Time, t.UnixNano()/int64(time.Millisecond)) - } - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - assert.Equal(suite.T(), len(ingestedData), col.Len()) - for i := 0; i < col.Len(); i++ { - currentExpected := expected[col.Name()][i].Value - f, err := col.FloatAt(i) - assert.NoError(suite.T(), err) - - if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { - assert.Equal(suite.T(), currentExpected, f) - } - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregateSeriesWithAlias() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedResult := 40.0 - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - aliasName := "iguaz" - params, _, _ := pquerier.ParseQuery(fmt.Sprintf("select max(cpu) as %v", aliasName)) - - params.From = suite.basicQueryTime - params.To = suite.basicQueryTime + int64(numberOfEvents*eventsInterval) - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - assert.Equal(suite.T(), 1, len(data), "queried data does not match expected") - assert.Equal(suite.T(), expectedResult, data[0].Value, "queried data does not match expected") - - seriesName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - suite.Equal(aliasName, seriesName) - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestStringAndFloatMetricsDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.NoError(err, "failed to create v3io adapter") - - metricName1 := "cpu" - metricName2 := "log" - labels := utils.LabelsFromStringList("os", "linux") - labelsWithName := append(labels, utils.LabelsFromStringList("__name__", metricName2)...) - - expectedTimeColumn := []int64{suite.basicQueryTime, suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis} - logData := []interface{}{"a", "b", "c"} - expectedColumns := map[string][]interface{}{metricName1: {10.0, 20.0, 30.0}, - metricName2: logData} - appender, err := adapter.Appender() - suite.NoError(err, "failed to create v3io appender") - - ref, err := appender.Add(labelsWithName, expectedTimeColumn[0], logData[0]) - suite.NoError(err, "failed to add data to the TSDB appender") - for i := 1; i < len(expectedTimeColumn); i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], logData[i]) - } - - _, err = appender.WaitForCompletion(0) - suite.NoError(err, "failed to wait for TSDB append completion") - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - suite.NoError(err, "failed to create querier") - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} - iter, err := querierV2.SelectDataFrame(params) - suite.NoError(err, "failed to execute query") - - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().Equal(expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - var v interface{} - - column, err := frame.Column(columnName) - suite.NoError(err) - if column.DType() == frames.FloatType { - v, _ = column.FloatAt(i) - } else if column.DType() == frames.StringType { - v, _ = column.StringAt(i) - } else { - suite.Fail(fmt.Sprintf("column type is not as expected: %v", column.DType())) - } - - suite.Require().Equal(expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) - } - } - } -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesTimesFallsOnStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 20}, - {Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 60}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesWithInterpolation() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 40}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartitionExactlyOnStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, - {Time: suite.basicQueryTime, Value: 50}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 100}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}, - "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, - {Time: suite.basicQueryTime, Value: 25}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartitionWithInterpolation() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 3*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 21}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 21}, - {Time: suite.basicQueryTime, Value: 50}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 61}}, - "count": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime, Value: 2}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 2}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 1}}, - "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 10.5}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 10.5}, - {Time: suite.basicQueryTime, Value: 25}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30.5}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu)),count_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesWithInterpolationOverTolerance() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 5 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - selectParams.To = suite.basicQueryTime + 10*tsdbtest.MinuteInMillis - for i := 0; i < len(selectParams.RequestedColumns); i++ { - selectParams.RequestedColumns[i].InterpolationTolerance = tsdbtest.MinuteInMillis - } - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryMultipleMetricsWithMultipleLabelSets() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} - ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, - {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{fmt.Sprintf("%v-%v", metricName1, "linux"): ingestData1, - fmt.Sprintf("%v-%v", metricName2, "linux"): ingestData2, - fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels1, - Data: ingestData2}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData3}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Filter: "1==1", - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - os := set.At().Labels().Get("os") - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", name, os)], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryDataFrameMultipleMetricsWithMultipleLabelSets() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}} - ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, - {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{ - fmt.Sprintf("%v-%v", metricName1, "linux"): {{suite.basicQueryTime, 10}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, math.NaN()}}, - fmt.Sprintf("%v-%v", metricName2, "linux"): {{suite.basicQueryTime, math.NaN()}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}}, - fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels1, - Data: ingestData2}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData3}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Filter: "1==1", - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), 2, indexCol.Len()) - for i := 0; i < indexCol.Len(); i++ { - t, err := indexCol.TimeAt(i) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", metricName1, "linux")][i].Time, t.UnixNano()/int64(time.Millisecond)) - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - currentExpectedData := expectedData[fmt.Sprintf("%v-%v", col.Name(), frame.Labels()["os"])] - assert.Equal(suite.T(), len(currentExpectedData), col.Len()) - currentExpected := currentExpectedData[i].Value - f, err := col.FloatAt(i) - assert.NoError(suite.T(), err) - - if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { - assert.Equal(suite.T(), currentExpected, f) - } - } - } - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregatesWithDisabledClientAggregation() { - suite.v3ioConfig.DisableClientAggr = true - defer func() { suite.v3ioConfig.DisableClientAggr = false }() - - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime, Value: 30}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "avg", From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - currentExpected, ok := expected[agg] - suite.Require().Equal(true, ok, "got unexpected aggregate result") - assert.Equal(suite.T(), currentExpected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDifferentLabelSetsInDifferentPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels2 := utils.LabelsFromStringList("os", "mac") - - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 40}, - {suite.basicQueryTime, 40}} - - expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDifferentMetricsInDifferentPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 10}, - {suite.basicQueryTime, 40}} - - expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{ - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectDataframeAggregationsMetricsHaveBigGaps() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} - - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu1", - Labels: labels1, - Data: ingestedData1}, - tsdbtest.Metric{ - Name: "cpu2", - Labels: labels1, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} - expected := map[string][]float64{"count(cpu1)": {1, 1, math.NaN()}, - "count(cpu2)": {math.NaN(), math.NaN(), 1}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{ - Functions: "count", - Step: int64(tsdbtest.MinuteInMillis), - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var dataFrameCount int - for set.NextFrame() { - dataFrameCount++ - frame, err := set.GetFrame() - suite.Require().NoError(err) - suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") - suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") - - indexCol := frame.Indices()[0] - - for i := 0; i < len(expected); i++ { - t, err := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().NoError(err) - suite.Require().Equal(expectedTime[i], timeMillis) - - for _, currName := range frame.Names() { - currCol, err := frame.Column(currName) - suite.Require().NoError(err) - currVal, err := currCol.FloatAt(i) - - suite.Require().NoError(err) - if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { - suite.Require().Equal(expected[currName][i], currVal) - } - } - } - } - - suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectDataframeDaownsampleMetricsHaveBigGaps() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} - - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu1", - Labels: labels1, - Data: ingestedData1}, - tsdbtest.Metric{ - Name: "cpu2", - Labels: labels1, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} - expected := map[string][]float64{"cpu1": {10, 20, math.NaN()}, - "cpu2": {math.NaN(), math.NaN(), 30}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{ - Step: int64(tsdbtest.MinuteInMillis), - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var dataFrameCount int - for set.NextFrame() { - dataFrameCount++ - frame, err := set.GetFrame() - suite.Require().NoError(err) - suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") - suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") - - indexCol := frame.Indices()[0] - - for i := 0; i < len(expected); i++ { - t, err := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().NoError(err) - suite.Require().Equal(expectedTime[i], timeMillis) - - for _, currName := range frame.Names() { - currCol, err := frame.Column(currName) - suite.Require().NoError(err) - currVal, err := currCol.FloatAt(i) - - suite.Require().NoError(err) - if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { - suite.Require().Equal(expected[currName][i], currVal) - } - } - } - } - - suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) toMillis(date string) int64 { - time, err := tsdbtest.DateStringToMillis(date) - suite.NoError(err) - return time -} - -func TestQueryV2Suite(t *testing.T) { - suite.Run(t, new(testQuerySuite)) -} - -type getLabelSetsSuite struct { - suite.Suite - v3ioConfig *config.V3ioConfig - suiteTimestamp int64 - basicQueryTime int64 -} - -func (suite *getLabelSetsSuite) SetupSuite() { - v3ioConfig, err := tsdbtest.LoadV3ioConfig() - if err != nil { - suite.T().Fatalf("unable to load configuration. Error: %v", err) - } - - suite.v3ioConfig = v3ioConfig - suite.suiteTimestamp = time.Now().Unix() - suite.basicQueryTime, err = tsdbtest.DateStringToMillis("2018-07-21T10:00:00Z") - suite.NoError(err) -} - -func (suite *getLabelSetsSuite) SetupTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) -} - -func (suite *getLabelSetsSuite) TearDownTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - if !suite.T().Failed() { - tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) - } -} - -func (suite *getLabelSetsSuite) TestGetLabels() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsAllMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "diskio")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsAllSpecificMetric() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsWithFilter() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "os=='linux'") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func TestGetLabelSetsSuite(t *testing.T) { - suite.Run(t, new(getLabelSetsSuite)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go index 4e0ad994..7c31fe84 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go @@ -22,9 +22,10 @@ import ( const defaultToleranceFactor = 2 type selectQueryContext struct { - logger logger.Logger - container *v3io.Container - workers int + logger logger.Logger + container *v3io.Container + workers int + v3ioConfig *config.V3ioConfig queryParams *SelectParams showAggregateLabel bool @@ -35,6 +36,10 @@ type selectQueryContext struct { totalColumns int isCrossSeriesAggregate bool + // In case one of the aggregates of one of the metrics should use client side aggregates + // but the user requested to disable client aggregations - return raw data for every requested metric + forceRawQuery bool + dataFrames map[uint64]*dataFrame frameList []*dataFrame requestChannels []chan *qryResults @@ -143,6 +148,9 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio mint = queryCtx.queryParams.From } + queryRawInsteadOfAggregates, doForceAllRawQuery := false, false + var index int + for metric := range queryCtx.columnsSpecByMetric { var aggregationParams *aggregate.AggregationParams functions, requestAggregatesAndRaw := queryCtx.metricsAggregatesToString(metric) @@ -158,8 +166,11 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio "v", partition.AggrBuckets(), queryCtx.queryParams.Step, + queryCtx.queryParams.AggregationWindow, partition.RollupTime(), - queryCtx.queryParams.Windows) + queryCtx.queryParams.Windows, + queryCtx.queryParams.disableClientAggr, + queryCtx.v3ioConfig.UseServerAggregateCoefficient) if err != nil { return nil, err @@ -168,21 +179,56 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio } - newQuery := &partQuery{mint: mint, maxt: maxt, partition: partition, step: queryCtx.queryParams.Step} + newQuery := &partQuery{mint: mint, + maxt: maxt, + partition: partition, + step: queryCtx.queryParams.Step, + name: metric, + aggregatesAndChunk: requestAggregatesAndRaw} if aggregationParams != nil { // Cross series aggregations cannot use server side aggregates. - newQuery.useServerSideAggregates = aggregationParams.CanAggregate(partition.AggrType()) && !queryCtx.isCrossSeriesAggregate + newQuery.useServerSideAggregates = aggregationParams.CanAggregate(partition.AggrType()) && + !queryCtx.isCrossSeriesAggregate && + !queryCtx.queryParams.UseOnlyClientAggr if newQuery.useServerSideAggregates || !queryCtx.queryParams.disableClientAggr { newQuery.aggregationParams = aggregationParams } } - var preAggregateLabels []string if newQuery.useServerSideAggregates && !requestAggregatesAndRaw { - preAggregateLabels = queryCtx.parsePreAggregateLabels(partition) + newQuery.preAggregateLabels = queryCtx.parsePreAggregateLabels(partition) } - err = newQuery.getItems(queryCtx, metric, preAggregateLabels, requestAggregatesAndRaw) + queries = append(queries, newQuery) + + currentQueryShouldQueryRawInsteadOfAggregates := !newQuery.useServerSideAggregates && queryCtx.queryParams.disableClientAggr + if len(queryCtx.columnsSpecByMetric) == 1 && currentQueryShouldQueryRawInsteadOfAggregates { + doForceAllRawQuery = true + } else if index == 0 { + queryRawInsteadOfAggregates = currentQueryShouldQueryRawInsteadOfAggregates + } else if queryRawInsteadOfAggregates != currentQueryShouldQueryRawInsteadOfAggregates { + doForceAllRawQuery = true + } + index++ + } + + if doForceAllRawQuery { + queryCtx.forceRawQuery = true + for _, q := range queries { + q.aggregationParams = nil + q.useServerSideAggregates = false + err = q.getItems(queryCtx) + if err != nil { + break + } + } + } else { + for _, q := range queries { + err = q.getItems(queryCtx) + if err != nil { + break + } + } } return queries, err @@ -324,7 +370,12 @@ func (queryCtx *selectQueryContext) processQueryResults(query *partQuery) error func (queryCtx *selectQueryContext) createColumnSpecs() ([]columnMeta, map[string][]columnMeta, error) { var columnsSpec []columnMeta columnsSpecByMetric := make(map[string][]columnMeta) - for i, col := range queryCtx.queryParams.getRequestedColumns() { + requestedColumns, err := queryCtx.queryParams.getRequestedColumns() + if err != nil { + return nil, nil, err + } + + for i, col := range requestedColumns { _, ok := columnsSpecByMetric[col.Metric] if !ok { columnsSpecByMetric[col.Metric] = []columnMeta{} @@ -430,7 +481,9 @@ func (queryCtx *selectQueryContext) generateTimeColumn() Column { } func (queryCtx *selectQueryContext) isRawQuery() bool { - return (!queryCtx.hasAtLeastOneFunction() && queryCtx.queryParams.Step == 0) || queryCtx.queryParams.disableAllAggr + return (!queryCtx.hasAtLeastOneFunction() && queryCtx.queryParams.Step == 0) || + queryCtx.queryParams.disableAllAggr || + queryCtx.forceRawQuery } func (queryCtx *selectQueryContext) hasAtLeastOneFunction() bool { @@ -467,18 +520,22 @@ type partQuery struct { chunkTime int64 useServerSideAggregates bool aggregationParams *aggregate.AggregationParams + + name string + preAggregateLabels []string + aggregatesAndChunk bool } -func (query *partQuery) getItems(ctx *selectQueryContext, name string, preAggregateLabels []string, aggregatesAndChunk bool) error { +func (query *partQuery) getItems(ctx *selectQueryContext) error { path := query.partition.GetTablePath() - if len(preAggregateLabels) > 0 { - path = fmt.Sprintf("%sagg/%s/", path, strings.Join(preAggregateLabels, ",")) + if len(query.preAggregateLabels) > 0 { + path = fmt.Sprintf("%sagg/%s/", path, strings.Join(query.preAggregateLabels, ",")) } var shardingKeys []string - if name != "" { - shardingKeys = query.partition.GetShardingKeys(name) + if query.name != "" { + shardingKeys = query.partition.GetShardingKeys(query.name) } attrs := []string{config.LabelSetAttrName, config.EncodingAttrName, config.MetricNameAttrName, config.MaxTimeAttrName, config.ObjectNameAttrName} @@ -487,15 +544,15 @@ func (query *partQuery) getItems(ctx *selectQueryContext, name string, preAggreg } // It is possible to request both server aggregates and raw chunk data (to downsample) for the same metric // example: `select max(cpu), avg(cpu), cpu` with step = 1h - if !query.useServerSideAggregates || aggregatesAndChunk { - chunkAttr, chunk0Time := query.partition.Range2Attrs("v", query.mint, query.maxt) + if !query.useServerSideAggregates || query.aggregatesAndChunk { + chunkAttr, chunk0Time := query.partition.Range2Attrs("v", query.mint-ctx.queryParams.AggregationWindow, query.maxt) query.chunk0Time = chunk0Time query.attrs = append(query.attrs, chunkAttr...) } attrs = append(attrs, query.attrs...) - ctx.logger.DebugWith("Select - GetItems", "path", path, "attr", attrs, "filter", ctx.queryParams.Filter, "name", name) - input := v3io.GetItemsInput{Path: path, AttributeNames: attrs, Filter: ctx.queryParams.Filter, ShardingKey: name} + ctx.logger.DebugWith("Select - GetItems", "path", path, "attr", attrs, "filter", ctx.queryParams.Filter, "name", query.name) + input := v3io.GetItemsInput{Path: path, AttributeNames: attrs, Filter: ctx.queryParams.Filter, ShardingKey: query.name} iter, err := utils.NewAsyncItemsCursor(ctx.container, &input, ctx.workers, shardingKeys, ctx.logger) if err != nil { return err diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go index 9aed2e6b..8f3d32c8 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go @@ -127,6 +127,41 @@ func TestCreateColumnSpecs(t *testing.T) { } } +func TestNegativeCreateColumnSpecs(t *testing.T) { + testCases := []struct { + desc string + params SelectParams + }{ + {params: SelectParams{Name: "cpu", Functions: "count, count"}}, + + {params: SelectParams{Name: "cpu", Functions: "count, max,count"}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "cpu", Function: "count"}}}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "diskio", Function: "count"}, + {Metric: "cpu", Function: "count"}}}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "diskio", Function: "count"}, + {Metric: "cpu", Function: " count "}}}}, + + {params: SelectParams{Name: "cpu", Functions: "count, count", UseOnlyClientAggr: true, disableClientAggr: true}}, + } + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + ctx := selectQueryContext{} + ctx.queryParams = &test.params + _, _, err := ctx.createColumnSpecs() + + if err == nil { + t.Fatal("expected error but finished normally") + } + }) + } +} + func toAggr(str string) aggregate.AggrType { aggr, _ := aggregate.AggregateFromString(str) return aggr diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go index 48378b51..bb239726 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go @@ -27,11 +27,11 @@ func (q *qryResults) IsDownsample() bool { } func (q *qryResults) IsServerAggregates() bool { - return q.query.aggregationParams != nil && q.query.aggregationParams.CanAggregate(q.query.partition.AggrType()) + return q.query.aggregationParams != nil && q.query.useServerSideAggregates } func (q *qryResults) IsClientAggregates() bool { - return q.query.aggregationParams != nil && !q.query.aggregationParams.CanAggregate(q.query.partition.AggrType()) + return q.query.aggregationParams != nil && !q.query.useServerSideAggregates } type RequestedColumn struct { diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go index 829bc65f..bd77a960 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go @@ -1,3 +1,5 @@ +// +build unit + package querier import ( @@ -66,6 +68,6 @@ func (suite *testIterSortMergerSuite) TestIterSortMerger() { suite.Require().Equal(uint64(3), iter.At().GetKey()) } -func TestAddSuite(t *testing.T) { +func TestIterSortMergerSuiteSuite(t *testing.T) { suite.Run(t, new(testIterSortMergerSuite)) } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go index d024f07b..ccec3e25 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go @@ -259,6 +259,10 @@ func (q *V3ioQuerier) LabelValues(labelKey string) (result []string, err error) return } +func (q *V3ioQuerier) LabelNames() ([]string, error) { + return nil, nil +} + func (q *V3ioQuerier) Close() error { return nil } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go index 31f6a30b..fcf1aed3 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go @@ -2,10 +2,8 @@ package tsdbtest import ( "fmt" - "go/build" "os" "path/filepath" - "strings" "github.com/pkg/errors" "github.com/v3io/v3io-tsdb/pkg/config" @@ -30,19 +28,26 @@ func GetV3ioConfigPath() (string, error) { return localConfigFile, nil } - gopath := os.Getenv("GOPATH") - if gopath == "" { - gopath = build.Default.GOPATH - } - gopaths := strings.Split(gopath, string(os.PathListSeparator)) - for _, path := range gopaths { - gopathConfig := filepath.Join(path, relativeProjectPath, config.DefaultConfigurationFileName) - if _, err := os.Stat(gopathConfig); !os.IsNotExist(err) { - return gopathConfig, nil + // Look for a parent directory containing a makefile and the configuration file (presumed to be the project root). + dirPath := "./" + for { + _, err := os.Stat(dirPath + "Makefile") + if err == nil { + confFilePath := dirPath + config.DefaultConfigurationFileName + _, err = os.Stat(confFilePath) + if err == nil { + return confFilePath, nil + } + break // Bail out if we found the makefile but the config is not there. + } + absolute, err := filepath.Abs(dirPath) + if err != nil || absolute == "/" { // Bail out if we reached the root. + break } + dirPath += "../" } - return "", errors.Errorf("config file is not specified and could not be found in GOPATH=%v", gopath) + return "", errors.Errorf("config file is not specified and could not be found") } func LoadV3ioConfig() (*config.V3ioConfig, error) { diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go index 68c6f9a6..e8b7b2cc 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go @@ -69,7 +69,7 @@ func TestGetV3ioConfigPath(t *testing.T) { }}, {description: "get config from project root", - expectedPath: filepath.Join(projectHome, config.DefaultConfigurationFileName), + expectedPath: "./../../../v3io-tsdb-config.yaml", setup: func() func() { // Make this test agnostic to environment variables at runtime (store & recover on exit) configPathEnv := os.Getenv(config.V3ioConfigEnvironmentVariable) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go index 495e2f51..08e2661f 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go @@ -21,7 +21,6 @@ such restriction. package tsdbctl import ( - "strconv" "strings" "time" @@ -34,19 +33,20 @@ import ( ) type queryCommandeer struct { - cmd *cobra.Command - rootCommandeer *RootCommandeer - name string - filter string - to string - from string - last string - windows string - functions string - step string - output string - oldQuerier bool - groupBy string + cmd *cobra.Command + rootCommandeer *RootCommandeer + name string + filter string + to string + from string + last string + functions string + step string + output string + oldQuerier bool + groupBy string + usePreciseAggregations bool + aggregationWindow string } func newQueryCommandeer(rootCommandeer *RootCommandeer) *queryCommandeer { @@ -100,23 +100,19 @@ Arguments: "Query filter, as an Iguazio Continuous Data Platform\nfilter expression. To reference a metric name from within\nthe query filter, use the \"__name__\" attribute.\nExamples: \"method=='get'\"; \"__name__='cpu' AND os=='win'\".") cmd.Flags().StringVarP(&commandeer.last, "last", "l", "", "Return data for the specified time period before the\ncurrent time, of the format \"[0-9]+[mhd]\" (where\n'm' = minutes, 'h' = hours, and 'd' = days>). When setting\nthis flag, don't set the -b|--begin or -e|--end flags.\nExamples: \"1h\"; \"15m\"; \"30d\" to return data for the last\n1 hour, 15 minutes, or 30 days.") - cmd.Flags().StringVarP(&commandeer.windows, "windows", "w", "", - "Overlapping windows of time to which to apply the aggregation\nfunctions (if defined - see the -a|--aggregates flag), as a\ncomma separated list of integer values (\"[0-9]+\").\nThe duration of each window is calculated by multiplying the\nvalue from the windows flag with the aggregation interval\n(see -i|--aggregation-interval). The windows' end time is\nthe query's end time (see -e|--end and -l|--last). If the\nwindow's duration extends beyond the query's start time (see\n-b|--begin and -l|--last), it will be shortened to fit the\nstart time. Example: -w \"1,2\" with -i \"2h\", -b 0, and the\ndefault end time (\"now\") defines overlapping aggregation\nwindows for the last 2 hours and 4 hours.") - // The default aggregates list for an overlapping-windows query is "avg", - // provided the TSDB instance has the "count" and "sum" aggregates, which - // make up the "avg" aggregate; ("count" is added automatically when adding - // any other aggregate). However, it was decided that documenting this - // would over complicate the documentation. + cmd.Flags().StringVarP(&commandeer.aggregationWindow, "aggregation-window", "w", "", + "Sliding time window for aggregation. Must be used in conjunction with `-a `. Examples: \"1h\"; \"150m\".") cmd.Flags().StringVarP(&commandeer.functions, "aggregates", "a", "", "Aggregation information to return, as a comma-separated\nlist of supported aggregation functions - count | avg |\nsum | min | max | stddev | stdvar | last | rate.\nFor cross series aggregations add an \"_all\" suffix for the wanted aggregate.\nNote: you can query either over time aggregates or cross series aggregate but not both in the same query.\nExample: \"sum,min,max,count\", \"sum_all,avg_all\".") cmd.Flags().StringVarP(&commandeer.step, "aggregation-interval", "i", "", "Aggregation interval for applying the aggregation functions\n(if set - see the -a|--aggregates flag), of the format\n\"[0-9]+[mhd]\" (where 'm' = minutes, 'h' = hours, and\n'd' = days). Examples: \"1h\"; \"150m\". (default =\n - )") cmd.Flags().StringVar(&commandeer.groupBy, "groupBy", "", "Comma separated list of labels to group the result by") + cmd.Flags().BoolVar(&commandeer.usePreciseAggregations, "use-precise-aggregations", false, + "Disable server aggregation optimizations for more accurate results.") cmd.Flags().BoolVarP(&commandeer.oldQuerier, "oldQuerier", "q", false, "use old querier") cmd.Flags().Lookup("oldQuerier").Hidden = true - cmd.Flags().Lookup("windows").Hidden = true // hidden, because only supported in old querier. commandeer.cmd = cmd return commandeer @@ -186,6 +182,10 @@ func (qc *queryCommandeer) newQuery(from, to, step int64) error { if err != nil { return errors.Wrap(err, "Failed to initialize the Querier object.") } + aggregationWindow, err := utils.Str2duration(qc.aggregationWindow) + if err != nil { + return errors.Wrap(err, "Failed to parse aggregation window") + } var selectParams *pquerier.SelectParams @@ -197,9 +197,13 @@ func (qc *queryCommandeer) newQuery(from, to, step int64) error { selectParams.Step = step selectParams.From = from selectParams.To = to + selectParams.UseOnlyClientAggr = qc.usePreciseAggregations + selectParams.AggregationWindow = aggregationWindow } else { selectParams = &pquerier.SelectParams{Name: qc.name, Functions: qc.functions, - Step: step, Filter: qc.filter, From: from, To: to, GroupBy: qc.groupBy} + Step: step, Filter: qc.filter, From: from, To: to, GroupBy: qc.groupBy, + UseOnlyClientAggr: qc.usePreciseAggregations, + AggregationWindow: aggregationWindow} } set, err := qry.Select(selectParams) @@ -225,22 +229,7 @@ func (qc *queryCommandeer) oldQuery(from, to, step int64) error { } var set utils.SeriesSet - if qc.windows == "" { - set, err = qry.Select(qc.name, qc.functions, step, qc.filter) - } else { - list := strings.Split(qc.windows, ",") - win := []int{} - for _, val := range list { - i, err := strconv.Atoi(val) - if err != nil { - return errors.Wrap(err, "Invalid window.") - } - win = append(win, i) - - } - - set, err = qry.SelectOverlap(qc.name, qc.functions, step, win, qc.filter) - } + set, err = qry.Select(qc.name, qc.functions, step, qc.filter) if err != nil { return errors.Wrap(err, "The query selection failed.") diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go index 43c245fa..53caa684 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go @@ -146,6 +146,16 @@ func (rc *RootCommandeer) populateConfig(cfg *config.V3ioConfig) error { if rc.accessKey != "" { cfg.AccessKey = rc.accessKey + } else if rc.password == "" { + envAccessKey := os.Getenv("V3IO_ACCESS_KEY") + if envAccessKey != "" { + cfg.AccessKey = envAccessKey + } + } + + envV3ioApi := os.Getenv("V3IO_API") + if envV3ioApi != "" { + cfg.WebApiEndpoint = envV3ioApi } if rc.v3ioPath != "" { diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go index 9be9e9f6..8e30bb2d 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go @@ -23,6 +23,7 @@ such restriction. package tsdbctl import ( + "os" "testing" "github.com/pkg/errors" @@ -37,10 +38,9 @@ type testTsdbctlSuite struct { func (suite *testTsdbctlSuite) TestPopulateConfigWithTenant() { rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123"} - cfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{TablePath: "/x/y/z"}) - suite.Require().Nil(err) + cfg := &config.V3ioConfig{Username: "Vel@Odar", Password: "p455w0rd", TablePath: "/x/y/z"} - err = rc.populateConfig(cfg) + err := rc.populateConfig(cfg) suite.Require().Nil(err) metricReporter, err := performance.DefaultReporterInstance() @@ -55,34 +55,100 @@ func (suite *testTsdbctlSuite) TestPopulateConfigWithTenant() { v3ioPath: "localhost:80123/123", Reporter: metricReporter, } - expectedCfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{ + expectedCfg := &config.V3ioConfig{ WebApiEndpoint: "localhost:80123", Container: "123", TablePath: "/x/y/z", Username: "Vel@Odar", Password: "p455w0rd", - AccessKey: "acce55-key", - }) + LogLevel: "info", + } - suite.Require().Nil(err) suite.Require().Equal(expectedCfg, rc.v3iocfg) suite.Require().Equal(expectedRc, rc) } func (suite *testTsdbctlSuite) TestContainerConfig() { - rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123", container: "test"} - cfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{TablePath: "/x/y/z"}) - suite.Require().Nil(err) + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123", container: "test", accessKey: "acce55-key"} + cfg := &config.V3ioConfig{Username: "Vel@Odar", Password: "p455w0rd", TablePath: "/x/y/z"} err = rc.populateConfig(cfg) - expectedCfg, _ := config.GetOrLoadFromStruct(&config.V3ioConfig{ + expectedCfg := &config.V3ioConfig{ WebApiEndpoint: "localhost:80123", Container: "test", TablePath: "/x/y/z", Username: "Vel@Odar", Password: "p455w0rd", AccessKey: "acce55-key", - }) + LogLevel: "info", + } + + suite.Require().Nil(err) + suite.Require().Equal(expectedCfg, rc.v3iocfg) +} + +func (suite *testTsdbctlSuite) TestConfigFromEnvVarsAndPassword() { + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{container: "test", username: "Vel@Odar", password: "p455w0rd"} + cfg := &config.V3ioConfig{TablePath: "/x/y/z"} + suite.Require().Nil(err) + + err = rc.populateConfig(cfg) + expectedCfg := &config.V3ioConfig{ + WebApiEndpoint: "host-from-env:123", + Container: "test", + TablePath: "/x/y/z", + Username: "Vel@Odar", + Password: "p455w0rd", + LogLevel: "info", + } + + suite.Require().Nil(err) + suite.Require().Equal(expectedCfg, rc.v3iocfg) +} + +func (suite *testTsdbctlSuite) TestConfigFromEnvVars() { + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{container: "test"} + cfg := &config.V3ioConfig{TablePath: "/x/y/z"} + suite.Require().Nil(err) + + err = rc.populateConfig(cfg) + expectedCfg := &config.V3ioConfig{ + WebApiEndpoint: "host-from-env:123", + Container: "test", + TablePath: "/x/y/z", + AccessKey: "key-from-env", + LogLevel: "info", + } suite.Require().Nil(err) suite.Require().Equal(expectedCfg, rc.v3iocfg) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go index e786ccfb..5d1d949a 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go @@ -189,7 +189,7 @@ func (ic *AsyncItemsCursor) processResponse() error { } // until IGZ-2.0 there is a bug in Nginx regarding range-scan, the following code is a mitigation for it. - if conf.DisableNginxMitigation { + if *conf.DisableNginxMitigation { ic.sendNextGetItemsOld(resp) } else { ic.sendNextGetItemsNew(resp) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go deleted file mode 100644 index 3db23645..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go +++ /dev/null @@ -1,300 +0,0 @@ -package promtsdb - -import ( - "context" - "fmt" - "strings" - - "github.com/nuclio/logger" - "github.com/pkg/errors" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/storage" - "github.com/v3io/v3io-go-http" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/appender" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/pquerier" - "github.com/v3io/v3io-tsdb/pkg/tsdb" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type V3ioPromAdapter struct { - db *tsdb.V3ioAdapter - logger logger.Logger -} - -func NewV3ioProm(cfg *config.V3ioConfig, container *v3io.Container, logger logger.Logger) (*V3ioPromAdapter, error) { - - if logger == nil { - newLogger, err := utils.NewLogger(cfg.LogLevel) - if err != nil { - return nil, errors.Wrap(err, "Unable to initialize logger.") - } - logger = newLogger - } - - adapter, err := tsdb.NewV3ioAdapter(cfg, container, logger) - newAdapter := V3ioPromAdapter{db: adapter, logger: logger.GetChild("v3io-prom-adapter")} - return &newAdapter, err -} - -func (a *V3ioPromAdapter) Appender() (storage.Appender, error) { - err := a.db.InitAppenderCache() - if err != nil { - return nil, err - } - - newAppender := v3ioAppender{metricsCache: a.db.MetricsCache} - return newAppender, nil -} - -func (a *V3ioPromAdapter) StartTime() (int64, error) { - return a.db.StartTime() -} - -func (a *V3ioPromAdapter) Close() error { - return nil -} - -func (a *V3ioPromAdapter) Querier(_ context.Context, mint, maxt int64) (storage.Querier, error) { - v3ioQuerier, err := a.db.QuerierV2() - promQuerier := V3ioPromQuerier{v3ioQuerier: v3ioQuerier, logger: a.logger.GetChild("v3io-prom-query"), mint: mint, maxt: maxt} - return &promQuerier, err -} - -type V3ioPromQuerier struct { - v3ioQuerier *pquerier.V3ioQuerier - logger logger.Logger - mint, maxt int64 -} - -// Select returns a set of series that matches the given label matchers. -func (promQuery *V3ioPromQuerier) Select(params *storage.SelectParams, oms ...*labels.Matcher) (storage.SeriesSet, error) { - name, filter, functions := match2filter(oms, promQuery.logger) - noAggr := false - - // if a nil params is passed we assume it's a metadata query, so we fetch only the different labelsets withtout data. - if params == nil { - labelSets, err := promQuery.v3ioQuerier.GetLabelSets(name, filter) - if err != nil { - return nil, err - } - - return &V3ioPromSeriesSet{newMetadataSeriesSet(labelSets)}, nil - } - - promQuery.logger.Debug("SelectParams: %+v", params) - - if params.Func != "" { - // only pass xx_over_time functions (just the xx part) - // TODO: support count/stdxx, require changes in Prometheus: promql/functions.go, not calc aggregate twice - if strings.HasSuffix(params.Func, "_over_time") { - f := params.Func[0:3] - if params.Step == 0 && (f == "min" || f == "max" || f == "sum" || f == "avg") { - functions = f - } else { - noAggr = true - } - } - } - - selectParams := &pquerier.SelectParams{Name: name, - Functions: functions, - Step: params.Step, - Filter: filter, - From: promQuery.mint, - To: promQuery.maxt} - - set, err := promQuery.v3ioQuerier.SelectProm(selectParams, noAggr) - return &V3ioPromSeriesSet{s: set}, err -} - -// LabelValues returns all potential values for a label name. -func (promQuery *V3ioPromQuerier) LabelValues(name string) ([]string, error) { - return promQuery.v3ioQuerier.LabelValues(name) -} - -// Close releases the resources of the Querier. -func (promQuery *V3ioPromQuerier) Close() error { - return nil -} - -func match2filter(oms []*labels.Matcher, logger logger.Logger) (string, string, string) { - var filter []string - agg := "" - name := "" - - for _, matcher := range oms { - logger.Debug("Matcher: %+v", matcher) - if matcher.Name == aggregate.AggregateLabel { - agg = matcher.Value - } else if matcher.Name == "__name__" && matcher.Type == labels.MatchEqual { - name = matcher.Value - } else { - switch matcher.Type { - case labels.MatchEqual: - filter = append(filter, fmt.Sprintf("%s=='%s'", matcher.Name, matcher.Value)) - case labels.MatchNotEqual: - filter = append(filter, fmt.Sprintf("%s!='%s'", matcher.Name, matcher.Value)) - case labels.MatchRegexp: - filter = append(filter, fmt.Sprintf("regexp_instr(%s,'%s') == 0", matcher.Name, matcher.Value)) - case labels.MatchNotRegexp: - filter = append(filter, fmt.Sprintf("regexp_instr(%s,'%s') != 0", matcher.Name, matcher.Value)) - - } - } - } - filterExp := strings.Join(filter, " and ") - return name, filterExp, agg -} - -type V3ioPromSeriesSet struct { - s utils.SeriesSet -} - -func (s *V3ioPromSeriesSet) Next() bool { return s.s.Next() } -func (s *V3ioPromSeriesSet) Err() error { return s.s.Err() } -func (s *V3ioPromSeriesSet) At() storage.Series { - series := s.s.At() - return &V3ioPromSeries{series} -} - -// Series represents a single time series. -type V3ioPromSeries struct { - s utils.Series -} - -// Labels returns the complete set of labels identifying the series. -func (s *V3ioPromSeries) Labels() labels.Labels { - lbls := labels.Labels{} - for _, l := range s.s.Labels() { - lbls = append(lbls, labels.Label{Name: l.Name, Value: l.Value}) - } - - return lbls -} - -// Iterator returns a new iterator of the data of the series. -func (s *V3ioPromSeries) Iterator() storage.SeriesIterator { - return &V3ioPromSeriesIterator{s: s.s.Iterator()} -} - -// SeriesIterator iterates over the data of a time series. -type V3ioPromSeriesIterator struct { - s utils.SeriesIterator -} - -// Seek advances the iterator forward to the given timestamp. -// If there's no value exactly at t, it advances to the first value -// after t. -func (s *V3ioPromSeriesIterator) Seek(t int64) bool { return s.s.Seek(t) } - -// Next advances the iterator by one. -func (s *V3ioPromSeriesIterator) Next() bool { return s.s.Next() } - -// At returns the current timestamp/value pair. -func (s *V3ioPromSeriesIterator) At() (t int64, v float64) { return s.s.At() } - -// error returns the current error. -func (s *V3ioPromSeriesIterator) Err() error { return s.s.Err() } - -type v3ioAppender struct { - metricsCache *appender.MetricsCache -} - -func (a v3ioAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error) { - lbls := Labels{lbls: &lset} - return a.metricsCache.Add(lbls, t, v) -} - -func (a v3ioAppender) AddFast(lset labels.Labels, ref uint64, t int64, v float64) error { - return a.metricsCache.AddFast(ref, t, v) -} - -func (a v3ioAppender) Commit() error { return nil } -func (a v3ioAppender) Rollback() error { return nil } - -type Labels struct { - lbls *labels.Labels -} - -// convert Label set to a string in the form key1=v1,key2=v2.. + name + hash -func (ls Labels) GetKey() (string, string, uint64) { - key := "" - name := "" - for _, lbl := range *ls.lbls { - if lbl.Name == "__name__" { - name = lbl.Value - } else { - key = key + lbl.Name + "=" + lbl.Value + "," - } - } - if len(key) == 0 { - return name, "", ls.lbls.Hash() - } - return name, key[:len(key)-1], ls.lbls.Hash() - -} - -// create update expression -func (ls Labels) GetExpr() string { - lblexpr := "" - for _, lbl := range *ls.lbls { - if lbl.Name != "__name__" { - lblexpr = lblexpr + fmt.Sprintf("%s='%s'; ", lbl.Name, lbl.Value) - } else { - lblexpr = lblexpr + fmt.Sprintf("_name='%s'; ", lbl.Value) - } - } - - return lblexpr -} - -func (ls Labels) LabelNames() []string { - var res []string - for _, l := range *ls.lbls { - res = append(res, l.Name) - } - return res -} - -func newMetadataSeriesSet(labels []utils.Labels) utils.SeriesSet { - return &metadataSeriesSet{labels: labels, currentIndex: -1, size: len(labels)} -} - -type metadataSeriesSet struct { - labels []utils.Labels - currentIndex int - size int -} - -func (ss *metadataSeriesSet) Next() bool { - ss.currentIndex++ - return ss.currentIndex < ss.size -} -func (ss *metadataSeriesSet) At() utils.Series { - return &metadataSeries{labels: ss.labels[ss.currentIndex]} -} -func (ss *metadataSeriesSet) Err() error { - return nil -} - -type metadataSeries struct { - labels utils.Labels -} - -func (s *metadataSeries) Labels() utils.Labels { return s.labels } -func (s *metadataSeries) Iterator() utils.SeriesIterator { return utils.NullSeriesIterator{} } -func (s *metadataSeries) GetKey() uint64 { return s.labels.Hash() } - -func (ls Labels) Filter(keep []string) utils.LabelsIfc { - var res labels.Labels - for _, l := range *ls.lbls { - for _, keepLabel := range keep { - if l.Name == labels.MetricName || l.Name == keepLabel { - res = append(res, l) - } - } - } - return Labels{lbls: &res} -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go deleted file mode 100644 index 2be95fe6..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build integration - -package promtsdb - -import ( - "fmt" - "math/rand" - "testing" - "time" - - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/storage" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/partmgr" -) - -const basetime = 15222481971234 - -func TestTsdbIntegration(t *testing.T) { - t.Skip("Needs to be refactored - Doesnt test anything") - - d, h := partmgr.TimeToDHM(basetime) - fmt.Println("base=", d, h) - cfg, err := config.GetOrLoadFromFile("../v3io-tsdb-config.yaml") - if err != nil { - t.Fatal(err) - } - fmt.Println(cfg) - - adapter, err := NewV3ioProm(cfg, nil, nil) - if err != nil { - t.Fatal(err) - } - - //adapter.partitionMngr.GetHead().NextPart(0) - - appender, err := adapter.Appender() - if err != nil { - t.Fatal(err) - } - - lset := labels.Labels{labels.Label{Name: "__name__", Value: "http_req"}, - labels.Label{Name: "method", Value: "post"}} - - err = DoAppend(lset, appender, 50, 120) - if err != nil { - t.Fatal(err) - } - - //time.Sleep(time.Second * 5) - //return - - qry, err := adapter.Querier(nil, basetime-0*3600*1000, basetime+5*3600*1000) - if err != nil { - t.Fatal(err) - } - - match := labels.Matcher{Type: labels.MatchEqual, Name: "__name__", Value: "http_req"} - match2 := labels.Matcher{Type: labels.MatchEqual, Name: aggregate.AggregateLabel, Value: "count,avg,sum"} - //params := storage.SelectParams{Func: "count,avg,sum", Step: 1000 * 3600} - params := storage.SelectParams{Func: "", Step: 0} - set, err := qry.Select(¶ms, &match, &match2) - if err != nil { - t.Fatal(err) - } - - lasth := 0 - for set.Next() { - if set.Err() != nil { - t.Fatal(set.Err()) - } - - series := set.At() - fmt.Println("\nLables:", series.Labels()) - iter := series.Iterator() - //iter.Seek(basetime-1*3600*1000) - for iter.Next() { - - if iter.Err() != nil { - t.Fatal(iter.Err()) - } - - t, v := iter.At() - d, h := partmgr.TimeToDHM(t) - if h != lasth { - fmt.Println() - } - fmt.Printf("t=%d:%d,v=%.2f ", d, h, v) - lasth = h - } - fmt.Println() - } - -} - -func DoAppend(lset labels.Labels, app storage.Appender, num, interval int) error { - //return nil - //time.Sleep(time.Second * 1) - curTime := int64(basetime) - - ref, err := app.Add(lset, curTime, 2) - if err != nil { - return err - } - - for i := 0; i <= num; i++ { - time.Sleep(time.Millisecond * 80) - curTime += int64(interval * 1000) - t := curTime + int64(rand.Intn(100)) - 50 - _, h := partmgr.TimeToDHM(t) - v := rand.Float64()*10 + float64(h*100) - fmt.Printf("t-%d,v%3.2f ", t, v) - err = app.AddFast(lset, ref, t, v) - if err != nil { - return err - } - } - - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go deleted file mode 100644 index 0bd02f6a..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build unit - -/* -Copyright 2018 Iguazio Systems Ltd. - -Licensed under the Apache License, Version 2.0 (the "License") with -an addition restriction as set forth herein. You may not use this -file except in compliance with the License. You may obtain a copy of -the License at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. - -In addition, you may not use the software for any purposes that are -illegal under applicable law, and the grant of the foregoing license -under the Apache 2.0 license is conditioned upon your compliance with -such restriction. -*/ - -package promtsdb - -import ( - "testing" - - "github.com/nuclio/logger" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/stretchr/testify/suite" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type testPromTsdbSuite struct { - suite.Suite - logger logger.Logger -} - -func (suite *testPromTsdbSuite) TestMatch2filterEmpty() { - - name, filter, aggr := match2filter(nil, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterEqual() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "field", Value: "literal"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("field=='literal'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterMultiple() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "field1", Value: "literal1"}, - {Type: labels.MatchNotEqual, Name: "field2", Value: "literal2"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("field1=='literal1' and field2!='literal2'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterMultipleWithName() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "__name__", Value: "literal1"}, - {Type: labels.MatchNotEqual, Name: "field2", Value: "literal2"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("literal1", name) - suite.Require().Equal("field2!='literal2'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterRegex() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchRegexp, Name: "field", Value: ".*"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal(`regexp_instr(field,'.*') == 0`, filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterRegexMultiple() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchRegexp, Name: "field1", Value: ".*"}, - {Type: labels.MatchNotRegexp, Name: "field2", Value: "..."}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal(`regexp_instr(field1,'.*') == 0 and regexp_instr(field2,'...') != 0`, filter) - suite.Require().Equal("", aggr) -} - -func TestPromTsdbSuite(t *testing.T) { - log, err := utils.NewLogger(config.DefaultLogLevel) - if err != nil { - t.Fatalf("Unable to initialize logger. Error: %v", err) - } - - testSuit := new(testPromTsdbSuite) - testSuit.logger = log - suite.Run(t, testSuit) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/README.md deleted file mode 100644 index 207b7b1d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/README.md +++ /dev/null @@ -1,21 +0,0 @@ -List of Dependencies ---- - -1 github.com/cespare/xxhash@569f7c8abf1f58d9043ab804d364483cb1c853b6 -2 github.com/cpuguy83/go-md2man@691ee98543af2f262f35fbb54bdd42f00b9b9cc5 -3 github.com/ghodss/yaml@c7ce16629ff4cd059ed96ed06419dd3856fd3577 -4 github.com/go-kit/kit@9890679578cab201bd981519c97365519193d1ce -5 github.com/go-logfmt/logfmt@390ab7935ee28ec6b286364bba9b4dd6410cb3d5 -6 github.com/nuclio/logger@ccc5ab971395c6eae9a743a678d7b1bcb8e70414 -7 github.com/nuclio/nuclio-sdk-go@f750b959d2f7ebec6ebd4bc6b5638307406a5888 -8 github.com/nuclio/nuclio-test-go@0ce6587f8e37fabf4fcacfec23545f0476a459e9 -9 github.com/nuclio/zap@4a2bd2f9ef28a241ed7e3a67afa4ee8a7f1fa1ed -10 github.com/pkg/errors@c059e472caf75dbe73903f6521a20abac245b17f -11 github.com/prometheus/common@c7de2306084e37d54b8be01f3541a8464345e9a5 -12 github.com/prometheus/prometheus@b75ec7e6ef3666695edfa7bc1d9fccd1fdaae82a -13 github.com/rcrowley/go-metrics@e2704e165165ec55d062f5919b4b29494e9fa790 -14 github.com/spf13/cobra@8d114be902bc9f08717804830a55c48378108a28 -15 github.com/spf13/pflag@298182f68c66c05229eb03ac171abe6e309ee79a -16 github.com/stretchr/testify@f35b8ab0b5a2cef36673838d662e249dd9c94686 -17 github.com/v3io/v3io-go-http@36f737b2e799f92019e40267e85f73a1dff37d09 -18 gopkg.in/yaml.v2@5420a8b6744d3b0345ab293f6fcba19c978f1183 diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go deleted file mode 100644 index aa577163..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "fmt" - "io" - "os" - - "github.com/cespare/xxhash" -) - -func main() { - if contains(os.Args[1:], "-h") { - fmt.Fprintf(os.Stderr, `Usage: - %s [filenames] -If no filenames are provided or only - is given, input is read from stdin. -`, os.Args[0]) - os.Exit(1) - } - if len(os.Args) < 2 || len(os.Args) == 2 && string(os.Args[1]) == "-" { - printHash(os.Stdin, "-") - return - } - for _, path := range os.Args[1:] { - f, err := os.Open(path) - if err != nil { - fmt.Fprintln(os.Stderr, err) - continue - } - printHash(f, path) - f.Close() - } -} - -func contains(ss []string, s string) bool { - for _, s1 := range ss { - if s1 == s { - return true - } - } - return false -} - -func printHash(r io.Reader, name string) { - h := xxhash.New() - if _, err := io.Copy(h, r); err != nil { - fmt.Fprintln(os.Stderr, err) - return - } - fmt.Printf("%016x %s\n", h.Sum64(), name) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json deleted file mode 100644 index a5f83163..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Vendor": true, - "Deadline": "2m", - "Sort": ["linter", "severity", "path", "line"], - "Enable": [ - "deadcode", - "errcheck", - "structcheck", - "unused", - "varcheck", - "unconvert", - "gofmt", - "goimports", - "golint", - "ineffassign", - "vet", - "goconst", - "megacheck" - ] -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile deleted file mode 100644 index 97bec828..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM golang:1.8 AS build -COPY . /go/src/github.com/cpuguy83/go-md2man -WORKDIR /go/src/github.com/cpuguy83/go-md2man -RUN CGO_ENABLED=0 go build - -FROM scratch -COPY --from=build /go/src/github.com/cpuguy83/go-md2man/go-md2man /go-md2man -ENTRYPOINT ["/go-md2man"] diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock deleted file mode 100644 index c793f305..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock +++ /dev/null @@ -1,21 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/russross/blackfriday" - packages = ["."] - revision = "cadec560ec52d93835bf2f15bd794700d3a2473b" - version = "v2.0.0" - -[[projects]] - branch = "master" - name = "github.com/shurcooL/sanitized_anchor_name" - packages = ["."] - revision = "86672fcb3f950f35f2e675df2240550f2a50762f" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "7e41574846e5cbae82c84bab5e2e655e842f4000964fcb68be48b2d2c55017f9" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml deleted file mode 100644 index 1ada6d87..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml +++ /dev/null @@ -1,26 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/russross/blackfriday" - version = "2.0.0" diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile deleted file mode 100644 index 6e30faf8..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -check: - gometalinter --config .gometalinter.json ./... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md deleted file mode 100644 index 29ed7c9e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md +++ /dev/null @@ -1,21 +0,0 @@ -go-md2man -========= - -** Work in Progress ** -This still needs a lot of help to be complete, or even usable! - -Uses blackfriday to process markdown into man pages. - -### Usage - -./md2man -in /path/to/markdownfile.md -out /manfile/output/path - -### How to contribute - -We use [dep](https://github.com/golang/dep/) for vendoring Go packages. -See dep documentation for how to update. - -### TODO - -- Needs oh so much testing love -- Look into blackfriday's 2.0 API diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md deleted file mode 100644 index 16d1133a..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md +++ /dev/null @@ -1,23 +0,0 @@ -go-md2man 1 "January 2015" go-md2man "User Manual" -================================================== - -# NAME - go-md2man - Convert markdown files into manpages - -# SYNOPSIS - go-md2man -in=[/path/to/md/file] -out=[/path/to/output] - -# Description - go-md2man converts standard markdown formatted documents into manpages. It is - written purely in Go so as to reduce dependencies on 3rd party libs. - - By default, the input is stdin and the output is stdout. - -# Example - Convert the markdown file "go-md2man.1.md" into a manpage. - - go-md2man -in=go-md2man.1.md -out=go-md2man.1.out - -# HISTORY - January 2015, Originally compiled by Brian Goff( cpuguy83@gmail.com ) - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go deleted file mode 100644 index c35dd335..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "os" - - "github.com/cpuguy83/go-md2man/md2man" -) - -var inFilePath = flag.String("in", "", "Path to file to be processed (default: stdin)") -var outFilePath = flag.String("out", "", "Path to output processed file (default: stdout)") - -func main() { - var err error - flag.Parse() - - inFile := os.Stdin - if *inFilePath != "" { - inFile, err = os.Open(*inFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } - defer inFile.Close() // nolint: errcheck - - doc, err := ioutil.ReadAll(inFile) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - out := md2man.Render(doc) - - outFile := os.Stdout - if *outFilePath != "" { - outFile, err = os.Create(*outFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - defer outFile.Close() // nolint: errcheck - } - _, err = outFile.Write(out) - if err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go index deaa27f7..af62279a 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go @@ -6,9 +6,15 @@ import ( // Render converts a markdown document into a roff formatted document. func Render(doc []byte) []byte { - renderer := NewRoffRenderer() + renderer := RoffRenderer(0) + extensions := 0 + extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS + extensions |= blackfriday.EXTENSION_TABLES + extensions |= blackfriday.EXTENSION_FENCED_CODE + extensions |= blackfriday.EXTENSION_AUTOLINK + extensions |= blackfriday.EXTENSION_SPACE_HEADERS + extensions |= blackfriday.EXTENSION_FOOTNOTES + extensions |= blackfriday.EXTENSION_TITLEBLOCK - return blackfriday.Run(doc, - []blackfriday.Option{blackfriday.WithRenderer(renderer), - blackfriday.WithExtensions(renderer.GetExtensions())}...) + return blackfriday.Markdown(doc, renderer, extensions) } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go index d8597cb3..8c29ec68 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go @@ -1,312 +1,252 @@ package md2man import ( + "bytes" "fmt" - "io" - "os" + "html" "strings" "github.com/russross/blackfriday" ) -// roffRenderer implements the blackfriday.Renderer interface for creating -// roff format (manpages) from markdown text type roffRenderer struct { - extensions blackfriday.Extensions - listCounters []int - firstHeader bool - defineTerm bool - listDepth int -} - -const ( - titleHeader = ".TH " - topLevelHeader = "\n\n.SH " - secondLevelHdr = "\n.SH " - otherHeader = "\n.SS " - crTag = "\n" - emphTag = "\\fI" - emphCloseTag = "\\fP" - strongTag = "\\fB" - strongCloseTag = "\\fP" - breakTag = "\n.br\n" - paraTag = "\n.PP\n" - hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n" - linkTag = "\n\\[la]" - linkCloseTag = "\\[ra]" - codespanTag = "\\fB\\fC" - codespanCloseTag = "\\fR" - codeTag = "\n.PP\n.RS\n\n.nf\n" - codeCloseTag = "\n.fi\n.RE\n" - quoteTag = "\n.PP\n.RS\n" - quoteCloseTag = "\n.RE\n" - listTag = "\n.RS\n" - listCloseTag = "\n.RE\n" - arglistTag = "\n.TP\n" - tableStart = "\n.TS\nallbox;\n" - tableEnd = ".TE\n" - tableCellStart = "T{\n" - tableCellEnd = "\nT}\n" -) + ListCounters []int +} -// NewRoffRenderer creates a new blackfriday Renderer for generating roff documents +// RoffRenderer creates a new blackfriday Renderer for generating roff documents // from markdown -func NewRoffRenderer() *roffRenderer { // nolint: golint - var extensions blackfriday.Extensions - - extensions |= blackfriday.NoIntraEmphasis - extensions |= blackfriday.Tables - extensions |= blackfriday.FencedCode - extensions |= blackfriday.SpaceHeadings - extensions |= blackfriday.Footnotes - extensions |= blackfriday.Titleblock - extensions |= blackfriday.DefinitionLists - return &roffRenderer{ - extensions: extensions, - } +func RoffRenderer(flags int) blackfriday.Renderer { + return &roffRenderer{} } -// GetExtensions returns the list of extensions used by this renderer implementation -func (r *roffRenderer) GetExtensions() blackfriday.Extensions { - return r.extensions +func (r *roffRenderer) GetFlags() int { + return 0 } -// RenderHeader handles outputting the header at document start -func (r *roffRenderer) RenderHeader(w io.Writer, ast *blackfriday.Node) { +func (r *roffRenderer) TitleBlock(out *bytes.Buffer, text []byte) { + out.WriteString(".TH ") + + splitText := bytes.Split(text, []byte("\n")) + for i, line := range splitText { + line = bytes.TrimPrefix(line, []byte("% ")) + if i == 0 { + line = bytes.Replace(line, []byte("("), []byte("\" \""), 1) + line = bytes.Replace(line, []byte(")"), []byte("\" \""), 1) + } + line = append([]byte("\""), line...) + line = append(line, []byte("\" ")...) + out.Write(line) + } + out.WriteString("\n") + // disable hyphenation - out(w, ".nh\n") + out.WriteString(".nh\n") + // disable justification (adjust text to left margin only) + out.WriteString(".ad l\n") } -// RenderFooter handles outputting the footer at the document end; the roff -// renderer has no footer information -func (r *roffRenderer) RenderFooter(w io.Writer, ast *blackfriday.Node) { +func (r *roffRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) { + out.WriteString("\n.PP\n.RS\n\n.nf\n") + escapeSpecialChars(out, text) + out.WriteString("\n.fi\n.RE\n") } -// RenderNode is called for each node in a markdown document; based on the node -// type the equivalent roff output is sent to the writer -func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus { +func (r *roffRenderer) BlockQuote(out *bytes.Buffer, text []byte) { + out.WriteString("\n.PP\n.RS\n") + out.Write(text) + out.WriteString("\n.RE\n") +} - var walkAction = blackfriday.GoToNext +func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) { // nolint: golint + out.Write(text) +} - switch node.Type { - case blackfriday.Text: - r.handleText(w, node, entering) - case blackfriday.Softbreak: - out(w, crTag) - case blackfriday.Hardbreak: - out(w, breakTag) - case blackfriday.Emph: - if entering { - out(w, emphTag) - } else { - out(w, emphCloseTag) - } - case blackfriday.Strong: - if entering { - out(w, strongTag) - } else { - out(w, strongCloseTag) - } - case blackfriday.Link: - if !entering { - out(w, linkTag+string(node.LinkData.Destination)+linkCloseTag) - } - case blackfriday.Image: - // ignore images - walkAction = blackfriday.SkipChildren - case blackfriday.Code: - out(w, codespanTag) - escapeSpecialChars(w, node.Literal) - out(w, codespanCloseTag) - case blackfriday.Document: - break - case blackfriday.Paragraph: - // roff .PP markers break lists - if r.listDepth > 0 { - return blackfriday.GoToNext - } - if entering { - out(w, paraTag) - } else { - out(w, crTag) - } - case blackfriday.BlockQuote: - if entering { - out(w, quoteTag) - } else { - out(w, quoteCloseTag) - } - case blackfriday.Heading: - r.handleHeading(w, node, entering) - case blackfriday.HorizontalRule: - out(w, hruleTag) - case blackfriday.List: - r.handleList(w, node, entering) - case blackfriday.Item: - r.handleItem(w, node, entering) - case blackfriday.CodeBlock: - out(w, codeTag) - escapeSpecialChars(w, node.Literal) - out(w, codeCloseTag) - case blackfriday.Table: - r.handleTable(w, node, entering) - case blackfriday.TableCell: - r.handleTableCell(w, node, entering) - case blackfriday.TableHead: - case blackfriday.TableBody: - case blackfriday.TableRow: - // no action as cell entries do all the nroff formatting - return blackfriday.GoToNext +func (r *roffRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) { + marker := out.Len() + + switch { + case marker == 0: + // This is the doc header + out.WriteString(".TH ") + case level == 1: + out.WriteString("\n\n.SH ") + case level == 2: + out.WriteString("\n.SH ") default: - fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String()) - } - return walkAction -} - -func (r *roffRenderer) handleText(w io.Writer, node *blackfriday.Node, entering bool) { - var ( - start, end string - ) - // handle special roff table cell text encapsulation - if node.Parent.Type == blackfriday.TableCell { - if len(node.Literal) > 30 { - start = tableCellStart - end = tableCellEnd - } else { - // end rows that aren't terminated by "tableCellEnd" with a cr if end of row - if node.Parent.Next == nil && !node.Parent.IsHeader { - end = crTag - } - } + out.WriteString("\n.SS ") } - out(w, start) - escapeSpecialChars(w, node.Literal) - out(w, end) -} - -func (r *roffRenderer) handleHeading(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - switch node.Level { - case 1: - if !r.firstHeader { - out(w, titleHeader) - r.firstHeader = true - break - } - out(w, topLevelHeader) - case 2: - out(w, secondLevelHdr) - default: - out(w, otherHeader) - } + + if !text() { + out.Truncate(marker) + return } } -func (r *roffRenderer) handleList(w io.Writer, node *blackfriday.Node, entering bool) { - openTag := listTag - closeTag := listCloseTag - if node.ListFlags&blackfriday.ListTypeDefinition != 0 { - // tags for definition lists handled within Item node - openTag = "" - closeTag = "" +func (r *roffRenderer) HRule(out *bytes.Buffer) { + out.WriteString("\n.ti 0\n\\l'\\n(.lu'\n") +} + +func (r *roffRenderer) List(out *bytes.Buffer, text func() bool, flags int) { + marker := out.Len() + r.ListCounters = append(r.ListCounters, 1) + out.WriteString("\n.RS\n") + if !text() { + out.Truncate(marker) + return } - if entering { - r.listDepth++ - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - r.listCounters = append(r.listCounters, 1) - } - out(w, openTag) + r.ListCounters = r.ListCounters[:len(r.ListCounters)-1] + out.WriteString("\n.RE\n") +} + +func (r *roffRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) { + if flags&blackfriday.LIST_TYPE_ORDERED != 0 { + out.WriteString(fmt.Sprintf(".IP \"%3d.\" 5\n", r.ListCounters[len(r.ListCounters)-1])) + r.ListCounters[len(r.ListCounters)-1]++ } else { - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - r.listCounters = r.listCounters[:len(r.listCounters)-1] - } - out(w, closeTag) - r.listDepth-- + out.WriteString(".IP \\(bu 2\n") + } + out.Write(text) + out.WriteString("\n") +} + +func (r *roffRenderer) Paragraph(out *bytes.Buffer, text func() bool) { + marker := out.Len() + out.WriteString("\n.PP\n") + if !text() { + out.Truncate(marker) + return + } + if marker != 0 { + out.WriteString("\n") } } -func (r *roffRenderer) handleItem(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - out(w, fmt.Sprintf(".IP \"%3d.\" 5\n", r.listCounters[len(r.listCounters)-1])) - r.listCounters[len(r.listCounters)-1]++ - } else if node.ListFlags&blackfriday.ListTypeDefinition != 0 { - // state machine for handling terms and following definitions - // since blackfriday does not distinguish them properly, nor - // does it seperate them into separate lists as it should - if !r.defineTerm { - out(w, arglistTag) - r.defineTerm = true - } else { - r.defineTerm = false - } - } else { - out(w, ".IP \\(bu 2\n") +func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { + out.WriteString("\n.TS\nallbox;\n") + + maxDelims := 0 + lines := strings.Split(strings.TrimRight(string(header), "\n")+"\n"+strings.TrimRight(string(body), "\n"), "\n") + for _, w := range lines { + curDelims := strings.Count(w, "\t") + if curDelims > maxDelims { + maxDelims = curDelims } - } else { - out(w, "\n") } + out.Write([]byte(strings.Repeat("l ", maxDelims+1) + "\n")) + out.Write([]byte(strings.Repeat("l ", maxDelims+1) + ".\n")) + out.Write(header) + if len(header) > 0 { + out.Write([]byte("\n")) + } + + out.Write(body) + out.WriteString("\n.TE\n") } -func (r *roffRenderer) handleTable(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - out(w, tableStart) - //call walker to count cells (and rows?) so format section can be produced - columns := countColumns(node) - out(w, strings.Repeat("l ", columns)+"\n") - out(w, strings.Repeat("l ", columns)+".\n") - } else { - out(w, tableEnd) +func (r *roffRenderer) TableRow(out *bytes.Buffer, text []byte) { + if out.Len() > 0 { + out.WriteString("\n") } + out.Write(text) } -func (r *roffRenderer) handleTableCell(w io.Writer, node *blackfriday.Node, entering bool) { - var ( - start, end string - ) - if node.IsHeader { - start = codespanTag - end = codespanCloseTag +func (r *roffRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { + if out.Len() > 0 { + out.WriteString("\t") } - if entering { - if node.Prev != nil && node.Prev.Type == blackfriday.TableCell { - out(w, "\t"+start) - } else { - out(w, start) - } - } else { - // need to carriage return if we are at the end of the header row - if node.IsHeader && node.Next == nil { - end = end + crTag - } - out(w, end) + if len(text) == 0 { + text = []byte{' '} } + out.Write([]byte("\\fB\\fC" + string(text) + "\\fR")) } -// because roff format requires knowing the column count before outputting any table -// data we need to walk a table tree and count the columns -func countColumns(node *blackfriday.Node) int { - var columns int - - node.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { - switch node.Type { - case blackfriday.TableRow: - if !entering { - return blackfriday.Terminate - } - case blackfriday.TableCell: - if entering { - columns++ - } - default: - } - return blackfriday.GoToNext - }) - return columns +func (r *roffRenderer) TableCell(out *bytes.Buffer, text []byte, align int) { + if out.Len() > 0 { + out.WriteString("\t") + } + if len(text) > 30 { + text = append([]byte("T{\n"), text...) + text = append(text, []byte("\nT}")...) + } + if len(text) == 0 { + text = []byte{' '} + } + out.Write(text) +} + +func (r *roffRenderer) Footnotes(out *bytes.Buffer, text func() bool) { + +} + +func (r *roffRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { + +} + +func (r *roffRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { + out.WriteString("\n\\[la]") + out.Write(link) + out.WriteString("\\[ra]") +} + +func (r *roffRenderer) CodeSpan(out *bytes.Buffer, text []byte) { + out.WriteString("\\fB\\fC") + escapeSpecialChars(out, text) + out.WriteString("\\fR") +} + +func (r *roffRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\fB") + out.Write(text) + out.WriteString("\\fP") } -func out(w io.Writer, output string) { - io.WriteString(w, output) // nolint: errcheck +func (r *roffRenderer) Emphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\fI") + out.Write(text) + out.WriteString("\\fP") +} + +func (r *roffRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { +} + +func (r *roffRenderer) LineBreak(out *bytes.Buffer) { + out.WriteString("\n.br\n") +} + +func (r *roffRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { + out.Write(content) + r.AutoLink(out, link, 0) +} + +func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) { // nolint: golint + out.Write(tag) +} + +func (r *roffRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\s+2") + out.Write(text) + out.WriteString("\\s-2") +} + +func (r *roffRenderer) StrikeThrough(out *bytes.Buffer, text []byte) { +} + +func (r *roffRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { + +} + +func (r *roffRenderer) Entity(out *bytes.Buffer, entity []byte) { + out.WriteString(html.UnescapeString(string(entity))) +} + +func (r *roffRenderer) NormalText(out *bytes.Buffer, text []byte) { + escapeSpecialChars(out, text) +} + +func (r *roffRenderer) DocumentHeader(out *bytes.Buffer) { +} + +func (r *roffRenderer) DocumentFooter(out *bytes.Buffer) { } func needsBackslash(c byte) bool { @@ -318,11 +258,11 @@ func needsBackslash(c byte) bool { return false } -func escapeSpecialChars(w io.Writer, text []byte) { +func escapeSpecialChars(out *bytes.Buffer, text []byte) { for i := 0; i < len(text); i++ { // escape initial apostrophe or period if len(text) >= 1 && (text[0] == '\'' || text[0] == '.') { - out(w, "\\&") + out.WriteString("\\&") } // directly copy normal characters @@ -332,14 +272,14 @@ func escapeSpecialChars(w io.Writer, text []byte) { i++ } if i > org { - w.Write(text[org:i]) // nolint: errcheck + out.Write(text[org:i]) } // escape a character if i >= len(text) { break } - - w.Write([]byte{'\\', text[i]}) // nolint: errcheck + out.WriteByte('\\') + out.WriteByte(text[i]) } } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools deleted file mode 100755 index 8efe701e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -go get -u github.com/alecthomas/gometalinter -gometalinter --install >/dev/null -go get -u github.com/golang/dep/cmd/dep diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor deleted file mode 100755 index ef29b4cd..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -dep ensure - -DIFF_PATH="vendor/" -DIFF=$(git status --porcelain -- "$DIFF_PATH") - -if [ "$DIFF" ]; then - echo - echo "These files were modified:" - echo - echo "$DIFF" - echo - exit 1 -else - echo "$DIFF_PATH is correct" -fi diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md deleted file mode 100644 index 2e0db355..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md +++ /dev/null @@ -1,283 +0,0 @@ -Blackfriday [![Build Status](https://travis-ci.org/russross/blackfriday.svg?branch=master)](https://travis-ci.org/russross/blackfriday) -=========== - -Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It -is paranoid about its input (so you can safely feed it user-supplied -data), it is fast, it supports common extensions (tables, smart -punctuation substitutions, etc.), and it is safe for all utf-8 -(unicode) input. - -HTML output is currently supported, along with Smartypants -extensions. - -It started as a translation from C of [Sundown][3]. - - -Installation ------------- - -Blackfriday is compatible with any modern Go release. With Go 1.7 and git -installed: - - go get gopkg.in/russross/blackfriday.v2 - -will download, compile, and install the package into your `$GOPATH` -directory hierarchy. Alternatively, you can achieve the same if you -import it into a project: - - import "gopkg.in/russross/blackfriday.v2" - -and `go get` without parameters. - - -Versions --------- - -Currently maintained and recommended version of Blackfriday is `v2`. It's being -developed on its own branch: https://github.com/russross/blackfriday/v2. You -should install and import it via [gopkg.in][6] at -`gopkg.in/russross/blackfriday.v2`. - -Version 2 offers a number of improvements over v1: - -* Cleaned up API -* A separate call to [`Parse`][4], which produces an abstract syntax tree for - the document -* Latest bug fixes -* Flexibility to easily add your own rendering extensions - -Potential drawbacks: - -* Our benchmarks show v2 to be slightly slower than v1. Currently in the - ballpark of around 15%. -* API breakage. If you can't afford modifying your code to adhere to the new API - and don't care too much about the new features, v2 is probably not for you. -* Several bug fixes are trailing behind and still need to be forward-ported to - v2. See issue [#348](https://github.com/russross/blackfriday/issues/348) for - tracking. - -Usage ------ - -For the most sensible markdown processing, it is as simple as getting your input -into a byte slice and calling: - -```go -output := blackfriday.Run(input) -``` - -Your input will be parsed and the output rendered with a set of most popular -extensions enabled. If you want the most basic feature set, corresponding with -the bare Markdown specification, use: - -```go -output := blackfriday.Run(input, blackfriday.WithNoExtensions()) -``` - -### Sanitize untrusted content - -Blackfriday itself does nothing to protect against malicious content. If you are -dealing with user-supplied markdown, we recommend running Blackfriday's output -through HTML sanitizer such as [Bluemonday][5]. - -Here's an example of simple usage of Blackfriday together with Bluemonday: - -```go -import ( - "github.com/microcosm-cc/bluemonday" - "github.com/russross/blackfriday" -) - -// ... -unsafe := blackfriday.Run(input) -html := bluemonday.UGCPolicy().SanitizeBytes(unsafe) -``` - -### Custom options - -If you want to customize the set of options, use `blackfriday.WithExtensions`, -`blackfriday.WithRenderer` and `blackfriday.WithRefOverride`. - -You can also check out `blackfriday-tool` for a more complete example -of how to use it. Download and install it using: - - go get github.com/russross/blackfriday-tool - -This is a simple command-line tool that allows you to process a -markdown file using a standalone program. You can also browse the -source directly on github if you are just looking for some example -code: - -* - -Note that if you have not already done so, installing -`blackfriday-tool` will be sufficient to download and install -blackfriday in addition to the tool itself. The tool binary will be -installed in `$GOPATH/bin`. This is a statically-linked binary that -can be copied to wherever you need it without worrying about -dependencies and library versions. - - -Features --------- - -All features of Sundown are supported, including: - -* **Compatibility**. The Markdown v1.0.3 test suite passes with - the `--tidy` option. Without `--tidy`, the differences are - mostly in whitespace and entity escaping, where blackfriday is - more consistent and cleaner. - -* **Common extensions**, including table support, fenced code - blocks, autolinks, strikethroughs, non-strict emphasis, etc. - -* **Safety**. Blackfriday is paranoid when parsing, making it safe - to feed untrusted user input without fear of bad things - happening. The test suite stress tests this and there are no - known inputs that make it crash. If you find one, please let me - know and send me the input that does it. - - NOTE: "safety" in this context means *runtime safety only*. In order to - protect yourself against JavaScript injection in untrusted content, see - [this example](https://github.com/russross/blackfriday#sanitize-untrusted-content). - -* **Fast processing**. It is fast enough to render on-demand in - most web applications without having to cache the output. - -* **Thread safety**. You can run multiple parsers in different - goroutines without ill effect. There is no dependence on global - shared state. - -* **Minimal dependencies**. Blackfriday only depends on standard - library packages in Go. The source code is pretty - self-contained, so it is easy to add to any project, including - Google App Engine projects. - -* **Standards compliant**. Output successfully validates using the - W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional. - - -Extensions ----------- - -In addition to the standard markdown syntax, this package -implements the following extensions: - -* **Intra-word emphasis supression**. The `_` character is - commonly used inside words when discussing code, so having - markdown interpret it as an emphasis command is usually the - wrong thing. Blackfriday lets you treat all emphasis markers as - normal characters when they occur inside a word. - -* **Tables**. Tables can be created by drawing them in the input - using a simple syntax: - - ``` - Name | Age - --------|------ - Bob | 27 - Alice | 23 - ``` - -* **Fenced code blocks**. In addition to the normal 4-space - indentation to mark code blocks, you can explicitly mark them - and supply a language (to make syntax highlighting simple). Just - mark it like this: - - ```go - func getTrue() bool { - return true - } - ``` - - You can use 3 or more backticks to mark the beginning of the - block, and the same number to mark the end of the block. - -* **Definition lists**. A simple definition list is made of a single-line - term followed by a colon and the definition for that term. - - Cat - : Fluffy animal everyone likes - - Internet - : Vector of transmission for pictures of cats - - Terms must be separated from the previous definition by a blank line. - -* **Footnotes**. A marker in the text that will become a superscript number; - a footnote definition that will be placed in a list of footnotes at the - end of the document. A footnote looks like this: - - This is a footnote.[^1] - - [^1]: the footnote text. - -* **Autolinking**. Blackfriday can find URLs that have not been - explicitly marked as links and turn them into links. - -* **Strikethrough**. Use two tildes (`~~`) to mark text that - should be crossed out. - -* **Hard line breaks**. With this extension enabled newlines in the input - translate into line breaks in the output. This extension is off by default. - -* **Smart quotes**. Smartypants-style punctuation substitution is - supported, turning normal double- and single-quote marks into - curly quotes, etc. - -* **LaTeX-style dash parsing** is an additional option, where `--` - is translated into `–`, and `---` is translated into - `—`. This differs from most smartypants processors, which - turn a single hyphen into an ndash and a double hyphen into an - mdash. - -* **Smart fractions**, where anything that looks like a fraction - is translated into suitable HTML (instead of just a few special - cases like most smartypant processors). For example, `4/5` - becomes `45`, which renders as - 45. - - -Other renderers ---------------- - -Blackfriday is structured to allow alternative rendering engines. Here -are a few of note: - -* [github_flavored_markdown](https://godoc.org/github.com/shurcooL/github_flavored_markdown): - provides a GitHub Flavored Markdown renderer with fenced code block - highlighting, clickable heading anchor links. - - It's not customizable, and its goal is to produce HTML output - equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode), - except the rendering is performed locally. - -* [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt, - but for markdown. - -* [LaTeX output](https://bitbucket.org/ambrevar/blackfriday-latex): - renders output as LaTeX. - - -Todo ----- - -* More unit testing -* Improve unicode support. It does not understand all unicode - rules (about what constitutes a letter, a punctuation symbol, - etc.), so it may fail to detect word boundaries correctly in - some instances. It is safe on all utf-8 input. - - -License -------- - -[Blackfriday is distributed under the Simplified BSD License](LICENSE.txt) - - - [1]: https://daringfireball.net/projects/markdown/ "Markdown" - [2]: https://golang.org/ "Go Language" - [3]: https://github.com/vmg/sundown "Sundown" - [4]: https://godoc.org/gopkg.in/russross/blackfriday.v2#Parse "Parse func" - [5]: https://github.com/microcosm-cc/bluemonday "Bluemonday" - [6]: https://labix.org/gopkg.in "gopkg.in" diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go deleted file mode 100644 index d7da33f2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go +++ /dev/null @@ -1,1549 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// Functions to parse block-level elements. -// - -package blackfriday - -import ( - "bytes" - "html" - "regexp" - - "github.com/shurcooL/sanitized_anchor_name" -) - -const ( - charEntity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});" - escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]" -) - -var ( - reBackslashOrAmp = regexp.MustCompile("[\\&]") - reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity) -) - -// Parse block-level data. -// Note: this function and many that it calls assume that -// the input buffer ends with a newline. -func (p *Markdown) block(data []byte) { - // this is called recursively: enforce a maximum depth - if p.nesting >= p.maxNesting { - return - } - p.nesting++ - - // parse out one block-level construct at a time - for len(data) > 0 { - // prefixed heading: - // - // # Heading 1 - // ## Heading 2 - // ... - // ###### Heading 6 - if p.isPrefixHeading(data) { - data = data[p.prefixHeading(data):] - continue - } - - // block of preformatted HTML: - // - //
- // ... - //
- if data[0] == '<' { - if i := p.html(data, true); i > 0 { - data = data[i:] - continue - } - } - - // title block - // - // % stuff - // % more stuff - // % even more stuff - if p.extensions&Titleblock != 0 { - if data[0] == '%' { - if i := p.titleBlock(data, true); i > 0 { - data = data[i:] - continue - } - } - } - - // blank lines. note: returns the # of bytes to skip - if i := p.isEmpty(data); i > 0 { - data = data[i:] - continue - } - - // indented code block: - // - // func max(a, b int) int { - // if a > b { - // return a - // } - // return b - // } - if p.codePrefix(data) > 0 { - data = data[p.code(data):] - continue - } - - // fenced code block: - // - // ``` go - // func fact(n int) int { - // if n <= 1 { - // return n - // } - // return n * fact(n-1) - // } - // ``` - if p.extensions&FencedCode != 0 { - if i := p.fencedCodeBlock(data, true); i > 0 { - data = data[i:] - continue - } - } - - // horizontal rule: - // - // ------ - // or - // ****** - // or - // ______ - if p.isHRule(data) { - p.addBlock(HorizontalRule, nil) - var i int - for i = 0; i < len(data) && data[i] != '\n'; i++ { - } - data = data[i:] - continue - } - - // block quote: - // - // > A big quote I found somewhere - // > on the web - if p.quotePrefix(data) > 0 { - data = data[p.quote(data):] - continue - } - - // table: - // - // Name | Age | Phone - // ------|-----|--------- - // Bob | 31 | 555-1234 - // Alice | 27 | 555-4321 - if p.extensions&Tables != 0 { - if i := p.table(data); i > 0 { - data = data[i:] - continue - } - } - - // an itemized/unordered list: - // - // * Item 1 - // * Item 2 - // - // also works with + or - - if p.uliPrefix(data) > 0 { - data = data[p.list(data, 0):] - continue - } - - // a numbered/ordered list: - // - // 1. Item 1 - // 2. Item 2 - if p.oliPrefix(data) > 0 { - data = data[p.list(data, ListTypeOrdered):] - continue - } - - // definition lists: - // - // Term 1 - // : Definition a - // : Definition b - // - // Term 2 - // : Definition c - if p.extensions&DefinitionLists != 0 { - if p.dliPrefix(data) > 0 { - data = data[p.list(data, ListTypeDefinition):] - continue - } - } - - // anything else must look like a normal paragraph - // note: this finds underlined headings, too - data = data[p.paragraph(data):] - } - - p.nesting-- -} - -func (p *Markdown) addBlock(typ NodeType, content []byte) *Node { - p.closeUnmatchedBlocks() - container := p.addChild(typ, 0) - container.content = content - return container -} - -func (p *Markdown) isPrefixHeading(data []byte) bool { - if data[0] != '#' { - return false - } - - if p.extensions&SpaceHeadings != 0 { - level := 0 - for level < 6 && level < len(data) && data[level] == '#' { - level++ - } - if level == len(data) || data[level] != ' ' { - return false - } - } - return true -} - -func (p *Markdown) prefixHeading(data []byte) int { - level := 0 - for level < 6 && level < len(data) && data[level] == '#' { - level++ - } - i := skipChar(data, level, ' ') - end := skipUntilChar(data, i, '\n') - skip := end - id := "" - if p.extensions&HeadingIDs != 0 { - j, k := 0, 0 - // find start/end of heading id - for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ { - } - for k = j + 1; k < end && data[k] != '}'; k++ { - } - // extract heading id iff found - if j < end && k < end { - id = string(data[j+2 : k]) - end = j - skip = k + 1 - for end > 0 && data[end-1] == ' ' { - end-- - } - } - } - for end > 0 && data[end-1] == '#' { - if isBackslashEscaped(data, end-1) { - break - } - end-- - } - for end > 0 && data[end-1] == ' ' { - end-- - } - if end > i { - if id == "" && p.extensions&AutoHeadingIDs != 0 { - id = sanitized_anchor_name.Create(string(data[i:end])) - } - block := p.addBlock(Heading, data[i:end]) - block.HeadingID = id - block.Level = level - } - return skip -} - -func (p *Markdown) isUnderlinedHeading(data []byte) int { - // test of level 1 heading - if data[0] == '=' { - i := skipChar(data, 1, '=') - i = skipChar(data, i, ' ') - if i < len(data) && data[i] == '\n' { - return 1 - } - return 0 - } - - // test of level 2 heading - if data[0] == '-' { - i := skipChar(data, 1, '-') - i = skipChar(data, i, ' ') - if i < len(data) && data[i] == '\n' { - return 2 - } - return 0 - } - - return 0 -} - -func (p *Markdown) titleBlock(data []byte, doRender bool) int { - if data[0] != '%' { - return 0 - } - splitData := bytes.Split(data, []byte("\n")) - var i int - for idx, b := range splitData { - if !bytes.HasPrefix(b, []byte("%")) { - i = idx // - 1 - break - } - } - - data = bytes.Join(splitData[0:i], []byte("\n")) - consumed := len(data) - data = bytes.TrimPrefix(data, []byte("% ")) - data = bytes.Replace(data, []byte("\n% "), []byte("\n"), -1) - block := p.addBlock(Heading, data) - block.Level = 1 - block.IsTitleblock = true - - return consumed -} - -func (p *Markdown) html(data []byte, doRender bool) int { - var i, j int - - // identify the opening tag - if data[0] != '<' { - return 0 - } - curtag, tagfound := p.htmlFindTag(data[1:]) - - // handle special cases - if !tagfound { - // check for an HTML comment - if size := p.htmlComment(data, doRender); size > 0 { - return size - } - - // check for an
tag - if size := p.htmlHr(data, doRender); size > 0 { - return size - } - - // no special case recognized - return 0 - } - - // look for an unindented matching closing tag - // followed by a blank line - found := false - /* - closetag := []byte("\n") - j = len(curtag) + 1 - for !found { - // scan for a closing tag at the beginning of a line - if skip := bytes.Index(data[j:], closetag); skip >= 0 { - j += skip + len(closetag) - } else { - break - } - - // see if it is the only thing on the line - if skip := p.isEmpty(data[j:]); skip > 0 { - // see if it is followed by a blank line/eof - j += skip - if j >= len(data) { - found = true - i = j - } else { - if skip := p.isEmpty(data[j:]); skip > 0 { - j += skip - found = true - i = j - } - } - } - } - */ - - // if not found, try a second pass looking for indented match - // but not if tag is "ins" or "del" (following original Markdown.pl) - if !found && curtag != "ins" && curtag != "del" { - i = 1 - for i < len(data) { - i++ - for i < len(data) && !(data[i-1] == '<' && data[i] == '/') { - i++ - } - - if i+2+len(curtag) >= len(data) { - break - } - - j = p.htmlFindEnd(curtag, data[i-1:]) - - if j > 0 { - i += j - 1 - found = true - break - } - } - } - - if !found { - return 0 - } - - // the end of the block has been found - if doRender { - // trim newlines - end := i - for end > 0 && data[end-1] == '\n' { - end-- - } - finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end])) - } - - return i -} - -func finalizeHTMLBlock(block *Node) { - block.Literal = block.content - block.content = nil -} - -// HTML comment, lax form -func (p *Markdown) htmlComment(data []byte, doRender bool) int { - i := p.inlineHTMLComment(data) - // needs to end with a blank line - if j := p.isEmpty(data[i:]); j > 0 { - size := i + j - if doRender { - // trim trailing newlines - end := size - for end > 0 && data[end-1] == '\n' { - end-- - } - block := p.addBlock(HTMLBlock, data[:end]) - finalizeHTMLBlock(block) - } - return size - } - return 0 -} - -// HR, which is the only self-closing block tag considered -func (p *Markdown) htmlHr(data []byte, doRender bool) int { - if len(data) < 4 { - return 0 - } - if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') { - return 0 - } - if data[3] != ' ' && data[3] != '/' && data[3] != '>' { - // not an
tag after all; at least not a valid one - return 0 - } - i := 3 - for i < len(data) && data[i] != '>' && data[i] != '\n' { - i++ - } - if i < len(data) && data[i] == '>' { - i++ - if j := p.isEmpty(data[i:]); j > 0 { - size := i + j - if doRender { - // trim newlines - end := size - for end > 0 && data[end-1] == '\n' { - end-- - } - finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end])) - } - return size - } - } - return 0 -} - -func (p *Markdown) htmlFindTag(data []byte) (string, bool) { - i := 0 - for i < len(data) && isalnum(data[i]) { - i++ - } - key := string(data[:i]) - if _, ok := blockTags[key]; ok { - return key, true - } - return "", false -} - -func (p *Markdown) htmlFindEnd(tag string, data []byte) int { - // assume data[0] == '<' && data[1] == '/' already tested - if tag == "hr" { - return 2 - } - // check if tag is a match - closetag := []byte("") - if !bytes.HasPrefix(data, closetag) { - return 0 - } - i := len(closetag) - - // check that the rest of the line is blank - skip := 0 - if skip = p.isEmpty(data[i:]); skip == 0 { - return 0 - } - i += skip - skip = 0 - - if i >= len(data) { - return i - } - - if p.extensions&LaxHTMLBlocks != 0 { - return i - } - if skip = p.isEmpty(data[i:]); skip == 0 { - // following line must be blank - return 0 - } - - return i + skip -} - -func (*Markdown) isEmpty(data []byte) int { - // it is okay to call isEmpty on an empty buffer - if len(data) == 0 { - return 0 - } - - var i int - for i = 0; i < len(data) && data[i] != '\n'; i++ { - if data[i] != ' ' && data[i] != '\t' { - return 0 - } - } - if i < len(data) && data[i] == '\n' { - i++ - } - return i -} - -func (*Markdown) isHRule(data []byte) bool { - i := 0 - - // skip up to three spaces - for i < 3 && data[i] == ' ' { - i++ - } - - // look at the hrule char - if data[i] != '*' && data[i] != '-' && data[i] != '_' { - return false - } - c := data[i] - - // the whole line must be the char or whitespace - n := 0 - for i < len(data) && data[i] != '\n' { - switch { - case data[i] == c: - n++ - case data[i] != ' ': - return false - } - i++ - } - - return n >= 3 -} - -// isFenceLine checks if there's a fence line (e.g., ``` or ``` go) at the beginning of data, -// and returns the end index if so, or 0 otherwise. It also returns the marker found. -// If syntax is not nil, it gets set to the syntax specified in the fence line. -func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker string) { - i, size := 0, 0 - - // skip up to three spaces - for i < len(data) && i < 3 && data[i] == ' ' { - i++ - } - - // check for the marker characters: ~ or ` - if i >= len(data) { - return 0, "" - } - if data[i] != '~' && data[i] != '`' { - return 0, "" - } - - c := data[i] - - // the whole line must be the same char or whitespace - for i < len(data) && data[i] == c { - size++ - i++ - } - - // the marker char must occur at least 3 times - if size < 3 { - return 0, "" - } - marker = string(data[i-size : i]) - - // if this is the end marker, it must match the beginning marker - if oldmarker != "" && marker != oldmarker { - return 0, "" - } - - // TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here - // into one, always get the syntax, and discard it if the caller doesn't care. - if syntax != nil { - syn := 0 - i = skipChar(data, i, ' ') - - if i >= len(data) { - if i == len(data) { - return i, marker - } - return 0, "" - } - - syntaxStart := i - - if data[i] == '{' { - i++ - syntaxStart++ - - for i < len(data) && data[i] != '}' && data[i] != '\n' { - syn++ - i++ - } - - if i >= len(data) || data[i] != '}' { - return 0, "" - } - - // strip all whitespace at the beginning and the end - // of the {} block - for syn > 0 && isspace(data[syntaxStart]) { - syntaxStart++ - syn-- - } - - for syn > 0 && isspace(data[syntaxStart+syn-1]) { - syn-- - } - - i++ - } else { - for i < len(data) && !isspace(data[i]) { - syn++ - i++ - } - } - - *syntax = string(data[syntaxStart : syntaxStart+syn]) - } - - i = skipChar(data, i, ' ') - if i >= len(data) || data[i] != '\n' { - if i == len(data) { - return i, marker - } - return 0, "" - } - return i + 1, marker // Take newline into account. -} - -// fencedCodeBlock returns the end index if data contains a fenced code block at the beginning, -// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects. -// If doRender is true, a final newline is mandatory to recognize the fenced code block. -func (p *Markdown) fencedCodeBlock(data []byte, doRender bool) int { - var syntax string - beg, marker := isFenceLine(data, &syntax, "") - if beg == 0 || beg >= len(data) { - return 0 - } - - var work bytes.Buffer - work.Write([]byte(syntax)) - work.WriteByte('\n') - - for { - // safe to assume beg < len(data) - - // check for the end of the code block - fenceEnd, _ := isFenceLine(data[beg:], nil, marker) - if fenceEnd != 0 { - beg += fenceEnd - break - } - - // copy the current line - end := skipUntilChar(data, beg, '\n') + 1 - - // did we reach the end of the buffer without a closing marker? - if end >= len(data) { - return 0 - } - - // verbatim copy to the working buffer - if doRender { - work.Write(data[beg:end]) - } - beg = end - } - - if doRender { - block := p.addBlock(CodeBlock, work.Bytes()) // TODO: get rid of temp buffer - block.IsFenced = true - finalizeCodeBlock(block) - } - - return beg -} - -func unescapeChar(str []byte) []byte { - if str[0] == '\\' { - return []byte{str[1]} - } - return []byte(html.UnescapeString(string(str))) -} - -func unescapeString(str []byte) []byte { - if reBackslashOrAmp.Match(str) { - return reEntityOrEscapedChar.ReplaceAllFunc(str, unescapeChar) - } - return str -} - -func finalizeCodeBlock(block *Node) { - if block.IsFenced { - newlinePos := bytes.IndexByte(block.content, '\n') - firstLine := block.content[:newlinePos] - rest := block.content[newlinePos+1:] - block.Info = unescapeString(bytes.Trim(firstLine, "\n")) - block.Literal = rest - } else { - block.Literal = block.content - } - block.content = nil -} - -func (p *Markdown) table(data []byte) int { - table := p.addBlock(Table, nil) - i, columns := p.tableHeader(data) - if i == 0 { - p.tip = table.Parent - table.Unlink() - return 0 - } - - p.addBlock(TableBody, nil) - - for i < len(data) { - pipes, rowStart := 0, i - for ; i < len(data) && data[i] != '\n'; i++ { - if data[i] == '|' { - pipes++ - } - } - - if pipes == 0 { - i = rowStart - break - } - - // include the newline in data sent to tableRow - if i < len(data) && data[i] == '\n' { - i++ - } - p.tableRow(data[rowStart:i], columns, false) - } - - return i -} - -// check if the specified position is preceded by an odd number of backslashes -func isBackslashEscaped(data []byte, i int) bool { - backslashes := 0 - for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' { - backslashes++ - } - return backslashes&1 == 1 -} - -func (p *Markdown) tableHeader(data []byte) (size int, columns []CellAlignFlags) { - i := 0 - colCount := 1 - for i = 0; i < len(data) && data[i] != '\n'; i++ { - if data[i] == '|' && !isBackslashEscaped(data, i) { - colCount++ - } - } - - // doesn't look like a table header - if colCount == 1 { - return - } - - // include the newline in the data sent to tableRow - j := i - if j < len(data) && data[j] == '\n' { - j++ - } - header := data[:j] - - // column count ignores pipes at beginning or end of line - if data[0] == '|' { - colCount-- - } - if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) { - colCount-- - } - - columns = make([]CellAlignFlags, colCount) - - // move on to the header underline - i++ - if i >= len(data) { - return - } - - if data[i] == '|' && !isBackslashEscaped(data, i) { - i++ - } - i = skipChar(data, i, ' ') - - // each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3 - // and trailing | optional on last column - col := 0 - for i < len(data) && data[i] != '\n' { - dashes := 0 - - if data[i] == ':' { - i++ - columns[col] |= TableAlignmentLeft - dashes++ - } - for i < len(data) && data[i] == '-' { - i++ - dashes++ - } - if i < len(data) && data[i] == ':' { - i++ - columns[col] |= TableAlignmentRight - dashes++ - } - for i < len(data) && data[i] == ' ' { - i++ - } - if i == len(data) { - return - } - // end of column test is messy - switch { - case dashes < 3: - // not a valid column - return - - case data[i] == '|' && !isBackslashEscaped(data, i): - // marker found, now skip past trailing whitespace - col++ - i++ - for i < len(data) && data[i] == ' ' { - i++ - } - - // trailing junk found after last column - if col >= colCount && i < len(data) && data[i] != '\n' { - return - } - - case (data[i] != '|' || isBackslashEscaped(data, i)) && col+1 < colCount: - // something else found where marker was required - return - - case data[i] == '\n': - // marker is optional for the last column - col++ - - default: - // trailing junk found after last column - return - } - } - if col != colCount { - return - } - - p.addBlock(TableHead, nil) - p.tableRow(header, columns, true) - size = i - if size < len(data) && data[size] == '\n' { - size++ - } - return -} - -func (p *Markdown) tableRow(data []byte, columns []CellAlignFlags, header bool) { - p.addBlock(TableRow, nil) - i, col := 0, 0 - - if data[i] == '|' && !isBackslashEscaped(data, i) { - i++ - } - - for col = 0; col < len(columns) && i < len(data); col++ { - for i < len(data) && data[i] == ' ' { - i++ - } - - cellStart := i - - for i < len(data) && (data[i] != '|' || isBackslashEscaped(data, i)) && data[i] != '\n' { - i++ - } - - cellEnd := i - - // skip the end-of-cell marker, possibly taking us past end of buffer - i++ - - for cellEnd > cellStart && cellEnd-1 < len(data) && data[cellEnd-1] == ' ' { - cellEnd-- - } - - cell := p.addBlock(TableCell, data[cellStart:cellEnd]) - cell.IsHeader = header - cell.Align = columns[col] - } - - // pad it out with empty columns to get the right number - for ; col < len(columns); col++ { - cell := p.addBlock(TableCell, nil) - cell.IsHeader = header - cell.Align = columns[col] - } - - // silently ignore rows with too many cells -} - -// returns blockquote prefix length -func (p *Markdown) quotePrefix(data []byte) int { - i := 0 - for i < 3 && i < len(data) && data[i] == ' ' { - i++ - } - if i < len(data) && data[i] == '>' { - if i+1 < len(data) && data[i+1] == ' ' { - return i + 2 - } - return i + 1 - } - return 0 -} - -// blockquote ends with at least one blank line -// followed by something without a blockquote prefix -func (p *Markdown) terminateBlockquote(data []byte, beg, end int) bool { - if p.isEmpty(data[beg:]) <= 0 { - return false - } - if end >= len(data) { - return true - } - return p.quotePrefix(data[end:]) == 0 && p.isEmpty(data[end:]) == 0 -} - -// parse a blockquote fragment -func (p *Markdown) quote(data []byte) int { - block := p.addBlock(BlockQuote, nil) - var raw bytes.Buffer - beg, end := 0, 0 - for beg < len(data) { - end = beg - // Step over whole lines, collecting them. While doing that, check for - // fenced code and if one's found, incorporate it altogether, - // irregardless of any contents inside it - for end < len(data) && data[end] != '\n' { - if p.extensions&FencedCode != 0 { - if i := p.fencedCodeBlock(data[end:], false); i > 0 { - // -1 to compensate for the extra end++ after the loop: - end += i - 1 - break - } - } - end++ - } - if end < len(data) && data[end] == '\n' { - end++ - } - if pre := p.quotePrefix(data[beg:]); pre > 0 { - // skip the prefix - beg += pre - } else if p.terminateBlockquote(data, beg, end) { - break - } - // this line is part of the blockquote - raw.Write(data[beg:end]) - beg = end - } - p.block(raw.Bytes()) - p.finalize(block) - return end -} - -// returns prefix length for block code -func (p *Markdown) codePrefix(data []byte) int { - if len(data) >= 1 && data[0] == '\t' { - return 1 - } - if len(data) >= 4 && data[0] == ' ' && data[1] == ' ' && data[2] == ' ' && data[3] == ' ' { - return 4 - } - return 0 -} - -func (p *Markdown) code(data []byte) int { - var work bytes.Buffer - - i := 0 - for i < len(data) { - beg := i - for i < len(data) && data[i] != '\n' { - i++ - } - if i < len(data) && data[i] == '\n' { - i++ - } - - blankline := p.isEmpty(data[beg:i]) > 0 - if pre := p.codePrefix(data[beg:i]); pre > 0 { - beg += pre - } else if !blankline { - // non-empty, non-prefixed line breaks the pre - i = beg - break - } - - // verbatim copy to the working buffer - if blankline { - work.WriteByte('\n') - } else { - work.Write(data[beg:i]) - } - } - - // trim all the \n off the end of work - workbytes := work.Bytes() - eol := len(workbytes) - for eol > 0 && workbytes[eol-1] == '\n' { - eol-- - } - if eol != len(workbytes) { - work.Truncate(eol) - } - - work.WriteByte('\n') - - block := p.addBlock(CodeBlock, work.Bytes()) // TODO: get rid of temp buffer - block.IsFenced = false - finalizeCodeBlock(block) - - return i -} - -// returns unordered list item prefix -func (p *Markdown) uliPrefix(data []byte) int { - i := 0 - // start with up to 3 spaces - for i < len(data) && i < 3 && data[i] == ' ' { - i++ - } - if i >= len(data)-1 { - return 0 - } - // need one of {'*', '+', '-'} followed by a space or a tab - if (data[i] != '*' && data[i] != '+' && data[i] != '-') || - (data[i+1] != ' ' && data[i+1] != '\t') { - return 0 - } - return i + 2 -} - -// returns ordered list item prefix -func (p *Markdown) oliPrefix(data []byte) int { - i := 0 - - // start with up to 3 spaces - for i < 3 && i < len(data) && data[i] == ' ' { - i++ - } - - // count the digits - start := i - for i < len(data) && data[i] >= '0' && data[i] <= '9' { - i++ - } - if start == i || i >= len(data)-1 { - return 0 - } - - // we need >= 1 digits followed by a dot and a space or a tab - if data[i] != '.' || !(data[i+1] == ' ' || data[i+1] == '\t') { - return 0 - } - return i + 2 -} - -// returns definition list item prefix -func (p *Markdown) dliPrefix(data []byte) int { - if len(data) < 2 { - return 0 - } - i := 0 - // need a ':' followed by a space or a tab - if data[i] != ':' || !(data[i+1] == ' ' || data[i+1] == '\t') { - return 0 - } - for i < len(data) && data[i] == ' ' { - i++ - } - return i + 2 -} - -// parse ordered or unordered list block -func (p *Markdown) list(data []byte, flags ListType) int { - i := 0 - flags |= ListItemBeginningOfList - block := p.addBlock(List, nil) - block.ListFlags = flags - block.Tight = true - - for i < len(data) { - skip := p.listItem(data[i:], &flags) - if flags&ListItemContainsBlock != 0 { - block.ListData.Tight = false - } - i += skip - if skip == 0 || flags&ListItemEndOfList != 0 { - break - } - flags &= ^ListItemBeginningOfList - } - - above := block.Parent - finalizeList(block) - p.tip = above - return i -} - -// Returns true if block ends with a blank line, descending if needed -// into lists and sublists. -func endsWithBlankLine(block *Node) bool { - // TODO: figure this out. Always false now. - for block != nil { - //if block.lastLineBlank { - //return true - //} - t := block.Type - if t == List || t == Item { - block = block.LastChild - } else { - break - } - } - return false -} - -func finalizeList(block *Node) { - block.open = false - item := block.FirstChild - for item != nil { - // check for non-final list item ending with blank line: - if endsWithBlankLine(item) && item.Next != nil { - block.ListData.Tight = false - break - } - // recurse into children of list item, to see if there are spaces - // between any of them: - subItem := item.FirstChild - for subItem != nil { - if endsWithBlankLine(subItem) && (item.Next != nil || subItem.Next != nil) { - block.ListData.Tight = false - break - } - subItem = subItem.Next - } - item = item.Next - } -} - -// Parse a single list item. -// Assumes initial prefix is already removed if this is a sublist. -func (p *Markdown) listItem(data []byte, flags *ListType) int { - // keep track of the indentation of the first line - itemIndent := 0 - if data[0] == '\t' { - itemIndent += 4 - } else { - for itemIndent < 3 && data[itemIndent] == ' ' { - itemIndent++ - } - } - - var bulletChar byte = '*' - i := p.uliPrefix(data) - if i == 0 { - i = p.oliPrefix(data) - } else { - bulletChar = data[i-2] - } - if i == 0 { - i = p.dliPrefix(data) - // reset definition term flag - if i > 0 { - *flags &= ^ListTypeTerm - } - } - if i == 0 { - // if in definition list, set term flag and continue - if *flags&ListTypeDefinition != 0 { - *flags |= ListTypeTerm - } else { - return 0 - } - } - - // skip leading whitespace on first line - for i < len(data) && data[i] == ' ' { - i++ - } - - // find the end of the line - line := i - for i > 0 && i < len(data) && data[i-1] != '\n' { - i++ - } - - // get working buffer - var raw bytes.Buffer - - // put the first line into the working buffer - raw.Write(data[line:i]) - line = i - - // process the following lines - containsBlankLine := false - sublist := 0 - -gatherlines: - for line < len(data) { - i++ - - // find the end of this line - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // if it is an empty line, guess that it is part of this item - // and move on to the next line - if p.isEmpty(data[line:i]) > 0 { - containsBlankLine = true - line = i - continue - } - - // calculate the indentation - indent := 0 - indentIndex := 0 - if data[line] == '\t' { - indentIndex++ - indent += 4 - } else { - for indent < 4 && line+indent < i && data[line+indent] == ' ' { - indent++ - indentIndex++ - } - } - - chunk := data[line+indentIndex : i] - - // evaluate how this line fits in - switch { - // is this a nested list item? - case (p.uliPrefix(chunk) > 0 && !p.isHRule(chunk)) || - p.oliPrefix(chunk) > 0 || - p.dliPrefix(chunk) > 0: - - if containsBlankLine { - *flags |= ListItemContainsBlock - } - - // to be a nested list, it must be indented more - // if not, it is the next item in the same list - if indent <= itemIndent { - break gatherlines - } - - // is this the first item in the nested list? - if sublist == 0 { - sublist = raw.Len() - } - - // is this a nested prefix heading? - case p.isPrefixHeading(chunk): - // if the heading is not indented, it is not nested in the list - // and thus ends the list - if containsBlankLine && indent < 4 { - *flags |= ListItemEndOfList - break gatherlines - } - *flags |= ListItemContainsBlock - - // anything following an empty line is only part - // of this item if it is indented 4 spaces - // (regardless of the indentation of the beginning of the item) - case containsBlankLine && indent < 4: - if *flags&ListTypeDefinition != 0 && i < len(data)-1 { - // is the next item still a part of this list? - next := i - for next < len(data) && data[next] != '\n' { - next++ - } - for next < len(data)-1 && data[next] == '\n' { - next++ - } - if i < len(data)-1 && data[i] != ':' && data[next] != ':' { - *flags |= ListItemEndOfList - } - } else { - *flags |= ListItemEndOfList - } - break gatherlines - - // a blank line means this should be parsed as a block - case containsBlankLine: - raw.WriteByte('\n') - *flags |= ListItemContainsBlock - } - - // if this line was preceded by one or more blanks, - // re-introduce the blank into the buffer - if containsBlankLine { - containsBlankLine = false - raw.WriteByte('\n') - } - - // add the line into the working buffer without prefix - raw.Write(data[line+indentIndex : i]) - - line = i - } - - rawBytes := raw.Bytes() - - block := p.addBlock(Item, nil) - block.ListFlags = *flags - block.Tight = false - block.BulletChar = bulletChar - block.Delimiter = '.' // Only '.' is possible in Markdown, but ')' will also be possible in CommonMark - - // render the contents of the list item - if *flags&ListItemContainsBlock != 0 && *flags&ListTypeTerm == 0 { - // intermediate render of block item, except for definition term - if sublist > 0 { - p.block(rawBytes[:sublist]) - p.block(rawBytes[sublist:]) - } else { - p.block(rawBytes) - } - } else { - // intermediate render of inline item - if sublist > 0 { - child := p.addChild(Paragraph, 0) - child.content = rawBytes[:sublist] - p.block(rawBytes[sublist:]) - } else { - child := p.addChild(Paragraph, 0) - child.content = rawBytes - } - } - return line -} - -// render a single paragraph that has already been parsed out -func (p *Markdown) renderParagraph(data []byte) { - if len(data) == 0 { - return - } - - // trim leading spaces - beg := 0 - for data[beg] == ' ' { - beg++ - } - - end := len(data) - // trim trailing newline - if data[len(data)-1] == '\n' { - end-- - } - - // trim trailing spaces - for end > beg && data[end-1] == ' ' { - end-- - } - - p.addBlock(Paragraph, data[beg:end]) -} - -func (p *Markdown) paragraph(data []byte) int { - // prev: index of 1st char of previous line - // line: index of 1st char of current line - // i: index of cursor/end of current line - var prev, line, i int - tabSize := TabSizeDefault - if p.extensions&TabSizeEight != 0 { - tabSize = TabSizeDouble - } - // keep going until we find something to mark the end of the paragraph - for i < len(data) { - // mark the beginning of the current line - prev = line - current := data[i:] - line = i - - // did we find a reference or a footnote? If so, end a paragraph - // preceding it and report that we have consumed up to the end of that - // reference: - if refEnd := isReference(p, current, tabSize); refEnd > 0 { - p.renderParagraph(data[:i]) - return i + refEnd - } - - // did we find a blank line marking the end of the paragraph? - if n := p.isEmpty(current); n > 0 { - // did this blank line followed by a definition list item? - if p.extensions&DefinitionLists != 0 { - if i < len(data)-1 && data[i+1] == ':' { - return p.list(data[prev:], ListTypeDefinition) - } - } - - p.renderParagraph(data[:i]) - return i + n - } - - // an underline under some text marks a heading, so our paragraph ended on prev line - if i > 0 { - if level := p.isUnderlinedHeading(current); level > 0 { - // render the paragraph - p.renderParagraph(data[:prev]) - - // ignore leading and trailing whitespace - eol := i - 1 - for prev < eol && data[prev] == ' ' { - prev++ - } - for eol > prev && data[eol-1] == ' ' { - eol-- - } - - id := "" - if p.extensions&AutoHeadingIDs != 0 { - id = sanitized_anchor_name.Create(string(data[prev:eol])) - } - - block := p.addBlock(Heading, data[prev:eol]) - block.Level = level - block.HeadingID = id - - // find the end of the underline - for i < len(data) && data[i] != '\n' { - i++ - } - return i - } - } - - // if the next line starts a block of HTML, then the paragraph ends here - if p.extensions&LaxHTMLBlocks != 0 { - if data[i] == '<' && p.html(current, false) > 0 { - // rewind to before the HTML block - p.renderParagraph(data[:i]) - return i - } - } - - // if there's a prefixed heading or a horizontal rule after this, paragraph is over - if p.isPrefixHeading(current) || p.isHRule(current) { - p.renderParagraph(data[:i]) - return i - } - - // if there's a fenced code block, paragraph is over - if p.extensions&FencedCode != 0 { - if p.fencedCodeBlock(current, false) > 0 { - p.renderParagraph(data[:i]) - return i - } - } - - // if there's a definition list item, prev line is a definition term - if p.extensions&DefinitionLists != 0 { - if p.dliPrefix(current) != 0 { - ret := p.list(data[prev:], ListTypeDefinition) - return ret - } - } - - // if there's a list after this, paragraph is over - if p.extensions&NoEmptyLineBeforeBlock != 0 { - if p.uliPrefix(current) != 0 || - p.oliPrefix(current) != 0 || - p.quotePrefix(current) != 0 || - p.codePrefix(current) != 0 { - p.renderParagraph(data[:i]) - return i - } - } - - // otherwise, scan to the beginning of the next line - nl := bytes.IndexByte(data[i:], '\n') - if nl >= 0 { - i += nl + 1 - } else { - i += len(data[i:]) - } - } - - p.renderParagraph(data[:i]) - return i -} - -func skipChar(data []byte, start int, char byte) int { - i := start - for i < len(data) && data[i] == char { - i++ - } - return i -} - -func skipUntilChar(text []byte, start int, char byte) int { - i := start - for i < len(text) && text[i] != char { - i++ - } - return i -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go deleted file mode 100644 index 5b3fa987..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Package blackfriday is a markdown processor. -// -// It translates plain text with simple formatting rules into an AST, which can -// then be further processed to HTML (provided by Blackfriday itself) or other -// formats (provided by the community). -// -// The simplest way to invoke Blackfriday is to call the Run function. It will -// take a text input and produce a text output in HTML (or other format). -// -// A slightly more sophisticated way to use Blackfriday is to create a Markdown -// processor and to call Parse, which returns a syntax tree for the input -// document. You can leverage Blackfriday's parsing for content extraction from -// markdown documents. You can assign a custom renderer and set various options -// to the Markdown processor. -// -// If you're interested in calling Blackfriday from command line, see -// https://github.com/russross/blackfriday-tool. -package blackfriday diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go deleted file mode 100644 index 6385f27c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go +++ /dev/null @@ -1,34 +0,0 @@ -package blackfriday - -import ( - "html" - "io" -) - -var htmlEscaper = [256][]byte{ - '&': []byte("&"), - '<': []byte("<"), - '>': []byte(">"), - '"': []byte("""), -} - -func escapeHTML(w io.Writer, s []byte) { - var start, end int - for end < len(s) { - escSeq := htmlEscaper[s[end]] - if escSeq != nil { - w.Write(s[start:end]) - w.Write(escSeq) - start = end + 1 - } - end++ - } - if start < len(s) && end <= len(s) { - w.Write(s[start:end]) - } -} - -func escLink(w io.Writer, text []byte) { - unesc := html.UnescapeString(string(text)) - escapeHTML(w, []byte(unesc)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go deleted file mode 100644 index 25fb185e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go +++ /dev/null @@ -1,940 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// -// HTML rendering backend -// -// - -package blackfriday - -import ( - "bytes" - "fmt" - "io" - "regexp" - "strings" -) - -// HTMLFlags control optional behavior of HTML renderer. -type HTMLFlags int - -// HTML renderer configuration options. -const ( - HTMLFlagsNone HTMLFlags = 0 - SkipHTML HTMLFlags = 1 << iota // Skip preformatted HTML blocks - SkipImages // Skip embedded images - SkipLinks // Skip all links - Safelink // Only link to trusted protocols - NofollowLinks // Only link with rel="nofollow" - NoreferrerLinks // Only link with rel="noreferrer" - HrefTargetBlank // Add a blank target - CompletePage // Generate a complete HTML page - UseXHTML // Generate XHTML output instead of HTML - FootnoteReturnLinks // Generate a link at the end of a footnote to return to the source - Smartypants // Enable smart punctuation substitutions - SmartypantsFractions // Enable smart fractions (with Smartypants) - SmartypantsDashes // Enable smart dashes (with Smartypants) - SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants) - SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering - SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants) - TOC // Generate a table of contents -) - -var ( - htmlTagRe = regexp.MustCompile("(?i)^" + htmlTag) -) - -const ( - htmlTag = "(?:" + openTag + "|" + closeTag + "|" + htmlComment + "|" + - processingInstruction + "|" + declaration + "|" + cdata + ")" - closeTag = "]" - openTag = "<" + tagName + attribute + "*" + "\\s*/?>" - attribute = "(?:" + "\\s+" + attributeName + attributeValueSpec + "?)" - attributeValue = "(?:" + unquotedValue + "|" + singleQuotedValue + "|" + doubleQuotedValue + ")" - attributeValueSpec = "(?:" + "\\s*=" + "\\s*" + attributeValue + ")" - attributeName = "[a-zA-Z_:][a-zA-Z0-9:._-]*" - cdata = "" - declaration = "]*>" - doubleQuotedValue = "\"[^\"]*\"" - htmlComment = "|" - processingInstruction = "[<][?].*?[?][>]" - singleQuotedValue = "'[^']*'" - tagName = "[A-Za-z][A-Za-z0-9-]*" - unquotedValue = "[^\"'=<>`\\x00-\\x20]+" -) - -// HTMLRendererParameters is a collection of supplementary parameters tweaking -// the behavior of various parts of HTML renderer. -type HTMLRendererParameters struct { - // Prepend this text to each relative URL. - AbsolutePrefix string - // Add this text to each footnote anchor, to ensure uniqueness. - FootnoteAnchorPrefix string - // Show this text inside the tag for a footnote return link, if the - // HTML_FOOTNOTE_RETURN_LINKS flag is enabled. If blank, the string - // [return] is used. - FootnoteReturnLinkContents string - // If set, add this text to the front of each Heading ID, to ensure - // uniqueness. - HeadingIDPrefix string - // If set, add this text to the back of each Heading ID, to ensure uniqueness. - HeadingIDSuffix string - - Title string // Document title (used if CompletePage is set) - CSS string // Optional CSS file URL (used if CompletePage is set) - Icon string // Optional icon file URL (used if CompletePage is set) - - Flags HTMLFlags // Flags allow customizing this renderer's behavior -} - -// HTMLRenderer is a type that implements the Renderer interface for HTML output. -// -// Do not create this directly, instead use the NewHTMLRenderer function. -type HTMLRenderer struct { - HTMLRendererParameters - - closeTag string // how to end singleton tags: either " />" or ">" - - // Track heading IDs to prevent ID collision in a single generation. - headingIDs map[string]int - - lastOutputLen int - disableTags int - - sr *SPRenderer -} - -const ( - xhtmlClose = " />" - htmlClose = ">" -) - -// NewHTMLRenderer creates and configures an HTMLRenderer object, which -// satisfies the Renderer interface. -func NewHTMLRenderer(params HTMLRendererParameters) *HTMLRenderer { - // configure the rendering engine - closeTag := htmlClose - if params.Flags&UseXHTML != 0 { - closeTag = xhtmlClose - } - - if params.FootnoteReturnLinkContents == "" { - params.FootnoteReturnLinkContents = `[return]` - } - - return &HTMLRenderer{ - HTMLRendererParameters: params, - - closeTag: closeTag, - headingIDs: make(map[string]int), - - sr: NewSmartypantsRenderer(params.Flags), - } -} - -func isHTMLTag(tag []byte, tagname string) bool { - found, _ := findHTMLTagPos(tag, tagname) - return found -} - -// Look for a character, but ignore it when it's in any kind of quotes, it -// might be JavaScript -func skipUntilCharIgnoreQuotes(html []byte, start int, char byte) int { - inSingleQuote := false - inDoubleQuote := false - inGraveQuote := false - i := start - for i < len(html) { - switch { - case html[i] == char && !inSingleQuote && !inDoubleQuote && !inGraveQuote: - return i - case html[i] == '\'': - inSingleQuote = !inSingleQuote - case html[i] == '"': - inDoubleQuote = !inDoubleQuote - case html[i] == '`': - inGraveQuote = !inGraveQuote - } - i++ - } - return start -} - -func findHTMLTagPos(tag []byte, tagname string) (bool, int) { - i := 0 - if i < len(tag) && tag[0] != '<' { - return false, -1 - } - i++ - i = skipSpace(tag, i) - - if i < len(tag) && tag[i] == '/' { - i++ - } - - i = skipSpace(tag, i) - j := 0 - for ; i < len(tag); i, j = i+1, j+1 { - if j >= len(tagname) { - break - } - - if strings.ToLower(string(tag[i]))[0] != tagname[j] { - return false, -1 - } - } - - if i == len(tag) { - return false, -1 - } - - rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>') - if rightAngle >= i { - return true, rightAngle - } - - return false, -1 -} - -func skipSpace(tag []byte, i int) int { - for i < len(tag) && isspace(tag[i]) { - i++ - } - return i -} - -func isRelativeLink(link []byte) (yes bool) { - // a tag begin with '#' - if link[0] == '#' { - return true - } - - // link begin with '/' but not '//', the second maybe a protocol relative link - if len(link) >= 2 && link[0] == '/' && link[1] != '/' { - return true - } - - // only the root '/' - if len(link) == 1 && link[0] == '/' { - return true - } - - // current directory : begin with "./" - if bytes.HasPrefix(link, []byte("./")) { - return true - } - - // parent directory : begin with "../" - if bytes.HasPrefix(link, []byte("../")) { - return true - } - - return false -} - -func (r *HTMLRenderer) ensureUniqueHeadingID(id string) string { - for count, found := r.headingIDs[id]; found; count, found = r.headingIDs[id] { - tmp := fmt.Sprintf("%s-%d", id, count+1) - - if _, tmpFound := r.headingIDs[tmp]; !tmpFound { - r.headingIDs[id] = count + 1 - id = tmp - } else { - id = id + "-1" - } - } - - if _, found := r.headingIDs[id]; !found { - r.headingIDs[id] = 0 - } - - return id -} - -func (r *HTMLRenderer) addAbsPrefix(link []byte) []byte { - if r.AbsolutePrefix != "" && isRelativeLink(link) && link[0] != '.' { - newDest := r.AbsolutePrefix - if link[0] != '/' { - newDest += "/" - } - newDest += string(link) - return []byte(newDest) - } - return link -} - -func appendLinkAttrs(attrs []string, flags HTMLFlags, link []byte) []string { - if isRelativeLink(link) { - return attrs - } - val := []string{} - if flags&NofollowLinks != 0 { - val = append(val, "nofollow") - } - if flags&NoreferrerLinks != 0 { - val = append(val, "noreferrer") - } - if flags&HrefTargetBlank != 0 { - attrs = append(attrs, "target=\"_blank\"") - } - if len(val) == 0 { - return attrs - } - attr := fmt.Sprintf("rel=%q", strings.Join(val, " ")) - return append(attrs, attr) -} - -func isMailto(link []byte) bool { - return bytes.HasPrefix(link, []byte("mailto:")) -} - -func needSkipLink(flags HTMLFlags, dest []byte) bool { - if flags&SkipLinks != 0 { - return true - } - return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) -} - -func isSmartypantable(node *Node) bool { - pt := node.Parent.Type - return pt != Link && pt != CodeBlock && pt != Code -} - -func appendLanguageAttr(attrs []string, info []byte) []string { - if len(info) == 0 { - return attrs - } - endOfLang := bytes.IndexAny(info, "\t ") - if endOfLang < 0 { - endOfLang = len(info) - } - return append(attrs, fmt.Sprintf("class=\"language-%s\"", info[:endOfLang])) -} - -func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) { - w.Write(name) - if len(attrs) > 0 { - w.Write(spaceBytes) - w.Write([]byte(strings.Join(attrs, " "))) - } - w.Write(gtBytes) - r.lastOutputLen = 1 -} - -func footnoteRef(prefix string, node *Node) []byte { - urlFrag := prefix + string(slugify(node.Destination)) - anchor := fmt.Sprintf(`%d`, urlFrag, node.NoteID) - return []byte(fmt.Sprintf(`%s`, urlFrag, anchor)) -} - -func footnoteItem(prefix string, slug []byte) []byte { - return []byte(fmt.Sprintf(`
  • `, prefix, slug)) -} - -func footnoteReturnLink(prefix, returnLink string, slug []byte) []byte { - const format = ` %s` - return []byte(fmt.Sprintf(format, prefix, slug, returnLink)) -} - -func itemOpenCR(node *Node) bool { - if node.Prev == nil { - return false - } - ld := node.Parent.ListData - return !ld.Tight && ld.ListFlags&ListTypeDefinition == 0 -} - -func skipParagraphTags(node *Node) bool { - grandparent := node.Parent.Parent - if grandparent == nil || grandparent.Type != List { - return false - } - tightOrTerm := grandparent.Tight || node.Parent.ListFlags&ListTypeTerm != 0 - return grandparent.Type == List && tightOrTerm -} - -func cellAlignment(align CellAlignFlags) string { - switch align { - case TableAlignmentLeft: - return "left" - case TableAlignmentRight: - return "right" - case TableAlignmentCenter: - return "center" - default: - return "" - } -} - -func (r *HTMLRenderer) out(w io.Writer, text []byte) { - if r.disableTags > 0 { - w.Write(htmlTagRe.ReplaceAll(text, []byte{})) - } else { - w.Write(text) - } - r.lastOutputLen = len(text) -} - -func (r *HTMLRenderer) cr(w io.Writer) { - if r.lastOutputLen > 0 { - r.out(w, nlBytes) - } -} - -var ( - nlBytes = []byte{'\n'} - gtBytes = []byte{'>'} - spaceBytes = []byte{' '} -) - -var ( - brTag = []byte("
    ") - brXHTMLTag = []byte("
    ") - emTag = []byte("") - emCloseTag = []byte("") - strongTag = []byte("") - strongCloseTag = []byte("") - delTag = []byte("") - delCloseTag = []byte("") - ttTag = []byte("") - ttCloseTag = []byte("") - aTag = []byte("") - preTag = []byte("
    ")
    -	preCloseTag        = []byte("
    ") - codeTag = []byte("") - codeCloseTag = []byte("") - pTag = []byte("

    ") - pCloseTag = []byte("

    ") - blockquoteTag = []byte("
    ") - blockquoteCloseTag = []byte("
    ") - hrTag = []byte("
    ") - hrXHTMLTag = []byte("
    ") - ulTag = []byte("
      ") - ulCloseTag = []byte("
    ") - olTag = []byte("
      ") - olCloseTag = []byte("
    ") - dlTag = []byte("
    ") - dlCloseTag = []byte("
    ") - liTag = []byte("
  • ") - liCloseTag = []byte("
  • ") - ddTag = []byte("
    ") - ddCloseTag = []byte("
    ") - dtTag = []byte("
    ") - dtCloseTag = []byte("
    ") - tableTag = []byte("") - tableCloseTag = []byte("
    ") - tdTag = []byte("") - thTag = []byte("") - theadTag = []byte("") - theadCloseTag = []byte("") - tbodyTag = []byte("") - tbodyCloseTag = []byte("") - trTag = []byte("") - trCloseTag = []byte("") - h1Tag = []byte("") - h2Tag = []byte("") - h3Tag = []byte("") - h4Tag = []byte("") - h5Tag = []byte("") - h6Tag = []byte("") - - footnotesDivBytes = []byte("\n
    \n\n") - footnotesCloseDivBytes = []byte("\n
    \n") -) - -func headingTagsFromLevel(level int) ([]byte, []byte) { - switch level { - case 1: - return h1Tag, h1CloseTag - case 2: - return h2Tag, h2CloseTag - case 3: - return h3Tag, h3CloseTag - case 4: - return h4Tag, h4CloseTag - case 5: - return h5Tag, h5CloseTag - default: - return h6Tag, h6CloseTag - } -} - -func (r *HTMLRenderer) outHRTag(w io.Writer) { - if r.Flags&UseXHTML == 0 { - r.out(w, hrTag) - } else { - r.out(w, hrXHTMLTag) - } -} - -// RenderNode is a default renderer of a single node of a syntax tree. For -// block nodes it will be called twice: first time with entering=true, second -// time with entering=false, so that it could know when it's working on an open -// tag and when on close. It writes the result to w. -// -// The return value is a way to tell the calling walker to adjust its walk -// pattern: e.g. it can terminate the traversal by returning Terminate. Or it -// can ask the walker to skip a subtree of this node by returning SkipChildren. -// The typical behavior is to return GoToNext, which asks for the usual -// traversal to the next node. -func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkStatus { - attrs := []string{} - switch node.Type { - case Text: - if r.Flags&Smartypants != 0 { - var tmp bytes.Buffer - escapeHTML(&tmp, node.Literal) - r.sr.Process(w, tmp.Bytes()) - } else { - if node.Parent.Type == Link { - escLink(w, node.Literal) - } else { - escapeHTML(w, node.Literal) - } - } - case Softbreak: - r.cr(w) - // TODO: make it configurable via out(renderer.softbreak) - case Hardbreak: - if r.Flags&UseXHTML == 0 { - r.out(w, brTag) - } else { - r.out(w, brXHTMLTag) - } - r.cr(w) - case Emph: - if entering { - r.out(w, emTag) - } else { - r.out(w, emCloseTag) - } - case Strong: - if entering { - r.out(w, strongTag) - } else { - r.out(w, strongCloseTag) - } - case Del: - if entering { - r.out(w, delTag) - } else { - r.out(w, delCloseTag) - } - case HTMLSpan: - if r.Flags&SkipHTML != 0 { - break - } - r.out(w, node.Literal) - case Link: - // mark it but don't link it if it is not a safe link: no smartypants - dest := node.LinkData.Destination - if needSkipLink(r.Flags, dest) { - if entering { - r.out(w, ttTag) - } else { - r.out(w, ttCloseTag) - } - } else { - if entering { - dest = r.addAbsPrefix(dest) - var hrefBuf bytes.Buffer - hrefBuf.WriteString("href=\"") - escLink(&hrefBuf, dest) - hrefBuf.WriteByte('"') - attrs = append(attrs, hrefBuf.String()) - if node.NoteID != 0 { - r.out(w, footnoteRef(r.FootnoteAnchorPrefix, node)) - break - } - attrs = appendLinkAttrs(attrs, r.Flags, dest) - if len(node.LinkData.Title) > 0 { - var titleBuff bytes.Buffer - titleBuff.WriteString("title=\"") - escapeHTML(&titleBuff, node.LinkData.Title) - titleBuff.WriteByte('"') - attrs = append(attrs, titleBuff.String()) - } - r.tag(w, aTag, attrs) - } else { - if node.NoteID != 0 { - break - } - r.out(w, aCloseTag) - } - } - case Image: - if r.Flags&SkipImages != 0 { - return SkipChildren - } - if entering { - dest := node.LinkData.Destination - dest = r.addAbsPrefix(dest) - if r.disableTags == 0 { - //if options.safe && potentiallyUnsafe(dest) { - //out(w, ``)
-				//} else {
-				r.out(w, []byte(`<img src=`)) - } - } - case Code: - r.out(w, codeTag) - escapeHTML(w, node.Literal) - r.out(w, codeCloseTag) - case Document: - break - case Paragraph: - if skipParagraphTags(node) { - break - } - if entering { - // TODO: untangle this clusterfuck about when the newlines need - // to be added and when not. - if node.Prev != nil { - switch node.Prev.Type { - case HTMLBlock, List, Paragraph, Heading, CodeBlock, BlockQuote, HorizontalRule: - r.cr(w) - } - } - if node.Parent.Type == BlockQuote && node.Prev == nil { - r.cr(w) - } - r.out(w, pTag) - } else { - r.out(w, pCloseTag) - if !(node.Parent.Type == Item && node.Next == nil) { - r.cr(w) - } - } - case BlockQuote: - if entering { - r.cr(w) - r.out(w, blockquoteTag) - } else { - r.out(w, blockquoteCloseTag) - r.cr(w) - } - case HTMLBlock: - if r.Flags&SkipHTML != 0 { - break - } - r.cr(w) - r.out(w, node.Literal) - r.cr(w) - case Heading: - openTag, closeTag := headingTagsFromLevel(node.Level) - if entering { - if node.IsTitleblock { - attrs = append(attrs, `class="title"`) - } - if node.HeadingID != "" { - id := r.ensureUniqueHeadingID(node.HeadingID) - if r.HeadingIDPrefix != "" { - id = r.HeadingIDPrefix + id - } - if r.HeadingIDSuffix != "" { - id = id + r.HeadingIDSuffix - } - attrs = append(attrs, fmt.Sprintf(`id="%s"`, id)) - } - r.cr(w) - r.tag(w, openTag, attrs) - } else { - r.out(w, closeTag) - if !(node.Parent.Type == Item && node.Next == nil) { - r.cr(w) - } - } - case HorizontalRule: - r.cr(w) - r.outHRTag(w) - r.cr(w) - case List: - openTag := ulTag - closeTag := ulCloseTag - if node.ListFlags&ListTypeOrdered != 0 { - openTag = olTag - closeTag = olCloseTag - } - if node.ListFlags&ListTypeDefinition != 0 { - openTag = dlTag - closeTag = dlCloseTag - } - if entering { - if node.IsFootnotesList { - r.out(w, footnotesDivBytes) - r.outHRTag(w) - r.cr(w) - } - r.cr(w) - if node.Parent.Type == Item && node.Parent.Parent.Tight { - r.cr(w) - } - r.tag(w, openTag[:len(openTag)-1], attrs) - r.cr(w) - } else { - r.out(w, closeTag) - //cr(w) - //if node.parent.Type != Item { - // cr(w) - //} - if node.Parent.Type == Item && node.Next != nil { - r.cr(w) - } - if node.Parent.Type == Document || node.Parent.Type == BlockQuote { - r.cr(w) - } - if node.IsFootnotesList { - r.out(w, footnotesCloseDivBytes) - } - } - case Item: - openTag := liTag - closeTag := liCloseTag - if node.ListFlags&ListTypeDefinition != 0 { - openTag = ddTag - closeTag = ddCloseTag - } - if node.ListFlags&ListTypeTerm != 0 { - openTag = dtTag - closeTag = dtCloseTag - } - if entering { - if itemOpenCR(node) { - r.cr(w) - } - if node.ListData.RefLink != nil { - slug := slugify(node.ListData.RefLink) - r.out(w, footnoteItem(r.FootnoteAnchorPrefix, slug)) - break - } - r.out(w, openTag) - } else { - if node.ListData.RefLink != nil { - slug := slugify(node.ListData.RefLink) - if r.Flags&FootnoteReturnLinks != 0 { - r.out(w, footnoteReturnLink(r.FootnoteAnchorPrefix, r.FootnoteReturnLinkContents, slug)) - } - } - r.out(w, closeTag) - r.cr(w) - } - case CodeBlock: - attrs = appendLanguageAttr(attrs, node.Info) - r.cr(w) - r.out(w, preTag) - r.tag(w, codeTag[:len(codeTag)-1], attrs) - escapeHTML(w, node.Literal) - r.out(w, codeCloseTag) - r.out(w, preCloseTag) - if node.Parent.Type != Item { - r.cr(w) - } - case Table: - if entering { - r.cr(w) - r.out(w, tableTag) - } else { - r.out(w, tableCloseTag) - r.cr(w) - } - case TableCell: - openTag := tdTag - closeTag := tdCloseTag - if node.IsHeader { - openTag = thTag - closeTag = thCloseTag - } - if entering { - align := cellAlignment(node.Align) - if align != "" { - attrs = append(attrs, fmt.Sprintf(`align="%s"`, align)) - } - if node.Prev == nil { - r.cr(w) - } - r.tag(w, openTag, attrs) - } else { - r.out(w, closeTag) - r.cr(w) - } - case TableHead: - if entering { - r.cr(w) - r.out(w, theadTag) - } else { - r.out(w, theadCloseTag) - r.cr(w) - } - case TableBody: - if entering { - r.cr(w) - r.out(w, tbodyTag) - // XXX: this is to adhere to a rather silly test. Should fix test. - if node.FirstChild == nil { - r.cr(w) - } - } else { - r.out(w, tbodyCloseTag) - r.cr(w) - } - case TableRow: - if entering { - r.cr(w) - r.out(w, trTag) - } else { - r.out(w, trCloseTag) - r.cr(w) - } - default: - panic("Unknown node type " + node.Type.String()) - } - return GoToNext -} - -// RenderHeader writes HTML document preamble and TOC if requested. -func (r *HTMLRenderer) RenderHeader(w io.Writer, ast *Node) { - r.writeDocumentHeader(w) - if r.Flags&TOC != 0 { - r.writeTOC(w, ast) - } -} - -// RenderFooter writes HTML document footer. -func (r *HTMLRenderer) RenderFooter(w io.Writer, ast *Node) { - if r.Flags&CompletePage == 0 { - return - } - io.WriteString(w, "\n\n\n") -} - -func (r *HTMLRenderer) writeDocumentHeader(w io.Writer) { - if r.Flags&CompletePage == 0 { - return - } - ending := "" - if r.Flags&UseXHTML != 0 { - io.WriteString(w, "\n") - io.WriteString(w, "\n") - ending = " /" - } else { - io.WriteString(w, "\n") - io.WriteString(w, "\n") - } - io.WriteString(w, "\n") - io.WriteString(w, " ") - if r.Flags&Smartypants != 0 { - r.sr.Process(w, []byte(r.Title)) - } else { - escapeHTML(w, []byte(r.Title)) - } - io.WriteString(w, "\n") - io.WriteString(w, " \n") - io.WriteString(w, " \n") - if r.CSS != "" { - io.WriteString(w, " \n") - } - if r.Icon != "" { - io.WriteString(w, " \n") - } - io.WriteString(w, "\n") - io.WriteString(w, "\n\n") -} - -func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) { - buf := bytes.Buffer{} - - inHeading := false - tocLevel := 0 - headingCount := 0 - - ast.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Heading && !node.HeadingData.IsTitleblock { - inHeading = entering - if entering { - node.HeadingID = fmt.Sprintf("toc_%d", headingCount) - if node.Level == tocLevel { - buf.WriteString("\n\n
  • ") - } else if node.Level < tocLevel { - for node.Level < tocLevel { - tocLevel-- - buf.WriteString("
  • \n") - } - buf.WriteString("\n\n
  • ") - } else { - for node.Level > tocLevel { - tocLevel++ - buf.WriteString("\n") - } - - if buf.Len() > 0 { - io.WriteString(w, "\n") - } - r.lastOutputLen = buf.Len() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go deleted file mode 100644 index 3d633106..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go +++ /dev/null @@ -1,1214 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// Functions to parse inline elements. -// - -package blackfriday - -import ( - "bytes" - "regexp" - "strconv" -) - -var ( - urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+` - anchorRe = regexp.MustCompile(`^(]+")?\s?>` + urlRe + `<\/a>)`) - - // TODO: improve this regexp to catch all possible entities: - htmlEntityRe = regexp.MustCompile(`&[a-z]{2,5};`) -) - -// Functions to parse text within a block -// Each function returns the number of chars taken care of -// data is the complete block being rendered -// offset is the number of valid chars before the current cursor - -func (p *Markdown) inline(currBlock *Node, data []byte) { - // handlers might call us recursively: enforce a maximum depth - if p.nesting >= p.maxNesting || len(data) == 0 { - return - } - p.nesting++ - beg, end := 0, 0 - for end < len(data) { - handler := p.inlineCallback[data[end]] - if handler != nil { - if consumed, node := handler(p, data, end); consumed == 0 { - // No action from the callback. - end++ - } else { - // Copy inactive chars into the output. - currBlock.AppendChild(text(data[beg:end])) - if node != nil { - currBlock.AppendChild(node) - } - // Skip past whatever the callback used. - beg = end + consumed - end = beg - } - } else { - end++ - } - } - if beg < len(data) { - if data[end-1] == '\n' { - end-- - } - currBlock.AppendChild(text(data[beg:end])) - } - p.nesting-- -} - -// single and double emphasis parsing -func emphasis(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - c := data[0] - - if len(data) > 2 && data[1] != c { - // whitespace cannot follow an opening emphasis; - // strikethrough only takes two characters '~~' - if c == '~' || isspace(data[1]) { - return 0, nil - } - ret, node := helperEmphasis(p, data[1:], c) - if ret == 0 { - return 0, nil - } - - return ret + 1, node - } - - if len(data) > 3 && data[1] == c && data[2] != c { - if isspace(data[2]) { - return 0, nil - } - ret, node := helperDoubleEmphasis(p, data[2:], c) - if ret == 0 { - return 0, nil - } - - return ret + 2, node - } - - if len(data) > 4 && data[1] == c && data[2] == c && data[3] != c { - if c == '~' || isspace(data[3]) { - return 0, nil - } - ret, node := helperTripleEmphasis(p, data, 3, c) - if ret == 0 { - return 0, nil - } - - return ret + 3, node - } - - return 0, nil -} - -func codeSpan(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - nb := 0 - - // count the number of backticks in the delimiter - for nb < len(data) && data[nb] == '`' { - nb++ - } - - // find the next delimiter - i, end := 0, 0 - for end = nb; end < len(data) && i < nb; end++ { - if data[end] == '`' { - i++ - } else { - i = 0 - } - } - - // no matching delimiter? - if i < nb && end >= len(data) { - return 0, nil - } - - // trim outside whitespace - fBegin := nb - for fBegin < end && data[fBegin] == ' ' { - fBegin++ - } - - fEnd := end - nb - for fEnd > fBegin && data[fEnd-1] == ' ' { - fEnd-- - } - - // render the code span - if fBegin != fEnd { - code := NewNode(Code) - code.Literal = data[fBegin:fEnd] - return end, code - } - - return end, nil -} - -// newline preceded by two spaces becomes
    -func maybeLineBreak(p *Markdown, data []byte, offset int) (int, *Node) { - origOffset := offset - for offset < len(data) && data[offset] == ' ' { - offset++ - } - - if offset < len(data) && data[offset] == '\n' { - if offset-origOffset >= 2 { - return offset - origOffset + 1, NewNode(Hardbreak) - } - return offset - origOffset, nil - } - return 0, nil -} - -// newline without two spaces works when HardLineBreak is enabled -func lineBreak(p *Markdown, data []byte, offset int) (int, *Node) { - if p.extensions&HardLineBreak != 0 { - return 1, NewNode(Hardbreak) - } - return 0, nil -} - -type linkType int - -const ( - linkNormal linkType = iota - linkImg - linkDeferredFootnote - linkInlineFootnote -) - -func isReferenceStyleLink(data []byte, pos int, t linkType) bool { - if t == linkDeferredFootnote { - return false - } - return pos < len(data)-1 && data[pos] == '[' && data[pos+1] != '^' -} - -func maybeImage(p *Markdown, data []byte, offset int) (int, *Node) { - if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, data, offset) - } - return 0, nil -} - -func maybeInlineFootnote(p *Markdown, data []byte, offset int) (int, *Node) { - if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, data, offset) - } - return 0, nil -} - -// '[': parse a link or an image or a footnote -func link(p *Markdown, data []byte, offset int) (int, *Node) { - // no links allowed inside regular links, footnote, and deferred footnotes - if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') { - return 0, nil - } - - var t linkType - switch { - // special case: ![^text] == deferred footnote (that follows something with - // an exclamation point) - case p.extensions&Footnotes != 0 && len(data)-1 > offset && data[offset+1] == '^': - t = linkDeferredFootnote - // ![alt] == image - case offset >= 0 && data[offset] == '!': - t = linkImg - offset++ - // ^[text] == inline footnote - // [^refId] == deferred footnote - case p.extensions&Footnotes != 0: - if offset >= 0 && data[offset] == '^' { - t = linkInlineFootnote - offset++ - } else if len(data)-1 > offset && data[offset+1] == '^' { - t = linkDeferredFootnote - } - // [text] == regular link - default: - t = linkNormal - } - - data = data[offset:] - - var ( - i = 1 - noteID int - title, link, altContent []byte - textHasNl = false - ) - - if t == linkDeferredFootnote { - i++ - } - - // look for the matching closing bracket - for level := 1; level > 0 && i < len(data); i++ { - switch { - case data[i] == '\n': - textHasNl = true - - case data[i-1] == '\\': - continue - - case data[i] == '[': - level++ - - case data[i] == ']': - level-- - if level <= 0 { - i-- // compensate for extra i++ in for loop - } - } - } - - if i >= len(data) { - return 0, nil - } - - txtE := i - i++ - var footnoteNode *Node - - // skip any amount of whitespace or newline - // (this is much more lax than original markdown syntax) - for i < len(data) && isspace(data[i]) { - i++ - } - - // inline style link - switch { - case i < len(data) && data[i] == '(': - // skip initial whitespace - i++ - - for i < len(data) && isspace(data[i]) { - i++ - } - - linkB := i - - // look for link end: ' " ) - findlinkend: - for i < len(data) { - switch { - case data[i] == '\\': - i += 2 - - case data[i] == ')' || data[i] == '\'' || data[i] == '"': - break findlinkend - - default: - i++ - } - } - - if i >= len(data) { - return 0, nil - } - linkE := i - - // look for title end if present - titleB, titleE := 0, 0 - if data[i] == '\'' || data[i] == '"' { - i++ - titleB = i - - findtitleend: - for i < len(data) { - switch { - case data[i] == '\\': - i += 2 - - case data[i] == ')': - break findtitleend - - default: - i++ - } - } - - if i >= len(data) { - return 0, nil - } - - // skip whitespace after title - titleE = i - 1 - for titleE > titleB && isspace(data[titleE]) { - titleE-- - } - - // check for closing quote presence - if data[titleE] != '\'' && data[titleE] != '"' { - titleB, titleE = 0, 0 - linkE = i - } - } - - // remove whitespace at the end of the link - for linkE > linkB && isspace(data[linkE-1]) { - linkE-- - } - - // remove optional angle brackets around the link - if data[linkB] == '<' { - linkB++ - } - if data[linkE-1] == '>' { - linkE-- - } - - // build escaped link and title - if linkE > linkB { - link = data[linkB:linkE] - } - - if titleE > titleB { - title = data[titleB:titleE] - } - - i++ - - // reference style link - case isReferenceStyleLink(data, i, t): - var id []byte - altContentConsidered := false - - // look for the id - i++ - linkB := i - for i < len(data) && data[i] != ']' { - i++ - } - if i >= len(data) { - return 0, nil - } - linkE := i - - // find the reference - if linkB == linkE { - if textHasNl { - var b bytes.Buffer - - for j := 1; j < txtE; j++ { - switch { - case data[j] != '\n': - b.WriteByte(data[j]) - case data[j-1] != ' ': - b.WriteByte(' ') - } - } - - id = b.Bytes() - } else { - id = data[1:txtE] - altContentConsidered = true - } - } else { - id = data[linkB:linkE] - } - - // find the reference with matching id - lr, ok := p.getRef(string(id)) - if !ok { - return 0, nil - } - - // keep link and title from reference - link = lr.link - title = lr.title - if altContentConsidered { - altContent = lr.text - } - i++ - - // shortcut reference style link or reference or inline footnote - default: - var id []byte - - // craft the id - if textHasNl { - var b bytes.Buffer - - for j := 1; j < txtE; j++ { - switch { - case data[j] != '\n': - b.WriteByte(data[j]) - case data[j-1] != ' ': - b.WriteByte(' ') - } - } - - id = b.Bytes() - } else { - if t == linkDeferredFootnote { - id = data[2:txtE] // get rid of the ^ - } else { - id = data[1:txtE] - } - } - - footnoteNode = NewNode(Item) - if t == linkInlineFootnote { - // create a new reference - noteID = len(p.notes) + 1 - - var fragment []byte - if len(id) > 0 { - if len(id) < 16 { - fragment = make([]byte, len(id)) - } else { - fragment = make([]byte, 16) - } - copy(fragment, slugify(id)) - } else { - fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteID))...) - } - - ref := &reference{ - noteID: noteID, - hasBlock: false, - link: fragment, - title: id, - footnote: footnoteNode, - } - - p.notes = append(p.notes, ref) - - link = ref.link - title = ref.title - } else { - // find the reference with matching id - lr, ok := p.getRef(string(id)) - if !ok { - return 0, nil - } - - if t == linkDeferredFootnote { - lr.noteID = len(p.notes) + 1 - lr.footnote = footnoteNode - p.notes = append(p.notes, lr) - } - - // keep link and title from reference - link = lr.link - // if inline footnote, title == footnote contents - title = lr.title - noteID = lr.noteID - } - - // rewind the whitespace - i = txtE + 1 - } - - var uLink []byte - if t == linkNormal || t == linkImg { - if len(link) > 0 { - var uLinkBuf bytes.Buffer - unescapeText(&uLinkBuf, link) - uLink = uLinkBuf.Bytes() - } - - // links need something to click on and somewhere to go - if len(uLink) == 0 || (t == linkNormal && txtE <= 1) { - return 0, nil - } - } - - // call the relevant rendering function - var linkNode *Node - switch t { - case linkNormal: - linkNode = NewNode(Link) - linkNode.Destination = normalizeURI(uLink) - linkNode.Title = title - if len(altContent) > 0 { - linkNode.AppendChild(text(altContent)) - } else { - // links cannot contain other links, so turn off link parsing - // temporarily and recurse - insideLink := p.insideLink - p.insideLink = true - p.inline(linkNode, data[1:txtE]) - p.insideLink = insideLink - } - - case linkImg: - linkNode = NewNode(Image) - linkNode.Destination = uLink - linkNode.Title = title - linkNode.AppendChild(text(data[1:txtE])) - i++ - - case linkInlineFootnote, linkDeferredFootnote: - linkNode = NewNode(Link) - linkNode.Destination = link - linkNode.Title = title - linkNode.NoteID = noteID - linkNode.Footnote = footnoteNode - if t == linkInlineFootnote { - i++ - } - - default: - return 0, nil - } - - return i, linkNode -} - -func (p *Markdown) inlineHTMLComment(data []byte) int { - if len(data) < 5 { - return 0 - } - if data[0] != '<' || data[1] != '!' || data[2] != '-' || data[3] != '-' { - return 0 - } - i := 5 - // scan for an end-of-comment marker, across lines if necessary - for i < len(data) && !(data[i-2] == '-' && data[i-1] == '-' && data[i] == '>') { - i++ - } - // no end-of-comment marker - if i >= len(data) { - return 0 - } - return i + 1 -} - -func stripMailto(link []byte) []byte { - if bytes.HasPrefix(link, []byte("mailto://")) { - return link[9:] - } else if bytes.HasPrefix(link, []byte("mailto:")) { - return link[7:] - } else { - return link - } -} - -// autolinkType specifies a kind of autolink that gets detected. -type autolinkType int - -// These are the possible flag values for the autolink renderer. -const ( - notAutolink autolinkType = iota - normalAutolink - emailAutolink -) - -// '<' when tags or autolinks are allowed -func leftAngle(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - altype, end := tagLength(data) - if size := p.inlineHTMLComment(data); size > 0 { - end = size - } - if end > 2 { - if altype != notAutolink { - var uLink bytes.Buffer - unescapeText(&uLink, data[1:end+1-2]) - if uLink.Len() > 0 { - link := uLink.Bytes() - node := NewNode(Link) - node.Destination = link - if altype == emailAutolink { - node.Destination = append([]byte("mailto:"), link...) - } - node.AppendChild(text(stripMailto(link))) - return end, node - } - } else { - htmlTag := NewNode(HTMLSpan) - htmlTag.Literal = data[:end] - return end, htmlTag - } - } - - return end, nil -} - -// '\\' backslash escape -var escapeChars = []byte("\\`*_{}[]()#+-.!:|&<>~") - -func escape(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - if len(data) > 1 { - if p.extensions&BackslashLineBreak != 0 && data[1] == '\n' { - return 2, NewNode(Hardbreak) - } - if bytes.IndexByte(escapeChars, data[1]) < 0 { - return 0, nil - } - - return 2, text(data[1:2]) - } - - return 2, nil -} - -func unescapeText(ob *bytes.Buffer, src []byte) { - i := 0 - for i < len(src) { - org := i - for i < len(src) && src[i] != '\\' { - i++ - } - - if i > org { - ob.Write(src[org:i]) - } - - if i+1 >= len(src) { - break - } - - ob.WriteByte(src[i+1]) - i += 2 - } -} - -// '&' escaped when it doesn't belong to an entity -// valid entities are assumed to be anything matching &#?[A-Za-z0-9]+; -func entity(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - end := 1 - - if end < len(data) && data[end] == '#' { - end++ - } - - for end < len(data) && isalnum(data[end]) { - end++ - } - - if end < len(data) && data[end] == ';' { - end++ // real entity - } else { - return 0, nil // lone '&' - } - - ent := data[:end] - // undo & escaping or it will be converted to &amp; by another - // escaper in the renderer - if bytes.Equal(ent, []byte("&")) { - ent = []byte{'&'} - } - - return end, text(ent) -} - -func linkEndsWithEntity(data []byte, linkEnd int) bool { - entityRanges := htmlEntityRe.FindAllIndex(data[:linkEnd], -1) - return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd -} - -// hasPrefixCaseInsensitive is a custom implementation of -// strings.HasPrefix(strings.ToLower(s), prefix) -// we rolled our own because ToLower pulls in a huge machinery of lowercasing -// anything from Unicode and that's very slow. Since this func will only be -// used on ASCII protocol prefixes, we can take shortcuts. -func hasPrefixCaseInsensitive(s, prefix []byte) bool { - if len(s) < len(prefix) { - return false - } - delta := byte('a' - 'A') - for i, b := range prefix { - if b != s[i] && b != s[i]+delta { - return false - } - } - return true -} - -var protocolPrefixes = [][]byte{ - []byte("http://"), - []byte("https://"), - []byte("ftp://"), - []byte("file://"), - []byte("mailto:"), -} - -const shortestPrefix = 6 // len("ftp://"), the shortest of the above - -func maybeAutoLink(p *Markdown, data []byte, offset int) (int, *Node) { - // quick check to rule out most false hits - if p.insideLink || len(data) < offset+shortestPrefix { - return 0, nil - } - for _, prefix := range protocolPrefixes { - endOfHead := offset + 8 // 8 is the len() of the longest prefix - if endOfHead > len(data) { - endOfHead = len(data) - } - if hasPrefixCaseInsensitive(data[offset:endOfHead], prefix) { - return autoLink(p, data, offset) - } - } - return 0, nil -} - -func autoLink(p *Markdown, data []byte, offset int) (int, *Node) { - // Now a more expensive check to see if we're not inside an anchor element - anchorStart := offset - offsetFromAnchor := 0 - for anchorStart > 0 && data[anchorStart] != '<' { - anchorStart-- - offsetFromAnchor++ - } - - anchorStr := anchorRe.Find(data[anchorStart:]) - if anchorStr != nil { - anchorClose := NewNode(HTMLSpan) - anchorClose.Literal = anchorStr[offsetFromAnchor:] - return len(anchorStr) - offsetFromAnchor, anchorClose - } - - // scan backward for a word boundary - rewind := 0 - for offset-rewind > 0 && rewind <= 7 && isletter(data[offset-rewind-1]) { - rewind++ - } - if rewind > 6 { // longest supported protocol is "mailto" which has 6 letters - return 0, nil - } - - origData := data - data = data[offset-rewind:] - - if !isSafeLink(data) { - return 0, nil - } - - linkEnd := 0 - for linkEnd < len(data) && !isEndOfLink(data[linkEnd]) { - linkEnd++ - } - - // Skip punctuation at the end of the link - if (data[linkEnd-1] == '.' || data[linkEnd-1] == ',') && data[linkEnd-2] != '\\' { - linkEnd-- - } - - // But don't skip semicolon if it's a part of escaped entity: - if data[linkEnd-1] == ';' && data[linkEnd-2] != '\\' && !linkEndsWithEntity(data, linkEnd) { - linkEnd-- - } - - // See if the link finishes with a punctuation sign that can be closed. - var copen byte - switch data[linkEnd-1] { - case '"': - copen = '"' - case '\'': - copen = '\'' - case ')': - copen = '(' - case ']': - copen = '[' - case '}': - copen = '{' - default: - copen = 0 - } - - if copen != 0 { - bufEnd := offset - rewind + linkEnd - 2 - - openDelim := 1 - - /* Try to close the final punctuation sign in this same line; - * if we managed to close it outside of the URL, that means that it's - * not part of the URL. If it closes inside the URL, that means it - * is part of the URL. - * - * Examples: - * - * foo http://www.pokemon.com/Pikachu_(Electric) bar - * => http://www.pokemon.com/Pikachu_(Electric) - * - * foo (http://www.pokemon.com/Pikachu_(Electric)) bar - * => http://www.pokemon.com/Pikachu_(Electric) - * - * foo http://www.pokemon.com/Pikachu_(Electric)) bar - * => http://www.pokemon.com/Pikachu_(Electric)) - * - * (foo http://www.pokemon.com/Pikachu_(Electric)) bar - * => foo http://www.pokemon.com/Pikachu_(Electric) - */ - - for bufEnd >= 0 && origData[bufEnd] != '\n' && openDelim != 0 { - if origData[bufEnd] == data[linkEnd-1] { - openDelim++ - } - - if origData[bufEnd] == copen { - openDelim-- - } - - bufEnd-- - } - - if openDelim == 0 { - linkEnd-- - } - } - - var uLink bytes.Buffer - unescapeText(&uLink, data[:linkEnd]) - - if uLink.Len() > 0 { - node := NewNode(Link) - node.Destination = uLink.Bytes() - node.AppendChild(text(uLink.Bytes())) - return linkEnd, node - } - - return linkEnd, nil -} - -func isEndOfLink(char byte) bool { - return isspace(char) || char == '<' -} - -var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")} -var validPaths = [][]byte{[]byte("/"), []byte("./"), []byte("../")} - -func isSafeLink(link []byte) bool { - for _, path := range validPaths { - if len(link) >= len(path) && bytes.Equal(link[:len(path)], path) { - if len(link) == len(path) { - return true - } else if isalnum(link[len(path)]) { - return true - } - } - } - - for _, prefix := range validUris { - // TODO: handle unicode here - // case-insensitive prefix test - if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isalnum(link[len(prefix)]) { - return true - } - } - - return false -} - -// return the length of the given tag, or 0 is it's not valid -func tagLength(data []byte) (autolink autolinkType, end int) { - var i, j int - - // a valid tag can't be shorter than 3 chars - if len(data) < 3 { - return notAutolink, 0 - } - - // begins with a '<' optionally followed by '/', followed by letter or number - if data[0] != '<' { - return notAutolink, 0 - } - if data[1] == '/' { - i = 2 - } else { - i = 1 - } - - if !isalnum(data[i]) { - return notAutolink, 0 - } - - // scheme test - autolink = notAutolink - - // try to find the beginning of an URI - for i < len(data) && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-') { - i++ - } - - if i > 1 && i < len(data) && data[i] == '@' { - if j = isMailtoAutoLink(data[i:]); j != 0 { - return emailAutolink, i + j - } - } - - if i > 2 && i < len(data) && data[i] == ':' { - autolink = normalAutolink - i++ - } - - // complete autolink test: no whitespace or ' or " - switch { - case i >= len(data): - autolink = notAutolink - case autolink != notAutolink: - j = i - - for i < len(data) { - if data[i] == '\\' { - i += 2 - } else if data[i] == '>' || data[i] == '\'' || data[i] == '"' || isspace(data[i]) { - break - } else { - i++ - } - - } - - if i >= len(data) { - return autolink, 0 - } - if i > j && data[i] == '>' { - return autolink, i + 1 - } - - // one of the forbidden chars has been found - autolink = notAutolink - } - i += bytes.IndexByte(data[i:], '>') - if i < 0 { - return autolink, 0 - } - return autolink, i + 1 -} - -// look for the address part of a mail autolink and '>' -// this is less strict than the original markdown e-mail address matching -func isMailtoAutoLink(data []byte) int { - nb := 0 - - // address is assumed to be: [-@._a-zA-Z0-9]+ with exactly one '@' - for i := 0; i < len(data); i++ { - if isalnum(data[i]) { - continue - } - - switch data[i] { - case '@': - nb++ - - case '-', '.', '_': - break - - case '>': - if nb == 1 { - return i + 1 - } - return 0 - default: - return 0 - } - } - - return 0 -} - -// look for the next emph char, skipping other constructs -func helperFindEmphChar(data []byte, c byte) int { - i := 0 - - for i < len(data) { - for i < len(data) && data[i] != c && data[i] != '`' && data[i] != '[' { - i++ - } - if i >= len(data) { - return 0 - } - // do not count escaped chars - if i != 0 && data[i-1] == '\\' { - i++ - continue - } - if data[i] == c { - return i - } - - if data[i] == '`' { - // skip a code span - tmpI := 0 - i++ - for i < len(data) && data[i] != '`' { - if tmpI == 0 && data[i] == c { - tmpI = i - } - i++ - } - if i >= len(data) { - return tmpI - } - i++ - } else if data[i] == '[' { - // skip a link - tmpI := 0 - i++ - for i < len(data) && data[i] != ']' { - if tmpI == 0 && data[i] == c { - tmpI = i - } - i++ - } - i++ - for i < len(data) && (data[i] == ' ' || data[i] == '\n') { - i++ - } - if i >= len(data) { - return tmpI - } - if data[i] != '[' && data[i] != '(' { // not a link - if tmpI > 0 { - return tmpI - } - continue - } - cc := data[i] - i++ - for i < len(data) && data[i] != cc { - if tmpI == 0 && data[i] == c { - return i - } - i++ - } - if i >= len(data) { - return tmpI - } - i++ - } - } - return 0 -} - -func helperEmphasis(p *Markdown, data []byte, c byte) (int, *Node) { - i := 0 - - // skip one symbol if coming from emph3 - if len(data) > 1 && data[0] == c && data[1] == c { - i = 1 - } - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - if i >= len(data) { - return 0, nil - } - - if i+1 < len(data) && data[i+1] == c { - i++ - continue - } - - if data[i] == c && !isspace(data[i-1]) { - - if p.extensions&NoIntraEmphasis != 0 { - if !(i+1 == len(data) || isspace(data[i+1]) || ispunct(data[i+1])) { - continue - } - } - - emph := NewNode(Emph) - p.inline(emph, data[:i]) - return i + 1, emph - } - } - - return 0, nil -} - -func helperDoubleEmphasis(p *Markdown, data []byte, c byte) (int, *Node) { - i := 0 - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - - if i+1 < len(data) && data[i] == c && data[i+1] == c && i > 0 && !isspace(data[i-1]) { - nodeType := Strong - if c == '~' { - nodeType = Del - } - node := NewNode(nodeType) - p.inline(node, data[:i]) - return i + 2, node - } - i++ - } - return 0, nil -} - -func helperTripleEmphasis(p *Markdown, data []byte, offset int, c byte) (int, *Node) { - i := 0 - origData := data - data = data[offset:] - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - - // skip whitespace preceded symbols - if data[i] != c || isspace(data[i-1]) { - continue - } - - switch { - case i+2 < len(data) && data[i+1] == c && data[i+2] == c: - // triple symbol found - strong := NewNode(Strong) - em := NewNode(Emph) - strong.AppendChild(em) - p.inline(em, data[:i]) - return i + 3, strong - case (i+1 < len(data) && data[i+1] == c): - // double symbol found, hand over to emph1 - length, node := helperEmphasis(p, origData[offset-2:], c) - if length == 0 { - return 0, nil - } - return length - 2, node - default: - // single symbol found, hand over to emph2 - length, node := helperDoubleEmphasis(p, origData[offset-1:], c) - if length == 0 { - return 0, nil - } - return length - 1, node - } - } - return 0, nil -} - -func text(s []byte) *Node { - node := NewNode(Text) - node.Literal = s - return node -} - -func normalizeURI(s []byte) []byte { - return s // TODO: implement -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go deleted file mode 100644 index ff61cb05..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go +++ /dev/null @@ -1,940 +0,0 @@ -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. - -package blackfriday - -import ( - "bytes" - "fmt" - "io" - "strings" - "unicode/utf8" -) - -// -// Markdown parsing and processing -// - -// Version string of the package. Appears in the rendered document when -// CompletePage flag is on. -const Version = "2.0" - -// Extensions is a bitwise or'ed collection of enabled Blackfriday's -// extensions. -type Extensions int - -// These are the supported markdown parsing extensions. -// OR these values together to select multiple extensions. -const ( - NoExtensions Extensions = 0 - NoIntraEmphasis Extensions = 1 << iota // Ignore emphasis markers inside words - Tables // Render tables - FencedCode // Render fenced code blocks - Autolink // Detect embedded URLs that are not explicitly marked - Strikethrough // Strikethrough text using ~~test~~ - LaxHTMLBlocks // Loosen up HTML block parsing rules - SpaceHeadings // Be strict about prefix heading rules - HardLineBreak // Translate newlines into line breaks - TabSizeEight // Expand tabs to eight spaces instead of four - Footnotes // Pandoc-style footnotes - NoEmptyLineBeforeBlock // No need to insert an empty line to start a (code, quote, ordered list, unordered list) block - HeadingIDs // specify heading IDs with {#id} - Titleblock // Titleblock ala pandoc - AutoHeadingIDs // Create the heading ID from the text - BackslashLineBreak // Translate trailing backslashes into line breaks - DefinitionLists // Render definition lists - - CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | - SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes - - CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | - Autolink | Strikethrough | SpaceHeadings | HeadingIDs | - BackslashLineBreak | DefinitionLists -) - -// ListType contains bitwise or'ed flags for list and list item objects. -type ListType int - -// These are the possible flag values for the ListItem renderer. -// Multiple flag values may be ORed together. -// These are mostly of interest if you are writing a new output format. -const ( - ListTypeOrdered ListType = 1 << iota - ListTypeDefinition - ListTypeTerm - - ListItemContainsBlock - ListItemBeginningOfList // TODO: figure out if this is of any use now - ListItemEndOfList -) - -// CellAlignFlags holds a type of alignment in a table cell. -type CellAlignFlags int - -// These are the possible flag values for the table cell renderer. -// Only a single one of these values will be used; they are not ORed together. -// These are mostly of interest if you are writing a new output format. -const ( - TableAlignmentLeft CellAlignFlags = 1 << iota - TableAlignmentRight - TableAlignmentCenter = (TableAlignmentLeft | TableAlignmentRight) -) - -// The size of a tab stop. -const ( - TabSizeDefault = 4 - TabSizeDouble = 8 -) - -// blockTags is a set of tags that are recognized as HTML block tags. -// Any of these can be included in markdown text without special escaping. -var blockTags = map[string]struct{}{ - "blockquote": struct{}{}, - "del": struct{}{}, - "div": struct{}{}, - "dl": struct{}{}, - "fieldset": struct{}{}, - "form": struct{}{}, - "h1": struct{}{}, - "h2": struct{}{}, - "h3": struct{}{}, - "h4": struct{}{}, - "h5": struct{}{}, - "h6": struct{}{}, - "iframe": struct{}{}, - "ins": struct{}{}, - "math": struct{}{}, - "noscript": struct{}{}, - "ol": struct{}{}, - "pre": struct{}{}, - "p": struct{}{}, - "script": struct{}{}, - "style": struct{}{}, - "table": struct{}{}, - "ul": struct{}{}, - - // HTML5 - "address": struct{}{}, - "article": struct{}{}, - "aside": struct{}{}, - "canvas": struct{}{}, - "figcaption": struct{}{}, - "figure": struct{}{}, - "footer": struct{}{}, - "header": struct{}{}, - "hgroup": struct{}{}, - "main": struct{}{}, - "nav": struct{}{}, - "output": struct{}{}, - "progress": struct{}{}, - "section": struct{}{}, - "video": struct{}{}, -} - -// Renderer is the rendering interface. This is mostly of interest if you are -// implementing a new rendering format. -// -// Only an HTML implementation is provided in this repository, see the README -// for external implementations. -type Renderer interface { - // RenderNode is the main rendering method. It will be called once for - // every leaf node and twice for every non-leaf node (first with - // entering=true, then with entering=false). The method should write its - // rendition of the node to the supplied writer w. - RenderNode(w io.Writer, node *Node, entering bool) WalkStatus - - // RenderHeader is a method that allows the renderer to produce some - // content preceding the main body of the output document. The header is - // understood in the broad sense here. For example, the default HTML - // renderer will write not only the HTML document preamble, but also the - // table of contents if it was requested. - // - // The method will be passed an entire document tree, in case a particular - // implementation needs to inspect it to produce output. - // - // The output should be written to the supplied writer w. If your - // implementation has no header to write, supply an empty implementation. - RenderHeader(w io.Writer, ast *Node) - - // RenderFooter is a symmetric counterpart of RenderHeader. - RenderFooter(w io.Writer, ast *Node) -} - -// Callback functions for inline parsing. One such function is defined -// for each character that triggers a response when parsing inline data. -type inlineParser func(p *Markdown, data []byte, offset int) (int, *Node) - -// Markdown is a type that holds extensions and the runtime state used by -// Parse, and the renderer. You can not use it directly, construct it with New. -type Markdown struct { - renderer Renderer - referenceOverride ReferenceOverrideFunc - refs map[string]*reference - inlineCallback [256]inlineParser - extensions Extensions - nesting int - maxNesting int - insideLink bool - - // Footnotes need to be ordered as well as available to quickly check for - // presence. If a ref is also a footnote, it's stored both in refs and here - // in notes. Slice is nil if footnotes not enabled. - notes []*reference - - doc *Node - tip *Node // = doc - oldTip *Node - lastMatchedContainer *Node // = doc - allClosed bool -} - -func (p *Markdown) getRef(refid string) (ref *reference, found bool) { - if p.referenceOverride != nil { - r, overridden := p.referenceOverride(refid) - if overridden { - if r == nil { - return nil, false - } - return &reference{ - link: []byte(r.Link), - title: []byte(r.Title), - noteID: 0, - hasBlock: false, - text: []byte(r.Text)}, true - } - } - // refs are case insensitive - ref, found = p.refs[strings.ToLower(refid)] - return ref, found -} - -func (p *Markdown) finalize(block *Node) { - above := block.Parent - block.open = false - p.tip = above -} - -func (p *Markdown) addChild(node NodeType, offset uint32) *Node { - return p.addExistingChild(NewNode(node), offset) -} - -func (p *Markdown) addExistingChild(node *Node, offset uint32) *Node { - for !p.tip.canContain(node.Type) { - p.finalize(p.tip) - } - p.tip.AppendChild(node) - p.tip = node - return node -} - -func (p *Markdown) closeUnmatchedBlocks() { - if !p.allClosed { - for p.oldTip != p.lastMatchedContainer { - parent := p.oldTip.Parent - p.finalize(p.oldTip) - p.oldTip = parent - } - p.allClosed = true - } -} - -// -// -// Public interface -// -// - -// Reference represents the details of a link. -// See the documentation in Options for more details on use-case. -type Reference struct { - // Link is usually the URL the reference points to. - Link string - // Title is the alternate text describing the link in more detail. - Title string - // Text is the optional text to override the ref with if the syntax used was - // [refid][] - Text string -} - -// ReferenceOverrideFunc is expected to be called with a reference string and -// return either a valid Reference type that the reference string maps to or -// nil. If overridden is false, the default reference logic will be executed. -// See the documentation in Options for more details on use-case. -type ReferenceOverrideFunc func(reference string) (ref *Reference, overridden bool) - -// New constructs a Markdown processor. You can use the same With* functions as -// for Run() to customize parser's behavior and the renderer. -func New(opts ...Option) *Markdown { - var p Markdown - for _, opt := range opts { - opt(&p) - } - p.refs = make(map[string]*reference) - p.maxNesting = 16 - p.insideLink = false - docNode := NewNode(Document) - p.doc = docNode - p.tip = docNode - p.oldTip = docNode - p.lastMatchedContainer = docNode - p.allClosed = true - // register inline parsers - p.inlineCallback[' '] = maybeLineBreak - p.inlineCallback['*'] = emphasis - p.inlineCallback['_'] = emphasis - if p.extensions&Strikethrough != 0 { - p.inlineCallback['~'] = emphasis - } - p.inlineCallback['`'] = codeSpan - p.inlineCallback['\n'] = lineBreak - p.inlineCallback['['] = link - p.inlineCallback['<'] = leftAngle - p.inlineCallback['\\'] = escape - p.inlineCallback['&'] = entity - p.inlineCallback['!'] = maybeImage - p.inlineCallback['^'] = maybeInlineFootnote - if p.extensions&Autolink != 0 { - p.inlineCallback['h'] = maybeAutoLink - p.inlineCallback['m'] = maybeAutoLink - p.inlineCallback['f'] = maybeAutoLink - p.inlineCallback['H'] = maybeAutoLink - p.inlineCallback['M'] = maybeAutoLink - p.inlineCallback['F'] = maybeAutoLink - } - if p.extensions&Footnotes != 0 { - p.notes = make([]*reference, 0) - } - return &p -} - -// Option customizes the Markdown processor's default behavior. -type Option func(*Markdown) - -// WithRenderer allows you to override the default renderer. -func WithRenderer(r Renderer) Option { - return func(p *Markdown) { - p.renderer = r - } -} - -// WithExtensions allows you to pick some of the many extensions provided by -// Blackfriday. You can bitwise OR them. -func WithExtensions(e Extensions) Option { - return func(p *Markdown) { - p.extensions = e - } -} - -// WithNoExtensions turns off all extensions and custom behavior. -func WithNoExtensions() Option { - return func(p *Markdown) { - p.extensions = NoExtensions - p.renderer = NewHTMLRenderer(HTMLRendererParameters{ - Flags: HTMLFlagsNone, - }) - } -} - -// WithRefOverride sets an optional function callback that is called every -// time a reference is resolved. -// -// In Markdown, the link reference syntax can be made to resolve a link to -// a reference instead of an inline URL, in one of the following ways: -// -// * [link text][refid] -// * [refid][] -// -// Usually, the refid is defined at the bottom of the Markdown document. If -// this override function is provided, the refid is passed to the override -// function first, before consulting the defined refids at the bottom. If -// the override function indicates an override did not occur, the refids at -// the bottom will be used to fill in the link details. -func WithRefOverride(o ReferenceOverrideFunc) Option { - return func(p *Markdown) { - p.referenceOverride = o - } -} - -// Run is the main entry point to Blackfriday. It parses and renders a -// block of markdown-encoded text. -// -// The simplest invocation of Run takes one argument, input: -// output := Run(input) -// This will parse the input with CommonExtensions enabled and render it with -// the default HTMLRenderer (with CommonHTMLFlags). -// -// Variadic arguments opts can customize the default behavior. Since Markdown -// type does not contain exported fields, you can not use it directly. Instead, -// use the With* functions. For example, this will call the most basic -// functionality, with no extensions: -// output := Run(input, WithNoExtensions()) -// -// You can use any number of With* arguments, even contradicting ones. They -// will be applied in order of appearance and the latter will override the -// former: -// output := Run(input, WithNoExtensions(), WithExtensions(exts), -// WithRenderer(yourRenderer)) -func Run(input []byte, opts ...Option) []byte { - r := NewHTMLRenderer(HTMLRendererParameters{ - Flags: CommonHTMLFlags, - }) - optList := []Option{WithRenderer(r), WithExtensions(CommonExtensions)} - optList = append(optList, opts...) - parser := New(optList...) - ast := parser.Parse(input) - var buf bytes.Buffer - parser.renderer.RenderHeader(&buf, ast) - ast.Walk(func(node *Node, entering bool) WalkStatus { - return parser.renderer.RenderNode(&buf, node, entering) - }) - parser.renderer.RenderFooter(&buf, ast) - return buf.Bytes() -} - -// Parse is an entry point to the parsing part of Blackfriday. It takes an -// input markdown document and produces a syntax tree for its contents. This -// tree can then be rendered with a default or custom renderer, or -// analyzed/transformed by the caller to whatever non-standard needs they have. -// The return value is the root node of the syntax tree. -func (p *Markdown) Parse(input []byte) *Node { - p.block(input) - // Walk the tree and finish up some of unfinished blocks - for p.tip != nil { - p.finalize(p.tip) - } - // Walk the tree again and process inline markdown in each block - p.doc.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Paragraph || node.Type == Heading || node.Type == TableCell { - p.inline(node, node.content) - node.content = nil - } - return GoToNext - }) - p.parseRefsToAST() - return p.doc -} - -func (p *Markdown) parseRefsToAST() { - if p.extensions&Footnotes == 0 || len(p.notes) == 0 { - return - } - p.tip = p.doc - block := p.addBlock(List, nil) - block.IsFootnotesList = true - block.ListFlags = ListTypeOrdered - flags := ListItemBeginningOfList - // Note: this loop is intentionally explicit, not range-form. This is - // because the body of the loop will append nested footnotes to p.notes and - // we need to process those late additions. Range form would only walk over - // the fixed initial set. - for i := 0; i < len(p.notes); i++ { - ref := p.notes[i] - p.addExistingChild(ref.footnote, 0) - block := ref.footnote - block.ListFlags = flags | ListTypeOrdered - block.RefLink = ref.link - if ref.hasBlock { - flags |= ListItemContainsBlock - p.block(ref.title) - } else { - p.inline(block, ref.title) - } - flags &^= ListItemBeginningOfList | ListItemContainsBlock - } - above := block.Parent - finalizeList(block) - p.tip = above - block.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Paragraph || node.Type == Heading { - p.inline(node, node.content) - node.content = nil - } - return GoToNext - }) -} - -// -// Link references -// -// This section implements support for references that (usually) appear -// as footnotes in a document, and can be referenced anywhere in the document. -// The basic format is: -// -// [1]: http://www.google.com/ "Google" -// [2]: http://www.github.com/ "Github" -// -// Anywhere in the document, the reference can be linked by referring to its -// label, i.e., 1 and 2 in this example, as in: -// -// This library is hosted on [Github][2], a git hosting site. -// -// Actual footnotes as specified in Pandoc and supported by some other Markdown -// libraries such as php-markdown are also taken care of. They look like this: -// -// This sentence needs a bit of further explanation.[^note] -// -// [^note]: This is the explanation. -// -// Footnotes should be placed at the end of the document in an ordered list. -// Inline footnotes such as: -// -// Inline footnotes^[Not supported.] also exist. -// -// are not yet supported. - -// reference holds all information necessary for a reference-style links or -// footnotes. -// -// Consider this markdown with reference-style links: -// -// [link][ref] -// -// [ref]: /url/ "tooltip title" -// -// It will be ultimately converted to this HTML: -// -//

    link

    -// -// And a reference structure will be populated as follows: -// -// p.refs["ref"] = &reference{ -// link: "/url/", -// title: "tooltip title", -// } -// -// Alternatively, reference can contain information about a footnote. Consider -// this markdown: -// -// Text needing a footnote.[^a] -// -// [^a]: This is the note -// -// A reference structure will be populated as follows: -// -// p.refs["a"] = &reference{ -// link: "a", -// title: "This is the note", -// noteID: , -// } -// -// TODO: As you can see, it begs for splitting into two dedicated structures -// for refs and for footnotes. -type reference struct { - link []byte - title []byte - noteID int // 0 if not a footnote ref - hasBlock bool - footnote *Node // a link to the Item node within a list of footnotes - - text []byte // only gets populated by refOverride feature with Reference.Text -} - -func (r *reference) String() string { - return fmt.Sprintf("{link: %q, title: %q, text: %q, noteID: %d, hasBlock: %v}", - r.link, r.title, r.text, r.noteID, r.hasBlock) -} - -// Check whether or not data starts with a reference link. -// If so, it is parsed and stored in the list of references -// (in the render struct). -// Returns the number of bytes to skip to move past it, -// or zero if the first line is not a reference. -func isReference(p *Markdown, data []byte, tabSize int) int { - // up to 3 optional leading spaces - if len(data) < 4 { - return 0 - } - i := 0 - for i < 3 && data[i] == ' ' { - i++ - } - - noteID := 0 - - // id part: anything but a newline between brackets - if data[i] != '[' { - return 0 - } - i++ - if p.extensions&Footnotes != 0 { - if i < len(data) && data[i] == '^' { - // we can set it to anything here because the proper noteIds will - // be assigned later during the second pass. It just has to be != 0 - noteID = 1 - i++ - } - } - idOffset := i - for i < len(data) && data[i] != '\n' && data[i] != '\r' && data[i] != ']' { - i++ - } - if i >= len(data) || data[i] != ']' { - return 0 - } - idEnd := i - // footnotes can have empty ID, like this: [^], but a reference can not be - // empty like this: []. Break early if it's not a footnote and there's no ID - if noteID == 0 && idOffset == idEnd { - return 0 - } - // spacer: colon (space | tab)* newline? (space | tab)* - i++ - if i >= len(data) || data[i] != ':' { - return 0 - } - i++ - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i < len(data) && (data[i] == '\n' || data[i] == '\r') { - i++ - if i < len(data) && data[i] == '\n' && data[i-1] == '\r' { - i++ - } - } - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i >= len(data) { - return 0 - } - - var ( - linkOffset, linkEnd int - titleOffset, titleEnd int - lineEnd int - raw []byte - hasBlock bool - ) - - if p.extensions&Footnotes != 0 && noteID != 0 { - linkOffset, linkEnd, raw, hasBlock = scanFootnote(p, data, i, tabSize) - lineEnd = linkEnd - } else { - linkOffset, linkEnd, titleOffset, titleEnd, lineEnd = scanLinkRef(p, data, i) - } - if lineEnd == 0 { - return 0 - } - - // a valid ref has been found - - ref := &reference{ - noteID: noteID, - hasBlock: hasBlock, - } - - if noteID > 0 { - // reusing the link field for the id since footnotes don't have links - ref.link = data[idOffset:idEnd] - // if footnote, it's not really a title, it's the contained text - ref.title = raw - } else { - ref.link = data[linkOffset:linkEnd] - ref.title = data[titleOffset:titleEnd] - } - - // id matches are case-insensitive - id := string(bytes.ToLower(data[idOffset:idEnd])) - - p.refs[id] = ref - - return lineEnd -} - -func scanLinkRef(p *Markdown, data []byte, i int) (linkOffset, linkEnd, titleOffset, titleEnd, lineEnd int) { - // link: whitespace-free sequence, optionally between angle brackets - if data[i] == '<' { - i++ - } - linkOffset = i - for i < len(data) && data[i] != ' ' && data[i] != '\t' && data[i] != '\n' && data[i] != '\r' { - i++ - } - linkEnd = i - if data[linkOffset] == '<' && data[linkEnd-1] == '>' { - linkOffset++ - linkEnd-- - } - - // optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i < len(data) && data[i] != '\n' && data[i] != '\r' && data[i] != '\'' && data[i] != '"' && data[i] != '(' { - return - } - - // compute end-of-line - if i >= len(data) || data[i] == '\r' || data[i] == '\n' { - lineEnd = i - } - if i+1 < len(data) && data[i] == '\r' && data[i+1] == '\n' { - lineEnd++ - } - - // optional (space|tab)* spacer after a newline - if lineEnd > 0 { - i = lineEnd + 1 - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - } - - // optional title: any non-newline sequence enclosed in '"() alone on its line - if i+1 < len(data) && (data[i] == '\'' || data[i] == '"' || data[i] == '(') { - i++ - titleOffset = i - - // look for EOL - for i < len(data) && data[i] != '\n' && data[i] != '\r' { - i++ - } - if i+1 < len(data) && data[i] == '\n' && data[i+1] == '\r' { - titleEnd = i + 1 - } else { - titleEnd = i - } - - // step back - i-- - for i > titleOffset && (data[i] == ' ' || data[i] == '\t') { - i-- - } - if i > titleOffset && (data[i] == '\'' || data[i] == '"' || data[i] == ')') { - lineEnd = titleEnd - titleEnd = i - } - } - - return -} - -// The first bit of this logic is the same as Parser.listItem, but the rest -// is much simpler. This function simply finds the entire block and shifts it -// over by one tab if it is indeed a block (just returns the line if it's not). -// blockEnd is the end of the section in the input buffer, and contents is the -// extracted text that was shifted over one tab. It will need to be rendered at -// the end of the document. -func scanFootnote(p *Markdown, data []byte, i, indentSize int) (blockStart, blockEnd int, contents []byte, hasBlock bool) { - if i == 0 || len(data) == 0 { - return - } - - // skip leading whitespace on first line - for i < len(data) && data[i] == ' ' { - i++ - } - - blockStart = i - - // find the end of the line - blockEnd = i - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // get working buffer - var raw bytes.Buffer - - // put the first line into the working buffer - raw.Write(data[blockEnd:i]) - blockEnd = i - - // process the following lines - containsBlankLine := false - -gatherLines: - for blockEnd < len(data) { - i++ - - // find the end of this line - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // if it is an empty line, guess that it is part of this item - // and move on to the next line - if p.isEmpty(data[blockEnd:i]) > 0 { - containsBlankLine = true - blockEnd = i - continue - } - - n := 0 - if n = isIndented(data[blockEnd:i], indentSize); n == 0 { - // this is the end of the block. - // we don't want to include this last line in the index. - break gatherLines - } - - // if there were blank lines before this one, insert a new one now - if containsBlankLine { - raw.WriteByte('\n') - containsBlankLine = false - } - - // get rid of that first tab, write to buffer - raw.Write(data[blockEnd+n : i]) - hasBlock = true - - blockEnd = i - } - - if data[blockEnd-1] != '\n' { - raw.WriteByte('\n') - } - - contents = raw.Bytes() - - return -} - -// -// -// Miscellaneous helper functions -// -// - -// Test if a character is a punctuation symbol. -// Taken from a private function in regexp in the stdlib. -func ispunct(c byte) bool { - for _, r := range []byte("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") { - if c == r { - return true - } - } - return false -} - -// Test if a character is a whitespace character. -func isspace(c byte) bool { - return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' -} - -// Test if a character is letter. -func isletter(c byte) bool { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') -} - -// Test if a character is a letter or a digit. -// TODO: check when this is looking for ASCII alnum and when it should use unicode -func isalnum(c byte) bool { - return (c >= '0' && c <= '9') || isletter(c) -} - -// Replace tab characters with spaces, aligning to the next TAB_SIZE column. -// always ends output with a newline -func expandTabs(out *bytes.Buffer, line []byte, tabSize int) { - // first, check for common cases: no tabs, or only tabs at beginning of line - i, prefix := 0, 0 - slowcase := false - for i = 0; i < len(line); i++ { - if line[i] == '\t' { - if prefix == i { - prefix++ - } else { - slowcase = true - break - } - } - } - - // no need to decode runes if all tabs are at the beginning of the line - if !slowcase { - for i = 0; i < prefix*tabSize; i++ { - out.WriteByte(' ') - } - out.Write(line[prefix:]) - return - } - - // the slow case: we need to count runes to figure out how - // many spaces to insert for each tab - column := 0 - i = 0 - for i < len(line) { - start := i - for i < len(line) && line[i] != '\t' { - _, size := utf8.DecodeRune(line[i:]) - i += size - column++ - } - - if i > start { - out.Write(line[start:i]) - } - - if i >= len(line) { - break - } - - for { - out.WriteByte(' ') - column++ - if column%tabSize == 0 { - break - } - } - - i++ - } -} - -// Find if a line counts as indented or not. -// Returns number of characters the indent is (0 = not indented). -func isIndented(data []byte, indentSize int) int { - if len(data) == 0 { - return 0 - } - if data[0] == '\t' { - return 1 - } - if len(data) < indentSize { - return 0 - } - for i := 0; i < indentSize; i++ { - if data[i] != ' ' { - return 0 - } - } - return indentSize -} - -// Create a url-safe slug for fragments -func slugify(in []byte) []byte { - if len(in) == 0 { - return in - } - out := make([]byte, 0, len(in)) - sym := false - - for _, ch := range in { - if isalnum(ch) { - sym = false - out = append(out, ch) - } else if sym { - continue - } else { - out = append(out, '-') - sym = true - } - } - var a, b int - var ch byte - for a, ch = range out { - if ch != '-' { - break - } - } - for b = len(out) - 1; b > 0; b-- { - if out[b] != '-' { - break - } - } - return out[a : b+1] -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go deleted file mode 100644 index 51b9e8c1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go +++ /dev/null @@ -1,354 +0,0 @@ -package blackfriday - -import ( - "bytes" - "fmt" -) - -// NodeType specifies a type of a single node of a syntax tree. Usually one -// node (and its type) corresponds to a single markdown feature, e.g. emphasis -// or code block. -type NodeType int - -// Constants for identifying different types of nodes. See NodeType. -const ( - Document NodeType = iota - BlockQuote - List - Item - Paragraph - Heading - HorizontalRule - Emph - Strong - Del - Link - Image - Text - HTMLBlock - CodeBlock - Softbreak - Hardbreak - Code - HTMLSpan - Table - TableCell - TableHead - TableBody - TableRow -) - -var nodeTypeNames = []string{ - Document: "Document", - BlockQuote: "BlockQuote", - List: "List", - Item: "Item", - Paragraph: "Paragraph", - Heading: "Heading", - HorizontalRule: "HorizontalRule", - Emph: "Emph", - Strong: "Strong", - Del: "Del", - Link: "Link", - Image: "Image", - Text: "Text", - HTMLBlock: "HTMLBlock", - CodeBlock: "CodeBlock", - Softbreak: "Softbreak", - Hardbreak: "Hardbreak", - Code: "Code", - HTMLSpan: "HTMLSpan", - Table: "Table", - TableCell: "TableCell", - TableHead: "TableHead", - TableBody: "TableBody", - TableRow: "TableRow", -} - -func (t NodeType) String() string { - return nodeTypeNames[t] -} - -// ListData contains fields relevant to a List and Item node type. -type ListData struct { - ListFlags ListType - Tight bool // Skip

    s around list item data if true - BulletChar byte // '*', '+' or '-' in bullet lists - Delimiter byte // '.' or ')' after the number in ordered lists - RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering - IsFootnotesList bool // This is a list of footnotes -} - -// LinkData contains fields relevant to a Link node type. -type LinkData struct { - Destination []byte // Destination is what goes into a href - Title []byte // Title is the tooltip thing that goes in a title attribute - NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote - Footnote *Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. -} - -// CodeBlockData contains fields relevant to a CodeBlock node type. -type CodeBlockData struct { - IsFenced bool // Specifies whether it's a fenced code block or an indented one - Info []byte // This holds the info string - FenceChar byte - FenceLength int - FenceOffset int -} - -// TableCellData contains fields relevant to a TableCell node type. -type TableCellData struct { - IsHeader bool // This tells if it's under the header row - Align CellAlignFlags // This holds the value for align attribute -} - -// HeadingData contains fields relevant to a Heading node type. -type HeadingData struct { - Level int // This holds the heading level number - HeadingID string // This might hold heading ID, if present - IsTitleblock bool // Specifies whether it's a title block -} - -// Node is a single element in the abstract syntax tree of the parsed document. -// It holds connections to the structurally neighboring nodes and, for certain -// types of nodes, additional information that might be needed when rendering. -type Node struct { - Type NodeType // Determines the type of the node - Parent *Node // Points to the parent - FirstChild *Node // Points to the first child, if any - LastChild *Node // Points to the last child, if any - Prev *Node // Previous sibling; nil if it's the first child - Next *Node // Next sibling; nil if it's the last child - - Literal []byte // Text contents of the leaf nodes - - HeadingData // Populated if Type is Heading - ListData // Populated if Type is List - CodeBlockData // Populated if Type is CodeBlock - LinkData // Populated if Type is Link - TableCellData // Populated if Type is TableCell - - content []byte // Markdown content of the block nodes - open bool // Specifies an open block node that has not been finished to process yet -} - -// NewNode allocates a node of a specified type. -func NewNode(typ NodeType) *Node { - return &Node{ - Type: typ, - open: true, - } -} - -func (n *Node) String() string { - ellipsis := "" - snippet := n.Literal - if len(snippet) > 16 { - snippet = snippet[:16] - ellipsis = "..." - } - return fmt.Sprintf("%s: '%s%s'", n.Type, snippet, ellipsis) -} - -// Unlink removes node 'n' from the tree. -// It panics if the node is nil. -func (n *Node) Unlink() { - if n.Prev != nil { - n.Prev.Next = n.Next - } else if n.Parent != nil { - n.Parent.FirstChild = n.Next - } - if n.Next != nil { - n.Next.Prev = n.Prev - } else if n.Parent != nil { - n.Parent.LastChild = n.Prev - } - n.Parent = nil - n.Next = nil - n.Prev = nil -} - -// AppendChild adds a node 'child' as a child of 'n'. -// It panics if either node is nil. -func (n *Node) AppendChild(child *Node) { - child.Unlink() - child.Parent = n - if n.LastChild != nil { - n.LastChild.Next = child - child.Prev = n.LastChild - n.LastChild = child - } else { - n.FirstChild = child - n.LastChild = child - } -} - -// InsertBefore inserts 'sibling' immediately before 'n'. -// It panics if either node is nil. -func (n *Node) InsertBefore(sibling *Node) { - sibling.Unlink() - sibling.Prev = n.Prev - if sibling.Prev != nil { - sibling.Prev.Next = sibling - } - sibling.Next = n - n.Prev = sibling - sibling.Parent = n.Parent - if sibling.Prev == nil { - sibling.Parent.FirstChild = sibling - } -} - -func (n *Node) isContainer() bool { - switch n.Type { - case Document: - fallthrough - case BlockQuote: - fallthrough - case List: - fallthrough - case Item: - fallthrough - case Paragraph: - fallthrough - case Heading: - fallthrough - case Emph: - fallthrough - case Strong: - fallthrough - case Del: - fallthrough - case Link: - fallthrough - case Image: - fallthrough - case Table: - fallthrough - case TableHead: - fallthrough - case TableBody: - fallthrough - case TableRow: - fallthrough - case TableCell: - return true - default: - return false - } -} - -func (n *Node) canContain(t NodeType) bool { - if n.Type == List { - return t == Item - } - if n.Type == Document || n.Type == BlockQuote || n.Type == Item { - return t != Item - } - if n.Type == Table { - return t == TableHead || t == TableBody - } - if n.Type == TableHead || n.Type == TableBody { - return t == TableRow - } - if n.Type == TableRow { - return t == TableCell - } - return false -} - -// WalkStatus allows NodeVisitor to have some control over the tree traversal. -// It is returned from NodeVisitor and different values allow Node.Walk to -// decide which node to go to next. -type WalkStatus int - -const ( - // GoToNext is the default traversal of every node. - GoToNext WalkStatus = iota - // SkipChildren tells walker to skip all children of current node. - SkipChildren - // Terminate tells walker to terminate the traversal. - Terminate -) - -// NodeVisitor is a callback to be called when traversing the syntax tree. -// Called twice for every node: once with entering=true when the branch is -// first visited, then with entering=false after all the children are done. -type NodeVisitor func(node *Node, entering bool) WalkStatus - -// Walk is a convenience method that instantiates a walker and starts a -// traversal of subtree rooted at n. -func (n *Node) Walk(visitor NodeVisitor) { - w := newNodeWalker(n) - for w.current != nil { - status := visitor(w.current, w.entering) - switch status { - case GoToNext: - w.next() - case SkipChildren: - w.entering = false - w.next() - case Terminate: - return - } - } -} - -type nodeWalker struct { - current *Node - root *Node - entering bool -} - -func newNodeWalker(root *Node) *nodeWalker { - return &nodeWalker{ - current: root, - root: root, - entering: true, - } -} - -func (nw *nodeWalker) next() { - if (!nw.current.isContainer() || !nw.entering) && nw.current == nw.root { - nw.current = nil - return - } - if nw.entering && nw.current.isContainer() { - if nw.current.FirstChild != nil { - nw.current = nw.current.FirstChild - nw.entering = true - } else { - nw.entering = false - } - } else if nw.current.Next == nil { - nw.current = nw.current.Parent - nw.entering = false - } else { - nw.current = nw.current.Next - nw.entering = true - } -} - -func dump(ast *Node) { - fmt.Println(dumpString(ast)) -} - -func dumpR(ast *Node, depth int) string { - if ast == nil { - return "" - } - indent := bytes.Repeat([]byte("\t"), depth) - content := ast.Literal - if content == nil { - content = ast.content - } - result := fmt.Sprintf("%s%s(%q)\n", indent, ast.Type, content) - for n := ast.FirstChild; n != nil; n = n.Next { - result += dumpR(n, depth+1) - } - return result -} - -func dumpString(ast *Node) string { - return dumpR(ast, 0) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go deleted file mode 100644 index 3a220e94..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go +++ /dev/null @@ -1,457 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// -// SmartyPants rendering -// -// - -package blackfriday - -import ( - "bytes" - "io" -) - -// SPRenderer is a struct containing state of a Smartypants renderer. -type SPRenderer struct { - inSingleQuote bool - inDoubleQuote bool - callbacks [256]smartCallback -} - -func wordBoundary(c byte) bool { - return c == 0 || isspace(c) || ispunct(c) -} - -func tolower(c byte) byte { - if c >= 'A' && c <= 'Z' { - return c - 'A' + 'a' - } - return c -} - -func isdigit(c byte) bool { - return c >= '0' && c <= '9' -} - -func smartQuoteHelper(out *bytes.Buffer, previousChar byte, nextChar byte, quote byte, isOpen *bool, addNBSP bool) bool { - // edge of the buffer is likely to be a tag that we don't get to see, - // so we treat it like text sometimes - - // enumerate all sixteen possibilities for (previousChar, nextChar) - // each can be one of {0, space, punct, other} - switch { - case previousChar == 0 && nextChar == 0: - // context is not any help here, so toggle - *isOpen = !*isOpen - case isspace(previousChar) && nextChar == 0: - // [ "] might be [ "foo...] - *isOpen = true - case ispunct(previousChar) && nextChar == 0: - // [!"] hmm... could be [Run!"] or [("...] - *isOpen = false - case /* isnormal(previousChar) && */ nextChar == 0: - // [a"] is probably a close - *isOpen = false - case previousChar == 0 && isspace(nextChar): - // [" ] might be [...foo" ] - *isOpen = false - case isspace(previousChar) && isspace(nextChar): - // [ " ] context is not any help here, so toggle - *isOpen = !*isOpen - case ispunct(previousChar) && isspace(nextChar): - // [!" ] is probably a close - *isOpen = false - case /* isnormal(previousChar) && */ isspace(nextChar): - // [a" ] this is one of the easy cases - *isOpen = false - case previousChar == 0 && ispunct(nextChar): - // ["!] hmm... could be ["$1.95] or ["!...] - *isOpen = false - case isspace(previousChar) && ispunct(nextChar): - // [ "!] looks more like [ "$1.95] - *isOpen = true - case ispunct(previousChar) && ispunct(nextChar): - // [!"!] context is not any help here, so toggle - *isOpen = !*isOpen - case /* isnormal(previousChar) && */ ispunct(nextChar): - // [a"!] is probably a close - *isOpen = false - case previousChar == 0 /* && isnormal(nextChar) */ : - // ["a] is probably an open - *isOpen = true - case isspace(previousChar) /* && isnormal(nextChar) */ : - // [ "a] this is one of the easy cases - *isOpen = true - case ispunct(previousChar) /* && isnormal(nextChar) */ : - // [!"a] is probably an open - *isOpen = true - default: - // [a'b] maybe a contraction? - *isOpen = false - } - - // Note that with the limited lookahead, this non-breaking - // space will also be appended to single double quotes. - if addNBSP && !*isOpen { - out.WriteString(" ") - } - - out.WriteByte('&') - if *isOpen { - out.WriteByte('l') - } else { - out.WriteByte('r') - } - out.WriteByte(quote) - out.WriteString("quo;") - - if addNBSP && *isOpen { - out.WriteString(" ") - } - - return true -} - -func (r *SPRenderer) smartSingleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 { - t1 := tolower(text[1]) - - if t1 == '\'' { - nextChar := byte(0) - if len(text) >= 3 { - nextChar = text[2] - } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote, false) { - return 1 - } - } - - if (t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd') && (len(text) < 3 || wordBoundary(text[2])) { - out.WriteString("’") - return 0 - } - - if len(text) >= 3 { - t2 := tolower(text[2]) - - if ((t1 == 'r' && t2 == 'e') || (t1 == 'l' && t2 == 'l') || (t1 == 'v' && t2 == 'e')) && - (len(text) < 4 || wordBoundary(text[3])) { - out.WriteString("’") - return 0 - } - } - } - - nextChar := byte(0) - if len(text) > 1 { - nextChar = text[1] - } - if smartQuoteHelper(out, previousChar, nextChar, 's', &r.inSingleQuote, false) { - return 0 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartParens(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 { - t1 := tolower(text[1]) - t2 := tolower(text[2]) - - if t1 == 'c' && t2 == ')' { - out.WriteString("©") - return 2 - } - - if t1 == 'r' && t2 == ')' { - out.WriteString("®") - return 2 - } - - if len(text) >= 4 && t1 == 't' && t2 == 'm' && text[3] == ')' { - out.WriteString("™") - return 3 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDash(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 { - if text[1] == '-' { - out.WriteString("—") - return 1 - } - - if wordBoundary(previousChar) && wordBoundary(text[1]) { - out.WriteString("–") - return 0 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDashLatex(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 && text[1] == '-' && text[2] == '-' { - out.WriteString("—") - return 2 - } - if len(text) >= 2 && text[1] == '-' { - out.WriteString("–") - return 1 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartAmpVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte, addNBSP bool) int { - if bytes.HasPrefix(text, []byte(""")) { - nextChar := byte(0) - if len(text) >= 7 { - nextChar = text[6] - } - if smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote, addNBSP) { - return 5 - } - } - - if bytes.HasPrefix(text, []byte("�")) { - return 3 - } - - out.WriteByte('&') - return 0 -} - -func (r *SPRenderer) smartAmp(angledQuotes, addNBSP bool) func(*bytes.Buffer, byte, []byte) int { - var quote byte = 'd' - if angledQuotes { - quote = 'a' - } - - return func(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartAmpVariant(out, previousChar, text, quote, addNBSP) - } -} - -func (r *SPRenderer) smartPeriod(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 && text[1] == '.' && text[2] == '.' { - out.WriteString("…") - return 2 - } - - if len(text) >= 5 && text[1] == ' ' && text[2] == '.' && text[3] == ' ' && text[4] == '.' { - out.WriteString("…") - return 4 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartBacktick(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 && text[1] == '`' { - nextChar := byte(0) - if len(text) >= 3 { - nextChar = text[2] - } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote, false) { - return 1 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartNumberGeneric(out *bytes.Buffer, previousChar byte, text []byte) int { - if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { - // is it of the form digits/digits(word boundary)?, i.e., \d+/\d+\b - // note: check for regular slash (/) or fraction slash (â„, 0x2044, or 0xe2 81 84 in utf-8) - // and avoid changing dates like 1/23/2005 into fractions. - numEnd := 0 - for len(text) > numEnd && isdigit(text[numEnd]) { - numEnd++ - } - if numEnd == 0 { - out.WriteByte(text[0]) - return 0 - } - denStart := numEnd + 1 - if len(text) > numEnd+3 && text[numEnd] == 0xe2 && text[numEnd+1] == 0x81 && text[numEnd+2] == 0x84 { - denStart = numEnd + 3 - } else if len(text) < numEnd+2 || text[numEnd] != '/' { - out.WriteByte(text[0]) - return 0 - } - denEnd := denStart - for len(text) > denEnd && isdigit(text[denEnd]) { - denEnd++ - } - if denEnd == denStart { - out.WriteByte(text[0]) - return 0 - } - if len(text) == denEnd || wordBoundary(text[denEnd]) && text[denEnd] != '/' { - out.WriteString("") - out.Write(text[:numEnd]) - out.WriteString("") - out.Write(text[denStart:denEnd]) - out.WriteString("") - return denEnd - 1 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartNumber(out *bytes.Buffer, previousChar byte, text []byte) int { - if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { - if text[0] == '1' && text[1] == '/' && text[2] == '2' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' { - out.WriteString("½") - return 2 - } - } - - if text[0] == '1' && text[1] == '/' && text[2] == '4' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' || (len(text) >= 5 && tolower(text[3]) == 't' && tolower(text[4]) == 'h') { - out.WriteString("¼") - return 2 - } - } - - if text[0] == '3' && text[1] == '/' && text[2] == '4' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' || (len(text) >= 6 && tolower(text[3]) == 't' && tolower(text[4]) == 'h' && tolower(text[5]) == 's') { - out.WriteString("¾") - return 2 - } - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDoubleQuoteVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { - nextChar := byte(0) - if len(text) > 1 { - nextChar = text[1] - } - if !smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote, false) { - out.WriteString(""") - } - - return 0 -} - -func (r *SPRenderer) smartDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartDoubleQuoteVariant(out, previousChar, text, 'd') -} - -func (r *SPRenderer) smartAngledDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartDoubleQuoteVariant(out, previousChar, text, 'a') -} - -func (r *SPRenderer) smartLeftAngle(out *bytes.Buffer, previousChar byte, text []byte) int { - i := 0 - - for i < len(text) && text[i] != '>' { - i++ - } - - out.Write(text[:i+1]) - return i -} - -type smartCallback func(out *bytes.Buffer, previousChar byte, text []byte) int - -// NewSmartypantsRenderer constructs a Smartypants renderer object. -func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer { - var ( - r SPRenderer - - smartAmpAngled = r.smartAmp(true, false) - smartAmpAngledNBSP = r.smartAmp(true, true) - smartAmpRegular = r.smartAmp(false, false) - smartAmpRegularNBSP = r.smartAmp(false, true) - - addNBSP = flags&SmartypantsQuotesNBSP != 0 - ) - - if flags&SmartypantsAngledQuotes == 0 { - r.callbacks['"'] = r.smartDoubleQuote - if !addNBSP { - r.callbacks['&'] = smartAmpRegular - } else { - r.callbacks['&'] = smartAmpRegularNBSP - } - } else { - r.callbacks['"'] = r.smartAngledDoubleQuote - if !addNBSP { - r.callbacks['&'] = smartAmpAngled - } else { - r.callbacks['&'] = smartAmpAngledNBSP - } - } - r.callbacks['\''] = r.smartSingleQuote - r.callbacks['('] = r.smartParens - if flags&SmartypantsDashes != 0 { - if flags&SmartypantsLatexDashes == 0 { - r.callbacks['-'] = r.smartDash - } else { - r.callbacks['-'] = r.smartDashLatex - } - } - r.callbacks['.'] = r.smartPeriod - if flags&SmartypantsFractions == 0 { - r.callbacks['1'] = r.smartNumber - r.callbacks['3'] = r.smartNumber - } else { - for ch := '1'; ch <= '9'; ch++ { - r.callbacks[ch] = r.smartNumberGeneric - } - } - r.callbacks['<'] = r.smartLeftAngle - r.callbacks['`'] = r.smartBacktick - return &r -} - -// Process is the entry point of the Smartypants renderer. -func (r *SPRenderer) Process(w io.Writer, text []byte) { - mark := 0 - for i := 0; i < len(text); i++ { - if action := r.callbacks[text[i]]; action != nil { - if i > mark { - w.Write(text[mark:i]) - } - previousChar := byte(0) - if i > 0 { - previousChar = text[i-1] - } - var tmp bytes.Buffer - i += action(&tmp, previousChar, text[i:]) - w.Write(tmp.Bytes()) - mark = i + 1 - } - } - if mark < len(text) { - w.Write(text[mark:]) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE deleted file mode 100644 index c35c17af..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2015 Dmitri Shuralyov - -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/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md deleted file mode 100644 index 670bf0fe..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md +++ /dev/null @@ -1,36 +0,0 @@ -sanitized_anchor_name -===================== - -[![Build Status](https://travis-ci.org/shurcooL/sanitized_anchor_name.svg?branch=master)](https://travis-ci.org/shurcooL/sanitized_anchor_name) [![GoDoc](https://godoc.org/github.com/shurcooL/sanitized_anchor_name?status.svg)](https://godoc.org/github.com/shurcooL/sanitized_anchor_name) - -Package sanitized_anchor_name provides a func to create sanitized anchor names. - -Its logic can be reused by multiple packages to create interoperable anchor names -and links to those anchors. - -At this time, it does not try to ensure that generated anchor names -are unique, that responsibility falls on the caller. - -Installation ------------- - -```bash -go get -u github.com/shurcooL/sanitized_anchor_name -``` - -Example -------- - -```Go -anchorName := sanitized_anchor_name.Create("This is a header") - -fmt.Println(anchorName) - -// Output: -// this-is-a-header -``` - -License -------- - -- [MIT License](LICENSE) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go deleted file mode 100644 index 6a77d124..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package sanitized_anchor_name provides a func to create sanitized anchor names. -// -// Its logic can be reused by multiple packages to create interoperable anchor names -// and links to those anchors. -// -// At this time, it does not try to ensure that generated anchor names -// are unique, that responsibility falls on the caller. -package sanitized_anchor_name // import "github.com/shurcooL/sanitized_anchor_name" - -import "unicode" - -// Create returns a sanitized anchor name for the given text. -func Create(text string) string { - var anchorName []rune - var futureDash = false - for _, r := range text { - switch { - case unicode.IsLetter(r) || unicode.IsNumber(r): - if futureDash && len(anchorName) > 0 { - anchorName = append(anchorName, '-') - } - futureDash = false - anchorName = append(anchorName, unicode.ToLower(r)) - default: - futureDash = true - } - } - return string(anchorName) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE new file mode 100644 index 00000000..bc52e96f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2012-2016 Dave Collins + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go new file mode 100644 index 00000000..79299478 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go @@ -0,0 +1,145 @@ +// Copyright (c) 2015-2016 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is not running on Google App Engine, compiled by GopherJS, and +// "-tags safe" is not added to the go build command line. The "disableunsafe" +// tag is deprecated and thus should not be used. +// Go versions prior to 1.4 are disabled because they use a different layout +// for interfaces which make the implementation of unsafeReflectValue more complex. +// +build !js,!appengine,!safe,!disableunsafe,go1.4 + +package spew + +import ( + "reflect" + "unsafe" +) + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = false + + // ptrSize is the size of a pointer on the current arch. + ptrSize = unsafe.Sizeof((*byte)(nil)) +) + +type flag uintptr + +var ( + // flagRO indicates whether the value field of a reflect.Value + // is read-only. + flagRO flag + + // flagAddr indicates whether the address of the reflect.Value's + // value may be taken. + flagAddr flag +) + +// flagKindMask holds the bits that make up the kind +// part of the flags field. In all the supported versions, +// it is in the lower 5 bits. +const flagKindMask = flag(0x1f) + +// Different versions of Go have used different +// bit layouts for the flags type. This table +// records the known combinations. +var okFlags = []struct { + ro, addr flag +}{{ + // From Go 1.4 to 1.5 + ro: 1 << 5, + addr: 1 << 7, +}, { + // Up to Go tip. + ro: 1<<5 | 1<<6, + addr: 1 << 8, +}} + +var flagValOffset = func() uintptr { + field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") + if !ok { + panic("reflect.Value has no flag field") + } + return field.Offset +}() + +// flagField returns a pointer to the flag field of a reflect.Value. +func flagField(v *reflect.Value) *flag { + return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) +} + +// unsafeReflectValue converts the passed reflect.Value into a one that bypasses +// the typical safety restrictions preventing access to unaddressable and +// unexported data. It works by digging the raw pointer to the underlying +// value out of the protected value and generating a new unprotected (unsafe) +// reflect.Value to it. +// +// This allows us to check for implementations of the Stringer and error +// interfaces to be used for pretty printing ordinarily unaddressable and +// inaccessible values such as unexported struct fields. +func unsafeReflectValue(v reflect.Value) reflect.Value { + if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { + return v + } + flagFieldPtr := flagField(&v) + *flagFieldPtr &^= flagRO + *flagFieldPtr |= flagAddr + return v +} + +// Sanity checks against future reflect package changes +// to the type or semantics of the Value.flag field. +func init() { + field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") + if !ok { + panic("reflect.Value has no flag field") + } + if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { + panic("reflect.Value flag field has changed kind") + } + type t0 int + var t struct { + A t0 + // t0 will have flagEmbedRO set. + t0 + // a will have flagStickyRO set + a t0 + } + vA := reflect.ValueOf(t).FieldByName("A") + va := reflect.ValueOf(t).FieldByName("a") + vt0 := reflect.ValueOf(t).FieldByName("t0") + + // Infer flagRO from the difference between the flags + // for the (otherwise identical) fields in t. + flagPublic := *flagField(&vA) + flagWithRO := *flagField(&va) | *flagField(&vt0) + flagRO = flagPublic ^ flagWithRO + + // Infer flagAddr from the difference between a value + // taken from a pointer and not. + vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") + flagNoPtr := *flagField(&vA) + flagPtr := *flagField(&vPtrA) + flagAddr = flagNoPtr ^ flagPtr + + // Check that the inferred flags tally with one of the known versions. + for _, f := range okFlags { + if flagRO == f.ro && flagAddr == f.addr { + return + } + } + panic("reflect.Value read-only flag has changed semantics") +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go new file mode 100644 index 00000000..205c28d6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go @@ -0,0 +1,38 @@ +// Copyright (c) 2015-2016 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is running on Google App Engine, compiled by GopherJS, or +// "-tags safe" is added to the go build command line. The "disableunsafe" +// tag is deprecated and thus should not be used. +// +build js appengine safe disableunsafe !go1.4 + +package spew + +import "reflect" + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = true +) + +// unsafeReflectValue typically converts the passed reflect.Value into a one +// that bypasses the typical safety restrictions preventing access to +// unaddressable and unexported data. However, doing this relies on access to +// the unsafe package. This is a stub version which simply returns the passed +// reflect.Value when the unsafe package is not available. +func unsafeReflectValue(v reflect.Value) reflect.Value { + return v +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go new file mode 100644 index 00000000..1be8ce94 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "io" + "reflect" + "sort" + "strconv" +) + +// Some constants in the form of bytes to avoid string overhead. This mirrors +// the technique used in the fmt package. +var ( + panicBytes = []byte("(PANIC=") + plusBytes = []byte("+") + iBytes = []byte("i") + trueBytes = []byte("true") + falseBytes = []byte("false") + interfaceBytes = []byte("(interface {})") + commaNewlineBytes = []byte(",\n") + newlineBytes = []byte("\n") + openBraceBytes = []byte("{") + openBraceNewlineBytes = []byte("{\n") + closeBraceBytes = []byte("}") + asteriskBytes = []byte("*") + colonBytes = []byte(":") + colonSpaceBytes = []byte(": ") + openParenBytes = []byte("(") + closeParenBytes = []byte(")") + spaceBytes = []byte(" ") + pointerChainBytes = []byte("->") + nilAngleBytes = []byte("") + maxNewlineBytes = []byte("\n") + maxShortBytes = []byte("") + circularBytes = []byte("") + circularShortBytes = []byte("") + invalidAngleBytes = []byte("") + openBracketBytes = []byte("[") + closeBracketBytes = []byte("]") + percentBytes = []byte("%") + precisionBytes = []byte(".") + openAngleBytes = []byte("<") + closeAngleBytes = []byte(">") + openMapBytes = []byte("map[") + closeMapBytes = []byte("]") + lenEqualsBytes = []byte("len=") + capEqualsBytes = []byte("cap=") +) + +// hexDigits is used to map a decimal value to a hex digit. +var hexDigits = "0123456789abcdef" + +// catchPanic handles any panics that might occur during the handleMethods +// calls. +func catchPanic(w io.Writer, v reflect.Value) { + if err := recover(); err != nil { + w.Write(panicBytes) + fmt.Fprintf(w, "%v", err) + w.Write(closeParenBytes) + } +} + +// handleMethods attempts to call the Error and String methods on the underlying +// type the passed reflect.Value represents and outputes the result to Writer w. +// +// It handles panics in any called methods by catching and displaying the error +// as the formatted value. +func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { + // We need an interface to check if the type implements the error or + // Stringer interface. However, the reflect package won't give us an + // interface on certain things like unexported struct fields in order + // to enforce visibility rules. We use unsafe, when it's available, + // to bypass these restrictions since this package does not mutate the + // values. + if !v.CanInterface() { + if UnsafeDisabled { + return false + } + + v = unsafeReflectValue(v) + } + + // Choose whether or not to do error and Stringer interface lookups against + // the base type or a pointer to the base type depending on settings. + // Technically calling one of these methods with a pointer receiver can + // mutate the value, however, types which choose to satisify an error or + // Stringer interface with a pointer receiver should not be mutating their + // state inside these interface methods. + if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { + v = unsafeReflectValue(v) + } + if v.CanAddr() { + v = v.Addr() + } + + // Is it an error or Stringer? + switch iface := v.Interface().(type) { + case error: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.Error())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + + w.Write([]byte(iface.Error())) + return true + + case fmt.Stringer: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.String())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + w.Write([]byte(iface.String())) + return true + } + return false +} + +// printBool outputs a boolean value as true or false to Writer w. +func printBool(w io.Writer, val bool) { + if val { + w.Write(trueBytes) + } else { + w.Write(falseBytes) + } +} + +// printInt outputs a signed integer value to Writer w. +func printInt(w io.Writer, val int64, base int) { + w.Write([]byte(strconv.FormatInt(val, base))) +} + +// printUint outputs an unsigned integer value to Writer w. +func printUint(w io.Writer, val uint64, base int) { + w.Write([]byte(strconv.FormatUint(val, base))) +} + +// printFloat outputs a floating point value using the specified precision, +// which is expected to be 32 or 64bit, to Writer w. +func printFloat(w io.Writer, val float64, precision int) { + w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) +} + +// printComplex outputs a complex value using the specified float precision +// for the real and imaginary parts to Writer w. +func printComplex(w io.Writer, c complex128, floatPrecision int) { + r := real(c) + w.Write(openParenBytes) + w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) + i := imag(c) + if i >= 0 { + w.Write(plusBytes) + } + w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) + w.Write(iBytes) + w.Write(closeParenBytes) +} + +// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' +// prefix to Writer w. +func printHexPtr(w io.Writer, p uintptr) { + // Null pointer. + num := uint64(p) + if num == 0 { + w.Write(nilAngleBytes) + return + } + + // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix + buf := make([]byte, 18) + + // It's simpler to construct the hex string right to left. + base := uint64(16) + i := len(buf) - 1 + for num >= base { + buf[i] = hexDigits[num%base] + num /= base + i-- + } + buf[i] = hexDigits[num] + + // Add '0x' prefix. + i-- + buf[i] = 'x' + i-- + buf[i] = '0' + + // Strip unused leading bytes. + buf = buf[i:] + w.Write(buf) +} + +// valuesSorter implements sort.Interface to allow a slice of reflect.Value +// elements to be sorted. +type valuesSorter struct { + values []reflect.Value + strings []string // either nil or same len and values + cs *ConfigState +} + +// newValuesSorter initializes a valuesSorter instance, which holds a set of +// surrogate keys on which the data should be sorted. It uses flags in +// ConfigState to decide if and how to populate those surrogate keys. +func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { + vs := &valuesSorter{values: values, cs: cs} + if canSortSimply(vs.values[0].Kind()) { + return vs + } + if !cs.DisableMethods { + vs.strings = make([]string, len(values)) + for i := range vs.values { + b := bytes.Buffer{} + if !handleMethods(cs, &b, vs.values[i]) { + vs.strings = nil + break + } + vs.strings[i] = b.String() + } + } + if vs.strings == nil && cs.SpewKeys { + vs.strings = make([]string, len(values)) + for i := range vs.values { + vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) + } + } + return vs +} + +// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted +// directly, or whether it should be considered for sorting by surrogate keys +// (if the ConfigState allows it). +func canSortSimply(kind reflect.Kind) bool { + // This switch parallels valueSortLess, except for the default case. + switch kind { + case reflect.Bool: + return true + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + return true + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return true + case reflect.Float32, reflect.Float64: + return true + case reflect.String: + return true + case reflect.Uintptr: + return true + case reflect.Array: + return true + } + return false +} + +// Len returns the number of values in the slice. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Len() int { + return len(s.values) +} + +// Swap swaps the values at the passed indices. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Swap(i, j int) { + s.values[i], s.values[j] = s.values[j], s.values[i] + if s.strings != nil { + s.strings[i], s.strings[j] = s.strings[j], s.strings[i] + } +} + +// valueSortLess returns whether the first value should sort before the second +// value. It is used by valueSorter.Less as part of the sort.Interface +// implementation. +func valueSortLess(a, b reflect.Value) bool { + switch a.Kind() { + case reflect.Bool: + return !a.Bool() && b.Bool() + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + return a.Int() < b.Int() + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return a.Uint() < b.Uint() + case reflect.Float32, reflect.Float64: + return a.Float() < b.Float() + case reflect.String: + return a.String() < b.String() + case reflect.Uintptr: + return a.Uint() < b.Uint() + case reflect.Array: + // Compare the contents of both arrays. + l := a.Len() + for i := 0; i < l; i++ { + av := a.Index(i) + bv := b.Index(i) + if av.Interface() == bv.Interface() { + continue + } + return valueSortLess(av, bv) + } + } + return a.String() < b.String() +} + +// Less returns whether the value at index i should sort before the +// value at index j. It is part of the sort.Interface implementation. +func (s *valuesSorter) Less(i, j int) bool { + if s.strings == nil { + return valueSortLess(s.values[i], s.values[j]) + } + return s.strings[i] < s.strings[j] +} + +// sortValues is a sort function that handles both native types and any type that +// can be converted to error or Stringer. Other inputs are sorted according to +// their Value.String() value to ensure display stability. +func sortValues(values []reflect.Value, cs *ConfigState) { + if len(values) == 0 { + return + } + sort.Sort(newValuesSorter(values, cs)) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/config.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/config.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/config.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/config.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go new file mode 100644 index 00000000..f78d89fc --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go @@ -0,0 +1,509 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "encoding/hex" + "fmt" + "io" + "os" + "reflect" + "regexp" + "strconv" + "strings" +) + +var ( + // uint8Type is a reflect.Type representing a uint8. It is used to + // convert cgo types to uint8 slices for hexdumping. + uint8Type = reflect.TypeOf(uint8(0)) + + // cCharRE is a regular expression that matches a cgo char. + // It is used to detect character arrays to hexdump them. + cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`) + + // cUnsignedCharRE is a regular expression that matches a cgo unsigned + // char. It is used to detect unsigned character arrays to hexdump + // them. + cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`) + + // cUint8tCharRE is a regular expression that matches a cgo uint8_t. + // It is used to detect uint8_t arrays to hexdump them. + cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`) +) + +// dumpState contains information about the state of a dump operation. +type dumpState struct { + w io.Writer + depth int + pointers map[uintptr]int + ignoreNextType bool + ignoreNextIndent bool + cs *ConfigState +} + +// indent performs indentation according to the depth level and cs.Indent +// option. +func (d *dumpState) indent() { + if d.ignoreNextIndent { + d.ignoreNextIndent = false + return + } + d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) +} + +// unpackValue returns values inside of non-nil interfaces when possible. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface && !v.IsNil() { + v = v.Elem() + } + return v +} + +// dumpPtr handles formatting of pointers by indirecting them as necessary. +func (d *dumpState) dumpPtr(v reflect.Value) { + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range d.pointers { + if depth >= d.depth { + delete(d.pointers, k) + } + } + + // Keep list of all dereferenced pointers to show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by dereferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := d.pointers[addr]; ok && pd < d.depth { + cycleFound = true + indirects-- + break + } + d.pointers[addr] = d.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type information. + d.w.Write(openParenBytes) + d.w.Write(bytes.Repeat(asteriskBytes, indirects)) + d.w.Write([]byte(ve.Type().String())) + d.w.Write(closeParenBytes) + + // Display pointer information. + if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { + d.w.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + d.w.Write(pointerChainBytes) + } + printHexPtr(d.w, addr) + } + d.w.Write(closeParenBytes) + } + + // Display dereferenced value. + d.w.Write(openParenBytes) + switch { + case nilFound: + d.w.Write(nilAngleBytes) + + case cycleFound: + d.w.Write(circularBytes) + + default: + d.ignoreNextType = true + d.dump(ve) + } + d.w.Write(closeParenBytes) +} + +// dumpSlice handles formatting of arrays and slices. Byte (uint8 under +// reflection) arrays and slices are dumped in hexdump -C fashion. +func (d *dumpState) dumpSlice(v reflect.Value) { + // Determine whether this type should be hex dumped or not. Also, + // for types which should be hexdumped, try to use the underlying data + // first, then fall back to trying to convert them to a uint8 slice. + var buf []uint8 + doConvert := false + doHexDump := false + numEntries := v.Len() + if numEntries > 0 { + vt := v.Index(0).Type() + vts := vt.String() + switch { + // C types that need to be converted. + case cCharRE.MatchString(vts): + fallthrough + case cUnsignedCharRE.MatchString(vts): + fallthrough + case cUint8tCharRE.MatchString(vts): + doConvert = true + + // Try to use existing uint8 slices and fall back to converting + // and copying if that fails. + case vt.Kind() == reflect.Uint8: + // We need an addressable interface to convert the type + // to a byte slice. However, the reflect package won't + // give us an interface on certain things like + // unexported struct fields in order to enforce + // visibility rules. We use unsafe, when available, to + // bypass these restrictions since this package does not + // mutate the values. + vs := v + if !vs.CanInterface() || !vs.CanAddr() { + vs = unsafeReflectValue(vs) + } + if !UnsafeDisabled { + vs = vs.Slice(0, numEntries) + + // Use the existing uint8 slice if it can be + // type asserted. + iface := vs.Interface() + if slice, ok := iface.([]uint8); ok { + buf = slice + doHexDump = true + break + } + } + + // The underlying data needs to be converted if it can't + // be type asserted to a uint8 slice. + doConvert = true + } + + // Copy and convert the underlying type if needed. + if doConvert && vt.ConvertibleTo(uint8Type) { + // Convert and copy each element into a uint8 byte + // slice. + buf = make([]uint8, numEntries) + for i := 0; i < numEntries; i++ { + vv := v.Index(i) + buf[i] = uint8(vv.Convert(uint8Type).Uint()) + } + doHexDump = true + } + } + + // Hexdump the entire slice as needed. + if doHexDump { + indent := strings.Repeat(d.cs.Indent, d.depth) + str := indent + hex.Dump(buf) + str = strings.Replace(str, "\n", "\n"+indent, -1) + str = strings.TrimRight(str, d.cs.Indent) + d.w.Write([]byte(str)) + return + } + + // Recursively call dump for each item. + for i := 0; i < numEntries; i++ { + d.dump(d.unpackValue(v.Index(i))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } +} + +// dump is the main workhorse for dumping a value. It uses the passed reflect +// value to figure out what kind of object we are dealing with and formats it +// appropriately. It is a recursive function, however circular data structures +// are detected and handled properly. +func (d *dumpState) dump(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + d.w.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + d.indent() + d.dumpPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !d.ignoreNextType { + d.indent() + d.w.Write(openParenBytes) + d.w.Write([]byte(v.Type().String())) + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + d.ignoreNextType = false + + // Display length and capacity if the built-in len and cap functions + // work with the value's kind and the len/cap itself is non-zero. + valueLen, valueCap := 0, 0 + switch v.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + valueLen, valueCap = v.Len(), v.Cap() + case reflect.Map, reflect.String: + valueLen = v.Len() + } + if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 { + d.w.Write(openParenBytes) + if valueLen != 0 { + d.w.Write(lenEqualsBytes) + printInt(d.w, int64(valueLen), 10) + } + if !d.cs.DisableCapacities && valueCap != 0 { + if valueLen != 0 { + d.w.Write(spaceBytes) + } + d.w.Write(capEqualsBytes) + printInt(d.w, int64(valueCap), 10) + } + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + + // Call Stringer/error interfaces if they exist and the handle methods flag + // is enabled + if !d.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(d.cs, d.w, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(d.w, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(d.w, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(d.w, v.Uint(), 10) + + case reflect.Float32: + printFloat(d.w, v.Float(), 32) + + case reflect.Float64: + printFloat(d.w, v.Float(), 64) + + case reflect.Complex64: + printComplex(d.w, v.Complex(), 32) + + case reflect.Complex128: + printComplex(d.w, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + d.dumpSlice(v) + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.String: + d.w.Write([]byte(strconv.Quote(v.String()))) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + d.w.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + numEntries := v.Len() + keys := v.MapKeys() + if d.cs.SortKeys { + sortValues(keys, d.cs) + } + for i, key := range keys { + d.dump(d.unpackValue(key)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.MapIndex(key))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Struct: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + vt := v.Type() + numFields := v.NumField() + for i := 0; i < numFields; i++ { + d.indent() + vtf := vt.Field(i) + d.w.Write([]byte(vtf.Name)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.Field(i))) + if i < (numFields - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(d.w, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(d.w, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it in case any new + // types are added. + default: + if v.CanInterface() { + fmt.Fprintf(d.w, "%v", v.Interface()) + } else { + fmt.Fprintf(d.w, "%v", v.String()) + } + } +} + +// fdump is a helper function to consolidate the logic from the various public +// methods which take varying writers and config states. +func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { + for _, arg := range a { + if arg == nil { + w.Write(interfaceBytes) + w.Write(spaceBytes) + w.Write(nilAngleBytes) + w.Write(newlineBytes) + continue + } + + d := dumpState{w: w, cs: cs} + d.pointers = make(map[uintptr]int) + d.dump(reflect.ValueOf(arg)) + d.w.Write(newlineBytes) + } +} + +// Fdump formats and displays the passed arguments to io.Writer w. It formats +// exactly the same as Dump. +func Fdump(w io.Writer, a ...interface{}) { + fdump(&Config, w, a...) +} + +// Sdump returns a string with the passed arguments formatted exactly the same +// as Dump. +func Sdump(a ...interface{}) string { + var buf bytes.Buffer + fdump(&Config, &buf, a...) + return buf.String() +} + +/* +Dump displays the passed parameters to standard out with newlines, customizable +indentation, and additional debug information such as complete types and all +pointer addresses used to indirect to the final value. It provides the +following features over the built-in printing facilities provided by the fmt +package: + + * Pointers are dereferenced and followed + * Circular data structures are detected and handled properly + * Custom Stringer/error interfaces are optionally invoked, including + on unexported types + * Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + * Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output + +The configuration options are controlled by an exported package global, +spew.Config. See ConfigState for options documentation. + +See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to +get the formatted result as a string. +*/ +func Dump(a ...interface{}) { + fdump(&Config, os.Stdout, a...) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go new file mode 100644 index 00000000..b04edb7d --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "reflect" + "strconv" + "strings" +) + +// supportedFlags is a list of all the character flags supported by fmt package. +const supportedFlags = "0-+# " + +// formatState implements the fmt.Formatter interface and contains information +// about the state of a formatting operation. The NewFormatter function can +// be used to get a new Formatter which can be used directly as arguments +// in standard fmt package printing calls. +type formatState struct { + value interface{} + fs fmt.State + depth int + pointers map[uintptr]int + ignoreNextType bool + cs *ConfigState +} + +// buildDefaultFormat recreates the original format string without precision +// and width information to pass in to fmt.Sprintf in the case of an +// unrecognized type. Unless new types are added to the language, this +// function won't ever be called. +func (f *formatState) buildDefaultFormat() (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + buf.WriteRune('v') + + format = buf.String() + return format +} + +// constructOrigFormat recreates the original format string including precision +// and width information to pass along to the standard fmt package. This allows +// automatic deferral of all format strings this package doesn't support. +func (f *formatState) constructOrigFormat(verb rune) (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + if width, ok := f.fs.Width(); ok { + buf.WriteString(strconv.Itoa(width)) + } + + if precision, ok := f.fs.Precision(); ok { + buf.Write(precisionBytes) + buf.WriteString(strconv.Itoa(precision)) + } + + buf.WriteRune(verb) + + format = buf.String() + return format +} + +// unpackValue returns values inside of non-nil interfaces when possible and +// ensures that types for values which have been unpacked from an interface +// are displayed when the show types flag is also set. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (f *formatState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface { + f.ignoreNextType = false + if !v.IsNil() { + v = v.Elem() + } + } + return v +} + +// formatPtr handles formatting of pointers by indirecting them as necessary. +func (f *formatState) formatPtr(v reflect.Value) { + // Display nil if top level pointer is nil. + showTypes := f.fs.Flag('#') + if v.IsNil() && (!showTypes || f.ignoreNextType) { + f.fs.Write(nilAngleBytes) + return + } + + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range f.pointers { + if depth >= f.depth { + delete(f.pointers, k) + } + } + + // Keep list of all dereferenced pointers to possibly show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by derferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := f.pointers[addr]; ok && pd < f.depth { + cycleFound = true + indirects-- + break + } + f.pointers[addr] = f.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type or indirection level depending on flags. + if showTypes && !f.ignoreNextType { + f.fs.Write(openParenBytes) + f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) + f.fs.Write([]byte(ve.Type().String())) + f.fs.Write(closeParenBytes) + } else { + if nilFound || cycleFound { + indirects += strings.Count(ve.Type().String(), "*") + } + f.fs.Write(openAngleBytes) + f.fs.Write([]byte(strings.Repeat("*", indirects))) + f.fs.Write(closeAngleBytes) + } + + // Display pointer information depending on flags. + if f.fs.Flag('+') && (len(pointerChain) > 0) { + f.fs.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + f.fs.Write(pointerChainBytes) + } + printHexPtr(f.fs, addr) + } + f.fs.Write(closeParenBytes) + } + + // Display dereferenced value. + switch { + case nilFound: + f.fs.Write(nilAngleBytes) + + case cycleFound: + f.fs.Write(circularShortBytes) + + default: + f.ignoreNextType = true + f.format(ve) + } +} + +// format is the main workhorse for providing the Formatter interface. It +// uses the passed reflect value to figure out what kind of object we are +// dealing with and formats it appropriately. It is a recursive function, +// however circular data structures are detected and handled properly. +func (f *formatState) format(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + f.fs.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + f.formatPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !f.ignoreNextType && f.fs.Flag('#') { + f.fs.Write(openParenBytes) + f.fs.Write([]byte(v.Type().String())) + f.fs.Write(closeParenBytes) + } + f.ignoreNextType = false + + // Call Stringer/error interfaces if they exist and the handle methods + // flag is enabled. + if !f.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(f.cs, f.fs, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(f.fs, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(f.fs, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(f.fs, v.Uint(), 10) + + case reflect.Float32: + printFloat(f.fs, v.Float(), 32) + + case reflect.Float64: + printFloat(f.fs, v.Float(), 64) + + case reflect.Complex64: + printComplex(f.fs, v.Complex(), 32) + + case reflect.Complex128: + printComplex(f.fs, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + f.fs.Write(openBracketBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + numEntries := v.Len() + for i := 0; i < numEntries; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(v.Index(i))) + } + } + f.depth-- + f.fs.Write(closeBracketBytes) + + case reflect.String: + f.fs.Write([]byte(v.String())) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + f.fs.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + + f.fs.Write(openMapBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + keys := v.MapKeys() + if f.cs.SortKeys { + sortValues(keys, f.cs) + } + for i, key := range keys { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(key)) + f.fs.Write(colonBytes) + f.ignoreNextType = true + f.format(f.unpackValue(v.MapIndex(key))) + } + } + f.depth-- + f.fs.Write(closeMapBytes) + + case reflect.Struct: + numFields := v.NumField() + f.fs.Write(openBraceBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + vt := v.Type() + for i := 0; i < numFields; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + vtf := vt.Field(i) + if f.fs.Flag('+') || f.fs.Flag('#') { + f.fs.Write([]byte(vtf.Name)) + f.fs.Write(colonBytes) + } + f.format(f.unpackValue(v.Field(i))) + } + } + f.depth-- + f.fs.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(f.fs, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(f.fs, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it if any get added. + default: + format := f.buildDefaultFormat() + if v.CanInterface() { + fmt.Fprintf(f.fs, format, v.Interface()) + } else { + fmt.Fprintf(f.fs, format, v.String()) + } + } +} + +// Format satisfies the fmt.Formatter interface. See NewFormatter for usage +// details. +func (f *formatState) Format(fs fmt.State, verb rune) { + f.fs = fs + + // Use standard formatting for verbs that are not v. + if verb != 'v' { + format := f.constructOrigFormat(verb) + fmt.Fprintf(fs, format, f.value) + return + } + + if f.value == nil { + if fs.Flag('#') { + fs.Write(interfaceBytes) + } + fs.Write(nilAngleBytes) + return + } + + f.format(reflect.ValueOf(f.value)) +} + +// newFormatter is a helper function to consolidate the logic from the various +// public methods which take varying config states. +func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { + fs := &formatState{value: v, cs: cs} + fs.pointers = make(map[uintptr]int) + return fs +} + +/* +NewFormatter returns a custom formatter that satisfies the fmt.Formatter +interface. As a result, it integrates cleanly with standard fmt package +printing functions. The formatter is useful for inline printing of smaller data +types similar to the standard %v format specifier. + +The custom formatter only responds to the %v (most compact), %+v (adds pointer +addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb +combinations. Any other verbs such as %x and %q will be sent to the the +standard fmt package for formatting. In addition, the custom formatter ignores +the width and precision arguments (however they will still work on the format +specifiers not handled by the custom formatter). + +Typically this function shouldn't be called directly. It is much easier to make +use of the custom formatter by calling one of the convenience functions such as +Printf, Println, or Fprintf. +*/ +func NewFormatter(v interface{}) fmt.Formatter { + return newFormatter(&Config, v) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/spew.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/spew.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/spew.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/spew.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore new file mode 100644 index 00000000..e256a31e --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore @@ -0,0 +1,20 @@ +# OSX leaves these everywhere on SMB shares +._* + +# Eclipse files +.classpath +.project +.settings/** + +# Emacs save files +*~ + +# Vim-related files +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist + +# Go test binaries +*.test diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml new file mode 100644 index 00000000..0e9d6edc --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml @@ -0,0 +1,7 @@ +language: go +go: + - 1.3 + - 1.4 +script: + - go test + - go build diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go index 6e7f14fc..4fb4054a 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io" "reflect" "strconv" @@ -27,19 +26,15 @@ func Marshal(o interface{}) ([]byte, error) { return y, nil } -// JSONOpt is a decoding option for decoding from JSON format. -type JSONOpt func(*json.Decoder) *json.Decoder - -// Unmarshal converts YAML to JSON then uses JSON to unmarshal into an object, -// optionally configuring the behavior of the JSON unmarshal. -func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error { +// Converts YAML to JSON then uses JSON to unmarshal into an object. +func Unmarshal(y []byte, o interface{}) error { vo := reflect.ValueOf(o) - j, err := yamlToJSON(y, &vo, yaml.Unmarshal) + j, err := yamlToJSON(y, &vo) if err != nil { return fmt.Errorf("error converting YAML to JSON: %v", err) } - err = jsonUnmarshal(bytes.NewReader(j), o, opts...) + err = json.Unmarshal(j, o) if err != nil { return fmt.Errorf("error unmarshaling JSON: %v", err) } @@ -47,21 +42,6 @@ func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error { return nil } -// jsonUnmarshal unmarshals the JSON byte stream from the given reader into the -// object, optionally applying decoder options prior to decoding. We are not -// using json.Unmarshal directly as we want the chance to pass in non-default -// options. -func jsonUnmarshal(r io.Reader, o interface{}, opts ...JSONOpt) error { - d := json.NewDecoder(r) - for _, opt := range opts { - d = opt(d) - } - if err := d.Decode(&o); err != nil { - return fmt.Errorf("while decoding JSON: %v", err) - } - return nil -} - // Convert JSON to YAML. func JSONToYAML(j []byte) ([]byte, error) { // Convert the JSON to an object. @@ -80,8 +60,8 @@ func JSONToYAML(j []byte) ([]byte, error) { return yaml.Marshal(jsonObj) } -// YAMLToJSON converts YAML to JSON. Since JSON is a subset of YAML, -// passing JSON through this method should be a no-op. +// Convert YAML to JSON. Since JSON is a subset of YAML, passing JSON through +// this method should be a no-op. // // Things YAML can do that are not supported by JSON: // * In YAML you can have binary and null keys in your maps. These are invalid @@ -90,22 +70,14 @@ func JSONToYAML(j []byte) ([]byte, error) { // use binary data with this library, encode the data as base64 as usual but do // not use the !!binary tag in your YAML. This will ensure the original base64 // encoded data makes it all the way through to the JSON. -// -// For strict decoding of YAML, use YAMLToJSONStrict. func YAMLToJSON(y []byte) ([]byte, error) { - return yamlToJSON(y, nil, yaml.Unmarshal) -} - -// YAMLToJSONStrict is like YAMLToJSON but enables strict YAML decoding, -// returning an error on any duplicate field names. -func YAMLToJSONStrict(y []byte) ([]byte, error) { - return yamlToJSON(y, nil, yaml.UnmarshalStrict) + return yamlToJSON(y, nil) } -func yamlToJSON(y []byte, jsonTarget *reflect.Value, yamlUnmarshal func([]byte, interface{}) error) ([]byte, error) { +func yamlToJSON(y []byte, jsonTarget *reflect.Value) ([]byte, error) { // Convert the YAML to an object. var yamlObj interface{} - err := yamlUnmarshal(y, &yamlObj) + err := yaml.Unmarshal(y, &yamlObj) if err != nil { return nil, err } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go deleted file mode 100644 index ab3e06a2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go +++ /dev/null @@ -1,14 +0,0 @@ -// This file contains changes that are only compatible with go 1.10 and onwards. - -// +build go1.10 - -package yaml - -import "encoding/json" - -// DisallowUnknownFields configures the JSON decoder to error out if unknown -// fields come along, instead of dropping them by default. -func DisallowUnknownFields(d *json.Decoder) *json.Decoder { - d.DisallowUnknownFields() - return d -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md deleted file mode 100644 index c0751f85..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md +++ /dev/null @@ -1,18 +0,0 @@ -# Contributing - -First, thank you for contributing! We love and encourage pull requests from everyone. - -Before submitting major changes, here are a few guidelines to follow: - -1. Check the [open issues][issues] and [pull requests][prs] for existing discussions. -1. Open an [issue][issues] first, to discuss a new feature or enhancement. -1. Write tests, and make sure the test suite passes locally and on CI. -1. Open a pull request, and reference the relevant issue(s). -1. After receiving feedback, [squash your commits][squash] and add a [great commit message][message]. -1. Have fun! - -[issues]: https://github.com/go-kit/kit/issues -[prs]: https://github.com/go-kit/kit/pulls -[squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html -[message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE deleted file mode 100644 index 9d83342a..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Peter Bourgon - -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/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md deleted file mode 100644 index a3682408..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md +++ /dev/null @@ -1,120 +0,0 @@ -# Go kit [![Circle CI](https://circleci.com/gh/go-kit/kit.svg?style=shield)](https://circleci.com/gh/go-kit/kit) [![Travis CI](https://travis-ci.org/go-kit/kit.svg?branch=master)](https://travis-ci.org/go-kit/kit) [![GoDoc](https://godoc.org/github.com/go-kit/kit?status.svg)](https://godoc.org/github.com/go-kit/kit) [![Coverage Status](https://coveralls.io/repos/go-kit/kit/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-kit/kit?branch=master) [![Go Report Card](https://goreportcard.com/badge/go-kit/kit)](https://goreportcard.com/report/go-kit/kit) [![Sourcegraph](https://sourcegraph.com/github.com/go-kit/kit/-/badge.svg)](https://sourcegraph.com/github.com/go-kit/kit?badge) - -**Go kit** is a **programming toolkit** for building microservices -(or elegant monoliths) in Go. We solve common problems in distributed -systems and application architecture so you can focus on delivering -business value. - -- Website: [gokit.io](https://gokit.io) -- Mailing list: [go-kit](https://groups.google.com/forum/#!forum/go-kit) -- Slack: [gophers.slack.com](https://gophers.slack.com) **#go-kit** ([invite](https://gophersinvite.herokuapp.com/)) - -## Motivation - -Go has emerged as the language of the server, but it remains underrepresented -in so-called "modern enterprise" companies like Facebook, Twitter, Netflix, and -SoundCloud. Many of these organizations have turned to JVM-based stacks for -their business logic, owing in large part to libraries and ecosystems that -directly support their microservice architectures. - -To reach its next level of success, Go needs more than simple primitives and -idioms. It needs a comprehensive toolkit, for coherent distributed programming -in the large. Go kit is a set of packages and best practices, which provide a -comprehensive, robust, and trustable way of building microservices for -organizations of any size. - -For more details, see - [the website](https://gokit.io), - [the motivating blog post](http://peter.bourgon.org/go-kit/) and - [the video of the talk](https://www.youtube.com/watch?v=iFR_7AKkJFU). -See also the - [Go kit talk at GopherCon 2015](https://www.youtube.com/watch?v=1AjaZi4QuGo). - -## Goals - -- Operate in a heterogeneous SOA — expect to interact with mostly non-Go-kit services -- RPC as the primary messaging pattern -- Pluggable serialization and transport — not just JSON over HTTP -- Operate within existing infrastructures — no mandates for specific tools or technologies - -## Non-goals - -- Supporting messaging patterns other than RPC (for now) — e.g. MPI, pub/sub, CQRS, etc. -- Re-implementing functionality that can be provided by adapting existing software -- Having opinions on operational concerns: deployment, configuration, process supervision, orchestration, etc. - -## Contributing - -Please see [CONTRIBUTING.md](/CONTRIBUTING.md). -Thank you, [contributors](https://github.com/go-kit/kit/graphs/contributors)! - -## Dependency management - -Go kit is a library, designed to be imported into a binary package. Vendoring -is currently the best way for binary package authors to ensure reliable, -reproducible builds. Therefore, we strongly recommend our users use vendoring -for all of their dependencies, including Go kit. To avoid compatibility and -availability issues, Go kit doesn't vendor its own dependencies, and -doesn't recommend use of third-party import proxies. - -There are several tools which make vendoring easier, including - [dep](https://github.com/golang/dep), - [gb](http://getgb.io), - [glide](https://github.com/Masterminds/glide), - [gvt](https://github.com/FiloSottile/gvt), and - [govendor](https://github.com/kardianos/govendor). -In addition, Go kit uses a variety of continuous integration providers - to find and fix compatibility problems as soon as they occur. - -## Related projects - -Projects with a ★ have had particular influence on Go kit's design (or vice-versa). - -### Service frameworks - -- [gizmo](https://github.com/nytimes/gizmo), a microservice toolkit from The New York Times ★ -- [go-micro](https://github.com/myodc/go-micro), a microservices client/server library ★ -- [gotalk](https://github.com/rsms/gotalk), async peer communication protocol & library -- [Kite](https://github.com/koding/kite), a micro-service framework -- [gocircuit](https://github.com/gocircuit/circuit), dynamic cloud orchestration - -### Individual components - -- [afex/hystrix-go](https://github.com/afex/hystrix-go), client-side latency and fault tolerance library -- [armon/go-metrics](https://github.com/armon/go-metrics), library for exporting performance and runtime metrics to external metrics systems -- [codahale/lunk](https://github.com/codahale/lunk), structured logging in the style of Google's Dapper or Twitter's Zipkin -- [eapache/go-resiliency](https://github.com/eapache/go-resiliency), resiliency patterns -- [sasbury/logging](https://github.com/sasbury/logging), a tagged style of logging -- [grpc/grpc-go](https://github.com/grpc/grpc-go), HTTP/2 based RPC -- [inconshreveable/log15](https://github.com/inconshreveable/log15), simple, powerful logging for Go ★ -- [mailgun/vulcand](https://github.com/vulcand/vulcand), programmatic load balancer backed by etcd -- [mattheath/phosphor](https://github.com/mondough/phosphor), distributed system tracing -- [pivotal-golang/lager](https://github.com/pivotal-golang/lager), an opinionated logging library -- [rubyist/circuitbreaker](https://github.com/rubyist/circuitbreaker), circuit breaker library -- [sirupsen/logrus](https://github.com/sirupsen/logrus), structured, pluggable logging for Go ★ -- [sourcegraph/appdash](https://github.com/sourcegraph/appdash), application tracing system based on Google's Dapper -- [spacemonkeygo/monitor](https://github.com/spacemonkeygo/monitor), data collection, monitoring, instrumentation, and Zipkin client library -- [streadway/handy](https://github.com/streadway/handy), net/http handler filters -- [vitess/rpcplus](https://godoc.org/github.com/youtube/vitess/go/rpcplus), package rpc + context.Context -- [gdamore/mangos](https://github.com/gdamore/mangos), nanomsg implementation in pure Go - -### Web frameworks - -- [Gorilla](http://www.gorillatoolkit.org) -- [Gin](https://gin-gonic.github.io/gin/) -- [Negroni](https://github.com/codegangsta/negroni) -- [Goji](https://github.com/zenazn/goji) -- [Martini](https://github.com/go-martini/martini) -- [Beego](http://beego.me/) -- [Revel](https://revel.github.io/) (considered [harmful](https://github.com/go-kit/kit/issues/350)) -- [GoBuffalo](https://gobuffalo.io/) - -## Additional reading - -- [Architecting for the Cloud](https://slideshare.net/stonse/architecting-for-the-cloud-using-netflixoss-codemash-workshop-29852233) — Netflix -- [Dapper, a Large-Scale Distributed Systems Tracing Infrastructure](http://research.google.com/pubs/pub36356.html) — Google -- [Your Server as a Function](http://monkey.org/~marius/funsrv.pdf) (PDF) — Twitter - ---- - -Development supported by [DigitalOcean](https://digitalocean.com). diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md deleted file mode 100644 index 26d6c4b3..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md +++ /dev/null @@ -1,20 +0,0 @@ -This package provides a Basic Authentication middleware. - -It'll try to compare credentials from Authentication request header to a username/password pair in middleware constructor. - -More details about this type of authentication can be found in [Mozilla article](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). - -## Usage - -```go -import httptransport "github.com/go-kit/kit/transport/http" - -httptransport.NewServer( - AuthMiddleware(cfg.auth.user, cfg.auth.password, "Example Realm")(makeUppercaseEndpoint()), - decodeMappingsRequest, - httptransport.EncodeJSONResponse, - httptransport.ServerBefore(httptransport.PopulateRequestContext), - ) -``` - -For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like ```httptransport.ServerBefore(httptransport.PopulateRequestContext)```. \ No newline at end of file diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go deleted file mode 100644 index ad7e4085..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go +++ /dev/null @@ -1,94 +0,0 @@ -package basic - -import ( - "bytes" - "context" - "crypto/sha256" - "crypto/subtle" - "encoding/base64" - "fmt" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// AuthError represents an authorization error. -type AuthError struct { - Realm string -} - -// StatusCode is an implementation of the StatusCoder interface in go-kit/http. -func (AuthError) StatusCode() int { - return http.StatusUnauthorized -} - -// Error is an implementation of the Error interface. -func (AuthError) Error() string { - return http.StatusText(http.StatusUnauthorized) -} - -// Headers is an implementation of the Headerer interface in go-kit/http. -func (e AuthError) Headers() http.Header { - return http.Header{ - "Content-Type": []string{"text/plain; charset=utf-8"}, - "X-Content-Type-Options": []string{"nosniff"}, - "WWW-Authenticate": []string{fmt.Sprintf(`Basic realm=%q`, e.Realm)}, - } -} - -// parseBasicAuth parses an HTTP Basic Authentication string. -// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ([]byte("Aladdin"), []byte("open sesame"), true). -func parseBasicAuth(auth string) (username, password []byte, ok bool) { - const prefix = "Basic " - if !strings.HasPrefix(auth, prefix) { - return - } - c, err := base64.StdEncoding.DecodeString(auth[len(prefix):]) - if err != nil { - return - } - - s := bytes.IndexByte(c, ':') - if s < 0 { - return - } - return c[:s], c[s+1:], true -} - -// Returns a hash of a given slice. -func toHashSlice(s []byte) []byte { - hash := sha256.Sum256(s) - return hash[:] -} - -// AuthMiddleware returns a Basic Authentication middleware for a particular user and password. -func AuthMiddleware(requiredUser, requiredPassword, realm string) endpoint.Middleware { - requiredUserBytes := toHashSlice([]byte(requiredUser)) - requiredPasswordBytes := toHashSlice([]byte(requiredPassword)) - - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - auth, ok := ctx.Value(httptransport.ContextKeyRequestAuthorization).(string) - if !ok { - return nil, AuthError{realm} - } - - givenUser, givenPassword, ok := parseBasicAuth(auth) - if !ok { - return nil, AuthError{realm} - } - - givenUserBytes := toHashSlice(givenUser) - givenPasswordBytes := toHashSlice(givenPassword) - - if subtle.ConstantTimeCompare(givenUserBytes, requiredUserBytes) == 0 || - subtle.ConstantTimeCompare(givenPasswordBytes, requiredPasswordBytes) == 0 { - return nil, AuthError{realm} - } - - return next(ctx, request) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md deleted file mode 100644 index 1ed825a9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# package auth/jwt - -`package auth/jwt` provides a set of interfaces for service authorization -through [JSON Web Tokens](https://jwt.io/). - -## Usage - -NewParser takes a key function and an expected signing method and returns an -`endpoint.Middleware`. The middleware will parse a token passed into the -context via the `jwt.JWTTokenContextKey`. If the token is valid, any claims -will be added to the context via the `jwt.JWTClaimsContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - kf := func(token *stdjwt.Token) (interface{}, error) { return []byte("SigningString"), nil } - exampleEndpoint = MakeExampleEndpoint(service) - exampleEndpoint = jwt.NewParser(kf, stdjwt.SigningMethodHS256, jwt.StandardClaimsFactory)(exampleEndpoint) - } -} -``` - -NewSigner takes a JWT key ID header, the signing key, signing method, and a -claims object. It returns an `endpoint.Middleware`. The middleware will build -the token string and add it to the context via the `jwt.JWTTokenContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(...).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -In order for the parser and the signer to work, the authorization headers need -to be passed between the request and the context. `HTTPToContext()`, -`ContextToHTTP()`, `GRPCToContext()`, and `ContextToGRPC()` are given as -helpers to do this. These functions implement the correlating transport's -RequestFunc interface and can be passed as ClientBefore or ServerBefore -options. - -Example of use in a client: - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - grpctransport "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - - options := []httptransport.ClientOption{} - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(..., grpctransport.ClientBefore(jwt.ContextToGRPC())).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -Example of use in a server: - -```go -import ( - "context" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/log" - grpctransport "github.com/go-kit/kit/transport/grpc" -) - -func MakeGRPCServer(ctx context.Context, endpoints Endpoints, logger log.Logger) pb.ExampleServer { - options := []grpctransport.ServerOption{grpctransport.ServerErrorLogger(logger)} - - return &grpcServer{ - createUser: grpctransport.NewServer( - ctx, - endpoints.CreateUserEndpoint, - DecodeGRPCCreateUserRequest, - EncodeGRPCCreateUserResponse, - append(options, grpctransport.ServerBefore(jwt.GRPCToContext()))..., - ), - getUser: grpctransport.NewServer( - ctx, - endpoints.GetUserEndpoint, - DecodeGRPCGetUserRequest, - EncodeGRPCGetUserResponse, - options..., - ), - } -} -``` diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go deleted file mode 100644 index 0e29e6d6..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go +++ /dev/null @@ -1,143 +0,0 @@ -package jwt - -import ( - "context" - "errors" - - jwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/endpoint" -) - -type contextKey string - -const ( - // JWTTokenContextKey holds the key used to store a JWT Token in the - // context. - JWTTokenContextKey contextKey = "JWTToken" - - // JWTClaimsContextKey holds the key used to store the JWT Claims in the - // context. - JWTClaimsContextKey contextKey = "JWTClaims" -) - -var ( - // ErrTokenContextMissing denotes a token was not passed into the parsing - // middleware's context. - ErrTokenContextMissing = errors.New("token up for parsing was not passed through the context") - - // ErrTokenInvalid denotes a token was not able to be validated. - ErrTokenInvalid = errors.New("JWT Token was invalid") - - // ErrTokenExpired denotes a token's expire header (exp) has since passed. - ErrTokenExpired = errors.New("JWT Token is expired") - - // ErrTokenMalformed denotes a token was not formatted as a JWT token. - ErrTokenMalformed = errors.New("JWT Token is malformed") - - // ErrTokenNotActive denotes a token's not before header (nbf) is in the - // future. - ErrTokenNotActive = errors.New("token is not valid yet") - - // ErrUnexpectedSigningMethod denotes a token was signed with an unexpected - // signing method. - ErrUnexpectedSigningMethod = errors.New("unexpected signing method") -) - -// NewSigner creates a new JWT token generating middleware, specifying key ID, -// signing string, signing method and the claims you would like it to contain. -// Tokens are signed with a Key ID header (kid) which is useful for determining -// the key to use for parsing. Particularly useful for clients. -func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Claims) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - token := jwt.NewWithClaims(method, claims) - token.Header["kid"] = kid - - // Sign and get the complete encoded token as a string using the secret - tokenString, err := token.SignedString(key) - if err != nil { - return nil, err - } - ctx = context.WithValue(ctx, JWTTokenContextKey, tokenString) - - return next(ctx, request) - } - } -} - -// ClaimsFactory is a factory for jwt.Claims. -// Useful in NewParser middleware. -type ClaimsFactory func() jwt.Claims - -// MapClaimsFactory is a ClaimsFactory that returns -// an empty jwt.MapClaims. -func MapClaimsFactory() jwt.Claims { - return jwt.MapClaims{} -} - -// StandardClaimsFactory is a ClaimsFactory that returns -// an empty jwt.StandardClaims. -func StandardClaimsFactory() jwt.Claims { - return &jwt.StandardClaims{} -} - -// NewParser creates a new JWT token parsing middleware, specifying a -// jwt.Keyfunc interface, the signing method and the claims type to be used. NewParser -// adds the resulting claims to endpoint context or returns error on invalid token. -// Particularly useful for servers. -func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod, newClaims ClaimsFactory) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - // tokenString is stored in the context from the transport handlers. - tokenString, ok := ctx.Value(JWTTokenContextKey).(string) - if !ok { - return nil, ErrTokenContextMissing - } - - // Parse takes the token string and a function for looking up the - // key. The latter is especially useful if you use multiple keys - // for your application. The standard is to use 'kid' in the head - // of the token to identify which key to use, but the parsed token - // (head and claims) is provided to the callback, providing - // flexibility. - token, err := jwt.ParseWithClaims(tokenString, newClaims(), func(token *jwt.Token) (interface{}, error) { - // Don't forget to validate the alg is what you expect: - if token.Method != method { - return nil, ErrUnexpectedSigningMethod - } - - return keyFunc(token) - }) - if err != nil { - if e, ok := err.(*jwt.ValidationError); ok { - switch { - case e.Errors&jwt.ValidationErrorMalformed != 0: - // Token is malformed - return nil, ErrTokenMalformed - case e.Errors&jwt.ValidationErrorExpired != 0: - // Token is expired - return nil, ErrTokenExpired - case e.Errors&jwt.ValidationErrorNotValidYet != 0: - // Token is not active yet - return nil, ErrTokenNotActive - case e.Inner != nil: - // report e.Inner - return nil, e.Inner - } - // We have a ValidationError but have no specific Go kit error for it. - // Fall through to return original error. - } - return nil, err - } - - if !token.Valid { - return nil, ErrTokenInvalid - } - - ctx = context.WithValue(ctx, JWTClaimsContextKey, token.Claims) - - return next(ctx, request) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go deleted file mode 100644 index 57b3aaee..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go +++ /dev/null @@ -1,89 +0,0 @@ -package jwt - -import ( - "context" - "fmt" - stdhttp "net/http" - "strings" - - "google.golang.org/grpc/metadata" - - "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/transport/http" -) - -const ( - bearer string = "bearer" - bearerFormat string = "Bearer %s" -) - -// HTTPToContext moves a JWT from request header to context. Particularly -// useful for servers. -func HTTPToContext() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := extractTokenFromAuthHeader(r.Header.Get("Authorization")) - if !ok { - return ctx - } - - return context.WithValue(ctx, JWTTokenContextKey, token) - } -} - -// ContextToHTTP moves a JWT from context to request header. Particularly -// useful for clients. -func ContextToHTTP() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - r.Header.Add("Authorization", generateAuthHeaderFromToken(token)) - } - return ctx - } -} - -// GRPCToContext moves a JWT from grpc metadata to context. Particularly -// userful for servers. -func GRPCToContext() grpc.ServerRequestFunc { - return func(ctx context.Context, md metadata.MD) context.Context { - // capital "Key" is illegal in HTTP/2. - authHeader, ok := md["authorization"] - if !ok { - return ctx - } - - token, ok := extractTokenFromAuthHeader(authHeader[0]) - if ok { - ctx = context.WithValue(ctx, JWTTokenContextKey, token) - } - - return ctx - } -} - -// ContextToGRPC moves a JWT from context to grpc metadata. Particularly -// useful for clients. -func ContextToGRPC() grpc.ClientRequestFunc { - return func(ctx context.Context, md *metadata.MD) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - // capital "Key" is illegal in HTTP/2. - (*md)["authorization"] = []string{generateAuthHeaderFromToken(token)} - } - - return ctx - } -} - -func extractTokenFromAuthHeader(val string) (token string, ok bool) { - authHeaderParts := strings.Split(val, " ") - if len(authHeaderParts) != 2 || strings.ToLower(authHeaderParts[0]) != bearer { - return "", false - } - - return authHeaderParts[1], true -} - -func generateAuthHeaderFromToken(token string) string { - return fmt.Sprintf(bearerFormat, token) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml deleted file mode 100644 index 453528c4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 - -jobs: - build: - machine: true - working_directory: /home/circleci/.go_workspace/src/github.com/go-kit/kit - environment: - ETCD_ADDR: http://localhost:2379 - CONSUL_ADDR: localhost:8500 - ZK_ADDR: localhost:2181 - EUREKA_ADDR: http://localhost:8761/eureka - steps: - - checkout - - run: docker-compose -f docker-compose-integration.yml up -d --force-recreate - - run: go get -t github.com/go-kit/kit/... - - run: go test -v -race -tags integration github.com/go-kit/kit/... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go deleted file mode 100644 index fe749575..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// Package circuitbreaker implements the circuit breaker pattern. -// -// Circuit breakers prevent thundering herds, and improve resiliency against -// intermittent errors. Every client-side endpoint should be wrapped in a -// circuit breaker. -// -// We provide several implementations in this package, but if you're looking -// for guidance, Gobreaker is probably the best place to start. It has a -// simple and intuitive API, and is well-tested. -package circuitbreaker diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go deleted file mode 100644 index cf06304f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go +++ /dev/null @@ -1,22 +0,0 @@ -package circuitbreaker - -import ( - "context" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/endpoint" -) - -// Gobreaker returns an endpoint.Middleware that implements the circuit -// breaker pattern using the sony/gobreaker package. Only errors returned by -// the wrapped endpoint count against the circuit breaker's error count. -// -// See http://godoc.org/github.com/sony/gobreaker for more information. -func Gobreaker(cb *gobreaker.CircuitBreaker) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - return cb.Execute(func() (interface{}, error) { return next(ctx, request) }) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go deleted file mode 100644 index a5b60be2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go +++ /dev/null @@ -1,38 +0,0 @@ -package circuitbreaker - -import ( - "context" - "time" - - "github.com/streadway/handy/breaker" - - "github.com/go-kit/kit/endpoint" -) - -// HandyBreaker returns an endpoint.Middleware that implements the circuit -// breaker pattern using the streadway/handy/breaker package. Only errors -// returned by the wrapped endpoint count against the circuit breaker's error -// count. -// -// See http://godoc.org/github.com/streadway/handy/breaker for more -// information. -func HandyBreaker(cb breaker.Breaker) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - if !cb.Allow() { - return nil, breaker.ErrCircuitOpen - } - - defer func(begin time.Time) { - if err == nil { - cb.Success(time.Since(begin)) - } else { - cb.Failure(time.Since(begin)) - } - }(time.Now()) - - response, err = next(ctx, request) - return - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go deleted file mode 100644 index 3c59ec41..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go +++ /dev/null @@ -1,31 +0,0 @@ -package circuitbreaker - -import ( - "context" - - "github.com/afex/hystrix-go/hystrix" - - "github.com/go-kit/kit/endpoint" -) - -// Hystrix returns an endpoint.Middleware that implements the circuit -// breaker pattern using the afex/hystrix-go package. -// -// When using this circuit breaker, please configure your commands separately. -// -// See https://godoc.org/github.com/afex/hystrix-go/hystrix for more -// information. -func Hystrix(commandName string) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - var resp interface{} - if err := hystrix.Do(commandName, func() (err error) { - resp, err = next(ctx, request) - return err - }, nil); err != nil { - return nil, err - } - return resp, nil - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore deleted file mode 100644 index 747f955c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore +++ /dev/null @@ -1 +0,0 @@ -testdata/*/*/ diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md deleted file mode 100644 index 12cd03e1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# kitgen -kitgen is an experimental code generation utility that helps with some of the -boilerplate code required to implement the "onion" pattern `go-kit` utilizes. - -## Usage -Before using this tool please explore the [testdata]() directory for examples -of the inputs it requires and the outputs that will be produced. _You may not -need this tool._ If you are new to and just learning `go-kit` or if your use -case involves introducing `go-kit` to an existing codebase you are better -suited by slowly building out the "onion" by hand. - -Before starting you need to *install* `kitgen` utility — see instructions below. -1. **Define** your service. Create a `.go` file with the definition of your -Service interface and any of the custom types it refers to: -```go -// service.go -package profilesvc // don't forget to name your package - -type Service interface { - PostProfile(ctx context.Context, p Profile) error - // ... -} -type Profile struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - // ... -} -``` -2. **Generate** your code. Run the following command: -```sh -kitgen ./service.go -# kitgen has a couple of flags that you may find useful - -# keep all code in the root directory -kitgen -repo-layout flat ./service.go - -# put generated code elsewhere -kitgen -target-dir ~/Projects/gohome/src/home.com/kitchenservice/brewcoffee -``` - -## Installation -1. **Fetch** the `inlinefiles` utility. Go generate will use it to create your -code: -``` -go get github.com/nyarly/inlinefiles -``` -2. **Install** the binary for easy access to `kitgen`. Run the following commands: -```sh -cd $GOPATH/src/github.com/go-kit/kit/cmd/kitgen -go install - -# Check installation by running: -kitgen -h -``` diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go deleted file mode 100644 index bcf4e0a5..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import "go/ast" - -type arg struct { - name, asField *ast.Ident - typ ast.Expr -} - -func (a arg) chooseName(scope *ast.Scope) *ast.Ident { - if a.name == nil || scope.Lookup(a.name.Name) != nil { - return inventName(a.typ, scope) - } - return a.name -} - -func (a arg) field(scope *ast.Scope) *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{a.chooseName(scope)}, - Type: a.typ, - } -} - -func (a arg) result() *ast.Field { - return &ast.Field{ - Names: nil, - Type: a.typ, - } -} - -func (a arg) exported() *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{id(export(a.asField.Name))}, - Type: a.typ, - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go deleted file mode 100644 index ab7c277d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go +++ /dev/null @@ -1,208 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/parser" - "go/token" - "strings" - "unicode" -) - -func export(s string) string { - return strings.Title(s) -} - -func unexport(s string) string { - first := true - return strings.Map(func(r rune) rune { - if first { - first = false - return unicode.ToLower(r) - } - return r - }, s) -} - -func inventName(t ast.Expr, scope *ast.Scope) *ast.Ident { - n := baseName(t) - for try := 0; ; try++ { - nstr := pickName(n, try) - obj := ast.NewObj(ast.Var, nstr) - if alt := scope.Insert(obj); alt == nil { - return ast.NewIdent(nstr) - } - } -} - -func baseName(t ast.Expr) string { - switch tt := t.(type) { - default: - panic(fmt.Sprintf("don't know how to choose a base name for %T (%[1]v)", tt)) - case *ast.ArrayType: - return "slice" - case *ast.Ident: - return tt.Name - case *ast.SelectorExpr: - return tt.Sel.Name - } -} - -func pickName(base string, idx int) string { - if idx == 0 { - switch base { - default: - return strings.Split(base, "")[0] - case "Context": - return "ctx" - case "error": - return "err" - } - } - return fmt.Sprintf("%s%d", base, idx) -} - -func scopeWith(names ...string) *ast.Scope { - scope := ast.NewScope(nil) - for _, name := range names { - scope.Insert(ast.NewObj(ast.Var, name)) - } - return scope -} - -type visitFn func(ast.Node, func(ast.Node)) - -func (fn visitFn) Visit(node ast.Node, r func(ast.Node)) Visitor { - fn(node, r) - return fn -} - -func replaceIdent(src ast.Node, named string, with ast.Node) ast.Node { - r := visitFn(func(node ast.Node, replaceWith func(ast.Node)) { - switch id := node.(type) { - case *ast.Ident: - if id.Name == named { - replaceWith(with) - } - } - }) - return WalkReplace(r, src) -} - -func replaceLit(src ast.Node, from, to string) ast.Node { - r := visitFn(func(node ast.Node, replaceWith func(ast.Node)) { - switch lit := node.(type) { - case *ast.BasicLit: - if lit.Value == from { - replaceWith(&ast.BasicLit{Value: to}) - } - } - }) - return WalkReplace(r, src) -} - -func fullAST() *ast.File { - full, err := ASTTemplates.Open("full.go") - if err != nil { - panic(err) - } - f, err := parser.ParseFile(token.NewFileSet(), "templates/full.go", full, parser.DeclarationErrors) - if err != nil { - panic(err) - } - return f -} - -func fetchImports() []*ast.ImportSpec { - return fullAST().Imports -} - -func fetchFuncDecl(name string) *ast.FuncDecl { - f := fullAST() - for _, decl := range f.Decls { - if f, ok := decl.(*ast.FuncDecl); ok && f.Name.Name == name { - return f - } - } - panic(fmt.Errorf("No function called %q in 'templates/full.go'", name)) -} - -func id(name string) *ast.Ident { - return ast.NewIdent(name) -} - -func sel(ids ...*ast.Ident) ast.Expr { - switch len(ids) { - default: - return &ast.SelectorExpr{ - X: sel(ids[:len(ids)-1]...), - Sel: ids[len(ids)-1], - } - case 1: - return ids[0] - case 0: - panic("zero ids to sel()") - } -} - -func typeField(t ast.Expr) *ast.Field { - return &ast.Field{Type: t} -} - -func field(n *ast.Ident, t ast.Expr) *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{n}, - Type: t, - } -} - -func fieldList(list ...*ast.Field) *ast.FieldList { - return &ast.FieldList{List: list} -} - -func mappedFieldList(fn func(arg) *ast.Field, args ...arg) *ast.FieldList { - fl := &ast.FieldList{List: []*ast.Field{}} - for _, a := range args { - fl.List = append(fl.List, fn(a)) - } - return fl -} - -func blockStmt(stmts ...ast.Stmt) *ast.BlockStmt { - return &ast.BlockStmt{ - List: stmts, - } -} - -func structDecl(name *ast.Ident, fields *ast.FieldList) ast.Decl { - return typeDecl(&ast.TypeSpec{ - Name: name, - Type: &ast.StructType{ - Fields: fields, - }, - }) -} - -func typeDecl(ts *ast.TypeSpec) ast.Decl { - return &ast.GenDecl{ - Tok: token.TYPE, - Specs: []ast.Spec{ts}, - } -} - -func pasteStmts(body *ast.BlockStmt, idx int, stmts []ast.Stmt) { - list := body.List - prefix := list[:idx] - suffix := make([]ast.Stmt, len(list)-idx-1) - copy(suffix, list[idx+1:]) - - body.List = append(append(prefix, stmts...), suffix...) -} - -func importFor(is *ast.ImportSpec) *ast.GenDecl { - return &ast.GenDecl{Tok: token.IMPORT, Specs: []ast.Spec{is}} -} - -func importSpec(path string) *ast.ImportSpec { - return &ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"` + path + `"`}} -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go deleted file mode 100644 index 13aa87c2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go +++ /dev/null @@ -1,11 +0,0 @@ -// This file was automatically generated based on the contents of *.tmpl -// If you need to update this file, change the contents of those files -// (or add new ones) and run 'go generate' - -package main - -import "golang.org/x/tools/godoc/vfs/mapfs" - -var ASTTemplates = mapfs.New(map[string]string{ - `full.go`: "package foo\n\nimport (\n \"context\"\n \"encoding/json\"\n \"errors\"\n \"net/http\"\n\n \"github.com/go-kit/kit/endpoint\"\n httptransport \"github.com/go-kit/kit/transport/http\"\n)\n\ntype ExampleService struct {\n}\n\ntype ExampleRequest struct {\n I int\n S string\n}\ntype ExampleResponse struct {\n S string\n Err error\n}\n\ntype Endpoints struct {\n ExampleEndpoint endpoint.Endpoint\n}\n\nfunc (f ExampleService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) {\n panic(errors.New(\"not implemented\"))\n}\n\nfunc makeExampleEndpoint(f ExampleService) endpoint.Endpoint {\n return func(ctx context.Context, request interface{}) (interface{}, error) {\n req := request.(ExampleRequest)\n s, err := f.ExampleEndpoint(ctx, req.I, req.S)\n return ExampleResponse{S: s, Err: err}, nil\n }\n}\n\nfunc inlineHandlerBuilder(m *http.ServeMux, endpoints Endpoints) {\n m.Handle(\"/bar\", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse))\n}\n\nfunc NewHTTPHandler(endpoints Endpoints) http.Handler {\n m := http.NewServeMux()\n inlineHandlerBuilder(m, endpoints)\n return m\n}\n\nfunc DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) {\n var req ExampleRequest\n err := json.NewDecoder(r.Body).Decode(&req)\n return req, err\n}\n\nfunc EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {\n w.Header().Set(\"Content-Type\", \"application/json; charset=utf-8\")\n return json.NewEncoder(w).Encode(response)\n}\n", -}) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go deleted file mode 100644 index 27e2fec3..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import "path/filepath" - -type deflayout struct { - targetDir string -} - -func (l deflayout) packagePath(sub string) string { - return filepath.Join(l.targetDir, sub) -} - -func (l deflayout) transformAST(ctx *sourceContext) (files, error) { - out := make(outputTree) - - endpoints := out.addFile("endpoints/endpoints.go", "endpoints") - http := out.addFile("http/http.go", "http") - service := out.addFile("service/service.go", "service") - - addImports(endpoints, ctx) - addImports(http, ctx) - addImports(service, ctx) - - for _, typ := range ctx.types { - addType(service, typ) - } - - for _, iface := range ctx.interfaces { //only one... - addStubStruct(service, iface) - - for _, meth := range iface.methods { - addMethod(service, iface, meth) - addRequestStruct(endpoints, meth) - addResponseStruct(endpoints, meth) - addEndpointMaker(endpoints, iface, meth) - } - - addEndpointsStruct(endpoints, iface) - addHTTPHandler(http, iface) - - for _, meth := range iface.methods { - addDecoder(http, meth) - addEncoder(http, meth) - } - - for name := range out { - out[name] = selectify(out[name], "service", iface.stubName().Name, l.packagePath("service")) - for _, meth := range iface.methods { - out[name] = selectify(out[name], "endpoints", meth.requestStructName().Name, l.packagePath("endpoints")) - } - } - } - - for name := range out { - out[name] = selectify(out[name], "endpoints", "Endpoints", l.packagePath("endpoints")) - - for _, typ := range ctx.types { - out[name] = selectify(out[name], "service", typ.Name.Name, l.packagePath("service")) - } - } - - return formatNodes(out) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go deleted file mode 100644 index fedffa4b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import "go/ast" - -type flat struct{} - -func (f flat) transformAST(ctx *sourceContext) (files, error) { - root := &ast.File{ - Name: ctx.pkg, - Decls: []ast.Decl{}, - } - - addImports(root, ctx) - - for _, typ := range ctx.types { - addType(root, typ) - } - - for _, iface := range ctx.interfaces { //only one... - addStubStruct(root, iface) - - for _, meth := range iface.methods { - addMethod(root, iface, meth) - addRequestStruct(root, meth) - addResponseStruct(root, meth) - addEndpointMaker(root, iface, meth) - } - - addEndpointsStruct(root, iface) - addHTTPHandler(root, iface) - - for _, meth := range iface.methods { - addDecoder(root, meth) - addEncoder(root, meth) - } - } - - return formatNodes(outputTree{"gokit.go": root}) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go deleted file mode 100644 index 0c984dfc..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import "go/ast" - -// because "interface" is a keyword... -type iface struct { - name, stubname, rcvrName *ast.Ident - methods []method -} - -func (i iface) stubName() *ast.Ident { - return i.stubname -} - -func (i iface) stubStructDecl() ast.Decl { - return structDecl(i.stubName(), &ast.FieldList{}) -} - -func (i iface) endpointsStruct() ast.Decl { - fl := &ast.FieldList{} - for _, m := range i.methods { - fl.List = append(fl.List, &ast.Field{Names: []*ast.Ident{m.name}, Type: sel(id("endpoint"), id("Endpoint"))}) - } - return structDecl(id("Endpoints"), fl) -} - -func (i iface) httpHandler() ast.Decl { - handlerFn := fetchFuncDecl("NewHTTPHandler") - - // does this "inlining" process merit a helper akin to replaceIdent? - handleCalls := []ast.Stmt{} - for _, m := range i.methods { - handleCall := fetchFuncDecl("inlineHandlerBuilder").Body.List[0].(*ast.ExprStmt).X.(*ast.CallExpr) - - handleCall = replaceLit(handleCall, `"/bar"`, `"`+m.pathName()+`"`).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "ExampleEndpoint", m.name).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "DecodeExampleRequest", m.decodeFuncName()).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "EncodeExampleResponse", m.encodeFuncName()).(*ast.CallExpr) - - handleCalls = append(handleCalls, &ast.ExprStmt{X: handleCall}) - } - - pasteStmts(handlerFn.Body, 1, handleCalls) - - return handlerFn -} - -func (i iface) reciever() *ast.Field { - return field(i.receiverName(), i.stubName()) -} - -func (i iface) receiverName() *ast.Ident { - if i.rcvrName != nil { - return i.rcvrName - } - scope := ast.NewScope(nil) - for _, meth := range i.methods { - for _, arg := range meth.params { - if arg.name != nil { - scope.Insert(ast.NewObj(ast.Var, arg.name.Name)) - } - } - for _, arg := range meth.results { - if arg.name != nil { - scope.Insert(ast.NewObj(ast.Var, arg.name.Name)) - } - } - } - return id(unexport(inventName(i.name, scope).Name)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go deleted file mode 100644 index fdfd1fb9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go +++ /dev/null @@ -1,156 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "go/ast" - "go/parser" - "go/token" - "io" - "log" - "os" - "path" - - "github.com/pkg/errors" -) - -// go get github.com/nyarly/inlinefiles -//go:generate inlinefiles --package=main --vfs=ASTTemplates ./templates ast_templates.go - -func usage() string { - return fmt.Sprintf("Usage: %s (try -h)", os.Args[0]) -} - -var ( - help = flag.Bool("h", false, "print this help") - layoutkind = flag.String("repo-layout", "default", "default, flat...") - outdirrel = flag.String("target-dir", ".", "base directory to emit into") - //contextOmittable = flag.Bool("allow-no-context", false, "allow service methods to omit context parameter") -) - -func helpText() { - fmt.Println("USAGE") - fmt.Println(" kitgen [flags] path/to/service.go") - fmt.Println("") - fmt.Println("FLAGS") - flag.PrintDefaults() -} - -func main() { - flag.Parse() - - if *help { - helpText() - os.Exit(0) - } - - outdir := *outdirrel - if !path.IsAbs(*outdirrel) { - wd, err := os.Getwd() - if err != nil { - log.Fatalf("error getting current working directory: %v", err) - } - outdir = path.Join(wd, *outdirrel) - } - - var layout layout - switch *layoutkind { - default: - log.Fatalf("Unrecognized layout kind: %q - try 'default' or 'flat'", *layoutkind) - case "default": - gopath := getGopath() - importBase, err := importPath(outdir, gopath) - if err != nil { - log.Fatal(err) - } - layout = deflayout{targetDir: importBase} - case "flat": - layout = flat{} - } - - if len(os.Args) < 2 { - log.Fatal(usage()) - } - filename := flag.Arg(0) - file, err := os.Open(filename) - if err != nil { - log.Fatalf("error while opening %q: %v", filename, err) - } - - tree, err := process(filename, file, layout) - if err != nil { - log.Fatal(err) - } - - err = splat(outdir, tree) - if err != nil { - log.Fatal(err) - } -} - -func process(filename string, source io.Reader, layout layout) (files, error) { - f, err := parseFile(filename, source) - if err != nil { - return nil, errors.Wrapf(err, "parsing input %q", filename) - } - - context, err := extractContext(f) - if err != nil { - return nil, errors.Wrapf(err, "examining input file %q", filename) - } - - tree, err := layout.transformAST(context) - if err != nil { - return nil, errors.Wrapf(err, "generating AST") - } - return tree, nil -} - -/* - buf, err := formatNode(dest) - if err != nil { - return nil, errors.Wrapf(err, "formatting") - } - return buf, nil -} -*/ - -func parseFile(fname string, source io.Reader) (ast.Node, error) { - f, err := parser.ParseFile(token.NewFileSet(), fname, source, parser.DeclarationErrors) - if err != nil { - return nil, err - } - return f, nil -} - -func extractContext(f ast.Node) (*sourceContext, error) { - context := &sourceContext{} - visitor := &parseVisitor{src: context} - - ast.Walk(visitor, f) - - return context, context.validate() -} - -func splat(dir string, tree files) error { - for fn, buf := range tree { - if err := splatFile(path.Join(dir, fn), buf); err != nil { - return err - } - } - return nil -} - -func splatFile(target string, buf io.Reader) error { - err := os.MkdirAll(path.Dir(target), os.ModePerm) - if err != nil { - return errors.Wrapf(err, "Couldn't create directory for %q", target) - } - f, err := os.Create(target) - if err != nil { - return errors.Wrapf(err, "Couldn't create file %q", target) - } - defer f.Close() - _, err = io.Copy(f, buf) - return errors.Wrapf(err, "Error writing data to file %q", target) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go deleted file mode 100644 index f7a6da1b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go +++ /dev/null @@ -1,220 +0,0 @@ -package main - -import ( - "go/ast" - "go/token" - "strings" -) - -type method struct { - name *ast.Ident - params []arg - results []arg - structsResolved bool -} - -func (m method) definition(ifc iface) ast.Decl { - notImpl := fetchFuncDecl("ExampleEndpoint") - - notImpl.Name = m.name - notImpl.Recv = fieldList(ifc.reciever()) - scope := scopeWith(notImpl.Recv.List[0].Names[0].Name) - notImpl.Type.Params = m.funcParams(scope) - notImpl.Type.Results = m.funcResults() - - return notImpl -} - -func (m method) endpointMaker(ifc iface) ast.Decl { - endpointFn := fetchFuncDecl("makeExampleEndpoint") - scope := scopeWith("ctx", "req", ifc.receiverName().Name) - - anonFunc := endpointFn.Body.List[0].(*ast.ReturnStmt).Results[0].(*ast.FuncLit) - if !m.hasContext() { - // strip context param from endpoint function - anonFunc.Type.Params.List = anonFunc.Type.Params.List[1:] - } - - anonFunc = replaceIdent(anonFunc, "ExampleRequest", m.requestStructName()).(*ast.FuncLit) - callMethod := m.called(ifc, scope, "ctx", "req") - anonFunc.Body.List[1] = callMethod - anonFunc.Body.List[2].(*ast.ReturnStmt).Results[0] = m.wrapResult(callMethod.Lhs) - - endpointFn.Body.List[0].(*ast.ReturnStmt).Results[0] = anonFunc - endpointFn.Name = m.endpointMakerName() - endpointFn.Type.Params = fieldList(ifc.reciever()) - endpointFn.Type.Results = fieldList(typeField(sel(id("endpoint"), id("Endpoint")))) - return endpointFn -} - -func (m method) pathName() string { - return "/" + strings.ToLower(m.name.Name) -} - -func (m method) encodeFuncName() *ast.Ident { - return id("Encode" + m.name.Name + "Response") -} - -func (m method) decodeFuncName() *ast.Ident { - return id("Decode" + m.name.Name + "Request") -} - -func (m method) resultNames(scope *ast.Scope) []*ast.Ident { - ids := []*ast.Ident{} - for _, rz := range m.results { - ids = append(ids, rz.chooseName(scope)) - } - return ids -} - -func (m method) called(ifc iface, scope *ast.Scope, ctxName, spreadStruct string) *ast.AssignStmt { - m.resolveStructNames() - - resNamesExpr := []ast.Expr{} - for _, r := range m.resultNames(scope) { - resNamesExpr = append(resNamesExpr, ast.Expr(r)) - } - - arglist := []ast.Expr{} - if m.hasContext() { - arglist = append(arglist, id(ctxName)) - } - ssid := id(spreadStruct) - for _, f := range m.requestStructFields().List { - arglist = append(arglist, sel(ssid, f.Names[0])) - } - - return &ast.AssignStmt{ - Lhs: resNamesExpr, - Tok: token.DEFINE, - Rhs: []ast.Expr{ - &ast.CallExpr{ - Fun: sel(ifc.receiverName(), m.name), - Args: arglist, - }, - }, - } -} - -func (m method) wrapResult(results []ast.Expr) ast.Expr { - kvs := []ast.Expr{} - m.resolveStructNames() - - for i, a := range m.results { - kvs = append(kvs, &ast.KeyValueExpr{ - Key: ast.NewIdent(export(a.asField.Name)), - Value: results[i], - }) - } - return &ast.CompositeLit{ - Type: m.responseStructName(), - Elts: kvs, - } -} - -func (m method) resolveStructNames() { - if m.structsResolved { - return - } - m.structsResolved = true - scope := ast.NewScope(nil) - for i, p := range m.params { - p.asField = p.chooseName(scope) - m.params[i] = p - } - scope = ast.NewScope(nil) - for i, r := range m.results { - r.asField = r.chooseName(scope) - m.results[i] = r - } -} - -func (m method) decoderFunc() ast.Decl { - fn := fetchFuncDecl("DecodeExampleRequest") - fn.Name = m.decodeFuncName() - fn = replaceIdent(fn, "ExampleRequest", m.requestStructName()).(*ast.FuncDecl) - return fn -} - -func (m method) encoderFunc() ast.Decl { - fn := fetchFuncDecl("EncodeExampleResponse") - fn.Name = m.encodeFuncName() - return fn -} - -func (m method) endpointMakerName() *ast.Ident { - return id("Make" + m.name.Name + "Endpoint") -} - -func (m method) requestStruct() ast.Decl { - m.resolveStructNames() - return structDecl(m.requestStructName(), m.requestStructFields()) -} - -func (m method) responseStruct() ast.Decl { - m.resolveStructNames() - return structDecl(m.responseStructName(), m.responseStructFields()) -} - -func (m method) hasContext() bool { - if len(m.params) < 1 { - return false - } - carg := m.params[0].typ - // ugh. this is maybe okay for the one-off, but a general case for matching - // types would be helpful - if sel, is := carg.(*ast.SelectorExpr); is && sel.Sel.Name == "Context" { - if id, is := sel.X.(*ast.Ident); is && id.Name == "context" { - return true - } - } - return false -} - -func (m method) nonContextParams() []arg { - if m.hasContext() { - return m.params[1:] - } - return m.params -} - -func (m method) funcParams(scope *ast.Scope) *ast.FieldList { - parms := &ast.FieldList{} - if m.hasContext() { - parms.List = []*ast.Field{{ - Names: []*ast.Ident{ast.NewIdent("ctx")}, - Type: sel(id("context"), id("Context")), - }} - scope.Insert(ast.NewObj(ast.Var, "ctx")) - } - parms.List = append(parms.List, mappedFieldList(func(a arg) *ast.Field { - return a.field(scope) - }, m.nonContextParams()...).List...) - return parms -} - -func (m method) funcResults() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.result() - }, m.results...) -} - -func (m method) requestStructName() *ast.Ident { - return id(export(m.name.Name) + "Request") -} - -func (m method) requestStructFields() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.exported() - }, m.nonContextParams()...) -} - -func (m method) responseStructName() *ast.Ident { - return id(export(m.name.Name) + "Response") -} - -func (m method) responseStructFields() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.exported() - }, m.results...) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go deleted file mode 100644 index aa513134..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go +++ /dev/null @@ -1,178 +0,0 @@ -package main - -import ( - "go/ast" -) - -type ( - parseVisitor struct { - src *sourceContext - } - - typeSpecVisitor struct { - src *sourceContext - node *ast.TypeSpec - iface *iface - name *ast.Ident - } - - interfaceTypeVisitor struct { - node *ast.TypeSpec - ts *typeSpecVisitor - methods []method - } - - methodVisitor struct { - depth int - node *ast.TypeSpec - list *[]method - name *ast.Ident - params, results *[]arg - isMethod bool - } - - argListVisitor struct { - list *[]arg - } - - argVisitor struct { - node *ast.TypeSpec - parts []ast.Expr - list *[]arg - } -) - -func (v *parseVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - return v - case *ast.File: - v.src.pkg = rn.Name - return v - case *ast.ImportSpec: - v.src.imports = append(v.src.imports, rn) - return nil - - case *ast.TypeSpec: - switch rn.Type.(type) { - default: - v.src.types = append(v.src.types, rn) - case *ast.InterfaceType: - // can't output interfaces - // because they'd conflict with our implementations - } - return &typeSpecVisitor{src: v.src, node: rn} - } -} - -/* -package foo - -type FooService interface { - Bar(ctx context.Context, i int, s string) (string, error) -} -*/ - -func (v *typeSpecVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - return v - case *ast.Ident: - if v.name == nil { - v.name = rn - } - return v - case *ast.InterfaceType: - return &interfaceTypeVisitor{ts: v, methods: []method{}} - case nil: - if v.iface != nil { - v.iface.name = v.name - sn := *v.name - v.iface.stubname = &sn - v.iface.stubname.Name = v.name.String() - v.src.interfaces = append(v.src.interfaces, *v.iface) - } - return nil - } -} - -func (v *interfaceTypeVisitor) Visit(n ast.Node) ast.Visitor { - switch n.(type) { - default: - return v - case *ast.Field: - return &methodVisitor{list: &v.methods} - case nil: - v.ts.iface = &iface{methods: v.methods} - return nil - } -} - -func (v *methodVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - v.depth++ - return v - case *ast.Ident: - if rn.IsExported() { - v.name = rn - } - v.depth++ - return v - case *ast.FuncType: - v.depth++ - v.isMethod = true - return v - case *ast.FieldList: - if v.params == nil { - v.params = &[]arg{} - return &argListVisitor{list: v.params} - } - if v.results == nil { - v.results = &[]arg{} - } - return &argListVisitor{list: v.results} - case nil: - v.depth-- - if v.depth == 0 && v.isMethod && v.name != nil { - *v.list = append(*v.list, method{name: v.name, params: *v.params, results: *v.results}) - } - return nil - } -} - -func (v *argListVisitor) Visit(n ast.Node) ast.Visitor { - switch n.(type) { - default: - return nil - case *ast.Field: - return &argVisitor{list: v.list} - } -} - -func (v *argVisitor) Visit(n ast.Node) ast.Visitor { - switch t := n.(type) { - case *ast.CommentGroup, *ast.BasicLit: - return nil - case *ast.Ident: //Expr -> everything, but clarity - if t.Name != "_" { - v.parts = append(v.parts, t) - } - case ast.Expr: - v.parts = append(v.parts, t) - case nil: - names := v.parts[:len(v.parts)-1] - tp := v.parts[len(v.parts)-1] - if len(names) == 0 { - *v.list = append(*v.list, arg{typ: tp}) - return nil - } - for _, n := range names { - *v.list = append(*v.list, arg{ - name: n.(*ast.Ident), - typ: tp, - }) - } - } - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go deleted file mode 100644 index f6b70dcd..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go +++ /dev/null @@ -1,759 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" -) - -// A Visitor's Visit method is invoked for each node encountered by walkToReplace. -// If the result visitor w is not nil, walkToReplace visits each of the children -// of node with the visitor w, followed by a call of w.Visit(nil). -type Visitor interface { - Visit(node ast.Node, replace func(ast.Node)) (w Visitor) -} - -// Helper functions for common node lists. They may be empty. - -func walkIdentList(v Visitor, list []*ast.Ident) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(*ast.Ident) - }) - } -} - -func walkExprList(v Visitor, list []ast.Expr) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Expr) - }) - } -} - -func walkStmtList(v Visitor, list []ast.Stmt) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Stmt) - }) - } -} - -func walkDeclList(v Visitor, list []ast.Decl) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Decl) - }) - } -} - -// WalkToReplace traverses an AST in depth-first order: It starts by calling -// v.Visit(node); node must not be nil. If the visitor w returned by -// v.Visit(node) is not nil, walkToReplace is invoked recursively with visitor -// w for each of the non-nil children of node, followed by a call of -// w.Visit(nil). -func WalkReplace(v Visitor, node ast.Node) (replacement ast.Node) { - walkToReplace(v, node, func(r ast.Node) { - replacement = r - }) - return -} - -func walkToReplace(v Visitor, node ast.Node, replace func(ast.Node)) { - if v == nil { - return - } - var replacement ast.Node - repl := func(r ast.Node) { - replacement = r - replace(r) - } - - v = v.Visit(node, repl) - - if replacement != nil { - return - } - - // walk children - // (the order of the cases matches the order - // of the corresponding node types in ast.go) - switch n := node.(type) { - - // These are all leaves, so there's no sub-walk to do. - // We just need to replace them on their parent with a copy. - case *ast.Comment: - cpy := *n - replace(&cpy) - case *ast.BadExpr: - cpy := *n - replace(&cpy) - case *ast.Ident: - cpy := *n - replace(&cpy) - case *ast.BasicLit: - cpy := *n - replace(&cpy) - case *ast.BadDecl: - cpy := *n - replace(&cpy) - case *ast.EmptyStmt: - cpy := *n - replace(&cpy) - case *ast.BadStmt: - cpy := *n - replace(&cpy) - - case *ast.CommentGroup: - cpy := *n - - if n.List != nil { - cpy.List = make([]*ast.Comment, len(n.List)) - copy(cpy.List, n.List) - } - - for i, c := range cpy.List { - walkToReplace(v, c, func(r ast.Node) { - cpy.List[i] = r.(*ast.Comment) - }) - } - replace(&cpy) - - case *ast.Field: - cpy := *n - if n.Names != nil { - cpy.Names = make([]*ast.Ident, len(n.Names)) - copy(cpy.Names, n.Names) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkIdentList(v, cpy.Names) - - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - if cpy.Tag != nil { - walkToReplace(v, cpy.Tag, func(r ast.Node) { - cpy.Tag = r.(*ast.BasicLit) - }) - } - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - replace(&cpy) - - case *ast.FieldList: - cpy := *n - if n.List != nil { - cpy.List = make([]*ast.Field, len(n.List)) - copy(cpy.List, n.List) - } - - for i, f := range cpy.List { - walkToReplace(v, f, func(r ast.Node) { - cpy.List[i] = r.(*ast.Field) - }) - } - - replace(&cpy) - - case *ast.Ellipsis: - cpy := *n - - if cpy.Elt != nil { - walkToReplace(v, cpy.Elt, func(r ast.Node) { - cpy.Elt = r.(ast.Expr) - }) - } - - replace(&cpy) - - case *ast.FuncLit: - cpy := *n - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(*ast.FuncType) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.CompositeLit: - cpy := *n - if n.Elts != nil { - cpy.Elts = make([]ast.Expr, len(n.Elts)) - copy(cpy.Elts, n.Elts) - } - - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - walkExprList(v, cpy.Elts) - - replace(&cpy) - case *ast.ParenExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SelectorExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Sel, func(r ast.Node) { - cpy.Sel = r.(*ast.Ident) - }) - - replace(&cpy) - case *ast.IndexExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Index, func(r ast.Node) { - cpy.Index = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SliceExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - if cpy.Low != nil { - walkToReplace(v, cpy.Low, func(r ast.Node) { - cpy.Low = r.(ast.Expr) - }) - } - if cpy.High != nil { - walkToReplace(v, cpy.High, func(r ast.Node) { - cpy.High = r.(ast.Expr) - }) - } - if cpy.Max != nil { - walkToReplace(v, cpy.Max, func(r ast.Node) { - cpy.Max = r.(ast.Expr) - }) - } - - replace(&cpy) - case *ast.TypeAssertExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - replace(&cpy) - case *ast.CallExpr: - cpy := *n - if n.Args != nil { - cpy.Args = make([]ast.Expr, len(n.Args)) - copy(cpy.Args, n.Args) - } - - walkToReplace(v, cpy.Fun, func(r ast.Node) { - cpy.Fun = r.(ast.Expr) - }) - walkExprList(v, cpy.Args) - - replace(&cpy) - case *ast.StarExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.UnaryExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.BinaryExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Y, func(r ast.Node) { - cpy.Y = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.KeyValueExpr: - cpy := *n - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - - // Types - case *ast.ArrayType: - cpy := *n - if cpy.Len != nil { - walkToReplace(v, cpy.Len, func(r ast.Node) { - cpy.Len = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.Elt, func(r ast.Node) { - cpy.Elt = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.StructType: - cpy := *n - walkToReplace(v, cpy.Fields, func(r ast.Node) { - cpy.Fields = r.(*ast.FieldList) - }) - - replace(&cpy) - case *ast.FuncType: - cpy := *n - if cpy.Params != nil { - walkToReplace(v, cpy.Params, func(r ast.Node) { - cpy.Params = r.(*ast.FieldList) - }) - } - if cpy.Results != nil { - walkToReplace(v, cpy.Results, func(r ast.Node) { - cpy.Results = r.(*ast.FieldList) - }) - } - - replace(&cpy) - case *ast.InterfaceType: - cpy := *n - walkToReplace(v, cpy.Methods, func(r ast.Node) { - cpy.Methods = r.(*ast.FieldList) - }) - - replace(&cpy) - case *ast.MapType: - cpy := *n - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.ChanType: - cpy := *n - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.DeclStmt: - cpy := *n - walkToReplace(v, cpy.Decl, func(r ast.Node) { - cpy.Decl = r.(ast.Decl) - }) - - replace(&cpy) - case *ast.LabeledStmt: - cpy := *n - walkToReplace(v, cpy.Label, func(r ast.Node) { - cpy.Label = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Stmt, func(r ast.Node) { - cpy.Stmt = r.(ast.Stmt) - }) - - replace(&cpy) - case *ast.ExprStmt: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SendStmt: - cpy := *n - walkToReplace(v, cpy.Chan, func(r ast.Node) { - cpy.Chan = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.IncDecStmt: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.AssignStmt: - cpy := *n - if n.Lhs != nil { - cpy.Lhs = make([]ast.Expr, len(n.Lhs)) - copy(cpy.Lhs, n.Lhs) - } - if n.Rhs != nil { - cpy.Rhs = make([]ast.Expr, len(n.Rhs)) - copy(cpy.Rhs, n.Rhs) - } - - walkExprList(v, cpy.Lhs) - walkExprList(v, cpy.Rhs) - - replace(&cpy) - case *ast.GoStmt: - cpy := *n - walkToReplace(v, cpy.Call, func(r ast.Node) { - cpy.Call = r.(*ast.CallExpr) - }) - - replace(&cpy) - case *ast.DeferStmt: - cpy := *n - walkToReplace(v, cpy.Call, func(r ast.Node) { - cpy.Call = r.(*ast.CallExpr) - }) - - replace(&cpy) - case *ast.ReturnStmt: - cpy := *n - if n.Results != nil { - cpy.Results = make([]ast.Expr, len(n.Results)) - copy(cpy.Results, n.Results) - } - - walkExprList(v, cpy.Results) - - replace(&cpy) - case *ast.BranchStmt: - cpy := *n - if cpy.Label != nil { - walkToReplace(v, cpy.Label, func(r ast.Node) { - cpy.Label = r.(*ast.Ident) - }) - } - - replace(&cpy) - case *ast.BlockStmt: - cpy := *n - if n.List != nil { - cpy.List = make([]ast.Stmt, len(n.List)) - copy(cpy.List, n.List) - } - - walkStmtList(v, cpy.List) - - replace(&cpy) - case *ast.IfStmt: - cpy := *n - - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Cond, func(r ast.Node) { - cpy.Cond = r.(ast.Expr) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - if cpy.Else != nil { - walkToReplace(v, cpy.Else, func(r ast.Node) { - cpy.Else = r.(ast.Stmt) - }) - } - - replace(&cpy) - case *ast.CaseClause: - cpy := *n - if n.List != nil { - cpy.List = make([]ast.Expr, len(n.List)) - copy(cpy.List, n.List) - } - if n.Body != nil { - cpy.Body = make([]ast.Stmt, len(n.Body)) - copy(cpy.Body, n.Body) - } - - walkExprList(v, cpy.List) - walkStmtList(v, cpy.Body) - - replace(&cpy) - case *ast.SwitchStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - if cpy.Tag != nil { - walkToReplace(v, cpy.Tag, func(r ast.Node) { - cpy.Tag = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.TypeSwitchStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Assign, func(r ast.Node) { - cpy.Assign = r.(ast.Stmt) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.CommClause: - cpy := *n - if n.Body != nil { - cpy.Body = make([]ast.Stmt, len(n.Body)) - copy(cpy.Body, n.Body) - } - - if cpy.Comm != nil { - walkToReplace(v, cpy.Comm, func(r ast.Node) { - cpy.Comm = r.(ast.Stmt) - }) - } - walkStmtList(v, cpy.Body) - - replace(&cpy) - case *ast.SelectStmt: - cpy := *n - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.ForStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - if cpy.Cond != nil { - walkToReplace(v, cpy.Cond, func(r ast.Node) { - cpy.Cond = r.(ast.Expr) - }) - } - if cpy.Post != nil { - walkToReplace(v, cpy.Post, func(r ast.Node) { - cpy.Post = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.RangeStmt: - cpy := *n - if cpy.Key != nil { - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - } - if cpy.Value != nil { - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - // Declarations - replace(&cpy) - case *ast.ImportSpec: - cpy := *n - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - if cpy.Name != nil { - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - } - walkToReplace(v, cpy.Path, func(r ast.Node) { - cpy.Path = r.(*ast.BasicLit) - }) - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - case *ast.ValueSpec: - cpy := *n - if n.Names != nil { - cpy.Names = make([]*ast.Ident, len(n.Names)) - copy(cpy.Names, n.Names) - } - if n.Values != nil { - cpy.Values = make([]ast.Expr, len(n.Values)) - copy(cpy.Values, n.Values) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - - walkIdentList(v, cpy.Names) - - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - - walkExprList(v, cpy.Values) - - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - - case *ast.TypeSpec: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - case *ast.GenDecl: - cpy := *n - if n.Specs != nil { - cpy.Specs = make([]ast.Spec, len(n.Specs)) - copy(cpy.Specs, n.Specs) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - for i, s := range cpy.Specs { - walkToReplace(v, s, func(r ast.Node) { - cpy.Specs[i] = r.(ast.Spec) - }) - } - - replace(&cpy) - case *ast.FuncDecl: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - if cpy.Recv != nil { - walkToReplace(v, cpy.Recv, func(r ast.Node) { - cpy.Recv = r.(*ast.FieldList) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(*ast.FuncType) - }) - if cpy.Body != nil { - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - } - - // Files and packages - replace(&cpy) - case *ast.File: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkDeclList(v, cpy.Decls) - // don't walk cpy.Comments - they have been - // visited already through the individual - // nodes - - replace(&cpy) - case *ast.Package: - cpy := *n - cpy.Files = map[string]*ast.File{} - - for i, f := range n.Files { - cpy.Files[i] = f - walkToReplace(v, f, func(r ast.Node) { - cpy.Files[i] = r.(*ast.File) - }) - } - replace(&cpy) - - default: - panic(fmt.Sprintf("walkToReplace: unexpected node type %T", n)) - } - - if v != nil { - v.Visit(nil, func(ast.Node) { panic("can't replace the go-up nil") }) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go deleted file mode 100644 index 35933a20..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/token" -) - -type sourceContext struct { - pkg *ast.Ident - imports []*ast.ImportSpec - interfaces []iface - types []*ast.TypeSpec -} - -func (sc *sourceContext) validate() error { - if len(sc.interfaces) != 1 { - return fmt.Errorf("found %d interfaces, expecting exactly 1", len(sc.interfaces)) - } - for _, i := range sc.interfaces { - for _, m := range i.methods { - if len(m.results) < 1 { - return fmt.Errorf("method %q of interface %q has no result types", m.name, i.name) - } - } - } - return nil -} - -func (sc *sourceContext) importDecls() (decls []ast.Decl) { - have := map[string]struct{}{} - notHave := func(is *ast.ImportSpec) bool { - if _, has := have[is.Path.Value]; has { - return false - } - have[is.Path.Value] = struct{}{} - return true - } - - for _, is := range sc.imports { - if notHave(is) { - decls = append(decls, importFor(is)) - } - } - - for _, is := range fetchImports() { - if notHave(is) { - decls = append(decls, &ast.GenDecl{Tok: token.IMPORT, Specs: []ast.Spec{is}}) - } - } - - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go deleted file mode 100644 index c3516856..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go +++ /dev/null @@ -1,60 +0,0 @@ -package foo - -import ( - "context" - "encoding/json" - "errors" - "net/http" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -type ExampleService struct { -} - -type ExampleRequest struct { - I int - S string -} -type ExampleResponse struct { - S string - Err error -} - -type Endpoints struct { - ExampleEndpoint endpoint.Endpoint -} - -func (f ExampleService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) { - panic(errors.New("not implemented")) -} - -func makeExampleEndpoint(f ExampleService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(ExampleRequest) - s, err := f.ExampleEndpoint(ctx, req.I, req.S) - return ExampleResponse{S: s, Err: err}, nil - } -} - -func inlineHandlerBuilder(m *http.ServeMux, endpoints Endpoints) { - m.Handle("/bar", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse)) -} - -func NewHTTPHandler(endpoints Endpoints) http.Handler { - m := http.NewServeMux() - inlineHandlerBuilder(m, endpoints) - return m -} - -func DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req ExampleRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -func EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go deleted file mode 100644 index 362398c9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go +++ /dev/null @@ -1,230 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "go/ast" - "go/format" - "go/token" - "io" - "os" - "path/filepath" - "sort" - "strings" - - "github.com/davecgh/go-spew/spew" - "github.com/pkg/errors" - - "golang.org/x/tools/imports" -) - -type ( - files map[string]io.Reader - layout interface { - transformAST(ctx *sourceContext) (files, error) - } - outputTree map[string]*ast.File -) - -func (ot outputTree) addFile(path, pkgname string) *ast.File { - file := &ast.File{ - Name: id(pkgname), - Decls: []ast.Decl{}, - } - ot[path] = file - return file -} - -func getGopath() string { - gopath, set := os.LookupEnv("GOPATH") - if !set { - return filepath.Join(os.Getenv("HOME"), "go") - } - return gopath -} - -func importPath(targetDir, gopath string) (string, error) { - if !filepath.IsAbs(targetDir) { - return "", fmt.Errorf("%q is not an absolute path", targetDir) - } - - for _, dir := range filepath.SplitList(gopath) { - abspath, err := filepath.Abs(dir) - if err != nil { - continue - } - srcPath := filepath.Join(abspath, "src") - - res, err := filepath.Rel(srcPath, targetDir) - if err != nil { - continue - } - if strings.Index(res, "..") == -1 { - return res, nil - } - } - return "", fmt.Errorf("%q is not in GOPATH (%s)", targetDir, gopath) - -} - -func selectify(file *ast.File, pkgName, identName, importPath string) *ast.File { - if file.Name.Name == pkgName { - return file - } - - selector := sel(id(pkgName), id(identName)) - var did bool - if file, did = selectifyIdent(identName, file, selector); did { - addImport(file, importPath) - } - return file -} - -type selIdentFn func(ast.Node, func(ast.Node)) Visitor - -func (f selIdentFn) Visit(node ast.Node, r func(ast.Node)) Visitor { - return f(node, r) -} - -func selectifyIdent(identName string, file *ast.File, selector ast.Expr) (*ast.File, bool) { - var replaced bool - var r selIdentFn - r = selIdentFn(func(node ast.Node, replaceWith func(ast.Node)) Visitor { - switch id := node.(type) { - case *ast.SelectorExpr: - return nil - case *ast.Ident: - if id.Name == identName { - replaced = true - replaceWith(selector) - } - } - return r - }) - return WalkReplace(r, file).(*ast.File), replaced -} - -func formatNode(fname string, node ast.Node) (*bytes.Buffer, error) { - if file, is := node.(*ast.File); is { - sort.Stable(sortableDecls(file.Decls)) - } - outfset := token.NewFileSet() - buf := &bytes.Buffer{} - err := format.Node(buf, outfset, node) - if err != nil { - return nil, err - } - imps, err := imports.Process(fname, buf.Bytes(), nil) - if err != nil { - return nil, err - } - return bytes.NewBuffer(imps), nil -} - -type sortableDecls []ast.Decl - -func (sd sortableDecls) Len() int { - return len(sd) -} - -func (sd sortableDecls) Less(i int, j int) bool { - switch left := sd[i].(type) { - case *ast.GenDecl: - switch right := sd[j].(type) { - default: - return left.Tok == token.IMPORT - case *ast.GenDecl: - return left.Tok == token.IMPORT && right.Tok != token.IMPORT - } - } - return false -} - -func (sd sortableDecls) Swap(i int, j int) { - sd[i], sd[j] = sd[j], sd[i] -} - -func formatNodes(nodes outputTree) (files, error) { - res := files{} - var err error - for fn, node := range nodes { - res[fn], err = formatNode(fn, node) - if err != nil { - return nil, errors.Wrapf(err, "formatNodes") - } - } - return res, nil -} - -// XXX debug -func spewDecls(f *ast.File) { - for _, d := range f.Decls { - switch dcl := d.(type) { - default: - spew.Dump(dcl) - case *ast.GenDecl: - spew.Dump(dcl.Tok) - case *ast.FuncDecl: - spew.Dump(dcl.Name.Name) - } - } -} - -func addImports(root *ast.File, ctx *sourceContext) { - root.Decls = append(root.Decls, ctx.importDecls()...) -} - -func addImport(root *ast.File, path string) { - for _, d := range root.Decls { - if imp, is := d.(*ast.GenDecl); is && imp.Tok == token.IMPORT { - for _, s := range imp.Specs { - if s.(*ast.ImportSpec).Path.Value == `"`+path+`"` { - return // already have one - // xxx aliased imports? - } - } - } - } - root.Decls = append(root.Decls, importFor(importSpec(path))) -} - -func addStubStruct(root *ast.File, iface iface) { - root.Decls = append(root.Decls, iface.stubStructDecl()) -} - -func addType(root *ast.File, typ *ast.TypeSpec) { - root.Decls = append(root.Decls, typeDecl(typ)) -} - -func addMethod(root *ast.File, iface iface, meth method) { - def := meth.definition(iface) - root.Decls = append(root.Decls, def) -} - -func addRequestStruct(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.requestStruct()) -} - -func addResponseStruct(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.responseStruct()) -} - -func addEndpointMaker(root *ast.File, ifc iface, meth method) { - root.Decls = append(root.Decls, meth.endpointMaker(ifc)) -} - -func addEndpointsStruct(root *ast.File, ifc iface) { - root.Decls = append(root.Decls, ifc.endpointsStruct()) -} - -func addHTTPHandler(root *ast.File, ifc iface) { - root.Decls = append(root.Decls, ifc.httpHandler()) -} - -func addDecoder(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.decoderFunc()) -} - -func addEncoder(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.encoderFunc()) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash deleted file mode 100755 index cf8fee93..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -if ! type -P gover -then - echo gover missing: go get github.com/modocache/gover - exit 1 -fi - -if ! type -P goveralls -then - echo goveralls missing: go get github.com/mattn/goveralls - exit 1 -fi - -if [[ "$COVERALLS_TOKEN" == "" ]] -then - echo COVERALLS_TOKEN not set - exit 1 -fi - -go list ./... | grep -v '/examples/' | cut -d'/' -f 4- | while read d -do - cd $d - go test -covermode count -coverprofile coverage.coverprofile - cd - -done - -gover -goveralls -coverprofile gover.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN -find . -name '*.coverprofile' -delete - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml deleted file mode 100644 index 287d97db..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '2' -services: - etcd: - image: quay.io/coreos/etcd - ports: - - "2379:2379" - command: /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001" - consul: - image: progrium/consul - ports: - - "8500:8500" - command: -server -bootstrap - zk: - image: zookeeper - ports: - - "2181:2181" - eureka: - image: springcloud/eureka - environment: - eureka.server.responseCacheUpdateIntervalMs: 1000 - ports: - - "8761:8761" diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go deleted file mode 100644 index 84e27b95..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Package endpoint defines an abstraction for RPCs. -// -// Endpoints are a fundamental building block for many Go kit components. -// Endpoints are implemented by servers, and called by clients. -package endpoint diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go deleted file mode 100644 index 6e9da367..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go +++ /dev/null @@ -1,40 +0,0 @@ -package endpoint - -import ( - "context" -) - -// Endpoint is the fundamental building block of servers and clients. -// It represents a single RPC method. -type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error) - -// Nop is an endpoint that does nothing and returns a nil error. -// Useful for tests. -func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil } - -// Middleware is a chainable behavior modifier for endpoints. -type Middleware func(Endpoint) Endpoint - -// Chain is a helper function for composing middlewares. Requests will -// traverse them in the order they're declared. That is, the first middleware -// is treated as the outermost middleware. -func Chain(outer Middleware, others ...Middleware) Middleware { - return func(next Endpoint) Endpoint { - for i := len(others) - 1; i >= 0; i-- { // reverse - next = others[i](next) - } - return outer(next) - } -} - -// Failer may be implemented by Go kit response types that contain business -// logic error details. If Failed returns a non-nil error, the Go kit transport -// layer may interpret this as a business logic error, and may encode it -// differently than a regular, successful response. -// -// It's not necessary for your response types to implement Failer, but it may -// help for more sophisticated use cases. The addsvc example shows how Failer -// should be used by a complete application. -type Failer interface { - Failed() error -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md deleted file mode 100644 index 2891d788..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Examples - -For more information about these examples, - including a walkthrough of the stringsvc example, - see [gokit.io/examples](https://gokit.io/examples). diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md deleted file mode 100644 index 08080060..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# addsvc - -addsvc is an example microservice which takes full advantage of most of Go -kit's features, including both service- and transport-level middlewares, -speaking multiple transports simultaneously, distributed tracing, and rich -error definitions. The server binary is available in cmd/addsvc. The client -binary is available in cmd/addcli. - -Finally, the addtransport package provides both server and clients for each -supported transport. The client structs bake-in certain middlewares, in order to -demonstrate the _client library pattern_. But beware: client libraries are -generally a bad idea, because they easily lead to the - [distributed monolith antipattern](https://www.microservices.com/talks/dont-build-a-distributed-monolith/). -If you don't _know_ you need to use one in your organization, it's probably best -avoided: prefer moving that logic to consumers, and relying on - [contract testing](https://docs.pact.io/best_practices/contract_tests_not_functional_tests.html) -to detect incompatibilities. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go deleted file mode 100644 index 099eb590..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go +++ /dev/null @@ -1,226 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "os" - "strconv" - "text/tabwriter" - "time" - - "google.golang.org/grpc" - - "github.com/apache/thrift/lib/go/thrift" - lightstep "github.com/lightstep/lightstep-tracer-go" - stdopentracing "github.com/opentracing/opentracing-go" - zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" - zipkin "github.com/openzipkin/zipkin-go" - zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" - "sourcegraph.com/sourcegraph/appdash" - appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -func main() { - // The addcli presumes no service discovery system, and expects users to - // provide the direct address of an addsvc. This presumption is reflected in - // the addcli binary and the client packages: the -transport.addr flags - // and various client constructors both expect host:port strings. For an - // example service with a client built on top of a service discovery system, - // see profilesvc. - fs := flag.NewFlagSet("addcli", flag.ExitOnError) - var ( - httpAddr = fs.String("http-addr", "", "HTTP address of addsvc") - grpcAddr = fs.String("grpc-addr", "", "gRPC address of addsvc") - thriftAddr = fs.String("thrift-addr", "", "Thrift address of addsvc") - jsonRPCAddr = fs.String("jsonrpc-addr", "", "JSON RPC address of addsvc") - thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") - thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") - thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") - zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) via HTTP Reporter URL e.g. http://localhost:9411/api/v2/spans") - zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) via a collector URL e.g. http://localhost:9411/api/v1/spans") - lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") - appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") - method = fs.String("method", "sum", "sum, concat") - ) - fs.Usage = usageFor(fs, os.Args[0]+" [flags] ") - fs.Parse(os.Args[1:]) - if len(fs.Args()) != 2 { - fs.Usage() - os.Exit(1) - } - - // This is a demonstration client, which supports multiple tracers. - // Your clients will probably just use one tracer. - var otTracer stdopentracing.Tracer - { - if *zipkinV1URL != "" && *zipkinV2URL == "" { - collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - defer collector.Close() - var ( - debug = false - hostPort = "localhost:0" - serviceName = "addsvc-cli" - ) - recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) - otTracer, err = zipkinot.NewTracer(recorder) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - } else if *lightstepToken != "" { - otTracer = lightstep.NewTracer(lightstep.Options{ - AccessToken: *lightstepToken, - }) - defer lightstep.FlushLightStepTracer(otTracer) - } else if *appdashAddr != "" { - otTracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) - } else { - otTracer = stdopentracing.GlobalTracer() // no-op - } - } - - // This is a demonstration of the native Zipkin tracing client. If using - // Zipkin this is the more idiomatic client over OpenTracing. - var zipkinTracer *zipkin.Tracer - { - var ( - err error - hostPort = "" // if host:port is unknown we can keep this empty - serviceName = "addsvc-cli" - useNoopTracer = (*zipkinV2URL == "") - reporter = zipkinhttp.NewReporter(*zipkinV2URL) - ) - defer reporter.Close() - zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) - zipkinTracer, err = zipkin.NewTracer( - reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), - ) - if err != nil { - fmt.Fprintf(os.Stderr, "unable to create zipkin tracer: %s\n", err.Error()) - os.Exit(1) - } - } - - // This is a demonstration client, which supports multiple transports. - // Your clients will probably just define and stick with 1 transport. - var ( - svc addservice.Service - err error - ) - if *httpAddr != "" { - svc, err = addtransport.NewHTTPClient(*httpAddr, otTracer, zipkinTracer, log.NewNopLogger()) - } else if *grpcAddr != "" { - conn, err := grpc.Dial(*grpcAddr, grpc.WithInsecure(), grpc.WithTimeout(time.Second)) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v", err) - os.Exit(1) - } - defer conn.Close() - svc = addtransport.NewGRPCClient(conn, otTracer, zipkinTracer, log.NewNopLogger()) - } else if *jsonRPCAddr != "" { - svc, err = addtransport.NewJSONRPCClient(*jsonRPCAddr, otTracer, log.NewNopLogger()) - } else if *thriftAddr != "" { - // It's necessary to do all of this construction in the func main, - // because (among other reasons) we need to control the lifecycle of the - // Thrift transport, i.e. close it eventually. - var protocolFactory thrift.TProtocolFactory - switch *thriftProtocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - default: - fmt.Fprintf(os.Stderr, "error: invalid protocol %q\n", *thriftProtocol) - os.Exit(1) - } - var transportFactory thrift.TTransportFactory - if *thriftBuffer > 0 { - transportFactory = thrift.NewTBufferedTransportFactory(*thriftBuffer) - } else { - transportFactory = thrift.NewTTransportFactory() - } - if *thriftFramed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) - } - transportSocket, err := thrift.NewTSocket(*thriftAddr) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - transport, err := transportFactory.GetTransport(transportSocket) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - if err := transport.Open(); err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - defer transport.Close() - client := addthrift.NewAddServiceClientFactory(transport, protocolFactory) - svc = addtransport.NewThriftClient(client) - } else { - fmt.Fprintf(os.Stderr, "error: no remote address specified\n") - os.Exit(1) - } - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - - switch *method { - case "sum": - a, _ := strconv.ParseInt(fs.Args()[0], 10, 64) - b, _ := strconv.ParseInt(fs.Args()[1], 10, 64) - v, err := svc.Sum(context.Background(), int(a), int(b)) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - fmt.Fprintf(os.Stdout, "%d + %d = %d\n", a, b, v) - - case "concat": - a := fs.Args()[0] - b := fs.Args()[1] - v, err := svc.Concat(context.Background(), a, b) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - fmt.Fprintf(os.Stdout, "%q + %q = %q\n", a, b, v) - - default: - fmt.Fprintf(os.Stderr, "error: invalid method %q\n", *method) - os.Exit(1) - } -} - -func usageFor(fs *flag.FlagSet, short string) func() { - return func() { - fmt.Fprintf(os.Stderr, "USAGE\n") - fmt.Fprintf(os.Stderr, " %s\n", short) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "FLAGS\n") - w := tabwriter.NewWriter(os.Stderr, 0, 2, 2, ' ', 0) - fs.VisitAll(func(f *flag.Flag) { - fmt.Fprintf(w, "\t-%s %s\t%s\n", f.Name, f.DefValue, f.Usage) - }) - w.Flush() - fmt.Fprintf(os.Stderr, "\n") - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go deleted file mode 100644 index dac7c560..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go +++ /dev/null @@ -1,322 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "net" - "net/http" - "os" - "os/signal" - "syscall" - "text/tabwriter" - - "github.com/apache/thrift/lib/go/thrift" - lightstep "github.com/lightstep/lightstep-tracer-go" - "github.com/oklog/oklog/pkg/group" - stdopentracing "github.com/opentracing/opentracing-go" - zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" - zipkin "github.com/openzipkin/zipkin-go" - zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - "google.golang.org/grpc" - "sourcegraph.com/sourcegraph/appdash" - appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" - "github.com/go-kit/kit/metrics/prometheus" - kitgrpc "github.com/go-kit/kit/transport/grpc" - - addpb "github.com/go-kit/kit/examples/addsvc/pb" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -func main() { - // Define our flags. Your service probably won't need to bind listeners for - // *all* supported transports, or support both Zipkin and LightStep, and so - // on, but we do it here for demonstration purposes. - fs := flag.NewFlagSet("addsvc", flag.ExitOnError) - var ( - debugAddr = fs.String("debug.addr", ":8080", "Debug and metrics listen address") - httpAddr = fs.String("http-addr", ":8081", "HTTP listen address") - grpcAddr = fs.String("grpc-addr", ":8082", "gRPC listen address") - thriftAddr = fs.String("thrift-addr", ":8083", "Thrift listen address") - jsonRPCAddr = fs.String("jsonrpc-addr", ":8084", "JSON RPC listen address") - thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") - thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") - thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") - zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) using a Reporter URL e.g. http://localhost:9411/api/v2/spans") - zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) using a collector URL e.g. http://localhost:9411/api/v1/spans") - lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") - appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") - ) - fs.Usage = usageFor(fs, os.Args[0]+" [flags]") - fs.Parse(os.Args[1:]) - - // Create a single logger, which we'll use and give to other components. - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - // Determine which OpenTracing tracer to use. We'll pass the tracer to all the - // components that use it, as a dependency. - var tracer stdopentracing.Tracer - { - if *zipkinV1URL != "" && *zipkinV2URL == "" { - logger.Log("tracer", "Zipkin", "type", "OpenTracing", "URL", *zipkinV1URL) - collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - defer collector.Close() - var ( - debug = false - hostPort = "localhost:80" - serviceName = "addsvc" - ) - recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) - tracer, err = zipkinot.NewTracer(recorder) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - } else if *lightstepToken != "" { - logger.Log("tracer", "LightStep") // probably don't want to print out the token :) - tracer = lightstep.NewTracer(lightstep.Options{ - AccessToken: *lightstepToken, - }) - defer lightstep.FlushLightStepTracer(tracer) - } else if *appdashAddr != "" { - logger.Log("tracer", "Appdash", "addr", *appdashAddr) - tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) - } else { - tracer = stdopentracing.GlobalTracer() // no-op - } - } - - var zipkinTracer *zipkin.Tracer - { - var ( - err error - hostPort = "localhost:80" - serviceName = "addsvc" - useNoopTracer = (*zipkinV2URL == "") - reporter = zipkinhttp.NewReporter(*zipkinV2URL) - ) - defer reporter.Close() - zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) - zipkinTracer, err = zipkin.NewTracer( - reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - if !useNoopTracer { - logger.Log("tracer", "Zipkin", "type", "Native", "URL", *zipkinV2URL) - } - } - - // Create the (sparse) metrics we'll use in the service. They, too, are - // dependencies that we pass to components that use them. - var ints, chars metrics.Counter - { - // Business-level metrics. - ints = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "integers_summed", - Help: "Total count of integers summed via the Sum method.", - }, []string{}) - chars = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "characters_concatenated", - Help: "Total count of characters concatenated via the Concat method.", - }, []string{}) - } - var duration metrics.Histogram - { - // Endpoint-level metrics. - duration = prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "request_duration_seconds", - Help: "Request duration in seconds.", - }, []string{"method", "success"}) - } - http.DefaultServeMux.Handle("/metrics", promhttp.Handler()) - - // Build the layers of the service "onion" from the inside out. First, the - // business logic service; then, the set of endpoints that wrap the service; - // and finally, a series of concrete transport adapters. The adapters, like - // the HTTP handler or the gRPC server, are the bridge between Go kit and - // the interfaces that the transports expect. Note that we're not binding - // them to ports or anything yet; we'll do that next. - var ( - service = addservice.New(logger, ints, chars) - endpoints = addendpoint.New(service, logger, duration, tracer, zipkinTracer) - httpHandler = addtransport.NewHTTPHandler(endpoints, tracer, zipkinTracer, logger) - grpcServer = addtransport.NewGRPCServer(endpoints, tracer, zipkinTracer, logger) - thriftServer = addtransport.NewThriftServer(endpoints) - jsonrpcHandler = addtransport.NewJSONRPCHandler(endpoints, logger) - ) - - // Now we're to the part of the func main where we want to start actually - // running things, like servers bound to listeners to receive connections. - // - // The method is the same for each component: add a new actor to the group - // struct, which is a combination of 2 anonymous functions: the first - // function actually runs the component, and the second function should - // interrupt the first function and cause it to return. It's in these - // functions that we actually bind the Go kit server/handler structs to the - // concrete transports and run them. - // - // Putting each component into its own block is mostly for aesthetics: it - // clearly demarcates the scope in which each listener/socket may be used. - var g group.Group - { - // The debug listener mounts the http.DefaultServeMux, and serves up - // stuff like the Prometheus metrics route, the Go debug and profiling - // routes, and so on. - debugListener, err := net.Listen("tcp", *debugAddr) - if err != nil { - logger.Log("transport", "debug/HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "debug/HTTP", "addr", *debugAddr) - return http.Serve(debugListener, http.DefaultServeMux) - }, func(error) { - debugListener.Close() - }) - } - { - // The HTTP listener mounts the Go kit HTTP handler we created. - httpListener, err := net.Listen("tcp", *httpAddr) - if err != nil { - logger.Log("transport", "HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "HTTP", "addr", *httpAddr) - return http.Serve(httpListener, httpHandler) - }, func(error) { - httpListener.Close() - }) - } - { - // The gRPC listener mounts the Go kit gRPC server we created. - grpcListener, err := net.Listen("tcp", *grpcAddr) - if err != nil { - logger.Log("transport", "gRPC", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "gRPC", "addr", *grpcAddr) - // we add the Go Kit gRPC Interceptor to our gRPC service as it is used by - // the here demonstrated zipkin tracing middleware. - baseServer := grpc.NewServer(grpc.UnaryInterceptor(kitgrpc.Interceptor)) - addpb.RegisterAddServer(baseServer, grpcServer) - return baseServer.Serve(grpcListener) - }, func(error) { - grpcListener.Close() - }) - } - { - // The Thrift socket mounts the Go kit Thrift server we created earlier. - // There's a lot of boilerplate involved here, related to configuring - // the protocol and transport; blame Thrift. - thriftSocket, err := thrift.NewTServerSocket(*thriftAddr) - if err != nil { - logger.Log("transport", "Thrift", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "Thrift", "addr", *thriftAddr) - var protocolFactory thrift.TProtocolFactory - switch *thriftProtocol { - case "binary": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - default: - return fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol) - } - var transportFactory thrift.TTransportFactory - if *thriftBuffer > 0 { - transportFactory = thrift.NewTBufferedTransportFactory(*thriftBuffer) - } else { - transportFactory = thrift.NewTTransportFactory() - } - if *thriftFramed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) - } - return thrift.NewTSimpleServer4( - addthrift.NewAddServiceProcessor(thriftServer), - thriftSocket, - transportFactory, - protocolFactory, - ).Serve() - }, func(error) { - thriftSocket.Close() - }) - } - { - httpListener, err := net.Listen("tcp", *jsonRPCAddr) - if err != nil { - logger.Log("transport", "JSONRPC over HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "JSONRPC over HTTP", "addr", *jsonRPCAddr) - return http.Serve(httpListener, jsonrpcHandler) - }, func(error) { - httpListener.Close() - }) - } - { - // This function just sits and waits for ctrl-C. - cancelInterrupt := make(chan struct{}) - g.Add(func() error { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - select { - case sig := <-c: - return fmt.Errorf("received signal %s", sig) - case <-cancelInterrupt: - return nil - } - }, func(error) { - close(cancelInterrupt) - }) - } - logger.Log("exit", g.Run()) -} - -func usageFor(fs *flag.FlagSet, short string) func() { - return func() { - fmt.Fprintf(os.Stderr, "USAGE\n") - fmt.Fprintf(os.Stderr, " %s\n", short) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "FLAGS\n") - w := tabwriter.NewWriter(os.Stderr, 0, 2, 2, ' ', 0) - fs.VisitAll(func(f *flag.Flag) { - fmt.Fprintf(w, "\t-%s %s\t%s\n", f.Name, f.DefValue, f.Usage) - }) - w.Flush() - fmt.Fprintf(os.Stderr, "\n") - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go deleted file mode 100644 index 781b50b7..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go +++ /dev/null @@ -1,270 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: addsvc.proto - -/* -Package pb is a generated protocol buffer package. - -It is generated from these files: - addsvc.proto - -It has these top-level messages: - SumRequest - SumReply - ConcatRequest - ConcatReply -*/ -package pb - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// 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.ProtoPackageIsVersion2 // please upgrade the proto package - -// The sum request contains two parameters. -type SumRequest struct { - A int64 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"` - B int64 `protobuf:"varint,2,opt,name=b" json:"b,omitempty"` -} - -func (m *SumRequest) Reset() { *m = SumRequest{} } -func (m *SumRequest) String() string { return proto.CompactTextString(m) } -func (*SumRequest) ProtoMessage() {} -func (*SumRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -func (m *SumRequest) GetA() int64 { - if m != nil { - return m.A - } - return 0 -} - -func (m *SumRequest) GetB() int64 { - if m != nil { - return m.B - } - return 0 -} - -// The sum response contains the result of the calculation. -type SumReply struct { - V int64 `protobuf:"varint,1,opt,name=v" json:"v,omitempty"` - Err string `protobuf:"bytes,2,opt,name=err" json:"err,omitempty"` -} - -func (m *SumReply) Reset() { *m = SumReply{} } -func (m *SumReply) String() string { return proto.CompactTextString(m) } -func (*SumReply) ProtoMessage() {} -func (*SumReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -func (m *SumReply) GetV() int64 { - if m != nil { - return m.V - } - return 0 -} - -func (m *SumReply) GetErr() string { - if m != nil { - return m.Err - } - return "" -} - -// The Concat request contains two parameters. -type ConcatRequest struct { - A string `protobuf:"bytes,1,opt,name=a" json:"a,omitempty"` - B string `protobuf:"bytes,2,opt,name=b" json:"b,omitempty"` -} - -func (m *ConcatRequest) Reset() { *m = ConcatRequest{} } -func (m *ConcatRequest) String() string { return proto.CompactTextString(m) } -func (*ConcatRequest) ProtoMessage() {} -func (*ConcatRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - -func (m *ConcatRequest) GetA() string { - if m != nil { - return m.A - } - return "" -} - -func (m *ConcatRequest) GetB() string { - if m != nil { - return m.B - } - return "" -} - -// The Concat response contains the result of the concatenation. -type ConcatReply struct { - V string `protobuf:"bytes,1,opt,name=v" json:"v,omitempty"` - Err string `protobuf:"bytes,2,opt,name=err" json:"err,omitempty"` -} - -func (m *ConcatReply) Reset() { *m = ConcatReply{} } -func (m *ConcatReply) String() string { return proto.CompactTextString(m) } -func (*ConcatReply) ProtoMessage() {} -func (*ConcatReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - -func (m *ConcatReply) GetV() string { - if m != nil { - return m.V - } - return "" -} - -func (m *ConcatReply) GetErr() string { - if m != nil { - return m.Err - } - return "" -} - -func init() { - proto.RegisterType((*SumRequest)(nil), "pb.SumRequest") - proto.RegisterType((*SumReply)(nil), "pb.SumReply") - proto.RegisterType((*ConcatRequest)(nil), "pb.ConcatRequest") - proto.RegisterType((*ConcatReply)(nil), "pb.ConcatReply") -} - -// 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 - -// Client API for Add service - -type AddClient interface { - // Sums two integers. - Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumReply, error) - // Concatenates two strings - Concat(ctx context.Context, in *ConcatRequest, opts ...grpc.CallOption) (*ConcatReply, error) -} - -type addClient struct { - cc *grpc.ClientConn -} - -func NewAddClient(cc *grpc.ClientConn) AddClient { - return &addClient{cc} -} - -func (c *addClient) Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumReply, error) { - out := new(SumReply) - err := grpc.Invoke(ctx, "/pb.Add/Sum", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *addClient) Concat(ctx context.Context, in *ConcatRequest, opts ...grpc.CallOption) (*ConcatReply, error) { - out := new(ConcatReply) - err := grpc.Invoke(ctx, "/pb.Add/Concat", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Add service - -type AddServer interface { - // Sums two integers. - Sum(context.Context, *SumRequest) (*SumReply, error) - // Concatenates two strings - Concat(context.Context, *ConcatRequest) (*ConcatReply, error) -} - -func RegisterAddServer(s *grpc.Server, srv AddServer) { - s.RegisterService(&_Add_serviceDesc, srv) -} - -func _Add_Sum_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SumRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AddServer).Sum(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.Add/Sum", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AddServer).Sum(ctx, req.(*SumRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Add_Concat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ConcatRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AddServer).Concat(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.Add/Concat", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AddServer).Concat(ctx, req.(*ConcatRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Add_serviceDesc = grpc.ServiceDesc{ - ServiceName: "pb.Add", - HandlerType: (*AddServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Sum", - Handler: _Add_Sum_Handler, - }, - { - MethodName: "Concat", - Handler: _Add_Concat_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "addsvc.proto", -} - -func init() { proto.RegisterFile("addsvc.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 189 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x4c, 0x49, 0x29, - 0x2e, 0x4b, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52, 0xd2, 0xe0, 0xe2, - 0x0a, 0x2e, 0xcd, 0x0d, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0xe2, 0xe1, 0x62, 0x4c, 0x94, - 0x60, 0x54, 0x60, 0xd4, 0x60, 0x0e, 0x62, 0x4c, 0x04, 0xf1, 0x92, 0x24, 0x98, 0x20, 0xbc, 0x24, - 0x25, 0x2d, 0x2e, 0x0e, 0xb0, 0xca, 0x82, 0x9c, 0x4a, 0x90, 0x4c, 0x19, 0x4c, 0x5d, 0x99, 0x90, - 0x00, 0x17, 0x73, 0x6a, 0x51, 0x11, 0x58, 0x25, 0x67, 0x10, 0x88, 0xa9, 0xa4, 0xcd, 0xc5, 0xeb, - 0x9c, 0x9f, 0x97, 0x9c, 0x58, 0x82, 0x61, 0x30, 0x27, 0x8a, 0xc1, 0x9c, 0x20, 0x83, 0x75, 0xb9, - 0xb8, 0x61, 0x8a, 0x51, 0xcc, 0xe6, 0xc4, 0x6a, 0xb6, 0x51, 0x0c, 0x17, 0xb3, 0x63, 0x4a, 0x8a, - 0x90, 0x2a, 0x17, 0x73, 0x70, 0x69, 0xae, 0x10, 0x9f, 0x5e, 0x41, 0x92, 0x1e, 0xc2, 0x07, 0x52, - 0x3c, 0x70, 0x7e, 0x41, 0x4e, 0xa5, 0x12, 0x83, 0x90, 0x1e, 0x17, 0x1b, 0xc4, 0x70, 0x21, 0x41, - 0x90, 0x0c, 0x8a, 0xab, 0xa4, 0xf8, 0x91, 0x85, 0xc0, 0xea, 0x93, 0xd8, 0xc0, 0x41, 0x63, 0x0c, - 0x08, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x37, 0x81, 0x99, 0x2a, 0x01, 0x00, 0x00, -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto deleted file mode 100644 index cf61532f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto +++ /dev/null @@ -1,36 +0,0 @@ -syntax = "proto3"; - -package pb; - -// The Add service definition. -service Add { - // Sums two integers. - rpc Sum (SumRequest) returns (SumReply) {} - - // Concatenates two strings - rpc Concat (ConcatRequest) returns (ConcatReply) {} -} - -// The sum request contains two parameters. -message SumRequest { - int64 a = 1; - int64 b = 2; -} - -// The sum response contains the result of the calculation. -message SumReply { - int64 v = 1; - string err = 2; -} - -// The Concat request contains two parameters. -message ConcatRequest { - string a = 1; - string b = 2; -} - -// The Concat response contains the result of the concatenation. -message ConcatReply { - string v = 1; - string err = 2; -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go deleted file mode 100644 index c83047b7..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go +++ /dev/null @@ -1,43 +0,0 @@ -package addendpoint - -import ( - "context" - "fmt" - "time" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// InstrumentingMiddleware returns an endpoint middleware that records -// the duration of each invocation to the passed histogram. The middleware adds -// a single field: "success", which is "true" if no error is returned, and -// "false" otherwise. -func InstrumentingMiddleware(duration metrics.Histogram) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - - defer func(begin time.Time) { - duration.With("success", fmt.Sprint(err == nil)).Observe(time.Since(begin).Seconds()) - }(time.Now()) - return next(ctx, request) - - } - } -} - -// LoggingMiddleware returns an endpoint middleware that logs the -// duration of each invocation, and the resulting error, if any. -func LoggingMiddleware(logger log.Logger) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - - defer func(begin time.Time) { - logger.Log("transport_error", err, "took", time.Since(begin)) - }(time.Now()) - return next(ctx, request) - - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go deleted file mode 100644 index 03411a9e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go +++ /dev/null @@ -1,133 +0,0 @@ -package addendpoint - -import ( - "context" - "time" - - "golang.org/x/time/rate" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -// Set collects all of the endpoints that compose an add service. It's meant to -// be used as a helper struct, to collect all of the endpoints into a single -// parameter. -type Set struct { - SumEndpoint endpoint.Endpoint - ConcatEndpoint endpoint.Endpoint -} - -// New returns a Set that wraps the provided server, and wires in all of the -// expected endpoint middlewares via the various parameters. -func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer) Set { - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = MakeSumEndpoint(svc) - sumEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 1))(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(sumEndpoint) - sumEndpoint = opentracing.TraceServer(otTracer, "Sum")(sumEndpoint) - sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) - sumEndpoint = LoggingMiddleware(log.With(logger, "method", "Sum"))(sumEndpoint) - sumEndpoint = InstrumentingMiddleware(duration.With("method", "Sum"))(sumEndpoint) - } - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = MakeConcatEndpoint(svc) - concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100))(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(concatEndpoint) - concatEndpoint = opentracing.TraceServer(otTracer, "Concat")(concatEndpoint) - concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) - concatEndpoint = LoggingMiddleware(log.With(logger, "method", "Concat"))(concatEndpoint) - concatEndpoint = InstrumentingMiddleware(duration.With("method", "Concat"))(concatEndpoint) - } - return Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// Sum implements the service interface, so Set may be used as a service. -// This is primarily useful in the context of a client library. -func (s Set) Sum(ctx context.Context, a, b int) (int, error) { - resp, err := s.SumEndpoint(ctx, SumRequest{A: a, B: b}) - if err != nil { - return 0, err - } - response := resp.(SumResponse) - return response.V, response.Err -} - -// Concat implements the service interface, so Set may be used as a -// service. This is primarily useful in the context of a client library. -func (s Set) Concat(ctx context.Context, a, b string) (string, error) { - resp, err := s.ConcatEndpoint(ctx, ConcatRequest{A: a, B: b}) - if err != nil { - return "", err - } - response := resp.(ConcatResponse) - return response.V, response.Err -} - -// MakeSumEndpoint constructs a Sum endpoint wrapping the service. -func MakeSumEndpoint(s addservice.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(SumRequest) - v, err := s.Sum(ctx, req.A, req.B) - return SumResponse{V: v, Err: err}, nil - } -} - -// MakeConcatEndpoint constructs a Concat endpoint wrapping the service. -func MakeConcatEndpoint(s addservice.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(ConcatRequest) - v, err := s.Concat(ctx, req.A, req.B) - return ConcatResponse{V: v, Err: err}, nil - } -} - -// compile time assertions for our response types implementing endpoint.Failer. -var ( - _ endpoint.Failer = SumResponse{} - _ endpoint.Failer = ConcatResponse{} -) - -// SumRequest collects the request parameters for the Sum method. -type SumRequest struct { - A, B int -} - -// SumResponse collects the response values for the Sum method. -type SumResponse struct { - V int `json:"v"` - Err error `json:"-"` // should be intercepted by Failed/errorEncoder -} - -// Failed implements endpoint.Failer. -func (r SumResponse) Failed() error { return r.Err } - -// ConcatRequest collects the request parameters for the Concat method. -type ConcatRequest struct { - A, B string -} - -// ConcatResponse collects the response values for the Concat method. -type ConcatResponse struct { - V string `json:"v"` - Err error `json:"-"` -} - -// Failed implements endpoint.Failer. -func (r ConcatResponse) Failed() error { return r.Err } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go deleted file mode 100644 index 5a1d6ee5..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go +++ /dev/null @@ -1,69 +0,0 @@ -package addservice - -import ( - "context" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// Middleware describes a service (as opposed to endpoint) middleware. -type Middleware func(Service) Service - -// LoggingMiddleware takes a logger as a dependency -// and returns a ServiceMiddleware. -func LoggingMiddleware(logger log.Logger) Middleware { - return func(next Service) Service { - return loggingMiddleware{logger, next} - } -} - -type loggingMiddleware struct { - logger log.Logger - next Service -} - -func (mw loggingMiddleware) Sum(ctx context.Context, a, b int) (v int, err error) { - defer func() { - mw.logger.Log("method", "Sum", "a", a, "b", b, "v", v, "err", err) - }() - return mw.next.Sum(ctx, a, b) -} - -func (mw loggingMiddleware) Concat(ctx context.Context, a, b string) (v string, err error) { - defer func() { - mw.logger.Log("method", "Concat", "a", a, "b", b, "v", v, "err", err) - }() - return mw.next.Concat(ctx, a, b) -} - -// InstrumentingMiddleware returns a service middleware that instruments -// the number of integers summed and characters concatenated over the lifetime of -// the service. -func InstrumentingMiddleware(ints, chars metrics.Counter) Middleware { - return func(next Service) Service { - return instrumentingMiddleware{ - ints: ints, - chars: chars, - next: next, - } - } -} - -type instrumentingMiddleware struct { - ints metrics.Counter - chars metrics.Counter - next Service -} - -func (mw instrumentingMiddleware) Sum(ctx context.Context, a, b int) (int, error) { - v, err := mw.next.Sum(ctx, a, b) - mw.ints.Add(float64(v)) - return v, err -} - -func (mw instrumentingMiddleware) Concat(ctx context.Context, a, b string) (string, error) { - v, err := mw.next.Concat(ctx, a, b) - mw.chars.Add(float64(len(v))) - return v, err -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go deleted file mode 100644 index d884373b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go +++ /dev/null @@ -1,71 +0,0 @@ -package addservice - -import ( - "context" - "errors" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// Service describes a service that adds things together. -type Service interface { - Sum(ctx context.Context, a, b int) (int, error) - Concat(ctx context.Context, a, b string) (string, error) -} - -// New returns a basic Service with all of the expected middlewares wired in. -func New(logger log.Logger, ints, chars metrics.Counter) Service { - var svc Service - { - svc = NewBasicService() - svc = LoggingMiddleware(logger)(svc) - svc = InstrumentingMiddleware(ints, chars)(svc) - } - return svc -} - -var ( - // ErrTwoZeroes is an arbitrary business rule for the Add method. - ErrTwoZeroes = errors.New("can't sum two zeroes") - - // ErrIntOverflow protects the Add method. We've decided that this error - // indicates a misbehaving service and should count against e.g. circuit - // breakers. So, we return it directly in endpoints, to illustrate the - // difference. In a real service, this probably wouldn't be the case. - ErrIntOverflow = errors.New("integer overflow") - - // ErrMaxSizeExceeded protects the Concat method. - ErrMaxSizeExceeded = errors.New("result exceeds maximum size") -) - -// NewBasicService returns a naïve, stateless implementation of Service. -func NewBasicService() Service { - return basicService{} -} - -type basicService struct{} - -const ( - intMax = 1<<31 - 1 - intMin = -(intMax + 1) - maxLen = 10 -) - -func (s basicService) Sum(_ context.Context, a, b int) (int, error) { - if a == 0 && b == 0 { - return 0, ErrTwoZeroes - } - if (b > 0 && a > (intMax-b)) || (b < 0 && a < (intMin-b)) { - return 0, ErrIntOverflow - } - return a + b, nil -} - -// Concat implements Service. -func (s basicService) Concat(_ context.Context, a, b string) (string, error) { - if len(a)+len(b) > maxLen { - return "", ErrMaxSizeExceeded - } - return a + b, nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go deleted file mode 100644 index ca14cce7..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go +++ /dev/null @@ -1,239 +0,0 @@ -package addtransport - -import ( - "context" - "errors" - "time" - - "google.golang.org/grpc" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - oldcontext "golang.org/x/net/context" - "golang.org/x/time/rate" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - grpctransport "github.com/go-kit/kit/transport/grpc" - - "github.com/go-kit/kit/examples/addsvc/pb" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -type grpcServer struct { - sum grpctransport.Handler - concat grpctransport.Handler -} - -// NewGRPCServer makes a set of endpoints available as a gRPC AddServer. -func NewGRPCServer(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) pb.AddServer { - // Zipkin GRPC Server Trace can either be instantiated per gRPC method with a - // provided operation name or a global tracing service can be instantiated - // without an operation name and fed to each Go kit gRPC server as a - // ServerOption. - // In the latter case, the operation name will be the endpoint's grpc method - // path if used in combination with the Go kit gRPC Interceptor. - // - // In this example, we demonstrate a global Zipkin tracing service with - // Go kit gRPC Interceptor. - zipkinServer := zipkin.GRPCServerTrace(zipkinTracer) - - options := []grpctransport.ServerOption{ - grpctransport.ServerErrorLogger(logger), - zipkinServer, - } - - return &grpcServer{ - sum: grpctransport.NewServer( - endpoints.SumEndpoint, - decodeGRPCSumRequest, - encodeGRPCSumResponse, - append(options, grpctransport.ServerBefore(opentracing.GRPCToContext(otTracer, "Sum", logger)))..., - ), - concat: grpctransport.NewServer( - endpoints.ConcatEndpoint, - decodeGRPCConcatRequest, - encodeGRPCConcatResponse, - append(options, grpctransport.ServerBefore(opentracing.GRPCToContext(otTracer, "Concat", logger)))..., - ), - } -} - -func (s *grpcServer) Sum(ctx oldcontext.Context, req *pb.SumRequest) (*pb.SumReply, error) { - _, rep, err := s.sum.ServeGRPC(ctx, req) - if err != nil { - return nil, err - } - return rep.(*pb.SumReply), nil -} - -func (s *grpcServer) Concat(ctx oldcontext.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) { - _, rep, err := s.concat.ServeGRPC(ctx, req) - if err != nil { - return nil, err - } - return rep.(*pb.ConcatReply), nil -} - -// NewGRPCClient returns an AddService backed by a gRPC server at the other end -// of the conn. The caller is responsible for constructing the conn, and -// eventually closing the underlying transport. We bake-in certain middlewares, -// implementing the client library pattern. -func NewGRPCClient(conn *grpc.ClientConn, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) addservice.Service { - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Zipkin GRPC Client Trace can either be instantiated per gRPC method with a - // provided operation name or a global tracing client can be instantiated - // without an operation name and fed to each Go kit client as ClientOption. - // In the latter case, the operation name will be the endpoint's grpc method - // path. - // - // In this example, we demonstrace a global tracing client. - zipkinClient := zipkin.GRPCClientTrace(zipkinTracer) - - // global client middlewares - options := []grpctransport.ClientOption{ - zipkinClient, - } - - // Each individual endpoint is an grpc/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // made your own client library, you'd do this work there, so your server - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = grpctransport.NewClient( - conn, - "pb.Add", - "Sum", - encodeGRPCSumRequest, - decodeGRPCSumResponse, - pb.SumReply{}, - append(options, grpctransport.ClientBefore(opentracing.ContextToGRPC(otTracer, logger)))..., - ).Endpoint() - sumEndpoint = opentracing.TraceClient(otTracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = grpctransport.NewClient( - conn, - "pb.Add", - "Concat", - encodeGRPCConcatRequest, - decodeGRPCConcatResponse, - pb.ConcatReply{}, - append(options, grpctransport.ClientBefore(opentracing.ContextToGRPC(otTracer, logger)))..., - ).Endpoint() - concatEndpoint = opentracing.TraceClient(otTracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// decodeGRPCSumRequest is a transport/grpc.DecodeRequestFunc that converts a -// gRPC sum request to a user-domain sum request. Primarily useful in a server. -func decodeGRPCSumRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { - req := grpcReq.(*pb.SumRequest) - return addendpoint.SumRequest{A: int(req.A), B: int(req.B)}, nil -} - -// decodeGRPCConcatRequest is a transport/grpc.DecodeRequestFunc that converts a -// gRPC concat request to a user-domain concat request. Primarily useful in a -// server. -func decodeGRPCConcatRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { - req := grpcReq.(*pb.ConcatRequest) - return addendpoint.ConcatRequest{A: req.A, B: req.B}, nil -} - -// decodeGRPCSumResponse is a transport/grpc.DecodeResponseFunc that converts a -// gRPC sum reply to a user-domain sum response. Primarily useful in a client. -func decodeGRPCSumResponse(_ context.Context, grpcReply interface{}) (interface{}, error) { - reply := grpcReply.(*pb.SumReply) - return addendpoint.SumResponse{V: int(reply.V), Err: str2err(reply.Err)}, nil -} - -// decodeGRPCConcatResponse is a transport/grpc.DecodeResponseFunc that converts -// a gRPC concat reply to a user-domain concat response. Primarily useful in a -// client. -func decodeGRPCConcatResponse(_ context.Context, grpcReply interface{}) (interface{}, error) { - reply := grpcReply.(*pb.ConcatReply) - return addendpoint.ConcatResponse{V: reply.V, Err: str2err(reply.Err)}, nil -} - -// encodeGRPCSumResponse is a transport/grpc.EncodeResponseFunc that converts a -// user-domain sum response to a gRPC sum reply. Primarily useful in a server. -func encodeGRPCSumResponse(_ context.Context, response interface{}) (interface{}, error) { - resp := response.(addendpoint.SumResponse) - return &pb.SumReply{V: int64(resp.V), Err: err2str(resp.Err)}, nil -} - -// encodeGRPCConcatResponse is a transport/grpc.EncodeResponseFunc that converts -// a user-domain concat response to a gRPC concat reply. Primarily useful in a -// server. -func encodeGRPCConcatResponse(_ context.Context, response interface{}) (interface{}, error) { - resp := response.(addendpoint.ConcatResponse) - return &pb.ConcatReply{V: resp.V, Err: err2str(resp.Err)}, nil -} - -// encodeGRPCSumRequest is a transport/grpc.EncodeRequestFunc that converts a -// user-domain sum request to a gRPC sum request. Primarily useful in a client. -func encodeGRPCSumRequest(_ context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.SumRequest) - return &pb.SumRequest{A: int64(req.A), B: int64(req.B)}, nil -} - -// encodeGRPCConcatRequest is a transport/grpc.EncodeRequestFunc that converts a -// user-domain concat request to a gRPC concat request. Primarily useful in a -// client. -func encodeGRPCConcatRequest(_ context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.ConcatRequest) - return &pb.ConcatRequest{A: req.A, B: req.B}, nil -} - -// These annoying helper functions are required to translate Go error types to -// and from strings, which is the type we use in our IDLs to represent errors. -// There is special casing to treat empty strings as nil errors. - -func str2err(s string) error { - if s == "" { - return nil - } - return errors.New(s) -} - -func err2str(err error) string { - if err == nil { - return "" - } - return err.Error() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go deleted file mode 100644 index c1e2b296..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go +++ /dev/null @@ -1,244 +0,0 @@ -package addtransport - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -// NewHTTPHandler returns an HTTP handler that makes a set of endpoints -// available on predefined paths. -func NewHTTPHandler(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) http.Handler { - // Zipkin HTTP Server Trace can either be instantiated per endpoint with a - // provided operation name or a global tracing service can be instantiated - // without an operation name and fed to each Go kit endpoint as ServerOption. - // In the latter case, the operation name will be the endpoint's http method. - // We demonstrate a global tracing service here. - zipkinServer := zipkin.HTTPServerTrace(zipkinTracer) - - options := []httptransport.ServerOption{ - httptransport.ServerErrorEncoder(errorEncoder), - httptransport.ServerErrorLogger(logger), - zipkinServer, - } - - m := http.NewServeMux() - m.Handle("/sum", httptransport.NewServer( - endpoints.SumEndpoint, - decodeHTTPSumRequest, - encodeHTTPGenericResponse, - append(options, httptransport.ServerBefore(opentracing.HTTPToContext(otTracer, "Sum", logger)))..., - )) - m.Handle("/concat", httptransport.NewServer( - endpoints.ConcatEndpoint, - decodeHTTPConcatRequest, - encodeHTTPGenericResponse, - append(options, httptransport.ServerBefore(opentracing.HTTPToContext(otTracer, "Concat", logger)))..., - )) - return m -} - -// NewHTTPClient returns an AddService backed by an HTTP server living at the -// remote instance. We expect instance to come from a service discovery system, -// so likely of the form "host:port". We bake-in certain middlewares, -// implementing the client library pattern. -func NewHTTPClient(instance string, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) (addservice.Service, error) { - // Quickly sanitize the instance string. - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - return nil, err - } - - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Zipkin HTTP Client Trace can either be instantiated per endpoint with a - // provided operation name or a global tracing client can be instantiated - // without an operation name and fed to each Go kit endpoint as ClientOption. - // In the latter case, the operation name will be the endpoint's http method. - zipkinClient := zipkin.HTTPClientTrace(zipkinTracer) - - // global client middlewares - options := []httptransport.ClientOption{ - zipkinClient, - } - - // Each individual endpoint is an http/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // made your own client library, you'd do this work there, so your server - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = httptransport.NewClient( - "POST", - copyURL(u, "/sum"), - encodeHTTPGenericRequest, - decodeHTTPSumResponse, - append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., - ).Endpoint() - sumEndpoint = opentracing.TraceClient(otTracer, "Sum")(sumEndpoint) - sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = httptransport.NewClient( - "POST", - copyURL(u, "/concat"), - encodeHTTPGenericRequest, - decodeHTTPConcatResponse, - append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., - ).Endpoint() - concatEndpoint = opentracing.TraceClient(otTracer, "Concat")(concatEndpoint) - concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - }, nil -} - -func copyURL(base *url.URL, path string) *url.URL { - next := *base - next.Path = path - return &next -} - -func errorEncoder(_ context.Context, err error, w http.ResponseWriter) { - w.WriteHeader(err2code(err)) - json.NewEncoder(w).Encode(errorWrapper{Error: err.Error()}) -} - -func err2code(err error) int { - switch err { - case addservice.ErrTwoZeroes, addservice.ErrMaxSizeExceeded, addservice.ErrIntOverflow: - return http.StatusBadRequest - } - return http.StatusInternalServerError -} - -func errorDecoder(r *http.Response) error { - var w errorWrapper - if err := json.NewDecoder(r.Body).Decode(&w); err != nil { - return err - } - return errors.New(w.Error) -} - -type errorWrapper struct { - Error string `json:"error"` -} - -// decodeHTTPSumRequest is a transport/http.DecodeRequestFunc that decodes a -// JSON-encoded sum request from the HTTP request body. Primarily useful in a -// server. -func decodeHTTPSumRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req addendpoint.SumRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -// decodeHTTPConcatRequest is a transport/http.DecodeRequestFunc that decodes a -// JSON-encoded concat request from the HTTP request body. Primarily useful in a -// server. -func decodeHTTPConcatRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req addendpoint.ConcatRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -// decodeHTTPSumResponse is a transport/http.DecodeResponseFunc that decodes a -// JSON-encoded sum response from the HTTP response body. If the response has a -// non-200 status code, we will interpret that as an error and attempt to decode -// the specific error message from the response body. Primarily useful in a -// client. -func decodeHTTPSumResponse(_ context.Context, r *http.Response) (interface{}, error) { - if r.StatusCode != http.StatusOK { - return nil, errors.New(r.Status) - } - var resp addendpoint.SumResponse - err := json.NewDecoder(r.Body).Decode(&resp) - return resp, err -} - -// decodeHTTPConcatResponse is a transport/http.DecodeResponseFunc that decodes -// a JSON-encoded concat response from the HTTP response body. If the response -// has a non-200 status code, we will interpret that as an error and attempt to -// decode the specific error message from the response body. Primarily useful in -// a client. -func decodeHTTPConcatResponse(_ context.Context, r *http.Response) (interface{}, error) { - if r.StatusCode != http.StatusOK { - return nil, errors.New(r.Status) - } - var resp addendpoint.ConcatResponse - err := json.NewDecoder(r.Body).Decode(&resp) - return resp, err -} - -// encodeHTTPGenericRequest is a transport/http.EncodeRequestFunc that -// JSON-encodes any request to the request body. Primarily useful in a client. -func encodeHTTPGenericRequest(_ context.Context, r *http.Request, request interface{}) error { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - r.Body = ioutil.NopCloser(&buf) - return nil -} - -// encodeHTTPGenericResponse is a transport/http.EncodeResponseFunc that encodes -// the response as JSON to the response writer. Primarily useful in a server. -func encodeHTTPGenericResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if f, ok := response.(endpoint.Failer); ok && f.Failed() != nil { - errorEncoder(ctx, f.Failed(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go deleted file mode 100644 index a8975ef4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go +++ /dev/null @@ -1,213 +0,0 @@ -package addtransport - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/transport/http/jsonrpc" - stdopentracing "github.com/opentracing/opentracing-go" - "github.com/sony/gobreaker" -) - -// NewJSONRPCHandler returns a JSON RPC Server/Handler that can be passed to http.Handle() -func NewJSONRPCHandler(endpoints addendpoint.Set, logger log.Logger) *jsonrpc.Server { - handler := jsonrpc.NewServer( - makeEndpointCodecMap(endpoints), - jsonrpc.ServerErrorLogger(logger), - ) - return handler -} - -// NewJSONRPCClient returns an addservice backed by a JSON RPC over HTTP server -// living at the remote instance. We expect instance to come from a service -// discovery system, so likely of the form "host:port". We bake-in certain -// middlewares, implementing the client library pattern. -func NewJSONRPCClient(instance string, tracer stdopentracing.Tracer, logger log.Logger) (addservice.Service, error) { - // Quickly sanitize the instance string. - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - return nil, err - } - - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = jsonrpc.NewClient( - u, - "sum", - jsonrpc.ClientRequestEncoder(encodeSumRequest), - jsonrpc.ClientResponseDecoder(decodeSumResponse), - ).Endpoint() - sumEndpoint = opentracing.TraceClient(tracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = jsonrpc.NewClient( - u, - "concat", - jsonrpc.ClientRequestEncoder(encodeConcatRequest), - jsonrpc.ClientResponseDecoder(decodeConcatResponse), - ).Endpoint() - concatEndpoint = opentracing.TraceClient(tracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 30 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - }, nil - -} - -// makeEndpointCodecMap returns a codec map configured for the addsvc. -func makeEndpointCodecMap(endpoints addendpoint.Set) jsonrpc.EndpointCodecMap { - return jsonrpc.EndpointCodecMap{ - "sum": jsonrpc.EndpointCodec{ - Endpoint: endpoints.SumEndpoint, - Decode: decodeSumRequest, - Encode: encodeSumResponse, - }, - "concat": jsonrpc.EndpointCodec{ - Endpoint: endpoints.ConcatEndpoint, - Decode: decodeConcatRequest, - Encode: encodeConcatResponse, - }, - } -} - -func decodeSumRequest(_ context.Context, msg json.RawMessage) (interface{}, error) { - var req addendpoint.SumRequest - err := json.Unmarshal(msg, &req) - if err != nil { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("couldn't unmarshal body to sum request: %s", err), - } - } - return req, nil -} - -func encodeSumResponse(_ context.Context, obj interface{}) (json.RawMessage, error) { - res, ok := obj.(addendpoint.SumResponse) - if !ok { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("Asserting result to *SumResponse failed. Got %T, %+v", obj, obj), - } - } - b, err := json.Marshal(res) - if err != nil { - return nil, fmt.Errorf("couldn't marshal response: %s", err) - } - return b, nil -} - -func decodeSumResponse(_ context.Context, res jsonrpc.Response) (interface{}, error) { - if res.Error != nil { - return nil, *res.Error - } - var sumres addendpoint.SumResponse - err := json.Unmarshal(res.Result, &sumres) - if err != nil { - return nil, fmt.Errorf("couldn't unmarshal body to SumResponse: %s", err) - } - return sumres, nil -} - -func encodeSumRequest(_ context.Context, obj interface{}) (json.RawMessage, error) { - req, ok := obj.(addendpoint.SumRequest) - if !ok { - return nil, fmt.Errorf("couldn't assert request as SumRequest, got %T", obj) - } - b, err := json.Marshal(req) - if err != nil { - return nil, fmt.Errorf("couldn't marshal request: %s", err) - } - return b, nil -} - -func decodeConcatRequest(_ context.Context, msg json.RawMessage) (interface{}, error) { - var req addendpoint.ConcatRequest - err := json.Unmarshal(msg, &req) - if err != nil { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("couldn't unmarshal body to concat request: %s", err), - } - } - return req, nil -} - -func encodeConcatResponse(_ context.Context, obj interface{}) (json.RawMessage, error) { - res, ok := obj.(addendpoint.ConcatResponse) - if !ok { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("Asserting result to *ConcatResponse failed. Got %T, %+v", obj, obj), - } - } - b, err := json.Marshal(res) - if err != nil { - return nil, fmt.Errorf("couldn't marshal response: %s", err) - } - return b, nil -} - -func decodeConcatResponse(_ context.Context, res jsonrpc.Response) (interface{}, error) { - if res.Error != nil { - return nil, *res.Error - } - var concatres addendpoint.ConcatResponse - err := json.Unmarshal(res.Result, &concatres) - if err != nil { - return nil, fmt.Errorf("couldn't unmarshal body to ConcatResponse: %s", err) - } - return concatres, nil -} - -func encodeConcatRequest(_ context.Context, obj interface{}) (json.RawMessage, error) { - req, ok := obj.(addendpoint.ConcatRequest) - if !ok { - return nil, fmt.Errorf("couldn't assert request as ConcatRequest, got %T", obj) - } - b, err := json.Marshal(req) - if err != nil { - return nil, fmt.Errorf("couldn't marshal request: %s", err) - } - return b, nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go deleted file mode 100644 index 485840fe..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go +++ /dev/null @@ -1,120 +0,0 @@ -package addtransport - -import ( - "context" - "time" - - "golang.org/x/time/rate" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/ratelimit" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -type thriftServer struct { - ctx context.Context - endpoints addendpoint.Set -} - -// NewThriftServer makes a set of endpoints available as a Thrift service. -func NewThriftServer(endpoints addendpoint.Set) addthrift.AddService { - return &thriftServer{ - endpoints: endpoints, - } -} - -func (s *thriftServer) Sum(ctx context.Context, a int64, b int64) (*addthrift.SumReply, error) { - request := addendpoint.SumRequest{A: int(a), B: int(b)} - response, err := s.endpoints.SumEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(addendpoint.SumResponse) - return &addthrift.SumReply{Value: int64(resp.V), Err: err2str(resp.Err)}, nil -} - -func (s *thriftServer) Concat(ctx context.Context, a string, b string) (*addthrift.ConcatReply, error) { - request := addendpoint.ConcatRequest{A: a, B: b} - response, err := s.endpoints.ConcatEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(addendpoint.ConcatResponse) - return &addthrift.ConcatReply{Value: resp.V, Err: err2str(resp.Err)}, nil -} - -// NewThriftClient returns an AddService backed by a Thrift server described by -// the provided client. The caller is responsible for constructing the client, -// and eventually closing the underlying transport. We bake-in certain middlewares, -// implementing the client library pattern. -func NewThriftClient(client *addthrift.AddServiceClient) addservice.Service { - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Each individual endpoint is an http/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = MakeThriftSumEndpoint(client) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = MakeThriftConcatEndpoint(client) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// MakeThriftSumEndpoint returns an endpoint that invokes the passed Thrift client. -// Useful only in clients, and only until a proper transport/thrift.Client exists. -func MakeThriftSumEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.SumRequest) - reply, err := client.Sum(ctx, int64(req.A), int64(req.B)) - if err == addservice.ErrIntOverflow { - return nil, err // special case; see comment on ErrIntOverflow - } - return addendpoint.SumResponse{V: int(reply.Value), Err: err}, nil - } -} - -// MakeThriftConcatEndpoint returns an endpoint that invokes the passed Thrift -// client. Useful only in clients, and only until a proper -// transport/thrift.Client exists. -func MakeThriftConcatEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.ConcatRequest) - reply, err := client.Concat(ctx, req.A, req.B) - return addendpoint.ConcatResponse{V: reply.Value, Err: err}, nil - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift deleted file mode 100644 index e67ce1b2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift +++ /dev/null @@ -1,14 +0,0 @@ -struct SumReply { - 1: i64 value - 2: string err -} - -struct ConcatReply { - 1: string value - 2: string err -} - -service AddService { - SumReply Sum(1: i64 a, 2: i64 b) - ConcatReply Concat(1: string a, 2: string b) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go deleted file mode 100644 index 88387e14..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go +++ /dev/null @@ -1,7 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -var GoUnusedProtection__ int; - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go deleted file mode 100755 index 9e6800e7..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go +++ /dev/null @@ -1,186 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package main - -import ( - "context" - "flag" - "fmt" - "math" - "net" - "net/url" - "os" - "strconv" - "strings" - "github.com/apache/thrift/lib/go/thrift" - "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - - -func Usage() { - fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") - flag.PrintDefaults() - fmt.Fprintln(os.Stderr, "\nFunctions:") - fmt.Fprintln(os.Stderr, " SumReply Sum(i64 a, i64 b)") - fmt.Fprintln(os.Stderr, " ConcatReply Concat(string a, string b)") - fmt.Fprintln(os.Stderr) - os.Exit(0) -} - -type httpHeaders map[string]string - -func (h httpHeaders) String() string { - var m map[string]string = h - return fmt.Sprintf("%s", m) -} - -func (h httpHeaders) Set(value string) error { - parts := strings.Split(value, ": ") - if len(parts) != 2 { - return fmt.Errorf("header should be of format 'Key: Value'") - } - h[parts[0]] = parts[1] - return nil -} - -func main() { - flag.Usage = Usage - var host string - var port int - var protocol string - var urlString string - var framed bool - var useHttp bool - headers := make(httpHeaders) - var parsedUrl *url.URL - var trans thrift.TTransport - _ = strconv.Atoi - _ = math.Abs - flag.Usage = Usage - flag.StringVar(&host, "h", "localhost", "Specify host and port") - flag.IntVar(&port, "p", 9090, "Specify port") - flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") - flag.StringVar(&urlString, "u", "", "Specify the url") - flag.BoolVar(&framed, "framed", false, "Use framed transport") - flag.BoolVar(&useHttp, "http", false, "Use http") - flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")") - flag.Parse() - - if len(urlString) > 0 { - var err error - parsedUrl, err = url.Parse(urlString) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - host = parsedUrl.Host - useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https" - } else if useHttp { - _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - } - - cmd := flag.Arg(0) - var err error - if useHttp { - trans, err = thrift.NewTHttpClient(parsedUrl.String()) - if len(headers) > 0 { - httptrans := trans.(*thrift.THttpClient) - for key, value := range headers { - httptrans.SetHeader(key, value) - } - } - } else { - portStr := fmt.Sprint(port) - if strings.Contains(host, ":") { - host, portStr, err = net.SplitHostPort(host) - if err != nil { - fmt.Fprintln(os.Stderr, "error with host:", err) - os.Exit(1) - } - } - trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) - if err != nil { - fmt.Fprintln(os.Stderr, "error resolving address:", err) - os.Exit(1) - } - if framed { - trans = thrift.NewTFramedTransport(trans) - } - } - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating transport", err) - os.Exit(1) - } - defer trans.Close() - var protocolFactory thrift.TProtocolFactory - switch protocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - break - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - break - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - break - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - break - default: - fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) - Usage() - os.Exit(1) - } - iprot := protocolFactory.GetProtocol(trans) - oprot := protocolFactory.GetProtocol(trans) - client := addsvc.NewAddServiceClient(thrift.NewTStandardClient(iprot, oprot)) - if err := trans.Open(); err != nil { - fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) - os.Exit(1) - } - - switch cmd { - case "Sum": - if flag.NArg() - 1 != 2 { - fmt.Fprintln(os.Stderr, "Sum requires 2 args") - flag.Usage() - } - argvalue0, err6 := (strconv.ParseInt(flag.Arg(1), 10, 64)) - if err6 != nil { - Usage() - return - } - value0 := argvalue0 - argvalue1, err7 := (strconv.ParseInt(flag.Arg(2), 10, 64)) - if err7 != nil { - Usage() - return - } - value1 := argvalue1 - fmt.Print(client.Sum(context.Background(), value0, value1)) - fmt.Print("\n") - break - case "Concat": - if flag.NArg() - 1 != 2 { - fmt.Fprintln(os.Stderr, "Concat requires 2 args") - flag.Usage() - } - argvalue0 := flag.Arg(1) - value0 := argvalue0 - argvalue1 := flag.Arg(2) - value1 := argvalue1 - fmt.Print(client.Concat(context.Background(), value0, value1)) - fmt.Print("\n") - break - case "": - Usage() - break - default: - fmt.Fprintln(os.Stderr, "Invalid function ", cmd) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go deleted file mode 100644 index eea54fe1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -import ( - "bytes" - "context" - "reflect" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = context.Background -var _ = reflect.DeepEqual -var _ = bytes.Equal - - -func init() { -} - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go deleted file mode 100644 index 14a87e6d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go +++ /dev/null @@ -1,935 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -import ( - "bytes" - "context" - "reflect" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = context.Background -var _ = reflect.DeepEqual -var _ = bytes.Equal - -// Attributes: -// - Value -// - Err -type SumReply struct { - Value int64 `thrift:"value,1" db:"value" json:"value"` - Err string `thrift:"err,2" db:"err" json:"err"` -} - -func NewSumReply() *SumReply { - return &SumReply{} -} - - -func (p *SumReply) GetValue() int64 { - return p.Value -} - -func (p *SumReply) GetErr() string { - return p.Err -} -func (p *SumReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.I64 { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *SumReply) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.Value = v -} - return nil -} - -func (p *SumReply) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.Err = v -} - return nil -} - -func (p *SumReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("SumReply"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *SumReply) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) } - if err := oprot.WriteI64(int64(p.Value)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) } - return err -} - -func (p *SumReply) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("err", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:err: ", p), err) } - if err := oprot.WriteString(string(p.Err)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.err (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:err: ", p), err) } - return err -} - -func (p *SumReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("SumReply(%+v)", *p) -} - -// Attributes: -// - Value -// - Err -type ConcatReply struct { - Value string `thrift:"value,1" db:"value" json:"value"` - Err string `thrift:"err,2" db:"err" json:"err"` -} - -func NewConcatReply() *ConcatReply { - return &ConcatReply{} -} - - -func (p *ConcatReply) GetValue() string { - return p.Value -} - -func (p *ConcatReply) GetErr() string { - return p.Err -} -func (p *ConcatReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *ConcatReply) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.Value = v -} - return nil -} - -func (p *ConcatReply) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.Err = v -} - return nil -} - -func (p *ConcatReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("ConcatReply"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *ConcatReply) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("value", thrift.STRING, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) } - if err := oprot.WriteString(string(p.Value)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) } - return err -} - -func (p *ConcatReply) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("err", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:err: ", p), err) } - if err := oprot.WriteString(string(p.Err)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.err (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:err: ", p), err) } - return err -} - -func (p *ConcatReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("ConcatReply(%+v)", *p) -} - -type AddService interface { - // Parameters: - // - A - // - B - Sum(ctx context.Context, a int64, b int64) (r *SumReply, err error) - // Parameters: - // - A - // - B - Concat(ctx context.Context, a string, b string) (r *ConcatReply, err error) -} - -type AddServiceClient struct { - c thrift.TClient -} - -func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { - return &AddServiceClient{ - c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), - } -} - -func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { - return &AddServiceClient{ - c: thrift.NewTStandardClient(iprot, oprot), - } -} - -func NewAddServiceClient(c thrift.TClient) *AddServiceClient { - return &AddServiceClient{ - c: c, - } -} - -func (p *AddServiceClient) Client_() thrift.TClient { - return p.c -} -// Parameters: -// - A -// - B -func (p *AddServiceClient) Sum(ctx context.Context, a int64, b int64) (r *SumReply, err error) { - var _args0 AddServiceSumArgs - _args0.A = a - _args0.B = b - var _result1 AddServiceSumResult - if err = p.Client_().Call(ctx, "Sum", &_args0, &_result1); err != nil { - return - } - return _result1.GetSuccess(), nil -} - -// Parameters: -// - A -// - B -func (p *AddServiceClient) Concat(ctx context.Context, a string, b string) (r *ConcatReply, err error) { - var _args2 AddServiceConcatArgs - _args2.A = a - _args2.B = b - var _result3 AddServiceConcatResult - if err = p.Client_().Call(ctx, "Concat", &_args2, &_result3); err != nil { - return - } - return _result3.GetSuccess(), nil -} - -type AddServiceProcessor struct { - processorMap map[string]thrift.TProcessorFunction - handler AddService -} - -func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { - p.processorMap[key] = processor -} - -func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { - processor, ok = p.processorMap[key] - return processor, ok -} - -func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { - return p.processorMap -} - -func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { - - self4 := &AddServiceProcessor{handler:handler, processorMap:make(map[string]thrift.TProcessorFunction)} - self4.processorMap["Sum"] = &addServiceProcessorSum{handler:handler} - self4.processorMap["Concat"] = &addServiceProcessorConcat{handler:handler} -return self4 -} - -func (p *AddServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - name, _, seqId, err := iprot.ReadMessageBegin() - if err != nil { return false, err } - if processor, ok := p.GetProcessorFunction(name); ok { - return processor.Process(ctx, seqId, iprot, oprot) - } - iprot.Skip(thrift.STRUCT) - iprot.ReadMessageEnd() - x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function " + name) - oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) - x5.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, x5 - -} - -type addServiceProcessorSum struct { - handler AddService -} - -func (p *addServiceProcessorSum) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := AddServiceSumArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - result := AddServiceSumResult{} -var retval *SumReply - var err2 error - if retval, err2 = p.handler.Sum(ctx, args.A, args.B); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Sum: " + err2.Error()) - oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval -} - if err2 = oprot.WriteMessageBegin("Sum", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type addServiceProcessorConcat struct { - handler AddService -} - -func (p *addServiceProcessorConcat) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := AddServiceConcatArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - result := AddServiceConcatResult{} -var retval *ConcatReply - var err2 error - if retval, err2 = p.handler.Concat(ctx, args.A, args.B); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Concat: " + err2.Error()) - oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval -} - if err2 = oprot.WriteMessageBegin("Concat", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - - -// HELPER FUNCTIONS AND STRUCTURES - -// Attributes: -// - A -// - B -type AddServiceSumArgs struct { - A int64 `thrift:"a,1" db:"a" json:"a"` - B int64 `thrift:"b,2" db:"b" json:"b"` -} - -func NewAddServiceSumArgs() *AddServiceSumArgs { - return &AddServiceSumArgs{} -} - - -func (p *AddServiceSumArgs) GetA() int64 { - return p.A -} - -func (p *AddServiceSumArgs) GetB() int64 { - return p.B -} -func (p *AddServiceSumArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.I64 { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.I64 { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceSumArgs) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.A = v -} - return nil -} - -func (p *AddServiceSumArgs) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.B = v -} - return nil -} - -func (p *AddServiceSumArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Sum_args"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceSumArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) } - if err := oprot.WriteI64(int64(p.A)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) } - return err -} - -func (p *AddServiceSumArgs) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) } - if err := oprot.WriteI64(int64(p.B)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) } - return err -} - -func (p *AddServiceSumArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceSumArgs(%+v)", *p) -} - -// Attributes: -// - Success -type AddServiceSumResult struct { - Success *SumReply `thrift:"success,0" db:"success" json:"success,omitempty"` -} - -func NewAddServiceSumResult() *AddServiceSumResult { - return &AddServiceSumResult{} -} - -var AddServiceSumResult_Success_DEFAULT *SumReply -func (p *AddServiceSumResult) GetSuccess() *SumReply { - if !p.IsSetSuccess() { - return AddServiceSumResult_Success_DEFAULT - } -return p.Success -} -func (p *AddServiceSumResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *AddServiceSumResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err := p.ReadField0(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceSumResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &SumReply{} - if err := p.Success.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) - } - return nil -} - -func (p *AddServiceSumResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Sum_result"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField0(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceSumResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } - if err := p.Success.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } - } - return err -} - -func (p *AddServiceSumResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceSumResult(%+v)", *p) -} - -// Attributes: -// - A -// - B -type AddServiceConcatArgs struct { - A string `thrift:"a,1" db:"a" json:"a"` - B string `thrift:"b,2" db:"b" json:"b"` -} - -func NewAddServiceConcatArgs() *AddServiceConcatArgs { - return &AddServiceConcatArgs{} -} - - -func (p *AddServiceConcatArgs) GetA() string { - return p.A -} - -func (p *AddServiceConcatArgs) GetB() string { - return p.B -} -func (p *AddServiceConcatArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceConcatArgs) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.A = v -} - return nil -} - -func (p *AddServiceConcatArgs) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.B = v -} - return nil -} - -func (p *AddServiceConcatArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Concat_args"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceConcatArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("a", thrift.STRING, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) } - if err := oprot.WriteString(string(p.A)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) } - return err -} - -func (p *AddServiceConcatArgs) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("b", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) } - if err := oprot.WriteString(string(p.B)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) } - return err -} - -func (p *AddServiceConcatArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceConcatArgs(%+v)", *p) -} - -// Attributes: -// - Success -type AddServiceConcatResult struct { - Success *ConcatReply `thrift:"success,0" db:"success" json:"success,omitempty"` -} - -func NewAddServiceConcatResult() *AddServiceConcatResult { - return &AddServiceConcatResult{} -} - -var AddServiceConcatResult_Success_DEFAULT *ConcatReply -func (p *AddServiceConcatResult) GetSuccess() *ConcatReply { - if !p.IsSetSuccess() { - return AddServiceConcatResult_Success_DEFAULT - } -return p.Success -} -func (p *AddServiceConcatResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *AddServiceConcatResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err := p.ReadField0(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceConcatResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &ConcatReply{} - if err := p.Success.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) - } - return nil -} - -func (p *AddServiceConcatResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Concat_result"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField0(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceConcatResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } - if err := p.Success.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } - } - return err -} - -func (p *AddServiceConcatResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceConcatResult(%+v)", *p) -} - - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go deleted file mode 100644 index 5891241d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go +++ /dev/null @@ -1,287 +0,0 @@ -package main - -import ( - "bytes" - "context" - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/url" - "os" - "os/signal" - "strings" - "syscall" - "time" - - consulsd "github.com/go-kit/kit/sd/consul" - "github.com/gorilla/mux" - "github.com/hashicorp/consul/api" - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "google.golang.org/grpc" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/lb" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" -) - -func main() { - var ( - httpAddr = flag.String("http.addr", ":8000", "Address for HTTP (JSON) server") - consulAddr = flag.String("consul.addr", "", "Consul agent address") - retryMax = flag.Int("retry.max", 3, "per-request retries to different instances") - retryTimeout = flag.Duration("retry.timeout", 500*time.Millisecond, "per-request timeout, including retries") - ) - flag.Parse() - - // Logging domain. - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - // Service discovery domain. In this example we use Consul. - var client consulsd.Client - { - consulConfig := api.DefaultConfig() - if len(*consulAddr) > 0 { - consulConfig.Address = *consulAddr - } - consulClient, err := api.NewClient(consulConfig) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - client = consulsd.NewClient(consulClient) - } - - // Transport domain. - tracer := stdopentracing.GlobalTracer() // no-op - zipkinTracer, _ := stdzipkin.NewTracer(nil, stdzipkin.WithNoopTracer(true)) - ctx := context.Background() - r := mux.NewRouter() - - // Now we begin installing the routes. Each route corresponds to a single - // method: sum, concat, uppercase, and count. - - // addsvc routes. - { - // Each method gets constructed with a factory. Factories take an - // instance string, and return a specific endpoint. In the factory we - // dial the instance string we get from Consul, and then leverage an - // addsvc client package to construct a complete service. We can then - // leverage the addsvc.Make{Sum,Concat}Endpoint constructors to convert - // the complete service to specific endpoint. - var ( - tags = []string{} - passingOnly = true - endpoints = addendpoint.Set{} - instancer = consulsd.NewInstancer(client, logger, "addsvc", tags, passingOnly) - ) - { - factory := addsvcFactory(addendpoint.MakeSumEndpoint, tracer, zipkinTracer, logger) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - endpoints.SumEndpoint = retry - } - { - factory := addsvcFactory(addendpoint.MakeConcatEndpoint, tracer, zipkinTracer, logger) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - endpoints.ConcatEndpoint = retry - } - - // Here we leverage the fact that addsvc comes with a constructor for an - // HTTP handler, and just install it under a particular path prefix in - // our router. - - r.PathPrefix("/addsvc").Handler(http.StripPrefix("/addsvc", addtransport.NewHTTPHandler(endpoints, tracer, zipkinTracer, logger))) - } - - // stringsvc routes. - { - // addsvc had lots of nice importable Go packages we could leverage. - // With stringsvc we are not so fortunate, it just has some endpoints - // that we assume will exist. So we have to write that logic here. This - // is by design, so you can see two totally different methods of - // proxying to a remote service. - - var ( - tags = []string{} - passingOnly = true - uppercase endpoint.Endpoint - count endpoint.Endpoint - instancer = consulsd.NewInstancer(client, logger, "stringsvc", tags, passingOnly) - ) - { - factory := stringsvcFactory(ctx, "GET", "/uppercase") - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - uppercase = retry - } - { - factory := stringsvcFactory(ctx, "GET", "/count") - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - count = retry - } - - // We can use the transport/http.Server to act as our handler, all we - // have to do provide it with the encode and decode functions for our - // stringsvc methods. - - r.Handle("/stringsvc/uppercase", httptransport.NewServer(uppercase, decodeUppercaseRequest, encodeJSONResponse)) - r.Handle("/stringsvc/count", httptransport.NewServer(count, decodeCountRequest, encodeJSONResponse)) - } - - // Interrupt handler. - errc := make(chan error) - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - errc <- fmt.Errorf("%s", <-c) - }() - - // HTTP transport. - go func() { - logger.Log("transport", "HTTP", "addr", *httpAddr) - errc <- http.ListenAndServe(*httpAddr, r) - }() - - // Run! - logger.Log("exit", <-errc) -} - -func addsvcFactory(makeEndpoint func(addservice.Service) endpoint.Endpoint, tracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - // We could just as easily use the HTTP or Thrift client package to make - // the connection to addsvc. We've chosen gRPC arbitrarily. Note that - // the transport is an implementation detail: it doesn't leak out of - // this function. Nice! - - conn, err := grpc.Dial(instance, grpc.WithInsecure()) - if err != nil { - return nil, nil, err - } - service := addtransport.NewGRPCClient(conn, tracer, zipkinTracer, logger) - endpoint := makeEndpoint(service) - - // Notice that the addsvc gRPC client converts the connection to a - // complete addsvc, and we just throw away everything except the method - // we're interested in. A smarter factory would mux multiple methods - // over the same connection. But that would require more work to manage - // the returned io.Closer, e.g. reference counting. Since this is for - // the purposes of demonstration, we'll just keep it simple. - - return endpoint, conn, nil - } -} - -func stringsvcFactory(ctx context.Context, method, path string) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - tgt, err := url.Parse(instance) - if err != nil { - return nil, nil, err - } - tgt.Path = path - - // Since stringsvc doesn't have any kind of package we can import, or - // any formal spec, we are forced to just assert where the endpoints - // live, and write our own code to encode and decode requests and - // responses. Ideally, if you write the service, you will want to - // provide stronger guarantees to your clients. - - var ( - enc httptransport.EncodeRequestFunc - dec httptransport.DecodeResponseFunc - ) - switch path { - case "/uppercase": - enc, dec = encodeJSONRequest, decodeUppercaseResponse - case "/count": - enc, dec = encodeJSONRequest, decodeCountResponse - default: - return nil, nil, fmt.Errorf("unknown stringsvc path %q", path) - } - - return httptransport.NewClient(method, tgt, enc, dec).Endpoint(), nil, nil - } -} - -func encodeJSONRequest(_ context.Context, req *http.Request, request interface{}) error { - // Both uppercase and count requests are encoded in the same way: - // simple JSON serialization to the request body. - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - req.Body = ioutil.NopCloser(&buf) - return nil -} - -func encodeJSONResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -// I've just copied these functions from stringsvc3/transport.go, inlining the -// struct definitions. - -func decodeUppercaseResponse(ctx context.Context, resp *http.Response) (interface{}, error) { - var response struct { - V string `json:"v"` - Err string `json:"err,omitempty"` - } - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func decodeCountResponse(ctx context.Context, resp *http.Response) (interface{}, error) { - var response struct { - V int `json:"v"` - } - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func decodeUppercaseRequest(ctx context.Context, req *http.Request) (interface{}, error) { - var request struct { - S string `json:"s"` - } - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(ctx context.Context, req *http.Request) (interface{}, error) { - var request struct { - S string `json:"s"` - } - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md deleted file mode 100644 index 34a06e71..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# profilesvc - -This example demonstrates how to use Go kit to implement a REST-y HTTP service. -It leverages the excellent [gorilla mux package](https://github.com/gorilla/mux) for routing. - -Run the example with the optional port address for the service: - -```bash -$ go run ./cmd/profilesvc/main.go -http.addr :8080 -ts=2018-05-01T16:13:12.849086255Z caller=main.go:47 transport=HTTP addr=:8080 -``` - -Create a Profile: - -```bash -$ curl -d '{"id":"1234","Name":"Go Kit"}' -H "Content-Type: application/json" -X POST http://localhost:8080/profiles/ -{} -``` - -Get the profile you just created - -```bash -$ curl localhost:8080/profiles/1234 -{"profile":{"id":"1234","name":"Go Kit"}} -``` diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go deleted file mode 100644 index 03c1dc7a..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go +++ /dev/null @@ -1,121 +0,0 @@ -// Package client provides a profilesvc client based on a predefined Consul -// service name and relevant tags. Users must only provide the address of a -// Consul server. -package client - -import ( - "io" - "time" - - consulapi "github.com/hashicorp/consul/api" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/examples/profilesvc" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/consul" - "github.com/go-kit/kit/sd/lb" -) - -// New returns a service that's load-balanced over instances of profilesvc found -// in the provided Consul server. The mechanism of looking up profilesvc -// instances in Consul is hard-coded into the client. -func New(consulAddr string, logger log.Logger) (profilesvc.Service, error) { - apiclient, err := consulapi.NewClient(&consulapi.Config{ - Address: consulAddr, - }) - if err != nil { - return nil, err - } - - // As the implementer of profilesvc, we declare and enforce these - // parameters for all of the profilesvc consumers. - var ( - consulService = "profilesvc" - consulTags = []string{"prod"} - passingOnly = true - retryMax = 3 - retryTimeout = 500 * time.Millisecond - ) - - var ( - sdclient = consul.NewClient(apiclient) - instancer = consul.NewInstancer(sdclient, logger, consulService, consulTags, passingOnly) - endpoints profilesvc.Endpoints - ) - { - factory := factoryFor(profilesvc.MakePostProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PostProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePutProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PutProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePatchProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PatchProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeDeleteProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.DeleteProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetAddressesEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetAddressesEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetAddressEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePostAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PostAddressEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeDeleteAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.DeleteAddressEndpoint = retry - } - - return endpoints, nil -} - -func factoryFor(makeEndpoint func(profilesvc.Service) endpoint.Endpoint) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - service, err := profilesvc.MakeClientEndpoints(instance) - if err != nil { - return nil, nil, err - } - return makeEndpoint(service), nil, nil - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go deleted file mode 100644 index fda75295..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "net/http" - "os" - "os/signal" - "syscall" - - "github.com/go-kit/kit/examples/profilesvc" - "github.com/go-kit/kit/log" -) - -func main() { - var ( - httpAddr = flag.String("http.addr", ":8080", "HTTP listen address") - ) - flag.Parse() - - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - var s profilesvc.Service - { - s = profilesvc.NewInmemService() - s = profilesvc.LoggingMiddleware(logger)(s) - } - - var h http.Handler - { - h = profilesvc.MakeHTTPHandler(s, log.With(logger, "component", "HTTP")) - } - - errs := make(chan error) - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - errs <- fmt.Errorf("%s", <-c) - }() - - go func() { - logger.Log("transport", "HTTP", "addr", *httpAddr) - errs <- http.ListenAndServe(*httpAddr, h) - }() - - logger.Log("exit", <-errs) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go deleted file mode 100644 index 794d0f17..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go +++ /dev/null @@ -1,387 +0,0 @@ -package profilesvc - -import ( - "context" - "net/url" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// Endpoints collects all of the endpoints that compose a profile service. It's -// meant to be used as a helper struct, to collect all of the endpoints into a -// single parameter. -// -// In a server, it's useful for functions that need to operate on a per-endpoint -// basis. For example, you might pass an Endpoints to a function that produces -// an http.Handler, with each method (endpoint) wired up to a specific path. (It -// is probably a mistake in design to invoke the Service methods on the -// Endpoints struct in a server.) -// -// In a client, it's useful to collect individually constructed endpoints into a -// single type that implements the Service interface. For example, you might -// construct individual endpoints using transport/http.NewClient, combine them -// into an Endpoints, and return it to the caller as a Service. -type Endpoints struct { - PostProfileEndpoint endpoint.Endpoint - GetProfileEndpoint endpoint.Endpoint - PutProfileEndpoint endpoint.Endpoint - PatchProfileEndpoint endpoint.Endpoint - DeleteProfileEndpoint endpoint.Endpoint - GetAddressesEndpoint endpoint.Endpoint - GetAddressEndpoint endpoint.Endpoint - PostAddressEndpoint endpoint.Endpoint - DeleteAddressEndpoint endpoint.Endpoint -} - -// MakeServerEndpoints returns an Endpoints struct where each endpoint invokes -// the corresponding method on the provided service. Useful in a profilesvc -// server. -func MakeServerEndpoints(s Service) Endpoints { - return Endpoints{ - PostProfileEndpoint: MakePostProfileEndpoint(s), - GetProfileEndpoint: MakeGetProfileEndpoint(s), - PutProfileEndpoint: MakePutProfileEndpoint(s), - PatchProfileEndpoint: MakePatchProfileEndpoint(s), - DeleteProfileEndpoint: MakeDeleteProfileEndpoint(s), - GetAddressesEndpoint: MakeGetAddressesEndpoint(s), - GetAddressEndpoint: MakeGetAddressEndpoint(s), - PostAddressEndpoint: MakePostAddressEndpoint(s), - DeleteAddressEndpoint: MakeDeleteAddressEndpoint(s), - } -} - -// MakeClientEndpoints returns an Endpoints struct where each endpoint invokes -// the corresponding method on the remote instance, via a transport/http.Client. -// Useful in a profilesvc client. -func MakeClientEndpoints(instance string) (Endpoints, error) { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - tgt, err := url.Parse(instance) - if err != nil { - return Endpoints{}, err - } - tgt.Path = "" - - options := []httptransport.ClientOption{} - - // Note that the request encoders need to modify the request URL, changing - // the path. That's fine: we simply need to provide specific encoders for - // each endpoint. - - return Endpoints{ - PostProfileEndpoint: httptransport.NewClient("POST", tgt, encodePostProfileRequest, decodePostProfileResponse, options...).Endpoint(), - GetProfileEndpoint: httptransport.NewClient("GET", tgt, encodeGetProfileRequest, decodeGetProfileResponse, options...).Endpoint(), - PutProfileEndpoint: httptransport.NewClient("PUT", tgt, encodePutProfileRequest, decodePutProfileResponse, options...).Endpoint(), - PatchProfileEndpoint: httptransport.NewClient("PATCH", tgt, encodePatchProfileRequest, decodePatchProfileResponse, options...).Endpoint(), - DeleteProfileEndpoint: httptransport.NewClient("DELETE", tgt, encodeDeleteProfileRequest, decodeDeleteProfileResponse, options...).Endpoint(), - GetAddressesEndpoint: httptransport.NewClient("GET", tgt, encodeGetAddressesRequest, decodeGetAddressesResponse, options...).Endpoint(), - GetAddressEndpoint: httptransport.NewClient("GET", tgt, encodeGetAddressRequest, decodeGetAddressResponse, options...).Endpoint(), - PostAddressEndpoint: httptransport.NewClient("POST", tgt, encodePostAddressRequest, decodePostAddressResponse, options...).Endpoint(), - DeleteAddressEndpoint: httptransport.NewClient("DELETE", tgt, encodeDeleteAddressRequest, decodeDeleteAddressResponse, options...).Endpoint(), - }, nil -} - -// PostProfile implements Service. Primarily useful in a client. -func (e Endpoints) PostProfile(ctx context.Context, p Profile) error { - request := postProfileRequest{Profile: p} - response, err := e.PostProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(postProfileResponse) - return resp.Err -} - -// GetProfile implements Service. Primarily useful in a client. -func (e Endpoints) GetProfile(ctx context.Context, id string) (Profile, error) { - request := getProfileRequest{ID: id} - response, err := e.GetProfileEndpoint(ctx, request) - if err != nil { - return Profile{}, err - } - resp := response.(getProfileResponse) - return resp.Profile, resp.Err -} - -// PutProfile implements Service. Primarily useful in a client. -func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error { - request := putProfileRequest{ID: id, Profile: p} - response, err := e.PutProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(putProfileResponse) - return resp.Err -} - -// PatchProfile implements Service. Primarily useful in a client. -func (e Endpoints) PatchProfile(ctx context.Context, id string, p Profile) error { - request := patchProfileRequest{ID: id, Profile: p} - response, err := e.PatchProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(patchProfileResponse) - return resp.Err -} - -// DeleteProfile implements Service. Primarily useful in a client. -func (e Endpoints) DeleteProfile(ctx context.Context, id string) error { - request := deleteProfileRequest{ID: id} - response, err := e.DeleteProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(deleteProfileResponse) - return resp.Err -} - -// GetAddresses implements Service. Primarily useful in a client. -func (e Endpoints) GetAddresses(ctx context.Context, profileID string) ([]Address, error) { - request := getAddressesRequest{ProfileID: profileID} - response, err := e.GetAddressesEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(getAddressesResponse) - return resp.Addresses, resp.Err -} - -// GetAddress implements Service. Primarily useful in a client. -func (e Endpoints) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) { - request := getAddressRequest{ProfileID: profileID, AddressID: addressID} - response, err := e.GetAddressEndpoint(ctx, request) - if err != nil { - return Address{}, err - } - resp := response.(getAddressResponse) - return resp.Address, resp.Err -} - -// PostAddress implements Service. Primarily useful in a client. -func (e Endpoints) PostAddress(ctx context.Context, profileID string, a Address) error { - request := postAddressRequest{ProfileID: profileID, Address: a} - response, err := e.PostAddressEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(postAddressResponse) - return resp.Err -} - -// DeleteAddress implements Service. Primarily useful in a client. -func (e Endpoints) DeleteAddress(ctx context.Context, profileID string, addressID string) error { - request := deleteAddressRequest{ProfileID: profileID, AddressID: addressID} - response, err := e.DeleteAddressEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(deleteAddressResponse) - return resp.Err -} - -// MakePostProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePostProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(postProfileRequest) - e := s.PostProfile(ctx, req.Profile) - return postProfileResponse{Err: e}, nil - } -} - -// MakeGetProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getProfileRequest) - p, e := s.GetProfile(ctx, req.ID) - return getProfileResponse{Profile: p, Err: e}, nil - } -} - -// MakePutProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePutProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(putProfileRequest) - e := s.PutProfile(ctx, req.ID, req.Profile) - return putProfileResponse{Err: e}, nil - } -} - -// MakePatchProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePatchProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(patchProfileRequest) - e := s.PatchProfile(ctx, req.ID, req.Profile) - return patchProfileResponse{Err: e}, nil - } -} - -// MakeDeleteProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeDeleteProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(deleteProfileRequest) - e := s.DeleteProfile(ctx, req.ID) - return deleteProfileResponse{Err: e}, nil - } -} - -// MakeGetAddressesEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetAddressesEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getAddressesRequest) - a, e := s.GetAddresses(ctx, req.ProfileID) - return getAddressesResponse{Addresses: a, Err: e}, nil - } -} - -// MakeGetAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getAddressRequest) - a, e := s.GetAddress(ctx, req.ProfileID, req.AddressID) - return getAddressResponse{Address: a, Err: e}, nil - } -} - -// MakePostAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePostAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(postAddressRequest) - e := s.PostAddress(ctx, req.ProfileID, req.Address) - return postAddressResponse{Err: e}, nil - } -} - -// MakeDeleteAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(deleteAddressRequest) - e := s.DeleteAddress(ctx, req.ProfileID, req.AddressID) - return deleteAddressResponse{Err: e}, nil - } -} - -// We have two options to return errors from the business logic. -// -// We could return the error via the endpoint itself. That makes certain things -// a little bit easier, like providing non-200 HTTP responses to the client. But -// Go kit assumes that endpoint errors are (or may be treated as) -// transport-domain errors. For example, an endpoint error will count against a -// circuit breaker error count. -// -// Therefore, it's often better to return service (business logic) errors in the -// response object. This means we have to do a bit more work in the HTTP -// response encoder to detect e.g. a not-found error and provide a proper HTTP -// status code. That work is done with the errorer interface, in transport.go. -// Response types that may contain business-logic errors implement that -// interface. - -type postProfileRequest struct { - Profile Profile -} - -type postProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r postProfileResponse) error() error { return r.Err } - -type getProfileRequest struct { - ID string -} - -type getProfileResponse struct { - Profile Profile `json:"profile,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getProfileResponse) error() error { return r.Err } - -type putProfileRequest struct { - ID string - Profile Profile -} - -type putProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r putProfileResponse) error() error { return nil } - -type patchProfileRequest struct { - ID string - Profile Profile -} - -type patchProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r patchProfileResponse) error() error { return r.Err } - -type deleteProfileRequest struct { - ID string -} - -type deleteProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r deleteProfileResponse) error() error { return r.Err } - -type getAddressesRequest struct { - ProfileID string -} - -type getAddressesResponse struct { - Addresses []Address `json:"addresses,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getAddressesResponse) error() error { return r.Err } - -type getAddressRequest struct { - ProfileID string - AddressID string -} - -type getAddressResponse struct { - Address Address `json:"address,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getAddressResponse) error() error { return r.Err } - -type postAddressRequest struct { - ProfileID string - Address Address -} - -type postAddressResponse struct { - Err error `json:"err,omitempty"` -} - -func (r postAddressResponse) error() error { return r.Err } - -type deleteAddressRequest struct { - ProfileID string - AddressID string -} - -type deleteAddressResponse struct { - Err error `json:"err,omitempty"` -} - -func (r deleteAddressResponse) error() error { return r.Err } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go deleted file mode 100644 index 1b738f5b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go +++ /dev/null @@ -1,88 +0,0 @@ -package profilesvc - -import ( - "context" - "time" - - "github.com/go-kit/kit/log" -) - -// Middleware describes a service (as opposed to endpoint) middleware. -type Middleware func(Service) Service - -func LoggingMiddleware(logger log.Logger) Middleware { - return func(next Service) Service { - return &loggingMiddleware{ - next: next, - logger: logger, - } - } -} - -type loggingMiddleware struct { - next Service - logger log.Logger -} - -func (mw loggingMiddleware) PostProfile(ctx context.Context, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PostProfile", "id", p.ID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PostProfile(ctx, p) -} - -func (mw loggingMiddleware) GetProfile(ctx context.Context, id string) (p Profile, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetProfile(ctx, id) -} - -func (mw loggingMiddleware) PutProfile(ctx context.Context, id string, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PutProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PutProfile(ctx, id, p) -} - -func (mw loggingMiddleware) PatchProfile(ctx context.Context, id string, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PatchProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PatchProfile(ctx, id, p) -} - -func (mw loggingMiddleware) DeleteProfile(ctx context.Context, id string) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "DeleteProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.DeleteProfile(ctx, id) -} - -func (mw loggingMiddleware) GetAddresses(ctx context.Context, profileID string) (addresses []Address, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetAddresses", "profileID", profileID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetAddresses(ctx, profileID) -} - -func (mw loggingMiddleware) GetAddress(ctx context.Context, profileID string, addressID string) (a Address, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetAddress(ctx, profileID, addressID) -} - -func (mw loggingMiddleware) PostAddress(ctx context.Context, profileID string, a Address) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PostAddress", "profileID", profileID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PostAddress(ctx, profileID, a) -} - -func (mw loggingMiddleware) DeleteAddress(ctx context.Context, profileID string, addressID string) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "DeleteAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.DeleteAddress(ctx, profileID, addressID) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go deleted file mode 100644 index cd34ecd9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go +++ /dev/null @@ -1,185 +0,0 @@ -package profilesvc - -import ( - "context" - "errors" - "sync" -) - -// Service is a simple CRUD interface for user profiles. -type Service interface { - PostProfile(ctx context.Context, p Profile) error - GetProfile(ctx context.Context, id string) (Profile, error) - PutProfile(ctx context.Context, id string, p Profile) error - PatchProfile(ctx context.Context, id string, p Profile) error - DeleteProfile(ctx context.Context, id string) error - GetAddresses(ctx context.Context, profileID string) ([]Address, error) - GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) - PostAddress(ctx context.Context, profileID string, a Address) error - DeleteAddress(ctx context.Context, profileID string, addressID string) error -} - -// Profile represents a single user profile. -// ID should be globally unique. -type Profile struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - Addresses []Address `json:"addresses,omitempty"` -} - -// Address is a field of a user profile. -// ID should be unique within the profile (at a minimum). -type Address struct { - ID string `json:"id"` - Location string `json:"location,omitempty"` -} - -var ( - ErrInconsistentIDs = errors.New("inconsistent IDs") - ErrAlreadyExists = errors.New("already exists") - ErrNotFound = errors.New("not found") -) - -type inmemService struct { - mtx sync.RWMutex - m map[string]Profile -} - -func NewInmemService() Service { - return &inmemService{ - m: map[string]Profile{}, - } -} - -func (s *inmemService) PostProfile(ctx context.Context, p Profile) error { - s.mtx.Lock() - defer s.mtx.Unlock() - if _, ok := s.m[p.ID]; ok { - return ErrAlreadyExists // POST = create, don't overwrite - } - s.m[p.ID] = p - return nil -} - -func (s *inmemService) GetProfile(ctx context.Context, id string) (Profile, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[id] - if !ok { - return Profile{}, ErrNotFound - } - return p, nil -} - -func (s *inmemService) PutProfile(ctx context.Context, id string, p Profile) error { - if id != p.ID { - return ErrInconsistentIDs - } - s.mtx.Lock() - defer s.mtx.Unlock() - s.m[id] = p // PUT = create or update - return nil -} - -func (s *inmemService) PatchProfile(ctx context.Context, id string, p Profile) error { - if p.ID != "" && id != p.ID { - return ErrInconsistentIDs - } - - s.mtx.Lock() - defer s.mtx.Unlock() - - existing, ok := s.m[id] - if !ok { - return ErrNotFound // PATCH = update existing, don't create - } - - // We assume that it's not possible to PATCH the ID, and that it's not - // possible to PATCH any field to its zero value. That is, the zero value - // means not specified. The way around this is to use e.g. Name *string in - // the Profile definition. But since this is just a demonstrative example, - // I'm leaving that out. - - if p.Name != "" { - existing.Name = p.Name - } - if len(p.Addresses) > 0 { - existing.Addresses = p.Addresses - } - s.m[id] = existing - return nil -} - -func (s *inmemService) DeleteProfile(ctx context.Context, id string) error { - s.mtx.Lock() - defer s.mtx.Unlock() - if _, ok := s.m[id]; !ok { - return ErrNotFound - } - delete(s.m, id) - return nil -} - -func (s *inmemService) GetAddresses(ctx context.Context, profileID string) ([]Address, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[profileID] - if !ok { - return []Address{}, ErrNotFound - } - return p.Addresses, nil -} - -func (s *inmemService) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[profileID] - if !ok { - return Address{}, ErrNotFound - } - for _, address := range p.Addresses { - if address.ID == addressID { - return address, nil - } - } - return Address{}, ErrNotFound -} - -func (s *inmemService) PostAddress(ctx context.Context, profileID string, a Address) error { - s.mtx.Lock() - defer s.mtx.Unlock() - p, ok := s.m[profileID] - if !ok { - return ErrNotFound - } - for _, address := range p.Addresses { - if address.ID == a.ID { - return ErrAlreadyExists - } - } - p.Addresses = append(p.Addresses, a) - s.m[profileID] = p - return nil -} - -func (s *inmemService) DeleteAddress(ctx context.Context, profileID string, addressID string) error { - s.mtx.Lock() - defer s.mtx.Unlock() - p, ok := s.m[profileID] - if !ok { - return ErrNotFound - } - newAddresses := make([]Address, 0, len(p.Addresses)) - for _, address := range p.Addresses { - if address.ID == addressID { - continue // delete - } - newAddresses = append(newAddresses, address) - } - if len(newAddresses) == len(p.Addresses) { - return ErrNotFound - } - p.Addresses = newAddresses - s.m[profileID] = p - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go deleted file mode 100644 index 6d34126d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go +++ /dev/null @@ -1,400 +0,0 @@ -package profilesvc - -// The profilesvc is just over HTTP, so we just have a single transport.go. - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "net/url" - - "github.com/gorilla/mux" - - "github.com/go-kit/kit/log" - httptransport "github.com/go-kit/kit/transport/http" -) - -var ( - // ErrBadRouting is returned when an expected path variable is missing. - // It always indicates programmer error. - ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)") -) - -// MakeHTTPHandler mounts all of the service endpoints into an http.Handler. -// Useful in a profilesvc server. -func MakeHTTPHandler(s Service, logger log.Logger) http.Handler { - r := mux.NewRouter() - e := MakeServerEndpoints(s) - options := []httptransport.ServerOption{ - httptransport.ServerErrorLogger(logger), - httptransport.ServerErrorEncoder(encodeError), - } - - // POST /profiles/ adds another profile - // GET /profiles/:id retrieves the given profile by id - // PUT /profiles/:id post updated profile information about the profile - // PATCH /profiles/:id partial updated profile information - // DELETE /profiles/:id remove the given profile - // GET /profiles/:id/addresses/ retrieve addresses associated with the profile - // GET /profiles/:id/addresses/:addressID retrieve a particular profile address - // POST /profiles/:id/addresses/ add a new address - // DELETE /profiles/:id/addresses/:addressID remove an address - - r.Methods("POST").Path("/profiles/").Handler(httptransport.NewServer( - e.PostProfileEndpoint, - decodePostProfileRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.GetProfileEndpoint, - decodeGetProfileRequest, - encodeResponse, - options..., - )) - r.Methods("PUT").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.PutProfileEndpoint, - decodePutProfileRequest, - encodeResponse, - options..., - )) - r.Methods("PATCH").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.PatchProfileEndpoint, - decodePatchProfileRequest, - encodeResponse, - options..., - )) - r.Methods("DELETE").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.DeleteProfileEndpoint, - decodeDeleteProfileRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}/addresses/").Handler(httptransport.NewServer( - e.GetAddressesEndpoint, - decodeGetAddressesRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}/addresses/{addressID}").Handler(httptransport.NewServer( - e.GetAddressEndpoint, - decodeGetAddressRequest, - encodeResponse, - options..., - )) - r.Methods("POST").Path("/profiles/{id}/addresses/").Handler(httptransport.NewServer( - e.PostAddressEndpoint, - decodePostAddressRequest, - encodeResponse, - options..., - )) - r.Methods("DELETE").Path("/profiles/{id}/addresses/{addressID}").Handler(httptransport.NewServer( - e.DeleteAddressEndpoint, - decodeDeleteAddressRequest, - encodeResponse, - options..., - )) - return r -} - -func decodePostProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - var req postProfileRequest - if e := json.NewDecoder(r.Body).Decode(&req.Profile); e != nil { - return nil, e - } - return req, nil -} - -func decodeGetProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return getProfileRequest{ID: id}, nil -} - -func decodePutProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var profile Profile - if err := json.NewDecoder(r.Body).Decode(&profile); err != nil { - return nil, err - } - return putProfileRequest{ - ID: id, - Profile: profile, - }, nil -} - -func decodePatchProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var profile Profile - if err := json.NewDecoder(r.Body).Decode(&profile); err != nil { - return nil, err - } - return patchProfileRequest{ - ID: id, - Profile: profile, - }, nil -} - -func decodeDeleteProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return deleteProfileRequest{ID: id}, nil -} - -func decodeGetAddressesRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return getAddressesRequest{ProfileID: id}, nil -} - -func decodeGetAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - addressID, ok := vars["addressID"] - if !ok { - return nil, ErrBadRouting - } - return getAddressRequest{ - ProfileID: id, - AddressID: addressID, - }, nil -} - -func decodePostAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var address Address - if err := json.NewDecoder(r.Body).Decode(&address); err != nil { - return nil, err - } - return postAddressRequest{ - ProfileID: id, - Address: address, - }, nil -} - -func decodeDeleteAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - addressID, ok := vars["addressID"] - if !ok { - return nil, ErrBadRouting - } - return deleteAddressRequest{ - ProfileID: id, - AddressID: addressID, - }, nil -} - -func encodePostProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("POST").Path("/profiles/") - req.URL.Path = "/profiles/" - return encodeRequest(ctx, req, request) -} - -func encodeGetProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}") - r := request.(getProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodePutProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("PUT").Path("/profiles/{id}") - r := request.(putProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodePatchProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("PATCH").Path("/profiles/{id}") - r := request.(patchProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodeDeleteProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("DELETE").Path("/profiles/{id}") - r := request.(deleteProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodeGetAddressesRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}/addresses/") - r := request.(getAddressesRequest) - profileID := url.QueryEscape(r.ProfileID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" - return encodeRequest(ctx, req, request) -} - -func encodeGetAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}/addresses/{addressID}") - r := request.(getAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - addressID := url.QueryEscape(r.AddressID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" + addressID - return encodeRequest(ctx, req, request) -} - -func encodePostAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("POST").Path("/profiles/{id}/addresses/") - r := request.(postAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" - return encodeRequest(ctx, req, request) -} - -func encodeDeleteAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("DELETE").Path("/profiles/{id}/addresses/{addressID}") - r := request.(deleteAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - addressID := url.QueryEscape(r.AddressID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" + addressID - return encodeRequest(ctx, req, request) -} - -func decodePostProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response postProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePutProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response putProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePatchProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response patchProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeDeleteProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response deleteProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetAddressesResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getAddressesResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePostAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response postAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeDeleteAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response deleteAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -// errorer is implemented by all concrete response types that may contain -// errors. It allows us to change the HTTP response code without needing to -// trigger an endpoint (transport-level) error. For more information, read the -// big comment in endpoints.go. -type errorer interface { - error() error -} - -// encodeResponse is the common method to encode all response types to the -// client. I chose to do it this way because, since we're using JSON, there's no -// reason to provide anything more specific. It's certainly possible to -// specialize on a per-response (per-method) basis. -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - // Not a Go kit transport error, but a business-logic error. - // Provide those as HTTP errors. - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -// encodeRequest likewise JSON-encodes the request to the HTTP request body. -// Don't use it directly as a transport/http.Client EncodeRequestFunc: -// profilesvc endpoints require mutating the HTTP method and request path. -func encodeRequest(_ context.Context, req *http.Request, request interface{}) error { - var buf bytes.Buffer - err := json.NewEncoder(&buf).Encode(request) - if err != nil { - return err - } - req.Body = ioutil.NopCloser(&buf) - return nil -} - -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - if err == nil { - panic("encodeError with nil error") - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - w.WriteHeader(codeFrom(err)) - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} - -func codeFrom(err error) int { - switch err { - case ErrNotFound: - return http.StatusNotFound - case ErrAlreadyExists, ErrInconsistentIDs: - return http.StatusBadRequest - default: - return http.StatusInternalServerError - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md deleted file mode 100644 index 1a9a14ee..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# shipping - -This example demonstrates a more real-world application consisting of multiple services. - -## Description - -The implementation is based on the container shipping domain from the [Domain Driven Design](http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215) book by Eric Evans, which was [originally](http://dddsample.sourceforge.net/) implemented in Java but has since been ported to Go. This example is a somewhat stripped down version to demonstrate the use of Go kit. The [original Go application](https://github.com/marcusolsson/goddd) is maintained separately and accompanied by an [AngularJS application](https://github.com/marcusolsson/dddelivery-angularjs) as well as a mock [routing service](https://github.com/marcusolsson/pathfinder). - -### Organization - -The application consists of three application services, `booking`, `handling` and `tracking`. Each of these is an individual Go kit service as seen in previous examples. - -- __booking__ - used by the shipping company to book and route cargos. -- __handling__ - used by our staff around the world to register whenever the cargo has been received, loaded etc. -- __tracking__ - used by the customer to track the cargo along the route - -There are also a few pure domain packages that contain some intricate business-logic. They provide domain objects and services that are used by each application service to provide interesting use-cases for the user. - -`inmem` contains in-memory implementations for the repositories found in the domain packages. - -The `routing` package provides a _domain service_ that is used to query an external application for possible routes. - -## Contributing - -As with all Go kit examples you are more than welcome to contribute. If you do however, please consider contributing back to the original project as well. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go deleted file mode 100644 index abe83f75..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go +++ /dev/null @@ -1,139 +0,0 @@ -package booking - -import ( - "context" - "time" - - "github.com/go-kit/kit/endpoint" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type bookCargoRequest struct { - Origin location.UNLocode - Destination location.UNLocode - ArrivalDeadline time.Time -} - -type bookCargoResponse struct { - ID cargo.TrackingID `json:"tracking_id,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r bookCargoResponse) error() error { return r.Err } - -func makeBookCargoEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(bookCargoRequest) - id, err := s.BookNewCargo(req.Origin, req.Destination, req.ArrivalDeadline) - return bookCargoResponse{ID: id, Err: err}, nil - } -} - -type loadCargoRequest struct { - ID cargo.TrackingID -} - -type loadCargoResponse struct { - Cargo *Cargo `json:"cargo,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r loadCargoResponse) error() error { return r.Err } - -func makeLoadCargoEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(loadCargoRequest) - c, err := s.LoadCargo(req.ID) - return loadCargoResponse{Cargo: &c, Err: err}, nil - } -} - -type requestRoutesRequest struct { - ID cargo.TrackingID -} - -type requestRoutesResponse struct { - Routes []cargo.Itinerary `json:"routes,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r requestRoutesResponse) error() error { return r.Err } - -func makeRequestRoutesEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(requestRoutesRequest) - itin := s.RequestPossibleRoutesForCargo(req.ID) - return requestRoutesResponse{Routes: itin, Err: nil}, nil - } -} - -type assignToRouteRequest struct { - ID cargo.TrackingID - Itinerary cargo.Itinerary -} - -type assignToRouteResponse struct { - Err error `json:"error,omitempty"` -} - -func (r assignToRouteResponse) error() error { return r.Err } - -func makeAssignToRouteEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(assignToRouteRequest) - err := s.AssignCargoToRoute(req.ID, req.Itinerary) - return assignToRouteResponse{Err: err}, nil - } -} - -type changeDestinationRequest struct { - ID cargo.TrackingID - Destination location.UNLocode -} - -type changeDestinationResponse struct { - Err error `json:"error,omitempty"` -} - -func (r changeDestinationResponse) error() error { return r.Err } - -func makeChangeDestinationEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(changeDestinationRequest) - err := s.ChangeDestination(req.ID, req.Destination) - return changeDestinationResponse{Err: err}, nil - } -} - -type listCargosRequest struct{} - -type listCargosResponse struct { - Cargos []Cargo `json:"cargos,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r listCargosResponse) error() error { return r.Err } - -func makeListCargosEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - _ = request.(listCargosRequest) - return listCargosResponse{Cargos: s.Cargos(), Err: nil}, nil - } -} - -type listLocationsRequest struct { -} - -type listLocationsResponse struct { - Locations []Location `json:"locations,omitempty"` - Err error `json:"error,omitempty"` -} - -func makeListLocationsEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - _ = request.(listLocationsRequest) - return listLocationsResponse{Locations: s.Locations(), Err: nil}, nil - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go deleted file mode 100644 index b9b03b91..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go +++ /dev/null @@ -1,88 +0,0 @@ -package booking - -import ( - "time" - - "github.com/go-kit/kit/metrics" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) BookNewCargo(origin, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) { - defer func(begin time.Time) { - s.requestCount.With("method", "book").Add(1) - s.requestLatency.With("method", "book").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.BookNewCargo(origin, destination, deadline) -} - -func (s *instrumentingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "load").Add(1) - s.requestLatency.With("method", "load").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.LoadCargo(id) -} - -func (s *instrumentingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - defer func(begin time.Time) { - s.requestCount.With("method", "request_routes").Add(1) - s.requestLatency.With("method", "request_routes").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.RequestPossibleRoutesForCargo(id) -} - -func (s *instrumentingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "assign_to_route").Add(1) - s.requestLatency.With("method", "assign_to_route").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.AssignCargoToRoute(id, itinerary) -} - -func (s *instrumentingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "change_destination").Add(1) - s.requestLatency.With("method", "change_destination").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.ChangeDestination(id, l) -} - -func (s *instrumentingService) Cargos() []Cargo { - defer func(begin time.Time) { - s.requestCount.With("method", "list_cargos").Add(1) - s.requestLatency.With("method", "list_cargos").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Cargos() -} - -func (s *instrumentingService) Locations() []Location { - defer func(begin time.Time) { - s.requestCount.With("method", "list_locations").Add(1) - s.requestLatency.With("method", "list_locations").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Locations() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go deleted file mode 100644 index 931d4307..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go +++ /dev/null @@ -1,102 +0,0 @@ -package booking - -import ( - "time" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) BookNewCargo(origin location.UNLocode, destination location.UNLocode, deadline time.Time) (id cargo.TrackingID, err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "book", - "origin", origin, - "destination", destination, - "arrival_deadline", deadline, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.BookNewCargo(origin, destination, deadline) -} - -func (s *loggingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "load", - "tracking_id", id, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.LoadCargo(id) -} - -func (s *loggingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - defer func(begin time.Time) { - s.logger.Log( - "method", "request_routes", - "tracking_id", id, - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.RequestPossibleRoutesForCargo(id) -} - -func (s *loggingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "assign_to_route", - "tracking_id", id, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.AssignCargoToRoute(id, itinerary) -} - -func (s *loggingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "change_destination", - "tracking_id", id, - "destination", l, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.ChangeDestination(id, l) -} - -func (s *loggingService) Cargos() []Cargo { - defer func(begin time.Time) { - s.logger.Log( - "method", "list_cargos", - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.Cargos() -} - -func (s *loggingService) Locations() []Location { - defer func(begin time.Time) { - s.logger.Log( - "method", "list_locations", - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.Locations() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go deleted file mode 100644 index 8689a5a5..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go +++ /dev/null @@ -1,197 +0,0 @@ -// Package booking provides the use-case of booking a cargo. Used by views -// facing an administrator. -package booking - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/routing" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// Service is the interface that provides booking methods. -type Service interface { - // BookNewCargo registers a new cargo in the tracking system, not yet - // routed. - BookNewCargo(origin location.UNLocode, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) - - // LoadCargo returns a read model of a cargo. - LoadCargo(id cargo.TrackingID) (Cargo, error) - - // RequestPossibleRoutesForCargo requests a list of itineraries describing - // possible routes for this cargo. - RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary - - // AssignCargoToRoute assigns a cargo to the route specified by the - // itinerary. - AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) error - - // ChangeDestination changes the destination of a cargo. - ChangeDestination(id cargo.TrackingID, destination location.UNLocode) error - - // Cargos returns a list of all cargos that have been booked. - Cargos() []Cargo - - // Locations returns a list of registered locations. - Locations() []Location -} - -type service struct { - cargos cargo.Repository - locations location.Repository - handlingEvents cargo.HandlingEventRepository - routingService routing.Service -} - -func (s *service) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) error { - if id == "" || len(itinerary.Legs) == 0 { - return ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return err - } - - c.AssignToRoute(itinerary) - - return s.cargos.Store(c) -} - -func (s *service) BookNewCargo(origin, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) { - if origin == "" || destination == "" || deadline.IsZero() { - return "", ErrInvalidArgument - } - - id := cargo.NextTrackingID() - rs := cargo.RouteSpecification{ - Origin: origin, - Destination: destination, - ArrivalDeadline: deadline, - } - - c := cargo.New(id, rs) - - if err := s.cargos.Store(c); err != nil { - return "", err - } - - return c.TrackingID, nil -} - -func (s *service) LoadCargo(id cargo.TrackingID) (Cargo, error) { - if id == "" { - return Cargo{}, ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return Cargo{}, err - } - - return assemble(c, s.handlingEvents), nil -} - -func (s *service) ChangeDestination(id cargo.TrackingID, destination location.UNLocode) error { - if id == "" || destination == "" { - return ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return err - } - - l, err := s.locations.Find(destination) - if err != nil { - return err - } - - c.SpecifyNewRoute(cargo.RouteSpecification{ - Origin: c.Origin, - Destination: l.UNLocode, - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - }) - - if err := s.cargos.Store(c); err != nil { - return err - } - - return nil -} - -func (s *service) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - if id == "" { - return nil - } - - c, err := s.cargos.Find(id) - if err != nil { - return []cargo.Itinerary{} - } - - return s.routingService.FetchRoutesForSpecification(c.RouteSpecification) -} - -func (s *service) Cargos() []Cargo { - var result []Cargo - for _, c := range s.cargos.FindAll() { - result = append(result, assemble(c, s.handlingEvents)) - } - return result -} - -func (s *service) Locations() []Location { - var result []Location - for _, v := range s.locations.FindAll() { - result = append(result, Location{ - UNLocode: string(v.UNLocode), - Name: v.Name, - }) - } - return result -} - -// NewService creates a booking service with necessary dependencies. -func NewService(cargos cargo.Repository, locations location.Repository, events cargo.HandlingEventRepository, rs routing.Service) Service { - return &service{ - cargos: cargos, - locations: locations, - handlingEvents: events, - routingService: rs, - } -} - -// Location is a read model for booking views. -type Location struct { - UNLocode string `json:"locode"` - Name string `json:"name"` -} - -// Cargo is a read model for booking views. -type Cargo struct { - ArrivalDeadline time.Time `json:"arrival_deadline"` - Destination string `json:"destination"` - Legs []cargo.Leg `json:"legs,omitempty"` - Misrouted bool `json:"misrouted"` - Origin string `json:"origin"` - Routed bool `json:"routed"` - TrackingID string `json:"tracking_id"` -} - -func assemble(c *cargo.Cargo, events cargo.HandlingEventRepository) Cargo { - return Cargo{ - TrackingID: string(c.TrackingID), - Origin: string(c.Origin), - Destination: string(c.RouteSpecification.Destination), - Misrouted: c.Delivery.RoutingStatus == cargo.Misrouted, - Routed: !c.Itinerary.IsEmpty(), - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - Legs: c.Itinerary.Legs, - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go deleted file mode 100644 index 8cf11a26..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go +++ /dev/null @@ -1,194 +0,0 @@ -package booking - -import ( - "context" - "encoding/json" - "errors" - "net/http" - "time" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -// MakeHandler returns a handler for the booking service. -func MakeHandler(bs Service, logger kitlog.Logger) http.Handler { - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - bookCargoHandler := kithttp.NewServer( - makeBookCargoEndpoint(bs), - decodeBookCargoRequest, - encodeResponse, - opts..., - ) - loadCargoHandler := kithttp.NewServer( - makeLoadCargoEndpoint(bs), - decodeLoadCargoRequest, - encodeResponse, - opts..., - ) - requestRoutesHandler := kithttp.NewServer( - makeRequestRoutesEndpoint(bs), - decodeRequestRoutesRequest, - encodeResponse, - opts..., - ) - assignToRouteHandler := kithttp.NewServer( - makeAssignToRouteEndpoint(bs), - decodeAssignToRouteRequest, - encodeResponse, - opts..., - ) - changeDestinationHandler := kithttp.NewServer( - makeChangeDestinationEndpoint(bs), - decodeChangeDestinationRequest, - encodeResponse, - opts..., - ) - listCargosHandler := kithttp.NewServer( - makeListCargosEndpoint(bs), - decodeListCargosRequest, - encodeResponse, - opts..., - ) - listLocationsHandler := kithttp.NewServer( - makeListLocationsEndpoint(bs), - decodeListLocationsRequest, - encodeResponse, - opts..., - ) - - r := mux.NewRouter() - - r.Handle("/booking/v1/cargos", bookCargoHandler).Methods("POST") - r.Handle("/booking/v1/cargos", listCargosHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}", loadCargoHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}/request_routes", requestRoutesHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}/assign_to_route", assignToRouteHandler).Methods("POST") - r.Handle("/booking/v1/cargos/{id}/change_destination", changeDestinationHandler).Methods("POST") - r.Handle("/booking/v1/locations", listLocationsHandler).Methods("GET") - - return r -} - -var errBadRoute = errors.New("bad route") - -func decodeBookCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - var body struct { - Origin string `json:"origin"` - Destination string `json:"destination"` - ArrivalDeadline time.Time `json:"arrival_deadline"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return bookCargoRequest{ - Origin: location.UNLocode(body.Origin), - Destination: location.UNLocode(body.Destination), - ArrivalDeadline: body.ArrivalDeadline, - }, nil -} - -func decodeLoadCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - return loadCargoRequest{ID: cargo.TrackingID(id)}, nil -} - -func decodeRequestRoutesRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - return requestRoutesRequest{ID: cargo.TrackingID(id)}, nil -} - -func decodeAssignToRouteRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - - var itinerary cargo.Itinerary - if err := json.NewDecoder(r.Body).Decode(&itinerary); err != nil { - return nil, err - } - - return assignToRouteRequest{ - ID: cargo.TrackingID(id), - Itinerary: itinerary, - }, nil -} - -func decodeChangeDestinationRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - - var body struct { - Destination string `json:"destination"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return changeDestinationRequest{ - ID: cargo.TrackingID(id), - Destination: location.UNLocode(body.Destination), - }, nil -} - -func decodeListCargosRequest(_ context.Context, r *http.Request) (interface{}, error) { - return listCargosRequest{}, nil -} - -func decodeListLocationsRequest(_ context.Context, r *http.Request) (interface{}, error) { - return listLocationsRequest{}, nil -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go deleted file mode 100644 index a9440f51..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go +++ /dev/null @@ -1,137 +0,0 @@ -// Package cargo contains the heart of the domain model. -package cargo - -import ( - "errors" - "strings" - "time" - - "github.com/pborman/uuid" - - "github.com/go-kit/kit/examples/shipping/location" -) - -// TrackingID uniquely identifies a particular cargo. -type TrackingID string - -// Cargo is the central class in the domain model. -type Cargo struct { - TrackingID TrackingID - Origin location.UNLocode - RouteSpecification RouteSpecification - Itinerary Itinerary - Delivery Delivery -} - -// SpecifyNewRoute specifies a new route for this cargo. -func (c *Cargo) SpecifyNewRoute(rs RouteSpecification) { - c.RouteSpecification = rs - c.Delivery = c.Delivery.UpdateOnRouting(c.RouteSpecification, c.Itinerary) -} - -// AssignToRoute attaches a new itinerary to this cargo. -func (c *Cargo) AssignToRoute(itinerary Itinerary) { - c.Itinerary = itinerary - c.Delivery = c.Delivery.UpdateOnRouting(c.RouteSpecification, c.Itinerary) -} - -// DeriveDeliveryProgress updates all aspects of the cargo aggregate status -// based on the current route specification, itinerary and handling of the cargo. -func (c *Cargo) DeriveDeliveryProgress(history HandlingHistory) { - c.Delivery = DeriveDeliveryFrom(c.RouteSpecification, c.Itinerary, history) -} - -// New creates a new, unrouted cargo. -func New(id TrackingID, rs RouteSpecification) *Cargo { - itinerary := Itinerary{} - history := HandlingHistory{make([]HandlingEvent, 0)} - - return &Cargo{ - TrackingID: id, - Origin: rs.Origin, - RouteSpecification: rs, - Delivery: DeriveDeliveryFrom(rs, itinerary, history), - } -} - -// Repository provides access a cargo store. -type Repository interface { - Store(cargo *Cargo) error - Find(id TrackingID) (*Cargo, error) - FindAll() []*Cargo -} - -// ErrUnknown is used when a cargo could not be found. -var ErrUnknown = errors.New("unknown cargo") - -// NextTrackingID generates a new tracking ID. -// TODO: Move to infrastructure(?) -func NextTrackingID() TrackingID { - return TrackingID(strings.Split(strings.ToUpper(uuid.New()), "-")[0]) -} - -// RouteSpecification Contains information about a route: its origin, -// destination and arrival deadline. -type RouteSpecification struct { - Origin location.UNLocode - Destination location.UNLocode - ArrivalDeadline time.Time -} - -// IsSatisfiedBy checks whether provided itinerary satisfies this -// specification. -func (s RouteSpecification) IsSatisfiedBy(itinerary Itinerary) bool { - return itinerary.Legs != nil && - s.Origin == itinerary.InitialDepartureLocation() && - s.Destination == itinerary.FinalArrivalLocation() -} - -// RoutingStatus describes status of cargo routing. -type RoutingStatus int - -// Valid routing statuses. -const ( - NotRouted RoutingStatus = iota - Misrouted - Routed -) - -func (s RoutingStatus) String() string { - switch s { - case NotRouted: - return "Not routed" - case Misrouted: - return "Misrouted" - case Routed: - return "Routed" - } - return "" -} - -// TransportStatus describes status of cargo transportation. -type TransportStatus int - -// Valid transport statuses. -const ( - NotReceived TransportStatus = iota - InPort - OnboardCarrier - Claimed - Unknown -) - -func (s TransportStatus) String() string { - switch s { - case NotReceived: - return "Not received" - case InPort: - return "In port" - case OnboardCarrier: - return "Onboard carrier" - case Claimed: - return "Claimed" - case Unknown: - return "Unknown" - } - return "" -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go deleted file mode 100644 index 34f079dc..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go +++ /dev/null @@ -1,174 +0,0 @@ -package cargo - -import ( - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// Delivery is the actual transportation of the cargo, as opposed to the -// customer requirement (RouteSpecification) and the plan (Itinerary). -type Delivery struct { - Itinerary Itinerary - RouteSpecification RouteSpecification - RoutingStatus RoutingStatus - TransportStatus TransportStatus - NextExpectedActivity HandlingActivity - LastEvent HandlingEvent - LastKnownLocation location.UNLocode - CurrentVoyage voyage.Number - ETA time.Time - IsMisdirected bool - IsUnloadedAtDestination bool -} - -// UpdateOnRouting creates a new delivery snapshot to reflect changes in -// routing, i.e. when the route specification or the itinerary has changed but -// no additional handling of the cargo has been performed. -func (d Delivery) UpdateOnRouting(rs RouteSpecification, itinerary Itinerary) Delivery { - return newDelivery(d.LastEvent, itinerary, rs) -} - -// IsOnTrack checks if the delivery is on track. -func (d Delivery) IsOnTrack() bool { - return d.RoutingStatus == Routed && !d.IsMisdirected -} - -// DeriveDeliveryFrom creates a new delivery snapshot based on the complete -// handling history of a cargo, as well as its route specification and -// itinerary. -func DeriveDeliveryFrom(rs RouteSpecification, itinerary Itinerary, history HandlingHistory) Delivery { - lastEvent, _ := history.MostRecentlyCompletedEvent() - return newDelivery(lastEvent, itinerary, rs) -} - -// newDelivery creates a up-to-date delivery based on an handling event, -// itinerary and a route specification. -func newDelivery(lastEvent HandlingEvent, itinerary Itinerary, rs RouteSpecification) Delivery { - var ( - routingStatus = calculateRoutingStatus(itinerary, rs) - transportStatus = calculateTransportStatus(lastEvent) - lastKnownLocation = calculateLastKnownLocation(lastEvent) - isMisdirected = calculateMisdirectedStatus(lastEvent, itinerary) - isUnloadedAtDestination = calculateUnloadedAtDestination(lastEvent, rs) - currentVoyage = calculateCurrentVoyage(transportStatus, lastEvent) - ) - - d := Delivery{ - LastEvent: lastEvent, - Itinerary: itinerary, - RouteSpecification: rs, - RoutingStatus: routingStatus, - TransportStatus: transportStatus, - LastKnownLocation: lastKnownLocation, - IsMisdirected: isMisdirected, - IsUnloadedAtDestination: isUnloadedAtDestination, - CurrentVoyage: currentVoyage, - } - - d.NextExpectedActivity = calculateNextExpectedActivity(d) - d.ETA = calculateETA(d) - - return d -} - -// Below are internal functions used when creating a new delivery. - -func calculateRoutingStatus(itinerary Itinerary, rs RouteSpecification) RoutingStatus { - if itinerary.Legs == nil { - return NotRouted - } - - if rs.IsSatisfiedBy(itinerary) { - return Routed - } - - return Misrouted -} - -func calculateMisdirectedStatus(event HandlingEvent, itinerary Itinerary) bool { - if event.Activity.Type == NotHandled { - return false - } - - return !itinerary.IsExpected(event) -} - -func calculateUnloadedAtDestination(event HandlingEvent, rs RouteSpecification) bool { - if event.Activity.Type == NotHandled { - return false - } - - return event.Activity.Type == Unload && rs.Destination == event.Activity.Location -} - -func calculateTransportStatus(event HandlingEvent) TransportStatus { - switch event.Activity.Type { - case NotHandled: - return NotReceived - case Load: - return OnboardCarrier - case Unload: - return InPort - case Receive: - return InPort - case Customs: - return InPort - case Claim: - return Claimed - } - return Unknown -} - -func calculateLastKnownLocation(event HandlingEvent) location.UNLocode { - return event.Activity.Location -} - -func calculateNextExpectedActivity(d Delivery) HandlingActivity { - if !d.IsOnTrack() { - return HandlingActivity{} - } - - switch d.LastEvent.Activity.Type { - case NotHandled: - return HandlingActivity{Type: Receive, Location: d.RouteSpecification.Origin} - case Receive: - l := d.Itinerary.Legs[0] - return HandlingActivity{Type: Load, Location: l.LoadLocation, VoyageNumber: l.VoyageNumber} - case Load: - for _, l := range d.Itinerary.Legs { - if l.LoadLocation == d.LastEvent.Activity.Location { - return HandlingActivity{Type: Unload, Location: l.UnloadLocation, VoyageNumber: l.VoyageNumber} - } - } - case Unload: - for i, l := range d.Itinerary.Legs { - if l.UnloadLocation == d.LastEvent.Activity.Location { - if i < len(d.Itinerary.Legs)-1 { - return HandlingActivity{Type: Load, Location: d.Itinerary.Legs[i+1].LoadLocation, VoyageNumber: d.Itinerary.Legs[i+1].VoyageNumber} - } - - return HandlingActivity{Type: Claim, Location: l.UnloadLocation} - } - } - } - - return HandlingActivity{} -} - -func calculateCurrentVoyage(transportStatus TransportStatus, event HandlingEvent) voyage.Number { - if transportStatus == OnboardCarrier && event.Activity.Type != NotHandled { - return event.Activity.VoyageNumber - } - - return voyage.Number("") -} - -func calculateETA(d Delivery) time.Time { - if !d.IsOnTrack() { - return time.Time{} - } - - return d.Itinerary.FinalArrivalTime() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go deleted file mode 100644 index bec8509f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go +++ /dev/null @@ -1,121 +0,0 @@ -package cargo - -// TODO: It would make sense to have this in its own package. Unfortunately, -// then there would be a circular dependency between the cargo and handling -// packages since cargo.Delivery would use handling.HandlingEvent and -// handling.HandlingEvent would use cargo.TrackingID. Also, -// HandlingEventFactory depends on the cargo repository. -// -// It would make sense not having the cargo package depend on handling. - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// HandlingActivity represents how and where a cargo can be handled, and can -// be used to express predictions about what is expected to happen to a cargo -// in the future. -type HandlingActivity struct { - Type HandlingEventType - Location location.UNLocode - VoyageNumber voyage.Number -} - -// HandlingEvent is used to register the event when, for instance, a cargo is -// unloaded from a carrier at a some location at a given time. -type HandlingEvent struct { - TrackingID TrackingID - Activity HandlingActivity -} - -// HandlingEventType describes type of a handling event. -type HandlingEventType int - -// Valid handling event types. -const ( - NotHandled HandlingEventType = iota - Load - Unload - Receive - Claim - Customs -) - -func (t HandlingEventType) String() string { - switch t { - case NotHandled: - return "Not Handled" - case Load: - return "Load" - case Unload: - return "Unload" - case Receive: - return "Receive" - case Claim: - return "Claim" - case Customs: - return "Customs" - } - - return "" -} - -// HandlingHistory is the handling history of a cargo. -type HandlingHistory struct { - HandlingEvents []HandlingEvent -} - -// MostRecentlyCompletedEvent returns most recently completed handling event. -func (h HandlingHistory) MostRecentlyCompletedEvent() (HandlingEvent, error) { - if len(h.HandlingEvents) == 0 { - return HandlingEvent{}, errors.New("delivery history is empty") - } - - return h.HandlingEvents[len(h.HandlingEvents)-1], nil -} - -// HandlingEventRepository provides access a handling event store. -type HandlingEventRepository interface { - Store(e HandlingEvent) - QueryHandlingHistory(TrackingID) HandlingHistory -} - -// HandlingEventFactory creates handling events. -type HandlingEventFactory struct { - CargoRepository Repository - VoyageRepository voyage.Repository - LocationRepository location.Repository -} - -// CreateHandlingEvent creates a validated handling event. -func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID, - voyageNumber voyage.Number, unLocode location.UNLocode, eventType HandlingEventType) (HandlingEvent, error) { - - if _, err := f.CargoRepository.Find(id); err != nil { - return HandlingEvent{}, err - } - - if _, err := f.VoyageRepository.Find(voyageNumber); err != nil { - // TODO: This is pretty ugly, but when creating a Receive event, the voyage number is not known. - if len(voyageNumber) > 0 { - return HandlingEvent{}, err - } - } - - if _, err := f.LocationRepository.Find(unLocode); err != nil { - return HandlingEvent{}, err - } - - return HandlingEvent{ - TrackingID: id, - Activity: HandlingActivity{ - Type: eventType, - Location: unLocode, - VoyageNumber: voyageNumber, - }, - }, nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go deleted file mode 100644 index 6b5088ea..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go +++ /dev/null @@ -1,91 +0,0 @@ -package cargo - -import ( - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// Leg describes the transportation between two locations on a voyage. -type Leg struct { - VoyageNumber voyage.Number `json:"voyage_number"` - LoadLocation location.UNLocode `json:"from"` - UnloadLocation location.UNLocode `json:"to"` - LoadTime time.Time `json:"load_time"` - UnloadTime time.Time `json:"unload_time"` -} - -// NewLeg creates a new itinerary leg. -func NewLeg(voyageNumber voyage.Number, loadLocation, unloadLocation location.UNLocode, loadTime, unloadTime time.Time) Leg { - return Leg{ - VoyageNumber: voyageNumber, - LoadLocation: loadLocation, - UnloadLocation: unloadLocation, - LoadTime: loadTime, - UnloadTime: unloadTime, - } -} - -// Itinerary specifies steps required to transport a cargo from its origin to -// destination. -type Itinerary struct { - Legs []Leg `json:"legs"` -} - -// InitialDepartureLocation returns the start of the itinerary. -func (i Itinerary) InitialDepartureLocation() location.UNLocode { - if i.IsEmpty() { - return location.UNLocode("") - } - return i.Legs[0].LoadLocation -} - -// FinalArrivalLocation returns the end of the itinerary. -func (i Itinerary) FinalArrivalLocation() location.UNLocode { - if i.IsEmpty() { - return location.UNLocode("") - } - return i.Legs[len(i.Legs)-1].UnloadLocation -} - -// FinalArrivalTime returns the expected arrival time at final destination. -func (i Itinerary) FinalArrivalTime() time.Time { - return i.Legs[len(i.Legs)-1].UnloadTime -} - -// IsEmpty checks if the itinerary contains at least one leg. -func (i Itinerary) IsEmpty() bool { - return i.Legs == nil || len(i.Legs) == 0 -} - -// IsExpected checks if the given handling event is expected when executing -// this itinerary. -func (i Itinerary) IsExpected(event HandlingEvent) bool { - if i.IsEmpty() { - return true - } - - switch event.Activity.Type { - case Receive: - return i.InitialDepartureLocation() == event.Activity.Location - case Load: - for _, l := range i.Legs { - if l.LoadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber { - return true - } - } - return false - case Unload: - for _, l := range i.Legs { - if l.UnloadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber { - return true - } - } - return false - case Claim: - return i.FinalArrivalLocation() == event.Activity.Location - } - - return true -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go deleted file mode 100644 index 555d0873..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go +++ /dev/null @@ -1,34 +0,0 @@ -package handling - -import ( - "context" - "time" - - "github.com/go-kit/kit/endpoint" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type registerIncidentRequest struct { - ID cargo.TrackingID - Location location.UNLocode - Voyage voyage.Number - EventType cargo.HandlingEventType - CompletionTime time.Time -} - -type registerIncidentResponse struct { - Err error `json:"error,omitempty"` -} - -func (r registerIncidentResponse) error() error { return r.Err } - -func makeRegisterIncidentEndpoint(hs Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(registerIncidentRequest) - err := hs.RegisterHandlingEvent(req.CompletionTime, req.ID, req.Voyage, req.Location, req.EventType) - return registerIncidentResponse{Err: err}, nil - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go deleted file mode 100644 index fecce04e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go +++ /dev/null @@ -1,37 +0,0 @@ -package handling - -import ( - "time" - - "github.com/go-kit/kit/metrics" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - loc location.UNLocode, eventType cargo.HandlingEventType) error { - - defer func(begin time.Time) { - s.requestCount.With("method", "register_incident").Add(1) - s.requestLatency.With("method", "register_incident").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, loc, eventType) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go deleted file mode 100644 index 84722fb4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go +++ /dev/null @@ -1,38 +0,0 @@ -package handling - -import ( - "time" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - unLocode location.UNLocode, eventType cargo.HandlingEventType) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "register_incident", - "tracking_id", id, - "location", unLocode, - "voyage", voyageNumber, - "event_type", eventType, - "completion_time", completed, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, unLocode, eventType) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go deleted file mode 100644 index 83d503a2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package handling provides the use-case for registering incidents. Used by -// views facing the people handling the cargo along its route. -package handling - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/inspection" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// EventHandler provides a means of subscribing to registered handling events. -type EventHandler interface { - CargoWasHandled(cargo.HandlingEvent) -} - -// Service provides handling operations. -type Service interface { - // RegisterHandlingEvent registers a handling event in the system, and - // notifies interested parties that a cargo has been handled. - RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - unLocode location.UNLocode, eventType cargo.HandlingEventType) error -} - -type service struct { - handlingEventRepository cargo.HandlingEventRepository - handlingEventFactory cargo.HandlingEventFactory - handlingEventHandler EventHandler -} - -func (s *service) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - loc location.UNLocode, eventType cargo.HandlingEventType) error { - if completed.IsZero() || id == "" || loc == "" || eventType == cargo.NotHandled { - return ErrInvalidArgument - } - - e, err := s.handlingEventFactory.CreateHandlingEvent(time.Now(), completed, id, voyageNumber, loc, eventType) - if err != nil { - return err - } - - s.handlingEventRepository.Store(e) - s.handlingEventHandler.CargoWasHandled(e) - - return nil -} - -// NewService creates a handling event service with necessary dependencies. -func NewService(r cargo.HandlingEventRepository, f cargo.HandlingEventFactory, h EventHandler) Service { - return &service{ - handlingEventRepository: r, - handlingEventFactory: f, - handlingEventHandler: h, - } -} - -type handlingEventHandler struct { - InspectionService inspection.Service -} - -func (h *handlingEventHandler) CargoWasHandled(event cargo.HandlingEvent) { - h.InspectionService.InspectCargo(event.TrackingID) -} - -// NewEventHandler returns a new instance of a EventHandler. -func NewEventHandler(s inspection.Service) EventHandler { - return &handlingEventHandler{ - InspectionService: s, - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go deleted file mode 100644 index 0e21365b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go +++ /dev/null @@ -1,100 +0,0 @@ -package handling - -import ( - "context" - "encoding/json" - "net/http" - "time" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// MakeHandler returns a handler for the handling service. -func MakeHandler(hs Service, logger kitlog.Logger) http.Handler { - r := mux.NewRouter() - - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - registerIncidentHandler := kithttp.NewServer( - makeRegisterIncidentEndpoint(hs), - decodeRegisterIncidentRequest, - encodeResponse, - opts..., - ) - - r.Handle("/handling/v1/incidents", registerIncidentHandler).Methods("POST") - - return r -} - -func decodeRegisterIncidentRequest(_ context.Context, r *http.Request) (interface{}, error) { - var body struct { - CompletionTime time.Time `json:"completion_time"` - TrackingID string `json:"tracking_id"` - VoyageNumber string `json:"voyage"` - Location string `json:"location"` - EventType string `json:"event_type"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return registerIncidentRequest{ - CompletionTime: body.CompletionTime, - ID: cargo.TrackingID(body.TrackingID), - Voyage: voyage.Number(body.VoyageNumber), - Location: location.UNLocode(body.Location), - EventType: stringToEventType(body.EventType), - }, nil -} - -func stringToEventType(s string) cargo.HandlingEventType { - types := map[string]cargo.HandlingEventType{ - cargo.Receive.String(): cargo.Receive, - cargo.Load.String(): cargo.Load, - cargo.Unload.String(): cargo.Unload, - cargo.Customs.String(): cargo.Customs, - cargo.Claim.String(): cargo.Claim, - } - return types[s] -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go deleted file mode 100644 index f941b7eb..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go +++ /dev/null @@ -1,142 +0,0 @@ -// Package inmem provides in-memory implementations of all the domain repositories. -package inmem - -import ( - "sync" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type cargoRepository struct { - mtx sync.RWMutex - cargos map[cargo.TrackingID]*cargo.Cargo -} - -func (r *cargoRepository) Store(c *cargo.Cargo) error { - r.mtx.Lock() - defer r.mtx.Unlock() - r.cargos[c.TrackingID] = c - return nil -} - -func (r *cargoRepository) Find(id cargo.TrackingID) (*cargo.Cargo, error) { - r.mtx.RLock() - defer r.mtx.RUnlock() - if val, ok := r.cargos[id]; ok { - return val, nil - } - return nil, cargo.ErrUnknown -} - -func (r *cargoRepository) FindAll() []*cargo.Cargo { - r.mtx.RLock() - defer r.mtx.RUnlock() - c := make([]*cargo.Cargo, 0, len(r.cargos)) - for _, val := range r.cargos { - c = append(c, val) - } - return c -} - -// NewCargoRepository returns a new instance of a in-memory cargo repository. -func NewCargoRepository() cargo.Repository { - return &cargoRepository{ - cargos: make(map[cargo.TrackingID]*cargo.Cargo), - } -} - -type locationRepository struct { - locations map[location.UNLocode]*location.Location -} - -func (r *locationRepository) Find(locode location.UNLocode) (*location.Location, error) { - if l, ok := r.locations[locode]; ok { - return l, nil - } - return nil, location.ErrUnknown -} - -func (r *locationRepository) FindAll() []*location.Location { - l := make([]*location.Location, 0, len(r.locations)) - for _, val := range r.locations { - l = append(l, val) - } - return l -} - -// NewLocationRepository returns a new instance of a in-memory location repository. -func NewLocationRepository() location.Repository { - r := &locationRepository{ - locations: make(map[location.UNLocode]*location.Location), - } - - r.locations[location.SESTO] = location.Stockholm - r.locations[location.AUMEL] = location.Melbourne - r.locations[location.CNHKG] = location.Hongkong - r.locations[location.JNTKO] = location.Tokyo - r.locations[location.NLRTM] = location.Rotterdam - r.locations[location.DEHAM] = location.Hamburg - - return r -} - -type voyageRepository struct { - voyages map[voyage.Number]*voyage.Voyage -} - -func (r *voyageRepository) Find(voyageNumber voyage.Number) (*voyage.Voyage, error) { - if v, ok := r.voyages[voyageNumber]; ok { - return v, nil - } - - return nil, voyage.ErrUnknown -} - -// NewVoyageRepository returns a new instance of a in-memory voyage repository. -func NewVoyageRepository() voyage.Repository { - r := &voyageRepository{ - voyages: make(map[voyage.Number]*voyage.Voyage), - } - - r.voyages[voyage.V100.Number] = voyage.V100 - r.voyages[voyage.V300.Number] = voyage.V300 - r.voyages[voyage.V400.Number] = voyage.V400 - - r.voyages[voyage.V0100S.Number] = voyage.V0100S - r.voyages[voyage.V0200T.Number] = voyage.V0200T - r.voyages[voyage.V0300A.Number] = voyage.V0300A - r.voyages[voyage.V0301S.Number] = voyage.V0301S - r.voyages[voyage.V0400S.Number] = voyage.V0400S - - return r -} - -type handlingEventRepository struct { - mtx sync.RWMutex - events map[cargo.TrackingID][]cargo.HandlingEvent -} - -func (r *handlingEventRepository) Store(e cargo.HandlingEvent) { - r.mtx.Lock() - defer r.mtx.Unlock() - // Make array if it's the first event with this tracking ID. - if _, ok := r.events[e.TrackingID]; !ok { - r.events[e.TrackingID] = make([]cargo.HandlingEvent, 0) - } - r.events[e.TrackingID] = append(r.events[e.TrackingID], e) -} - -func (r *handlingEventRepository) QueryHandlingHistory(id cargo.TrackingID) cargo.HandlingHistory { - r.mtx.RLock() - defer r.mtx.RUnlock() - return cargo.HandlingHistory{HandlingEvents: r.events[id]} -} - -// NewHandlingEventRepository returns a new instance of a in-memory handling event repository. -func NewHandlingEventRepository() cargo.HandlingEventRepository { - return &handlingEventRepository{ - events: make(map[cargo.TrackingID][]cargo.HandlingEvent), - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go deleted file mode 100644 index 2ebf73d4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go +++ /dev/null @@ -1,53 +0,0 @@ -// Package inspection provides means to inspect cargos. -package inspection - -import ( - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// EventHandler provides means of subscribing to inspection events. -type EventHandler interface { - CargoWasMisdirected(*cargo.Cargo) - CargoHasArrived(*cargo.Cargo) -} - -// Service provides cargo inspection operations. -type Service interface { - // InspectCargo inspects cargo and send relevant notifications to - // interested parties, for example if a cargo has been misdirected, or - // unloaded at the final destination. - InspectCargo(id cargo.TrackingID) -} - -type service struct { - cargos cargo.Repository - events cargo.HandlingEventRepository - handler EventHandler -} - -// TODO: Should be transactional -func (s *service) InspectCargo(id cargo.TrackingID) { - c, err := s.cargos.Find(id) - if err != nil { - return - } - - h := s.events.QueryHandlingHistory(id) - - c.DeriveDeliveryProgress(h) - - if c.Delivery.IsMisdirected { - s.handler.CargoWasMisdirected(c) - } - - if c.Delivery.IsUnloadedAtDestination { - s.handler.CargoHasArrived(c) - } - - s.cargos.Store(c) -} - -// NewService creates a inspection service with necessary dependencies. -func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository, handler EventHandler) Service { - return &service{cargos, events, handler} -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go deleted file mode 100644 index ee2e5d45..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package location provides the Location aggregate. -package location - -import ( - "errors" -) - -// UNLocode is the United Nations location code that uniquely identifies a -// particular location. -// -// http://www.unece.org/cefact/locode/ -// http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE -type UNLocode string - -// Location is a location is our model is stops on a journey, such as cargo -// origin or destination, or carrier movement endpoints. -type Location struct { - UNLocode UNLocode - Name string -} - -// ErrUnknown is used when a location could not be found. -var ErrUnknown = errors.New("unknown location") - -// Repository provides access a location store. -type Repository interface { - Find(locode UNLocode) (*Location, error) - FindAll() []*Location -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go deleted file mode 100644 index 7fd34efa..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go +++ /dev/null @@ -1,27 +0,0 @@ -package location - -// Sample UN locodes. -var ( - SESTO UNLocode = "SESTO" - AUMEL UNLocode = "AUMEL" - CNHKG UNLocode = "CNHKG" - USNYC UNLocode = "USNYC" - USCHI UNLocode = "USCHI" - JNTKO UNLocode = "JNTKO" - DEHAM UNLocode = "DEHAM" - NLRTM UNLocode = "NLRTM" - FIHEL UNLocode = "FIHEL" -) - -// Sample locations. -var ( - Stockholm = &Location{SESTO, "Stockholm"} - Melbourne = &Location{AUMEL, "Melbourne"} - Hongkong = &Location{CNHKG, "Hongkong"} - NewYork = &Location{USNYC, "New York"} - Chicago = &Location{USCHI, "Chicago"} - Tokyo = &Location{JNTKO, "Tokyo"} - Hamburg = &Location{DEHAM, "Hamburg"} - Rotterdam = &Location{NLRTM, "Rotterdam"} - Helsinki = &Location{FIHEL, "Helsinki"} -) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go deleted file mode 100644 index 8337d61d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go +++ /dev/null @@ -1,200 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "net/http" - "os" - "os/signal" - "syscall" - "time" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - - "github.com/go-kit/kit/examples/shipping/booking" - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/handling" - "github.com/go-kit/kit/examples/shipping/inmem" - "github.com/go-kit/kit/examples/shipping/inspection" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/routing" - "github.com/go-kit/kit/examples/shipping/tracking" -) - -const ( - defaultPort = "8080" - defaultRoutingServiceURL = "http://localhost:7878" -) - -func main() { - var ( - addr = envString("PORT", defaultPort) - rsurl = envString("ROUTINGSERVICE_URL", defaultRoutingServiceURL) - - httpAddr = flag.String("http.addr", ":"+addr, "HTTP listen address") - routingServiceURL = flag.String("service.routing", rsurl, "routing service URL") - - ctx = context.Background() - ) - - flag.Parse() - - var logger log.Logger - logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - - var ( - cargos = inmem.NewCargoRepository() - locations = inmem.NewLocationRepository() - voyages = inmem.NewVoyageRepository() - handlingEvents = inmem.NewHandlingEventRepository() - ) - - // Configure some questionable dependencies. - var ( - handlingEventFactory = cargo.HandlingEventFactory{ - CargoRepository: cargos, - VoyageRepository: voyages, - LocationRepository: locations, - } - handlingEventHandler = handling.NewEventHandler( - inspection.NewService(cargos, handlingEvents, nil), - ) - ) - - // Facilitate testing by adding some cargos. - storeTestData(cargos) - - fieldKeys := []string{"method"} - - var rs routing.Service - rs = routing.NewProxyingMiddleware(ctx, *routingServiceURL)(rs) - - var bs booking.Service - bs = booking.NewService(cargos, locations, handlingEvents, rs) - bs = booking.NewLoggingService(log.With(logger, "component", "booking"), bs) - bs = booking.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "booking_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "booking_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - bs, - ) - - var ts tracking.Service - ts = tracking.NewService(cargos, handlingEvents) - ts = tracking.NewLoggingService(log.With(logger, "component", "tracking"), ts) - ts = tracking.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "tracking_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "tracking_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - ts, - ) - - var hs handling.Service - hs = handling.NewService(handlingEvents, handlingEventFactory, handlingEventHandler) - hs = handling.NewLoggingService(log.With(logger, "component", "handling"), hs) - hs = handling.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "handling_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "handling_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - hs, - ) - - httpLogger := log.With(logger, "component", "http") - - mux := http.NewServeMux() - - mux.Handle("/booking/v1/", booking.MakeHandler(bs, httpLogger)) - mux.Handle("/tracking/v1/", tracking.MakeHandler(ts, httpLogger)) - mux.Handle("/handling/v1/", handling.MakeHandler(hs, httpLogger)) - - http.Handle("/", accessControl(mux)) - http.Handle("/metrics", promhttp.Handler()) - - errs := make(chan error, 2) - go func() { - logger.Log("transport", "http", "address", *httpAddr, "msg", "listening") - errs <- http.ListenAndServe(*httpAddr, nil) - }() - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT) - errs <- fmt.Errorf("%s", <-c) - }() - - logger.Log("terminated", <-errs) -} - -func accessControl(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") - w.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type") - - if r.Method == "OPTIONS" { - return - } - - h.ServeHTTP(w, r) - }) -} - -func envString(env, fallback string) string { - e := os.Getenv(env) - if e == "" { - return fallback - } - return e -} - -func storeTestData(r cargo.Repository) { - test1 := cargo.New("FTL456", cargo.RouteSpecification{ - Origin: location.AUMEL, - Destination: location.SESTO, - ArrivalDeadline: time.Now().AddDate(0, 0, 7), - }) - if err := r.Store(test1); err != nil { - panic(err) - } - - test2 := cargo.New("ABC123", cargo.RouteSpecification{ - Origin: location.SESTO, - Destination: location.CNHKG, - ArrivalDeadline: time.Now().AddDate(0, 0, 14), - }) - if err := r.Store(test2); err != nil { - panic(err) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go deleted file mode 100644 index 0c9150b1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go +++ /dev/null @@ -1,117 +0,0 @@ -package routing - -import ( - "context" - "encoding/json" - "net/http" - "net/url" - "time" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type proxyService struct { - context.Context - FetchRoutesEndpoint endpoint.Endpoint - Service -} - -func (s proxyService) FetchRoutesForSpecification(rs cargo.RouteSpecification) []cargo.Itinerary { - response, err := s.FetchRoutesEndpoint(s.Context, fetchRoutesRequest{ - From: string(rs.Origin), - To: string(rs.Destination), - }) - if err != nil { - return []cargo.Itinerary{} - } - - resp := response.(fetchRoutesResponse) - - var itineraries []cargo.Itinerary - for _, r := range resp.Paths { - var legs []cargo.Leg - for _, e := range r.Edges { - legs = append(legs, cargo.Leg{ - VoyageNumber: voyage.Number(e.Voyage), - LoadLocation: location.UNLocode(e.Origin), - UnloadLocation: location.UNLocode(e.Destination), - LoadTime: e.Departure, - UnloadTime: e.Arrival, - }) - } - - itineraries = append(itineraries, cargo.Itinerary{Legs: legs}) - } - - return itineraries -} - -// ServiceMiddleware defines a middleware for a routing service. -type ServiceMiddleware func(Service) Service - -// NewProxyingMiddleware returns a new instance of a proxying middleware. -func NewProxyingMiddleware(ctx context.Context, proxyURL string) ServiceMiddleware { - return func(next Service) Service { - var e endpoint.Endpoint - e = makeFetchRoutesEndpoint(ctx, proxyURL) - e = circuitbreaker.Hystrix("fetch-routes")(e) - return proxyService{ctx, e, next} - } -} - -type fetchRoutesRequest struct { - From string - To string -} - -type fetchRoutesResponse struct { - Paths []struct { - Edges []struct { - Origin string `json:"origin"` - Destination string `json:"destination"` - Voyage string `json:"voyage"` - Departure time.Time `json:"departure"` - Arrival time.Time `json:"arrival"` - } `json:"edges"` - } `json:"paths"` -} - -func makeFetchRoutesEndpoint(ctx context.Context, instance string) endpoint.Endpoint { - u, err := url.Parse(instance) - if err != nil { - panic(err) - } - if u.Path == "" { - u.Path = "/paths" - } - return kithttp.NewClient( - "GET", u, - encodeFetchRoutesRequest, - decodeFetchRoutesResponse, - ).Endpoint() -} - -func decodeFetchRoutesResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response fetchRoutesResponse - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func encodeFetchRoutesRequest(_ context.Context, r *http.Request, request interface{}) error { - req := request.(fetchRoutesRequest) - - vals := r.URL.Query() - vals.Add("from", req.From) - vals.Add("to", req.To) - r.URL.RawQuery = vals.Encode() - - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go deleted file mode 100644 index 50496f2b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go +++ /dev/null @@ -1,15 +0,0 @@ -// Package routing provides the routing domain service. It does not actually -// implement the routing service but merely acts as a proxy for a separate -// bounded context. -package routing - -import ( - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// Service provides access to an external routing service. -type Service interface { - // FetchRoutesForSpecification finds all possible routes that satisfy a - // given specification. - FetchRoutesForSpecification(rs cargo.RouteSpecification) []cargo.Itinerary -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go deleted file mode 100644 index ddb13172..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go +++ /dev/null @@ -1,26 +0,0 @@ -package tracking - -import ( - "context" - - "github.com/go-kit/kit/endpoint" -) - -type trackCargoRequest struct { - ID string -} - -type trackCargoResponse struct { - Cargo *Cargo `json:"cargo,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r trackCargoResponse) error() error { return r.Err } - -func makeTrackCargoEndpoint(ts Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(trackCargoRequest) - c, err := ts.Track(req.ID) - return trackCargoResponse{Cargo: &c, Err: err}, nil - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go deleted file mode 100644 index f5dc018b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go +++ /dev/null @@ -1,31 +0,0 @@ -package tracking - -import ( - "time" - - "github.com/go-kit/kit/metrics" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) Track(id string) (Cargo, error) { - defer func(begin time.Time) { - s.requestCount.With("method", "track").Add(1) - s.requestLatency.With("method", "track").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Track(id) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go deleted file mode 100644 index 584aeaa4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go +++ /dev/null @@ -1,24 +0,0 @@ -package tracking - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) Track(id string) (c Cargo, err error) { - defer func(begin time.Time) { - s.logger.Log("method", "track", "tracking_id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return s.Service.Track(id) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go deleted file mode 100644 index b0e360b2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go +++ /dev/null @@ -1,163 +0,0 @@ -// Package tracking provides the use-case of tracking a cargo. Used by views -// facing the end-user. -package tracking - -import ( - "errors" - "fmt" - "strings" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// Service is the interface that provides the basic Track method. -type Service interface { - // Track returns a cargo matching a tracking ID. - Track(id string) (Cargo, error) -} - -type service struct { - cargos cargo.Repository - handlingEvents cargo.HandlingEventRepository -} - -func (s *service) Track(id string) (Cargo, error) { - if id == "" { - return Cargo{}, ErrInvalidArgument - } - c, err := s.cargos.Find(cargo.TrackingID(id)) - if err != nil { - return Cargo{}, err - } - return assemble(c, s.handlingEvents), nil -} - -// NewService returns a new instance of the default Service. -func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository) Service { - return &service{ - cargos: cargos, - handlingEvents: events, - } -} - -// Cargo is a read model for tracking views. -type Cargo struct { - TrackingID string `json:"tracking_id"` - StatusText string `json:"status_text"` - Origin string `json:"origin"` - Destination string `json:"destination"` - ETA time.Time `json:"eta"` - NextExpectedActivity string `json:"next_expected_activity"` - ArrivalDeadline time.Time `json:"arrival_deadline"` - Events []Event `json:"events"` -} - -// Leg is a read model for booking views. -type Leg struct { - VoyageNumber string `json:"voyage_number"` - From string `json:"from"` - To string `json:"to"` - LoadTime time.Time `json:"load_time"` - UnloadTime time.Time `json:"unload_time"` -} - -// Event is a read model for tracking views. -type Event struct { - Description string `json:"description"` - Expected bool `json:"expected"` -} - -func assemble(c *cargo.Cargo, events cargo.HandlingEventRepository) Cargo { - return Cargo{ - TrackingID: string(c.TrackingID), - Origin: string(c.Origin), - Destination: string(c.RouteSpecification.Destination), - ETA: c.Delivery.ETA, - NextExpectedActivity: nextExpectedActivity(c), - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - StatusText: assembleStatusText(c), - Events: assembleEvents(c, events), - } -} - -func assembleLegs(c cargo.Cargo) []Leg { - var legs []Leg - for _, l := range c.Itinerary.Legs { - legs = append(legs, Leg{ - VoyageNumber: string(l.VoyageNumber), - From: string(l.LoadLocation), - To: string(l.UnloadLocation), - LoadTime: l.LoadTime, - UnloadTime: l.UnloadTime, - }) - } - return legs -} - -func nextExpectedActivity(c *cargo.Cargo) string { - a := c.Delivery.NextExpectedActivity - prefix := "Next expected activity is to" - - switch a.Type { - case cargo.Load: - return fmt.Sprintf("%s %s cargo onto voyage %s in %s.", prefix, strings.ToLower(a.Type.String()), a.VoyageNumber, a.Location) - case cargo.Unload: - return fmt.Sprintf("%s %s cargo off of voyage %s in %s.", prefix, strings.ToLower(a.Type.String()), a.VoyageNumber, a.Location) - case cargo.NotHandled: - return "There are currently no expected activities for this cargo." - } - - return fmt.Sprintf("%s %s cargo in %s.", prefix, strings.ToLower(a.Type.String()), a.Location) -} - -func assembleStatusText(c *cargo.Cargo) string { - switch c.Delivery.TransportStatus { - case cargo.NotReceived: - return "Not received" - case cargo.InPort: - return fmt.Sprintf("In port %s", c.Delivery.LastKnownLocation) - case cargo.OnboardCarrier: - return fmt.Sprintf("Onboard voyage %s", c.Delivery.CurrentVoyage) - case cargo.Claimed: - return "Claimed" - default: - return "Unknown" - } -} - -func assembleEvents(c *cargo.Cargo, handlingEvents cargo.HandlingEventRepository) []Event { - h := handlingEvents.QueryHandlingHistory(c.TrackingID) - - var events []Event - for _, e := range h.HandlingEvents { - var description string - - switch e.Activity.Type { - case cargo.NotHandled: - description = "Cargo has not yet been received." - case cargo.Receive: - description = fmt.Sprintf("Received in %s, at %s", e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Load: - description = fmt.Sprintf("Loaded onto voyage %s in %s, at %s.", e.Activity.VoyageNumber, e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Unload: - description = fmt.Sprintf("Unloaded off voyage %s in %s, at %s.", e.Activity.VoyageNumber, e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Claim: - description = fmt.Sprintf("Claimed in %s, at %s.", e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Customs: - description = fmt.Sprintf("Cleared customs in %s, at %s.", e.Activity.Location, time.Now().Format(time.RFC3339)) - default: - description = "[Unknown status]" - } - - events = append(events, Event{ - Description: description, - Expected: c.Itinerary.IsExpected(e), - }) - } - - return events -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go deleted file mode 100644 index 32db9716..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go +++ /dev/null @@ -1,74 +0,0 @@ -package tracking - -import ( - "context" - "encoding/json" - "errors" - "net/http" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// MakeHandler returns a handler for the tracking service. -func MakeHandler(ts Service, logger kitlog.Logger) http.Handler { - r := mux.NewRouter() - - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - trackCargoHandler := kithttp.NewServer( - makeTrackCargoEndpoint(ts), - decodeTrackCargoRequest, - encodeResponse, - opts..., - ) - - r.Handle("/tracking/v1/cargos/{id}", trackCargoHandler).Methods("GET") - - return r -} - -func decodeTrackCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errors.New("bad route") - } - return trackCargoRequest{ID: id}, nil -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go deleted file mode 100644 index 751f5885..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go +++ /dev/null @@ -1,40 +0,0 @@ -package voyage - -import "github.com/go-kit/kit/examples/shipping/location" - -// A set of sample voyages. -var ( - V100 = New("V100", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.CNHKG, ArrivalLocation: location.JNTKO}, - {DepartureLocation: location.JNTKO, ArrivalLocation: location.USNYC}, - }, - }) - - V300 = New("V300", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.JNTKO, ArrivalLocation: location.NLRTM}, - {DepartureLocation: location.NLRTM, ArrivalLocation: location.DEHAM}, - {DepartureLocation: location.DEHAM, ArrivalLocation: location.AUMEL}, - {DepartureLocation: location.AUMEL, ArrivalLocation: location.JNTKO}, - }, - }) - - V400 = New("V400", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.DEHAM, ArrivalLocation: location.SESTO}, - {DepartureLocation: location.SESTO, ArrivalLocation: location.FIHEL}, - {DepartureLocation: location.FIHEL, ArrivalLocation: location.DEHAM}, - }, - }) -) - -// These voyages are hard-coded into the current pathfinder. Make sure -// they exist. -var ( - V0100S = New("0100S", Schedule{[]CarrierMovement{}}) - V0200T = New("0200T", Schedule{[]CarrierMovement{}}) - V0300A = New("0300A", Schedule{[]CarrierMovement{}}) - V0301S = New("0301S", Schedule{[]CarrierMovement{}}) - V0400S = New("0400S", Schedule{[]CarrierMovement{}}) -) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go deleted file mode 100644 index 37366af4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go +++ /dev/null @@ -1,44 +0,0 @@ -// Package voyage provides the Voyage aggregate. -package voyage - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/location" -) - -// Number uniquely identifies a particular Voyage. -type Number string - -// Voyage is a uniquely identifiable series of carrier movements. -type Voyage struct { - Number Number - Schedule Schedule -} - -// New creates a voyage with a voyage number and a provided schedule. -func New(n Number, s Schedule) *Voyage { - return &Voyage{Number: n, Schedule: s} -} - -// Schedule describes a voyage schedule. -type Schedule struct { - CarrierMovements []CarrierMovement -} - -// CarrierMovement is a vessel voyage from one location to another. -type CarrierMovement struct { - DepartureLocation location.UNLocode - ArrivalLocation location.UNLocode - DepartureTime time.Time - ArrivalTime time.Time -} - -// ErrUnknown is used when a voyage could not be found. -var ErrUnknown = errors.New("unknown voyage") - -// Repository provides access a voyage store. -type Repository interface { - Find(Number) (*Voyage, error) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go deleted file mode 100644 index 8cbca37d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go +++ /dev/null @@ -1,115 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "log" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -// stringService is a concrete implementation of StringService -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// For each method, we define request and response structs -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} - -// Endpoints are a primary abstraction in go-kit. An endpoint represents a single RPC (method in our service interface) -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -// Transports expose the service to the network. In this first example we utilize JSON over HTTP. -func main() { - svc := stringService{} - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go deleted file mode 100644 index 675617d9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/go-kit/kit/metrics" -) - -type instrumentingMiddleware struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - countResult metrics.Histogram - next StringService -} - -func (mw instrumentingMiddleware) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - }(time.Now()) - - output, err = mw.next.Uppercase(s) - return -} - -func (mw instrumentingMiddleware) Count(s string) (n int) { - defer func(begin time.Time) { - lvs := []string{"method", "count", "error", "false"} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - mw.countResult.Observe(float64(n)) - }(time.Now()) - - n = mw.next.Count(s) - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go deleted file mode 100644 index b958f3b6..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -type loggingMiddleware struct { - logger log.Logger - next StringService -} - -func (mw loggingMiddleware) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "uppercase", - "input", s, - "output", output, - "err", err, - "took", time.Since(begin), - ) - }(time.Now()) - - output, err = mw.next.Uppercase(s) - return -} - -func (mw loggingMiddleware) Count(s string) (n int) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "count", - "input", s, - "n", n, - "took", time.Since(begin), - ) - }(time.Now()) - - n = mw.next.Count(s) - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go deleted file mode 100644 index 60544f27..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "net/http" - "os" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - httptransport "github.com/go-kit/kit/transport/http" -) - -func main() { - logger := log.NewLogfmtLogger(os.Stderr) - - fieldKeys := []string{"method", "error"} - requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys) - requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys) - countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "count_result", - Help: "The result of each count method.", - }, []string{}) // no fields here - - var svc StringService - svc = stringService{} - svc = loggingMiddleware{logger, svc} - svc = instrumentingMiddleware{requestCount, requestLatency, countResult, svc} - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - http.Handle("/metrics", promhttp.Handler()) - logger.Log("msg", "HTTP", "addr", ":8080") - logger.Log("err", http.ListenAndServe(":8080", nil)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go deleted file mode 100644 index 1da2f3eb..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "errors" - "strings" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go deleted file mode 100644 index 3e892a9c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/go-kit/kit/endpoint" -) - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go deleted file mode 100644 index b21c016c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/go-kit/kit/metrics" -) - -func instrumentingMiddleware( - requestCount metrics.Counter, - requestLatency metrics.Histogram, - countResult metrics.Histogram, -) ServiceMiddleware { - return func(next StringService) StringService { - return instrmw{requestCount, requestLatency, countResult, next} - } -} - -type instrmw struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - countResult metrics.Histogram - StringService -} - -func (mw instrmw) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - }(time.Now()) - - output, err = mw.StringService.Uppercase(s) - return -} - -func (mw instrmw) Count(s string) (n int) { - defer func(begin time.Time) { - lvs := []string{"method", "count", "error", "false"} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - mw.countResult.Observe(float64(n)) - }(time.Now()) - - n = mw.StringService.Count(s) - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go deleted file mode 100644 index 72a2709d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -func loggingMiddleware(logger log.Logger) ServiceMiddleware { - return func(next StringService) StringService { - return logmw{logger, next} - } -} - -type logmw struct { - logger log.Logger - StringService -} - -func (mw logmw) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "uppercase", - "input", s, - "output", output, - "err", err, - "took", time.Since(begin), - ) - }(time.Now()) - - output, err = mw.StringService.Uppercase(s) - return -} - -func (mw logmw) Count(s string) (n int) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "count", - "input", s, - "n", n, - "took", time.Since(begin), - ) - }(time.Now()) - - n = mw.StringService.Count(s) - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go deleted file mode 100644 index 5cdb43b1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "context" - "flag" - "net/http" - "os" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - httptransport "github.com/go-kit/kit/transport/http" -) - -func main() { - var ( - listen = flag.String("listen", ":8080", "HTTP listen address") - proxy = flag.String("proxy", "", "Optional comma-separated list of URLs to proxy uppercase requests") - ) - flag.Parse() - - var logger log.Logger - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "listen", *listen, "caller", log.DefaultCaller) - - fieldKeys := []string{"method", "error"} - requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys) - requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys) - countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "count_result", - Help: "The result of each count method.", - }, []string{}) - - var svc StringService - svc = stringService{} - svc = proxyingMiddleware(context.Background(), *proxy, logger)(svc) - svc = loggingMiddleware(logger)(svc) - svc = instrumentingMiddleware(requestCount, requestLatency, countResult)(svc) - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - http.Handle("/metrics", promhttp.Handler()) - logger.Log("msg", "HTTP", "addr", *listen) - logger.Log("err", http.ListenAndServe(*listen, nil)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go deleted file mode 100644 index 0f678077..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go +++ /dev/null @@ -1,117 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/lb" - httptransport "github.com/go-kit/kit/transport/http" -) - -func proxyingMiddleware(ctx context.Context, instances string, logger log.Logger) ServiceMiddleware { - // If instances is empty, don't proxy. - if instances == "" { - logger.Log("proxy_to", "none") - return func(next StringService) StringService { return next } - } - - // Set some parameters for our client. - var ( - qps = 100 // beyond which we will return an error - maxAttempts = 3 // per request, before giving up - maxTime = 250 * time.Millisecond // wallclock time, before giving up - ) - - // Otherwise, construct an endpoint for each instance in the list, and add - // it to a fixed set of endpoints. In a real service, rather than doing this - // by hand, you'd probably use package sd's support for your service - // discovery system. - var ( - instanceList = split(instances) - endpointer sd.FixedEndpointer - ) - logger.Log("proxy_to", fmt.Sprint(instanceList)) - for _, instance := range instanceList { - var e endpoint.Endpoint - e = makeUppercaseProxy(ctx, instance) - e = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(e) - e = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), qps))(e) - endpointer = append(endpointer, e) - } - - // Now, build a single, retrying, load-balancing endpoint out of all of - // those individual endpoints. - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(maxAttempts, maxTime, balancer) - - // And finally, return the ServiceMiddleware, implemented by proxymw. - return func(next StringService) StringService { - return proxymw{ctx, next, retry} - } -} - -// proxymw implements StringService, forwarding Uppercase requests to the -// provided endpoint, and serving all other (i.e. Count) requests via the -// next StringService. -type proxymw struct { - ctx context.Context - next StringService // Serve most requests via this service... - uppercase endpoint.Endpoint // ...except Uppercase, which gets served by this endpoint -} - -func (mw proxymw) Count(s string) int { - return mw.next.Count(s) -} - -func (mw proxymw) Uppercase(s string) (string, error) { - response, err := mw.uppercase(mw.ctx, uppercaseRequest{S: s}) - if err != nil { - return "", err - } - - resp := response.(uppercaseResponse) - if resp.Err != "" { - return resp.V, errors.New(resp.Err) - } - return resp.V, nil -} - -func makeUppercaseProxy(ctx context.Context, instance string) endpoint.Endpoint { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - panic(err) - } - if u.Path == "" { - u.Path = "/uppercase" - } - return httptransport.NewClient( - "GET", - u, - encodeRequest, - decodeUppercaseResponse, - ).Endpoint() -} - -func split(s string) []string { - a := strings.Split(s, ",") - for i := range a { - a[i] = strings.TrimSpace(a[i]) - } - return a -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go deleted file mode 100644 index 7e1773a9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "errors" - "strings" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// ServiceMiddleware is a chainable behavior modifier for StringService. -type ServiceMiddleware func(StringService) StringService diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go deleted file mode 100644 index c17a055c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "bytes" - "context" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/go-kit/kit/endpoint" -) - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeUppercaseResponse(_ context.Context, r *http.Response) (interface{}, error) { - var response uppercaseResponse - if err := json.NewDecoder(r.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -func encodeRequest(_ context.Context, r *http.Request, request interface{}) error { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - r.Body = ioutil.NopCloser(&buf) - return nil -} - -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go deleted file mode 100644 index c6447079..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go +++ /dev/null @@ -1,206 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "log" - "strings" - "flag" - "net/http" - - "github.com/go-kit/kit/endpoint" - natstransport "github.com/go-kit/kit/transport/nats" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/nats-io/go-nats" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(context.Context, string) (string, error) - Count(context.Context, string) int -} - -// stringService is a concrete implementation of StringService -type stringService struct{} - -func (stringService) Uppercase(_ context.Context, s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(_ context.Context, s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// For each method, we define request and response structs -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} - -// Endpoints are a primary abstraction in go-kit. An endpoint represents a single RPC (method in our service interface) -func makeUppercaseHTTPEndpoint(nc *nats.Conn) endpoint.Endpoint { - return natstransport.NewPublisher( - nc, - "stringsvc.uppercase", - natstransport.EncodeJSONRequest, - decodeUppercaseResponse, - ).Endpoint() -} - -func makeCountHTTPEndpoint(nc *nats.Conn) endpoint.Endpoint { - return natstransport.NewPublisher( - nc, - "stringsvc.count", - natstransport.EncodeJSONRequest, - decodeCountResponse, - ).Endpoint() -} - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(ctx, req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(ctx, req.S) - return countResponse{v}, nil - } -} - -// Transports expose the service to the network. In this fourth example we utilize JSON over NATS and HTTP. -func main() { - svc := stringService{} - - natsURL := flag.String("nats-url", nats.DefaultURL, "URL for connection to NATS") - flag.Parse() - - nc, err := nats.Connect(*natsURL) - if err != nil { - log.Fatal(err) - } - defer nc.Close() - - uppercaseHTTPHandler := httptransport.NewServer( - makeUppercaseHTTPEndpoint(nc), - decodeUppercaseHTTPRequest, - httptransport.EncodeJSONResponse, - ) - - countHTTPHandler := httptransport.NewServer( - makeCountHTTPEndpoint(nc), - decodeCountHTTPRequest, - httptransport.EncodeJSONResponse, - ) - - uppercaseHandler := natstransport.NewSubscriber( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - natstransport.EncodeJSONResponse, - ) - - countHandler := natstransport.NewSubscriber( - makeCountEndpoint(svc), - decodeCountRequest, - natstransport.EncodeJSONResponse, - ) - - uSub, err := nc.QueueSubscribe("stringsvc.uppercase", "stringsvc", uppercaseHandler.ServeMsg(nc)) - if err != nil { - log.Fatal(err) - } - defer uSub.Unsubscribe() - - cSub, err := nc.QueueSubscribe("stringsvc.count", "stringsvc", countHandler.ServeMsg(nc)) - if err != nil { - log.Fatal(err) - } - defer cSub.Unsubscribe() - - http.Handle("/uppercase", uppercaseHTTPHandler) - http.Handle("/count", countHTTPHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) - -} - -func decodeUppercaseHTTPRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountHTTPRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeUppercaseResponse(_ context.Context, msg *nats.Msg) (interface{}, error) { - var response uppercaseResponse - - if err := json.Unmarshal(msg.Data, &response); err != nil { - return nil, err - } - - return response, nil -} - -func decodeCountResponse(_ context.Context, msg *nats.Msg) (interface{}, error) { - var response countResponse - - if err := json.Unmarshal(msg.Data, &response); err != nil { - return nil, err - } - - return response, nil -} - -func decodeUppercaseRequest(_ context.Context, msg *nats.Msg) (interface{}, error) { - var request uppercaseRequest - - if err := json.Unmarshal(msg.Data, &request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, msg *nats.Msg) (interface{}, error) { - var request countRequest - - if err := json.Unmarshal(msg.Data, &request); err != nil { - return nil, err - } - return request, nil -} - diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint deleted file mode 100755 index 12e30727..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -if [ ! $(command -v gometalinter) ] -then - go get github.com/alecthomas/gometalinter - gometalinter --update --install -fi - -time gometalinter \ - --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ - --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ - --exclude='/thrift/' \ - --exclude='/pb/' \ - --exclude='no args in Log call \(vet\)' \ - --disable=dupl \ - --disable=aligncheck \ - --disable=gotype \ - --cyclo-over=20 \ - --tests \ - --concurrency=2 \ - --deadline=300s \ - ./... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md deleted file mode 100644 index 7222f800..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md +++ /dev/null @@ -1,147 +0,0 @@ -# package log - -`package log` provides a minimal interface for structured logging in services. -It may be wrapped to encode conventions, enforce type-safety, provide leveled -logging, and so on. It can be used for both typical application log events, -and log-structured data streams. - -## Structured logging - -Structured logging is, basically, conceding to the reality that logs are -_data_, and warrant some level of schematic rigor. Using a stricter, -key/value-oriented message format for our logs, containing contextual and -semantic information, makes it much easier to get insight into the -operational activity of the systems we build. Consequently, `package log` is -of the strong belief that "[the benefits of structured logging outweigh the -minimal effort involved](https://www.thoughtworks.com/radar/techniques/structured-logging)". - -Migrating from unstructured to structured logging is probably a lot easier -than you'd expect. - -```go -// Unstructured -log.Printf("HTTP server listening on %s", addr) - -// Structured -logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") -``` - -## Usage - -### Typical application logging - -```go -w := log.NewSyncWriter(os.Stderr) -logger := log.NewLogfmtLogger(w) -logger.Log("question", "what is the meaning of life?", "answer", 42) - -// Output: -// question="what is the meaning of life?" answer=42 -``` - -### Contextual Loggers - -```go -func main() { - var logger log.Logger - logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - logger = log.With(logger, "instance_id", 123) - - logger.Log("msg", "starting") - NewWorker(log.With(logger, "component", "worker")).Run() - NewSlacker(log.With(logger, "component", "slacker")).Run() -} - -// Output: -// instance_id=123 msg=starting -// instance_id=123 component=worker msg=running -// instance_id=123 component=slacker msg=running -``` - -### Interact with stdlib logger - -Redirect stdlib logger to Go kit logger. - -```go -import ( - "os" - stdlog "log" - kitlog "github.com/go-kit/kit/log" -) - -func main() { - logger := kitlog.NewJSONLogger(kitlog.NewSyncWriter(os.Stdout)) - stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) - stdlog.Print("I sure like pie") -} - -// Output: -// {"msg":"I sure like pie","ts":"2016/01/01 12:34:56"} -``` - -Or, if, for legacy reasons, you need to pipe all of your logging through the -stdlib log package, you can redirect Go kit logger to the stdlib logger. - -```go -logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{}) -logger.Log("legacy", true, "msg", "at least it's something") - -// Output: -// 2016/01/01 12:34:56 legacy=true msg="at least it's something" -``` - -### Timestamps and callers - -```go -var logger log.Logger -logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) -logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) - -logger.Log("msg", "hello") - -// Output: -// ts=2016-01-01T12:34:56Z caller=main.go:15 msg=hello -``` - -## Supported output formats - -- [Logfmt](https://brandur.org/logfmt) ([see also](https://blog.codeship.com/logfmt-a-log-format-thats-easy-to-read-and-write)) -- JSON - -## Enhancements - -`package log` is centered on the one-method Logger interface. - -```go -type Logger interface { - Log(keyvals ...interface{}) error -} -``` - -This interface, and its supporting code like is the product of much iteration -and evaluation. For more details on the evolution of the Logger interface, -see [The Hunt for a Logger Interface](http://go-talks.appspot.com/github.com/ChrisHines/talks/structured-logging/structured-logging.slide#1), -a talk by [Chris Hines](https://github.com/ChrisHines). -Also, please see -[#63](https://github.com/go-kit/kit/issues/63), -[#76](https://github.com/go-kit/kit/pull/76), -[#131](https://github.com/go-kit/kit/issues/131), -[#157](https://github.com/go-kit/kit/pull/157), -[#164](https://github.com/go-kit/kit/issues/164), and -[#252](https://github.com/go-kit/kit/pull/252) -to review historical conversations about package log and the Logger interface. - -Value-add packages and suggestions, -like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/kit/log/level), -are of course welcome. Good proposals should - -- Be composable with [contextual loggers](https://godoc.org/github.com/go-kit/kit/log#With), -- Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/kit/log#Caller) in any wrapped contextual loggers, and -- Be friendly to packages that accept only an unadorned log.Logger. - -## Benchmarks & comparisons - -There are a few Go logging benchmarks and comparisons that include Go kit's package log. - -- [imkira/go-loggers-bench](https://github.com/imkira/go-loggers-bench) includes kit/log -- [uber-common/zap](https://github.com/uber-common/zap), a zero-alloc logging library, includes a comparison with kit/log diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go deleted file mode 100644 index a0342127..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go +++ /dev/null @@ -1,127 +0,0 @@ -package levels - -import "github.com/go-kit/kit/log" - -// Levels provides a leveled logging wrapper around a logger. It has five -// levels: debug, info, warning (warn), error, and critical (crit). If you -// want a different set of levels, you can create your own levels type very -// easily, and you can elide the configuration. -type Levels struct { - logger log.Logger - levelKey string - - // We have a choice between storing level values in string fields or - // making a separate context for each level. When using string fields the - // Log method must combine the base context, the level data, and the - // logged keyvals; but the With method only requires updating one context. - // If we instead keep a separate context for each level the Log method - // must only append the new keyvals; but the With method would have to - // update all five contexts. - - // Roughly speaking, storing multiple contexts breaks even if the ratio of - // Log/With calls is more than the number of levels. We have chosen to - // make the With method cheap and the Log method a bit more costly because - // we do not expect most applications to Log more than five times for each - // call to With. - - debugValue string - infoValue string - warnValue string - errorValue string - critValue string -} - -// New creates a new leveled logger, wrapping the passed logger. -func New(logger log.Logger, options ...Option) Levels { - l := Levels{ - logger: logger, - levelKey: "level", - - debugValue: "debug", - infoValue: "info", - warnValue: "warn", - errorValue: "error", - critValue: "crit", - } - for _, option := range options { - option(&l) - } - return l -} - -// With returns a new leveled logger that includes keyvals in all log events. -func (l Levels) With(keyvals ...interface{}) Levels { - return Levels{ - logger: log.With(l.logger, keyvals...), - levelKey: l.levelKey, - debugValue: l.debugValue, - infoValue: l.infoValue, - warnValue: l.warnValue, - errorValue: l.errorValue, - critValue: l.critValue, - } -} - -// Debug returns a debug level logger. -func (l Levels) Debug() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.debugValue) -} - -// Info returns an info level logger. -func (l Levels) Info() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.infoValue) -} - -// Warn returns a warning level logger. -func (l Levels) Warn() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.warnValue) -} - -// Error returns an error level logger. -func (l Levels) Error() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.errorValue) -} - -// Crit returns a critical level logger. -func (l Levels) Crit() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.critValue) -} - -// Option sets a parameter for leveled loggers. -type Option func(*Levels) - -// Key sets the key for the field used to indicate log level. By default, -// the key is "level". -func Key(key string) Option { - return func(l *Levels) { l.levelKey = key } -} - -// DebugValue sets the value for the field used to indicate the debug log -// level. By default, the value is "debug". -func DebugValue(value string) Option { - return func(l *Levels) { l.debugValue = value } -} - -// InfoValue sets the value for the field used to indicate the info log level. -// By default, the value is "info". -func InfoValue(value string) Option { - return func(l *Levels) { l.infoValue = value } -} - -// WarnValue sets the value for the field used to indicate the warning log -// level. By default, the value is "warn". -func WarnValue(value string) Option { - return func(l *Levels) { l.warnValue = value } -} - -// ErrorValue sets the value for the field used to indicate the error log -// level. By default, the value is "error". -func ErrorValue(value string) Option { - return func(l *Levels) { l.errorValue = value } -} - -// CritValue sets the value for the field used to indicate the critical log -// level. By default, the value is "crit". -func CritValue(value string) Option { - return func(l *Levels) { l.critValue = value } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go deleted file mode 100644 index 918c0af4..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go +++ /dev/null @@ -1,116 +0,0 @@ -// Package log provides a structured logger. -// -// Structured logging produces logs easily consumed later by humans or -// machines. Humans might be interested in debugging errors, or tracing -// specific requests. Machines might be interested in counting interesting -// events, or aggregating information for off-line processing. In both cases, -// it is important that the log messages are structured and actionable. -// Package log is designed to encourage both of these best practices. -// -// Basic Usage -// -// The fundamental interface is Logger. Loggers create log events from -// key/value data. The Logger interface has a single method, Log, which -// accepts a sequence of alternating key/value pairs, which this package names -// keyvals. -// -// type Logger interface { -// Log(keyvals ...interface{}) error -// } -// -// Here is an example of a function using a Logger to create log events. -// -// func RunTask(task Task, logger log.Logger) string { -// logger.Log("taskID", task.ID, "event", "starting task") -// ... -// logger.Log("taskID", task.ID, "event", "task complete") -// } -// -// The keys in the above example are "taskID" and "event". The values are -// task.ID, "starting task", and "task complete". Every key is followed -// immediately by its value. -// -// Keys are usually plain strings. Values may be any type that has a sensible -// encoding in the chosen log format. With structured logging it is a good -// idea to log simple values without formatting them. This practice allows -// the chosen logger to encode values in the most appropriate way. -// -// Contextual Loggers -// -// A contextual logger stores keyvals that it includes in all log events. -// Building appropriate contextual loggers reduces repetition and aids -// consistency in the resulting log output. With and WithPrefix add context to -// a logger. We can use With to improve the RunTask example. -// -// func RunTask(task Task, logger log.Logger) string { -// logger = log.With(logger, "taskID", task.ID) -// logger.Log("event", "starting task") -// ... -// taskHelper(task.Cmd, logger) -// ... -// logger.Log("event", "task complete") -// } -// -// The improved version emits the same log events as the original for the -// first and last calls to Log. Passing the contextual logger to taskHelper -// enables each log event created by taskHelper to include the task.ID even -// though taskHelper does not have access to that value. Using contextual -// loggers this way simplifies producing log output that enables tracing the -// life cycle of individual tasks. (See the Contextual example for the full -// code of the above snippet.) -// -// Dynamic Contextual Values -// -// A Valuer function stored in a contextual logger generates a new value each -// time an event is logged. The Valuer example demonstrates how this feature -// works. -// -// Valuers provide the basis for consistently logging timestamps and source -// code location. The log package defines several valuers for that purpose. -// See Timestamp, DefaultTimestamp, DefaultTimestampUTC, Caller, and -// DefaultCaller. A common logger initialization sequence that ensures all log -// entries contain a timestamp and source location looks like this: -// -// logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) -// logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) -// -// Concurrent Safety -// -// Applications with multiple goroutines want each log event written to the -// same logger to remain separate from other log events. Package log provides -// two simple solutions for concurrent safe logging. -// -// NewSyncWriter wraps an io.Writer and serializes each call to its Write -// method. Using a SyncWriter has the benefit that the smallest practical -// portion of the logging logic is performed within a mutex, but it requires -// the formatting Logger to make only one call to Write per log event. -// -// NewSyncLogger wraps any Logger and serializes each call to its Log method. -// Using a SyncLogger has the benefit that it guarantees each log event is -// handled atomically within the wrapped logger, but it typically serializes -// both the formatting and output logic. Use a SyncLogger if the formatting -// logger may perform multiple writes per log event. -// -// Error Handling -// -// This package relies on the practice of wrapping or decorating loggers with -// other loggers to provide composable pieces of functionality. It also means -// that Logger.Log must return an error because some -// implementations—especially those that output log data to an io.Writer—may -// encounter errors that cannot be handled locally. This in turn means that -// Loggers that wrap other loggers should return errors from the wrapped -// logger up the stack. -// -// Fortunately, the decorator pattern also provides a way to avoid the -// necessity to check for errors every time an application calls Logger.Log. -// An application required to panic whenever its Logger encounters -// an error could initialize its logger as follows. -// -// fmtlogger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) -// logger := log.LoggerFunc(func(keyvals ...interface{}) error { -// if err := fmtlogger.Log(keyvals...); err != nil { -// panic(err) -// } -// return nil -// }) -package log diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go deleted file mode 100644 index 66094b4d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go +++ /dev/null @@ -1,89 +0,0 @@ -package log - -import ( - "encoding" - "encoding/json" - "fmt" - "io" - "reflect" -) - -type jsonLogger struct { - io.Writer -} - -// NewJSONLogger returns a Logger that encodes keyvals to the Writer as a -// single JSON object. Each log event produces no more than one call to -// w.Write. The passed Writer must be safe for concurrent use by multiple -// goroutines if the returned Logger will be used concurrently. -func NewJSONLogger(w io.Writer) Logger { - return &jsonLogger{w} -} - -func (l *jsonLogger) Log(keyvals ...interface{}) error { - n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd - m := make(map[string]interface{}, n) - for i := 0; i < len(keyvals); i += 2 { - k := keyvals[i] - var v interface{} = ErrMissingValue - if i+1 < len(keyvals) { - v = keyvals[i+1] - } - merge(m, k, v) - } - return json.NewEncoder(l.Writer).Encode(m) -} - -func merge(dst map[string]interface{}, k, v interface{}) { - var key string - switch x := k.(type) { - case string: - key = x - case fmt.Stringer: - key = safeString(x) - default: - key = fmt.Sprint(x) - } - - // We want json.Marshaler and encoding.TextMarshaller to take priority over - // err.Error() and v.String(). But json.Marshall (called later) does that by - // default so we force a no-op if it's one of those 2 case. - switch x := v.(type) { - case json.Marshaler: - case encoding.TextMarshaler: - case error: - v = safeError(x) - case fmt.Stringer: - v = safeString(x) - } - - dst[key] = v -} - -func safeString(str fmt.Stringer) (s string) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { - s = "NULL" - } else { - panic(panicVal) - } - } - }() - s = str.String() - return -} - -func safeError(err error) (s interface{}) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { - s = nil - } else { - panic(panicVal) - } - } - }() - s = err.Error() - return -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go deleted file mode 100644 index 505d307b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go +++ /dev/null @@ -1,22 +0,0 @@ -// Package level implements leveled logging on top of Go kit's log package. To -// use the level package, create a logger as per normal in your func main, and -// wrap it with level.NewFilter. -// -// var logger log.Logger -// logger = log.NewLogfmtLogger(os.Stderr) -// logger = level.NewFilter(logger, level.AllowInfo()) // <-- -// logger = log.With(logger, "ts", log.DefaultTimestampUTC) -// -// Then, at the callsites, use one of the level.Debug, Info, Warn, or Error -// helper methods to emit leveled log events. -// -// logger.Log("foo", "bar") // as normal, no level -// level.Debug(logger).Log("request_id", reqID, "trace_data", trace.Get()) -// if value > 100 { -// level.Error(logger).Log("value", value) -// } -// -// NewFilter allows precise control over what happens when a log event is -// emitted without a level key, or if a squelched level is used. Check the -// Option functions for details. -package level diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go deleted file mode 100644 index fceafc45..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go +++ /dev/null @@ -1,205 +0,0 @@ -package level - -import "github.com/go-kit/kit/log" - -// Error returns a logger that includes a Key/ErrorValue pair. -func Error(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), ErrorValue()) -} - -// Warn returns a logger that includes a Key/WarnValue pair. -func Warn(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), WarnValue()) -} - -// Info returns a logger that includes a Key/InfoValue pair. -func Info(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), InfoValue()) -} - -// Debug returns a logger that includes a Key/DebugValue pair. -func Debug(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), DebugValue()) -} - -// NewFilter wraps next and implements level filtering. See the commentary on -// the Option functions for a detailed description of how to configure levels. -// If no options are provided, all leveled log events created with Debug, -// Info, Warn or Error helper methods are squelched and non-leveled log -// events are passed to next unmodified. -func NewFilter(next log.Logger, options ...Option) log.Logger { - l := &logger{ - next: next, - } - for _, option := range options { - option(l) - } - return l -} - -type logger struct { - next log.Logger - allowed level - squelchNoLevel bool - errNotAllowed error - errNoLevel error -} - -func (l *logger) Log(keyvals ...interface{}) error { - var hasLevel, levelAllowed bool - for i := 1; i < len(keyvals); i += 2 { - if v, ok := keyvals[i].(*levelValue); ok { - hasLevel = true - levelAllowed = l.allowed&v.level != 0 - break - } - } - if !hasLevel && l.squelchNoLevel { - return l.errNoLevel - } - if hasLevel && !levelAllowed { - return l.errNotAllowed - } - return l.next.Log(keyvals...) -} - -// Option sets a parameter for the leveled logger. -type Option func(*logger) - -// AllowAll is an alias for AllowDebug. -func AllowAll() Option { - return AllowDebug() -} - -// AllowDebug allows error, warn, info and debug level log events to pass. -func AllowDebug() Option { - return allowed(levelError | levelWarn | levelInfo | levelDebug) -} - -// AllowInfo allows error, warn and info level log events to pass. -func AllowInfo() Option { - return allowed(levelError | levelWarn | levelInfo) -} - -// AllowWarn allows error and warn level log events to pass. -func AllowWarn() Option { - return allowed(levelError | levelWarn) -} - -// AllowError allows only error level log events to pass. -func AllowError() Option { - return allowed(levelError) -} - -// AllowNone allows no leveled log events to pass. -func AllowNone() Option { - return allowed(0) -} - -func allowed(allowed level) Option { - return func(l *logger) { l.allowed = allowed } -} - -// ErrNotAllowed sets the error to return from Log when it squelches a log -// event disallowed by the configured Allow[Level] option. By default, -// ErrNotAllowed is nil; in this case the log event is squelched with no -// error. -func ErrNotAllowed(err error) Option { - return func(l *logger) { l.errNotAllowed = err } -} - -// SquelchNoLevel instructs Log to squelch log events with no level, so that -// they don't proceed through to the wrapped logger. If SquelchNoLevel is set -// to true and a log event is squelched in this way, the error value -// configured with ErrNoLevel is returned to the caller. -func SquelchNoLevel(squelch bool) Option { - return func(l *logger) { l.squelchNoLevel = squelch } -} - -// ErrNoLevel sets the error to return from Log when it squelches a log event -// with no level. By default, ErrNoLevel is nil; in this case the log event is -// squelched with no error. -func ErrNoLevel(err error) Option { - return func(l *logger) { l.errNoLevel = err } -} - -// NewInjector wraps next and returns a logger that adds a Key/level pair to -// the beginning of log events that don't already contain a level. In effect, -// this gives a default level to logs without a level. -func NewInjector(next log.Logger, level Value) log.Logger { - return &injector{ - next: next, - level: level, - } -} - -type injector struct { - next log.Logger - level interface{} -} - -func (l *injector) Log(keyvals ...interface{}) error { - for i := 1; i < len(keyvals); i += 2 { - if _, ok := keyvals[i].(*levelValue); ok { - return l.next.Log(keyvals...) - } - } - kvs := make([]interface{}, len(keyvals)+2) - kvs[0], kvs[1] = key, l.level - copy(kvs[2:], keyvals) - return l.next.Log(kvs...) -} - -// Value is the interface that each of the canonical level values implement. -// It contains unexported methods that prevent types from other packages from -// implementing it and guaranteeing that NewFilter can distinguish the levels -// defined in this package from all other values. -type Value interface { - String() string - levelVal() -} - -// Key returns the unique key added to log events by the loggers in this -// package. -func Key() interface{} { return key } - -// ErrorValue returns the unique value added to log events by Error. -func ErrorValue() Value { return errorValue } - -// WarnValue returns the unique value added to log events by Warn. -func WarnValue() Value { return warnValue } - -// InfoValue returns the unique value added to log events by Info. -func InfoValue() Value { return infoValue } - -// DebugValue returns the unique value added to log events by Warn. -func DebugValue() Value { return debugValue } - -var ( - // key is of type interface{} so that it allocates once during package - // initialization and avoids allocating every time the value is added to a - // []interface{} later. - key interface{} = "level" - - errorValue = &levelValue{level: levelError, name: "error"} - warnValue = &levelValue{level: levelWarn, name: "warn"} - infoValue = &levelValue{level: levelInfo, name: "info"} - debugValue = &levelValue{level: levelDebug, name: "debug"} -) - -type level byte - -const ( - levelDebug level = 1 << iota - levelInfo - levelWarn - levelError -) - -type levelValue struct { - name string - level -} - -func (v *levelValue) String() string { return v.name } -func (v *levelValue) levelVal() {} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go deleted file mode 100644 index 66a9e2fd..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go +++ /dev/null @@ -1,135 +0,0 @@ -package log - -import "errors" - -// Logger is the fundamental interface for all log operations. Log creates a -// log event from keyvals, a variadic sequence of alternating keys and values. -// Implementations must be safe for concurrent use by multiple goroutines. In -// particular, any implementation of Logger that appends to keyvals or -// modifies or retains any of its elements must make a copy first. -type Logger interface { - Log(keyvals ...interface{}) error -} - -// ErrMissingValue is appended to keyvals slices with odd length to substitute -// the missing value. -var ErrMissingValue = errors.New("(MISSING)") - -// With returns a new contextual logger with keyvals prepended to those passed -// to calls to Log. If logger is also a contextual logger created by With or -// WithPrefix, keyvals is appended to the existing context. -// -// The returned Logger replaces all value elements (odd indexes) containing a -// Valuer with their generated value for each call to its Log method. -func With(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - return &context{ - logger: l.logger, - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - keyvals: kvs[:len(kvs):len(kvs)], - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// WithPrefix returns a new contextual logger with keyvals prepended to those -// passed to calls to Log. If logger is also a contextual logger created by -// With or WithPrefix, keyvals is prepended to the existing context. -// -// The returned Logger replaces all value elements (odd indexes) containing a -// Valuer with their generated value for each call to its Log method. -func WithPrefix(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - n := len(l.keyvals) + len(keyvals) - if len(keyvals)%2 != 0 { - n++ - } - kvs := make([]interface{}, 0, n) - kvs = append(kvs, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - kvs = append(kvs, l.keyvals...) - return &context{ - logger: l.logger, - keyvals: kvs, - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// context is the Logger implementation returned by With and WithPrefix. It -// wraps a Logger and holds keyvals that it includes in all log events. Its -// Log method calls bindValues to generate values for each Valuer in the -// context keyvals. -// -// A context must always have the same number of stack frames between calls to -// its Log method and the eventual binding of Valuers to their value. This -// requirement comes from the functional requirement to allow a context to -// resolve application call site information for a Caller stored in the -// context. To do this we must be able to predict the number of logging -// functions on the stack when bindValues is called. -// -// Two implementation details provide the needed stack depth consistency. -// -// 1. newContext avoids introducing an additional layer when asked to -// wrap another context. -// 2. With and WithPrefix avoid introducing an additional layer by -// returning a newly constructed context with a merged keyvals rather -// than simply wrapping the existing context. -type context struct { - logger Logger - keyvals []interface{} - hasValuer bool -} - -func newContext(logger Logger) *context { - if c, ok := logger.(*context); ok { - return c - } - return &context{logger: logger} -} - -// Log replaces all value elements (odd indexes) containing a Valuer in the -// stored context with their generated value, appends keyvals, and passes the -// result to the wrapped Logger. -func (l *context) Log(keyvals ...interface{}) error { - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - if l.hasValuer { - // If no keyvals were appended above then we must copy l.keyvals so - // that future log events will reevaluate the stored Valuers. - if len(keyvals) == 0 { - kvs = append([]interface{}{}, l.keyvals...) - } - bindValues(kvs[:len(l.keyvals)]) - } - return l.logger.Log(kvs...) -} - -// LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If -// f is a function with the appropriate signature, LoggerFunc(f) is a Logger -// object that calls f. -type LoggerFunc func(...interface{}) error - -// Log implements Logger by calling f(keyvals...). -func (f LoggerFunc) Log(keyvals ...interface{}) error { - return f(keyvals...) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go deleted file mode 100644 index a0030529..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go +++ /dev/null @@ -1,62 +0,0 @@ -package log - -import ( - "bytes" - "io" - "sync" - - "github.com/go-logfmt/logfmt" -) - -type logfmtEncoder struct { - *logfmt.Encoder - buf bytes.Buffer -} - -func (l *logfmtEncoder) Reset() { - l.Encoder.Reset() - l.buf.Reset() -} - -var logfmtEncoderPool = sync.Pool{ - New: func() interface{} { - var enc logfmtEncoder - enc.Encoder = logfmt.NewEncoder(&enc.buf) - return &enc - }, -} - -type logfmtLogger struct { - w io.Writer -} - -// NewLogfmtLogger returns a logger that encodes keyvals to the Writer in -// logfmt format. Each log event produces no more than one call to w.Write. -// The passed Writer must be safe for concurrent use by multiple goroutines if -// the returned Logger will be used concurrently. -func NewLogfmtLogger(w io.Writer) Logger { - return &logfmtLogger{w} -} - -func (l logfmtLogger) Log(keyvals ...interface{}) error { - enc := logfmtEncoderPool.Get().(*logfmtEncoder) - enc.Reset() - defer logfmtEncoderPool.Put(enc) - - if err := enc.EncodeKeyvals(keyvals...); err != nil { - return err - } - - // Add newline to the end of the buffer - if err := enc.EndRecord(); err != nil { - return err - } - - // The Logger interface requires implementations to be safe for concurrent - // use by multiple goroutines. For this implementation that means making - // only one call to l.w.Write() for each call to Log. - if _, err := l.w.Write(enc.buf.Bytes()); err != nil { - return err - } - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go deleted file mode 100644 index e7e370c9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package logrus provides an adapter to the -// go-kit log.Logger interface. -package logrus - -import ( - "errors" - "fmt" - - "github.com/go-kit/kit/log" - "github.com/sirupsen/logrus" -) - -type logrusLogger struct { - *logrus.Logger -} - -var errMissingValue = errors.New("(MISSING)") - -// NewLogrusLogger returns a go-kit log.Logger that sends log events to a Logrus logger. -func NewLogrusLogger(logger *logrus.Logger) log.Logger { - return &logrusLogger{logger} -} - -func (l logrusLogger) Log(keyvals ...interface{}) error { - fields := logrus.Fields{} - for i := 0; i < len(keyvals); i += 2 { - if i+1 < len(keyvals) { - fields[fmt.Sprint(keyvals[i])] = keyvals[i+1] - } else { - fields[fmt.Sprint(keyvals[i])] = errMissingValue - } - } - l.WithFields(fields).Info() - return nil -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go deleted file mode 100644 index 1047d626..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go +++ /dev/null @@ -1,8 +0,0 @@ -package log - -type nopLogger struct{} - -// NewNopLogger returns a logger that doesn't do anything. -func NewNopLogger() Logger { return nopLogger{} } - -func (nopLogger) Log(...interface{}) error { return nil } diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go deleted file mode 100644 index ff96b5de..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go +++ /dev/null @@ -1,116 +0,0 @@ -package log - -import ( - "io" - "log" - "regexp" - "strings" -) - -// StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's -// designed to be passed to a Go kit logger as the writer, for cases where -// it's necessary to redirect all Go kit log output to the stdlib logger. -// -// If you have any choice in the matter, you shouldn't use this. Prefer to -// redirect the stdlib log to the Go kit logger via NewStdlibAdapter. -type StdlibWriter struct{} - -// Write implements io.Writer. -func (w StdlibWriter) Write(p []byte) (int, error) { - log.Print(strings.TrimSpace(string(p))) - return len(p), nil -} - -// StdlibAdapter wraps a Logger and allows it to be passed to the stdlib -// logger's SetOutput. It will extract date/timestamps, filenames, and -// messages, and place them under relevant keys. -type StdlibAdapter struct { - Logger - timestampKey string - fileKey string - messageKey string -} - -// StdlibAdapterOption sets a parameter for the StdlibAdapter. -type StdlibAdapterOption func(*StdlibAdapter) - -// TimestampKey sets the key for the timestamp field. By default, it's "ts". -func TimestampKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.timestampKey = key } -} - -// FileKey sets the key for the file and line field. By default, it's "caller". -func FileKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.fileKey = key } -} - -// MessageKey sets the key for the actual log message. By default, it's "msg". -func MessageKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.messageKey = key } -} - -// NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed -// logger. It's designed to be passed to log.SetOutput. -func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { - a := StdlibAdapter{ - Logger: logger, - timestampKey: "ts", - fileKey: "caller", - messageKey: "msg", - } - for _, option := range options { - option(&a) - } - return a -} - -func (a StdlibAdapter) Write(p []byte) (int, error) { - result := subexps(p) - keyvals := []interface{}{} - var timestamp string - if date, ok := result["date"]; ok && date != "" { - timestamp = date - } - if time, ok := result["time"]; ok && time != "" { - if timestamp != "" { - timestamp += " " - } - timestamp += time - } - if timestamp != "" { - keyvals = append(keyvals, a.timestampKey, timestamp) - } - if file, ok := result["file"]; ok && file != "" { - keyvals = append(keyvals, a.fileKey, file) - } - if msg, ok := result["msg"]; ok { - keyvals = append(keyvals, a.messageKey, msg) - } - if err := a.Logger.Log(keyvals...); err != nil { - return 0, err - } - return len(p), nil -} - -const ( - logRegexpDate = `(?P[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` - logRegexpTime = `(?P

    + if data[0] == '<' { + if i := p.html(out, data, true); i > 0 { + data = data[i:] + continue + } + } + + // title block + // + // % stuff + // % more stuff + // % even more stuff + if p.flags&EXTENSION_TITLEBLOCK != 0 { + if data[0] == '%' { + if i := p.titleBlock(out, data, true); i > 0 { + data = data[i:] + continue + } + } + } + + // blank lines. note: returns the # of bytes to skip + if i := p.isEmpty(data); i > 0 { + data = data[i:] + continue + } + + // indented code block: + // + // func max(a, b int) int { + // if a > b { + // return a + // } + // return b + // } + if p.codePrefix(data) > 0 { + data = data[p.code(out, data):] + continue + } + + // fenced code block: + // + // ``` go info string here + // func fact(n int) int { + // if n <= 1 { + // return n + // } + // return n * fact(n-1) + // } + // ``` + if p.flags&EXTENSION_FENCED_CODE != 0 { + if i := p.fencedCodeBlock(out, data, true); i > 0 { + data = data[i:] + continue + } + } + + // horizontal rule: + // + // ------ + // or + // ****** + // or + // ______ + if p.isHRule(data) { + p.r.HRule(out) + var i int + for i = 0; data[i] != '\n'; i++ { + } + data = data[i:] + continue + } + + // block quote: + // + // > A big quote I found somewhere + // > on the web + if p.quotePrefix(data) > 0 { + data = data[p.quote(out, data):] + continue + } + + // table: + // + // Name | Age | Phone + // ------|-----|--------- + // Bob | 31 | 555-1234 + // Alice | 27 | 555-4321 + if p.flags&EXTENSION_TABLES != 0 { + if i := p.table(out, data); i > 0 { + data = data[i:] + continue + } + } + + // an itemized/unordered list: + // + // * Item 1 + // * Item 2 + // + // also works with + or - + if p.uliPrefix(data) > 0 { + data = data[p.list(out, data, 0):] + continue + } + + // a numbered/ordered list: + // + // 1. Item 1 + // 2. Item 2 + if p.oliPrefix(data) > 0 { + data = data[p.list(out, data, LIST_TYPE_ORDERED):] + continue + } + + // definition lists: + // + // Term 1 + // : Definition a + // : Definition b + // + // Term 2 + // : Definition c + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.dliPrefix(data) > 0 { + data = data[p.list(out, data, LIST_TYPE_DEFINITION):] + continue + } + } + + // anything else must look like a normal paragraph + // note: this finds underlined headers, too + data = data[p.paragraph(out, data):] + } + + p.nesting-- +} + +func (p *parser) isPrefixHeader(data []byte) bool { + if data[0] != '#' { + return false + } + + if p.flags&EXTENSION_SPACE_HEADERS != 0 { + level := 0 + for level < 6 && data[level] == '#' { + level++ + } + if data[level] != ' ' { + return false + } + } + return true +} + +func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int { + level := 0 + for level < 6 && data[level] == '#' { + level++ + } + i := skipChar(data, level, ' ') + end := skipUntilChar(data, i, '\n') + skip := end + id := "" + if p.flags&EXTENSION_HEADER_IDS != 0 { + j, k := 0, 0 + // find start/end of header id + for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ { + } + for k = j + 1; k < end && data[k] != '}'; k++ { + } + // extract header id iff found + if j < end && k < end { + id = string(data[j+2 : k]) + end = j + skip = k + 1 + for end > 0 && data[end-1] == ' ' { + end-- + } + } + } + for end > 0 && data[end-1] == '#' { + if isBackslashEscaped(data, end-1) { + break + } + end-- + } + for end > 0 && data[end-1] == ' ' { + end-- + } + if end > i { + if id == "" && p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + id = SanitizedAnchorName(string(data[i:end])) + } + work := func() bool { + p.inline(out, data[i:end]) + return true + } + p.r.Header(out, work, level, id) + } + return skip +} + +func (p *parser) isUnderlinedHeader(data []byte) int { + // test of level 1 header + if data[0] == '=' { + i := skipChar(data, 1, '=') + i = skipChar(data, i, ' ') + if data[i] == '\n' { + return 1 + } else { + return 0 + } + } + + // test of level 2 header + if data[0] == '-' { + i := skipChar(data, 1, '-') + i = skipChar(data, i, ' ') + if data[i] == '\n' { + return 2 + } else { + return 0 + } + } + + return 0 +} + +func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int { + if data[0] != '%' { + return 0 + } + splitData := bytes.Split(data, []byte("\n")) + var i int + for idx, b := range splitData { + if !bytes.HasPrefix(b, []byte("%")) { + i = idx // - 1 + break + } + } + + data = bytes.Join(splitData[0:i], []byte("\n")) + p.r.TitleBlock(out, data) + + return len(data) +} + +func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int { + var i, j int + + // identify the opening tag + if data[0] != '<' { + return 0 + } + curtag, tagfound := p.htmlFindTag(data[1:]) + + // handle special cases + if !tagfound { + // check for an HTML comment + if size := p.htmlComment(out, data, doRender); size > 0 { + return size + } + + // check for an
    tag + if size := p.htmlHr(out, data, doRender); size > 0 { + return size + } + + // check for HTML CDATA + if size := p.htmlCDATA(out, data, doRender); size > 0 { + return size + } + + // no special case recognized + return 0 + } + + // look for an unindented matching closing tag + // followed by a blank line + found := false + /* + closetag := []byte("\n") + j = len(curtag) + 1 + for !found { + // scan for a closing tag at the beginning of a line + if skip := bytes.Index(data[j:], closetag); skip >= 0 { + j += skip + len(closetag) + } else { + break + } + + // see if it is the only thing on the line + if skip := p.isEmpty(data[j:]); skip > 0 { + // see if it is followed by a blank line/eof + j += skip + if j >= len(data) { + found = true + i = j + } else { + if skip := p.isEmpty(data[j:]); skip > 0 { + j += skip + found = true + i = j + } + } + } + } + */ + + // if not found, try a second pass looking for indented match + // but not if tag is "ins" or "del" (following original Markdown.pl) + if !found && curtag != "ins" && curtag != "del" { + i = 1 + for i < len(data) { + i++ + for i < len(data) && !(data[i-1] == '<' && data[i] == '/') { + i++ + } + + if i+2+len(curtag) >= len(data) { + break + } + + j = p.htmlFindEnd(curtag, data[i-1:]) + + if j > 0 { + i += j - 1 + found = true + break + } + } + } + + if !found { + return 0 + } + + // the end of the block has been found + if doRender { + // trim newlines + end := i + for end > 0 && data[end-1] == '\n' { + end-- + } + p.r.BlockHtml(out, data[:end]) + } + + return i +} + +func (p *parser) renderHTMLBlock(out *bytes.Buffer, data []byte, start int, doRender bool) int { + // html block needs to end with a blank line + if i := p.isEmpty(data[start:]); i > 0 { + size := start + i + if doRender { + // trim trailing newlines + end := size + for end > 0 && data[end-1] == '\n' { + end-- + } + p.r.BlockHtml(out, data[:end]) + } + return size + } + return 0 +} + +// HTML comment, lax form +func (p *parser) htmlComment(out *bytes.Buffer, data []byte, doRender bool) int { + i := p.inlineHTMLComment(out, data) + return p.renderHTMLBlock(out, data, i, doRender) +} + +// HTML CDATA section +func (p *parser) htmlCDATA(out *bytes.Buffer, data []byte, doRender bool) int { + const cdataTag = "') { + i++ + } + i++ + // no end-of-comment marker + if i >= len(data) { + return 0 + } + return p.renderHTMLBlock(out, data, i, doRender) +} + +// HR, which is the only self-closing block tag considered +func (p *parser) htmlHr(out *bytes.Buffer, data []byte, doRender bool) int { + if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') { + return 0 + } + if data[3] != ' ' && data[3] != '/' && data[3] != '>' { + // not an
    tag after all; at least not a valid one + return 0 + } + + i := 3 + for data[i] != '>' && data[i] != '\n' { + i++ + } + + if data[i] == '>' { + return p.renderHTMLBlock(out, data, i+1, doRender) + } + + return 0 +} + +func (p *parser) htmlFindTag(data []byte) (string, bool) { + i := 0 + for isalnum(data[i]) { + i++ + } + key := string(data[:i]) + if _, ok := blockTags[key]; ok { + return key, true + } + return "", false +} + +func (p *parser) htmlFindEnd(tag string, data []byte) int { + // assume data[0] == '<' && data[1] == '/' already tested + + // check if tag is a match + closetag := []byte("") + if !bytes.HasPrefix(data, closetag) { + return 0 + } + i := len(closetag) + + // check that the rest of the line is blank + skip := 0 + if skip = p.isEmpty(data[i:]); skip == 0 { + return 0 + } + i += skip + skip = 0 + + if i >= len(data) { + return i + } + + if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + return i + } + if skip = p.isEmpty(data[i:]); skip == 0 { + // following line must be blank + return 0 + } + + return i + skip +} + +func (*parser) isEmpty(data []byte) int { + // it is okay to call isEmpty on an empty buffer + if len(data) == 0 { + return 0 + } + + var i int + for i = 0; i < len(data) && data[i] != '\n'; i++ { + if data[i] != ' ' && data[i] != '\t' { + return 0 + } + } + return i + 1 +} + +func (*parser) isHRule(data []byte) bool { + i := 0 + + // skip up to three spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // look at the hrule char + if data[i] != '*' && data[i] != '-' && data[i] != '_' { + return false + } + c := data[i] + + // the whole line must be the char or whitespace + n := 0 + for data[i] != '\n' { + switch { + case data[i] == c: + n++ + case data[i] != ' ': + return false + } + i++ + } + + return n >= 3 +} + +// isFenceLine checks if there's a fence line (e.g., ``` or ``` go) at the beginning of data, +// and returns the end index if so, or 0 otherwise. It also returns the marker found. +// If syntax is not nil, it gets set to the syntax specified in the fence line. +// A final newline is mandatory to recognize the fence line, unless newlineOptional is true. +func isFenceLine(data []byte, info *string, oldmarker string, newlineOptional bool) (end int, marker string) { + i, size := 0, 0 + + // skip up to three spaces + for i < len(data) && i < 3 && data[i] == ' ' { + i++ + } + + // check for the marker characters: ~ or ` + if i >= len(data) { + return 0, "" + } + if data[i] != '~' && data[i] != '`' { + return 0, "" + } + + c := data[i] + + // the whole line must be the same char or whitespace + for i < len(data) && data[i] == c { + size++ + i++ + } + + // the marker char must occur at least 3 times + if size < 3 { + return 0, "" + } + marker = string(data[i-size : i]) + + // if this is the end marker, it must match the beginning marker + if oldmarker != "" && marker != oldmarker { + return 0, "" + } + + // TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here + // into one, always get the info string, and discard it if the caller doesn't care. + if info != nil { + infoLength := 0 + i = skipChar(data, i, ' ') + + if i >= len(data) { + if newlineOptional && i == len(data) { + return i, marker + } + return 0, "" + } + + infoStart := i + + if data[i] == '{' { + i++ + infoStart++ + + for i < len(data) && data[i] != '}' && data[i] != '\n' { + infoLength++ + i++ + } + + if i >= len(data) || data[i] != '}' { + return 0, "" + } + + // strip all whitespace at the beginning and the end + // of the {} block + for infoLength > 0 && isspace(data[infoStart]) { + infoStart++ + infoLength-- + } + + for infoLength > 0 && isspace(data[infoStart+infoLength-1]) { + infoLength-- + } + + i++ + } else { + for i < len(data) && !isverticalspace(data[i]) { + infoLength++ + i++ + } + } + + *info = strings.TrimSpace(string(data[infoStart : infoStart+infoLength])) + } + + i = skipChar(data, i, ' ') + if i >= len(data) || data[i] != '\n' { + if newlineOptional && i == len(data) { + return i, marker + } + return 0, "" + } + + return i + 1, marker // Take newline into account. +} + +// fencedCodeBlock returns the end index if data contains a fenced code block at the beginning, +// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects. +// If doRender is true, a final newline is mandatory to recognize the fenced code block. +func (p *parser) fencedCodeBlock(out *bytes.Buffer, data []byte, doRender bool) int { + var infoString string + beg, marker := isFenceLine(data, &infoString, "", false) + if beg == 0 || beg >= len(data) { + return 0 + } + + var work bytes.Buffer + + for { + // safe to assume beg < len(data) + + // check for the end of the code block + newlineOptional := !doRender + fenceEnd, _ := isFenceLine(data[beg:], nil, marker, newlineOptional) + if fenceEnd != 0 { + beg += fenceEnd + break + } + + // copy the current line + end := skipUntilChar(data, beg, '\n') + 1 + + // did we reach the end of the buffer without a closing marker? + if end >= len(data) { + return 0 + } + + // verbatim copy to the working buffer + if doRender { + work.Write(data[beg:end]) + } + beg = end + } + + if doRender { + p.r.BlockCode(out, work.Bytes(), infoString) + } + + return beg +} + +func (p *parser) table(out *bytes.Buffer, data []byte) int { + var header bytes.Buffer + i, columns := p.tableHeader(&header, data) + if i == 0 { + return 0 + } + + var body bytes.Buffer + + for i < len(data) { + pipes, rowStart := 0, i + for ; data[i] != '\n'; i++ { + if data[i] == '|' { + pipes++ + } + } + + if pipes == 0 { + i = rowStart + break + } + + // include the newline in data sent to tableRow + i++ + p.tableRow(&body, data[rowStart:i], columns, false) + } + + p.r.Table(out, header.Bytes(), body.Bytes(), columns) + + return i +} + +// check if the specified position is preceded by an odd number of backslashes +func isBackslashEscaped(data []byte, i int) bool { + backslashes := 0 + for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' { + backslashes++ + } + return backslashes&1 == 1 +} + +func (p *parser) tableHeader(out *bytes.Buffer, data []byte) (size int, columns []int) { + i := 0 + colCount := 1 + for i = 0; data[i] != '\n'; i++ { + if data[i] == '|' && !isBackslashEscaped(data, i) { + colCount++ + } + } + + // doesn't look like a table header + if colCount == 1 { + return + } + + // include the newline in the data sent to tableRow + header := data[:i+1] + + // column count ignores pipes at beginning or end of line + if data[0] == '|' { + colCount-- + } + if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) { + colCount-- + } + + columns = make([]int, colCount) + + // move on to the header underline + i++ + if i >= len(data) { + return + } + + if data[i] == '|' && !isBackslashEscaped(data, i) { + i++ + } + i = skipChar(data, i, ' ') + + // each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3 + // and trailing | optional on last column + col := 0 + for data[i] != '\n' { + dashes := 0 + + if data[i] == ':' { + i++ + columns[col] |= TABLE_ALIGNMENT_LEFT + dashes++ + } + for data[i] == '-' { + i++ + dashes++ + } + if data[i] == ':' { + i++ + columns[col] |= TABLE_ALIGNMENT_RIGHT + dashes++ + } + for data[i] == ' ' { + i++ + } + + // end of column test is messy + switch { + case dashes < 3: + // not a valid column + return + + case data[i] == '|' && !isBackslashEscaped(data, i): + // marker found, now skip past trailing whitespace + col++ + i++ + for data[i] == ' ' { + i++ + } + + // trailing junk found after last column + if col >= colCount && data[i] != '\n' { + return + } + + case (data[i] != '|' || isBackslashEscaped(data, i)) && col+1 < colCount: + // something else found where marker was required + return + + case data[i] == '\n': + // marker is optional for the last column + col++ + + default: + // trailing junk found after last column + return + } + } + if col != colCount { + return + } + + p.tableRow(out, header, columns, true) + size = i + 1 + return +} + +func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int, header bool) { + i, col := 0, 0 + var rowWork bytes.Buffer + + if data[i] == '|' && !isBackslashEscaped(data, i) { + i++ + } + + for col = 0; col < len(columns) && i < len(data); col++ { + for data[i] == ' ' { + i++ + } + + cellStart := i + + for (data[i] != '|' || isBackslashEscaped(data, i)) && data[i] != '\n' { + i++ + } + + cellEnd := i + + // skip the end-of-cell marker, possibly taking us past end of buffer + i++ + + for cellEnd > cellStart && data[cellEnd-1] == ' ' { + cellEnd-- + } + + var cellWork bytes.Buffer + p.inline(&cellWork, data[cellStart:cellEnd]) + + if header { + p.r.TableHeaderCell(&rowWork, cellWork.Bytes(), columns[col]) + } else { + p.r.TableCell(&rowWork, cellWork.Bytes(), columns[col]) + } + } + + // pad it out with empty columns to get the right number + for ; col < len(columns); col++ { + if header { + p.r.TableHeaderCell(&rowWork, nil, columns[col]) + } else { + p.r.TableCell(&rowWork, nil, columns[col]) + } + } + + // silently ignore rows with too many cells + + p.r.TableRow(out, rowWork.Bytes()) +} + +// returns blockquote prefix length +func (p *parser) quotePrefix(data []byte) int { + i := 0 + for i < 3 && data[i] == ' ' { + i++ + } + if data[i] == '>' { + if data[i+1] == ' ' { + return i + 2 + } + return i + 1 + } + return 0 +} + +// blockquote ends with at least one blank line +// followed by something without a blockquote prefix +func (p *parser) terminateBlockquote(data []byte, beg, end int) bool { + if p.isEmpty(data[beg:]) <= 0 { + return false + } + if end >= len(data) { + return true + } + return p.quotePrefix(data[end:]) == 0 && p.isEmpty(data[end:]) == 0 +} + +// parse a blockquote fragment +func (p *parser) quote(out *bytes.Buffer, data []byte) int { + var raw bytes.Buffer + beg, end := 0, 0 + for beg < len(data) { + end = beg + // Step over whole lines, collecting them. While doing that, check for + // fenced code and if one's found, incorporate it altogether, + // irregardless of any contents inside it + for data[end] != '\n' { + if p.flags&EXTENSION_FENCED_CODE != 0 { + if i := p.fencedCodeBlock(out, data[end:], false); i > 0 { + // -1 to compensate for the extra end++ after the loop: + end += i - 1 + break + } + } + end++ + } + end++ + + if pre := p.quotePrefix(data[beg:]); pre > 0 { + // skip the prefix + beg += pre + } else if p.terminateBlockquote(data, beg, end) { + break + } + + // this line is part of the blockquote + raw.Write(data[beg:end]) + beg = end + } + + var cooked bytes.Buffer + p.block(&cooked, raw.Bytes()) + p.r.BlockQuote(out, cooked.Bytes()) + return end +} + +// returns prefix length for block code +func (p *parser) codePrefix(data []byte) int { + if data[0] == ' ' && data[1] == ' ' && data[2] == ' ' && data[3] == ' ' { + return 4 + } + return 0 +} + +func (p *parser) code(out *bytes.Buffer, data []byte) int { + var work bytes.Buffer + + i := 0 + for i < len(data) { + beg := i + for data[i] != '\n' { + i++ + } + i++ + + blankline := p.isEmpty(data[beg:i]) > 0 + if pre := p.codePrefix(data[beg:i]); pre > 0 { + beg += pre + } else if !blankline { + // non-empty, non-prefixed line breaks the pre + i = beg + break + } + + // verbatim copy to the working buffeu + if blankline { + work.WriteByte('\n') + } else { + work.Write(data[beg:i]) + } + } + + // trim all the \n off the end of work + workbytes := work.Bytes() + eol := len(workbytes) + for eol > 0 && workbytes[eol-1] == '\n' { + eol-- + } + if eol != len(workbytes) { + work.Truncate(eol) + } + + work.WriteByte('\n') + + p.r.BlockCode(out, work.Bytes(), "") + + return i +} + +// returns unordered list item prefix +func (p *parser) uliPrefix(data []byte) int { + i := 0 + + // start with up to 3 spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // need a *, +, or - followed by a space + if (data[i] != '*' && data[i] != '+' && data[i] != '-') || + data[i+1] != ' ' { + return 0 + } + return i + 2 +} + +// returns ordered list item prefix +func (p *parser) oliPrefix(data []byte) int { + i := 0 + + // start with up to 3 spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // count the digits + start := i + for data[i] >= '0' && data[i] <= '9' { + i++ + } + + // we need >= 1 digits followed by a dot and a space + if start == i || data[i] != '.' || data[i+1] != ' ' { + return 0 + } + return i + 2 +} + +// returns definition list item prefix +func (p *parser) dliPrefix(data []byte) int { + i := 0 + + // need a : followed by a spaces + if data[i] != ':' || data[i+1] != ' ' { + return 0 + } + for data[i] == ' ' { + i++ + } + return i + 2 +} + +// parse ordered or unordered list block +func (p *parser) list(out *bytes.Buffer, data []byte, flags int) int { + i := 0 + flags |= LIST_ITEM_BEGINNING_OF_LIST + work := func() bool { + for i < len(data) { + skip := p.listItem(out, data[i:], &flags) + i += skip + + if skip == 0 || flags&LIST_ITEM_END_OF_LIST != 0 { + break + } + flags &= ^LIST_ITEM_BEGINNING_OF_LIST + } + return true + } + + p.r.List(out, work, flags) + return i +} + +// Parse a single list item. +// Assumes initial prefix is already removed if this is a sublist. +func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *int) int { + // keep track of the indentation of the first line + itemIndent := 0 + for itemIndent < 3 && data[itemIndent] == ' ' { + itemIndent++ + } + + i := p.uliPrefix(data) + if i == 0 { + i = p.oliPrefix(data) + } + if i == 0 { + i = p.dliPrefix(data) + // reset definition term flag + if i > 0 { + *flags &= ^LIST_TYPE_TERM + } + } + if i == 0 { + // if in defnition list, set term flag and continue + if *flags&LIST_TYPE_DEFINITION != 0 { + *flags |= LIST_TYPE_TERM + } else { + return 0 + } + } + + // skip leading whitespace on first line + for data[i] == ' ' { + i++ + } + + // find the end of the line + line := i + for i > 0 && data[i-1] != '\n' { + i++ + } + + // get working buffer + var raw bytes.Buffer + + // put the first line into the working buffer + raw.Write(data[line:i]) + line = i + + // process the following lines + containsBlankLine := false + sublist := 0 + codeBlockMarker := "" + +gatherlines: + for line < len(data) { + i++ + + // find the end of this line + for data[i-1] != '\n' { + i++ + } + + // if it is an empty line, guess that it is part of this item + // and move on to the next line + if p.isEmpty(data[line:i]) > 0 { + containsBlankLine = true + raw.Write(data[line:i]) + line = i + continue + } + + // calculate the indentation + indent := 0 + for indent < 4 && line+indent < i && data[line+indent] == ' ' { + indent++ + } + + chunk := data[line+indent : i] + + if p.flags&EXTENSION_FENCED_CODE != 0 { + // determine if in or out of codeblock + // if in codeblock, ignore normal list processing + _, marker := isFenceLine(chunk, nil, codeBlockMarker, false) + if marker != "" { + if codeBlockMarker == "" { + // start of codeblock + codeBlockMarker = marker + } else { + // end of codeblock. + *flags |= LIST_ITEM_CONTAINS_BLOCK + codeBlockMarker = "" + } + } + // we are in a codeblock, write line, and continue + if codeBlockMarker != "" || marker != "" { + raw.Write(data[line+indent : i]) + line = i + continue gatherlines + } + } + + // evaluate how this line fits in + switch { + // is this a nested list item? + case (p.uliPrefix(chunk) > 0 && !p.isHRule(chunk)) || + p.oliPrefix(chunk) > 0 || + p.dliPrefix(chunk) > 0: + + if containsBlankLine { + // end the list if the type changed after a blank line + if indent <= itemIndent && + ((*flags&LIST_TYPE_ORDERED != 0 && p.uliPrefix(chunk) > 0) || + (*flags&LIST_TYPE_ORDERED == 0 && p.oliPrefix(chunk) > 0)) { + + *flags |= LIST_ITEM_END_OF_LIST + break gatherlines + } + *flags |= LIST_ITEM_CONTAINS_BLOCK + } + + // to be a nested list, it must be indented more + // if not, it is the next item in the same list + if indent <= itemIndent { + break gatherlines + } + + // is this the first item in the nested list? + if sublist == 0 { + sublist = raw.Len() + } + + // is this a nested prefix header? + case p.isPrefixHeader(chunk): + // if the header is not indented, it is not nested in the list + // and thus ends the list + if containsBlankLine && indent < 4 { + *flags |= LIST_ITEM_END_OF_LIST + break gatherlines + } + *flags |= LIST_ITEM_CONTAINS_BLOCK + + // anything following an empty line is only part + // of this item if it is indented 4 spaces + // (regardless of the indentation of the beginning of the item) + case containsBlankLine && indent < 4: + if *flags&LIST_TYPE_DEFINITION != 0 && i < len(data)-1 { + // is the next item still a part of this list? + next := i + for data[next] != '\n' { + next++ + } + for next < len(data)-1 && data[next] == '\n' { + next++ + } + if i < len(data)-1 && data[i] != ':' && data[next] != ':' { + *flags |= LIST_ITEM_END_OF_LIST + } + } else { + *flags |= LIST_ITEM_END_OF_LIST + } + break gatherlines + + // a blank line means this should be parsed as a block + case containsBlankLine: + *flags |= LIST_ITEM_CONTAINS_BLOCK + } + + containsBlankLine = false + + // add the line into the working buffer without prefix + raw.Write(data[line+indent : i]) + + line = i + } + + // If reached end of data, the Renderer.ListItem call we're going to make below + // is definitely the last in the list. + if line >= len(data) { + *flags |= LIST_ITEM_END_OF_LIST + } + + rawBytes := raw.Bytes() + + // render the contents of the list item + var cooked bytes.Buffer + if *flags&LIST_ITEM_CONTAINS_BLOCK != 0 && *flags&LIST_TYPE_TERM == 0 { + // intermediate render of block item, except for definition term + if sublist > 0 { + p.block(&cooked, rawBytes[:sublist]) + p.block(&cooked, rawBytes[sublist:]) + } else { + p.block(&cooked, rawBytes) + } + } else { + // intermediate render of inline item + if sublist > 0 { + p.inline(&cooked, rawBytes[:sublist]) + p.block(&cooked, rawBytes[sublist:]) + } else { + p.inline(&cooked, rawBytes) + } + } + + // render the actual list item + cookedBytes := cooked.Bytes() + parsedEnd := len(cookedBytes) + + // strip trailing newlines + for parsedEnd > 0 && cookedBytes[parsedEnd-1] == '\n' { + parsedEnd-- + } + p.r.ListItem(out, cookedBytes[:parsedEnd], *flags) + + return line +} + +// render a single paragraph that has already been parsed out +func (p *parser) renderParagraph(out *bytes.Buffer, data []byte) { + if len(data) == 0 { + return + } + + // trim leading spaces + beg := 0 + for data[beg] == ' ' { + beg++ + } + + // trim trailing newline + end := len(data) - 1 + + // trim trailing spaces + for end > beg && data[end-1] == ' ' { + end-- + } + + work := func() bool { + p.inline(out, data[beg:end]) + return true + } + p.r.Paragraph(out, work) +} + +func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { + // prev: index of 1st char of previous line + // line: index of 1st char of current line + // i: index of cursor/end of current line + var prev, line, i int + + // keep going until we find something to mark the end of the paragraph + for i < len(data) { + // mark the beginning of the current line + prev = line + current := data[i:] + line = i + + // did we find a blank line marking the end of the paragraph? + if n := p.isEmpty(current); n > 0 { + // did this blank line followed by a definition list item? + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if i < len(data)-1 && data[i+1] == ':' { + return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + } + } + + p.renderParagraph(out, data[:i]) + return i + n + } + + // an underline under some text marks a header, so our paragraph ended on prev line + if i > 0 { + if level := p.isUnderlinedHeader(current); level > 0 { + // render the paragraph + p.renderParagraph(out, data[:prev]) + + // ignore leading and trailing whitespace + eol := i - 1 + for prev < eol && data[prev] == ' ' { + prev++ + } + for eol > prev && data[eol-1] == ' ' { + eol-- + } + + // render the header + // this ugly double closure avoids forcing variables onto the heap + work := func(o *bytes.Buffer, pp *parser, d []byte) func() bool { + return func() bool { + pp.inline(o, d) + return true + } + }(out, p, data[prev:eol]) + + id := "" + if p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + id = SanitizedAnchorName(string(data[prev:eol])) + } + + p.r.Header(out, work, level, id) + + // find the end of the underline + for data[i] != '\n' { + i++ + } + return i + } + } + + // if the next line starts a block of HTML, then the paragraph ends here + if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + if data[i] == '<' && p.html(out, current, false) > 0 { + // rewind to before the HTML block + p.renderParagraph(out, data[:i]) + return i + } + } + + // if there's a prefixed header or a horizontal rule after this, paragraph is over + if p.isPrefixHeader(current) || p.isHRule(current) { + p.renderParagraph(out, data[:i]) + return i + } + + // if there's a fenced code block, paragraph is over + if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.fencedCodeBlock(out, current, false) > 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + + // if there's a definition list item, prev line is a definition term + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.dliPrefix(current) != 0 { + return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + } + } + + // if there's a list after this, paragraph is over + if p.flags&EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK != 0 { + if p.uliPrefix(current) != 0 || + p.oliPrefix(current) != 0 || + p.quotePrefix(current) != 0 || + p.codePrefix(current) != 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + + // otherwise, scan to the beginning of the next line + for data[i] != '\n' { + i++ + } + i++ + } + + p.renderParagraph(out, data[:i]) + return i +} + +// SanitizedAnchorName returns a sanitized anchor name for the given text. +// +// It implements the algorithm specified in the package comment. +func SanitizedAnchorName(text string) string { + var anchorName []rune + futureDash := false + for _, r := range text { + switch { + case unicode.IsLetter(r) || unicode.IsNumber(r): + if futureDash && len(anchorName) > 0 { + anchorName = append(anchorName, '-') + } + futureDash = false + anchorName = append(anchorName, unicode.ToLower(r)) + default: + futureDash = true + } + } + return string(anchorName) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go new file mode 100644 index 00000000..9656c42a --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go @@ -0,0 +1,32 @@ +// Package blackfriday is a Markdown processor. +// +// It translates plain text with simple formatting rules into HTML or LaTeX. +// +// Sanitized Anchor Names +// +// Blackfriday includes an algorithm for creating sanitized anchor names +// corresponding to a given input text. This algorithm is used to create +// anchors for headings when EXTENSION_AUTO_HEADER_IDS is enabled. The +// algorithm is specified below, so that other packages can create +// compatible anchor names and links to those anchors. +// +// The algorithm iterates over the input text, interpreted as UTF-8, +// one Unicode code point (rune) at a time. All runes that are letters (category L) +// or numbers (category N) are considered valid characters. They are mapped to +// lower case, and included in the output. All other runes are considered +// invalid characters. Invalid characters that preceed the first valid character, +// as well as invalid character that follow the last valid character +// are dropped completely. All other sequences of invalid characters +// between two valid characters are replaced with a single dash character '-'. +// +// SanitizedAnchorName exposes this functionality, and can be used to +// create compatible links to the anchor names generated by blackfriday. +// This algorithm is also implemented in a small standalone package at +// github.com/shurcooL/sanitized_anchor_name. It can be useful for clients +// that want a small package and don't need full functionality of blackfriday. +package blackfriday + +// NOTE: Keep Sanitized Anchor Name algorithm in sync with package +// github.com/shurcooL/sanitized_anchor_name. +// Otherwise, users of sanitized_anchor_name will get anchor names +// that are incompatible with those generated by blackfriday. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod new file mode 100644 index 00000000..b05561a0 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod @@ -0,0 +1 @@ +module github.com/russross/blackfriday diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go new file mode 100644 index 00000000..e0a6c69c --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go @@ -0,0 +1,938 @@ +// +// Blackfriday Markdown Processor +// Available at http://github.com/russross/blackfriday +// +// Copyright © 2011 Russ Ross . +// Distributed under the Simplified BSD License. +// See README.md for details. +// + +// +// +// HTML rendering backend +// +// + +package blackfriday + +import ( + "bytes" + "fmt" + "regexp" + "strconv" + "strings" +) + +// Html renderer configuration options. +const ( + HTML_SKIP_HTML = 1 << iota // skip preformatted HTML blocks + HTML_SKIP_STYLE // skip embedded ", basePathEscaped) - fmt.Fprintf(w, "

    %s

    ", basePathEscaped) - fmt.Fprintf(w, "
      ") - - if len(basePathEscaped) > 1 { - var parentURI URI - base.CopyTo(&parentURI) - parentURI.Update(string(base.Path()) + "/..") - parentPathEscaped := html.EscapeString(string(parentURI.Path())) - fmt.Fprintf(w, `
    • ..
    • `, parentPathEscaped) - } - - f, err := os.Open(dirPath) - if err != nil { - return nil, err - } - - fileinfos, err := f.Readdir(0) - f.Close() - if err != nil { - return nil, err - } - - fm := make(map[string]os.FileInfo, len(fileinfos)) - var filenames []string - for _, fi := range fileinfos { - name := fi.Name() - if strings.HasSuffix(name, h.compressedFileSuffix) { - // Do not show compressed files on index page. - continue - } - fm[name] = fi - filenames = append(filenames, name) - } - - var u URI - base.CopyTo(&u) - u.Update(string(u.Path()) + "/") - - sort.Sort(sort.StringSlice(filenames)) - for _, name := range filenames { - u.Update(name) - pathEscaped := html.EscapeString(string(u.Path())) - fi := fm[name] - auxStr := "dir" - className := "dir" - if !fi.IsDir() { - auxStr = fmt.Sprintf("file, %d bytes", fi.Size()) - className = "file" - } - fmt.Fprintf(w, `
    • %s, %s, last modified %s
    • `, - pathEscaped, className, html.EscapeString(name), auxStr, fsModTime(fi.ModTime())) - } - - fmt.Fprintf(w, "
    ") - - if mustCompress { - var zbuf ByteBuffer - zbuf.B = AppendGzipBytesLevel(zbuf.B, w.B, CompressDefaultCompression) - w = &zbuf - } - - dirIndex := w.B - lastModified := time.Now() - ff := &fsFile{ - h: h, - dirIndex: dirIndex, - contentType: "text/html; charset=utf-8", - contentLength: len(dirIndex), - compressed: mustCompress, - lastModified: lastModified, - lastModifiedStr: AppendHTTPDate(nil, lastModified), - - t: lastModified, - } - return ff, nil -} - -const ( - fsMinCompressRatio = 0.8 - fsMaxCompressibleFileSize = 8 * 1024 * 1024 -) - -func (h *fsHandler) compressAndOpenFSFile(filePath string) (*fsFile, error) { - f, err := os.Open(filePath) - if err != nil { - return nil, err - } - - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for file %q: %s", filePath, err) - } - - if fileInfo.IsDir() { - f.Close() - return nil, errDirIndexRequired - } - - if strings.HasSuffix(filePath, h.compressedFileSuffix) || - fileInfo.Size() > fsMaxCompressibleFileSize || - !isFileCompressible(f, fsMinCompressRatio) { - return h.newFSFile(f, fileInfo, false) - } - - compressedFilePath := filePath + h.compressedFileSuffix - absPath, err := filepath.Abs(compressedFilePath) - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot determine absolute path for %q: %s", compressedFilePath, err) - } - - flock := getFileLock(absPath) - flock.Lock() - ff, err := h.compressFileNolock(f, fileInfo, filePath, compressedFilePath) - flock.Unlock() - - return ff, err -} - -func (h *fsHandler) compressFileNolock(f *os.File, fileInfo os.FileInfo, filePath, compressedFilePath string) (*fsFile, error) { - // Attempt to open compressed file created by another concurrent - // goroutine. - // It is safe opening such a file, since the file creation - // is guarded by file mutex - see getFileLock call. - if _, err := os.Stat(compressedFilePath); err == nil { - f.Close() - return h.newCompressedFSFile(compressedFilePath) - } - - // Create temporary file, so concurrent goroutines don't use - // it until it is created. - tmpFilePath := compressedFilePath + ".tmp" - zf, err := os.Create(tmpFilePath) - if err != nil { - f.Close() - if !os.IsPermission(err) { - return nil, fmt.Errorf("cannot create temporary file %q: %s", tmpFilePath, err) - } - return nil, errNoCreatePermission - } - - zw := acquireStacklessGzipWriter(zf, CompressDefaultCompression) - _, err = copyZeroAlloc(zw, f) - if err1 := zw.Flush(); err == nil { - err = err1 - } - releaseStacklessGzipWriter(zw, CompressDefaultCompression) - zf.Close() - f.Close() - if err != nil { - return nil, fmt.Errorf("error when compressing file %q to %q: %s", filePath, tmpFilePath, err) - } - if err = os.Chtimes(tmpFilePath, time.Now(), fileInfo.ModTime()); err != nil { - return nil, fmt.Errorf("cannot change modification time to %s for tmp file %q: %s", - fileInfo.ModTime(), tmpFilePath, err) - } - if err = os.Rename(tmpFilePath, compressedFilePath); err != nil { - return nil, fmt.Errorf("cannot move compressed file from %q to %q: %s", tmpFilePath, compressedFilePath, err) - } - return h.newCompressedFSFile(compressedFilePath) -} - -func (h *fsHandler) newCompressedFSFile(filePath string) (*fsFile, error) { - f, err := os.Open(filePath) - if err != nil { - return nil, fmt.Errorf("cannot open compressed file %q: %s", filePath, err) - } - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for compressed file %q: %s", filePath, err) - } - return h.newFSFile(f, fileInfo, true) -} - -func (h *fsHandler) openFSFile(filePath string, mustCompress bool) (*fsFile, error) { - filePathOriginal := filePath - if mustCompress { - filePath += h.compressedFileSuffix - } - - f, err := os.Open(filePath) - if err != nil { - if mustCompress && os.IsNotExist(err) { - return h.compressAndOpenFSFile(filePathOriginal) - } - return nil, err - } - - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for file %q: %s", filePath, err) - } - - if fileInfo.IsDir() { - f.Close() - if mustCompress { - return nil, fmt.Errorf("directory with unexpected suffix found: %q. Suffix: %q", - filePath, h.compressedFileSuffix) - } - return nil, errDirIndexRequired - } - - if mustCompress { - fileInfoOriginal, err := os.Stat(filePathOriginal) - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for original file %q: %s", filePathOriginal, err) - } - - if fileInfoOriginal.ModTime() != fileInfo.ModTime() { - // The compressed file became stale. Re-create it. - f.Close() - os.Remove(filePath) - return h.compressAndOpenFSFile(filePathOriginal) - } - } - - return h.newFSFile(f, fileInfo, mustCompress) -} - -func (h *fsHandler) newFSFile(f *os.File, fileInfo os.FileInfo, compressed bool) (*fsFile, error) { - n := fileInfo.Size() - contentLength := int(n) - if n != int64(contentLength) { - f.Close() - return nil, fmt.Errorf("too big file: %d bytes", n) - } - - // detect content-type - ext := fileExtension(fileInfo.Name(), compressed, h.compressedFileSuffix) - contentType := mime.TypeByExtension(ext) - if len(contentType) == 0 { - data, err := readFileHeader(f, compressed) - if err != nil { - return nil, fmt.Errorf("cannot read header of the file %q: %s", f.Name(), err) - } - contentType = http.DetectContentType(data) - } - - lastModified := fileInfo.ModTime() - ff := &fsFile{ - h: h, - f: f, - contentType: contentType, - contentLength: contentLength, - compressed: compressed, - lastModified: lastModified, - lastModifiedStr: AppendHTTPDate(nil, lastModified), - - t: time.Now(), - } - return ff, nil -} - -func readFileHeader(f *os.File, compressed bool) ([]byte, error) { - r := io.Reader(f) - var zr *gzip.Reader - if compressed { - var err error - if zr, err = acquireGzipReader(f); err != nil { - return nil, err - } - r = zr - } - - lr := &io.LimitedReader{ - R: r, - N: 512, - } - data, err := ioutil.ReadAll(lr) - f.Seek(0, 0) - - if zr != nil { - releaseGzipReader(zr) - } - - return data, err -} - -func stripLeadingSlashes(path []byte, stripSlashes int) []byte { - for stripSlashes > 0 && len(path) > 0 { - if path[0] != '/' { - panic("BUG: path must start with slash") - } - n := bytes.IndexByte(path[1:], '/') - if n < 0 { - path = path[:0] - break - } - path = path[n+1:] - stripSlashes-- - } - return path -} - -func stripTrailingSlashes(path []byte) []byte { - for len(path) > 0 && path[len(path)-1] == '/' { - path = path[:len(path)-1] - } - return path -} - -func fileExtension(path string, compressed bool, compressedFileSuffix string) string { - if compressed && strings.HasSuffix(path, compressedFileSuffix) { - path = path[:len(path)-len(compressedFileSuffix)] - } - n := strings.LastIndexByte(path, '.') - if n < 0 { - return "" - } - return path[n:] -} - -// FileLastModified returns last modified time for the file. -func FileLastModified(path string) (time.Time, error) { - f, err := os.Open(path) - if err != nil { - return zeroTime, err - } - fileInfo, err := f.Stat() - f.Close() - if err != nil { - return zeroTime, err - } - return fsModTime(fileInfo.ModTime()), nil -} - -func fsModTime(t time.Time) time.Time { - return t.In(time.UTC).Truncate(time.Second) -} - -var ( - filesLockMap = make(map[string]*sync.Mutex) - filesLockMapLock sync.Mutex -) - -func getFileLock(absPath string) *sync.Mutex { - filesLockMapLock.Lock() - flock := filesLockMap[absPath] - if flock == nil { - flock = &sync.Mutex{} - filesLockMap[absPath] = flock - } - filesLockMapLock.Unlock() - return flock -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go deleted file mode 100644 index 4283433e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go +++ /dev/null @@ -1,2111 +0,0 @@ -package fasthttp - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - "sync/atomic" - "time" -) - -// ResponseHeader represents HTTP response header. -// -// It is forbidden copying ResponseHeader instances. -// Create new instances instead and use CopyTo. -// -// ResponseHeader instance MUST NOT be used from concurrently running -// goroutines. -type ResponseHeader struct { - noCopy noCopy - - disableNormalizing bool - noHTTP11 bool - connectionClose bool - - statusCode int - contentLength int - contentLengthBytes []byte - - contentType []byte - server []byte - - h []argsKV - bufKV argsKV - - cookies []argsKV -} - -// RequestHeader represents HTTP request header. -// -// It is forbidden copying RequestHeader instances. -// Create new instances instead and use CopyTo. -// -// RequestHeader instance MUST NOT be used from concurrently running -// goroutines. -type RequestHeader struct { - noCopy noCopy - - disableNormalizing bool - noHTTP11 bool - connectionClose bool - isGet bool - - // These two fields have been moved close to other bool fields - // for reducing RequestHeader object size. - cookiesCollected bool - rawHeadersParsed bool - - contentLength int - contentLengthBytes []byte - - method []byte - requestURI []byte - host []byte - contentType []byte - userAgent []byte - - h []argsKV - bufKV argsKV - - cookies []argsKV - - rawHeaders []byte -} - -// SetContentRange sets 'Content-Range: bytes startPos-endPos/contentLength' -// header. -func (h *ResponseHeader) SetContentRange(startPos, endPos, contentLength int) { - b := h.bufKV.value[:0] - b = append(b, strBytes...) - b = append(b, ' ') - b = AppendUint(b, startPos) - b = append(b, '-') - b = AppendUint(b, endPos) - b = append(b, '/') - b = AppendUint(b, contentLength) - h.bufKV.value = b - - h.SetCanonical(strContentRange, h.bufKV.value) -} - -// SetByteRange sets 'Range: bytes=startPos-endPos' header. -// -// * If startPos is negative, then 'bytes=-startPos' value is set. -// * If endPos is negative, then 'bytes=startPos-' value is set. -func (h *RequestHeader) SetByteRange(startPos, endPos int) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strBytes...) - b = append(b, '=') - if startPos >= 0 { - b = AppendUint(b, startPos) - } else { - endPos = -startPos - } - b = append(b, '-') - if endPos >= 0 { - b = AppendUint(b, endPos) - } - h.bufKV.value = b - - h.SetCanonical(strRange, h.bufKV.value) -} - -// StatusCode returns response status code. -func (h *ResponseHeader) StatusCode() int { - if h.statusCode == 0 { - return StatusOK - } - return h.statusCode -} - -// SetStatusCode sets response status code. -func (h *ResponseHeader) SetStatusCode(statusCode int) { - h.statusCode = statusCode -} - -// SetLastModified sets 'Last-Modified' header to the given value. -func (h *ResponseHeader) SetLastModified(t time.Time) { - h.bufKV.value = AppendHTTPDate(h.bufKV.value[:0], t) - h.SetCanonical(strLastModified, h.bufKV.value) -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (h *ResponseHeader) ConnectionClose() bool { - return h.connectionClose -} - -// SetConnectionClose sets 'Connection: close' header. -func (h *ResponseHeader) SetConnectionClose() { - h.connectionClose = true -} - -// ResetConnectionClose clears 'Connection: close' header if it exists. -func (h *ResponseHeader) ResetConnectionClose() { - if h.connectionClose { - h.connectionClose = false - h.h = delAllArgsBytes(h.h, strConnection) - } -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (h *RequestHeader) ConnectionClose() bool { - h.parseRawHeaders() - return h.connectionClose -} - -func (h *RequestHeader) connectionCloseFast() bool { - // h.parseRawHeaders() isn't called for performance reasons. - // Use ConnectionClose for triggering raw headers parsing. - return h.connectionClose -} - -// SetConnectionClose sets 'Connection: close' header. -func (h *RequestHeader) SetConnectionClose() { - // h.parseRawHeaders() isn't called for performance reasons. - h.connectionClose = true -} - -// ResetConnectionClose clears 'Connection: close' header if it exists. -func (h *RequestHeader) ResetConnectionClose() { - h.parseRawHeaders() - if h.connectionClose { - h.connectionClose = false - h.h = delAllArgsBytes(h.h, strConnection) - } -} - -// ConnectionUpgrade returns true if 'Connection: Upgrade' header is set. -func (h *ResponseHeader) ConnectionUpgrade() bool { - return hasHeaderValue(h.Peek("Connection"), strUpgrade) -} - -// ConnectionUpgrade returns true if 'Connection: Upgrade' header is set. -func (h *RequestHeader) ConnectionUpgrade() bool { - h.parseRawHeaders() - return hasHeaderValue(h.Peek("Connection"), strUpgrade) -} - -// ContentLength returns Content-Length header value. -// -// It may be negative: -// -1 means Transfer-Encoding: chunked. -// -2 means Transfer-Encoding: identity. -func (h *ResponseHeader) ContentLength() int { - return h.contentLength -} - -// SetContentLength sets Content-Length header value. -// -// Content-Length may be negative: -// -1 means Transfer-Encoding: chunked. -// -2 means Transfer-Encoding: identity. -func (h *ResponseHeader) SetContentLength(contentLength int) { - if h.mustSkipContentLength() { - return - } - h.contentLength = contentLength - if contentLength >= 0 { - h.contentLengthBytes = AppendUint(h.contentLengthBytes[:0], contentLength) - h.h = delAllArgsBytes(h.h, strTransferEncoding) - } else { - h.contentLengthBytes = h.contentLengthBytes[:0] - value := strChunked - if contentLength == -2 { - h.SetConnectionClose() - value = strIdentity - } - h.h = setArgBytes(h.h, strTransferEncoding, value) - } -} - -func (h *ResponseHeader) mustSkipContentLength() bool { - // From http/1.1 specs: - // All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body - statusCode := h.StatusCode() - - // Fast path. - if statusCode < 100 || statusCode == StatusOK { - return false - } - - // Slow path. - return statusCode == StatusNotModified || statusCode == StatusNoContent || statusCode < 200 -} - -// ContentLength returns Content-Length header value. -// -// It may be negative: -// -1 means Transfer-Encoding: chunked. -func (h *RequestHeader) ContentLength() int { - if h.noBody() { - return 0 - } - h.parseRawHeaders() - return h.contentLength -} - -// SetContentLength sets Content-Length header value. -// -// Negative content-length sets 'Transfer-Encoding: chunked' header. -func (h *RequestHeader) SetContentLength(contentLength int) { - h.parseRawHeaders() - h.contentLength = contentLength - if contentLength >= 0 { - h.contentLengthBytes = AppendUint(h.contentLengthBytes[:0], contentLength) - h.h = delAllArgsBytes(h.h, strTransferEncoding) - } else { - h.contentLengthBytes = h.contentLengthBytes[:0] - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } -} - -func (h *ResponseHeader) isCompressibleContentType() bool { - contentType := h.ContentType() - return bytes.HasPrefix(contentType, strTextSlash) || - bytes.HasPrefix(contentType, strApplicationSlash) -} - -// ContentType returns Content-Type header value. -func (h *ResponseHeader) ContentType() []byte { - contentType := h.contentType - if len(h.contentType) == 0 { - contentType = defaultContentType - } - return contentType -} - -// SetContentType sets Content-Type header value. -func (h *ResponseHeader) SetContentType(contentType string) { - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetContentTypeBytes sets Content-Type header value. -func (h *ResponseHeader) SetContentTypeBytes(contentType []byte) { - h.contentType = append(h.contentType[:0], contentType...) -} - -// Server returns Server header value. -func (h *ResponseHeader) Server() []byte { - return h.server -} - -// SetServer sets Server header value. -func (h *ResponseHeader) SetServer(server string) { - h.server = append(h.server[:0], server...) -} - -// SetServerBytes sets Server header value. -func (h *ResponseHeader) SetServerBytes(server []byte) { - h.server = append(h.server[:0], server...) -} - -// ContentType returns Content-Type header value. -func (h *RequestHeader) ContentType() []byte { - h.parseRawHeaders() - return h.contentType -} - -// SetContentType sets Content-Type header value. -func (h *RequestHeader) SetContentType(contentType string) { - h.parseRawHeaders() - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetContentTypeBytes sets Content-Type header value. -func (h *RequestHeader) SetContentTypeBytes(contentType []byte) { - h.parseRawHeaders() - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetMultipartFormBoundary sets the following Content-Type: -// 'multipart/form-data; boundary=...' -// where ... is substituted by the given boundary. -func (h *RequestHeader) SetMultipartFormBoundary(boundary string) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strMultipartFormData...) - b = append(b, ';', ' ') - b = append(b, strBoundary...) - b = append(b, '=') - b = append(b, boundary...) - h.bufKV.value = b - - h.SetContentTypeBytes(h.bufKV.value) -} - -// SetMultipartFormBoundaryBytes sets the following Content-Type: -// 'multipart/form-data; boundary=...' -// where ... is substituted by the given boundary. -func (h *RequestHeader) SetMultipartFormBoundaryBytes(boundary []byte) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strMultipartFormData...) - b = append(b, ';', ' ') - b = append(b, strBoundary...) - b = append(b, '=') - b = append(b, boundary...) - h.bufKV.value = b - - h.SetContentTypeBytes(h.bufKV.value) -} - -// MultipartFormBoundary returns boundary part -// from 'multipart/form-data; boundary=...' Content-Type. -func (h *RequestHeader) MultipartFormBoundary() []byte { - b := h.ContentType() - if !bytes.HasPrefix(b, strMultipartFormData) { - return nil - } - b = b[len(strMultipartFormData):] - if len(b) == 0 || b[0] != ';' { - return nil - } - - var n int - for len(b) > 0 { - n++ - for len(b) > n && b[n] == ' ' { - n++ - } - b = b[n:] - if !bytes.HasPrefix(b, strBoundary) { - if n = bytes.IndexByte(b, ';'); n < 0 { - return nil - } - continue - } - - b = b[len(strBoundary):] - if len(b) == 0 || b[0] != '=' { - return nil - } - b = b[1:] - if n = bytes.IndexByte(b, ';'); n >= 0 { - b = b[:n] - } - if len(b) > 1 && b[0] == '"' && b[len(b)-1] == '"' { - b = b[1 : len(b)-1] - } - return b - } - return nil -} - -// Host returns Host header value. -func (h *RequestHeader) Host() []byte { - if len(h.host) > 0 { - return h.host - } - if !h.rawHeadersParsed { - // fast path without employing full headers parsing. - host := peekRawHeader(h.rawHeaders, strHost) - if len(host) > 0 { - h.host = append(h.host[:0], host...) - return h.host - } - } - - // slow path. - h.parseRawHeaders() - return h.host -} - -// SetHost sets Host header value. -func (h *RequestHeader) SetHost(host string) { - h.parseRawHeaders() - h.host = append(h.host[:0], host...) -} - -// SetHostBytes sets Host header value. -func (h *RequestHeader) SetHostBytes(host []byte) { - h.parseRawHeaders() - h.host = append(h.host[:0], host...) -} - -// UserAgent returns User-Agent header value. -func (h *RequestHeader) UserAgent() []byte { - h.parseRawHeaders() - return h.userAgent -} - -// SetUserAgent sets User-Agent header value. -func (h *RequestHeader) SetUserAgent(userAgent string) { - h.parseRawHeaders() - h.userAgent = append(h.userAgent[:0], userAgent...) -} - -// SetUserAgentBytes sets User-Agent header value. -func (h *RequestHeader) SetUserAgentBytes(userAgent []byte) { - h.parseRawHeaders() - h.userAgent = append(h.userAgent[:0], userAgent...) -} - -// Referer returns Referer header value. -func (h *RequestHeader) Referer() []byte { - return h.PeekBytes(strReferer) -} - -// SetReferer sets Referer header value. -func (h *RequestHeader) SetReferer(referer string) { - h.SetBytesK(strReferer, referer) -} - -// SetRefererBytes sets Referer header value. -func (h *RequestHeader) SetRefererBytes(referer []byte) { - h.SetCanonical(strReferer, referer) -} - -// Method returns HTTP request method. -func (h *RequestHeader) Method() []byte { - if len(h.method) == 0 { - return strGet - } - return h.method -} - -// SetMethod sets HTTP request method. -func (h *RequestHeader) SetMethod(method string) { - h.method = append(h.method[:0], method...) -} - -// SetMethodBytes sets HTTP request method. -func (h *RequestHeader) SetMethodBytes(method []byte) { - h.method = append(h.method[:0], method...) -} - -// RequestURI returns RequestURI from the first HTTP request line. -func (h *RequestHeader) RequestURI() []byte { - requestURI := h.requestURI - if len(requestURI) == 0 { - requestURI = strSlash - } - return requestURI -} - -// SetRequestURI sets RequestURI for the first HTTP request line. -// RequestURI must be properly encoded. -// Use URI.RequestURI for constructing proper RequestURI if unsure. -func (h *RequestHeader) SetRequestURI(requestURI string) { - h.requestURI = append(h.requestURI[:0], requestURI...) -} - -// SetRequestURIBytes sets RequestURI for the first HTTP request line. -// RequestURI must be properly encoded. -// Use URI.RequestURI for constructing proper RequestURI if unsure. -func (h *RequestHeader) SetRequestURIBytes(requestURI []byte) { - h.requestURI = append(h.requestURI[:0], requestURI...) -} - -// IsGet returns true if request method is GET. -func (h *RequestHeader) IsGet() bool { - // Optimize fast path for GET requests. - if !h.isGet { - h.isGet = bytes.Equal(h.Method(), strGet) - } - return h.isGet -} - -// IsPost returns true if request method is POST. -func (h *RequestHeader) IsPost() bool { - return bytes.Equal(h.Method(), strPost) -} - -// IsPut returns true if request method is PUT. -func (h *RequestHeader) IsPut() bool { - return bytes.Equal(h.Method(), strPut) -} - -// IsHead returns true if request method is HEAD. -func (h *RequestHeader) IsHead() bool { - // Fast path - if h.isGet { - return false - } - return bytes.Equal(h.Method(), strHead) -} - -// IsDelete returns true if request method is DELETE. -func (h *RequestHeader) IsDelete() bool { - return bytes.Equal(h.Method(), strDelete) -} - -// IsConnect returns true if request method is CONNECT. -func (h *RequestHeader) IsConnect() bool { - return bytes.Equal(h.Method(), strConnect) -} - -// IsOptions returns true if request method is OPTIONS. -func (h *RequestHeader) IsOptions() bool { - return bytes.Equal(h.Method(), strOptions) -} - -// IsTrace returns true if request method is TRACE. -func (h *RequestHeader) IsTrace() bool { - return bytes.Equal(h.Method(), strTrace) -} - -// IsPatch returns true if request method is PATCH. -func (h *RequestHeader) IsPatch() bool { - return bytes.Equal(h.Method(), strPatch) -} - -// IsHTTP11 returns true if the request is HTTP/1.1. -func (h *RequestHeader) IsHTTP11() bool { - return !h.noHTTP11 -} - -// IsHTTP11 returns true if the response is HTTP/1.1. -func (h *ResponseHeader) IsHTTP11() bool { - return !h.noHTTP11 -} - -// HasAcceptEncoding returns true if the header contains -// the given Accept-Encoding value. -func (h *RequestHeader) HasAcceptEncoding(acceptEncoding string) bool { - h.bufKV.value = append(h.bufKV.value[:0], acceptEncoding...) - return h.HasAcceptEncodingBytes(h.bufKV.value) -} - -// HasAcceptEncodingBytes returns true if the header contains -// the given Accept-Encoding value. -func (h *RequestHeader) HasAcceptEncodingBytes(acceptEncoding []byte) bool { - ae := h.peek(strAcceptEncoding) - n := bytes.Index(ae, acceptEncoding) - if n < 0 { - return false - } - b := ae[n+len(acceptEncoding):] - if len(b) > 0 && b[0] != ',' { - return false - } - if n == 0 { - return true - } - return ae[n-1] == ' ' -} - -// Len returns the number of headers set, -// i.e. the number of times f is called in VisitAll. -func (h *ResponseHeader) Len() int { - n := 0 - h.VisitAll(func(k, v []byte) { n++ }) - return n -} - -// Len returns the number of headers set, -// i.e. the number of times f is called in VisitAll. -func (h *RequestHeader) Len() int { - n := 0 - h.VisitAll(func(k, v []byte) { n++ }) - return n -} - -// DisableNormalizing disables header names' normalization. -// -// By default all the header names are normalized by uppercasing -// the first letter and all the first letters following dashes, -// while lowercasing all the other letters. -// Examples: -// -// * CONNECTION -> Connection -// * conteNT-tYPE -> Content-Type -// * foo-bar-baz -> Foo-Bar-Baz -// -// Disable header names' normalization only if know what are you doing. -func (h *RequestHeader) DisableNormalizing() { - h.disableNormalizing = true -} - -// DisableNormalizing disables header names' normalization. -// -// By default all the header names are normalized by uppercasing -// the first letter and all the first letters following dashes, -// while lowercasing all the other letters. -// Examples: -// -// * CONNECTION -> Connection -// * conteNT-tYPE -> Content-Type -// * foo-bar-baz -> Foo-Bar-Baz -// -// Disable header names' normalization only if know what are you doing. -func (h *ResponseHeader) DisableNormalizing() { - h.disableNormalizing = true -} - -// Reset clears response header. -func (h *ResponseHeader) Reset() { - h.disableNormalizing = false - h.resetSkipNormalize() -} - -func (h *ResponseHeader) resetSkipNormalize() { - h.noHTTP11 = false - h.connectionClose = false - - h.statusCode = 0 - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - - h.contentType = h.contentType[:0] - h.server = h.server[:0] - - h.h = h.h[:0] - h.cookies = h.cookies[:0] -} - -// Reset clears request header. -func (h *RequestHeader) Reset() { - h.disableNormalizing = false - h.resetSkipNormalize() -} - -func (h *RequestHeader) resetSkipNormalize() { - h.noHTTP11 = false - h.connectionClose = false - h.isGet = false - - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - - h.method = h.method[:0] - h.requestURI = h.requestURI[:0] - h.host = h.host[:0] - h.contentType = h.contentType[:0] - h.userAgent = h.userAgent[:0] - - h.h = h.h[:0] - h.cookies = h.cookies[:0] - h.cookiesCollected = false - - h.rawHeaders = h.rawHeaders[:0] - h.rawHeadersParsed = false -} - -// CopyTo copies all the headers to dst. -func (h *ResponseHeader) CopyTo(dst *ResponseHeader) { - dst.Reset() - - dst.disableNormalizing = h.disableNormalizing - dst.noHTTP11 = h.noHTTP11 - dst.connectionClose = h.connectionClose - - dst.statusCode = h.statusCode - dst.contentLength = h.contentLength - dst.contentLengthBytes = append(dst.contentLengthBytes[:0], h.contentLengthBytes...) - dst.contentType = append(dst.contentType[:0], h.contentType...) - dst.server = append(dst.server[:0], h.server...) - dst.h = copyArgs(dst.h, h.h) - dst.cookies = copyArgs(dst.cookies, h.cookies) -} - -// CopyTo copies all the headers to dst. -func (h *RequestHeader) CopyTo(dst *RequestHeader) { - dst.Reset() - - dst.disableNormalizing = h.disableNormalizing - dst.noHTTP11 = h.noHTTP11 - dst.connectionClose = h.connectionClose - dst.isGet = h.isGet - - dst.contentLength = h.contentLength - dst.contentLengthBytes = append(dst.contentLengthBytes[:0], h.contentLengthBytes...) - dst.method = append(dst.method[:0], h.method...) - dst.requestURI = append(dst.requestURI[:0], h.requestURI...) - dst.host = append(dst.host[:0], h.host...) - dst.contentType = append(dst.contentType[:0], h.contentType...) - dst.userAgent = append(dst.userAgent[:0], h.userAgent...) - dst.h = copyArgs(dst.h, h.h) - dst.cookies = copyArgs(dst.cookies, h.cookies) - dst.cookiesCollected = h.cookiesCollected - dst.rawHeaders = append(dst.rawHeaders[:0], h.rawHeaders...) - dst.rawHeadersParsed = h.rawHeadersParsed -} - -// VisitAll calls f for each header. -// -// f must not retain references to key and/or value after returning. -// Copy key and/or value contents before returning if you need retaining them. -func (h *ResponseHeader) VisitAll(f func(key, value []byte)) { - if len(h.contentLengthBytes) > 0 { - f(strContentLength, h.contentLengthBytes) - } - contentType := h.ContentType() - if len(contentType) > 0 { - f(strContentType, contentType) - } - server := h.Server() - if len(server) > 0 { - f(strServer, server) - } - if len(h.cookies) > 0 { - visitArgs(h.cookies, func(k, v []byte) { - f(strSetCookie, v) - }) - } - visitArgs(h.h, f) - if h.ConnectionClose() { - f(strConnection, strClose) - } -} - -// VisitAllCookie calls f for each response cookie. -// -// Cookie name is passed in key and the whole Set-Cookie header value -// is passed in value on each f invocation. Value may be parsed -// with Cookie.ParseBytes(). -// -// f must not retain references to key and/or value after returning. -func (h *ResponseHeader) VisitAllCookie(f func(key, value []byte)) { - visitArgs(h.cookies, f) -} - -// VisitAllCookie calls f for each request cookie. -// -// f must not retain references to key and/or value after returning. -func (h *RequestHeader) VisitAllCookie(f func(key, value []byte)) { - h.parseRawHeaders() - h.collectCookies() - visitArgs(h.cookies, f) -} - -// VisitAll calls f for each header. -// -// f must not retain references to key and/or value after returning. -// Copy key and/or value contents before returning if you need retaining them. -func (h *RequestHeader) VisitAll(f func(key, value []byte)) { - h.parseRawHeaders() - host := h.Host() - if len(host) > 0 { - f(strHost, host) - } - if len(h.contentLengthBytes) > 0 { - f(strContentLength, h.contentLengthBytes) - } - contentType := h.ContentType() - if len(contentType) > 0 { - f(strContentType, contentType) - } - userAgent := h.UserAgent() - if len(userAgent) > 0 { - f(strUserAgent, userAgent) - } - - h.collectCookies() - if len(h.cookies) > 0 { - h.bufKV.value = appendRequestCookieBytes(h.bufKV.value[:0], h.cookies) - f(strCookie, h.bufKV.value) - } - visitArgs(h.h, f) - if h.ConnectionClose() { - f(strConnection, strClose) - } -} - -// Del deletes header with the given key. -func (h *ResponseHeader) Del(key string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.del(k) -} - -// DelBytes deletes header with the given key. -func (h *ResponseHeader) DelBytes(key []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.del(h.bufKV.key) -} - -func (h *ResponseHeader) del(key []byte) { - switch string(key) { - case "Content-Type": - h.contentType = h.contentType[:0] - case "Server": - h.server = h.server[:0] - case "Set-Cookie": - h.cookies = h.cookies[:0] - case "Content-Length": - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - case "Connection": - h.connectionClose = false - } - h.h = delAllArgsBytes(h.h, key) -} - -// Del deletes header with the given key. -func (h *RequestHeader) Del(key string) { - h.parseRawHeaders() - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.del(k) -} - -// DelBytes deletes header with the given key. -func (h *RequestHeader) DelBytes(key []byte) { - h.parseRawHeaders() - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.del(h.bufKV.key) -} - -func (h *RequestHeader) del(key []byte) { - switch string(key) { - case "Host": - h.host = h.host[:0] - case "Content-Type": - h.contentType = h.contentType[:0] - case "User-Agent": - h.userAgent = h.userAgent[:0] - case "Cookie": - h.cookies = h.cookies[:0] - case "Content-Length": - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - case "Connection": - h.connectionClose = false - } - h.h = delAllArgsBytes(h.h, key) -} - -// Add adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use Set for setting a single header for the given key. -func (h *ResponseHeader) Add(key, value string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.h = appendArg(h.h, b2s(k), value) -} - -// AddBytesK adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesK for setting a single header for the given key. -func (h *ResponseHeader) AddBytesK(key []byte, value string) { - h.Add(b2s(key), value) -} - -// AddBytesV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesV for setting a single header for the given key. -func (h *ResponseHeader) AddBytesV(key string, value []byte) { - h.Add(key, b2s(value)) -} - -// AddBytesKV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesKV for setting a single header for the given key. -func (h *ResponseHeader) AddBytesKV(key, value []byte) { - h.Add(b2s(key), b2s(value)) -} - -// Set sets the given 'key: value' header. -// -// Use Add for setting multiple header values under the same key. -func (h *ResponseHeader) Set(key, value string) { - initHeaderKV(&h.bufKV, key, value, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, h.bufKV.value) -} - -// SetBytesK sets the given 'key: value' header. -// -// Use AddBytesK for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesK(key []byte, value string) { - h.bufKV.value = append(h.bufKV.value[:0], value...) - h.SetBytesKV(key, h.bufKV.value) -} - -// SetBytesV sets the given 'key: value' header. -// -// Use AddBytesV for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesV(key string, value []byte) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.SetCanonical(k, value) -} - -// SetBytesKV sets the given 'key: value' header. -// -// Use AddBytesKV for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesKV(key, value []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, value) -} - -// SetCanonical sets the given 'key: value' header assuming that -// key is in canonical form. -func (h *ResponseHeader) SetCanonical(key, value []byte) { - switch string(key) { - case "Content-Type": - h.SetContentTypeBytes(value) - case "Server": - h.SetServerBytes(value) - case "Set-Cookie": - var kv *argsKV - h.cookies, kv = allocArg(h.cookies) - kv.key = getCookieKey(kv.key, value) - kv.value = append(kv.value[:0], value...) - case "Content-Length": - if contentLength, err := parseContentLength(value); err == nil { - h.contentLength = contentLength - h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) - } - case "Connection": - if bytes.Equal(strClose, value) { - h.SetConnectionClose() - } else { - h.ResetConnectionClose() - h.h = setArgBytes(h.h, key, value) - } - case "Transfer-Encoding": - // Transfer-Encoding is managed automatically. - case "Date": - // Date is managed automatically. - default: - h.h = setArgBytes(h.h, key, value) - } -} - -// SetCookie sets the given response cookie. -// -// It is save re-using the cookie after the function returns. -func (h *ResponseHeader) SetCookie(cookie *Cookie) { - h.cookies = setArgBytes(h.cookies, cookie.Key(), cookie.Cookie()) -} - -// SetCookie sets 'key: value' cookies. -func (h *RequestHeader) SetCookie(key, value string) { - h.parseRawHeaders() - h.collectCookies() - h.cookies = setArg(h.cookies, key, value) -} - -// SetCookieBytesK sets 'key: value' cookies. -func (h *RequestHeader) SetCookieBytesK(key []byte, value string) { - h.SetCookie(b2s(key), value) -} - -// SetCookieBytesKV sets 'key: value' cookies. -func (h *RequestHeader) SetCookieBytesKV(key, value []byte) { - h.SetCookie(b2s(key), b2s(value)) -} - -// DelClientCookie instructs the client to remove the given cookie. -// -// Use DelCookie if you want just removing the cookie from response header. -func (h *ResponseHeader) DelClientCookie(key string) { - h.DelCookie(key) - - c := AcquireCookie() - c.SetKey(key) - c.SetExpire(CookieExpireDelete) - h.SetCookie(c) - ReleaseCookie(c) -} - -// DelClientCookieBytes instructs the client to remove the given cookie. -// -// Use DelCookieBytes if you want just removing the cookie from response header. -func (h *ResponseHeader) DelClientCookieBytes(key []byte) { - h.DelClientCookie(b2s(key)) -} - -// DelCookie removes cookie under the given key from response header. -// -// Note that DelCookie doesn't remove the cookie from the client. -// Use DelClientCookie instead. -func (h *ResponseHeader) DelCookie(key string) { - h.cookies = delAllArgs(h.cookies, key) -} - -// DelCookieBytes removes cookie under the given key from response header. -// -// Note that DelCookieBytes doesn't remove the cookie from the client. -// Use DelClientCookieBytes instead. -func (h *ResponseHeader) DelCookieBytes(key []byte) { - h.DelCookie(b2s(key)) -} - -// DelCookie removes cookie under the given key. -func (h *RequestHeader) DelCookie(key string) { - h.parseRawHeaders() - h.collectCookies() - h.cookies = delAllArgs(h.cookies, key) -} - -// DelCookieBytes removes cookie under the given key. -func (h *RequestHeader) DelCookieBytes(key []byte) { - h.DelCookie(b2s(key)) -} - -// DelAllCookies removes all the cookies from response headers. -func (h *ResponseHeader) DelAllCookies() { - h.cookies = h.cookies[:0] -} - -// DelAllCookies removes all the cookies from request headers. -func (h *RequestHeader) DelAllCookies() { - h.parseRawHeaders() - h.collectCookies() - h.cookies = h.cookies[:0] -} - -// Add adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use Set for setting a single header for the given key. -func (h *RequestHeader) Add(key, value string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.h = appendArg(h.h, b2s(k), value) -} - -// AddBytesK adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesK for setting a single header for the given key. -func (h *RequestHeader) AddBytesK(key []byte, value string) { - h.Add(b2s(key), value) -} - -// AddBytesV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesV for setting a single header for the given key. -func (h *RequestHeader) AddBytesV(key string, value []byte) { - h.Add(key, b2s(value)) -} - -// AddBytesKV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesKV for setting a single header for the given key. -func (h *RequestHeader) AddBytesKV(key, value []byte) { - h.Add(b2s(key), b2s(value)) -} - -// Set sets the given 'key: value' header. -// -// Use Add for setting multiple header values under the same key. -func (h *RequestHeader) Set(key, value string) { - initHeaderKV(&h.bufKV, key, value, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, h.bufKV.value) -} - -// SetBytesK sets the given 'key: value' header. -// -// Use AddBytesK for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesK(key []byte, value string) { - h.bufKV.value = append(h.bufKV.value[:0], value...) - h.SetBytesKV(key, h.bufKV.value) -} - -// SetBytesV sets the given 'key: value' header. -// -// Use AddBytesV for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesV(key string, value []byte) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.SetCanonical(k, value) -} - -// SetBytesKV sets the given 'key: value' header. -// -// Use AddBytesKV for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesKV(key, value []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, value) -} - -// SetCanonical sets the given 'key: value' header assuming that -// key is in canonical form. -func (h *RequestHeader) SetCanonical(key, value []byte) { - h.parseRawHeaders() - switch string(key) { - case "Host": - h.SetHostBytes(value) - case "Content-Type": - h.SetContentTypeBytes(value) - case "User-Agent": - h.SetUserAgentBytes(value) - case "Cookie": - h.collectCookies() - h.cookies = parseRequestCookies(h.cookies, value) - case "Content-Length": - if contentLength, err := parseContentLength(value); err == nil { - h.contentLength = contentLength - h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) - } - case "Connection": - if bytes.Equal(strClose, value) { - h.SetConnectionClose() - } else { - h.ResetConnectionClose() - h.h = setArgBytes(h.h, key, value) - } - case "Transfer-Encoding": - // Transfer-Encoding is managed automatically. - default: - h.h = setArgBytes(h.h, key, value) - } -} - -// Peek returns header value for the given key. -// -// Returned value is valid until the next call to ResponseHeader. -// Do not store references to returned value. Make copies instead. -func (h *ResponseHeader) Peek(key string) []byte { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - return h.peek(k) -} - -// PeekBytes returns header value for the given key. -// -// Returned value is valid until the next call to ResponseHeader. -// Do not store references to returned value. Make copies instead. -func (h *ResponseHeader) PeekBytes(key []byte) []byte { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - return h.peek(h.bufKV.key) -} - -// Peek returns header value for the given key. -// -// Returned value is valid until the next call to RequestHeader. -// Do not store references to returned value. Make copies instead. -func (h *RequestHeader) Peek(key string) []byte { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - return h.peek(k) -} - -// PeekBytes returns header value for the given key. -// -// Returned value is valid until the next call to RequestHeader. -// Do not store references to returned value. Make copies instead. -func (h *RequestHeader) PeekBytes(key []byte) []byte { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - return h.peek(h.bufKV.key) -} - -func (h *ResponseHeader) peek(key []byte) []byte { - switch string(key) { - case "Content-Type": - return h.ContentType() - case "Server": - return h.Server() - case "Connection": - if h.ConnectionClose() { - return strClose - } - return peekArgBytes(h.h, key) - case "Content-Length": - return h.contentLengthBytes - default: - return peekArgBytes(h.h, key) - } -} - -func (h *RequestHeader) peek(key []byte) []byte { - h.parseRawHeaders() - switch string(key) { - case "Host": - return h.Host() - case "Content-Type": - return h.ContentType() - case "User-Agent": - return h.UserAgent() - case "Connection": - if h.ConnectionClose() { - return strClose - } - return peekArgBytes(h.h, key) - case "Content-Length": - return h.contentLengthBytes - default: - return peekArgBytes(h.h, key) - } -} - -// Cookie returns cookie for the given key. -func (h *RequestHeader) Cookie(key string) []byte { - h.parseRawHeaders() - h.collectCookies() - return peekArgStr(h.cookies, key) -} - -// CookieBytes returns cookie for the given key. -func (h *RequestHeader) CookieBytes(key []byte) []byte { - h.parseRawHeaders() - h.collectCookies() - return peekArgBytes(h.cookies, key) -} - -// Cookie fills cookie for the given cookie.Key. -// -// Returns false if cookie with the given cookie.Key is missing. -func (h *ResponseHeader) Cookie(cookie *Cookie) bool { - v := peekArgBytes(h.cookies, cookie.Key()) - if v == nil { - return false - } - cookie.ParseBytes(v) - return true -} - -// Read reads response header from r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (h *ResponseHeader) Read(r *bufio.Reader) error { - n := 1 - for { - err := h.tryRead(r, n) - if err == nil { - return nil - } - if err != errNeedMore { - h.resetSkipNormalize() - return err - } - n = r.Buffered() + 1 - } -} - -func (h *ResponseHeader) tryRead(r *bufio.Reader, n int) error { - h.resetSkipNormalize() - b, err := r.Peek(n) - if len(b) == 0 { - // treat all errors on the first byte read as EOF - if n == 1 || err == io.EOF { - return io.EOF - } - - // This is for go 1.6 bug. See https://github.com/golang/go/issues/14121 . - if err == bufio.ErrBufferFull { - return &ErrSmallBuffer{ - error: fmt.Errorf("error when reading response headers: %s", errSmallBuffer), - } - } - - return fmt.Errorf("error when reading response headers: %s", err) - } - b = mustPeekBuffered(r) - headersLen, errParse := h.parse(b) - if errParse != nil { - return headerError("response", err, errParse, b) - } - mustDiscard(r, headersLen) - return nil -} - -func headerError(typ string, err, errParse error, b []byte) error { - if errParse != errNeedMore { - return headerErrorMsg(typ, errParse, b) - } - if err == nil { - return errNeedMore - } - - // Buggy servers may leave trailing CRLFs after http body. - // Treat this case as EOF. - if isOnlyCRLF(b) { - return io.EOF - } - - if err != bufio.ErrBufferFull { - return headerErrorMsg(typ, err, b) - } - return &ErrSmallBuffer{ - error: headerErrorMsg(typ, errSmallBuffer, b), - } -} - -func headerErrorMsg(typ string, err error, b []byte) error { - return fmt.Errorf("error when reading %s headers: %s. Buffer size=%d, contents: %s", typ, err, len(b), bufferSnippet(b)) -} - -// Read reads request header from r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (h *RequestHeader) Read(r *bufio.Reader) error { - n := 1 - for { - err := h.tryRead(r, n) - if err == nil { - return nil - } - if err != errNeedMore { - h.resetSkipNormalize() - return err - } - n = r.Buffered() + 1 - } -} - -func (h *RequestHeader) tryRead(r *bufio.Reader, n int) error { - h.resetSkipNormalize() - b, err := r.Peek(n) - if len(b) == 0 { - // treat all errors on the first byte read as EOF - if n == 1 || err == io.EOF { - return io.EOF - } - - // This is for go 1.6 bug. See https://github.com/golang/go/issues/14121 . - if err == bufio.ErrBufferFull { - return &ErrSmallBuffer{ - error: fmt.Errorf("error when reading request headers: %s", errSmallBuffer), - } - } - - return fmt.Errorf("error when reading request headers: %s", err) - } - b = mustPeekBuffered(r) - headersLen, errParse := h.parse(b) - if errParse != nil { - return headerError("request", err, errParse, b) - } - mustDiscard(r, headersLen) - return nil -} - -func bufferSnippet(b []byte) string { - n := len(b) - start := 200 - end := n - start - if start >= end { - start = n - end = n - } - bStart, bEnd := b[:start], b[end:] - if len(bEnd) == 0 { - return fmt.Sprintf("%q", b) - } - return fmt.Sprintf("%q...%q", bStart, bEnd) -} - -func isOnlyCRLF(b []byte) bool { - for _, ch := range b { - if ch != '\r' && ch != '\n' { - return false - } - } - return true -} - -func init() { - refreshServerDate() - go func() { - for { - time.Sleep(time.Second) - refreshServerDate() - } - }() -} - -var serverDate atomic.Value - -func refreshServerDate() { - b := AppendHTTPDate(nil, time.Now()) - serverDate.Store(b) -} - -// Write writes response header to w. -func (h *ResponseHeader) Write(w *bufio.Writer) error { - _, err := w.Write(h.Header()) - return err -} - -// WriteTo writes response header to w. -// -// WriteTo implements io.WriterTo interface. -func (h *ResponseHeader) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(h.Header()) - return int64(n), err -} - -// Header returns response header representation. -// -// The returned value is valid until the next call to ResponseHeader methods. -func (h *ResponseHeader) Header() []byte { - h.bufKV.value = h.AppendBytes(h.bufKV.value[:0]) - return h.bufKV.value -} - -// String returns response header representation. -func (h *ResponseHeader) String() string { - return string(h.Header()) -} - -// AppendBytes appends response header representation to dst and returns -// the extended dst. -func (h *ResponseHeader) AppendBytes(dst []byte) []byte { - statusCode := h.StatusCode() - if statusCode < 0 { - statusCode = StatusOK - } - dst = append(dst, statusLine(statusCode)...) - - server := h.Server() - if len(server) == 0 { - server = defaultServerName - } - dst = appendHeaderLine(dst, strServer, server) - dst = appendHeaderLine(dst, strDate, serverDate.Load().([]byte)) - - // Append Content-Type only for non-zero responses - // or if it is explicitly set. - // See https://github.com/valyala/fasthttp/issues/28 . - if h.ContentLength() != 0 || len(h.contentType) > 0 { - dst = appendHeaderLine(dst, strContentType, h.ContentType()) - } - - if len(h.contentLengthBytes) > 0 { - dst = appendHeaderLine(dst, strContentLength, h.contentLengthBytes) - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - if !bytes.Equal(kv.key, strDate) { - dst = appendHeaderLine(dst, kv.key, kv.value) - } - } - - n := len(h.cookies) - if n > 0 { - for i := 0; i < n; i++ { - kv := &h.cookies[i] - dst = appendHeaderLine(dst, strSetCookie, kv.value) - } - } - - if h.ConnectionClose() { - dst = appendHeaderLine(dst, strConnection, strClose) - } - - return append(dst, strCRLF...) -} - -// Write writes request header to w. -func (h *RequestHeader) Write(w *bufio.Writer) error { - _, err := w.Write(h.Header()) - return err -} - -// WriteTo writes request header to w. -// -// WriteTo implements io.WriterTo interface. -func (h *RequestHeader) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(h.Header()) - return int64(n), err -} - -// Header returns request header representation. -// -// The returned representation is valid until the next call to RequestHeader methods. -func (h *RequestHeader) Header() []byte { - h.bufKV.value = h.AppendBytes(h.bufKV.value[:0]) - return h.bufKV.value -} - -// String returns request header representation. -func (h *RequestHeader) String() string { - return string(h.Header()) -} - -// AppendBytes appends request header representation to dst and returns -// the extended dst. -func (h *RequestHeader) AppendBytes(dst []byte) []byte { - // there is no need in h.parseRawHeaders() here - raw headers are specially handled below. - dst = append(dst, h.Method()...) - dst = append(dst, ' ') - dst = append(dst, h.RequestURI()...) - dst = append(dst, ' ') - dst = append(dst, strHTTP11...) - dst = append(dst, strCRLF...) - - if !h.rawHeadersParsed && len(h.rawHeaders) > 0 { - return append(dst, h.rawHeaders...) - } - - userAgent := h.UserAgent() - if len(userAgent) == 0 { - userAgent = defaultUserAgent - } - dst = appendHeaderLine(dst, strUserAgent, userAgent) - - host := h.Host() - if len(host) > 0 { - dst = appendHeaderLine(dst, strHost, host) - } - - contentType := h.ContentType() - if !h.noBody() { - if len(contentType) == 0 { - contentType = strPostArgsContentType - } - dst = appendHeaderLine(dst, strContentType, contentType) - - if len(h.contentLengthBytes) > 0 { - dst = appendHeaderLine(dst, strContentLength, h.contentLengthBytes) - } - } else if len(contentType) > 0 { - dst = appendHeaderLine(dst, strContentType, contentType) - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - dst = appendHeaderLine(dst, kv.key, kv.value) - } - - // there is no need in h.collectCookies() here, since if cookies aren't collected yet, - // they all are located in h.h. - n := len(h.cookies) - if n > 0 { - dst = append(dst, strCookie...) - dst = append(dst, strColonSpace...) - dst = appendRequestCookieBytes(dst, h.cookies) - dst = append(dst, strCRLF...) - } - - if h.ConnectionClose() { - dst = appendHeaderLine(dst, strConnection, strClose) - } - - return append(dst, strCRLF...) -} - -func appendHeaderLine(dst, key, value []byte) []byte { - dst = append(dst, key...) - dst = append(dst, strColonSpace...) - dst = append(dst, value...) - return append(dst, strCRLF...) -} - -func (h *ResponseHeader) parse(buf []byte) (int, error) { - m, err := h.parseFirstLine(buf) - if err != nil { - return 0, err - } - n, err := h.parseHeaders(buf[m:]) - if err != nil { - return 0, err - } - return m + n, nil -} - -func (h *RequestHeader) noBody() bool { - return h.IsGet() || h.IsHead() -} - -func (h *RequestHeader) parse(buf []byte) (int, error) { - m, err := h.parseFirstLine(buf) - if err != nil { - return 0, err - } - - var n int - if !h.noBody() || h.noHTTP11 { - n, err = h.parseHeaders(buf[m:]) - if err != nil { - return 0, err - } - h.rawHeadersParsed = true - } else { - var rawHeaders []byte - rawHeaders, n, err = readRawHeaders(h.rawHeaders[:0], buf[m:]) - if err != nil { - return 0, err - } - h.rawHeaders = rawHeaders - } - return m + n, nil -} - -func (h *ResponseHeader) parseFirstLine(buf []byte) (int, error) { - bNext := buf - var b []byte - var err error - for len(b) == 0 { - if b, bNext, err = nextLine(bNext); err != nil { - return 0, err - } - } - - // parse protocol - n := bytes.IndexByte(b, ' ') - if n < 0 { - return 0, fmt.Errorf("cannot find whitespace in the first line of response %q", buf) - } - h.noHTTP11 = !bytes.Equal(b[:n], strHTTP11) - b = b[n+1:] - - // parse status code - h.statusCode, n, err = parseUintBuf(b) - if err != nil { - return 0, fmt.Errorf("cannot parse response status code: %s. Response %q", err, buf) - } - if len(b) > n && b[n] != ' ' { - return 0, fmt.Errorf("unexpected char at the end of status code. Response %q", buf) - } - - return len(buf) - len(bNext), nil -} - -func (h *RequestHeader) parseFirstLine(buf []byte) (int, error) { - bNext := buf - var b []byte - var err error - for len(b) == 0 { - if b, bNext, err = nextLine(bNext); err != nil { - return 0, err - } - } - - // parse method - n := bytes.IndexByte(b, ' ') - if n <= 0 { - return 0, fmt.Errorf("cannot find http request method in %q", buf) - } - h.method = append(h.method[:0], b[:n]...) - b = b[n+1:] - - // parse requestURI - n = bytes.LastIndexByte(b, ' ') - if n < 0 { - h.noHTTP11 = true - n = len(b) - } else if n == 0 { - return 0, fmt.Errorf("requestURI cannot be empty in %q", buf) - } else if !bytes.Equal(b[n+1:], strHTTP11) { - h.noHTTP11 = true - } - h.requestURI = append(h.requestURI[:0], b[:n]...) - - return len(buf) - len(bNext), nil -} - -func peekRawHeader(buf, key []byte) []byte { - n := bytes.Index(buf, key) - if n < 0 { - return nil - } - if n > 0 && buf[n-1] != '\n' { - return nil - } - n += len(key) - if n >= len(buf) { - return nil - } - if buf[n] != ':' { - return nil - } - n++ - if buf[n] != ' ' { - return nil - } - n++ - buf = buf[n:] - n = bytes.IndexByte(buf, '\n') - if n < 0 { - return nil - } - if n > 0 && buf[n-1] == '\r' { - n-- - } - return buf[:n] -} - -func readRawHeaders(dst, buf []byte) ([]byte, int, error) { - n := bytes.IndexByte(buf, '\n') - if n < 0 { - return nil, 0, errNeedMore - } - if (n == 1 && buf[0] == '\r') || n == 0 { - // empty headers - return dst, n + 1, nil - } - - n++ - b := buf - m := n - for { - b = b[m:] - m = bytes.IndexByte(b, '\n') - if m < 0 { - return nil, 0, errNeedMore - } - m++ - n += m - if (m == 2 && b[0] == '\r') || m == 1 { - dst = append(dst, buf[:n]...) - return dst, n, nil - } - } -} - -func (h *ResponseHeader) parseHeaders(buf []byte) (int, error) { - // 'identity' content-length by default - h.contentLength = -2 - - var s headerScanner - s.b = buf - s.disableNormalizing = h.disableNormalizing - var err error - var kv *argsKV - for s.next() { - switch string(s.key) { - case "Content-Type": - h.contentType = append(h.contentType[:0], s.value...) - case "Server": - h.server = append(h.server[:0], s.value...) - case "Content-Length": - if h.contentLength != -1 { - if h.contentLength, err = parseContentLength(s.value); err != nil { - h.contentLength = -2 - } else { - h.contentLengthBytes = append(h.contentLengthBytes[:0], s.value...) - } - } - case "Transfer-Encoding": - if !bytes.Equal(s.value, strIdentity) { - h.contentLength = -1 - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } - case "Set-Cookie": - h.cookies, kv = allocArg(h.cookies) - kv.key = getCookieKey(kv.key, s.value) - kv.value = append(kv.value[:0], s.value...) - case "Connection": - if bytes.Equal(s.value, strClose) { - h.connectionClose = true - } else { - h.connectionClose = false - h.h = appendArgBytes(h.h, s.key, s.value) - } - default: - h.h = appendArgBytes(h.h, s.key, s.value) - } - } - if s.err != nil { - h.connectionClose = true - return 0, s.err - } - - if h.contentLength < 0 { - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.contentLength == -2 && !h.ConnectionUpgrade() && !h.mustSkipContentLength() { - h.h = setArgBytes(h.h, strTransferEncoding, strIdentity) - h.connectionClose = true - } - if h.noHTTP11 && !h.connectionClose { - // close connection for non-http/1.1 response unless 'Connection: keep-alive' is set. - v := peekArgBytes(h.h, strConnection) - h.connectionClose = !hasHeaderValue(v, strKeepAlive) && !hasHeaderValue(v, strKeepAliveCamelCase) - } - - return len(buf) - len(s.b), nil -} - -func (h *RequestHeader) parseHeaders(buf []byte) (int, error) { - h.contentLength = -2 - - var s headerScanner - s.b = buf - s.disableNormalizing = h.disableNormalizing - var err error - for s.next() { - switch string(s.key) { - case "Host": - h.host = append(h.host[:0], s.value...) - case "User-Agent": - h.userAgent = append(h.userAgent[:0], s.value...) - case "Content-Type": - h.contentType = append(h.contentType[:0], s.value...) - case "Content-Length": - if h.contentLength != -1 { - if h.contentLength, err = parseContentLength(s.value); err != nil { - h.contentLength = -2 - } else { - h.contentLengthBytes = append(h.contentLengthBytes[:0], s.value...) - } - } - case "Transfer-Encoding": - if !bytes.Equal(s.value, strIdentity) { - h.contentLength = -1 - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } - case "Connection": - if bytes.Equal(s.value, strClose) { - h.connectionClose = true - } else { - h.connectionClose = false - h.h = appendArgBytes(h.h, s.key, s.value) - } - default: - h.h = appendArgBytes(h.h, s.key, s.value) - } - } - if s.err != nil { - h.connectionClose = true - return 0, s.err - } - - if h.contentLength < 0 { - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.noBody() { - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.noHTTP11 && !h.connectionClose { - // close connection for non-http/1.1 request unless 'Connection: keep-alive' is set. - v := peekArgBytes(h.h, strConnection) - h.connectionClose = !hasHeaderValue(v, strKeepAlive) && !hasHeaderValue(v, strKeepAliveCamelCase) - } - - return len(buf) - len(s.b), nil -} - -func (h *RequestHeader) parseRawHeaders() { - if h.rawHeadersParsed { - return - } - h.rawHeadersParsed = true - if len(h.rawHeaders) == 0 { - return - } - h.parseHeaders(h.rawHeaders) -} - -func (h *RequestHeader) collectCookies() { - if h.cookiesCollected { - return - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - if bytes.Equal(kv.key, strCookie) { - h.cookies = parseRequestCookies(h.cookies, kv.value) - tmp := *kv - copy(h.h[i:], h.h[i+1:]) - n-- - i-- - h.h[n] = tmp - h.h = h.h[:n] - } - } - h.cookiesCollected = true -} - -func parseContentLength(b []byte) (int, error) { - v, n, err := parseUintBuf(b) - if err != nil { - return -1, err - } - if n != len(b) { - return -1, fmt.Errorf("non-numeric chars at the end of Content-Length") - } - return v, nil -} - -type headerScanner struct { - b []byte - key []byte - value []byte - err error - - disableNormalizing bool -} - -func (s *headerScanner) next() bool { - bLen := len(s.b) - if bLen >= 2 && s.b[0] == '\r' && s.b[1] == '\n' { - s.b = s.b[2:] - return false - } - if bLen >= 1 && s.b[0] == '\n' { - s.b = s.b[1:] - return false - } - n := bytes.IndexByte(s.b, ':') - if n < 0 { - s.err = errNeedMore - return false - } - s.key = s.b[:n] - normalizeHeaderKey(s.key, s.disableNormalizing) - n++ - for len(s.b) > n && s.b[n] == ' ' { - n++ - } - s.b = s.b[n:] - n = bytes.IndexByte(s.b, '\n') - if n < 0 { - s.err = errNeedMore - return false - } - s.value = s.b[:n] - s.b = s.b[n+1:] - - if n > 0 && s.value[n-1] == '\r' { - n-- - } - for n > 0 && s.value[n-1] == ' ' { - n-- - } - s.value = s.value[:n] - return true -} - -type headerValueScanner struct { - b []byte - value []byte -} - -func (s *headerValueScanner) next() bool { - b := s.b - if len(b) == 0 { - return false - } - n := bytes.IndexByte(b, ',') - if n < 0 { - s.value = stripSpace(b) - s.b = b[len(b):] - return true - } - s.value = stripSpace(b[:n]) - s.b = b[n+1:] - return true -} - -func stripSpace(b []byte) []byte { - for len(b) > 0 && b[0] == ' ' { - b = b[1:] - } - for len(b) > 0 && b[len(b)-1] == ' ' { - b = b[:len(b)-1] - } - return b -} - -func hasHeaderValue(s, value []byte) bool { - var vs headerValueScanner - vs.b = s - for vs.next() { - if bytes.Equal(vs.value, value) { - return true - } - } - return false -} - -func nextLine(b []byte) ([]byte, []byte, error) { - nNext := bytes.IndexByte(b, '\n') - if nNext < 0 { - return nil, nil, errNeedMore - } - n := nNext - if n > 0 && b[n-1] == '\r' { - n-- - } - return b[:n], b[nNext+1:], nil -} - -func initHeaderKV(kv *argsKV, key, value string, disableNormalizing bool) { - kv.key = getHeaderKeyBytes(kv, key, disableNormalizing) - kv.value = append(kv.value[:0], value...) -} - -func getHeaderKeyBytes(kv *argsKV, key string, disableNormalizing bool) []byte { - kv.key = append(kv.key[:0], key...) - normalizeHeaderKey(kv.key, disableNormalizing) - return kv.key -} - -func normalizeHeaderKey(b []byte, disableNormalizing bool) { - if disableNormalizing { - return - } - - n := len(b) - if n == 0 { - return - } - - b[0] = toUpperTable[b[0]] - for i := 1; i < n; i++ { - p := &b[i] - if *p == '-' { - i++ - if i < n { - b[i] = toUpperTable[b[i]] - } - continue - } - *p = toLowerTable[*p] - } -} - -// AppendNormalizedHeaderKey appends normalized header key (name) to dst -// and returns the resulting dst. -// -// Normalized header key starts with uppercase letter. The first letters -// after dashes are also uppercased. All the other letters are lowercased. -// Examples: -// -// * coNTENT-TYPe -> Content-Type -// * HOST -> Host -// * foo-bar-baz -> Foo-Bar-Baz -func AppendNormalizedHeaderKey(dst []byte, key string) []byte { - dst = append(dst, key...) - normalizeHeaderKey(dst[len(dst)-len(key):], false) - return dst -} - -// AppendNormalizedHeaderKeyBytes appends normalized header key (name) to dst -// and returns the resulting dst. -// -// Normalized header key starts with uppercase letter. The first letters -// after dashes are also uppercased. All the other letters are lowercased. -// Examples: -// -// * coNTENT-TYPe -> Content-Type -// * HOST -> Host -// * foo-bar-baz -> Foo-Bar-Baz -func AppendNormalizedHeaderKeyBytes(dst, key []byte) []byte { - return AppendNormalizedHeaderKey(dst, b2s(key)) -} - -var ( - errNeedMore = errors.New("need more data: cannot find trailing lf") - errSmallBuffer = errors.New("small read buffer. Increase ReadBufferSize") -) - -// ErrSmallBuffer is returned when the provided buffer size is too small -// for reading request and/or response headers. -// -// ReadBufferSize value from Server or clients should reduce the number -// of such errors. -type ErrSmallBuffer struct { - error -} - -func mustPeekBuffered(r *bufio.Reader) []byte { - buf, err := r.Peek(r.Buffered()) - if len(buf) == 0 || err != nil { - panic(fmt.Sprintf("bufio.Reader.Peek() returned unexpected data (%q, %v)", buf, err)) - } - return buf -} - -func mustDiscard(r *bufio.Reader, n int) { - if _, err := r.Discard(n); err != nil { - panic(fmt.Sprintf("bufio.Reader.Discard(%d) failed: %s", n, err)) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go deleted file mode 100644 index 95ade063..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go +++ /dev/null @@ -1,1714 +0,0 @@ -package fasthttp - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - "mime/multipart" - "os" - "sync" - - "github.com/valyala/bytebufferpool" -) - -// Request represents HTTP request. -// -// It is forbidden copying Request instances. Create new instances -// and use CopyTo instead. -// -// Request instance MUST NOT be used from concurrently running goroutines. -type Request struct { - noCopy noCopy - - // Request header - // - // Copying Header by value is forbidden. Use pointer to Header instead. - Header RequestHeader - - uri URI - postArgs Args - - bodyStream io.Reader - w requestBodyWriter - body *bytebufferpool.ByteBuffer - - multipartForm *multipart.Form - multipartFormBoundary string - - // Group bool members in order to reduce Request object size. - parsedURI bool - parsedPostArgs bool - - keepBodyBuffer bool - - isTLS bool -} - -// Response represents HTTP response. -// -// It is forbidden copying Response instances. Create new instances -// and use CopyTo instead. -// -// Response instance MUST NOT be used from concurrently running goroutines. -type Response struct { - noCopy noCopy - - // Response header - // - // Copying Header by value is forbidden. Use pointer to Header instead. - Header ResponseHeader - - bodyStream io.Reader - w responseBodyWriter - body *bytebufferpool.ByteBuffer - - // Response.Read() skips reading body if set to true. - // Use it for reading HEAD responses. - // - // Response.Write() skips writing body if set to true. - // Use it for writing HEAD responses. - SkipBody bool - - keepBodyBuffer bool -} - -// SetHost sets host for the request. -func (req *Request) SetHost(host string) { - req.URI().SetHost(host) -} - -// SetHostBytes sets host for the request. -func (req *Request) SetHostBytes(host []byte) { - req.URI().SetHostBytes(host) -} - -// Host returns the host for the given request. -func (req *Request) Host() []byte { - return req.URI().Host() -} - -// SetRequestURI sets RequestURI. -func (req *Request) SetRequestURI(requestURI string) { - req.Header.SetRequestURI(requestURI) - req.parsedURI = false -} - -// SetRequestURIBytes sets RequestURI. -func (req *Request) SetRequestURIBytes(requestURI []byte) { - req.Header.SetRequestURIBytes(requestURI) - req.parsedURI = false -} - -// RequestURI returns request's URI. -func (req *Request) RequestURI() []byte { - if req.parsedURI { - requestURI := req.uri.RequestURI() - req.SetRequestURIBytes(requestURI) - } - return req.Header.RequestURI() -} - -// StatusCode returns response status code. -func (resp *Response) StatusCode() int { - return resp.Header.StatusCode() -} - -// SetStatusCode sets response status code. -func (resp *Response) SetStatusCode(statusCode int) { - resp.Header.SetStatusCode(statusCode) -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (resp *Response) ConnectionClose() bool { - return resp.Header.ConnectionClose() -} - -// SetConnectionClose sets 'Connection: close' header. -func (resp *Response) SetConnectionClose() { - resp.Header.SetConnectionClose() -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (req *Request) ConnectionClose() bool { - return req.Header.ConnectionClose() -} - -// SetConnectionClose sets 'Connection: close' header. -func (req *Request) SetConnectionClose() { - req.Header.SetConnectionClose() -} - -// SendFile registers file on the given path to be used as response body -// when Write is called. -// -// Note that SendFile doesn't set Content-Type, so set it yourself -// with Header.SetContentType. -func (resp *Response) SendFile(path string) error { - f, err := os.Open(path) - if err != nil { - return err - } - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return err - } - size64 := fileInfo.Size() - size := int(size64) - if int64(size) != size64 { - size = -1 - } - - resp.Header.SetLastModified(fileInfo.ModTime()) - resp.SetBodyStream(f, size) - return nil -} - -// SetBodyStream sets request body stream and, optionally body size. -// -// If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// Note that GET and HEAD requests cannot have body. -// -// See also SetBodyStreamWriter. -func (req *Request) SetBodyStream(bodyStream io.Reader, bodySize int) { - req.ResetBody() - req.bodyStream = bodyStream - req.Header.SetContentLength(bodySize) -} - -// SetBodyStream sets response body stream and, optionally body size. -// -// If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// See also SetBodyStreamWriter. -func (resp *Response) SetBodyStream(bodyStream io.Reader, bodySize int) { - resp.ResetBody() - resp.bodyStream = bodyStream - resp.Header.SetContentLength(bodySize) -} - -// IsBodyStream returns true if body is set via SetBodyStream* -func (req *Request) IsBodyStream() bool { - return req.bodyStream != nil -} - -// IsBodyStream returns true if body is set via SetBodyStream* -func (resp *Response) IsBodyStream() bool { - return resp.bodyStream != nil -} - -// SetBodyStreamWriter registers the given sw for populating request body. -// -// This function may be used in the following cases: -// -// * if request body is too big (more than 10MB). -// * if request body is streamed from slow external sources. -// * if request body must be streamed to the server in chunks -// (aka `http client push` or `chunked transfer-encoding`). -// -// Note that GET and HEAD requests cannot have body. -// -/// See also SetBodyStream. -func (req *Request) SetBodyStreamWriter(sw StreamWriter) { - sr := NewStreamReader(sw) - req.SetBodyStream(sr, -1) -} - -// SetBodyStreamWriter registers the given sw for populating response body. -// -// This function may be used in the following cases: -// -// * if response body is too big (more than 10MB). -// * if response body is streamed from slow external sources. -// * if response body must be streamed to the client in chunks -// (aka `http server push` or `chunked transfer-encoding`). -// -// See also SetBodyStream. -func (resp *Response) SetBodyStreamWriter(sw StreamWriter) { - sr := NewStreamReader(sw) - resp.SetBodyStream(sr, -1) -} - -// BodyWriter returns writer for populating response body. -// -// If used inside RequestHandler, the returned writer must not be used -// after returning from RequestHandler. Use RequestCtx.Write -// or SetBodyStreamWriter in this case. -func (resp *Response) BodyWriter() io.Writer { - resp.w.r = resp - return &resp.w -} - -// BodyWriter returns writer for populating request body. -func (req *Request) BodyWriter() io.Writer { - req.w.r = req - return &req.w -} - -type responseBodyWriter struct { - r *Response -} - -func (w *responseBodyWriter) Write(p []byte) (int, error) { - w.r.AppendBody(p) - return len(p), nil -} - -type requestBodyWriter struct { - r *Request -} - -func (w *requestBodyWriter) Write(p []byte) (int, error) { - w.r.AppendBody(p) - return len(p), nil -} - -// Body returns response body. -// -// The returned body is valid until the response modification. -func (resp *Response) Body() []byte { - if resp.bodyStream != nil { - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - _, err := copyZeroAlloc(bodyBuf, resp.bodyStream) - resp.closeBodyStream() - if err != nil { - bodyBuf.SetString(err.Error()) - } - } - return resp.bodyBytes() -} - -func (resp *Response) bodyBytes() []byte { - if resp.body == nil { - return nil - } - return resp.body.B -} - -func (req *Request) bodyBytes() []byte { - if req.body == nil { - return nil - } - return req.body.B -} - -func (resp *Response) bodyBuffer() *bytebufferpool.ByteBuffer { - if resp.body == nil { - resp.body = responseBodyPool.Get() - } - return resp.body -} - -func (req *Request) bodyBuffer() *bytebufferpool.ByteBuffer { - if req.body == nil { - req.body = requestBodyPool.Get() - } - return req.body -} - -var ( - responseBodyPool bytebufferpool.Pool - requestBodyPool bytebufferpool.Pool -) - -// BodyGunzip returns un-gzipped body data. -// -// This method may be used if the request header contains -// 'Content-Encoding: gzip' for reading un-gzipped body. -// Use Body for reading gzipped request body. -func (req *Request) BodyGunzip() ([]byte, error) { - return gunzipData(req.Body()) -} - -// BodyGunzip returns un-gzipped body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: gzip' for reading un-gzipped body. -// Use Body for reading gzipped response body. -func (resp *Response) BodyGunzip() ([]byte, error) { - return gunzipData(resp.Body()) -} - -func gunzipData(p []byte) ([]byte, error) { - var bb ByteBuffer - _, err := WriteGunzip(&bb, p) - if err != nil { - return nil, err - } - return bb.B, nil -} - -// BodyInflate returns inflated body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: deflate' for reading inflated request body. -// Use Body for reading deflated request body. -func (req *Request) BodyInflate() ([]byte, error) { - return inflateData(req.Body()) -} - -// BodyInflate returns inflated body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: deflate' for reading inflated response body. -// Use Body for reading deflated response body. -func (resp *Response) BodyInflate() ([]byte, error) { - return inflateData(resp.Body()) -} - -func inflateData(p []byte) ([]byte, error) { - var bb ByteBuffer - _, err := WriteInflate(&bb, p) - if err != nil { - return nil, err - } - return bb.B, nil -} - -// BodyWriteTo writes request body to w. -func (req *Request) BodyWriteTo(w io.Writer) error { - if req.bodyStream != nil { - _, err := copyZeroAlloc(w, req.bodyStream) - req.closeBodyStream() - return err - } - if req.onlyMultipartForm() { - return WriteMultipartForm(w, req.multipartForm, req.multipartFormBoundary) - } - _, err := w.Write(req.bodyBytes()) - return err -} - -// BodyWriteTo writes response body to w. -func (resp *Response) BodyWriteTo(w io.Writer) error { - if resp.bodyStream != nil { - _, err := copyZeroAlloc(w, resp.bodyStream) - resp.closeBodyStream() - return err - } - _, err := w.Write(resp.bodyBytes()) - return err -} - -// AppendBody appends p to response body. -// -// It is safe re-using p after the function returns. -func (resp *Response) AppendBody(p []byte) { - resp.AppendBodyString(b2s(p)) -} - -// AppendBodyString appends s to response body. -func (resp *Response) AppendBodyString(s string) { - resp.closeBodyStream() - resp.bodyBuffer().WriteString(s) -} - -// SetBody sets response body. -// -// It is safe re-using body argument after the function returns. -func (resp *Response) SetBody(body []byte) { - resp.SetBodyString(b2s(body)) -} - -// SetBodyString sets response body. -func (resp *Response) SetBodyString(body string) { - resp.closeBodyStream() - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - bodyBuf.WriteString(body) -} - -// ResetBody resets response body. -func (resp *Response) ResetBody() { - resp.closeBodyStream() - if resp.body != nil { - if resp.keepBodyBuffer { - resp.body.Reset() - } else { - responseBodyPool.Put(resp.body) - resp.body = nil - } - } -} - -// ReleaseBody retires the response body if it is greater than "size" bytes. -// -// This permits GC to reclaim the large buffer. If used, must be before -// ReleaseResponse. -// -// Use this method only if you really understand how it works. -// The majority of workloads don't need this method. -func (resp *Response) ReleaseBody(size int) { - if cap(resp.body.B) > size { - resp.closeBodyStream() - resp.body = nil - } -} - -// ReleaseBody retires the request body if it is greater than "size" bytes. -// -// This permits GC to reclaim the large buffer. If used, must be before -// ReleaseRequest. -// -// Use this method only if you really understand how it works. -// The majority of workloads don't need this method. -func (req *Request) ReleaseBody(size int) { - if cap(req.body.B) > size { - req.closeBodyStream() - req.body = nil - } -} - -// SwapBody swaps response body with the given body and returns -// the previous response body. -// -// It is forbidden to use the body passed to SwapBody after -// the function returns. -func (resp *Response) SwapBody(body []byte) []byte { - bb := resp.bodyBuffer() - - if resp.bodyStream != nil { - bb.Reset() - _, err := copyZeroAlloc(bb, resp.bodyStream) - resp.closeBodyStream() - if err != nil { - bb.Reset() - bb.SetString(err.Error()) - } - } - - oldBody := bb.B - bb.B = body - return oldBody -} - -// SwapBody swaps request body with the given body and returns -// the previous request body. -// -// It is forbidden to use the body passed to SwapBody after -// the function returns. -func (req *Request) SwapBody(body []byte) []byte { - bb := req.bodyBuffer() - - if req.bodyStream != nil { - bb.Reset() - _, err := copyZeroAlloc(bb, req.bodyStream) - req.closeBodyStream() - if err != nil { - bb.Reset() - bb.SetString(err.Error()) - } - } - - oldBody := bb.B - bb.B = body - return oldBody -} - -// Body returns request body. -// -// The returned body is valid until the request modification. -func (req *Request) Body() []byte { - if req.bodyStream != nil { - bodyBuf := req.bodyBuffer() - bodyBuf.Reset() - _, err := copyZeroAlloc(bodyBuf, req.bodyStream) - req.closeBodyStream() - if err != nil { - bodyBuf.SetString(err.Error()) - } - } else if req.onlyMultipartForm() { - body, err := marshalMultipartForm(req.multipartForm, req.multipartFormBoundary) - if err != nil { - return []byte(err.Error()) - } - return body - } - return req.bodyBytes() -} - -// AppendBody appends p to request body. -// -// It is safe re-using p after the function returns. -func (req *Request) AppendBody(p []byte) { - req.AppendBodyString(b2s(p)) -} - -// AppendBodyString appends s to request body. -func (req *Request) AppendBodyString(s string) { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - req.bodyBuffer().WriteString(s) -} - -// SetBody sets request body. -// -// It is safe re-using body argument after the function returns. -func (req *Request) SetBody(body []byte) { - req.SetBodyString(b2s(body)) -} - -// SetBodyString sets request body. -func (req *Request) SetBodyString(body string) { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - req.bodyBuffer().SetString(body) -} - -// ResetBody resets request body. -func (req *Request) ResetBody() { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - if req.body != nil { - if req.keepBodyBuffer { - req.body.Reset() - } else { - requestBodyPool.Put(req.body) - req.body = nil - } - } -} - -// CopyTo copies req contents to dst except of body stream. -func (req *Request) CopyTo(dst *Request) { - req.copyToSkipBody(dst) - if req.body != nil { - dst.bodyBuffer().Set(req.body.B) - } else if dst.body != nil { - dst.body.Reset() - } -} - -func (req *Request) copyToSkipBody(dst *Request) { - dst.Reset() - req.Header.CopyTo(&dst.Header) - - req.uri.CopyTo(&dst.uri) - dst.parsedURI = req.parsedURI - - req.postArgs.CopyTo(&dst.postArgs) - dst.parsedPostArgs = req.parsedPostArgs - dst.isTLS = req.isTLS - - // do not copy multipartForm - it will be automatically - // re-created on the first call to MultipartForm. -} - -// CopyTo copies resp contents to dst except of body stream. -func (resp *Response) CopyTo(dst *Response) { - resp.copyToSkipBody(dst) - if resp.body != nil { - dst.bodyBuffer().Set(resp.body.B) - } else if dst.body != nil { - dst.body.Reset() - } -} - -func (resp *Response) copyToSkipBody(dst *Response) { - dst.Reset() - resp.Header.CopyTo(&dst.Header) - dst.SkipBody = resp.SkipBody -} - -func swapRequestBody(a, b *Request) { - a.body, b.body = b.body, a.body - a.bodyStream, b.bodyStream = b.bodyStream, a.bodyStream -} - -func swapResponseBody(a, b *Response) { - a.body, b.body = b.body, a.body - a.bodyStream, b.bodyStream = b.bodyStream, a.bodyStream -} - -// URI returns request URI -func (req *Request) URI() *URI { - req.parseURI() - return &req.uri -} - -func (req *Request) parseURI() { - if req.parsedURI { - return - } - req.parsedURI = true - - req.uri.parseQuick(req.Header.RequestURI(), &req.Header, req.isTLS) -} - -// PostArgs returns POST arguments. -func (req *Request) PostArgs() *Args { - req.parsePostArgs() - return &req.postArgs -} - -func (req *Request) parsePostArgs() { - if req.parsedPostArgs { - return - } - req.parsedPostArgs = true - - if !bytes.HasPrefix(req.Header.ContentType(), strPostArgsContentType) { - return - } - req.postArgs.ParseBytes(req.bodyBytes()) -} - -// ErrNoMultipartForm means that the request's Content-Type -// isn't 'multipart/form-data'. -var ErrNoMultipartForm = errors.New("request has no multipart/form-data Content-Type") - -// MultipartForm returns requests's multipart form. -// -// Returns ErrNoMultipartForm if request's Content-Type -// isn't 'multipart/form-data'. -// -// RemoveMultipartFormFiles must be called after returned multipart form -// is processed. -func (req *Request) MultipartForm() (*multipart.Form, error) { - if req.multipartForm != nil { - return req.multipartForm, nil - } - - req.multipartFormBoundary = string(req.Header.MultipartFormBoundary()) - if len(req.multipartFormBoundary) == 0 { - return nil, ErrNoMultipartForm - } - - ce := req.Header.peek(strContentEncoding) - body := req.bodyBytes() - if bytes.Equal(ce, strGzip) { - // Do not care about memory usage here. - var err error - if body, err = AppendGunzipBytes(nil, body); err != nil { - return nil, fmt.Errorf("cannot gunzip request body: %s", err) - } - } else if len(ce) > 0 { - return nil, fmt.Errorf("unsupported Content-Encoding: %q", ce) - } - - f, err := readMultipartForm(bytes.NewReader(body), req.multipartFormBoundary, len(body), len(body)) - if err != nil { - return nil, err - } - req.multipartForm = f - return f, nil -} - -func marshalMultipartForm(f *multipart.Form, boundary string) ([]byte, error) { - var buf ByteBuffer - if err := WriteMultipartForm(&buf, f, boundary); err != nil { - return nil, err - } - return buf.B, nil -} - -// WriteMultipartForm writes the given multipart form f with the given -// boundary to w. -func WriteMultipartForm(w io.Writer, f *multipart.Form, boundary string) error { - // Do not care about memory allocations here, since multipart - // form processing is slow. - if len(boundary) == 0 { - panic("BUG: form boundary cannot be empty") - } - - mw := multipart.NewWriter(w) - if err := mw.SetBoundary(boundary); err != nil { - return fmt.Errorf("cannot use form boundary %q: %s", boundary, err) - } - - // marshal values - for k, vv := range f.Value { - for _, v := range vv { - if err := mw.WriteField(k, v); err != nil { - return fmt.Errorf("cannot write form field %q value %q: %s", k, v, err) - } - } - } - - // marshal files - for k, fvv := range f.File { - for _, fv := range fvv { - vw, err := mw.CreateFormFile(k, fv.Filename) - if err != nil { - return fmt.Errorf("cannot create form file %q (%q): %s", k, fv.Filename, err) - } - fh, err := fv.Open() - if err != nil { - return fmt.Errorf("cannot open form file %q (%q): %s", k, fv.Filename, err) - } - if _, err = copyZeroAlloc(vw, fh); err != nil { - return fmt.Errorf("error when copying form file %q (%q): %s", k, fv.Filename, err) - } - if err = fh.Close(); err != nil { - return fmt.Errorf("cannot close form file %q (%q): %s", k, fv.Filename, err) - } - } - } - - if err := mw.Close(); err != nil { - return fmt.Errorf("error when closing multipart form writer: %s", err) - } - - return nil -} - -func readMultipartForm(r io.Reader, boundary string, size, maxInMemoryFileSize int) (*multipart.Form, error) { - // Do not care about memory allocations here, since they are tiny - // compared to multipart data (aka multi-MB files) usually sent - // in multipart/form-data requests. - - if size <= 0 { - panic(fmt.Sprintf("BUG: form size must be greater than 0. Given %d", size)) - } - lr := io.LimitReader(r, int64(size)) - mr := multipart.NewReader(lr, boundary) - f, err := mr.ReadForm(int64(maxInMemoryFileSize)) - if err != nil { - return nil, fmt.Errorf("cannot read multipart/form-data body: %s", err) - } - return f, nil -} - -// Reset clears request contents. -func (req *Request) Reset() { - req.Header.Reset() - req.resetSkipHeader() -} - -func (req *Request) resetSkipHeader() { - req.ResetBody() - req.uri.Reset() - req.parsedURI = false - req.postArgs.Reset() - req.parsedPostArgs = false - req.isTLS = false -} - -// RemoveMultipartFormFiles removes multipart/form-data temporary files -// associated with the request. -func (req *Request) RemoveMultipartFormFiles() { - if req.multipartForm != nil { - // Do not check for error, since these files may be deleted or moved - // to new places by user code. - req.multipartForm.RemoveAll() - req.multipartForm = nil - } - req.multipartFormBoundary = "" -} - -// Reset clears response contents. -func (resp *Response) Reset() { - resp.Header.Reset() - resp.resetSkipHeader() - resp.SkipBody = false -} - -func (resp *Response) resetSkipHeader() { - resp.ResetBody() -} - -// Read reads request (including body) from the given r. -// -// RemoveMultipartFormFiles or Reset must be called after -// reading multipart/form-data request in order to delete temporarily -// uploaded files. -// -// If MayContinue returns true, the caller must: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (req *Request) Read(r *bufio.Reader) error { - return req.ReadLimitBody(r, 0) -} - -const defaultMaxInMemoryFileSize = 16 * 1024 * 1024 - -var errGetOnly = errors.New("non-GET request received") - -// ReadLimitBody reads request from the given r, limiting the body size. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -// -// RemoveMultipartFormFiles or Reset must be called after -// reading multipart/form-data request in order to delete temporarily -// uploaded files. -// -// If MayContinue returns true, the caller must: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (req *Request) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { - req.resetSkipHeader() - return req.readLimitBody(r, maxBodySize, false) -} - -func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool) error { - // Do not reset the request here - the caller must reset it before - // calling this method. - - err := req.Header.Read(r) - if err != nil { - return err - } - if getOnly && !req.Header.IsGet() { - return errGetOnly - } - - if req.Header.noBody() { - return nil - } - - if req.MayContinue() { - // 'Expect: 100-continue' header found. Let the caller deciding - // whether to read request body or - // to return StatusExpectationFailed. - return nil - } - - return req.ContinueReadBody(r, maxBodySize) -} - -// MayContinue returns true if the request contains -// 'Expect: 100-continue' header. -// -// The caller must do one of the following actions if MayContinue returns true: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -func (req *Request) MayContinue() bool { - return bytes.Equal(req.Header.peek(strExpect), str100Continue) -} - -// ContinueReadBody reads request body if request header contains -// 'Expect: 100-continue'. -// -// The caller must send StatusContinue response before calling this method. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -func (req *Request) ContinueReadBody(r *bufio.Reader, maxBodySize int) error { - var err error - contentLength := req.Header.ContentLength() - if contentLength > 0 { - if maxBodySize > 0 && contentLength > maxBodySize { - return ErrBodyTooLarge - } - - // Pre-read multipart form data of known length. - // This way we limit memory usage for large file uploads, since their contents - // is streamed into temporary files if file size exceeds defaultMaxInMemoryFileSize. - req.multipartFormBoundary = string(req.Header.MultipartFormBoundary()) - if len(req.multipartFormBoundary) > 0 && len(req.Header.peek(strContentEncoding)) == 0 { - req.multipartForm, err = readMultipartForm(r, req.multipartFormBoundary, contentLength, defaultMaxInMemoryFileSize) - if err != nil { - req.Reset() - } - return err - } - } - - if contentLength == -2 { - // identity body has no sense for http requests, since - // the end of body is determined by connection close. - // So just ignore request body for requests without - // 'Content-Length' and 'Transfer-Encoding' headers. - req.Header.SetContentLength(0) - return nil - } - - bodyBuf := req.bodyBuffer() - bodyBuf.Reset() - bodyBuf.B, err = readBody(r, contentLength, maxBodySize, bodyBuf.B) - if err != nil { - req.Reset() - return err - } - req.Header.SetContentLength(len(bodyBuf.B)) - return nil -} - -// Read reads response (including body) from the given r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (resp *Response) Read(r *bufio.Reader) error { - return resp.ReadLimitBody(r, 0) -} - -// ReadLimitBody reads response from the given r, limiting the body size. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (resp *Response) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { - resp.resetSkipHeader() - err := resp.Header.Read(r) - if err != nil { - return err - } - if resp.Header.StatusCode() == StatusContinue { - // Read the next response according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html . - if err = resp.Header.Read(r); err != nil { - return err - } - } - - if !resp.mustSkipBody() { - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - bodyBuf.B, err = readBody(r, resp.Header.ContentLength(), maxBodySize, bodyBuf.B) - if err != nil { - resp.Reset() - return err - } - resp.Header.SetContentLength(len(bodyBuf.B)) - } - return nil -} - -func (resp *Response) mustSkipBody() bool { - return resp.SkipBody || resp.Header.mustSkipContentLength() -} - -var errRequestHostRequired = errors.New("missing required Host header in request") - -// WriteTo writes request to w. It implements io.WriterTo. -func (req *Request) WriteTo(w io.Writer) (int64, error) { - return writeBufio(req, w) -} - -// WriteTo writes response to w. It implements io.WriterTo. -func (resp *Response) WriteTo(w io.Writer) (int64, error) { - return writeBufio(resp, w) -} - -func writeBufio(hw httpWriter, w io.Writer) (int64, error) { - sw := acquireStatsWriter(w) - bw := acquireBufioWriter(sw) - err1 := hw.Write(bw) - err2 := bw.Flush() - releaseBufioWriter(bw) - n := sw.bytesWritten - releaseStatsWriter(sw) - - err := err1 - if err == nil { - err = err2 - } - return n, err -} - -type statsWriter struct { - w io.Writer - bytesWritten int64 -} - -func (w *statsWriter) Write(p []byte) (int, error) { - n, err := w.w.Write(p) - w.bytesWritten += int64(n) - return n, err -} - -func acquireStatsWriter(w io.Writer) *statsWriter { - v := statsWriterPool.Get() - if v == nil { - return &statsWriter{ - w: w, - } - } - sw := v.(*statsWriter) - sw.w = w - return sw -} - -func releaseStatsWriter(sw *statsWriter) { - sw.w = nil - sw.bytesWritten = 0 - statsWriterPool.Put(sw) -} - -var statsWriterPool sync.Pool - -func acquireBufioWriter(w io.Writer) *bufio.Writer { - v := bufioWriterPool.Get() - if v == nil { - return bufio.NewWriter(w) - } - bw := v.(*bufio.Writer) - bw.Reset(w) - return bw -} - -func releaseBufioWriter(bw *bufio.Writer) { - bufioWriterPool.Put(bw) -} - -var bufioWriterPool sync.Pool - -func (req *Request) onlyMultipartForm() bool { - return req.multipartForm != nil && (req.body == nil || len(req.body.B) == 0) -} - -// Write writes request to w. -// -// Write doesn't flush request to w for performance reasons. -// -// See also WriteTo. -func (req *Request) Write(w *bufio.Writer) error { - if len(req.Header.Host()) == 0 || req.parsedURI { - uri := req.URI() - host := uri.Host() - if len(host) == 0 { - return errRequestHostRequired - } - req.Header.SetHostBytes(host) - req.Header.SetRequestURIBytes(uri.RequestURI()) - } - - if req.bodyStream != nil { - return req.writeBodyStream(w) - } - - body := req.bodyBytes() - var err error - if req.onlyMultipartForm() { - body, err = marshalMultipartForm(req.multipartForm, req.multipartFormBoundary) - if err != nil { - return fmt.Errorf("error when marshaling multipart form: %s", err) - } - req.Header.SetMultipartFormBoundary(req.multipartFormBoundary) - } - - hasBody := !req.Header.noBody() - if hasBody { - req.Header.SetContentLength(len(body)) - } - if err = req.Header.Write(w); err != nil { - return err - } - if hasBody { - _, err = w.Write(body) - } else if len(body) > 0 { - return fmt.Errorf("non-zero body for non-POST request. body=%q", body) - } - return err -} - -// WriteGzip writes response with gzipped body to w. -// -// The method gzips response body and sets 'Content-Encoding: gzip' -// header before writing response to w. -// -// WriteGzip doesn't flush response to w for performance reasons. -func (resp *Response) WriteGzip(w *bufio.Writer) error { - return resp.WriteGzipLevel(w, CompressDefaultCompression) -} - -// WriteGzipLevel writes response with gzipped body to w. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -// -// The method gzips response body and sets 'Content-Encoding: gzip' -// header before writing response to w. -// -// WriteGzipLevel doesn't flush response to w for performance reasons. -func (resp *Response) WriteGzipLevel(w *bufio.Writer, level int) error { - if err := resp.gzipBody(level); err != nil { - return err - } - return resp.Write(w) -} - -// WriteDeflate writes response with deflated body to w. -// -// The method deflates response body and sets 'Content-Encoding: deflate' -// header before writing response to w. -// -// WriteDeflate doesn't flush response to w for performance reasons. -func (resp *Response) WriteDeflate(w *bufio.Writer) error { - return resp.WriteDeflateLevel(w, CompressDefaultCompression) -} - -// WriteDeflateLevel writes response with deflated body to w. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -// -// The method deflates response body and sets 'Content-Encoding: deflate' -// header before writing response to w. -// -// WriteDeflateLevel doesn't flush response to w for performance reasons. -func (resp *Response) WriteDeflateLevel(w *bufio.Writer, level int) error { - if err := resp.deflateBody(level); err != nil { - return err - } - return resp.Write(w) -} - -func (resp *Response) gzipBody(level int) error { - if len(resp.Header.peek(strContentEncoding)) > 0 { - // It looks like the body is already compressed. - // Do not compress it again. - return nil - } - - if !resp.Header.isCompressibleContentType() { - // The content-type cannot be compressed. - return nil - } - - if resp.bodyStream != nil { - // Reset Content-Length to -1, since it is impossible - // to determine body size beforehand of streamed compression. - // For https://github.com/valyala/fasthttp/issues/176 . - resp.Header.SetContentLength(-1) - - // Do not care about memory allocations here, since gzip is slow - // and allocates a lot of memory by itself. - bs := resp.bodyStream - resp.bodyStream = NewStreamReader(func(sw *bufio.Writer) { - zw := acquireStacklessGzipWriter(sw, level) - fw := &flushWriter{ - wf: zw, - bw: sw, - } - copyZeroAlloc(fw, bs) - releaseStacklessGzipWriter(zw, level) - if bsc, ok := bs.(io.Closer); ok { - bsc.Close() - } - }) - } else { - bodyBytes := resp.bodyBytes() - if len(bodyBytes) < minCompressLen { - // There is no sense in spending CPU time on small body compression, - // since there is a very high probability that the compressed - // body size will be bigger than the original body size. - return nil - } - w := responseBodyPool.Get() - w.B = AppendGzipBytesLevel(w.B, bodyBytes, level) - - // Hack: swap resp.body with w. - if resp.body != nil { - responseBodyPool.Put(resp.body) - } - resp.body = w - } - resp.Header.SetCanonical(strContentEncoding, strGzip) - return nil -} - -func (resp *Response) deflateBody(level int) error { - if len(resp.Header.peek(strContentEncoding)) > 0 { - // It looks like the body is already compressed. - // Do not compress it again. - return nil - } - - if !resp.Header.isCompressibleContentType() { - // The content-type cannot be compressed. - return nil - } - - if resp.bodyStream != nil { - // Reset Content-Length to -1, since it is impossible - // to determine body size beforehand of streamed compression. - // For https://github.com/valyala/fasthttp/issues/176 . - resp.Header.SetContentLength(-1) - - // Do not care about memory allocations here, since flate is slow - // and allocates a lot of memory by itself. - bs := resp.bodyStream - resp.bodyStream = NewStreamReader(func(sw *bufio.Writer) { - zw := acquireStacklessDeflateWriter(sw, level) - fw := &flushWriter{ - wf: zw, - bw: sw, - } - copyZeroAlloc(fw, bs) - releaseStacklessDeflateWriter(zw, level) - if bsc, ok := bs.(io.Closer); ok { - bsc.Close() - } - }) - } else { - bodyBytes := resp.bodyBytes() - if len(bodyBytes) < minCompressLen { - // There is no sense in spending CPU time on small body compression, - // since there is a very high probability that the compressed - // body size will be bigger than the original body size. - return nil - } - w := responseBodyPool.Get() - w.B = AppendDeflateBytesLevel(w.B, bodyBytes, level) - - // Hack: swap resp.body with w. - if resp.body != nil { - responseBodyPool.Put(resp.body) - } - resp.body = w - } - resp.Header.SetCanonical(strContentEncoding, strDeflate) - return nil -} - -// Bodies with sizes smaller than minCompressLen aren't compressed at all -const minCompressLen = 200 - -type writeFlusher interface { - io.Writer - Flush() error -} - -type flushWriter struct { - wf writeFlusher - bw *bufio.Writer -} - -func (w *flushWriter) Write(p []byte) (int, error) { - n, err := w.wf.Write(p) - if err != nil { - return 0, err - } - if err = w.wf.Flush(); err != nil { - return 0, err - } - if err = w.bw.Flush(); err != nil { - return 0, err - } - return n, nil -} - -// Write writes response to w. -// -// Write doesn't flush response to w for performance reasons. -// -// See also WriteTo. -func (resp *Response) Write(w *bufio.Writer) error { - sendBody := !resp.mustSkipBody() - - if resp.bodyStream != nil { - return resp.writeBodyStream(w, sendBody) - } - - body := resp.bodyBytes() - bodyLen := len(body) - if sendBody || bodyLen > 0 { - resp.Header.SetContentLength(bodyLen) - } - if err := resp.Header.Write(w); err != nil { - return err - } - if sendBody { - if _, err := w.Write(body); err != nil { - return err - } - } - return nil -} - -func (req *Request) writeBodyStream(w *bufio.Writer) error { - var err error - - contentLength := req.Header.ContentLength() - if contentLength < 0 { - lrSize := limitedReaderSize(req.bodyStream) - if lrSize >= 0 { - contentLength = int(lrSize) - if int64(contentLength) != lrSize { - contentLength = -1 - } - if contentLength >= 0 { - req.Header.SetContentLength(contentLength) - } - } - } - if contentLength >= 0 { - if err = req.Header.Write(w); err == nil { - err = writeBodyFixedSize(w, req.bodyStream, int64(contentLength)) - } - } else { - req.Header.SetContentLength(-1) - if err = req.Header.Write(w); err == nil { - err = writeBodyChunked(w, req.bodyStream) - } - } - err1 := req.closeBodyStream() - if err == nil { - err = err1 - } - return err -} - -func (resp *Response) writeBodyStream(w *bufio.Writer, sendBody bool) error { - var err error - - contentLength := resp.Header.ContentLength() - if contentLength < 0 { - lrSize := limitedReaderSize(resp.bodyStream) - if lrSize >= 0 { - contentLength = int(lrSize) - if int64(contentLength) != lrSize { - contentLength = -1 - } - if contentLength >= 0 { - resp.Header.SetContentLength(contentLength) - } - } - } - if contentLength >= 0 { - if err = resp.Header.Write(w); err == nil && sendBody { - err = writeBodyFixedSize(w, resp.bodyStream, int64(contentLength)) - } - } else { - resp.Header.SetContentLength(-1) - if err = resp.Header.Write(w); err == nil && sendBody { - err = writeBodyChunked(w, resp.bodyStream) - } - } - err1 := resp.closeBodyStream() - if err == nil { - err = err1 - } - return err -} - -func (req *Request) closeBodyStream() error { - if req.bodyStream == nil { - return nil - } - var err error - if bsc, ok := req.bodyStream.(io.Closer); ok { - err = bsc.Close() - } - req.bodyStream = nil - return err -} - -func (resp *Response) closeBodyStream() error { - if resp.bodyStream == nil { - return nil - } - var err error - if bsc, ok := resp.bodyStream.(io.Closer); ok { - err = bsc.Close() - } - resp.bodyStream = nil - return err -} - -// String returns request representation. -// -// Returns error message instead of request representation on error. -// -// Use Write instead of String for performance-critical code. -func (req *Request) String() string { - return getHTTPString(req) -} - -// String returns response representation. -// -// Returns error message instead of response representation on error. -// -// Use Write instead of String for performance-critical code. -func (resp *Response) String() string { - return getHTTPString(resp) -} - -func getHTTPString(hw httpWriter) string { - w := AcquireByteBuffer() - bw := bufio.NewWriter(w) - if err := hw.Write(bw); err != nil { - return err.Error() - } - if err := bw.Flush(); err != nil { - return err.Error() - } - s := string(w.B) - ReleaseByteBuffer(w) - return s -} - -type httpWriter interface { - Write(w *bufio.Writer) error -} - -func writeBodyChunked(w *bufio.Writer, r io.Reader) error { - vbuf := copyBufPool.Get() - buf := vbuf.([]byte) - - var err error - var n int - for { - n, err = r.Read(buf) - if n == 0 { - if err == nil { - panic("BUG: io.Reader returned 0, nil") - } - if err == io.EOF { - if err = writeChunk(w, buf[:0]); err != nil { - break - } - err = nil - } - break - } - if err = writeChunk(w, buf[:n]); err != nil { - break - } - } - - copyBufPool.Put(vbuf) - return err -} - -func limitedReaderSize(r io.Reader) int64 { - lr, ok := r.(*io.LimitedReader) - if !ok { - return -1 - } - return lr.N -} - -func writeBodyFixedSize(w *bufio.Writer, r io.Reader, size int64) error { - if size > maxSmallFileSize { - // w buffer must be empty for triggering - // sendfile path in bufio.Writer.ReadFrom. - if err := w.Flush(); err != nil { - return err - } - } - - // Unwrap a single limited reader for triggering sendfile path - // in net.TCPConn.ReadFrom. - lr, ok := r.(*io.LimitedReader) - if ok { - r = lr.R - } - - n, err := copyZeroAlloc(w, r) - - if ok { - lr.N -= n - } - - if n != size && err == nil { - err = fmt.Errorf("copied %d bytes from body stream instead of %d bytes", n, size) - } - return err -} - -func copyZeroAlloc(w io.Writer, r io.Reader) (int64, error) { - vbuf := copyBufPool.Get() - buf := vbuf.([]byte) - n, err := io.CopyBuffer(w, r, buf) - copyBufPool.Put(vbuf) - return n, err -} - -var copyBufPool = sync.Pool{ - New: func() interface{} { - return make([]byte, 4096) - }, -} - -func writeChunk(w *bufio.Writer, b []byte) error { - n := len(b) - writeHexInt(w, n) - w.Write(strCRLF) - w.Write(b) - _, err := w.Write(strCRLF) - err1 := w.Flush() - if err == nil { - err = err1 - } - return err -} - -// ErrBodyTooLarge is returned if either request or response body exceeds -// the given limit. -var ErrBodyTooLarge = errors.New("body size exceeds the given limit") - -func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) { - dst = dst[:0] - if contentLength >= 0 { - if maxBodySize > 0 && contentLength > maxBodySize { - return dst, ErrBodyTooLarge - } - return appendBodyFixedSize(r, dst, contentLength) - } - if contentLength == -1 { - return readBodyChunked(r, maxBodySize, dst) - } - return readBodyIdentity(r, maxBodySize, dst) -} - -func readBodyIdentity(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, error) { - dst = dst[:cap(dst)] - if len(dst) == 0 { - dst = make([]byte, 1024) - } - offset := 0 - for { - nn, err := r.Read(dst[offset:]) - if nn <= 0 { - if err != nil { - if err == io.EOF { - return dst[:offset], nil - } - return dst[:offset], err - } - panic(fmt.Sprintf("BUG: bufio.Read() returned (%d, nil)", nn)) - } - offset += nn - if maxBodySize > 0 && offset > maxBodySize { - return dst[:offset], ErrBodyTooLarge - } - if len(dst) == offset { - n := round2(2 * offset) - if maxBodySize > 0 && n > maxBodySize { - n = maxBodySize + 1 - } - b := make([]byte, n) - copy(b, dst) - dst = b - } - } -} - -func appendBodyFixedSize(r *bufio.Reader, dst []byte, n int) ([]byte, error) { - if n == 0 { - return dst, nil - } - - offset := len(dst) - dstLen := offset + n - if cap(dst) < dstLen { - b := make([]byte, round2(dstLen)) - copy(b, dst) - dst = b - } - dst = dst[:dstLen] - - for { - nn, err := r.Read(dst[offset:]) - if nn <= 0 { - if err != nil { - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - return dst[:offset], err - } - panic(fmt.Sprintf("BUG: bufio.Read() returned (%d, nil)", nn)) - } - offset += nn - if offset == dstLen { - return dst, nil - } - } -} - -func readBodyChunked(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, error) { - if len(dst) > 0 { - panic("BUG: expected zero-length buffer") - } - - strCRLFLen := len(strCRLF) - for { - chunkSize, err := parseChunkSize(r) - if err != nil { - return dst, err - } - if maxBodySize > 0 && len(dst)+chunkSize > maxBodySize { - return dst, ErrBodyTooLarge - } - dst, err = appendBodyFixedSize(r, dst, chunkSize+strCRLFLen) - if err != nil { - return dst, err - } - if !bytes.Equal(dst[len(dst)-strCRLFLen:], strCRLF) { - return dst, fmt.Errorf("cannot find crlf at the end of chunk") - } - dst = dst[:len(dst)-strCRLFLen] - if chunkSize == 0 { - return dst, nil - } - } -} - -func parseChunkSize(r *bufio.Reader) (int, error) { - n, err := readHexInt(r) - if err != nil { - return -1, err - } - c, err := r.ReadByte() - if err != nil { - return -1, fmt.Errorf("cannot read '\r' char at the end of chunk size: %s", err) - } - if c != '\r' { - return -1, fmt.Errorf("unexpected char %q at the end of chunk size. Expected %q", c, '\r') - } - c, err = r.ReadByte() - if err != nil { - return -1, fmt.Errorf("cannot read '\n' char at the end of chunk size: %s", err) - } - if c != '\n' { - return -1, fmt.Errorf("unexpected char %q at the end of chunk size. Expected %q", c, '\n') - } - return n, nil -} - -func round2(n int) int { - if n <= 0 { - return 0 - } - n-- - x := uint(0) - for n > 0 { - n >>= 1 - x++ - } - return 1 << x -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go deleted file mode 100644 index 200ae512..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go +++ /dev/null @@ -1,35 +0,0 @@ -package pprofhandler - -import ( - "net/http/pprof" - "strings" - - "github.com/valyala/fasthttp" - "github.com/valyala/fasthttp/fasthttpadaptor" -) - -var ( - cmdline = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Cmdline) - profile = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Profile) - symbol = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Symbol) - trace = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Trace) - index = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Index) -) - -// PprofHandler serves server runtime profiling data in the format expected by the pprof visualization tool. -// -// See https://golang.org/pkg/net/http/pprof/ for details. -func PprofHandler(ctx *fasthttp.RequestCtx) { - ctx.Response.Header.Set("Content-Type", "text/html") - if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/cmdline") { - cmdline(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/profile") { - profile(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/symbol") { - symbol(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/trace") { - trace(ctx) - } else { - index(ctx) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE deleted file mode 100644 index 5f25159a..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Max Riveiro - -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/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go deleted file mode 100644 index 191fe641..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go +++ /dev/null @@ -1,57 +0,0 @@ -// +build linux darwin dragonfly freebsd netbsd openbsd rumprun - -// Package reuseport provides TCP net.Listener with SO_REUSEPORT support. -// -// SO_REUSEPORT allows linear scaling server performance on multi-CPU servers. -// See https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ for more details :) -// -// The package is based on https://github.com/kavu/go_reuseport . -package reuseport - -import ( - "fmt" - "net" - "strings" - - "github.com/valyala/tcplisten" -) - -// ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT. -type ErrNoReusePort struct { - err error -} - -// Error implements error interface. -func (e *ErrNoReusePort) Error() string { - return fmt.Sprintf("The OS doesn't support SO_REUSEPORT: %s", e.err) -} - -// Listen returns TCP listener with SO_REUSEPORT option set. -// -// The returned listener tries enabling the following TCP options, which usually -// have positive impact on performance: -// -// - TCP_DEFER_ACCEPT. This option expects that the server reads from accepted -// connections before writing to them. -// -// - TCP_FASTOPEN. See https://lwn.net/Articles/508865/ for details. -// -// Use https://github.com/valyala/tcplisten if you want customizing -// these options. -// -// Only tcp4 and tcp6 networks are supported. -// -// ErrNoReusePort error is returned if the system doesn't support SO_REUSEPORT. -func Listen(network, addr string) (net.Listener, error) { - ln, err := cfg.NewListener(network, addr) - if err != nil && strings.Contains(err.Error(), "SO_REUSEPORT") { - return nil, &ErrNoReusePort{err} - } - return ln, err -} - -var cfg = &tcplisten.Config{ - ReusePort: true, - DeferAccept: true, - FastOpen: true, -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go deleted file mode 100644 index 927a3b20..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go +++ /dev/null @@ -1,2019 +0,0 @@ -package fasthttp - -import ( - "bufio" - "crypto/tls" - "errors" - "fmt" - "io" - "log" - "mime/multipart" - "net" - "os" - "strings" - "sync" - "sync/atomic" - "time" -) - -// ServeConn serves HTTP requests from the given connection -// using the given handler. -// -// ServeConn returns nil if all requests from the c are successfully served. -// It returns non-nil error otherwise. -// -// Connection c must immediately propagate all the data passed to Write() -// to the client. Otherwise requests' processing may hang. -// -// ServeConn closes c before returning. -func ServeConn(c net.Conn, handler RequestHandler) error { - v := serverPool.Get() - if v == nil { - v = &Server{} - } - s := v.(*Server) - s.Handler = handler - err := s.ServeConn(c) - s.Handler = nil - serverPool.Put(v) - return err -} - -var serverPool sync.Pool - -// Serve serves incoming connections from the given listener -// using the given handler. -// -// Serve blocks until the given listener returns permanent error. -func Serve(ln net.Listener, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.Serve(ln) -} - -// ServeTLS serves HTTPS requests from the given net.Listener -// using the given handler. -// -// certFile and keyFile are paths to TLS certificate and key files. -func ServeTLS(ln net.Listener, certFile, keyFile string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ServeTLS(ln, certFile, keyFile) -} - -// ServeTLSEmbed serves HTTPS requests from the given net.Listener -// using the given handler. -// -// certData and keyData must contain valid TLS certificate and key data. -func ServeTLSEmbed(ln net.Listener, certData, keyData []byte, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ServeTLSEmbed(ln, certData, keyData) -} - -// ListenAndServe serves HTTP requests from the given TCP addr -// using the given handler. -func ListenAndServe(addr string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServe(addr) -} - -// ListenAndServeUNIX serves HTTP requests from the given UNIX addr -// using the given handler. -// -// The function deletes existing file at addr before starting serving. -// -// The server sets the given file mode for the UNIX addr. -func ListenAndServeUNIX(addr string, mode os.FileMode, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeUNIX(addr, mode) -} - -// ListenAndServeTLS serves HTTPS requests from the given TCP addr -// using the given handler. -// -// certFile and keyFile are paths to TLS certificate and key files. -func ListenAndServeTLS(addr, certFile, keyFile string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeTLS(addr, certFile, keyFile) -} - -// ListenAndServeTLSEmbed serves HTTPS requests from the given TCP addr -// using the given handler. -// -// certData and keyData must contain valid TLS certificate and key data. -func ListenAndServeTLSEmbed(addr string, certData, keyData []byte, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeTLSEmbed(addr, certData, keyData) -} - -// RequestHandler must process incoming requests. -// -// RequestHandler must call ctx.TimeoutError() before returning -// if it keeps references to ctx and/or its' members after the return. -// Consider wrapping RequestHandler into TimeoutHandler if response time -// must be limited. -type RequestHandler func(ctx *RequestCtx) - -// Server implements HTTP server. -// -// Default Server settings should satisfy the majority of Server users. -// Adjust Server settings only if you really understand the consequences. -// -// It is forbidden copying Server instances. Create new Server instances -// instead. -// -// It is safe to call Server methods from concurrently running goroutines. -type Server struct { - noCopy noCopy - - // Handler for processing incoming requests. - Handler RequestHandler - - // Server name for sending in response headers. - // - // Default server name is used if left blank. - Name string - - // The maximum number of concurrent connections the server may serve. - // - // DefaultConcurrency is used if not set. - Concurrency int - - // Whether to disable keep-alive connections. - // - // The server will close all the incoming connections after sending - // the first response to client if this option is set to true. - // - // By default keep-alive connections are enabled. - DisableKeepalive bool - - // Per-connection buffer size for requests' reading. - // This also limits the maximum header size. - // - // Increase this buffer if your clients send multi-KB RequestURIs - // and/or multi-KB headers (for example, BIG cookies). - // - // Default buffer size is used if not set. - ReadBufferSize int - - // Per-connection buffer size for responses' writing. - // - // Default buffer size is used if not set. - WriteBufferSize int - - // Maximum duration for reading the full request (including body). - // - // This also limits the maximum duration for idle keep-alive - // connections. - // - // By default request read timeout is unlimited. - ReadTimeout time.Duration - - // Maximum duration for writing the full response (including body). - // - // By default response write timeout is unlimited. - WriteTimeout time.Duration - - // Maximum number of concurrent client connections allowed per IP. - // - // By default unlimited number of concurrent connections - // may be established to the server from a single IP address. - MaxConnsPerIP int - - // Maximum number of requests served per connection. - // - // The server closes connection after the last request. - // 'Connection: close' header is added to the last response. - // - // By default unlimited number of requests may be served per connection. - MaxRequestsPerConn int - - // Maximum keep-alive connection lifetime. - // - // The server closes keep-alive connection after its' lifetime - // expiration. - // - // See also ReadTimeout for limiting the duration of idle keep-alive - // connections. - // - // By default keep-alive connection lifetime is unlimited. - MaxKeepaliveDuration time.Duration - - // Maximum request body size. - // - // The server rejects requests with bodies exceeding this limit. - // - // Request body size is limited by DefaultMaxRequestBodySize by default. - MaxRequestBodySize int - - // Aggressively reduces memory usage at the cost of higher CPU usage - // if set to true. - // - // Try enabling this option only if the server consumes too much memory - // serving mostly idle keep-alive connections. This may reduce memory - // usage by more than 50%. - // - // Aggressive memory usage reduction is disabled by default. - ReduceMemoryUsage bool - - // Rejects all non-GET requests if set to true. - // - // This option is useful as anti-DoS protection for servers - // accepting only GET requests. The request size is limited - // by ReadBufferSize if GetOnly is set. - // - // Server accepts all the requests by default. - GetOnly bool - - // Logs all errors, including the most frequent - // 'connection reset by peer', 'broken pipe' and 'connection timeout' - // errors. Such errors are common in production serving real-world - // clients. - // - // By default the most frequent errors such as - // 'connection reset by peer', 'broken pipe' and 'connection timeout' - // are suppressed in order to limit output log traffic. - LogAllErrors bool - - // Header names are passed as-is without normalization - // if this option is set. - // - // Disabled header names' normalization may be useful only for proxying - // incoming requests to other servers expecting case-sensitive - // header names. See https://github.com/valyala/fasthttp/issues/57 - // for details. - // - // By default request and response header names are normalized, i.e. - // The first letter and the first letters following dashes - // are uppercased, while all the other letters are lowercased. - // Examples: - // - // * HOST -> Host - // * content-type -> Content-Type - // * cONTENT-lenGTH -> Content-Length - DisableHeaderNamesNormalizing bool - - // Logger, which is used by RequestCtx.Logger(). - // - // By default standard logger from log package is used. - Logger Logger - - concurrency uint32 - concurrencyCh chan struct{} - perIPConnCounter perIPConnCounter - serverName atomic.Value - - ctxPool sync.Pool - readerPool sync.Pool - writerPool sync.Pool - hijackConnPool sync.Pool - bytePool sync.Pool -} - -// TimeoutHandler creates RequestHandler, which returns StatusRequestTimeout -// error with the given msg to the client if h didn't return during -// the given duration. -// -// The returned handler may return StatusTooManyRequests error with the given -// msg to the client if there are more than Server.Concurrency concurrent -// handlers h are running at the moment. -func TimeoutHandler(h RequestHandler, timeout time.Duration, msg string) RequestHandler { - if timeout <= 0 { - return h - } - - return func(ctx *RequestCtx) { - concurrencyCh := ctx.s.concurrencyCh - select { - case concurrencyCh <- struct{}{}: - default: - ctx.Error(msg, StatusTooManyRequests) - return - } - - ch := ctx.timeoutCh - if ch == nil { - ch = make(chan struct{}, 1) - ctx.timeoutCh = ch - } - go func() { - h(ctx) - ch <- struct{}{} - <-concurrencyCh - }() - ctx.timeoutTimer = initTimer(ctx.timeoutTimer, timeout) - select { - case <-ch: - case <-ctx.timeoutTimer.C: - ctx.TimeoutError(msg) - } - stopTimer(ctx.timeoutTimer) - } -} - -// CompressHandler returns RequestHandler that transparently compresses -// response body generated by h if the request contains 'gzip' or 'deflate' -// 'Accept-Encoding' header. -func CompressHandler(h RequestHandler) RequestHandler { - return CompressHandlerLevel(h, CompressDefaultCompression) -} - -// CompressHandlerLevel returns RequestHandler that transparently compresses -// response body generated by h if the request contains 'gzip' or 'deflate' -// 'Accept-Encoding' header. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -func CompressHandlerLevel(h RequestHandler, level int) RequestHandler { - return func(ctx *RequestCtx) { - h(ctx) - ce := ctx.Response.Header.PeekBytes(strContentEncoding) - if len(ce) > 0 { - // Do not compress responses with non-empty - // Content-Encoding. - return - } - if ctx.Request.Header.HasAcceptEncodingBytes(strGzip) { - ctx.Response.gzipBody(level) - } else if ctx.Request.Header.HasAcceptEncodingBytes(strDeflate) { - ctx.Response.deflateBody(level) - } - } -} - -// RequestCtx contains incoming request and manages outgoing response. -// -// It is forbidden copying RequestCtx instances. -// -// RequestHandler should avoid holding references to incoming RequestCtx and/or -// its' members after the return. -// If holding RequestCtx references after the return is unavoidable -// (for instance, ctx is passed to a separate goroutine and ctx lifetime cannot -// be controlled), then the RequestHandler MUST call ctx.TimeoutError() -// before return. -// -// It is unsafe modifying/reading RequestCtx instance from concurrently -// running goroutines. The only exception is TimeoutError*, which may be called -// while other goroutines accessing RequestCtx. -type RequestCtx struct { - noCopy noCopy - - // Incoming request. - // - // Copying Request by value is forbidden. Use pointer to Request instead. - Request Request - - // Outgoing response. - // - // Copying Response by value is forbidden. Use pointer to Response instead. - Response Response - - userValues userData - - lastReadDuration time.Duration - - connID uint64 - connRequestNum uint64 - connTime time.Time - - time time.Time - - logger ctxLogger - s *Server - c net.Conn - fbr firstByteReader - - timeoutResponse *Response - timeoutCh chan struct{} - timeoutTimer *time.Timer - - hijackHandler HijackHandler -} - -// HijackHandler must process the hijacked connection c. -// -// The connection c is automatically closed after returning from HijackHandler. -// -// The connection c must not be used after returning from the handler. -type HijackHandler func(c net.Conn) - -// Hijack registers the given handler for connection hijacking. -// -// The handler is called after returning from RequestHandler -// and sending http response. The current connection is passed -// to the handler. The connection is automatically closed after -// returning from the handler. -// -// The server skips calling the handler in the following cases: -// -// * 'Connection: close' header exists in either request or response. -// * Unexpected error during response writing to the connection. -// -// The server stops processing requests from hijacked connections. -// Server limits such as Concurrency, ReadTimeout, WriteTimeout, etc. -// aren't applied to hijacked connections. -// -// The handler must not retain references to ctx members. -// -// Arbitrary 'Connection: Upgrade' protocols may be implemented -// with HijackHandler. For instance, -// -// * WebSocket ( https://en.wikipedia.org/wiki/WebSocket ) -// * HTTP/2.0 ( https://en.wikipedia.org/wiki/HTTP/2 ) -// -func (ctx *RequestCtx) Hijack(handler HijackHandler) { - ctx.hijackHandler = handler -} - -// Hijacked returns true after Hijack is called. -func (ctx *RequestCtx) Hijacked() bool { - return ctx.hijackHandler != nil -} - -// SetUserValue stores the given value (arbitrary object) -// under the given key in ctx. -// -// The value stored in ctx may be obtained by UserValue*. -// -// This functionality may be useful for passing arbitrary values between -// functions involved in request processing. -// -// All the values are removed from ctx after returning from the top -// RequestHandler. Additionally, Close method is called on each value -// implementing io.Closer before removing the value from ctx. -func (ctx *RequestCtx) SetUserValue(key string, value interface{}) { - ctx.userValues.Set(key, value) -} - -// SetUserValueBytes stores the given value (arbitrary object) -// under the given key in ctx. -// -// The value stored in ctx may be obtained by UserValue*. -// -// This functionality may be useful for passing arbitrary values between -// functions involved in request processing. -// -// All the values stored in ctx are deleted after returning from RequestHandler. -func (ctx *RequestCtx) SetUserValueBytes(key []byte, value interface{}) { - ctx.userValues.SetBytes(key, value) -} - -// UserValue returns the value stored via SetUserValue* under the given key. -func (ctx *RequestCtx) UserValue(key string) interface{} { - return ctx.userValues.Get(key) -} - -// UserValueBytes returns the value stored via SetUserValue* -// under the given key. -func (ctx *RequestCtx) UserValueBytes(key []byte) interface{} { - return ctx.userValues.GetBytes(key) -} - -// VisitUserValues calls visitor for each existing userValue. -// -// visitor must not retain references to key and value after returning. -// Make key and/or value copies if you need storing them after returning. -func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, interface{})) { - for i, n := 0, len(ctx.userValues); i < n; i++ { - kv := &ctx.userValues[i] - visitor(kv.key, kv.value) - } -} - -type connTLSer interface { - ConnectionState() tls.ConnectionState -} - -// IsTLS returns true if the underlying connection is tls.Conn. -// -// tls.Conn is an encrypted connection (aka SSL, HTTPS). -func (ctx *RequestCtx) IsTLS() bool { - // cast to (connTLSer) instead of (*tls.Conn), since it catches - // cases with overridden tls.Conn such as: - // - // type customConn struct { - // *tls.Conn - // - // // other custom fields here - // } - _, ok := ctx.c.(connTLSer) - return ok -} - -// TLSConnectionState returns TLS connection state. -// -// The function returns nil if the underlying connection isn't tls.Conn. -// -// The returned state may be used for verifying TLS version, client certificates, -// etc. -func (ctx *RequestCtx) TLSConnectionState() *tls.ConnectionState { - tlsConn, ok := ctx.c.(connTLSer) - if !ok { - return nil - } - state := tlsConn.ConnectionState() - return &state -} - -type firstByteReader struct { - c net.Conn - ch byte - byteRead bool -} - -func (r *firstByteReader) Read(b []byte) (int, error) { - if len(b) == 0 { - return 0, nil - } - nn := 0 - if !r.byteRead { - b[0] = r.ch - b = b[1:] - r.byteRead = true - nn = 1 - } - n, err := r.c.Read(b) - return n + nn, err -} - -// Logger is used for logging formatted messages. -type Logger interface { - // Printf must have the same semantics as log.Printf. - Printf(format string, args ...interface{}) -} - -var ctxLoggerLock sync.Mutex - -type ctxLogger struct { - ctx *RequestCtx - logger Logger -} - -func (cl *ctxLogger) Printf(format string, args ...interface{}) { - ctxLoggerLock.Lock() - msg := fmt.Sprintf(format, args...) - ctx := cl.ctx - cl.logger.Printf("%.3f %s - %s", time.Since(ctx.Time()).Seconds(), ctx.String(), msg) - ctxLoggerLock.Unlock() -} - -var zeroTCPAddr = &net.TCPAddr{ - IP: net.IPv4zero, -} - -// String returns unique string representation of the ctx. -// -// The returned value may be useful for logging. -func (ctx *RequestCtx) String() string { - return fmt.Sprintf("#%016X - %s<->%s - %s %s", ctx.ID(), ctx.LocalAddr(), ctx.RemoteAddr(), ctx.Request.Header.Method(), ctx.URI().FullURI()) -} - -// ID returns unique ID of the request. -func (ctx *RequestCtx) ID() uint64 { - return (ctx.connID << 32) | ctx.connRequestNum -} - -// ConnID returns unique connection ID. -// -// This ID may be used to match distinct requests to the same incoming -// connection. -func (ctx *RequestCtx) ConnID() uint64 { - return ctx.connID -} - -// Time returns RequestHandler call time. -func (ctx *RequestCtx) Time() time.Time { - return ctx.time -} - -// ConnTime returns the time the server started serving the connection -// the current request came from. -func (ctx *RequestCtx) ConnTime() time.Time { - return ctx.connTime -} - -// ConnRequestNum returns request sequence number -// for the current connection. -// -// Sequence starts with 1. -func (ctx *RequestCtx) ConnRequestNum() uint64 { - return ctx.connRequestNum -} - -// SetConnectionClose sets 'Connection: close' response header and closes -// connection after the RequestHandler returns. -func (ctx *RequestCtx) SetConnectionClose() { - ctx.Response.SetConnectionClose() -} - -// SetStatusCode sets response status code. -func (ctx *RequestCtx) SetStatusCode(statusCode int) { - ctx.Response.SetStatusCode(statusCode) -} - -// SetContentType sets response Content-Type. -func (ctx *RequestCtx) SetContentType(contentType string) { - ctx.Response.Header.SetContentType(contentType) -} - -// SetContentTypeBytes sets response Content-Type. -// -// It is safe modifying contentType buffer after function return. -func (ctx *RequestCtx) SetContentTypeBytes(contentType []byte) { - ctx.Response.Header.SetContentTypeBytes(contentType) -} - -// RequestURI returns RequestURI. -// -// This uri is valid until returning from RequestHandler. -func (ctx *RequestCtx) RequestURI() []byte { - return ctx.Request.Header.RequestURI() -} - -// URI returns requested uri. -// -// The uri is valid until returning from RequestHandler. -func (ctx *RequestCtx) URI() *URI { - return ctx.Request.URI() -} - -// Referer returns request referer. -// -// The referer is valid until returning from RequestHandler. -func (ctx *RequestCtx) Referer() []byte { - return ctx.Request.Header.Referer() -} - -// UserAgent returns User-Agent header value from the request. -func (ctx *RequestCtx) UserAgent() []byte { - return ctx.Request.Header.UserAgent() -} - -// Path returns requested path. -// -// The path is valid until returning from RequestHandler. -func (ctx *RequestCtx) Path() []byte { - return ctx.URI().Path() -} - -// Host returns requested host. -// -// The host is valid until returning from RequestHandler. -func (ctx *RequestCtx) Host() []byte { - return ctx.URI().Host() -} - -// QueryArgs returns query arguments from RequestURI. -// -// It doesn't return POST'ed arguments - use PostArgs() for this. -// -// Returned arguments are valid until returning from RequestHandler. -// -// See also PostArgs, FormValue and FormFile. -func (ctx *RequestCtx) QueryArgs() *Args { - return ctx.URI().QueryArgs() -} - -// PostArgs returns POST arguments. -// -// It doesn't return query arguments from RequestURI - use QueryArgs for this. -// -// Returned arguments are valid until returning from RequestHandler. -// -// See also QueryArgs, FormValue and FormFile. -func (ctx *RequestCtx) PostArgs() *Args { - return ctx.Request.PostArgs() -} - -// MultipartForm returns requests's multipart form. -// -// Returns ErrNoMultipartForm if request's content-type -// isn't 'multipart/form-data'. -// -// All uploaded temporary files are automatically deleted after -// returning from RequestHandler. Either move or copy uploaded files -// into new place if you want retaining them. -// -// Use SaveMultipartFile function for permanently saving uploaded file. -// -// The returned form is valid until returning from RequestHandler. -// -// See also FormFile and FormValue. -func (ctx *RequestCtx) MultipartForm() (*multipart.Form, error) { - return ctx.Request.MultipartForm() -} - -// FormFile returns uploaded file associated with the given multipart form key. -// -// The file is automatically deleted after returning from RequestHandler, -// so either move or copy uploaded file into new place if you want retaining it. -// -// Use SaveMultipartFile function for permanently saving uploaded file. -// -// The returned file header is valid until returning from RequestHandler. -func (ctx *RequestCtx) FormFile(key string) (*multipart.FileHeader, error) { - mf, err := ctx.MultipartForm() - if err != nil { - return nil, err - } - if mf.File == nil { - return nil, err - } - fhh := mf.File[key] - if fhh == nil { - return nil, ErrMissingFile - } - return fhh[0], nil -} - -// ErrMissingFile may be returned from FormFile when the is no uploaded file -// associated with the given multipart form key. -var ErrMissingFile = errors.New("there is no uploaded file associated with the given key") - -// SaveMultipartFile saves multipart file fh under the given filename path. -func SaveMultipartFile(fh *multipart.FileHeader, path string) error { - f, err := fh.Open() - if err != nil { - return err - } - defer f.Close() - - if ff, ok := f.(*os.File); ok { - return os.Rename(ff.Name(), path) - } - - ff, err := os.Create(path) - if err != nil { - return err - } - defer ff.Close() - _, err = copyZeroAlloc(ff, f) - return err -} - -// FormValue returns form value associated with the given key. -// -// The value is searched in the following places: -// -// * Query string. -// * POST or PUT body. -// -// There are more fine-grained methods for obtaining form values: -// -// * QueryArgs for obtaining values from query string. -// * PostArgs for obtaining values from POST or PUT body. -// * MultipartForm for obtaining values from multipart form. -// * FormFile for obtaining uploaded files. -// -// The returned value is valid until returning from RequestHandler. -func (ctx *RequestCtx) FormValue(key string) []byte { - v := ctx.QueryArgs().Peek(key) - if len(v) > 0 { - return v - } - v = ctx.PostArgs().Peek(key) - if len(v) > 0 { - return v - } - mf, err := ctx.MultipartForm() - if err == nil && mf.Value != nil { - vv := mf.Value[key] - if len(vv) > 0 { - return []byte(vv[0]) - } - } - return nil -} - -// IsGet returns true if request method is GET. -func (ctx *RequestCtx) IsGet() bool { - return ctx.Request.Header.IsGet() -} - -// IsPost returns true if request method is POST. -func (ctx *RequestCtx) IsPost() bool { - return ctx.Request.Header.IsPost() -} - -// IsPut returns true if request method is PUT. -func (ctx *RequestCtx) IsPut() bool { - return ctx.Request.Header.IsPut() -} - -// IsDelete returns true if request method is DELETE. -func (ctx *RequestCtx) IsDelete() bool { - return ctx.Request.Header.IsDelete() -} - -// IsConnect returns true if request method is CONNECT. -func (ctx *RequestCtx) IsConnect() bool { - return ctx.Request.Header.IsConnect() -} - -// IsOptions returns true if request method is OPTIONS. -func (ctx *RequestCtx) IsOptions() bool { - return ctx.Request.Header.IsOptions() -} - -// IsTrace returns true if request method is TRACE. -func (ctx *RequestCtx) IsTrace() bool { - return ctx.Request.Header.IsTrace() -} - -// IsPatch returns true if request method is PATCH. -func (ctx *RequestCtx) IsPatch() bool { - return ctx.Request.Header.IsPatch() -} - -// Method return request method. -// -// Returned value is valid until returning from RequestHandler. -func (ctx *RequestCtx) Method() []byte { - return ctx.Request.Header.Method() -} - -// IsHead returns true if request method is HEAD. -func (ctx *RequestCtx) IsHead() bool { - return ctx.Request.Header.IsHead() -} - -// RemoteAddr returns client address for the given request. -// -// Always returns non-nil result. -func (ctx *RequestCtx) RemoteAddr() net.Addr { - if ctx.c == nil { - return zeroTCPAddr - } - addr := ctx.c.RemoteAddr() - if addr == nil { - return zeroTCPAddr - } - return addr -} - -// LocalAddr returns server address for the given request. -// -// Always returns non-nil result. -func (ctx *RequestCtx) LocalAddr() net.Addr { - if ctx.c == nil { - return zeroTCPAddr - } - addr := ctx.c.LocalAddr() - if addr == nil { - return zeroTCPAddr - } - return addr -} - -// RemoteIP returns the client ip the request came from. -// -// Always returns non-nil result. -func (ctx *RequestCtx) RemoteIP() net.IP { - return addrToIP(ctx.RemoteAddr()) -} - -// LocalIP returns the server ip the request came to. -// -// Always returns non-nil result. -func (ctx *RequestCtx) LocalIP() net.IP { - return addrToIP(ctx.LocalAddr()) -} - -func addrToIP(addr net.Addr) net.IP { - x, ok := addr.(*net.TCPAddr) - if !ok { - return net.IPv4zero - } - return x.IP -} - -// Error sets response status code to the given value and sets response body -// to the given message. -func (ctx *RequestCtx) Error(msg string, statusCode int) { - ctx.Response.Reset() - ctx.SetStatusCode(statusCode) - ctx.SetContentTypeBytes(defaultContentType) - ctx.SetBodyString(msg) -} - -// Success sets response Content-Type and body to the given values. -func (ctx *RequestCtx) Success(contentType string, body []byte) { - ctx.SetContentType(contentType) - ctx.SetBody(body) -} - -// SuccessString sets response Content-Type and body to the given values. -func (ctx *RequestCtx) SuccessString(contentType, body string) { - ctx.SetContentType(contentType) - ctx.SetBodyString(body) -} - -// Redirect sets 'Location: uri' response header and sets the given statusCode. -// -// statusCode must have one of the following values: -// -// * StatusMovedPermanently (301) -// * StatusFound (302) -// * StatusSeeOther (303) -// * StatusTemporaryRedirect (307) -// -// All other statusCode values are replaced by StatusFound (302). -// -// The redirect uri may be either absolute or relative to the current -// request uri. -func (ctx *RequestCtx) Redirect(uri string, statusCode int) { - u := AcquireURI() - ctx.URI().CopyTo(u) - u.Update(uri) - ctx.redirect(u.FullURI(), statusCode) - ReleaseURI(u) -} - -// RedirectBytes sets 'Location: uri' response header and sets -// the given statusCode. -// -// statusCode must have one of the following values: -// -// * StatusMovedPermanently (301) -// * StatusFound (302) -// * StatusSeeOther (303) -// * StatusTemporaryRedirect (307) -// -// All other statusCode values are replaced by StatusFound (302). -// -// The redirect uri may be either absolute or relative to the current -// request uri. -func (ctx *RequestCtx) RedirectBytes(uri []byte, statusCode int) { - s := b2s(uri) - ctx.Redirect(s, statusCode) -} - -func (ctx *RequestCtx) redirect(uri []byte, statusCode int) { - ctx.Response.Header.SetCanonical(strLocation, uri) - statusCode = getRedirectStatusCode(statusCode) - ctx.Response.SetStatusCode(statusCode) -} - -func getRedirectStatusCode(statusCode int) int { - if statusCode == StatusMovedPermanently || statusCode == StatusFound || - statusCode == StatusSeeOther || statusCode == StatusTemporaryRedirect { - return statusCode - } - return StatusFound -} - -// SetBody sets response body to the given value. -// -// It is safe re-using body argument after the function returns. -func (ctx *RequestCtx) SetBody(body []byte) { - ctx.Response.SetBody(body) -} - -// SetBodyString sets response body to the given value. -func (ctx *RequestCtx) SetBodyString(body string) { - ctx.Response.SetBodyString(body) -} - -// ResetBody resets response body contents. -func (ctx *RequestCtx) ResetBody() { - ctx.Response.ResetBody() -} - -// SendFile sends local file contents from the given path as response body. -// -// This is a shortcut to ServeFile(ctx, path). -// -// SendFile logs all the errors via ctx.Logger. -// -// See also ServeFile, FSHandler and FS. -func (ctx *RequestCtx) SendFile(path string) { - ServeFile(ctx, path) -} - -// SendFileBytes sends local file contents from the given path as response body. -// -// This is a shortcut to ServeFileBytes(ctx, path). -// -// SendFileBytes logs all the errors via ctx.Logger. -// -// See also ServeFileBytes, FSHandler and FS. -func (ctx *RequestCtx) SendFileBytes(path []byte) { - ServeFileBytes(ctx, path) -} - -// IfModifiedSince returns true if lastModified exceeds 'If-Modified-Since' -// value from the request header. -// -// The function returns true also 'If-Modified-Since' request header is missing. -func (ctx *RequestCtx) IfModifiedSince(lastModified time.Time) bool { - ifModStr := ctx.Request.Header.peek(strIfModifiedSince) - if len(ifModStr) == 0 { - return true - } - ifMod, err := ParseHTTPDate(ifModStr) - if err != nil { - return true - } - lastModified = lastModified.Truncate(time.Second) - return ifMod.Before(lastModified) -} - -// NotModified resets response and sets '304 Not Modified' response status code. -func (ctx *RequestCtx) NotModified() { - ctx.Response.Reset() - ctx.SetStatusCode(StatusNotModified) -} - -// NotFound resets response and sets '404 Not Found' response status code. -func (ctx *RequestCtx) NotFound() { - ctx.Response.Reset() - ctx.SetStatusCode(StatusNotFound) - ctx.SetBodyString("404 Page not found") -} - -// Write writes p into response body. -func (ctx *RequestCtx) Write(p []byte) (int, error) { - ctx.Response.AppendBody(p) - return len(p), nil -} - -// WriteString appends s to response body. -func (ctx *RequestCtx) WriteString(s string) (int, error) { - ctx.Response.AppendBodyString(s) - return len(s), nil -} - -// PostBody returns POST request body. -// -// The returned value is valid until RequestHandler return. -func (ctx *RequestCtx) PostBody() []byte { - return ctx.Request.Body() -} - -// SetBodyStream sets response body stream and, optionally body size. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// If bodySize is >= 0, then bodySize bytes must be provided by bodyStream -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// See also SetBodyStreamWriter. -func (ctx *RequestCtx) SetBodyStream(bodyStream io.Reader, bodySize int) { - ctx.Response.SetBodyStream(bodyStream, bodySize) -} - -// SetBodyStreamWriter registers the given stream writer for populating -// response body. -// -// Access to RequestCtx and/or its' members is forbidden from sw. -// -// This function may be used in the following cases: -// -// * if response body is too big (more than 10MB). -// * if response body is streamed from slow external sources. -// * if response body must be streamed to the client in chunks. -// (aka `http server push`). -func (ctx *RequestCtx) SetBodyStreamWriter(sw StreamWriter) { - ctx.Response.SetBodyStreamWriter(sw) -} - -// IsBodyStream returns true if response body is set via SetBodyStream*. -func (ctx *RequestCtx) IsBodyStream() bool { - return ctx.Response.IsBodyStream() -} - -// Logger returns logger, which may be used for logging arbitrary -// request-specific messages inside RequestHandler. -// -// Each message logged via returned logger contains request-specific information -// such as request id, request duration, local address, remote address, -// request method and request url. -// -// It is safe re-using returned logger for logging multiple messages -// for the current request. -// -// The returned logger is valid until returning from RequestHandler. -func (ctx *RequestCtx) Logger() Logger { - if ctx.logger.ctx == nil { - ctx.logger.ctx = ctx - } - if ctx.logger.logger == nil { - ctx.logger.logger = ctx.s.logger() - } - return &ctx.logger -} - -// TimeoutError sets response status code to StatusRequestTimeout and sets -// body to the given msg. -// -// All response modifications after TimeoutError call are ignored. -// -// TimeoutError MUST be called before returning from RequestHandler if there are -// references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutError(msg string) { - ctx.TimeoutErrorWithCode(msg, StatusRequestTimeout) -} - -// TimeoutErrorWithCode sets response body to msg and response status -// code to statusCode. -// -// All response modifications after TimeoutErrorWithCode call are ignored. -// -// TimeoutErrorWithCode MUST be called before returning from RequestHandler -// if there are references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutErrorWithCode(msg string, statusCode int) { - var resp Response - resp.SetStatusCode(statusCode) - resp.SetBodyString(msg) - ctx.TimeoutErrorWithResponse(&resp) -} - -// TimeoutErrorWithResponse marks the ctx as timed out and sends the given -// response to the client. -// -// All ctx modifications after TimeoutErrorWithResponse call are ignored. -// -// TimeoutErrorWithResponse MUST be called before returning from RequestHandler -// if there are references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutErrorWithResponse(resp *Response) { - respCopy := &Response{} - resp.CopyTo(respCopy) - ctx.timeoutResponse = respCopy -} - -// ListenAndServe serves HTTP requests from the given TCP4 addr. -// -// Pass custom listener to Serve if you need listening on non-TCP4 media -// such as IPv6. -func (s *Server) ListenAndServe(addr string) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.Serve(ln) -} - -// ListenAndServeUNIX serves HTTP requests from the given UNIX addr. -// -// The function deletes existing file at addr before starting serving. -// -// The server sets the given file mode for the UNIX addr. -func (s *Server) ListenAndServeUNIX(addr string, mode os.FileMode) error { - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("unexpected error when trying to remove unix socket file %q: %s", addr, err) - } - ln, err := net.Listen("unix", addr) - if err != nil { - return err - } - if err = os.Chmod(addr, mode); err != nil { - return fmt.Errorf("cannot chmod %#o for %q: %s", mode, addr, err) - } - return s.Serve(ln) -} - -// ListenAndServeTLS serves HTTPS requests from the given TCP4 addr. -// -// certFile and keyFile are paths to TLS certificate and key files. -// -// Pass custom listener to Serve if you need listening on non-TCP4 media -// such as IPv6. -func (s *Server) ListenAndServeTLS(addr, certFile, keyFile string) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.ServeTLS(ln, certFile, keyFile) -} - -// ListenAndServeTLSEmbed serves HTTPS requests from the given TCP4 addr. -// -// certData and keyData must contain valid TLS certificate and key data. -// -// Pass custom listener to Serve if you need listening on arbitrary media -// such as IPv6. -func (s *Server) ListenAndServeTLSEmbed(addr string, certData, keyData []byte) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.ServeTLSEmbed(ln, certData, keyData) -} - -// ServeTLS serves HTTPS requests from the given listener. -// -// certFile and keyFile are paths to TLS certificate and key files. -func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error { - lnTLS, err := newTLSListener(ln, certFile, keyFile) - if err != nil { - return err - } - return s.Serve(lnTLS) -} - -// ServeTLSEmbed serves HTTPS requests from the given listener. -// -// certData and keyData must contain valid TLS certificate and key data. -func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error { - lnTLS, err := newTLSListenerEmbed(ln, certData, keyData) - if err != nil { - return err - } - return s.Serve(lnTLS) -} - -func newTLSListener(ln net.Listener, certFile, keyFile string) (net.Listener, error) { - cert, err := tls.LoadX509KeyPair(certFile, keyFile) - if err != nil { - return nil, fmt.Errorf("cannot load TLS key pair from certFile=%q and keyFile=%q: %s", certFile, keyFile, err) - } - return newCertListener(ln, &cert), nil -} - -func newTLSListenerEmbed(ln net.Listener, certData, keyData []byte) (net.Listener, error) { - cert, err := tls.X509KeyPair(certData, keyData) - if err != nil { - return nil, fmt.Errorf("cannot load TLS key pair from the provided certData(%d) and keyData(%d): %s", - len(certData), len(keyData), err) - } - return newCertListener(ln, &cert), nil -} - -func newCertListener(ln net.Listener, cert *tls.Certificate) net.Listener { - tlsConfig := &tls.Config{ - Certificates: []tls.Certificate{*cert}, - PreferServerCipherSuites: true, - } - return tls.NewListener(ln, tlsConfig) -} - -// DefaultConcurrency is the maximum number of concurrent connections -// the Server may serve by default (i.e. if Server.Concurrency isn't set). -const DefaultConcurrency = 256 * 1024 - -// Serve serves incoming connections from the given listener. -// -// Serve blocks until the given listener returns permanent error. -func (s *Server) Serve(ln net.Listener) error { - var lastOverflowErrorTime time.Time - var lastPerIPErrorTime time.Time - var c net.Conn - var err error - - maxWorkersCount := s.getConcurrency() - s.concurrencyCh = make(chan struct{}, maxWorkersCount) - wp := &workerPool{ - WorkerFunc: s.serveConn, - MaxWorkersCount: maxWorkersCount, - LogAllErrors: s.LogAllErrors, - Logger: s.logger(), - } - wp.Start() - - for { - if c, err = acceptConn(s, ln, &lastPerIPErrorTime); err != nil { - wp.Stop() - if err == io.EOF { - return nil - } - return err - } - if !wp.Serve(c) { - s.writeFastError(c, StatusServiceUnavailable, - "The connection cannot be served because Server.Concurrency limit exceeded") - c.Close() - if time.Since(lastOverflowErrorTime) > time.Minute { - s.logger().Printf("The incoming connection cannot be served, because %d concurrent connections are served. "+ - "Try increasing Server.Concurrency", maxWorkersCount) - lastOverflowErrorTime = time.Now() - } - - // The current server reached concurrency limit, - // so give other concurrently running servers a chance - // accepting incoming connections on the same address. - // - // There is a hope other servers didn't reach their - // concurrency limits yet :) - time.Sleep(100 * time.Millisecond) - } - c = nil - } -} - -func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.Conn, error) { - for { - c, err := ln.Accept() - if err != nil { - if c != nil { - panic("BUG: net.Listener returned non-nil conn and non-nil error") - } - if netErr, ok := err.(net.Error); ok && netErr.Temporary() { - s.logger().Printf("Temporary error when accepting new connections: %s", netErr) - time.Sleep(time.Second) - continue - } - if err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") { - s.logger().Printf("Permanent error when accepting new connections: %s", err) - return nil, err - } - return nil, io.EOF - } - if c == nil { - panic("BUG: net.Listener returned (nil, nil)") - } - if s.MaxConnsPerIP > 0 { - pic := wrapPerIPConn(s, c) - if pic == nil { - if time.Since(*lastPerIPErrorTime) > time.Minute { - s.logger().Printf("The number of connections from %s exceeds MaxConnsPerIP=%d", - getConnIP4(c), s.MaxConnsPerIP) - *lastPerIPErrorTime = time.Now() - } - continue - } - c = pic - } - return c, nil - } -} - -func wrapPerIPConn(s *Server, c net.Conn) net.Conn { - ip := getUint32IP(c) - if ip == 0 { - return c - } - n := s.perIPConnCounter.Register(ip) - if n > s.MaxConnsPerIP { - s.perIPConnCounter.Unregister(ip) - s.writeFastError(c, StatusTooManyRequests, "The number of connections from your ip exceeds MaxConnsPerIP") - c.Close() - return nil - } - return acquirePerIPConn(c, ip, &s.perIPConnCounter) -} - -var defaultLogger = Logger(log.New(os.Stderr, "", log.LstdFlags)) - -func (s *Server) logger() Logger { - if s.Logger != nil { - return s.Logger - } - return defaultLogger -} - -var ( - // ErrPerIPConnLimit may be returned from ServeConn if the number of connections - // per ip exceeds Server.MaxConnsPerIP. - ErrPerIPConnLimit = errors.New("too many connections per ip") - - // ErrConcurrencyLimit may be returned from ServeConn if the number - // of concurrently served connections exceeds Server.Concurrency. - ErrConcurrencyLimit = errors.New("cannot serve the connection because Server.Concurrency concurrent connections are served") - - // ErrKeepaliveTimeout is returned from ServeConn - // if the connection lifetime exceeds MaxKeepaliveDuration. - ErrKeepaliveTimeout = errors.New("exceeded MaxKeepaliveDuration") -) - -// ServeConn serves HTTP requests from the given connection. -// -// ServeConn returns nil if all requests from the c are successfully served. -// It returns non-nil error otherwise. -// -// Connection c must immediately propagate all the data passed to Write() -// to the client. Otherwise requests' processing may hang. -// -// ServeConn closes c before returning. -func (s *Server) ServeConn(c net.Conn) error { - if s.MaxConnsPerIP > 0 { - pic := wrapPerIPConn(s, c) - if pic == nil { - return ErrPerIPConnLimit - } - c = pic - } - - n := atomic.AddUint32(&s.concurrency, 1) - if n > uint32(s.getConcurrency()) { - atomic.AddUint32(&s.concurrency, ^uint32(0)) - s.writeFastError(c, StatusServiceUnavailable, "The connection cannot be served because Server.Concurrency limit exceeded") - c.Close() - return ErrConcurrencyLimit - } - - err := s.serveConn(c) - - atomic.AddUint32(&s.concurrency, ^uint32(0)) - - if err != errHijacked { - err1 := c.Close() - if err == nil { - err = err1 - } - } else { - err = nil - } - return err -} - -var errHijacked = errors.New("connection has been hijacked") - -func (s *Server) getConcurrency() int { - n := s.Concurrency - if n <= 0 { - n = DefaultConcurrency - } - return n -} - -var globalConnID uint64 - -func nextConnID() uint64 { - return atomic.AddUint64(&globalConnID, 1) -} - -// DefaultMaxRequestBodySize is the maximum request body size the server -// reads by default. -// -// See Server.MaxRequestBodySize for details. -const DefaultMaxRequestBodySize = 4 * 1024 * 1024 - -func (s *Server) serveConn(c net.Conn) error { - serverName := s.getServerName() - connRequestNum := uint64(0) - connID := nextConnID() - currentTime := time.Now() - connTime := currentTime - maxRequestBodySize := s.MaxRequestBodySize - if maxRequestBodySize <= 0 { - maxRequestBodySize = DefaultMaxRequestBodySize - } - - ctx := s.acquireCtx(c) - ctx.connTime = connTime - isTLS := ctx.IsTLS() - var ( - br *bufio.Reader - bw *bufio.Writer - - err error - timeoutResponse *Response - hijackHandler HijackHandler - - lastReadDeadlineTime time.Time - lastWriteDeadlineTime time.Time - - connectionClose bool - isHTTP11 bool - ) - for { - connRequestNum++ - ctx.time = currentTime - - if s.ReadTimeout > 0 || s.MaxKeepaliveDuration > 0 { - lastReadDeadlineTime = s.updateReadDeadline(c, ctx, lastReadDeadlineTime) - if lastReadDeadlineTime.IsZero() { - err = ErrKeepaliveTimeout - break - } - } - - if !(s.ReduceMemoryUsage || ctx.lastReadDuration > time.Second) || br != nil { - if br == nil { - br = acquireReader(ctx) - } - } else { - br, err = acquireByteReader(&ctx) - } - ctx.Request.isTLS = isTLS - - if err == nil { - if s.DisableHeaderNamesNormalizing { - ctx.Request.Header.DisableNormalizing() - ctx.Response.Header.DisableNormalizing() - } - err = ctx.Request.readLimitBody(br, maxRequestBodySize, s.GetOnly) - if br.Buffered() == 0 || err != nil { - releaseReader(s, br) - br = nil - } - } - - currentTime = time.Now() - ctx.lastReadDuration = currentTime.Sub(ctx.time) - - if err != nil { - if err == io.EOF { - err = nil - } else { - bw = writeErrorResponse(bw, ctx, err) - } - break - } - - // 'Expect: 100-continue' request handling. - // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html for details. - if !ctx.Request.Header.noBody() && ctx.Request.MayContinue() { - // Send 'HTTP/1.1 100 Continue' response. - if bw == nil { - bw = acquireWriter(ctx) - } - bw.Write(strResponseContinue) - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - - // Read request body. - if br == nil { - br = acquireReader(ctx) - } - err = ctx.Request.ContinueReadBody(br, maxRequestBodySize) - if br.Buffered() == 0 || err != nil { - releaseReader(s, br) - br = nil - } - if err != nil { - bw = writeErrorResponse(bw, ctx, err) - break - } - } - - connectionClose = s.DisableKeepalive || ctx.Request.Header.connectionCloseFast() - isHTTP11 = ctx.Request.Header.IsHTTP11() - - ctx.Response.Header.SetServerBytes(serverName) - ctx.connID = connID - ctx.connRequestNum = connRequestNum - ctx.connTime = connTime - ctx.time = currentTime - s.Handler(ctx) - - timeoutResponse = ctx.timeoutResponse - if timeoutResponse != nil { - ctx = s.acquireCtx(c) - timeoutResponse.CopyTo(&ctx.Response) - if br != nil { - // Close connection, since br may be attached to the old ctx via ctx.fbr. - ctx.SetConnectionClose() - } - } - - if !ctx.IsGet() && ctx.IsHead() { - ctx.Response.SkipBody = true - } - ctx.Request.Reset() - - hijackHandler = ctx.hijackHandler - ctx.hijackHandler = nil - - ctx.userValues.Reset() - - if s.MaxRequestsPerConn > 0 && connRequestNum >= uint64(s.MaxRequestsPerConn) { - ctx.SetConnectionClose() - } - - if s.WriteTimeout > 0 || s.MaxKeepaliveDuration > 0 { - lastWriteDeadlineTime = s.updateWriteDeadline(c, ctx, lastWriteDeadlineTime) - } - - // Verify Request.Header.connectionCloseFast() again, - // since request handler might trigger full headers' parsing. - connectionClose = connectionClose || ctx.Request.Header.connectionCloseFast() || ctx.Response.ConnectionClose() - if connectionClose { - ctx.Response.Header.SetCanonical(strConnection, strClose) - } else if !isHTTP11 { - // Set 'Connection: keep-alive' response header for non-HTTP/1.1 request. - // There is no need in setting this header for http/1.1, since in http/1.1 - // connections are keep-alive by default. - ctx.Response.Header.SetCanonical(strConnection, strKeepAlive) - } - - if len(ctx.Response.Header.Server()) == 0 { - ctx.Response.Header.SetServerBytes(serverName) - } - - if bw == nil { - bw = acquireWriter(ctx) - } - if err = writeResponse(ctx, bw); err != nil { - break - } - - if br == nil || connectionClose { - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - if connectionClose { - break - } - } - - if hijackHandler != nil { - var hjr io.Reader - hjr = c - if br != nil { - hjr = br - br = nil - - // br may point to ctx.fbr, so do not return ctx into pool. - ctx = s.acquireCtx(c) - } - if bw != nil { - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - } - c.SetReadDeadline(zeroTime) - c.SetWriteDeadline(zeroTime) - go hijackConnHandler(hjr, c, s, hijackHandler) - hijackHandler = nil - err = errHijacked - break - } - - currentTime = time.Now() - } - - if br != nil { - releaseReader(s, br) - } - if bw != nil { - releaseWriter(s, bw) - } - s.releaseCtx(ctx) - return err -} - -func (s *Server) updateReadDeadline(c net.Conn, ctx *RequestCtx, lastDeadlineTime time.Time) time.Time { - readTimeout := s.ReadTimeout - currentTime := ctx.time - if s.MaxKeepaliveDuration > 0 { - connTimeout := s.MaxKeepaliveDuration - currentTime.Sub(ctx.connTime) - if connTimeout <= 0 { - return zeroTime - } - if connTimeout < readTimeout { - readTimeout = connTimeout - } - } - - // Optimization: update read deadline only if more than 25% - // of the last read deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. - if currentTime.Sub(lastDeadlineTime) > (readTimeout >> 2) { - if err := c.SetReadDeadline(currentTime.Add(readTimeout)); err != nil { - panic(fmt.Sprintf("BUG: error in SetReadDeadline(%s): %s", readTimeout, err)) - } - lastDeadlineTime = currentTime - } - return lastDeadlineTime -} - -func (s *Server) updateWriteDeadline(c net.Conn, ctx *RequestCtx, lastDeadlineTime time.Time) time.Time { - writeTimeout := s.WriteTimeout - if s.MaxKeepaliveDuration > 0 { - connTimeout := s.MaxKeepaliveDuration - time.Since(ctx.connTime) - if connTimeout <= 0 { - // MaxKeepAliveDuration exceeded, but let's try sending response anyway - // in 100ms with 'Connection: close' header. - ctx.SetConnectionClose() - connTimeout = 100 * time.Millisecond - } - if connTimeout < writeTimeout { - writeTimeout = connTimeout - } - } - - // Optimization: update write deadline only if more than 25% - // of the last write deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. - currentTime := time.Now() - if currentTime.Sub(lastDeadlineTime) > (writeTimeout >> 2) { - if err := c.SetWriteDeadline(currentTime.Add(writeTimeout)); err != nil { - panic(fmt.Sprintf("BUG: error in SetWriteDeadline(%s): %s", writeTimeout, err)) - } - lastDeadlineTime = currentTime - } - return lastDeadlineTime -} - -func hijackConnHandler(r io.Reader, c net.Conn, s *Server, h HijackHandler) { - hjc := s.acquireHijackConn(r, c) - h(hjc) - - if br, ok := r.(*bufio.Reader); ok { - releaseReader(s, br) - } - c.Close() - s.releaseHijackConn(hjc) -} - -func (s *Server) acquireHijackConn(r io.Reader, c net.Conn) *hijackConn { - v := s.hijackConnPool.Get() - if v == nil { - hjc := &hijackConn{ - Conn: c, - r: r, - } - return hjc - } - hjc := v.(*hijackConn) - hjc.Conn = c - hjc.r = r - return hjc -} - -func (s *Server) releaseHijackConn(hjc *hijackConn) { - hjc.Conn = nil - hjc.r = nil - s.hijackConnPool.Put(hjc) -} - -type hijackConn struct { - net.Conn - r io.Reader -} - -func (c hijackConn) Read(p []byte) (int, error) { - return c.r.Read(p) -} - -func (c hijackConn) Close() error { - // hijacked conn is closed in hijackConnHandler. - return nil -} - -// LastTimeoutErrorResponse returns the last timeout response set -// via TimeoutError* call. -// -// This function is intended for custom server implementations. -func (ctx *RequestCtx) LastTimeoutErrorResponse() *Response { - return ctx.timeoutResponse -} - -func writeResponse(ctx *RequestCtx, w *bufio.Writer) error { - if ctx.timeoutResponse != nil { - panic("BUG: cannot write timed out response") - } - err := ctx.Response.Write(w) - ctx.Response.Reset() - return err -} - -const ( - defaultReadBufferSize = 4096 - defaultWriteBufferSize = 4096 -) - -func acquireByteReader(ctxP **RequestCtx) (*bufio.Reader, error) { - ctx := *ctxP - s := ctx.s - c := ctx.c - t := ctx.time - s.releaseCtx(ctx) - - // Make GC happy, so it could garbage collect ctx - // while we waiting for the next request. - ctx = nil - *ctxP = nil - - v := s.bytePool.Get() - if v == nil { - v = make([]byte, 1) - } - b := v.([]byte) - n, err := c.Read(b) - ch := b[0] - s.bytePool.Put(v) - ctx = s.acquireCtx(c) - ctx.time = t - *ctxP = ctx - if err != nil { - // Treat all errors as EOF on unsuccessful read - // of the first request byte. - return nil, io.EOF - } - if n != 1 { - panic("BUG: Reader must return at least one byte") - } - - ctx.fbr.c = c - ctx.fbr.ch = ch - ctx.fbr.byteRead = false - r := acquireReader(ctx) - r.Reset(&ctx.fbr) - return r, nil -} - -func acquireReader(ctx *RequestCtx) *bufio.Reader { - v := ctx.s.readerPool.Get() - if v == nil { - n := ctx.s.ReadBufferSize - if n <= 0 { - n = defaultReadBufferSize - } - return bufio.NewReaderSize(ctx.c, n) - } - r := v.(*bufio.Reader) - r.Reset(ctx.c) - return r -} - -func releaseReader(s *Server, r *bufio.Reader) { - s.readerPool.Put(r) -} - -func acquireWriter(ctx *RequestCtx) *bufio.Writer { - v := ctx.s.writerPool.Get() - if v == nil { - n := ctx.s.WriteBufferSize - if n <= 0 { - n = defaultWriteBufferSize - } - return bufio.NewWriterSize(ctx.c, n) - } - w := v.(*bufio.Writer) - w.Reset(ctx.c) - return w -} - -func releaseWriter(s *Server, w *bufio.Writer) { - s.writerPool.Put(w) -} - -func (s *Server) acquireCtx(c net.Conn) *RequestCtx { - v := s.ctxPool.Get() - var ctx *RequestCtx - if v == nil { - ctx = &RequestCtx{ - s: s, - } - keepBodyBuffer := !s.ReduceMemoryUsage - ctx.Request.keepBodyBuffer = keepBodyBuffer - ctx.Response.keepBodyBuffer = keepBodyBuffer - } else { - ctx = v.(*RequestCtx) - } - ctx.c = c - return ctx -} - -// Init2 prepares ctx for passing to RequestHandler. -// -// conn is used only for determining local and remote addresses. -// -// This function is intended for custom Server implementations. -// See https://github.com/valyala/httpteleport for details. -func (ctx *RequestCtx) Init2(conn net.Conn, logger Logger, reduceMemoryUsage bool) { - ctx.c = conn - ctx.logger.logger = logger - ctx.connID = nextConnID() - ctx.s = fakeServer - ctx.connRequestNum = 0 - ctx.connTime = time.Now() - ctx.time = ctx.connTime - - keepBodyBuffer := !reduceMemoryUsage - ctx.Request.keepBodyBuffer = keepBodyBuffer - ctx.Response.keepBodyBuffer = keepBodyBuffer -} - -// Init prepares ctx for passing to RequestHandler. -// -// remoteAddr and logger are optional. They are used by RequestCtx.Logger(). -// -// This function is intended for custom Server implementations. -func (ctx *RequestCtx) Init(req *Request, remoteAddr net.Addr, logger Logger) { - if remoteAddr == nil { - remoteAddr = zeroTCPAddr - } - c := &fakeAddrer{ - laddr: zeroTCPAddr, - raddr: remoteAddr, - } - if logger == nil { - logger = defaultLogger - } - ctx.Init2(c, logger, true) - req.CopyTo(&ctx.Request) -} - -var fakeServer = &Server{ - // Initialize concurrencyCh for TimeoutHandler - concurrencyCh: make(chan struct{}, DefaultConcurrency), -} - -type fakeAddrer struct { - net.Conn - laddr net.Addr - raddr net.Addr -} - -func (fa *fakeAddrer) RemoteAddr() net.Addr { - return fa.raddr -} - -func (fa *fakeAddrer) LocalAddr() net.Addr { - return fa.laddr -} - -func (fa *fakeAddrer) Read(p []byte) (int, error) { - panic("BUG: unexpected Read call") -} - -func (fa *fakeAddrer) Write(p []byte) (int, error) { - panic("BUG: unexpected Write call") -} - -func (fa *fakeAddrer) Close() error { - panic("BUG: unexpected Close call") -} - -func (s *Server) releaseCtx(ctx *RequestCtx) { - if ctx.timeoutResponse != nil { - panic("BUG: cannot release timed out RequestCtx") - } - ctx.c = nil - ctx.fbr.c = nil - s.ctxPool.Put(ctx) -} - -func (s *Server) getServerName() []byte { - v := s.serverName.Load() - var serverName []byte - if v == nil { - serverName = []byte(s.Name) - if len(serverName) == 0 { - serverName = defaultServerName - } - s.serverName.Store(serverName) - } else { - serverName = v.([]byte) - } - return serverName -} - -func (s *Server) writeFastError(w io.Writer, statusCode int, msg string) { - w.Write(statusLine(statusCode)) - fmt.Fprintf(w, "Connection: close\r\n"+ - "Server: %s\r\n"+ - "Date: %s\r\n"+ - "Content-Type: text/plain\r\n"+ - "Content-Length: %d\r\n"+ - "\r\n"+ - "%s", - s.getServerName(), serverDate.Load(), len(msg), msg) -} - -func writeErrorResponse(bw *bufio.Writer, ctx *RequestCtx, err error) *bufio.Writer { - if _, ok := err.(*ErrSmallBuffer); ok { - ctx.Error("Too big request header", StatusRequestHeaderFieldsTooLarge) - } else { - ctx.Error("Error when parsing request", StatusBadRequest) - } - ctx.SetConnectionClose() - if bw == nil { - bw = acquireWriter(ctx) - } - writeResponse(ctx, bw) - bw.Flush() - return bw -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key deleted file mode 100644 index 00a79a3b..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD4IQusAs8PJdnG -3mURt/AXtgC+ceqLOatJ49JJE1VPTkMAy+oE1f1XvkMrYsHqmDf6GWVzgVXryL4U -wq2/nJSm56ddhN55nI8oSN3dtywUB8/ShelEN73nlN77PeD9tl6NksPwWaKrqxq0 -FlabRPZSQCfmgZbhDV8Sa8mfCkFU0G0lit6kLGceCKMvmW+9Bz7ebsYmVdmVMxmf -IJStFD44lWFTdUc65WISKEdW2ELcUefb0zOLw+0PCbXFGJH5x5ktksW8+BBk2Hkg -GeQRL/qPCccthbScO0VgNj3zJ3ZZL0ObSDAbvNDG85joeNjDNq5DT/BAZ0bOSbEF -sh+f9BAzAgMBAAECggEBAJWv2cq7Jw6MVwSRxYca38xuD6TUNBopgBvjREixURW2 -sNUaLuMb9Omp7fuOaE2N5rcJ+xnjPGIxh/oeN5MQctz9gwn3zf6vY+15h97pUb4D -uGvYPRDaT8YVGS+X9NMZ4ZCmqW2lpWzKnCFoGHcy8yZLbcaxBsRdvKzwOYGoPiFb -K2QuhXZ/1UPmqK9i2DFKtj40X6vBszTNboFxOVpXrPu0FJwLVSDf2hSZ4fMM0DH3 -YqwKcYf5te+hxGKgrqRA3tn0NCWii0in6QIwXMC+kMw1ebg/tZKqyDLMNptAK8J+ -DVw9m5X1seUHS5ehU/g2jrQrtK5WYn7MrFK4lBzlRwECgYEA/d1TeANYECDWRRDk -B0aaRZs87Rwl/J9PsvbsKvtU/bX+OfSOUjOa9iQBqn0LmU8GqusEET/QVUfocVwV -Bggf/5qDLxz100Rj0ags/yE/kNr0Bb31kkkKHFMnCT06YasR7qKllwrAlPJvQv9x -IzBKq+T/Dx08Wep9bCRSFhzRCnsCgYEA+jdeZXTDr/Vz+D2B3nAw1frqYFfGnEVY -wqmoK3VXMDkGuxsloO2rN+SyiUo3JNiQNPDub/t7175GH5pmKtZOlftePANsUjBj -wZ1D0rI5Bxu/71ibIUYIRVmXsTEQkh/ozoh3jXCZ9+bLgYiYx7789IUZZSokFQ3D -FICUT9KJ36kCgYAGoq9Y1rWJjmIrYfqj2guUQC+CfxbbGIrrwZqAsRsSmpwvhZ3m -tiSZxG0quKQB+NfSxdvQW5ulbwC7Xc3K35F+i9pb8+TVBdeaFkw+yu6vaZmxQLrX -fQM/pEjD7A7HmMIaO7QaU5SfEAsqdCTP56Y8AftMuNXn/8IRfo2KuGwaWwKBgFpU -ILzJoVdlad9E/Rw7LjYhZfkv1uBVXIyxyKcfrkEXZSmozDXDdxsvcZCEfVHM6Ipk -K/+7LuMcqp4AFEAEq8wTOdq6daFaHLkpt/FZK6M4TlruhtpFOPkoNc3e45eM83OT -6mziKINJC1CQ6m65sQHpBtjxlKMRG8rL/D6wx9s5AoGBAMRlqNPMwglT3hvDmsAt -9Lf9pdmhERUlHhD8bj8mDaBj2Aqv7f6VRJaYZqP403pKKQexuqcn80mtjkSAPFkN -Cj7BVt/RXm5uoxDTnfi26RF9F6yNDEJ7UU9+peBr99aazF/fTgW/1GcMkQnum8uV -c257YgaWmjK9uB0Y2r2VxS0G ------END PRIVATE KEY----- diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem deleted file mode 100644 index 93e77cd9..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICujCCAaKgAwIBAgIJAMbXnKZ/cikUMA0GCSqGSIb3DQEBCwUAMBUxEzARBgNV -BAMTCnVidW50dS5uYW4wHhcNMTUwMjA0MDgwMTM5WhcNMjUwMjAxMDgwMTM5WjAV -MRMwEQYDVQQDEwp1YnVudHUubmFuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEA+CELrALPDyXZxt5lEbfwF7YAvnHqizmrSePSSRNVT05DAMvqBNX9V75D -K2LB6pg3+hllc4FV68i+FMKtv5yUpuenXYTeeZyPKEjd3bcsFAfP0oXpRDe955Te -+z3g/bZejZLD8Fmiq6satBZWm0T2UkAn5oGW4Q1fEmvJnwpBVNBtJYrepCxnHgij -L5lvvQc+3m7GJlXZlTMZnyCUrRQ+OJVhU3VHOuViEihHVthC3FHn29Mzi8PtDwm1 -xRiR+ceZLZLFvPgQZNh5IBnkES/6jwnHLYW0nDtFYDY98yd2WS9Dm0gwG7zQxvOY -6HjYwzauQ0/wQGdGzkmxBbIfn/QQMwIDAQABow0wCzAJBgNVHRMEAjAAMA0GCSqG -SIb3DQEBCwUAA4IBAQBQjKm/4KN/iTgXbLTL3i7zaxYXFLXsnT1tF+ay4VA8aj98 -L3JwRTciZ3A5iy/W4VSCt3eASwOaPWHKqDBB5RTtL73LoAqsWmO3APOGQAbixcQ2 -45GXi05OKeyiYRi1Nvq7Unv9jUkRDHUYVPZVSAjCpsXzPhFkmZoTRxmx5l0ZF7Li -K91lI5h+eFq0dwZwrmlPambyh1vQUi70VHv8DNToVU29kel7YLbxGbuqETfhrcy6 -X+Mha6RYITkAn5FqsZcKMsc9eYGEF4l3XV+oS7q6xfTxktYJMFTI18J0lQ2Lv/CI -whdMnYGntDQBE/iFCrJEGNsKGc38796GBOb5j+zd ------END CERTIFICATE----- diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go deleted file mode 100644 index 7b7e53e3..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go +++ /dev/null @@ -1,77 +0,0 @@ -package fasthttp - -var ( - defaultServerName = []byte("fasthttp") - defaultUserAgent = []byte("fasthttp") - defaultContentType = []byte("text/plain; charset=utf-8") -) - -var ( - strSlash = []byte("/") - strSlashSlash = []byte("//") - strSlashDotDot = []byte("/..") - strSlashDotSlash = []byte("/./") - strSlashDotDotSlash = []byte("/../") - strCRLF = []byte("\r\n") - strHTTP = []byte("http") - strHTTPS = []byte("https") - strHTTP11 = []byte("HTTP/1.1") - strColonSlashSlash = []byte("://") - strColonSpace = []byte(": ") - strGMT = []byte("GMT") - - strResponseContinue = []byte("HTTP/1.1 100 Continue\r\n\r\n") - - strGet = []byte("GET") - strHead = []byte("HEAD") - strPost = []byte("POST") - strPut = []byte("PUT") - strDelete = []byte("DELETE") - strConnect = []byte("CONNECT") - strOptions = []byte("OPTIONS") - strTrace = []byte("TRACE") - strPatch = []byte("PATCH") - - strExpect = []byte("Expect") - strConnection = []byte("Connection") - strContentLength = []byte("Content-Length") - strContentType = []byte("Content-Type") - strDate = []byte("Date") - strHost = []byte("Host") - strReferer = []byte("Referer") - strServer = []byte("Server") - strTransferEncoding = []byte("Transfer-Encoding") - strContentEncoding = []byte("Content-Encoding") - strAcceptEncoding = []byte("Accept-Encoding") - strUserAgent = []byte("User-Agent") - strCookie = []byte("Cookie") - strSetCookie = []byte("Set-Cookie") - strLocation = []byte("Location") - strIfModifiedSince = []byte("If-Modified-Since") - strLastModified = []byte("Last-Modified") - strAcceptRanges = []byte("Accept-Ranges") - strRange = []byte("Range") - strContentRange = []byte("Content-Range") - - strCookieExpires = []byte("expires") - strCookieDomain = []byte("domain") - strCookiePath = []byte("path") - strCookieHTTPOnly = []byte("HttpOnly") - strCookieSecure = []byte("secure") - - strClose = []byte("close") - strGzip = []byte("gzip") - strDeflate = []byte("deflate") - strKeepAlive = []byte("keep-alive") - strKeepAliveCamelCase = []byte("Keep-Alive") - strUpgrade = []byte("Upgrade") - strChunked = []byte("chunked") - strIdentity = []byte("identity") - str100Continue = []byte("100-continue") - strPostArgsContentType = []byte("application/x-www-form-urlencoded") - strMultipartFormData = []byte("multipart/form-data") - strBoundary = []byte("boundary") - strBytes = []byte("bytes") - strTextSlash = []byte("text/") - strApplicationSlash = []byte("application/") -) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go deleted file mode 100644 index 081ac65c..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go +++ /dev/null @@ -1,231 +0,0 @@ -package fasthttp - -import ( - "net" - "runtime" - "strings" - "sync" - "time" -) - -// workerPool serves incoming connections via a pool of workers -// in FILO order, i.e. the most recently stopped worker will serve the next -// incoming connection. -// -// Such a scheme keeps CPU caches hot (in theory). -type workerPool struct { - // Function for serving server connections. - // It must leave c unclosed. - WorkerFunc func(c net.Conn) error - - MaxWorkersCount int - - LogAllErrors bool - - MaxIdleWorkerDuration time.Duration - - Logger Logger - - lock sync.Mutex - workersCount int - mustStop bool - - ready []*workerChan - - stopCh chan struct{} - - workerChanPool sync.Pool -} - -type workerChan struct { - lastUseTime time.Time - ch chan net.Conn -} - -func (wp *workerPool) Start() { - if wp.stopCh != nil { - panic("BUG: workerPool already started") - } - wp.stopCh = make(chan struct{}) - stopCh := wp.stopCh - go func() { - var scratch []*workerChan - for { - wp.clean(&scratch) - select { - case <-stopCh: - return - default: - time.Sleep(wp.getMaxIdleWorkerDuration()) - } - } - }() -} - -func (wp *workerPool) Stop() { - if wp.stopCh == nil { - panic("BUG: workerPool wasn't started") - } - close(wp.stopCh) - wp.stopCh = nil - - // Stop all the workers waiting for incoming connections. - // Do not wait for busy workers - they will stop after - // serving the connection and noticing wp.mustStop = true. - wp.lock.Lock() - ready := wp.ready - for i, ch := range ready { - ch.ch <- nil - ready[i] = nil - } - wp.ready = ready[:0] - wp.mustStop = true - wp.lock.Unlock() -} - -func (wp *workerPool) getMaxIdleWorkerDuration() time.Duration { - if wp.MaxIdleWorkerDuration <= 0 { - return 10 * time.Second - } - return wp.MaxIdleWorkerDuration -} - -func (wp *workerPool) clean(scratch *[]*workerChan) { - maxIdleWorkerDuration := wp.getMaxIdleWorkerDuration() - - // Clean least recently used workers if they didn't serve connections - // for more than maxIdleWorkerDuration. - currentTime := time.Now() - - wp.lock.Lock() - ready := wp.ready - n := len(ready) - i := 0 - for i < n && currentTime.Sub(ready[i].lastUseTime) > maxIdleWorkerDuration { - i++ - } - *scratch = append((*scratch)[:0], ready[:i]...) - if i > 0 { - m := copy(ready, ready[i:]) - for i = m; i < n; i++ { - ready[i] = nil - } - wp.ready = ready[:m] - } - wp.lock.Unlock() - - // Notify obsolete workers to stop. - // This notification must be outside the wp.lock, since ch.ch - // may be blocking and may consume a lot of time if many workers - // are located on non-local CPUs. - tmp := *scratch - for i, ch := range tmp { - ch.ch <- nil - tmp[i] = nil - } -} - -func (wp *workerPool) Serve(c net.Conn) bool { - ch := wp.getCh() - if ch == nil { - return false - } - ch.ch <- c - return true -} - -var workerChanCap = func() int { - // Use blocking workerChan if GOMAXPROCS=1. - // This immediately switches Serve to WorkerFunc, which results - // in higher performance (under go1.5 at least). - if runtime.GOMAXPROCS(0) == 1 { - return 0 - } - - // Use non-blocking workerChan if GOMAXPROCS>1, - // since otherwise the Serve caller (Acceptor) may lag accepting - // new connections if WorkerFunc is CPU-bound. - return 1 -}() - -func (wp *workerPool) getCh() *workerChan { - var ch *workerChan - createWorker := false - - wp.lock.Lock() - ready := wp.ready - n := len(ready) - 1 - if n < 0 { - if wp.workersCount < wp.MaxWorkersCount { - createWorker = true - wp.workersCount++ - } - } else { - ch = ready[n] - ready[n] = nil - wp.ready = ready[:n] - } - wp.lock.Unlock() - - if ch == nil { - if !createWorker { - return nil - } - vch := wp.workerChanPool.Get() - if vch == nil { - vch = &workerChan{ - ch: make(chan net.Conn, workerChanCap), - } - } - ch = vch.(*workerChan) - go func() { - wp.workerFunc(ch) - wp.workerChanPool.Put(vch) - }() - } - return ch -} - -func (wp *workerPool) release(ch *workerChan) bool { - ch.lastUseTime = time.Now() - wp.lock.Lock() - if wp.mustStop { - wp.lock.Unlock() - return false - } - wp.ready = append(wp.ready, ch) - wp.lock.Unlock() - return true -} - -func (wp *workerPool) workerFunc(ch *workerChan) { - var c net.Conn - - var err error - for c = range ch.ch { - if c == nil { - break - } - - if err = wp.WorkerFunc(c); err != nil && err != errHijacked { - errStr := err.Error() - if wp.LogAllErrors || !(strings.Contains(errStr, "broken pipe") || - strings.Contains(errStr, "reset by peer") || - strings.Contains(errStr, "i/o timeout")) { - wp.Logger.Printf("error when serving connection %q<->%q: %s", c.LocalAddr(), c.RemoteAddr(), err) - } - } - if err != errHijacked { - c.Close() - } - c = nil - - if !wp.release(ch) { - break - } - } - - wp.lock.Lock() - wp.workersCount-- - wp.lock.Unlock() -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml new file mode 100644 index 00000000..6a6ec2eb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml @@ -0,0 +1,15 @@ +language: go + +go: + - 1.6 + +script: + # build test for supported platforms + - GOOS=linux go build + - GOOS=darwin go build + - GOOS=freebsd go build + - GOOS=windows go build + - GOARCH=386 go build + + # run tests on a standard platform + - go test -v ./... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/README.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/README.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/bytebuffer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/bytebuffer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/bytebuffer.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/bytebuffer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/pool.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/pool.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/pool.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/pool.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore new file mode 100644 index 00000000..7b58ce45 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore @@ -0,0 +1,3 @@ +tags +*.pprof +*.fasthttp.gz diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml new file mode 100644 index 00000000..fca54a82 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml @@ -0,0 +1,36 @@ +language: go + +go: + - tip + - 1.11 + - 1.10.x + - 1.9.x + +os: + - linux + - osx + +matrix: + allow_failures: + - tip + fast_finish: true + +before_install: + - go get -t -v ./... + # - go get -v golang.org/x/tools/cmd/goimports + +script: + # TODO(@kirilldanshin) + # - test -z "$(goimports -d $(find . -type f -name '*.go' -not -path "./vendor/*"))" + # build test for supported platforms + - GOOS=linux go build + - GOOS=darwin go build + - GOOS=freebsd go build + - GOOS=windows go build + - GOARCH=386 go build + + # run tests on a standard platform + - go test -v ./... + + # run tests with the race detector as well + - go test -race -v ./... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/README.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/README.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/TODO b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/TODO similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/TODO rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/TODO diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/args.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/args.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/args.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/args.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv_32.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_32.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv_32.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_32.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv_64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv_64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/client.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/client.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/client.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/client.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/coarseTime.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/coarseTime.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/coarseTime.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/coarseTime.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/compress.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/compress.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/compress.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/compress.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/cookie.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/cookie.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/cookie.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/cookie.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fs.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fs.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fs.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fs.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.mod b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.mod similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.mod rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.mod diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.sum b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.sum similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.sum rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.sum diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/header.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/header.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/header.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/header.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/http.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/http.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/http.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/http.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/lbclient.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/lbclient.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/lbclient.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/lbclient.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/nocopy.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/nocopy.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/nocopy.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/nocopy.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/peripconn.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/peripconn.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/peripconn.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/peripconn.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/server.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/server.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/server.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/server.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/func.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/func.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/func.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/func.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/writer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/writer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stackless/writer.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/writer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/status.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/status.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/status.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/status.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stream.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stream.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/stream.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stream.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/strings.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/strings.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/strings.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/strings.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/tcpdialer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/tcpdialer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/tcpdialer.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/tcpdialer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/timer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/timer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/timer.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/timer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri_unix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri_unix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri_windows.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_windows.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/uri_windows.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_windows.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/userdata.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/userdata.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/userdata.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/userdata.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/workerpool.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/workerpool.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/workerpool.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/workerpool.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore new file mode 100644 index 00000000..26520536 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore @@ -0,0 +1 @@ +y.output diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml new file mode 100644 index 00000000..43c9bafa --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml @@ -0,0 +1,17 @@ +dist: trusty +sudo: false + +language: go +go: + - 1.6.x + - 1.7.x + - 1.8.x + - 1.9.x + +before_install: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + - go install golang.org/x/tools/cmd/goyacc + +script: + - travis_retry $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go deleted file mode 100644 index 6d8c1ef1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go +++ /dev/null @@ -1,511 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestPreview(t *testing.T) { - testcases := []struct { - sql string - want int - }{ - {"select ...", StmtSelect}, - {" select ...", StmtSelect}, - {"(select ...", StmtSelect}, - {"insert ...", StmtInsert}, - {"replace ....", StmtReplace}, - {" update ...", StmtUpdate}, - {"Update", StmtUpdate}, - {"UPDATE ...", StmtUpdate}, - {"\n\t delete ...", StmtDelete}, - {"", StmtUnknown}, - {" ", StmtUnknown}, - {"begin", StmtBegin}, - {" begin", StmtBegin}, - {" begin ", StmtBegin}, - {"\n\t begin ", StmtBegin}, - {"... begin ", StmtUnknown}, - {"begin ...", StmtUnknown}, - {"begin /* ... */", StmtBegin}, - {"begin /* ... *//*test*/", StmtBegin}, - {"start transaction", StmtBegin}, - {"commit", StmtCommit}, - {"commit /*...*/", StmtCommit}, - {"rollback", StmtRollback}, - {"rollback /*...*/", StmtRollback}, - {"create", StmtDDL}, - {"alter", StmtDDL}, - {"rename", StmtDDL}, - {"drop", StmtDDL}, - {"set", StmtSet}, - {"show", StmtShow}, - {"use", StmtUse}, - {"analyze", StmtOther}, - {"describe", StmtOther}, - {"desc", StmtOther}, - {"explain", StmtOther}, - {"repair", StmtOther}, - {"optimize", StmtOther}, - {"truncate", StmtDDL}, - {"unknown", StmtUnknown}, - - {"/* leading comment */ select ...", StmtSelect}, - {"/* leading comment */ (select ...", StmtSelect}, - {"/* leading comment */ /* leading comment 2 */ select ...", StmtSelect}, - {"/*! MySQL-specific comment */", StmtComment}, - {"/*!50708 MySQL-version comment */", StmtComment}, - {"-- leading single line comment \n select ...", StmtSelect}, - {"-- leading single line comment \n -- leading single line comment 2\n select ...", StmtSelect}, - - {"/* leading comment no end select ...", StmtUnknown}, - {"-- leading single line comment no end select ...", StmtUnknown}, - } - for _, tcase := range testcases { - if got := Preview(tcase.sql); got != tcase.want { - t.Errorf("Preview(%s): %v, want %v", tcase.sql, got, tcase.want) - } - } -} - -func TestIsDML(t *testing.T) { - testcases := []struct { - sql string - want bool - }{ - {" update ...", true}, - {"Update", true}, - {"UPDATE ...", true}, - {"\n\t delete ...", true}, - {"insert ...", true}, - {"replace ...", true}, - {"select ...", false}, - {" select ...", false}, - {"", false}, - {" ", false}, - } - for _, tcase := range testcases { - if got := IsDML(tcase.sql); got != tcase.want { - t.Errorf("IsDML(%s): %v, want %v", tcase.sql, got, tcase.want) - } - } -} - -func TestGetTableName(t *testing.T) { - testcases := []struct { - in, out string - }{{ - in: "select * from t", - out: "t", - }, { - in: "select * from t.t", - out: "", - }, { - in: "select * from (select * from t) as tt", - out: "", - }} - - for _, tc := range testcases { - tree, err := Parse(tc.in) - if err != nil { - t.Error(err) - continue - } - out := GetTableName(tree.(*Select).From[0].(*AliasedTableExpr).Expr) - if out.String() != tc.out { - t.Errorf("GetTableName('%s'): %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestIsColName(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: &ColName{}, - out: true, - }, { - in: newHexVal(""), - }} - for _, tc := range testcases { - out := IsColName(tc.in) - if out != tc.out { - t.Errorf("IsColName(%T): %v, want %v", tc.in, out, tc.out) - } - } -} - -func TestIsValue(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: newStrVal("aa"), - out: true, - }, { - in: newHexVal("3131"), - out: true, - }, { - in: newIntVal("1"), - out: true, - }, { - in: newValArg(":a"), - out: true, - }, { - in: &NullVal{}, - out: false, - }} - for _, tc := range testcases { - out := IsValue(tc.in) - if out != tc.out { - t.Errorf("IsValue(%T): %v, want %v", tc.in, out, tc.out) - } - if tc.out { - // NewPlanValue should not fail for valid values. - if _, err := NewPlanValue(tc.in); err != nil { - t.Error(err) - } - } - } -} - -func TestIsNull(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: &NullVal{}, - out: true, - }, { - in: newStrVal(""), - }} - for _, tc := range testcases { - out := IsNull(tc.in) - if out != tc.out { - t.Errorf("IsNull(%T): %v, want %v", tc.in, out, tc.out) - } - } -} - -func TestIsSimpleTuple(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: ValTuple{newStrVal("aa")}, - out: true, - }, { - in: ValTuple{&ColName{}}, - }, { - in: ListArg("::a"), - out: true, - }, { - in: &ColName{}, - }} - for _, tc := range testcases { - out := IsSimpleTuple(tc.in) - if out != tc.out { - t.Errorf("IsSimpleTuple(%T): %v, want %v", tc.in, out, tc.out) - } - if tc.out { - // NewPlanValue should not fail for valid tuples. - if _, err := NewPlanValue(tc.in); err != nil { - t.Error(err) - } - } - } -} - -func TestNewPlanValue(t *testing.T) { - tcases := []struct { - in Expr - out sqltypes.PlanValue - err string - }{{ - in: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }, - out: sqltypes.PlanValue{Key: "valarg"}, - }, { - in: &SQLVal{ - Type: IntVal, - Val: []byte("10"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewInt64(10)}, - }, { - in: &SQLVal{ - Type: IntVal, - Val: []byte("1111111111111111111111111111111111111111"), - }, - err: "value out of range", - }, { - in: &SQLVal{ - Type: StrVal, - Val: []byte("strval"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewVarBinary("strval")}, - }, { - in: &SQLVal{ - Type: HexVal, - Val: []byte("3131"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewVarBinary("11")}, - }, { - in: &SQLVal{ - Type: HexVal, - Val: []byte("313"), - }, - err: "odd length hex string", - }, { - in: ListArg("::list"), - out: sqltypes.PlanValue{ListKey: "list"}, - }, { - in: ValTuple{ - &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }, - &SQLVal{ - Type: StrVal, - Val: []byte("strval"), - }, - }, - out: sqltypes.PlanValue{ - Values: []sqltypes.PlanValue{{ - Key: "valarg", - }, { - Value: sqltypes.NewVarBinary("strval"), - }}, - }, - }, { - in: ValTuple{ - &ParenExpr{Expr: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }}, - }, - err: "expression is too complex", - }, { - in: ValTuple{ - ListArg("::list"), - }, - err: "unsupported: nested lists", - }, { - in: &NullVal{}, - out: sqltypes.PlanValue{}, - }, { - in: &ParenExpr{Expr: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }}, - err: "expression is too complex", - }} - for _, tc := range tcases { - got, err := NewPlanValue(tc.in) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("NewPlanValue(%s) error: %v, want '%s'", String(tc.in), err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("NewPlanValue(%s) error: nil, want '%s'", String(tc.in), tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("NewPlanValue(%s): %v, want %v", String(tc.in), got, tc.out) - } - } -} - -func TestStringIn(t *testing.T) { - testcases := []struct { - in1 string - in2 []string - out bool - }{{ - in1: "v1", - in2: []string{"v1", "v2"}, - out: true, - }, { - in1: "v0", - in2: []string{"v1", "v2"}, - }} - for _, tc := range testcases { - out := StringIn(tc.in1, tc.in2...) - if out != tc.out { - t.Errorf("StringIn(%v,%v): %#v, want %#v", tc.in1, tc.in2, out, tc.out) - } - } -} - -func TestExtractSetValues(t *testing.T) { - testcases := []struct { - sql string - out map[SetKey]interface{} - scope string - err string - }{{ - sql: "invalid", - err: "syntax error at position 8 near 'invalid'", - }, { - sql: "select * from t", - err: "ast did not yield *sqlparser.Set: *sqlparser.Select", - }, { - sql: "set autocommit=1+1", - err: "invalid syntax: 1 + 1", - }, { - sql: "set transaction_mode='single'", - out: map[SetKey]interface{}{{Key: "transaction_mode", Scope: "session"}: "single"}, - }, { - sql: "set autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set autocommit=true", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set autocommit=false", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(0)}, - }, { - sql: "set autocommit=on", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: "on"}, - }, { - sql: "set autocommit=off", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: "off"}, - }, { - sql: "set @@global.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "global"}: int64(1)}, - }, { - sql: "set @@global.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "global"}: int64(1)}, - }, { - sql: "set @@session.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.`autocommit`=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.'autocommit'=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.\"autocommit\"=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.'\"autocommit'=1", - out: map[SetKey]interface{}{{Key: "\"autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.`autocommit'`=1", - out: map[SetKey]interface{}{{Key: "autocommit'", Scope: "session"}: int64(1)}, - }, { - sql: "set AUTOCOMMIT=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "SET character_set_results = NULL", - out: map[SetKey]interface{}{{Key: "character_set_results", Scope: "session"}: nil}, - }, { - sql: "SET foo = 0x1234", - err: "invalid value type: 0x1234", - }, { - sql: "SET names utf8", - out: map[SetKey]interface{}{{Key: "names", Scope: "session"}: "utf8"}, - }, { - sql: "SET names ascii collate ascii_bin", - out: map[SetKey]interface{}{{Key: "names", Scope: "session"}: "ascii"}, - }, { - sql: "SET charset default", - out: map[SetKey]interface{}{{Key: "charset", Scope: "session"}: "default"}, - }, { - sql: "SET character set ascii", - out: map[SetKey]interface{}{{Key: "charset", Scope: "session"}: "ascii"}, - }, { - sql: "SET SESSION wait_timeout = 3600", - out: map[SetKey]interface{}{{Key: "wait_timeout", Scope: "session"}: int64(3600)}, - scope: "session", - }, { - sql: "SET GLOBAL wait_timeout = 3600", - out: map[SetKey]interface{}{{Key: "wait_timeout", Scope: "session"}: int64(3600)}, - scope: "global", - }, { - sql: "set session transaction isolation level repeatable read", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "repeatable read"}, - scope: "session", - }, { - sql: "set session transaction isolation level read committed", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "read committed"}, - scope: "session", - }, { - sql: "set session transaction isolation level read uncommitted", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "read uncommitted"}, - scope: "session", - }, { - sql: "set session transaction isolation level serializable", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "serializable"}, - scope: "session", - }, { - sql: "set session tx_read_only = 0", - out: map[SetKey]interface{}{{Key: "tx_read_only", Scope: "session"}: int64(0)}, - scope: "session", - }, { - sql: "set session tx_read_only = 1", - out: map[SetKey]interface{}{{Key: "tx_read_only", Scope: "session"}: int64(1)}, - scope: "session", - }, { - sql: "set session sql_safe_updates = 0", - out: map[SetKey]interface{}{{Key: "sql_safe_updates", Scope: "session"}: int64(0)}, - scope: "session", - }, { - sql: "set session sql_safe_updates = 1", - out: map[SetKey]interface{}{{Key: "sql_safe_updates", Scope: "session"}: int64(1)}, - scope: "session", - }} - for _, tcase := range testcases { - out, _, err := ExtractSetValues(tcase.sql) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ExtractSetValues(%s): %v, want '%s'", tcase.sql, err, tcase.err) - } - } else if err != nil { - t.Errorf("ExtractSetValues(%s): %v, want no error", tcase.sql, err) - } - if !reflect.DeepEqual(out, tcase.out) { - t.Errorf("ExtractSetValues(%s): %v, want '%v'", tcase.sql, out, tcase.out) - } - } -} - -func newStrVal(in string) *SQLVal { - return NewStrVal([]byte(in)) -} - -func newIntVal(in string) *SQLVal { - return NewIntVal([]byte(in)) -} - -func newHexVal(in string) *SQLVal { - return NewHexVal([]byte(in)) -} - -func newValArg(in string) *SQLVal { - return NewValArg([]byte(in)) -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go deleted file mode 100644 index c02d882e..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go +++ /dev/null @@ -1,636 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "encoding/json" - "reflect" - "strings" - "testing" - "unsafe" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestAppend(t *testing.T) { - query := "select * from t where a = 1" - tree, err := Parse(query) - if err != nil { - t.Error(err) - } - var b bytes.Buffer - Append(&b, tree) - got := b.String() - want := query - if got != want { - t.Errorf("Append: %s, want %s", got, want) - } - Append(&b, tree) - got = b.String() - want = query + query - if got != want { - t.Errorf("Append: %s, want %s", got, want) - } -} - -func TestSelect(t *testing.T) { - tree, err := Parse("select * from t where a = 1") - if err != nil { - t.Error(err) - } - expr := tree.(*Select).Where.Expr - - sel := &Select{} - sel.AddWhere(expr) - buf := NewTrackedBuffer(nil) - sel.Where.Format(buf) - want := " where a = 1" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel.AddWhere(expr) - buf = NewTrackedBuffer(nil) - sel.Where.Format(buf) - want = " where a = 1 and a = 1" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel = &Select{} - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having a = 1" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having a = 1 and a = 1" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } - - // OR clauses must be parenthesized. - tree, err = Parse("select * from t where a = 1 or b = 1") - if err != nil { - t.Error(err) - } - expr = tree.(*Select).Where.Expr - sel = &Select{} - sel.AddWhere(expr) - buf = NewTrackedBuffer(nil) - sel.Where.Format(buf) - want = " where (a = 1 or b = 1)" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel = &Select{} - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having (a = 1 or b = 1)" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } -} - -func TestRemoveHints(t *testing.T) { - for _, query := range []string{ - "select * from t use index (i)", - "select * from t force index (i)", - } { - tree, err := Parse(query) - if err != nil { - t.Fatal(err) - } - sel := tree.(*Select) - sel.From = TableExprs{ - sel.From[0].(*AliasedTableExpr).RemoveHints(), - } - buf := NewTrackedBuffer(nil) - sel.Format(buf) - if got, want := buf.String(), "select * from t"; got != want { - t.Errorf("stripped query: %s, want %s", got, want) - } - } -} - -func TestAddOrder(t *testing.T) { - src, err := Parse("select foo, bar from baz order by foo") - if err != nil { - t.Error(err) - } - order := src.(*Select).OrderBy[0] - dst, err := Parse("select * from t") - if err != nil { - t.Error(err) - } - dst.(*Select).AddOrder(order) - buf := NewTrackedBuffer(nil) - dst.Format(buf) - want := "select * from t order by foo asc" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } - dst, err = Parse("select * from t union select * from s") - if err != nil { - t.Error(err) - } - dst.(*Union).AddOrder(order) - buf = NewTrackedBuffer(nil) - dst.Format(buf) - want = "select * from t union select * from s order by foo asc" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } -} - -func TestSetLimit(t *testing.T) { - src, err := Parse("select foo, bar from baz limit 4") - if err != nil { - t.Error(err) - } - limit := src.(*Select).Limit - dst, err := Parse("select * from t") - if err != nil { - t.Error(err) - } - dst.(*Select).SetLimit(limit) - buf := NewTrackedBuffer(nil) - dst.Format(buf) - want := "select * from t limit 4" - if buf.String() != want { - t.Errorf("limit: %q, want %s", buf.String(), want) - } - dst, err = Parse("select * from t union select * from s") - if err != nil { - t.Error(err) - } - dst.(*Union).SetLimit(limit) - buf = NewTrackedBuffer(nil) - dst.Format(buf) - want = "select * from t union select * from s limit 4" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } -} - -func TestWhere(t *testing.T) { - var w *Where - buf := NewTrackedBuffer(nil) - w.Format(buf) - if buf.String() != "" { - t.Errorf("w.Format(nil): %q, want \"\"", buf.String()) - } - w = NewWhere(WhereStr, nil) - buf = NewTrackedBuffer(nil) - w.Format(buf) - if buf.String() != "" { - t.Errorf("w.Format(&Where{nil}: %q, want \"\"", buf.String()) - } -} - -func TestIsAggregate(t *testing.T) { - f := FuncExpr{Name: NewColIdent("avg")} - if !f.IsAggregate() { - t.Error("IsAggregate: false, want true") - } - - f = FuncExpr{Name: NewColIdent("Avg")} - if !f.IsAggregate() { - t.Error("IsAggregate: false, want true") - } - - f = FuncExpr{Name: NewColIdent("foo")} - if f.IsAggregate() { - t.Error("IsAggregate: true, want false") - } -} - -func TestReplaceExpr(t *testing.T) { - tcases := []struct { - in, out string - }{{ - in: "select * from t where (select a from b)", - out: ":a", - }, { - in: "select * from t where (select a from b) and b", - out: ":a and b", - }, { - in: "select * from t where a and (select a from b)", - out: "a and :a", - }, { - in: "select * from t where (select a from b) or b", - out: ":a or b", - }, { - in: "select * from t where a or (select a from b)", - out: "a or :a", - }, { - in: "select * from t where not (select a from b)", - out: "not :a", - }, { - in: "select * from t where ((select a from b))", - out: "(:a)", - }, { - in: "select * from t where (select a from b) = 1", - out: ":a = 1", - }, { - in: "select * from t where a = (select a from b)", - out: "a = :a", - }, { - in: "select * from t where a like b escape (select a from b)", - out: "a like b escape :a", - }, { - in: "select * from t where (select a from b) between a and b", - out: ":a between a and b", - }, { - in: "select * from t where a between (select a from b) and b", - out: "a between :a and b", - }, { - in: "select * from t where a between b and (select a from b)", - out: "a between b and :a", - }, { - in: "select * from t where (select a from b) is null", - out: ":a is null", - }, { - // exists should not replace. - in: "select * from t where exists (select a from b)", - out: "exists (select a from b)", - }, { - in: "select * from t where a in ((select a from b), 1)", - out: "a in (:a, 1)", - }, { - in: "select * from t where a in (0, (select a from b), 1)", - out: "a in (0, :a, 1)", - }, { - in: "select * from t where (select a from b) + 1", - out: ":a + 1", - }, { - in: "select * from t where 1+(select a from b)", - out: "1 + :a", - }, { - in: "select * from t where -(select a from b)", - out: "-:a", - }, { - in: "select * from t where interval (select a from b) aa", - out: "interval :a aa", - }, { - in: "select * from t where (select a from b) collate utf8", - out: ":a collate utf8", - }, { - in: "select * from t where func((select a from b), 1)", - out: "func(:a, 1)", - }, { - in: "select * from t where func(1, (select a from b), 1)", - out: "func(1, :a, 1)", - }, { - in: "select * from t where group_concat((select a from b), 1 order by a)", - out: "group_concat(:a, 1 order by a asc)", - }, { - in: "select * from t where group_concat(1 order by (select a from b), a)", - out: "group_concat(1 order by :a asc, a asc)", - }, { - in: "select * from t where group_concat(1 order by a, (select a from b))", - out: "group_concat(1 order by a asc, :a asc)", - }, { - in: "select * from t where substr(a, (select a from b), b)", - out: "substr(a, :a, b)", - }, { - in: "select * from t where substr(a, b, (select a from b))", - out: "substr(a, b, :a)", - }, { - in: "select * from t where convert((select a from b), json)", - out: "convert(:a, json)", - }, { - in: "select * from t where convert((select a from b) using utf8)", - out: "convert(:a using utf8)", - }, { - in: "select * from t where match((select a from b), 1) against (a)", - out: "match(:a, 1) against (a)", - }, { - in: "select * from t where match(1, (select a from b), 1) against (a)", - out: "match(1, :a, 1) against (a)", - }, { - in: "select * from t where match(1, a, 1) against ((select a from b))", - out: "match(1, a, 1) against (:a)", - }, { - in: "select * from t where case (select a from b) when a then b when b then c else d end", - out: "case :a when a then b when b then c else d end", - }, { - in: "select * from t where case a when (select a from b) then b when b then c else d end", - out: "case a when :a then b when b then c else d end", - }, { - in: "select * from t where case a when b then (select a from b) when b then c else d end", - out: "case a when b then :a when b then c else d end", - }, { - in: "select * from t where case a when b then c when (select a from b) then c else d end", - out: "case a when b then c when :a then c else d end", - }, { - in: "select * from t where case a when b then c when d then c else (select a from b) end", - out: "case a when b then c when d then c else :a end", - }} - to := NewValArg([]byte(":a")) - for _, tcase := range tcases { - tree, err := Parse(tcase.in) - if err != nil { - t.Fatal(err) - } - var from *Subquery - _ = Walk(func(node SQLNode) (kontinue bool, err error) { - if sq, ok := node.(*Subquery); ok { - from = sq - return false, nil - } - return true, nil - }, tree) - if from == nil { - t.Fatalf("from is nil for %s", tcase.in) - } - expr := ReplaceExpr(tree.(*Select).Where.Expr, from, to) - got := String(expr) - if tcase.out != got { - t.Errorf("ReplaceExpr(%s): %s, want %s", tcase.in, got, tcase.out) - } - } -} - -func TestExprFromValue(t *testing.T) { - tcases := []struct { - in sqltypes.Value - out SQLNode - err string - }{{ - in: sqltypes.NULL, - out: &NullVal{}, - }, { - in: sqltypes.NewInt64(1), - out: NewIntVal([]byte("1")), - }, { - in: sqltypes.NewFloat64(1.1), - out: NewFloatVal([]byte("1.1")), - }, { - in: sqltypes.MakeTrusted(sqltypes.Decimal, []byte("1.1")), - out: NewFloatVal([]byte("1.1")), - }, { - in: sqltypes.NewVarChar("aa"), - out: NewStrVal([]byte("aa")), - }, { - in: sqltypes.MakeTrusted(sqltypes.Expression, []byte("rand()")), - err: "cannot convert value EXPRESSION(rand()) to AST", - }} - for _, tcase := range tcases { - got, err := ExprFromValue(tcase.in) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ExprFromValue(%v) err: %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Error(err) - } - if got, want := got, tcase.out; !reflect.DeepEqual(got, want) { - t.Errorf("ExprFromValue(%v): %v, want %s", tcase.in, got, want) - } - } -} - -func TestColNameEqual(t *testing.T) { - var c1, c2 *ColName - if c1.Equal(c2) { - t.Error("nil columns equal, want unequal") - } - c1 = &ColName{ - Name: NewColIdent("aa"), - } - c2 = &ColName{ - Name: NewColIdent("bb"), - } - if c1.Equal(c2) { - t.Error("columns equal, want unequal") - } - c2.Name = NewColIdent("aa") - if !c1.Equal(c2) { - t.Error("columns unequal, want equal") - } -} - -func TestColIdent(t *testing.T) { - str := NewColIdent("Ab") - if str.String() != "Ab" { - t.Errorf("String=%s, want Ab", str.String()) - } - if str.String() != "Ab" { - t.Errorf("Val=%s, want Ab", str.String()) - } - if str.Lowered() != "ab" { - t.Errorf("Val=%s, want ab", str.Lowered()) - } - if !str.Equal(NewColIdent("aB")) { - t.Error("str.Equal(NewColIdent(aB))=false, want true") - } - if !str.EqualString("ab") { - t.Error("str.EqualString(ab)=false, want true") - } - str = NewColIdent("") - if str.Lowered() != "" { - t.Errorf("Val=%s, want \"\"", str.Lowered()) - } -} - -func TestColIdentMarshal(t *testing.T) { - str := NewColIdent("Ab") - b, err := json.Marshal(str) - if err != nil { - t.Fatal(err) - } - got := string(b) - want := `"Ab"` - if got != want { - t.Errorf("json.Marshal()= %s, want %s", got, want) - } - var out ColIdent - if err := json.Unmarshal(b, &out); err != nil { - t.Errorf("Unmarshal err: %v, want nil", err) - } - if !reflect.DeepEqual(out, str) { - t.Errorf("Unmarshal: %v, want %v", out, str) - } -} - -func TestColIdentSize(t *testing.T) { - size := unsafe.Sizeof(NewColIdent("")) - want := 2 * unsafe.Sizeof("") - if size != want { - t.Errorf("Size of ColIdent: %d, want 32", want) - } -} - -func TestTableIdentMarshal(t *testing.T) { - str := NewTableIdent("Ab") - b, err := json.Marshal(str) - if err != nil { - t.Fatal(err) - } - got := string(b) - want := `"Ab"` - if got != want { - t.Errorf("json.Marshal()= %s, want %s", got, want) - } - var out TableIdent - if err := json.Unmarshal(b, &out); err != nil { - t.Errorf("Unmarshal err: %v, want nil", err) - } - if !reflect.DeepEqual(out, str) { - t.Errorf("Unmarshal: %v, want %v", out, str) - } -} - -func TestHexDecode(t *testing.T) { - testcase := []struct { - in, out string - }{{ - in: "313233", - out: "123", - }, { - in: "ag", - out: "encoding/hex: invalid byte: U+0067 'g'", - }, { - in: "777", - out: "encoding/hex: odd length hex string", - }} - for _, tc := range testcase { - out, err := newHexVal(tc.in).HexDecode() - if err != nil { - if err.Error() != tc.out { - t.Errorf("Decode(%q): %v, want %s", tc.in, err, tc.out) - } - continue - } - if !bytes.Equal(out, []byte(tc.out)) { - t.Errorf("Decode(%q): %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestCompliantName(t *testing.T) { - testcases := []struct { - in, out string - }{{ - in: "aa", - out: "aa", - }, { - in: "1a", - out: "_a", - }, { - in: "a1", - out: "a1", - }, { - in: "a.b", - out: "a_b", - }, { - in: ".ab", - out: "_ab", - }} - for _, tc := range testcases { - out := NewColIdent(tc.in).CompliantName() - if out != tc.out { - t.Errorf("ColIdent(%s).CompliantNamt: %s, want %s", tc.in, out, tc.out) - } - out = NewTableIdent(tc.in).CompliantName() - if out != tc.out { - t.Errorf("TableIdent(%s).CompliantNamt: %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestColumns_FindColumn(t *testing.T) { - cols := Columns{NewColIdent("a"), NewColIdent("c"), NewColIdent("b"), NewColIdent("0")} - - testcases := []struct { - in string - out int - }{{ - in: "a", - out: 0, - }, { - in: "b", - out: 2, - }, - { - in: "0", - out: 3, - }, - { - in: "f", - out: -1, - }} - - for _, tc := range testcases { - val := cols.FindColumn(NewColIdent(tc.in)) - if val != tc.out { - t.Errorf("FindColumn(%s): %d, want %d", tc.in, val, tc.out) - } - } -} - -func TestSplitStatementToPieces(t *testing.T) { - testcases := []struct { - input string - output string - }{{ - input: "select * from table", - }, { - input: "select * from table1; select * from table2;", - output: "select * from table1; select * from table2", - }, { - input: "select * from /* comment ; */ table;", - output: "select * from /* comment ; */ table", - }, { - input: "select * from table where semi = ';';", - output: "select * from table where semi = ';'", - }, { - input: "select * from table1;--comment;\nselect * from table2;", - output: "select * from table1;--comment;\nselect * from table2", - }, { - input: "CREATE TABLE `total_data` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', " + - "`region` varchar(32) NOT NULL COMMENT 'region name, like zh; th; kepler'," + - "`data_size` bigint NOT NULL DEFAULT '0' COMMENT 'data size;'," + - "`createtime` datetime NOT NULL DEFAULT NOW() COMMENT 'create time;'," + - "`comment` varchar(100) NOT NULL DEFAULT '' COMMENT 'comment'," + - "PRIMARY KEY (`id`))", - }} - - for _, tcase := range testcases { - if tcase.output == "" { - tcase.output = tcase.input - } - - stmtPieces, err := SplitStatementToPieces(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - - out := strings.Join(stmtPieces, ";") - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go deleted file mode 100644 index 430293bf..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go +++ /dev/null @@ -1,375 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "testing" -) - -func TestSplitComments(t *testing.T) { - var testCases = []struct { - input, outSQL, outLeadingComments, outTrailingComments string - }{{ - input: "/", - outSQL: "/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "*/", - outSQL: "*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "/*/", - outSQL: "/*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "a*/", - outSQL: "a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "*a*/", - outSQL: "*a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "**a*/", - outSQL: "**a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "/*b**a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*b**a*/", - }, { - input: "/*a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*a*/", - }, { - input: "/**/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/**/", - }, { - input: "/*b*/ /*a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*b*/ /*a*/", - }, { - input: "/* before */ foo /* bar */", - outSQL: "foo", - outLeadingComments: "/* before */ ", - outTrailingComments: " /* bar */", - }, { - input: "/* before1 */ /* before2 */ foo /* after1 */ /* after2 */", - outSQL: "foo", - outLeadingComments: "/* before1 */ /* before2 */ ", - outTrailingComments: " /* after1 */ /* after2 */", - }, { - input: "/** before */ foo /** bar */", - outSQL: "foo", - outLeadingComments: "/** before */ ", - outTrailingComments: " /** bar */", - }, { - input: "/*** before */ foo /*** bar */", - outSQL: "foo", - outLeadingComments: "/*** before */ ", - outTrailingComments: " /*** bar */", - }, { - input: "/** before **/ foo /** bar **/", - outSQL: "foo", - outLeadingComments: "/** before **/ ", - outTrailingComments: " /** bar **/", - }, { - input: "/*** before ***/ foo /*** bar ***/", - outSQL: "foo", - outLeadingComments: "/*** before ***/ ", - outTrailingComments: " /*** bar ***/", - }, { - input: " /*** before ***/ foo /*** bar ***/ ", - outSQL: "foo", - outLeadingComments: "/*** before ***/ ", - outTrailingComments: " /*** bar ***/", - }, { - input: "*** bar ***/", - outSQL: "*** bar ***/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: " foo ", - outSQL: "foo", - outLeadingComments: "", - outTrailingComments: "", - }} - for _, testCase := range testCases { - gotSQL, gotComments := SplitMarginComments(testCase.input) - gotLeadingComments, gotTrailingComments := gotComments.Leading, gotComments.Trailing - - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - if gotLeadingComments != testCase.outLeadingComments { - t.Errorf("test input: '%s', got LeadingComments\n%+v, want\n%+v", testCase.input, gotLeadingComments, testCase.outLeadingComments) - } - if gotTrailingComments != testCase.outTrailingComments { - t.Errorf("test input: '%s', got TrailingComments\n%+v, want\n%+v", testCase.input, gotTrailingComments, testCase.outTrailingComments) - } - } -} - -func TestStripLeadingComments(t *testing.T) { - var testCases = []struct { - input, outSQL string - }{{ - input: "/", - outSQL: "/", - }, { - input: "*/", - outSQL: "*/", - }, { - input: "/*/", - outSQL: "/*/", - }, { - input: "/*a", - outSQL: "/*a", - }, { - input: "/*a*", - outSQL: "/*a*", - }, { - input: "/*a**", - outSQL: "/*a**", - }, { - input: "/*b**a*/", - outSQL: "", - }, { - input: "/*a*/", - outSQL: "", - }, { - input: "/**/", - outSQL: "", - }, { - input: "/*!*/", - outSQL: "/*!*/", - }, { - input: "/*!a*/", - outSQL: "/*!a*/", - }, { - input: "/*b*/ /*a*/", - outSQL: "", - }, { - input: `/*b*/ --foo -bar`, - outSQL: "bar", - }, { - input: "foo /* bar */", - outSQL: "foo /* bar */", - }, { - input: "/* foo */ bar", - outSQL: "bar", - }, { - input: "-- /* foo */ bar", - outSQL: "-- /* foo */ bar", - }, { - input: "foo -- bar */", - outSQL: "foo -- bar */", - }, { - input: `/* -foo */ bar`, - outSQL: "bar", - }, { - input: `-- foo bar -a`, - outSQL: "a", - }, { - input: `-- foo bar`, - outSQL: "-- foo bar", - }} - for _, testCase := range testCases { - gotSQL := StripLeadingComments(testCase.input) - - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - } -} - -func TestExtractMysqlComment(t *testing.T) { - var testCases = []struct { - input, outSQL, outVersion string - }{{ - input: "/*!50708SET max_execution_time=5000 */", - outSQL: "SET max_execution_time=5000", - outVersion: "50708", - }, { - input: "/*!50708 SET max_execution_time=5000*/", - outSQL: "SET max_execution_time=5000", - outVersion: "50708", - }, { - input: "/*!50708* from*/", - outSQL: "* from", - outVersion: "50708", - }, { - input: "/*! SET max_execution_time=5000*/", - outSQL: "SET max_execution_time=5000", - outVersion: "", - }} - for _, testCase := range testCases { - gotVersion, gotSQL := ExtractMysqlComment(testCase.input) - - if gotVersion != testCase.outVersion { - t.Errorf("test input: '%s', got version\n%+v, want\n%+v", testCase.input, gotVersion, testCase.outVersion) - } - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - } -} - -func TestExtractCommentDirectives(t *testing.T) { - var testCases = []struct { - input string - vals CommentDirectives - }{{ - input: "", - vals: nil, - }, { - input: "/* not a vt comment */", - vals: nil, - }, { - input: "/*vt+ */", - vals: CommentDirectives{}, - }, { - input: "/*vt+ SINGLE_OPTION */", - vals: CommentDirectives{ - "SINGLE_OPTION": true, - }, - }, { - input: "/*vt+ ONE_OPT TWO_OPT */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": true, - }, - }, { - input: "/*vt+ ONE_OPT */ /* other comment */ /*vt+ TWO_OPT */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": true, - }, - }, { - input: "/*vt+ ONE_OPT=abc TWO_OPT=def */", - vals: CommentDirectives{ - "ONE_OPT": "abc", - "TWO_OPT": "def", - }, - }, { - input: "/*vt+ ONE_OPT=true TWO_OPT=false */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": false, - }, - }, { - input: "/*vt+ ONE_OPT=true TWO_OPT=\"false\" */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": "\"false\"", - }, - }, { - input: "/*vt+ RANGE_OPT=[a:b] ANOTHER ANOTHER_WITH_VALEQ=val= AND_ONE_WITH_EQ== */", - vals: CommentDirectives{ - "RANGE_OPT": "[a:b]", - "ANOTHER": true, - "ANOTHER_WITH_VALEQ": "val=", - "AND_ONE_WITH_EQ": "=", - }, - }} - - for _, testCase := range testCases { - sql := "select " + testCase.input + " 1 from dual" - stmt, _ := Parse(sql) - comments := stmt.(*Select).Comments - vals := ExtractCommentDirectives(comments) - - if !reflect.DeepEqual(vals, testCase.vals) { - t.Errorf("test input: '%v', got vals:\n%+v, want\n%+v", testCase.input, vals, testCase.vals) - } - } - - d := CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": false, - "three": 1, - "four": 2, - "five": 0, - "six": "true", - } - - if !d.IsSet("ONE_OPT") { - t.Errorf("d.IsSet(ONE_OPT) should be true") - } - - if d.IsSet("TWO_OPT") { - t.Errorf("d.IsSet(TWO_OPT) should be false") - } - - if !d.IsSet("three") { - t.Errorf("d.IsSet(three) should be true") - } - - if d.IsSet("four") { - t.Errorf("d.IsSet(four) should be false") - } - - if d.IsSet("five") { - t.Errorf("d.IsSet(five) should be false") - } - - if d.IsSet("six") { - t.Errorf("d.IsSet(six) should be false") - } -} - -func TestSkipQueryPlanCacheDirective(t *testing.T) { - stmt, _ := Parse("insert /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ into user(id) values (1), (2)") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("insert into user(id) values (1), (2)") - if SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be false") - } - - stmt, _ = Parse("update /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ users set name=1") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("select /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ * from users") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("delete /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ from users") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go deleted file mode 100644 index 6f3b102f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package bytes2 - -import "testing" - -func TestBuffer(t *testing.T) { - b := NewBuffer(nil) - b.Write([]byte("ab")) - b.WriteString("cd") - b.WriteByte('e') - want := "abcde" - if got := string(b.Bytes()); got != want { - t.Errorf("b.Bytes(): %s, want %s", got, want) - } - if got := b.String(); got != want { - t.Errorf("b.String(): %s, want %s", got, want) - } - if got := b.Len(); got != 5 { - t.Errorf("b.Len(): %d, want 5", got) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go deleted file mode 100644 index d8208c6f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package hack - -import "testing" - -func TestStringArena(t *testing.T) { - sarena := NewStringArena(10) - - s0 := sarena.NewString(nil) - checkint(t, len(sarena.buf), 0) - checkint(t, sarena.SpaceLeft(), 10) - checkstring(t, s0, "") - - s1 := sarena.NewString([]byte("01234")) - checkint(t, len(sarena.buf), 5) - checkint(t, sarena.SpaceLeft(), 5) - checkstring(t, s1, "01234") - - s2 := sarena.NewString([]byte("5678")) - checkint(t, len(sarena.buf), 9) - checkint(t, sarena.SpaceLeft(), 1) - checkstring(t, s2, "5678") - - // s3 will be allocated outside of sarena - s3 := sarena.NewString([]byte("ab")) - checkint(t, len(sarena.buf), 9) - checkint(t, sarena.SpaceLeft(), 1) - checkstring(t, s3, "ab") - - // s4 should still fit in sarena - s4 := sarena.NewString([]byte("9")) - checkint(t, len(sarena.buf), 10) - checkint(t, sarena.SpaceLeft(), 0) - checkstring(t, s4, "9") - - sarena.buf[0] = 'A' - checkstring(t, s1, "A1234") - - sarena.buf[5] = 'B' - checkstring(t, s2, "B678") - - sarena.buf[9] = 'C' - // s3 will not change - checkstring(t, s3, "ab") - checkstring(t, s4, "C") - checkstring(t, sarena.str, "A1234B678C") -} - -func checkstring(t *testing.T, actual, expected string) { - if actual != expected { - t.Errorf("received %s, expecting %s", actual, expected) - } -} - -func checkint(t *testing.T, actual, expected int) { - if actual != expected { - t.Errorf("received %d, expecting %d", actual, expected) - } -} - -func TestByteToString(t *testing.T) { - v1 := []byte("1234") - if s := String(v1); s != "1234" { - t.Errorf("String(\"1234\"): %q, want 1234", s) - } - - v1 = []byte("") - if s := String(v1); s != "" { - t.Errorf("String(\"\"): %q, want empty", s) - } - - v1 = nil - if s := String(v1); s != "" { - t.Errorf("String(\"\"): %q, want empty", s) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go deleted file mode 100644 index ca0636c8..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go +++ /dev/null @@ -1,553 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestProtoConversions(t *testing.T) { - v := TestValue(Int64, "1") - got := ValueToProto(v) - want := &querypb.Value{Type: Int64, Value: []byte("1")} - if !reflect.DeepEqual(got, want) { - t.Errorf("ValueToProto: %v, want %v", got, want) - } - gotback := ProtoToValue(got) - if !reflect.DeepEqual(gotback, v) { - t.Errorf("ProtoToValue: %v, want %v", gotback, v) - } -} - -func TestBuildBindVariables(t *testing.T) { - tcases := []struct { - in map[string]interface{} - out map[string]*querypb.BindVariable - err string - }{{ - in: nil, - out: nil, - }, { - in: map[string]interface{}{ - "k": int64(1), - }, - out: map[string]*querypb.BindVariable{ - "k": Int64BindVariable(1), - }, - }, { - in: map[string]interface{}{ - "k": byte(1), - }, - err: "k: type uint8 not supported as bind var: 1", - }} - for _, tcase := range tcases { - bindVars, err := BuildBindVariables(tcase.in) - if err != nil { - if err.Error() != tcase.err { - t.Errorf("MapToBindVars(%v) error: %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if tcase.err != "" { - t.Errorf("MapToBindVars(%v) error: nil, want %s", tcase.in, tcase.err) - continue - } - if !BindVariablesEqual(bindVars, tcase.out) { - t.Errorf("MapToBindVars(%v): %v, want %s", tcase.in, bindVars, tcase.out) - } - } -} - -func TestBuildBindVariable(t *testing.T) { - tcases := []struct { - in interface{} - out *querypb.BindVariable - err string - }{{ - in: "aa", - out: &querypb.BindVariable{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, - }, { - in: []byte("aa"), - out: &querypb.BindVariable{ - Type: querypb.Type_VARBINARY, - Value: []byte("aa"), - }, - }, { - in: int(1), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: int64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: uint64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, - }, { - in: float64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("1"), - }, - }, { - in: nil, - out: NullBindVariable, - }, { - in: MakeTrusted(Int64, []byte("1")), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: []interface{}{"aa", int64(1)}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, { - Type: querypb.Type_INT64, - Value: []byte("1"), - }}, - }, - }, { - in: []string{"aa", "bb"}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, { - Type: querypb.Type_VARCHAR, - Value: []byte("bb"), - }}, - }, - }, { - in: [][]byte{[]byte("aa"), []byte("bb")}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARBINARY, - Value: []byte("aa"), - }, { - Type: querypb.Type_VARBINARY, - Value: []byte("bb"), - }}, - }, - }, { - in: []int{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, { - Type: querypb.Type_INT64, - Value: []byte("2"), - }}, - }, - }, { - in: []int64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, { - Type: querypb.Type_INT64, - Value: []byte("2"), - }}, - }, - }, { - in: []uint64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, { - Type: querypb.Type_UINT64, - Value: []byte("2"), - }}, - }, - }, { - in: []float64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_FLOAT64, - Value: []byte("1"), - }, { - Type: querypb.Type_FLOAT64, - Value: []byte("2"), - }}, - }, - }, { - in: byte(1), - err: "type uint8 not supported as bind var: 1", - }, { - in: []interface{}{1, byte(1)}, - err: "type uint8 not supported as bind var: 1", - }} - for _, tcase := range tcases { - bv, err := BuildBindVariable(tcase.in) - if err != nil { - if err.Error() != tcase.err { - t.Errorf("ToBindVar(%T(%v)) error: %v, want %s", tcase.in, tcase.in, err, tcase.err) - } - continue - } - if tcase.err != "" { - t.Errorf("ToBindVar(%T(%v)) error: nil, want %s", tcase.in, tcase.in, tcase.err) - continue - } - if !reflect.DeepEqual(bv, tcase.out) { - t.Errorf("ToBindVar(%T(%v)): %v, want %s", tcase.in, tcase.in, bv, tcase.out) - } - } -} - -func TestValidateBindVarables(t *testing.T) { - tcases := []struct { - in map[string]*querypb.BindVariable - err string - }{{ - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, - err: "", - }, { - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_INT64, - Value: []byte("a"), - }, - }, - err: `v: strconv.ParseInt: parsing "a": invalid syntax`, - }, { - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: Int64, - Value: []byte("a"), - }}, - }, - }, - err: `v: strconv.ParseInt: parsing "a": invalid syntax`, - }} - for _, tcase := range tcases { - err := ValidateBindVariables(tcase.in) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ValidateBindVars(%v): %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Errorf("ValidateBindVars(%v): %v, want nil", tcase.in, err) - } - } -} - -func TestValidateBindVariable(t *testing.T) { - testcases := []struct { - in *querypb.BindVariable - err string - }{{ - in: &querypb.BindVariable{ - Type: querypb.Type_INT8, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT16, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT24, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT32, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT8, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT16, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT24, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT32, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT32, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DECIMAL, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TIMESTAMP, - Value: []byte("2012-02-24 23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DATE, - Value: []byte("2012-02-24"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TIME, - Value: []byte("23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DATETIME, - Value: []byte("2012-02-24 23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_YEAR, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TEXT, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BLOB, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_VARCHAR, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BINARY, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_CHAR, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BIT, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_ENUM, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_SET, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_VARBINARY, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte(InvalidNeg), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte(InvalidPos), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("-1"), - }, - err: "invalid syntax", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte(InvalidPos), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("a"), - }, - err: "invalid syntax", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_EXPRESSION, - Value: []byte("a"), - }, - err: "invalid type specified for MakeValue: EXPRESSION", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }}, - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - }, - err: "empty tuple is not allowed", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_TUPLE, - }}, - }, - err: "tuple not allowed inside another tuple", - }} - for _, tcase := range testcases { - err := ValidateBindVariable(tcase.in) - if tcase.err != "" { - if err == nil || !strings.Contains(err.Error(), tcase.err) { - t.Errorf("ValidateBindVar(%v) error: %v, must contain %v", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Errorf("ValidateBindVar(%v) error: %v", tcase.in, err) - } - } - - // Special case: nil bind var. - err := ValidateBindVariable(nil) - want := "bind variable is nil" - if err == nil || err.Error() != want { - t.Errorf("ValidateBindVar(nil) error: %v, want %s", err, want) - } -} - -func TestBindVariableToValue(t *testing.T) { - v, err := BindVariableToValue(Int64BindVariable(1)) - if err != nil { - t.Error(err) - } - want := MakeTrusted(querypb.Type_INT64, []byte("1")) - if !reflect.DeepEqual(v, want) { - t.Errorf("BindVarToValue(1): %v, want %v", v, want) - } - - v, err = BindVariableToValue(&querypb.BindVariable{Type: querypb.Type_TUPLE}) - wantErr := "cannot convert a TUPLE bind var into a value" - if err == nil || err.Error() != wantErr { - t.Errorf(" BindVarToValue(TUPLE): %v, want %s", err, wantErr) - } -} - -func TestBindVariablesEqual(t *testing.T) { - bv1 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - bv2 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - bv3 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - if !BindVariablesEqual(bv1, bv2) { - t.Errorf("%v != %v, want equal", bv1, bv2) - } - if !BindVariablesEqual(bv1, bv3) { - t.Errorf("%v = %v, want not equal", bv1, bv3) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go deleted file mode 100644 index ea85c9c6..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go +++ /dev/null @@ -1,319 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestPlanValueIsNull(t *testing.T) { - tcases := []struct { - in PlanValue - out bool - }{{ - in: PlanValue{}, - out: true, - }, { - in: PlanValue{Key: "aa"}, - out: false, - }, { - in: PlanValue{Value: NewVarBinary("aa")}, - out: false, - }, { - in: PlanValue{ListKey: "aa"}, - out: false, - }, { - in: PlanValue{Values: []PlanValue{}}, - out: false, - }} - for _, tc := range tcases { - got := tc.in.IsNull() - if got != tc.out { - t.Errorf("IsNull(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestPlanValueIsList(t *testing.T) { - tcases := []struct { - in PlanValue - out bool - }{{ - in: PlanValue{}, - out: false, - }, { - in: PlanValue{Key: "aa"}, - out: false, - }, { - in: PlanValue{Value: NewVarBinary("aa")}, - out: false, - }, { - in: PlanValue{ListKey: "aa"}, - out: true, - }, { - in: PlanValue{Values: []PlanValue{}}, - out: true, - }} - for _, tc := range tcases { - got := tc.in.IsList() - if got != tc.out { - t.Errorf("IsList(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveRows(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - strValue := MakeTrusted(VarChar, []byte("aa")) - tcases := []struct { - in []PlanValue - out [][]Value - err string - }{{ - // Simple cases. - in: []PlanValue{ - {Key: "int"}, - }, - out: [][]Value{ - {intValue}, - }, - }, { - in: []PlanValue{ - {Value: intValue}, - }, - out: [][]Value{ - {intValue}, - }, - }, { - in: []PlanValue{ - {ListKey: "intstr"}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{ - {Values: []PlanValue{{Value: intValue}, {Value: strValue}}}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{ - {Values: []PlanValue{{Key: "int"}, {Value: strValue}}}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{{}}, - out: [][]Value{ - {NULL}, - }, - }, { - // Cases with varying rowcounts. - // All types of input.. - in: []PlanValue{ - {Key: "int"}, - {Value: strValue}, - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {intValue, strValue, intValue, strValue}, - {intValue, strValue, strValue, intValue}, - }, - }, { - // list, val, list. - in: []PlanValue{ - {Value: strValue}, - {Key: "int"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {strValue, intValue, strValue}, - {strValue, intValue, intValue}, - }, - }, { - // list, list - in: []PlanValue{ - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {intValue, strValue}, - {strValue, intValue}, - }, - }, { - // Error cases - in: []PlanValue{ - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}}}, - }, - err: "mismatch in number of column values", - }, { - // This is a different code path for a similar validation. - in: []PlanValue{ - {Values: []PlanValue{{Value: strValue}}}, - {ListKey: "intstr"}, - }, - err: "mismatch in number of column values", - }, { - in: []PlanValue{ - {Key: "absent"}, - }, - err: "missing bind var", - }, { - in: []PlanValue{ - {ListKey: "absent"}, - }, - err: "missing bind var", - }, { - in: []PlanValue{ - {Values: []PlanValue{{Key: "absent"}}}, - }, - err: "missing bind var", - }} - - for _, tc := range tcases { - got, err := ResolveRows(tc.in, testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveRows(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveRows(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveRows(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveList(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - strValue := MakeTrusted(VarChar, []byte("aa")) - tcases := []struct { - in PlanValue - out []Value - err string - }{{ - in: PlanValue{ListKey: "intstr"}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{Values: []PlanValue{{Value: intValue}, {Value: strValue}}}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{Values: []PlanValue{{Key: "int"}, {Value: strValue}}}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{ListKey: "absent"}, - err: "missing bind var", - }, { - in: PlanValue{Values: []PlanValue{{Key: "absent"}, {Value: strValue}}}, - err: "missing bind var", - }, { - in: PlanValue{ListKey: "int"}, - err: "single value was supplied for TUPLE bind var", - }, { - in: PlanValue{Key: "int"}, - err: "a single value was supplied where a list was expected", - }} - - for _, tc := range tcases { - got, err := tc.in.ResolveList(testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveList(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveList(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveList(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveValue(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - tcases := []struct { - in PlanValue - out Value - err string - }{{ - in: PlanValue{Key: "int"}, - out: intValue, - }, { - in: PlanValue{Value: intValue}, - out: intValue, - }, { - in: PlanValue{}, - out: NULL, - }, { - in: PlanValue{Key: "absent"}, - err: "missing bind var", - }, { - in: PlanValue{Key: "intstr"}, - err: "TUPLE was supplied for single value bind var", - }, { - in: PlanValue{ListKey: "intstr"}, - err: "a list was supplied where a single value was expected", - }} - - for _, tc := range tcases { - got, err := tc.in.ResolveValue(testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveValue(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveValue(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveValue(%v): %v, want %v", tc.in, got, tc.out) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go deleted file mode 100644 index 613fcda1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go +++ /dev/null @@ -1,414 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestTypeValues(t *testing.T) { - testcases := []struct { - defined querypb.Type - expected int - }{{ - defined: Null, - expected: 0, - }, { - defined: Int8, - expected: 1 | flagIsIntegral, - }, { - defined: Uint8, - expected: 2 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int16, - expected: 3 | flagIsIntegral, - }, { - defined: Uint16, - expected: 4 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int24, - expected: 5 | flagIsIntegral, - }, { - defined: Uint24, - expected: 6 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int32, - expected: 7 | flagIsIntegral, - }, { - defined: Uint32, - expected: 8 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int64, - expected: 9 | flagIsIntegral, - }, { - defined: Uint64, - expected: 10 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Float32, - expected: 11 | flagIsFloat, - }, { - defined: Float64, - expected: 12 | flagIsFloat, - }, { - defined: Timestamp, - expected: 13 | flagIsQuoted, - }, { - defined: Date, - expected: 14 | flagIsQuoted, - }, { - defined: Time, - expected: 15 | flagIsQuoted, - }, { - defined: Datetime, - expected: 16 | flagIsQuoted, - }, { - defined: Year, - expected: 17 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Decimal, - expected: 18, - }, { - defined: Text, - expected: 19 | flagIsQuoted | flagIsText, - }, { - defined: Blob, - expected: 20 | flagIsQuoted | flagIsBinary, - }, { - defined: VarChar, - expected: 21 | flagIsQuoted | flagIsText, - }, { - defined: VarBinary, - expected: 22 | flagIsQuoted | flagIsBinary, - }, { - defined: Char, - expected: 23 | flagIsQuoted | flagIsText, - }, { - defined: Binary, - expected: 24 | flagIsQuoted | flagIsBinary, - }, { - defined: Bit, - expected: 25 | flagIsQuoted, - }, { - defined: Enum, - expected: 26 | flagIsQuoted, - }, { - defined: Set, - expected: 27 | flagIsQuoted, - }, { - defined: Geometry, - expected: 29 | flagIsQuoted, - }, { - defined: TypeJSON, - expected: 30 | flagIsQuoted, - }, { - defined: Expression, - expected: 31, - }} - for _, tcase := range testcases { - if int(tcase.defined) != tcase.expected { - t.Errorf("Type %s: %d, want: %d", tcase.defined, int(tcase.defined), tcase.expected) - } - } -} - -// TestCategory verifies that the type categorizations -// are non-overlapping and complete. -func TestCategory(t *testing.T) { - alltypes := []querypb.Type{ - Null, - Int8, - Uint8, - Int16, - Uint16, - Int24, - Uint24, - Int32, - Uint32, - Int64, - Uint64, - Float32, - Float64, - Timestamp, - Date, - Time, - Datetime, - Year, - Decimal, - Text, - Blob, - VarChar, - VarBinary, - Char, - Binary, - Bit, - Enum, - Set, - Geometry, - TypeJSON, - Expression, - } - for _, typ := range alltypes { - matched := false - if IsSigned(typ) { - if !IsIntegral(typ) { - t.Errorf("Signed type %v is not an integral", typ) - } - matched = true - } - if IsUnsigned(typ) { - if !IsIntegral(typ) { - t.Errorf("Unsigned type %v is not an integral", typ) - } - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if IsFloat(typ) { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if IsQuoted(typ) { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if typ == Null || typ == Decimal || typ == Expression { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if !matched { - t.Errorf("%v matched no category", typ) - } - } -} - -func TestIsFunctions(t *testing.T) { - if IsIntegral(Null) { - t.Error("Null: IsIntegral, must be false") - } - if !IsIntegral(Int64) { - t.Error("Int64: !IsIntegral, must be true") - } - if IsSigned(Uint64) { - t.Error("Uint64: IsSigned, must be false") - } - if !IsSigned(Int64) { - t.Error("Int64: !IsSigned, must be true") - } - if IsUnsigned(Int64) { - t.Error("Int64: IsUnsigned, must be false") - } - if !IsUnsigned(Uint64) { - t.Error("Uint64: !IsUnsigned, must be true") - } - if IsFloat(Int64) { - t.Error("Int64: IsFloat, must be false") - } - if !IsFloat(Float64) { - t.Error("Uint64: !IsFloat, must be true") - } - if IsQuoted(Int64) { - t.Error("Int64: IsQuoted, must be false") - } - if !IsQuoted(Binary) { - t.Error("Binary: !IsQuoted, must be true") - } - if IsText(Int64) { - t.Error("Int64: IsText, must be false") - } - if !IsText(Char) { - t.Error("Char: !IsText, must be true") - } - if IsBinary(Int64) { - t.Error("Int64: IsBinary, must be false") - } - if !IsBinary(Binary) { - t.Error("Char: !IsBinary, must be true") - } - if !isNumber(Int64) { - t.Error("Int64: !isNumber, must be true") - } -} - -func TestTypeToMySQL(t *testing.T) { - v, f := TypeToMySQL(Bit) - if v != 16 { - t.Errorf("Bit: %d, want 16", v) - } - if f != mysqlUnsigned { - t.Errorf("Bit flag: %x, want %x", f, mysqlUnsigned) - } - v, f = TypeToMySQL(Date) - if v != 10 { - t.Errorf("Bit: %d, want 10", v) - } - if f != mysqlBinary { - t.Errorf("Bit flag: %x, want %x", f, mysqlBinary) - } -} - -func TestMySQLToType(t *testing.T) { - testcases := []struct { - intype int64 - inflags int64 - outtype querypb.Type - }{{ - intype: 1, - outtype: Int8, - }, { - intype: 1, - inflags: mysqlUnsigned, - outtype: Uint8, - }, { - intype: 2, - outtype: Int16, - }, { - intype: 2, - inflags: mysqlUnsigned, - outtype: Uint16, - }, { - intype: 3, - outtype: Int32, - }, { - intype: 3, - inflags: mysqlUnsigned, - outtype: Uint32, - }, { - intype: 4, - outtype: Float32, - }, { - intype: 5, - outtype: Float64, - }, { - intype: 6, - outtype: Null, - }, { - intype: 7, - outtype: Timestamp, - }, { - intype: 8, - outtype: Int64, - }, { - intype: 8, - inflags: mysqlUnsigned, - outtype: Uint64, - }, { - intype: 9, - outtype: Int24, - }, { - intype: 9, - inflags: mysqlUnsigned, - outtype: Uint24, - }, { - intype: 10, - outtype: Date, - }, { - intype: 11, - outtype: Time, - }, { - intype: 12, - outtype: Datetime, - }, { - intype: 13, - outtype: Year, - }, { - intype: 16, - outtype: Bit, - }, { - intype: 245, - outtype: TypeJSON, - }, { - intype: 246, - outtype: Decimal, - }, { - intype: 249, - outtype: Text, - }, { - intype: 250, - outtype: Text, - }, { - intype: 251, - outtype: Text, - }, { - intype: 252, - outtype: Text, - }, { - intype: 252, - inflags: mysqlBinary, - outtype: Blob, - }, { - intype: 253, - outtype: VarChar, - }, { - intype: 253, - inflags: mysqlBinary, - outtype: VarBinary, - }, { - intype: 254, - outtype: Char, - }, { - intype: 254, - inflags: mysqlBinary, - outtype: Binary, - }, { - intype: 254, - inflags: mysqlEnum, - outtype: Enum, - }, { - intype: 254, - inflags: mysqlSet, - outtype: Set, - }, { - intype: 255, - outtype: Geometry, - }, { - // Binary flag must be ignored. - intype: 8, - inflags: mysqlUnsigned | mysqlBinary, - outtype: Uint64, - }, { - // Unsigned flag must be ignored - intype: 252, - inflags: mysqlUnsigned | mysqlBinary, - outtype: Blob, - }} - for _, tcase := range testcases { - got, err := MySQLToType(tcase.intype, tcase.inflags) - if err != nil { - t.Error(err) - } - if got != tcase.outtype { - t.Errorf("MySQLToType(%d, %x): %v, want %v", tcase.intype, tcase.inflags, got, tcase.outtype) - } - } -} - -func TestTypeError(t *testing.T) { - _, err := MySQLToType(15, 0) - want := "unsupported type: 15" - if err == nil || err.Error() != want { - t.Errorf("MySQLToType: %v, want %s", err, want) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go deleted file mode 100644 index 96b137d1..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go +++ /dev/null @@ -1,408 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "bytes" - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -const ( - InvalidNeg = "-9223372036854775809" - MinNeg = "-9223372036854775808" - MinPos = "18446744073709551615" - InvalidPos = "18446744073709551616" -) - -func TestNewValue(t *testing.T) { - testcases := []struct { - inType querypb.Type - inVal string - outVal Value - outErr string - }{{ - inType: Null, - inVal: "", - outVal: NULL, - }, { - inType: Int8, - inVal: "1", - outVal: TestValue(Int8, "1"), - }, { - inType: Int16, - inVal: "1", - outVal: TestValue(Int16, "1"), - }, { - inType: Int24, - inVal: "1", - outVal: TestValue(Int24, "1"), - }, { - inType: Int32, - inVal: "1", - outVal: TestValue(Int32, "1"), - }, { - inType: Int64, - inVal: "1", - outVal: TestValue(Int64, "1"), - }, { - inType: Uint8, - inVal: "1", - outVal: TestValue(Uint8, "1"), - }, { - inType: Uint16, - inVal: "1", - outVal: TestValue(Uint16, "1"), - }, { - inType: Uint24, - inVal: "1", - outVal: TestValue(Uint24, "1"), - }, { - inType: Uint32, - inVal: "1", - outVal: TestValue(Uint32, "1"), - }, { - inType: Uint64, - inVal: "1", - outVal: TestValue(Uint64, "1"), - }, { - inType: Float32, - inVal: "1.00", - outVal: TestValue(Float32, "1.00"), - }, { - inType: Float64, - inVal: "1.00", - outVal: TestValue(Float64, "1.00"), - }, { - inType: Decimal, - inVal: "1.00", - outVal: TestValue(Decimal, "1.00"), - }, { - inType: Timestamp, - inVal: "2012-02-24 23:19:43", - outVal: TestValue(Timestamp, "2012-02-24 23:19:43"), - }, { - inType: Date, - inVal: "2012-02-24", - outVal: TestValue(Date, "2012-02-24"), - }, { - inType: Time, - inVal: "23:19:43", - outVal: TestValue(Time, "23:19:43"), - }, { - inType: Datetime, - inVal: "2012-02-24 23:19:43", - outVal: TestValue(Datetime, "2012-02-24 23:19:43"), - }, { - inType: Year, - inVal: "1", - outVal: TestValue(Year, "1"), - }, { - inType: Text, - inVal: "a", - outVal: TestValue(Text, "a"), - }, { - inType: Blob, - inVal: "a", - outVal: TestValue(Blob, "a"), - }, { - inType: VarChar, - inVal: "a", - outVal: TestValue(VarChar, "a"), - }, { - inType: Binary, - inVal: "a", - outVal: TestValue(Binary, "a"), - }, { - inType: Char, - inVal: "a", - outVal: TestValue(Char, "a"), - }, { - inType: Bit, - inVal: "1", - outVal: TestValue(Bit, "1"), - }, { - inType: Enum, - inVal: "a", - outVal: TestValue(Enum, "a"), - }, { - inType: Set, - inVal: "a", - outVal: TestValue(Set, "a"), - }, { - inType: VarBinary, - inVal: "a", - outVal: TestValue(VarBinary, "a"), - }, { - inType: Int64, - inVal: InvalidNeg, - outErr: "out of range", - }, { - inType: Int64, - inVal: InvalidPos, - outErr: "out of range", - }, { - inType: Uint64, - inVal: "-1", - outErr: "invalid syntax", - }, { - inType: Uint64, - inVal: InvalidPos, - outErr: "out of range", - }, { - inType: Float64, - inVal: "a", - outErr: "invalid syntax", - }, { - inType: Expression, - inVal: "a", - outErr: "invalid type specified for MakeValue: EXPRESSION", - }} - for _, tcase := range testcases { - v, err := NewValue(tcase.inType, []byte(tcase.inVal)) - if tcase.outErr != "" { - if err == nil || !strings.Contains(err.Error(), tcase.outErr) { - t.Errorf("ValueFromBytes(%v, %v) error: %v, must contain %v", tcase.inType, tcase.inVal, err, tcase.outErr) - } - continue - } - if err != nil { - t.Errorf("ValueFromBytes(%v, %v) error: %v", tcase.inType, tcase.inVal, err) - continue - } - if !reflect.DeepEqual(v, tcase.outVal) { - t.Errorf("ValueFromBytes(%v, %v) = %v, want %v", tcase.inType, tcase.inVal, v, tcase.outVal) - } - } -} - -// TestNew tests 'New' functions that are not tested -// through other code paths. -func TestNew(t *testing.T) { - got := NewInt32(1) - want := MakeTrusted(Int32, []byte("1")) - if !reflect.DeepEqual(got, want) { - t.Errorf("NewInt32(aa): %v, want %v", got, want) - } - - got = NewVarBinary("aa") - want = MakeTrusted(VarBinary, []byte("aa")) - if !reflect.DeepEqual(got, want) { - t.Errorf("NewVarBinary(aa): %v, want %v", got, want) - } -} - -func TestMakeTrusted(t *testing.T) { - v := MakeTrusted(Null, []byte("abcd")) - if !reflect.DeepEqual(v, NULL) { - t.Errorf("MakeTrusted(Null...) = %v, want null", v) - } - v = MakeTrusted(Int64, []byte("1")) - want := TestValue(Int64, "1") - if !reflect.DeepEqual(v, want) { - t.Errorf("MakeTrusted(Int64, \"1\") = %v, want %v", v, want) - } -} - -func TestIntegralValue(t *testing.T) { - testcases := []struct { - in string - outVal Value - outErr string - }{{ - in: MinNeg, - outVal: TestValue(Int64, MinNeg), - }, { - in: "1", - outVal: TestValue(Int64, "1"), - }, { - in: MinPos, - outVal: TestValue(Uint64, MinPos), - }, { - in: InvalidPos, - outErr: "out of range", - }} - for _, tcase := range testcases { - v, err := NewIntegral(tcase.in) - if tcase.outErr != "" { - if err == nil || !strings.Contains(err.Error(), tcase.outErr) { - t.Errorf("BuildIntegral(%v) error: %v, must contain %v", tcase.in, err, tcase.outErr) - } - continue - } - if err != nil { - t.Errorf("BuildIntegral(%v) error: %v", tcase.in, err) - continue - } - if !reflect.DeepEqual(v, tcase.outVal) { - t.Errorf("BuildIntegral(%v) = %v, want %v", tcase.in, v, tcase.outVal) - } - } -} - -func TestInerfaceValue(t *testing.T) { - testcases := []struct { - in interface{} - out Value - }{{ - in: nil, - out: NULL, - }, { - in: []byte("a"), - out: TestValue(VarBinary, "a"), - }, { - in: int64(1), - out: TestValue(Int64, "1"), - }, { - in: uint64(1), - out: TestValue(Uint64, "1"), - }, { - in: float64(1.2), - out: TestValue(Float64, "1.2"), - }, { - in: "a", - out: TestValue(VarChar, "a"), - }} - for _, tcase := range testcases { - v, err := InterfaceToValue(tcase.in) - if err != nil { - t.Errorf("BuildValue(%#v) error: %v", tcase.in, err) - continue - } - if !reflect.DeepEqual(v, tcase.out) { - t.Errorf("BuildValue(%#v) = %v, want %v", tcase.in, v, tcase.out) - } - } - - _, err := InterfaceToValue(make(chan bool)) - want := "unexpected" - if err == nil || !strings.Contains(err.Error(), want) { - t.Errorf("BuildValue(chan): %v, want %v", err, want) - } -} - -func TestAccessors(t *testing.T) { - v := TestValue(Int64, "1") - if v.Type() != Int64 { - t.Errorf("v.Type=%v, want Int64", v.Type()) - } - if !bytes.Equal(v.Raw(), []byte("1")) { - t.Errorf("v.Raw=%s, want 1", v.Raw()) - } - if v.Len() != 1 { - t.Errorf("v.Len=%d, want 1", v.Len()) - } - if v.ToString() != "1" { - t.Errorf("v.String=%s, want 1", v.ToString()) - } - if v.IsNull() { - t.Error("v.IsNull: true, want false") - } - if !v.IsIntegral() { - t.Error("v.IsIntegral: false, want true") - } - if !v.IsSigned() { - t.Error("v.IsSigned: false, want true") - } - if v.IsUnsigned() { - t.Error("v.IsUnsigned: true, want false") - } - if v.IsFloat() { - t.Error("v.IsFloat: true, want false") - } - if v.IsQuoted() { - t.Error("v.IsQuoted: true, want false") - } - if v.IsText() { - t.Error("v.IsText: true, want false") - } - if v.IsBinary() { - t.Error("v.IsBinary: true, want false") - } -} - -func TestToBytesAndString(t *testing.T) { - for _, v := range []Value{ - NULL, - TestValue(Int64, "1"), - TestValue(Int64, "12"), - } { - if b := v.ToBytes(); bytes.Compare(b, v.Raw()) != 0 { - t.Errorf("%v.ToBytes: %s, want %s", v, b, v.Raw()) - } - if s := v.ToString(); s != string(v.Raw()) { - t.Errorf("%v.ToString: %s, want %s", v, s, v.Raw()) - } - } - - tv := TestValue(Expression, "aa") - if b := tv.ToBytes(); b != nil { - t.Errorf("%v.ToBytes: %s, want nil", tv, b) - } - if s := tv.ToString(); s != "" { - t.Errorf("%v.ToString: %s, want \"\"", tv, s) - } -} - -func TestEncode(t *testing.T) { - testcases := []struct { - in Value - outSQL string - outASCII string - }{{ - in: NULL, - outSQL: "null", - outASCII: "null", - }, { - in: TestValue(Int64, "1"), - outSQL: "1", - outASCII: "1", - }, { - in: TestValue(VarChar, "foo"), - outSQL: "'foo'", - outASCII: "'Zm9v'", - }, { - in: TestValue(VarChar, "\x00'\"\b\n\r\t\x1A\\"), - outSQL: "'\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\'", - outASCII: "'ACciCAoNCRpc'", - }} - for _, tcase := range testcases { - buf := &bytes.Buffer{} - tcase.in.EncodeSQL(buf) - if tcase.outSQL != buf.String() { - t.Errorf("%v.EncodeSQL = %q, want %q", tcase.in, buf.String(), tcase.outSQL) - } - buf = &bytes.Buffer{} - tcase.in.EncodeASCII(buf) - if tcase.outASCII != buf.String() { - t.Errorf("%v.EncodeASCII = %q, want %q", tcase.in, buf.String(), tcase.outASCII) - } - } -} - -// TestEncodeMap ensures DontEscape is not escaped -func TestEncodeMap(t *testing.T) { - if SQLEncodeMap[DontEscape] != DontEscape { - t.Errorf("SQLEncodeMap[DontEscape] = %v, want %v", SQLEncodeMap[DontEscape], DontEscape) - } - if SQLDecodeMap[DontEscape] != DontEscape { - t.Errorf("SQLDecodeMap[DontEscape] = %v, want %v", SQLEncodeMap[DontEscape], DontEscape) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go deleted file mode 100644 index 3bfc7748..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestEncodable(t *testing.T) { - tcases := []struct { - in Encodable - out string - }{{ - in: InsertValues{{ - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("foo('a')"), - }, { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bar(`b`)"), - }}, - out: "(1, 'foo(\\'a\\')'), (2, 'bar(`b`)')", - }, { - // Single column. - in: &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk")}, - Rows: [][]sqltypes.Value{ - {sqltypes.NewInt64(1)}, - {sqltypes.NewVarBinary("aa")}, - }, - }, - out: "pk in (1, 'aa')", - }, { - // Multiple columns. - in: &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk1"), NewColIdent("pk2")}, - Rows: [][]sqltypes.Value{ - { - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("aa"), - }, - { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bb"), - }, - }, - }, - out: "(pk1 = 1 and pk2 = 'aa') or (pk1 = 2 and pk2 = 'bb')", - }} - for _, tcase := range tcases { - buf := new(bytes.Buffer) - tcase.in.EncodeSQL(buf) - if out := buf.String(); out != tcase.out { - t.Errorf("EncodeSQL(%v): %s, want %s", tcase.in, out, tcase.out) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go deleted file mode 100644 index 01ab03ef..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreedto in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package sqlparser - -// Additional tests to address the GitHub issues for this fork. - -import ( - "io" - "strings" - "testing" -) - -func TestParsing(t *testing.T) { - tests := []struct { - id int // Github issue ID - sql string - skip string - }{ - {id: 9, sql: "select 1 as 测试 from dual", skip: "Broken due to ReadByte()"}, - {id: 12, sql: "SELECT * FROM AccessToken LIMIT 10 OFFSET 13"}, - {id: 14, sql: "SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH)"}, - {id: 15, sql: "select STRAIGHT_JOIN t1.* FROM t1 INNER JOIN t2 ON t1.CommonID = t2.CommonID WHERE t1.FilterID = 1"}, - {id: 16, sql: "SELECT a FROM t WHERE FUNC(a) = 1"}, // Doesn't seem broken, need better example - {id: 21, sql: `CREATE TABLE t (UpdateDatetime TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP)`}, - {id: 21, sql: `CREATE TABLE t (UpdateDatetime TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间')`}, - {id: 24, sql: `select * from t1 join t2 using(id)`}, - } - - for _, test := range tests { - if test.skip != "" { - continue - } - - if _, err := Parse(test.sql); err != nil { - t.Errorf("https://github.com/xwb1989/sqlparser/issues/%d:\nParse(%q) err = %s, want nil", test.id, test.sql, err) - } - } -} - -// ExampleParse is the first example from the README.md. -func ExampleParse() { - sql := "SELECT * FROM table WHERE a = 'abc'" - stmt, err := Parse(sql) - if err != nil { - // Do something with the err - } - - // Otherwise do something with stmt - switch stmt := stmt.(type) { - case *Select: - _ = stmt - case *Insert: - } -} - -// ExampleParseNext is the second example from the README.md. -func ExampleParseNext() { - r := strings.NewReader("INSERT INTO table1 VALUES (1, 'a'); INSERT INTO table2 VALUES (3, 4);") - - tokens := NewTokenizer(r) - for { - stmt, err := ParseNext(tokens) - if err == io.EOF { - break - } - // Do something with stmt or err. - _ = stmt - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go deleted file mode 100644 index 20f7e39d..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go +++ /dev/null @@ -1,206 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "reflect" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestNormalize(t *testing.T) { - prefix := "bv" - testcases := []struct { - in string - outstmt string - outbv map[string]*querypb.BindVariable - }{{ - // str val - in: "select * from t where v1 = 'aa'", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte("aa")), - }, - }, { - // int val - in: "select * from t where v1 = 1", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // float val - in: "select * from t where v1 = 1.2", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Float64BindVariable(1.2), - }, - }, { - // multiple vals - in: "select * from t where v1 = 1.2 and v2 = 2", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Float64BindVariable(1.2), - "bv2": sqltypes.Int64BindVariable(2), - }, - }, { - // bv collision - in: "select * from t where v1 = :bv1 and v2 = 1", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv2": sqltypes.Int64BindVariable(1), - }, - }, { - // val reuse - in: "select * from t where v1 = 1 and v2 = 1", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // ints and strings are different - in: "select * from t where v1 = 1 and v2 = '1'", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - "bv2": sqltypes.BytesBindVariable([]byte("1")), - }, - }, { - // val should not be reused for non-select statements - in: "insert into a values(1, 1)", - outstmt: "insert into a values (:bv1, :bv2)", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - "bv2": sqltypes.Int64BindVariable(1), - }, - }, { - // val should be reused only in subqueries of DMLs - in: "update a set v1=(select 5 from t), v2=5, v3=(select 5 from t), v4=5", - outstmt: "update a set v1 = (select :bv1 from t), v2 = :bv2, v3 = (select :bv1 from t), v4 = :bv3", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(5), - "bv2": sqltypes.Int64BindVariable(5), - "bv3": sqltypes.Int64BindVariable(5), - }, - }, { - // list vars should work for DMLs also - in: "update a set v1=5 where v2 in (1, 4, 5)", - outstmt: "update a set v1 = :bv1 where v2 in ::bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(5), - "bv2": sqltypes.TestBindVariable([]interface{}{1, 4, 5}), - }, - }, { - // Hex value does not convert - in: "select * from t where v1 = 0x1234", - outstmt: "select * from t where v1 = 0x1234", - outbv: map[string]*querypb.BindVariable{}, - }, { - // Hex value does not convert for DMLs - in: "update a set v1 = 0x1234", - outstmt: "update a set v1 = 0x1234", - outbv: map[string]*querypb.BindVariable{}, - }, { - // Values up to len 256 will reuse. - in: fmt.Sprintf("select * from t where v1 = '%256s' and v2 = '%256s'", "a", "a"), - outstmt: "select * from t where v1 = :bv1 and v2 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%256s", "a"))), - }, - }, { - // Values greater than len 256 will not reuse. - in: fmt.Sprintf("select * from t where v1 = '%257s' and v2 = '%257s'", "b", "b"), - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%257s", "b"))), - "bv2": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%257s", "b"))), - }, - }, { - // bad int - in: "select * from t where v1 = 12345678901234567890", - outstmt: "select * from t where v1 = 12345678901234567890", - outbv: map[string]*querypb.BindVariable{}, - }, { - // comparison with no vals - in: "select * from t where v1 = v2", - outstmt: "select * from t where v1 = v2", - outbv: map[string]*querypb.BindVariable{}, - }, { - // IN clause with existing bv - in: "select * from t where v1 in ::list", - outstmt: "select * from t where v1 in ::list", - outbv: map[string]*querypb.BindVariable{}, - }, { - // IN clause with non-val values - in: "select * from t where v1 in (1, a)", - outstmt: "select * from t where v1 in (:bv1, a)", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // IN clause with vals - in: "select * from t where v1 in (1, '2')", - outstmt: "select * from t where v1 in ::bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.TestBindVariable([]interface{}{1, []byte("2")}), - }, - }, { - // NOT IN clause - in: "select * from t where v1 not in (1, '2')", - outstmt: "select * from t where v1 not in ::bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.TestBindVariable([]interface{}{1, []byte("2")}), - }, - }} - for _, tc := range testcases { - stmt, err := Parse(tc.in) - if err != nil { - t.Error(err) - continue - } - bv := make(map[string]*querypb.BindVariable) - Normalize(stmt, bv, prefix) - outstmt := String(stmt) - if outstmt != tc.outstmt { - t.Errorf("Query:\n%s:\n%s, want\n%s", tc.in, outstmt, tc.outstmt) - } - if !reflect.DeepEqual(tc.outbv, bv) { - t.Errorf("Query:\n%s:\n%v, want\n%v", tc.in, bv, tc.outbv) - } - } -} - -func TestGetBindVars(t *testing.T) { - stmt, err := Parse("select * from t where :v1 = :v2 and :v2 = :v3 and :v4 in ::v5") - if err != nil { - t.Fatal(err) - } - got := GetBindvars(stmt) - want := map[string]struct{}{ - "v1": {}, - "v2": {}, - "v3": {}, - "v4": {}, - "v5": {}, - } - if !reflect.DeepEqual(got, want) { - t.Errorf("GetBindVars: %v, want: %v", got, want) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go deleted file mode 100644 index bb92f9f2..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go +++ /dev/null @@ -1,163 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "io" - "strings" - "testing" -) - -// TestParseNextValid concatenates all the valid SQL test cases and check it can read -// them as one long string. -func TestParseNextValid(t *testing.T) { - var sql bytes.Buffer - for _, tcase := range validSQL { - sql.WriteString(strings.TrimSuffix(tcase.input, ";")) - sql.WriteRune(';') - } - - tokens := NewTokenizer(&sql) - for i, tcase := range validSQL { - input := tcase.input + ";" - want := tcase.output - if want == "" { - want = tcase.input - } - - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[%d] ParseNext(%q) err: %q, want nil", i, input, err) - continue - } - - if got := String(tree); got != want { - t.Fatalf("[%d] ParseNext(%q) = %q, want %q", i, input, got, want) - } - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(tokens) = (%q, %v) want io.EOF", String(tree), err) - } -} - -// TestParseNextErrors tests all the error cases, and ensures a valid -// SQL statement can be passed afterwards. -func TestParseNextErrors(t *testing.T) { - for _, tcase := range invalidSQL { - if tcase.excludeMulti { - // Skip tests which leave unclosed strings, or comments. - continue - } - - sql := tcase.input + "; select 1 from t" - tokens := NewStringTokenizer(sql) - - // The first statement should be an error - _, err := ParseNext(tokens) - if err == nil || err.Error() != tcase.output { - t.Fatalf("[0] ParseNext(%q) err: %q, want %q", sql, err, tcase.output) - continue - } - - // The second should be valid - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[1] ParseNext(%q) err: %q, want nil", sql, err) - continue - } - - want := "select 1 from t" - if got := String(tree); got != want { - t.Fatalf("[1] ParseNext(%q) = %q, want %q", sql, got, want) - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(tokens) = (%q, %v) want io.EOF", String(tree), err) - } - } -} - -// TestParseNextEdgeCases tests various ParseNext edge cases. -func TestParseNextEdgeCases(t *testing.T) { - tests := []struct { - name string - input string - want []string - }{{ - name: "Trailing ;", - input: "select 1 from a; update a set b = 2;", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "No trailing ;", - input: "select 1 from a; update a set b = 2", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Trailing whitespace", - input: "select 1 from a; update a set b = 2 ", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Trailing whitespace and ;", - input: "select 1 from a; update a set b = 2 ; ", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Handle ForceEOF statements", - input: "set character set utf8; select 1 from a", - want: []string{"set charset 'utf8'", "select 1 from a"}, - }, { - name: "Semicolin inside a string", - input: "set character set ';'; select 1 from a", - want: []string{"set charset ';'", "select 1 from a"}, - }, { - name: "Partial DDL", - input: "create table a; select 1 from a", - want: []string{"create table a", "select 1 from a"}, - }, { - name: "Partial DDL", - input: "create table a ignore me this is garbage; select 1 from a", - want: []string{"create table a", "select 1 from a"}, - }} - - for _, test := range tests { - tokens := NewStringTokenizer(test.input) - - for i, want := range test.want { - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[%d] ParseNext(%q) err = %q, want nil", i, test.input, err) - continue - } - - if got := String(tree); got != want { - t.Fatalf("[%d] ParseNext(%q) = %q, want %q", i, test.input, got, want) - } - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(%q) = (%q, %v) want io.EOF", test.input, String(tree), err) - } - - // And again, once more should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(%q) = (%q, %v) want io.EOF", test.input, String(tree), err) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go deleted file mode 100644 index ac659621..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go +++ /dev/null @@ -1,2126 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "fmt" - "strings" - "testing" -) - -var ( - validSQL = []struct { - input string - output string - }{{ - input: "select 1", - output: "select 1 from dual", - }, { - input: "select 1 from t", - }, { - input: "select .1 from t", - }, { - input: "select 1.2e1 from t", - }, { - input: "select 1.2e+1 from t", - }, { - input: "select 1.2e-1 from t", - }, { - input: "select 08.3 from t", - }, { - input: "select -1 from t where b = -2", - }, { - input: "select - -1 from t", - output: "select 1 from t", - }, { - input: "select 1 from t // aa\n", - output: "select 1 from t", - }, { - input: "select 1 from t -- aa\n", - output: "select 1 from t", - }, { - input: "select 1 from t # aa\n", - output: "select 1 from t", - }, { - input: "select 1 --aa\nfrom t", - output: "select 1 from t", - }, { - input: "select 1 #aa\nfrom t", - output: "select 1 from t", - }, { - input: "select /* simplest */ 1 from t", - }, { - input: "select /* double star **/ 1 from t", - }, { - input: "select /* double */ /* comment */ 1 from t", - }, { - input: "select /* back-quote keyword */ `By` from t", - }, { - input: "select /* back-quote num */ `2a` from t", - }, { - input: "select /* back-quote . */ `a.b` from t", - }, { - input: "select /* back-quote back-quote */ `a``b` from t", - }, { - input: "select /* back-quote unnecessary */ 1 from `t`", - output: "select /* back-quote unnecessary */ 1 from t", - }, { - input: "select /* back-quote idnum */ 1 from `a1`", - output: "select /* back-quote idnum */ 1 from a1", - }, { - input: "select /* @ */ @@a from b", - }, { - input: "select /* \\0 */ '\\0' from a", - }, { - input: "select 1 /* drop this comment */ from t", - output: "select 1 from t", - }, { - input: "select /* union */ 1 from t union select 1 from t", - }, { - input: "select /* double union */ 1 from t union select 1 from t union select 1 from t", - }, { - input: "select /* union all */ 1 from t union all select 1 from t", - }, { - input: "select /* union distinct */ 1 from t union distinct select 1 from t", - }, { - input: "(select /* union parenthesized select */ 1 from t order by a) union select 1 from t", - output: "(select /* union parenthesized select */ 1 from t order by a asc) union select 1 from t", - }, { - input: "select /* union parenthesized select 2 */ 1 from t union (select 1 from t)", - }, { - input: "select /* union order by */ 1 from t union select 1 from t order by a", - output: "select /* union order by */ 1 from t union select 1 from t order by a asc", - }, { - input: "select /* union order by limit lock */ 1 from t union select 1 from t order by a limit 1 for update", - output: "select /* union order by limit lock */ 1 from t union select 1 from t order by a asc limit 1 for update", - }, { - input: "select /* union with limit on lhs */ 1 from t limit 1 union select 1 from t", - }, { - input: "(select id, a from t order by id limit 1) union (select id, b as a from s order by id limit 1) order by a limit 1", - output: "(select id, a from t order by id asc limit 1) union (select id, b as a from s order by id asc limit 1) order by a asc limit 1", - }, { - input: "select a from (select 1 as a from tbl1 union select 2 from tbl2) as t", - }, { - input: "select * from t1 join (select * from t2 union select * from t3) as t", - }, { - // Ensure this doesn't generate: ""select * from t1 join t2 on a = b join t3 on a = b". - input: "select * from t1 join t2 on a = b join t3", - }, { - input: "select * from t1 where col in (select 1 from dual union select 2 from dual)", - }, { - input: "select * from t1 where exists (select a from t2 union select b from t3)", - }, { - input: "select /* distinct */ distinct 1 from t", - }, { - input: "select /* straight_join */ straight_join 1 from t", - }, { - input: "select /* for update */ 1 from t for update", - }, { - input: "select /* lock in share mode */ 1 from t lock in share mode", - }, { - input: "select /* select list */ 1, 2 from t", - }, { - input: "select /* * */ * from t", - }, { - input: "select /* a.* */ a.* from t", - }, { - input: "select /* a.b.* */ a.b.* from t", - }, { - input: "select /* column alias */ a b from t", - output: "select /* column alias */ a as b from t", - }, { - input: "select /* column alias with as */ a as b from t", - }, { - input: "select /* keyword column alias */ a as `By` from t", - }, { - input: "select /* column alias as string */ a as \"b\" from t", - output: "select /* column alias as string */ a as b from t", - }, { - input: "select /* column alias as string without as */ a \"b\" from t", - output: "select /* column alias as string without as */ a as b from t", - }, { - input: "select /* a.* */ a.* from t", - }, { - input: "select next value for t", - output: "select next 1 values from t", - }, { - input: "select next value from t", - output: "select next 1 values from t", - }, { - input: "select next 10 values from t", - }, { - input: "select next :a values from t", - }, { - input: "select /* `By`.* */ `By`.* from t", - }, { - input: "select /* select with bool expr */ a = b from t", - }, { - input: "select /* case_when */ case when a = b then c end from t", - }, { - input: "select /* case_when_else */ case when a = b then c else d end from t", - }, { - input: "select /* case_when_when_else */ case when a = b then c when b = d then d else d end from t", - }, { - input: "select /* case */ case aa when a = b then c end from t", - }, { - input: "select /* parenthesis */ 1 from (t)", - }, { - input: "select /* parenthesis multi-table */ 1 from (t1, t2)", - }, { - input: "select /* table list */ 1 from t1, t2", - }, { - input: "select /* parenthessis in table list 1 */ 1 from (t1), t2", - }, { - input: "select /* parenthessis in table list 2 */ 1 from t1, (t2)", - }, { - input: "select /* use */ 1 from t1 use index (a) where b = 1", - }, { - input: "select /* keyword index */ 1 from t1 use index (`By`) where b = 1", - }, { - input: "select /* ignore */ 1 from t1 as t2 ignore index (a), t3 use index (b) where b = 1", - }, { - input: "select /* use */ 1 from t1 as t2 use index (a), t3 use index (b) where b = 1", - }, { - input: "select /* force */ 1 from t1 as t2 force index (a), t3 force index (b) where b = 1", - }, { - input: "select /* table alias */ 1 from t t1", - output: "select /* table alias */ 1 from t as t1", - }, { - input: "select /* table alias with as */ 1 from t as t1", - }, { - input: "select /* string table alias */ 1 from t as 't1'", - output: "select /* string table alias */ 1 from t as t1", - }, { - input: "select /* string table alias without as */ 1 from t 't1'", - output: "select /* string table alias without as */ 1 from t as t1", - }, { - input: "select /* keyword table alias */ 1 from t as `By`", - }, { - input: "select /* join */ 1 from t1 join t2", - }, { - input: "select /* join on */ 1 from t1 join t2 on a = b", - }, { - input: "select /* join on */ 1 from t1 join t2 using (a)", - }, { - input: "select /* inner join */ 1 from t1 inner join t2", - output: "select /* inner join */ 1 from t1 join t2", - }, { - input: "select /* cross join */ 1 from t1 cross join t2", - output: "select /* cross join */ 1 from t1 join t2", - }, { - input: "select /* straight_join */ 1 from t1 straight_join t2", - }, { - input: "select /* straight_join on */ 1 from t1 straight_join t2 on a = b", - }, { - input: "select /* left join */ 1 from t1 left join t2 on a = b", - }, { - input: "select /* left join */ 1 from t1 left join t2 using (a)", - }, { - input: "select /* left outer join */ 1 from t1 left outer join t2 on a = b", - output: "select /* left outer join */ 1 from t1 left join t2 on a = b", - }, { - input: "select /* left outer join */ 1 from t1 left outer join t2 using (a)", - output: "select /* left outer join */ 1 from t1 left join t2 using (a)", - }, { - input: "select /* right join */ 1 from t1 right join t2 on a = b", - }, { - input: "select /* right join */ 1 from t1 right join t2 using (a)", - }, { - input: "select /* right outer join */ 1 from t1 right outer join t2 on a = b", - output: "select /* right outer join */ 1 from t1 right join t2 on a = b", - }, { - input: "select /* right outer join */ 1 from t1 right outer join t2 using (a)", - output: "select /* right outer join */ 1 from t1 right join t2 using (a)", - }, { - input: "select /* natural join */ 1 from t1 natural join t2", - }, { - input: "select /* natural left join */ 1 from t1 natural left join t2", - }, { - input: "select /* natural left outer join */ 1 from t1 natural left join t2", - output: "select /* natural left outer join */ 1 from t1 natural left join t2", - }, { - input: "select /* natural right join */ 1 from t1 natural right join t2", - }, { - input: "select /* natural right outer join */ 1 from t1 natural right join t2", - output: "select /* natural right outer join */ 1 from t1 natural right join t2", - }, { - input: "select /* join on */ 1 from t1 join t2 on a = b", - }, { - input: "select /* join using */ 1 from t1 join t2 using (a)", - }, { - input: "select /* join using (a, b, c) */ 1 from t1 join t2 using (a, b, c)", - }, { - input: "select /* s.t */ 1 from s.t", - }, { - input: "select /* keyword schema & table name */ 1 from `By`.`bY`", - }, { - input: "select /* select in from */ 1 from (select 1 from t) as a", - }, { - input: "select /* select in from with no as */ 1 from (select 1 from t) a", - output: "select /* select in from with no as */ 1 from (select 1 from t) as a", - }, { - input: "select /* where */ 1 from t where a = b", - }, { - input: "select /* and */ 1 from t where a = b and a = c", - }, { - input: "select /* && */ 1 from t where a = b && a = c", - output: "select /* && */ 1 from t where a = b and a = c", - }, { - input: "select /* or */ 1 from t where a = b or a = c", - }, { - input: "select /* || */ 1 from t where a = b || a = c", - output: "select /* || */ 1 from t where a = b or a = c", - }, { - input: "select /* not */ 1 from t where not a = b", - }, { - input: "select /* ! */ 1 from t where a = !1", - }, { - input: "select /* bool is */ 1 from t where a = b is null", - }, { - input: "select /* bool is not */ 1 from t where a = b is not false", - }, { - input: "select /* true */ 1 from t where true", - }, { - input: "select /* false */ 1 from t where false", - }, { - input: "select /* false on left */ 1 from t where false = 0", - }, { - input: "select /* exists */ 1 from t where exists (select 1 from t)", - }, { - input: "select /* (boolean) */ 1 from t where not (a = b)", - }, { - input: "select /* in value list */ 1 from t where a in (b, c)", - }, { - input: "select /* in select */ 1 from t where a in (select 1 from t)", - }, { - input: "select /* not in */ 1 from t where a not in (b, c)", - }, { - input: "select /* like */ 1 from t where a like b", - }, { - input: "select /* like escape */ 1 from t where a like b escape '!'", - }, { - input: "select /* not like */ 1 from t where a not like b", - }, { - input: "select /* not like escape */ 1 from t where a not like b escape '$'", - }, { - input: "select /* regexp */ 1 from t where a regexp b", - }, { - input: "select /* not regexp */ 1 from t where a not regexp b", - }, { - input: "select /* rlike */ 1 from t where a rlike b", - output: "select /* rlike */ 1 from t where a regexp b", - }, { - input: "select /* not rlike */ 1 from t where a not rlike b", - output: "select /* not rlike */ 1 from t where a not regexp b", - }, { - input: "select /* between */ 1 from t where a between b and c", - }, { - input: "select /* not between */ 1 from t where a not between b and c", - }, { - input: "select /* is null */ 1 from t where a is null", - }, { - input: "select /* is not null */ 1 from t where a is not null", - }, { - input: "select /* is true */ 1 from t where a is true", - }, { - input: "select /* is not true */ 1 from t where a is not true", - }, { - input: "select /* is false */ 1 from t where a is false", - }, { - input: "select /* is not false */ 1 from t where a is not false", - }, { - input: "select /* < */ 1 from t where a < b", - }, { - input: "select /* <= */ 1 from t where a <= b", - }, { - input: "select /* >= */ 1 from t where a >= b", - }, { - input: "select /* > */ 1 from t where a > b", - }, { - input: "select /* != */ 1 from t where a != b", - }, { - input: "select /* <> */ 1 from t where a <> b", - output: "select /* <> */ 1 from t where a != b", - }, { - input: "select /* <=> */ 1 from t where a <=> b", - }, { - input: "select /* != */ 1 from t where a != b", - }, { - input: "select /* single value expre list */ 1 from t where a in (b)", - }, { - input: "select /* select as a value expression */ 1 from t where a = (select a from t)", - }, { - input: "select /* parenthesised value */ 1 from t where a = (b)", - }, { - input: "select /* over-parenthesize */ ((1)) from t where ((a)) in (((1))) and ((a, b)) in ((((1, 1))), ((2, 2)))", - }, { - input: "select /* dot-parenthesize */ (a.b) from t where (b.c) = 2", - }, { - input: "select /* & */ 1 from t where a = b & c", - }, { - input: "select /* & */ 1 from t where a = b & c", - }, { - input: "select /* | */ 1 from t where a = b | c", - }, { - input: "select /* ^ */ 1 from t where a = b ^ c", - }, { - input: "select /* + */ 1 from t where a = b + c", - }, { - input: "select /* - */ 1 from t where a = b - c", - }, { - input: "select /* * */ 1 from t where a = b * c", - }, { - input: "select /* / */ 1 from t where a = b / c", - }, { - input: "select /* % */ 1 from t where a = b % c", - }, { - input: "select /* div */ 1 from t where a = b div c", - }, { - input: "select /* MOD */ 1 from t where a = b MOD c", - output: "select /* MOD */ 1 from t where a = b % c", - }, { - input: "select /* << */ 1 from t where a = b << c", - }, { - input: "select /* >> */ 1 from t where a = b >> c", - }, { - input: "select /* % no space */ 1 from t where a = b%c", - output: "select /* % no space */ 1 from t where a = b % c", - }, { - input: "select /* u+ */ 1 from t where a = +b", - }, { - input: "select /* u- */ 1 from t where a = -b", - }, { - input: "select /* u~ */ 1 from t where a = ~b", - }, { - input: "select /* -> */ a.b -> 'ab' from t", - }, { - input: "select /* -> */ a.b ->> 'ab' from t", - }, { - input: "select /* empty function */ 1 from t where a = b()", - }, { - input: "select /* function with 1 param */ 1 from t where a = b(c)", - }, { - input: "select /* function with many params */ 1 from t where a = b(c, d)", - }, { - input: "select /* function with distinct */ count(distinct a) from t", - }, { - input: "select /* if as func */ 1 from t where a = if(b)", - }, { - input: "select /* current_timestamp as func */ current_timestamp() from t", - }, { - input: "select /* mod as func */ a from tab where mod(b, 2) = 0", - }, { - input: "select /* database as func no param */ database() from t", - }, { - input: "select /* database as func 1 param */ database(1) from t", - }, { - input: "select /* a */ a from t", - }, { - input: "select /* a.b */ a.b from t", - }, { - input: "select /* a.b.c */ a.b.c from t", - }, { - input: "select /* keyword a.b */ `By`.`bY` from t", - }, { - input: "select /* string */ 'a' from t", - }, { - input: "select /* double quoted string */ \"a\" from t", - output: "select /* double quoted string */ 'a' from t", - }, { - input: "select /* quote quote in string */ 'a''a' from t", - output: "select /* quote quote in string */ 'a\\'a' from t", - }, { - input: "select /* double quote quote in string */ \"a\"\"a\" from t", - output: "select /* double quote quote in string */ 'a\\\"a' from t", - }, { - input: "select /* quote in double quoted string */ \"a'a\" from t", - output: "select /* quote in double quoted string */ 'a\\'a' from t", - }, { - input: "select /* backslash quote in string */ 'a\\'a' from t", - }, { - input: "select /* literal backslash in string */ 'a\\\\na' from t", - }, { - input: "select /* all escapes */ '\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\' from t", - }, { - input: "select /* non-escape */ '\\x' from t", - output: "select /* non-escape */ 'x' from t", - }, { - input: "select /* unescaped backslash */ '\\n' from t", - }, { - input: "select /* value argument */ :a from t", - }, { - input: "select /* value argument with digit */ :a1 from t", - }, { - input: "select /* value argument with dot */ :a.b from t", - }, { - input: "select /* positional argument */ ? from t", - output: "select /* positional argument */ :v1 from t", - }, { - input: "select /* multiple positional arguments */ ?, ? from t", - output: "select /* multiple positional arguments */ :v1, :v2 from t", - }, { - input: "select /* list arg */ * from t where a in ::list", - }, { - input: "select /* list arg not in */ * from t where a not in ::list", - }, { - input: "select /* null */ null from t", - }, { - input: "select /* octal */ 010 from t", - }, { - input: "select /* hex */ x'f0A1' from t", - output: "select /* hex */ X'f0A1' from t", - }, { - input: "select /* hex caps */ X'F0a1' from t", - }, { - input: "select /* bit literal */ b'0101' from t", - output: "select /* bit literal */ B'0101' from t", - }, { - input: "select /* bit literal caps */ B'010011011010' from t", - }, { - input: "select /* 0x */ 0xf0 from t", - }, { - input: "select /* float */ 0.1 from t", - }, { - input: "select /* group by */ 1 from t group by a", - }, { - input: "select /* having */ 1 from t having a = b", - }, { - input: "select /* simple order by */ 1 from t order by a", - output: "select /* simple order by */ 1 from t order by a asc", - }, { - input: "select /* order by asc */ 1 from t order by a asc", - }, { - input: "select /* order by desc */ 1 from t order by a desc", - }, { - input: "select /* order by null */ 1 from t order by null", - }, { - input: "select /* limit a */ 1 from t limit a", - }, { - input: "select /* limit a,b */ 1 from t limit a, b", - }, { - input: "select /* binary unary */ a- -b from t", - output: "select /* binary unary */ a - -b from t", - }, { - input: "select /* - - */ - -b from t", - }, { - input: "select /* binary binary */ binary binary b from t", - }, { - input: "select /* binary ~ */ binary ~b from t", - }, { - input: "select /* ~ binary */ ~ binary b from t", - }, { - input: "select /* interval */ adddate('2008-01-02', interval 31 day) from t", - }, { - input: "select /* interval keyword */ adddate('2008-01-02', interval 1 year) from t", - }, { - input: "select /* dual */ 1 from dual", - }, { - input: "select /* Dual */ 1 from Dual", - output: "select /* Dual */ 1 from dual", - }, { - input: "select /* DUAL */ 1 from Dual", - output: "select /* DUAL */ 1 from dual", - }, { - input: "select /* column as bool in where */ a from t where b", - }, { - input: "select /* OR of columns in where */ * from t where a or b", - }, { - input: "select /* OR of mixed columns in where */ * from t where a = 5 or b and c is not null", - }, { - input: "select /* OR in select columns */ (a or b) from t where c = 5", - }, { - input: "select /* bool as select value */ a, true from t", - }, { - input: "select /* bool column in ON clause */ * from t join s on t.id = s.id and s.foo where t.bar", - }, { - input: "select /* bool in order by */ * from t order by a is null or b asc", - }, { - input: "select /* string in case statement */ if(max(case a when 'foo' then 1 else 0 end) = 1, 'foo', 'bar') as foobar from t", - }, { - input: "/*!show databases*/", - output: "show databases", - }, { - input: "select /*!40101 * from*/ t", - output: "select * from t", - }, { - input: "select /*! * from*/ t", - output: "select * from t", - }, { - input: "select /*!* from*/ t", - output: "select * from t", - }, { - input: "select /*!401011 from*/ t", - output: "select 1 from t", - }, { - input: "select /* dual */ 1 from dual", - }, { - input: "insert /* simple */ into a values (1)", - }, { - input: "insert /* a.b */ into a.b values (1)", - }, { - input: "insert /* multi-value */ into a values (1, 2)", - }, { - input: "insert /* multi-value list */ into a values (1, 2), (3, 4)", - }, { - input: "insert /* no values */ into a values ()", - }, { - input: "insert /* set */ into a set a = 1, b = 2", - output: "insert /* set */ into a(a, b) values (1, 2)", - }, { - input: "insert /* set default */ into a set a = default, b = 2", - output: "insert /* set default */ into a(a, b) values (default, 2)", - }, { - input: "insert /* value expression list */ into a values (a + 1, 2 * 3)", - }, { - input: "insert /* default */ into a values (default, 2 * 3)", - }, { - input: "insert /* column list */ into a(a, b) values (1, 2)", - }, { - input: "insert into a(a, b) values (1, ifnull(null, default(b)))", - }, { - input: "insert /* qualified column list */ into a(a, b) values (1, 2)", - }, { - input: "insert /* qualified columns */ into t (t.a, t.b) values (1, 2)", - output: "insert /* qualified columns */ into t(a, b) values (1, 2)", - }, { - input: "insert /* select */ into a select b, c from d", - }, { - input: "insert /* no cols & paren select */ into a(select * from t)", - output: "insert /* no cols & paren select */ into a select * from t", - }, { - input: "insert /* cols & paren select */ into a(a,b,c) (select * from t)", - output: "insert /* cols & paren select */ into a(a, b, c) select * from t", - }, { - input: "insert /* cols & union with paren select */ into a(b, c) (select d, e from f) union (select g from h)", - }, { - input: "insert /* on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = d", - }, { - input: "insert /* bool in insert value */ into a values (1, true, false)", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2) on duplicate key update b = false, c = d", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(b), c = d", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(a.b), c = d", - }, { - input: "insert /* bool expression on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = a > d", - }, { - input: "update /* simple */ a set b = 3", - }, { - input: "update /* a.b */ a.b set b = 3", - }, { - input: "update /* list */ a set b = 3, c = 4", - }, { - input: "update /* expression */ a set b = 3 + 4", - }, { - input: "update /* where */ a set b = 3 where a = b", - }, { - input: "update /* order */ a set b = 3 order by c desc", - }, { - input: "update /* limit */ a set b = 3 limit c", - }, { - input: "update /* bool in update */ a set b = true", - }, { - input: "update /* bool expr in update */ a set b = 5 > 2", - }, { - input: "update /* bool in update where */ a set b = 5 where c", - }, { - input: "update /* table qualifier */ a set a.b = 3", - }, { - input: "update /* table qualifier */ a set t.a.b = 3", - }, { - input: "update /* table alias */ tt aa set aa.cc = 3", - output: "update /* table alias */ tt as aa set aa.cc = 3", - }, { - input: "update (select id from foo) subqalias set id = 4", - output: "update (select id from foo) as subqalias set id = 4", - }, { - input: "update foo f, bar b set f.id = b.id where b.name = 'test'", - output: "update foo as f, bar as b set f.id = b.id where b.name = 'test'", - }, { - input: "update foo f join bar b on f.name = b.name set f.id = b.id where b.name = 'test'", - output: "update foo as f join bar as b on f.name = b.name set f.id = b.id where b.name = 'test'", - }, { - input: "delete /* simple */ from a", - }, { - input: "delete /* a.b */ from a.b", - }, { - input: "delete /* where */ from a where a = b", - }, { - input: "delete /* order */ from a order by b desc", - }, { - input: "delete /* limit */ from a limit b", - }, { - input: "delete a from a join b on a.id = b.id where b.name = 'test'", - }, { - input: "delete a, b from a, b where a.id = b.id and b.name = 'test'", - }, { - input: "delete from a1, a2 using t1 as a1 inner join t2 as a2 where a1.id=a2.id", - output: "delete a1, a2 from t1 as a1 join t2 as a2 where a1.id = a2.id", - }, { - input: "set /* simple */ a = 3", - }, { - input: "set #simple\n b = 4", - }, { - input: "set character_set_results = utf8", - }, { - input: "set @@session.autocommit = true", - }, { - input: "set @@session.`autocommit` = true", - }, { - input: "set @@session.'autocommit' = true", - }, { - input: "set @@session.\"autocommit\" = true", - }, { - input: "set names utf8 collate foo", - output: "set names 'utf8'", - }, { - input: "set character set utf8", - output: "set charset 'utf8'", - }, { - input: "set character set 'utf8'", - output: "set charset 'utf8'", - }, { - input: "set character set \"utf8\"", - output: "set charset 'utf8'", - }, { - input: "set charset default", - output: "set charset default", - }, { - input: "set session wait_timeout = 3600", - output: "set session wait_timeout = 3600", - }, { - input: "set /* list */ a = 3, b = 4", - }, { - input: "set /* mixed list */ a = 3, names 'utf8', charset 'ascii', b = 4", - }, { - input: "set session transaction isolation level repeatable read", - output: "set session tx_isolation = 'repeatable read'", - }, { - input: "set global transaction isolation level repeatable read", - output: "set global tx_isolation = 'repeatable read'", - }, { - input: "set transaction isolation level repeatable read", - output: "set tx_isolation = 'repeatable read'", - }, { - input: "set transaction isolation level read committed", - output: "set tx_isolation = 'read committed'", - }, { - input: "set transaction isolation level read uncommitted", - output: "set tx_isolation = 'read uncommitted'", - }, { - input: "set transaction isolation level serializable", - output: "set tx_isolation = 'serializable'", - }, { - input: "set transaction read write", - output: "set tx_read_only = 0", - }, { - input: "set transaction read only", - output: "set tx_read_only = 1", - }, { - input: "set tx_read_only = 1", - }, { - input: "set tx_read_only = 0", - }, { - input: "set tx_isolation = 'repeatable read'", - }, { - input: "set tx_isolation = 'read committed'", - }, { - input: "set tx_isolation = 'read uncommitted'", - }, { - input: "set tx_isolation = 'serializable'", - }, { - input: "set sql_safe_updates = 0", - }, { - input: "set sql_safe_updates = 1", - }, { - input: "alter ignore table a add foo", - output: "alter table a", - }, { - input: "alter table a add foo", - output: "alter table a", - }, { - input: "alter table a add spatial key foo (column1)", - output: "alter table a", - }, { - input: "alter table a add unique key foo (column1)", - output: "alter table a", - }, { - input: "alter table `By` add foo", - output: "alter table `By`", - }, { - input: "alter table a alter foo", - output: "alter table a", - }, { - input: "alter table a change foo", - output: "alter table a", - }, { - input: "alter table a modify foo", - output: "alter table a", - }, { - input: "alter table a drop foo", - output: "alter table a", - }, { - input: "alter table a disable foo", - output: "alter table a", - }, { - input: "alter table a enable foo", - output: "alter table a", - }, { - input: "alter table a order foo", - output: "alter table a", - }, { - input: "alter table a default foo", - output: "alter table a", - }, { - input: "alter table a discard foo", - output: "alter table a", - }, { - input: "alter table a import foo", - output: "alter table a", - }, { - input: "alter table a rename b", - output: "rename table a to b", - }, { - input: "alter table `By` rename `bY`", - output: "rename table `By` to `bY`", - }, { - input: "alter table a rename to b", - output: "rename table a to b", - }, { - input: "alter table a rename as b", - output: "rename table a to b", - }, { - input: "alter table a rename index foo to bar", - output: "alter table a", - }, { - input: "alter table a rename key foo to bar", - output: "alter table a", - }, { - input: "alter table e auto_increment = 20", - output: "alter table e", - }, { - input: "alter table e character set = 'ascii'", - output: "alter table e", - }, { - input: "alter table e default character set = 'ascii'", - output: "alter table e", - }, { - input: "alter table e comment = 'hello'", - output: "alter table e", - }, { - input: "alter table a reorganize partition b into (partition c values less than (?), partition d values less than (maxvalue))", - output: "alter table a reorganize partition b into (partition c values less than (:v1), partition d values less than (maxvalue))", - }, { - input: "alter table a partition by range (id) (partition p0 values less than (10), partition p1 values less than (maxvalue))", - output: "alter table a", - }, { - input: "alter table a add column id int", - output: "alter table a", - }, { - input: "alter table a add index idx (id)", - output: "alter table a", - }, { - input: "alter table a add fulltext index idx (id)", - output: "alter table a", - }, { - input: "alter table a add spatial index idx (id)", - output: "alter table a", - }, { - input: "alter table a add foreign key", - output: "alter table a", - }, { - input: "alter table a add primary key", - output: "alter table a", - }, { - input: "alter table a add constraint", - output: "alter table a", - }, { - input: "alter table a add id", - output: "alter table a", - }, { - input: "alter table a drop column id int", - output: "alter table a", - }, { - input: "alter table a drop partition p2712", - output: "alter table a", - }, { - input: "alter table a drop index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop fulltext index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop spatial index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop foreign key", - output: "alter table a", - }, { - input: "alter table a drop primary key", - output: "alter table a", - }, { - input: "alter table a drop constraint", - output: "alter table a", - }, { - input: "alter table a drop id", - output: "alter table a", - }, { - input: "alter table a add vindex hash (id)", - }, { - input: "alter table a add vindex `hash` (`id`)", - output: "alter table a add vindex hash (id)", - }, { - input: "alter table a add vindex hash (id) using `hash`", - output: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table a add vindex `add` (`add`)", - }, { - input: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table a add vindex hash (id) using `hash`", - output: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table user add vindex name_lookup_vdx (name) using lookup_hash with owner=user, table=name_user_idx, from=name, to=user_id", - }, { - input: "alter table user2 add vindex name_lastname_lookup_vdx (name,lastname) using lookup with owner=`user`, table=`name_lastname_keyspace_id_map`, from=`name,lastname`, to=`keyspace_id`", - output: "alter table user2 add vindex name_lastname_lookup_vdx (name, lastname) using lookup with owner=user, table=name_lastname_keyspace_id_map, from=name,lastname, to=keyspace_id", - }, { - input: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex `hash`", - output: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex hash", - output: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex `add`", - output: "alter table a drop vindex `add`", - }, { - input: "create table a", - }, { - input: "create table a (\n\t`a` int\n)", - output: "create table a (\n\ta int\n)", - }, { - input: "create table `by` (\n\t`by` char\n)", - }, { - input: "create table if not exists a (\n\t`a` int\n)", - output: "create table a (\n\ta int\n)", - }, { - input: "create table a ignore me this is garbage", - output: "create table a", - }, { - input: "create table a (a int, b char, c garbage)", - output: "create table a", - }, { - input: "create vindex hash_vdx using hash", - }, { - input: "create vindex lookup_vdx using lookup with owner=user, table=name_user_idx, from=name, to=user_id", - }, { - input: "create vindex xyz_vdx using xyz with param1=hello, param2='world', param3=123", - }, { - input: "create index a on b", - output: "alter table b", - }, { - input: "create unique index a on b", - output: "alter table b", - }, { - input: "create unique index a using foo on b", - output: "alter table b", - }, { - input: "create fulltext index a using foo on b", - output: "alter table b", - }, { - input: "create spatial index a using foo on b", - output: "alter table b", - }, { - input: "create view a", - output: "create table a", - }, { - input: "create or replace view a", - output: "create table a", - }, { - input: "alter view a", - output: "alter table a", - }, { - input: "drop view a", - output: "drop table a", - }, { - input: "drop table a", - output: "drop table a", - }, { - input: "drop table if exists a", - output: "drop table if exists a", - }, { - input: "drop view if exists a", - output: "drop table if exists a", - }, { - input: "drop index b on a", - output: "alter table a", - }, { - input: "analyze table a", - output: "alter table a", - }, { - input: "show binary logs", - output: "show binary logs", - }, { - input: "show binlog events", - output: "show binlog", - }, { - input: "show character set", - output: "show character set", - }, { - input: "show character set like '%foo'", - output: "show character set", - }, { - input: "show collation", - output: "show collation", - }, { - input: "show create database d", - output: "show create database", - }, { - input: "show create event e", - output: "show create event", - }, { - input: "show create function f", - output: "show create function", - }, { - input: "show create procedure p", - output: "show create procedure", - }, { - input: "show create table t", - output: "show create table", - }, { - input: "show create trigger t", - output: "show create trigger", - }, { - input: "show create user u", - output: "show create user", - }, { - input: "show create view v", - output: "show create view", - }, { - input: "show databases", - output: "show databases", - }, { - input: "show engine INNODB", - output: "show engine", - }, { - input: "show engines", - output: "show engines", - }, { - input: "show storage engines", - output: "show storage", - }, { - input: "show errors", - output: "show errors", - }, { - input: "show events", - output: "show events", - }, { - input: "show function code func", - output: "show function", - }, { - input: "show function status", - output: "show function", - }, { - input: "show grants for 'root@localhost'", - output: "show grants", - }, { - input: "show index from table", - output: "show index", - }, { - input: "show indexes from table", - output: "show indexes", - }, { - input: "show keys from table", - output: "show keys", - }, { - input: "show master status", - output: "show master", - }, { - input: "show open tables", - output: "show open", - }, { - input: "show plugins", - output: "show plugins", - }, { - input: "show privileges", - output: "show privileges", - }, { - input: "show procedure code p", - output: "show procedure", - }, { - input: "show procedure status", - output: "show procedure", - }, { - input: "show processlist", - output: "show processlist", - }, { - input: "show full processlist", - output: "show processlist", - }, { - input: "show profile cpu for query 1", - output: "show profile", - }, { - input: "show profiles", - output: "show profiles", - }, { - input: "show relaylog events", - output: "show relaylog", - }, { - input: "show slave hosts", - output: "show slave", - }, { - input: "show slave status", - output: "show slave", - }, { - input: "show status", - output: "show status", - }, { - input: "show global status", - output: "show global status", - }, { - input: "show session status", - output: "show session status", - }, { - input: "show table status", - output: "show table", - }, { - input: "show tables", - }, { - input: "show tables like '%keyspace%'", - }, { - input: "show tables where 1 = 0", - }, { - input: "show tables from a", - }, { - input: "show tables from a where 1 = 0", - }, { - input: "show tables from a like '%keyspace%'", - }, { - input: "show full tables", - }, { - input: "show full tables from a", - }, { - input: "show full tables in a", - output: "show full tables from a", - }, { - input: "show full tables from a like '%keyspace%'", - }, { - input: "show full tables from a where 1 = 0", - }, { - input: "show full tables like '%keyspace%'", - }, { - input: "show full tables where 1 = 0", - }, { - input: "show triggers", - output: "show triggers", - }, { - input: "show variables", - output: "show variables", - }, { - input: "show global variables", - output: "show global variables", - }, { - input: "show session variables", - output: "show session variables", - }, { - input: "show vindexes", - output: "show vindexes", - }, { - input: "show vindexes on t", - output: "show vindexes on t", - }, { - input: "show vitess_keyspaces", - }, { - input: "show vitess_shards", - }, { - input: "show vitess_tablets", - }, { - input: "show vschema_tables", - }, { - input: "show warnings", - output: "show warnings", - }, { - input: "show foobar", - output: "show foobar", - }, { - input: "show foobar like select * from table where syntax is 'ignored'", - output: "show foobar", - }, { - input: "use db", - output: "use db", - }, { - input: "use duplicate", - output: "use `duplicate`", - }, { - input: "use `ks:-80@master`", - output: "use `ks:-80@master`", - }, { - input: "describe foobar", - output: "otherread", - }, { - input: "desc foobar", - output: "otherread", - }, { - input: "explain foobar", - output: "otherread", - }, { - input: "truncate table foo", - output: "truncate table foo", - }, { - input: "truncate foo", - output: "truncate table foo", - }, { - input: "repair foo", - output: "otheradmin", - }, { - input: "optimize foo", - output: "otheradmin", - }, { - input: "select /* EQ true */ 1 from t where a = true", - }, { - input: "select /* EQ false */ 1 from t where a = false", - }, { - input: "select /* NE true */ 1 from t where a != true", - }, { - input: "select /* NE false */ 1 from t where a != false", - }, { - input: "select /* LT true */ 1 from t where a < true", - }, { - input: "select /* LT false */ 1 from t where a < false", - }, { - input: "select /* GT true */ 1 from t where a > true", - }, { - input: "select /* GT false */ 1 from t where a > false", - }, { - input: "select /* LE true */ 1 from t where a <= true", - }, { - input: "select /* LE false */ 1 from t where a <= false", - }, { - input: "select /* GE true */ 1 from t where a >= true", - }, { - input: "select /* GE false */ 1 from t where a >= false", - }, { - input: "select * from t order by a collate utf8_general_ci", - output: "select * from t order by a collate utf8_general_ci asc", - }, { - input: "select k collate latin1_german2_ci as k1 from t1 order by k1 asc", - }, { - input: "select * from t group by a collate utf8_general_ci", - }, { - input: "select MAX(k collate latin1_german2_ci) from t1", - }, { - input: "select distinct k collate latin1_german2_ci from t1", - }, { - input: "select * from t1 where 'Müller' collate latin1_german2_ci = k", - }, { - input: "select * from t1 where k like 'Müller' collate latin1_german2_ci", - }, { - input: "select k from t1 group by k having k = 'Müller' collate latin1_german2_ci", - }, { - input: "select k from t1 join t2 order by a collate latin1_german2_ci asc, b collate latin1_german2_ci asc", - }, { - input: "select k collate 'latin1_german2_ci' as k1 from t1 order by k1 asc", - output: "select k collate latin1_german2_ci as k1 from t1 order by k1 asc", - }, { - input: "select /* drop trailing semicolon */ 1 from dual;", - output: "select /* drop trailing semicolon */ 1 from dual", - }, { - input: "select /* cache directive */ sql_no_cache 'foo' from t", - }, { - input: "select binary 'a' = 'A' from t", - }, { - input: "select 1 from t where foo = _binary 'bar'", - }, { - input: "select 1 from t where foo = _binary'bar'", - output: "select 1 from t where foo = _binary 'bar'", - }, { - input: "select match(a) against ('foo') from t", - }, { - input: "select match(a1, a2) against ('foo' in natural language mode with query expansion) from t", - }, { - input: "select title from video as v where match(v.title, v.tag) against ('DEMO' in boolean mode)", - }, { - input: "select name, group_concat(score) from t group by name", - }, { - input: "select name, group_concat(distinct id, score order by id desc separator ':') from t group by name", - }, { - input: "select * from t partition (p0)", - }, { - input: "select * from t partition (p0, p1)", - }, { - input: "select e.id, s.city from employees as e join stores partition (p1) as s on e.store_id = s.id", - }, { - input: "select truncate(120.3333, 2) from dual", - }, { - input: "update t partition (p0) set a = 1", - }, { - input: "insert into t partition (p0) values (1, 'asdf')", - }, { - input: "insert into t1 select * from t2 partition (p0)", - }, { - input: "replace into t partition (p0) values (1, 'asdf')", - }, { - input: "delete from t partition (p0) where a = 1", - }, { - input: "stream * from t", - }, { - input: "stream /* comment */ * from t", - }, { - input: "begin", - }, { - input: "start transaction", - output: "begin", - }, { - input: "commit", - }, { - input: "rollback", - }, { - input: "create database test_db", - }, { - input: "create schema test_db", - output: "create database test_db", - }, { - input: "create database if not exists test_db", - output: "create database test_db", - }, { - input: "drop database test_db", - }, { - input: "drop schema test_db", - output: "drop database test_db", - }, { - input: "drop database if exists test_db", - output: "drop database test_db", - }} -) - -func TestValid(t *testing.T) { - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("Parse(%q) err: %v, want nil", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("Parse(%q) = %q, want: %q", tcase.input, out, tcase.output) - } - // This test just exercises the tree walking functionality. - // There's no way automated way to verify that a node calls - // all its children. But we can examine code coverage and - // ensure that all walkSubtree functions were called. - Walk(func(node SQLNode) (bool, error) { - return true, nil - }, tree) - } -} - -func TestCaseSensitivity(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "create table A (\n\t`B` int\n)", - output: "create table A (\n\tB int\n)", - }, { - input: "create index b on A", - output: "alter table A", - }, { - input: "alter table A foo", - output: "alter table A", - }, { - input: "alter table A convert", - output: "alter table A", - }, { - // View names get lower-cased. - input: "alter view A foo", - output: "alter table a", - }, { - input: "alter table A rename to B", - output: "rename table A to B", - }, { - input: "rename table A to B", - }, { - input: "drop table B", - output: "drop table B", - }, { - input: "drop table if exists B", - output: "drop table if exists B", - }, { - input: "drop index b on A", - output: "alter table A", - }, { - input: "select a from B", - }, { - input: "select A as B from C", - }, { - input: "select B.* from c", - }, { - input: "select B.A from c", - }, { - input: "select * from B as C", - }, { - input: "select * from A.B", - }, { - input: "update A set b = 1", - }, { - input: "update A.B set b = 1", - }, { - input: "select A() from b", - }, { - input: "select A(B, C) from b", - }, { - input: "select A(distinct B, C) from b", - }, { - // IF is an exception. It's always lower-cased. - input: "select IF(B, C) from b", - output: "select if(B, C) from b", - }, { - input: "select * from b use index (A)", - }, { - input: "insert into A(A, B) values (1, 2)", - }, { - input: "CREATE TABLE A (\n\t`A` int\n)", - output: "create table A (\n\tA int\n)", - }, { - input: "create view A", - output: "create table a", - }, { - input: "alter view A", - output: "alter table a", - }, { - input: "drop view A", - output: "drop table a", - }, { - input: "drop view if exists A", - output: "drop table if exists a", - }, { - input: "select /* lock in SHARE MODE */ 1 from t lock in SHARE MODE", - output: "select /* lock in SHARE MODE */ 1 from t lock in share mode", - }, { - input: "select next VALUE from t", - output: "select next 1 values from t", - }, { - input: "select /* use */ 1 from t1 use index (A) where b = 1", - }} - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestKeywords(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select current_timestamp", - output: "select current_timestamp() from dual", - }, { - input: "update t set a = current_timestamp()", - }, { - input: "select a, current_date from t", - output: "select a, current_date() from t", - }, { - input: "insert into t(a, b) values (current_date, current_date())", - output: "insert into t(a, b) values (current_date(), current_date())", - }, { - input: "select * from t where a > utc_timestmp()", - }, { - input: "update t set b = utc_timestamp + 5", - output: "update t set b = utc_timestamp() + 5", - }, { - input: "select utc_time, utc_date", - output: "select utc_time(), utc_date() from dual", - }, { - input: "select 1 from dual where localtime > utc_time", - output: "select 1 from dual where localtime() > utc_time()", - }, { - input: "update t set a = localtimestamp(), b = utc_timestamp", - output: "update t set a = localtimestamp(), b = utc_timestamp()", - }, { - input: "insert into t(a) values (unix_timestamp)", - }, { - input: "select replace(a, 'foo', 'bar') from t", - }, { - input: "update t set a = replace('1234', '2', '1')", - }, { - input: "insert into t(a, b) values ('foo', 'bar') on duplicate key update a = replace(hex('foo'), 'f', 'b')", - }, { - input: "update t set a = left('1234', 3)", - }, { - input: "select left(a, 5) from t", - }, { - input: "update t set d = adddate(date('2003-12-31 01:02:03'), interval 5 days)", - }, { - input: "insert into t(a, b) values (left('foo', 1), 'b')", - }, { - input: "insert /* qualified function */ into t(a, b) values (test.PI(), 'b')", - }, { - input: "select /* keyword in qualified id */ * from t join z on t.key = z.key", - output: "select /* keyword in qualified id */ * from t join z on t.`key` = z.`key`", - }, { - input: "select /* non-reserved keywords as unqualified cols */ date, view, offset from t", - output: "select /* non-reserved keywords as unqualified cols */ `date`, `view`, `offset` from t", - }, { - input: "select /* share and mode as cols */ share, mode from t where share = 'foo'", - output: "select /* share and mode as cols */ `share`, `mode` from t where `share` = 'foo'", - }, { - input: "select /* unused keywords as cols */ write, varying from t where trailing = 'foo'", - output: "select /* unused keywords as cols */ `write`, `varying` from t where `trailing` = 'foo'", - }, { - input: "select status from t", - output: "select `status` from t", - }, { - input: "select variables from t", - output: "select `variables` from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestConvert(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select cast('abc' as date) from t", - output: "select convert('abc', date) from t", - }, { - input: "select convert('abc', binary(4)) from t", - }, { - input: "select convert('abc', binary) from t", - }, { - input: "select convert('abc', char character set binary) from t", - }, { - input: "select convert('abc', char(4) ascii) from t", - }, { - input: "select convert('abc', char unicode) from t", - }, { - input: "select convert('abc', char(4)) from t", - }, { - input: "select convert('abc', char) from t", - }, { - input: "select convert('abc', nchar(4)) from t", - }, { - input: "select convert('abc', nchar) from t", - }, { - input: "select convert('abc', signed) from t", - }, { - input: "select convert('abc', signed integer) from t", - output: "select convert('abc', signed) from t", - }, { - input: "select convert('abc', unsigned) from t", - }, { - input: "select convert('abc', unsigned integer) from t", - output: "select convert('abc', unsigned) from t", - }, { - input: "select convert('abc', decimal(3, 4)) from t", - }, { - input: "select convert('abc', decimal(4)) from t", - }, { - input: "select convert('abc', decimal) from t", - }, { - input: "select convert('abc', date) from t", - }, { - input: "select convert('abc', time(4)) from t", - }, { - input: "select convert('abc', time) from t", - }, { - input: "select convert('abc', datetime(9)) from t", - }, { - input: "select convert('abc', datetime) from t", - }, { - input: "select convert('abc', json) from t", - }, { - input: "select convert('abc' using ascii) from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } - - invalidSQL := []struct { - input string - output string - }{{ - input: "select convert('abc' as date) from t", - output: "syntax error at position 24 near 'as'", - }, { - input: "select convert from t", - output: "syntax error at position 20 near 'from'", - }, { - input: "select cast('foo', decimal) from t", - output: "syntax error at position 19", - }, { - input: "select convert('abc', datetime(4+9)) from t", - output: "syntax error at position 34", - }, { - input: "select convert('abc', decimal(4+9)) from t", - output: "syntax error at position 33", - }} - - for _, tcase := range invalidSQL { - _, err := Parse(tcase.input) - if err == nil || err.Error() != tcase.output { - t.Errorf("%s: %v, want %s", tcase.input, err, tcase.output) - } - } -} - -func TestSubStr(t *testing.T) { - - validSQL := []struct { - input string - output string - }{{ - input: "select substr(a, 1) from t", - }, { - input: "select substr(a, 1, 6) from t", - }, { - input: "select substring(a, 1) from t", - output: "select substr(a, 1) from t", - }, { - input: "select substring(a, 1, 6) from t", - output: "select substr(a, 1, 6) from t", - }, { - input: "select substr(a from 1 for 6) from t", - output: "select substr(a, 1, 6) from t", - }, { - input: "select substring(a from 1 for 6) from t", - output: "select substr(a, 1, 6) from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestCreateTable(t *testing.T) { - validSQL := []string{ - // test all the data types and options - "create table t (\n" + - " col_bit bit,\n" + - " col_tinyint tinyint auto_increment,\n" + - " col_tinyint3 tinyint(3) unsigned,\n" + - " col_smallint smallint,\n" + - " col_smallint4 smallint(4) zerofill,\n" + - " col_mediumint mediumint,\n" + - " col_mediumint5 mediumint(5) unsigned not null,\n" + - " col_int int,\n" + - " col_int10 int(10) not null,\n" + - " col_integer integer comment 'this is an integer',\n" + - " col_bigint bigint,\n" + - " col_bigint10 bigint(10) zerofill not null default 10,\n" + - " col_real real,\n" + - " col_real2 real(1,2) not null default 1.23,\n" + - " col_double double,\n" + - " col_double2 double(3,4) not null default 1.23,\n" + - " col_float float,\n" + - " col_float2 float(3,4) not null default 1.23,\n" + - " col_decimal decimal,\n" + - " col_decimal2 decimal(2),\n" + - " col_decimal3 decimal(2,3),\n" + - " col_numeric numeric,\n" + - " col_numeric2 numeric(2),\n" + - " col_numeric3 numeric(2,3),\n" + - " col_date date,\n" + - " col_time time,\n" + - " col_timestamp timestamp,\n" + - " col_datetime datetime,\n" + - " col_year year,\n" + - " col_char char,\n" + - " col_char2 char(2),\n" + - " col_char3 char(3) character set ascii,\n" + - " col_char4 char(4) character set ascii collate ascii_bin,\n" + - " col_varchar varchar,\n" + - " col_varchar2 varchar(2),\n" + - " col_varchar3 varchar(3) character set ascii,\n" + - " col_varchar4 varchar(4) character set ascii collate ascii_bin,\n" + - " col_binary binary,\n" + - " col_varbinary varbinary(10),\n" + - " col_tinyblob tinyblob,\n" + - " col_blob blob,\n" + - " col_mediumblob mediumblob,\n" + - " col_longblob longblob,\n" + - " col_tinytext tinytext,\n" + - " col_text text,\n" + - " col_mediumtext mediumtext,\n" + - " col_longtext longtext,\n" + - " col_text text character set ascii collate ascii_bin,\n" + - " col_json json,\n" + - " col_enum enum('a', 'b', 'c', 'd'),\n" + - " col_enum2 enum('a', 'b', 'c', 'd') character set ascii,\n" + - " col_enum3 enum('a', 'b', 'c', 'd') collate ascii_bin,\n" + - " col_enum4 enum('a', 'b', 'c', 'd') character set ascii collate ascii_bin,\n" + - " col_set set('a', 'b', 'c', 'd'),\n" + - " col_set2 set('a', 'b', 'c', 'd') character set ascii,\n" + - " col_set3 set('a', 'b', 'c', 'd') collate ascii_bin,\n" + - " col_set4 set('a', 'b', 'c', 'd') character set ascii collate ascii_bin,\n" + - " col_geometry1 geometry,\n" + - " col_geometry2 geometry not null,\n" + - " col_point1 point,\n" + - " col_point2 point not null,\n" + - " col_linestring1 linestring,\n" + - " col_linestring2 linestring not null,\n" + - " col_polygon1 polygon,\n" + - " col_polygon2 polygon not null,\n" + - " col_geometrycollection1 geometrycollection,\n" + - " col_geometrycollection2 geometrycollection not null,\n" + - " col_multipoint1 multipoint,\n" + - " col_multipoint2 multipoint not null,\n" + - " col_multilinestring1 multilinestring,\n" + - " col_multilinestring2 multilinestring not null,\n" + - " col_multipolygon1 multipolygon,\n" + - " col_multipolygon2 multipolygon not null\n" + - ")", - - // test defaults - "create table t (\n" + - " i1 int default 1,\n" + - " i2 int default null,\n" + - " f1 float default 1.23,\n" + - " s1 varchar default 'c',\n" + - " s2 varchar default 'this is a string',\n" + - " s3 varchar default null,\n" + - " s4 timestamp default current_timestamp,\n" + - " s5 bit(1) default B'0'\n" + - ")", - - // test key field options - "create table t (\n" + - " id int auto_increment primary key,\n" + - " username varchar unique key,\n" + - " email varchar unique,\n" + - " full_name varchar key,\n" + - " time1 timestamp on update current_timestamp,\n" + - " time2 timestamp default current_timestamp on update current_timestamp\n" + - ")", - - // test defining indexes separately - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " geom point not null,\n" + - " status_nonkeyword varchar,\n" + - " primary key (id),\n" + - " spatial key geom (geom),\n" + - " unique key by_username (username),\n" + - " unique by_username2 (username),\n" + - " unique index by_username3 (username),\n" + - " index by_status (status_nonkeyword),\n" + - " key by_full_name (full_name)\n" + - ")", - - // test that indexes support USING - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " status_nonkeyword varchar,\n" + - " primary key (id) using BTREE,\n" + - " unique key by_username (username) using HASH,\n" + - " unique by_username2 (username) using OTHER,\n" + - " unique index by_username3 (username) using XYZ,\n" + - " index by_status (status_nonkeyword) using PDQ,\n" + - " key by_full_name (full_name) using OTHER\n" + - ")", - // test other index options - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " primary key (id) comment 'hi',\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique index by_username4 (username) comment 'hi' using BTREE,\n" + - " unique index by_username4 (username) using BTREE key_block_size 4 comment 'hi'\n" + - ")", - - // multi-column indexes - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " a int,\n" + - " b int,\n" + - " c int,\n" + - " primary key (id, username),\n" + - " unique key by_abc (a, b, c),\n" + - " key by_email (email(10), username)\n" + - ")", - - // table options - "create table t (\n" + - " id int auto_increment\n" + - ") engine InnoDB,\n" + - " auto_increment 123,\n" + - " avg_row_length 1,\n" + - " default character set utf8mb4,\n" + - " character set latin1,\n" + - " checksum 0,\n" + - " default collate binary,\n" + - " collate ascii_bin,\n" + - " comment 'this is a comment',\n" + - " compression 'zlib',\n" + - " connection 'connect_string',\n" + - " data directory 'absolute path to directory',\n" + - " delay_key_write 1,\n" + - " encryption 'n',\n" + - " index directory 'absolute path to directory',\n" + - " insert_method no,\n" + - " key_block_size 1024,\n" + - " max_rows 100,\n" + - " min_rows 10,\n" + - " pack_keys 0,\n" + - " password 'sekret',\n" + - " row_format default,\n" + - " stats_auto_recalc default,\n" + - " stats_persistent 0,\n" + - " stats_sample_pages 1,\n" + - " tablespace tablespace_name storage disk,\n" + - " tablespace tablespace_name\n", - } - for _, sql := range validSQL { - sql = strings.TrimSpace(sql) - tree, err := ParseStrictDDL(sql) - if err != nil { - t.Errorf("input: %s, err: %v", sql, err) - continue - } - got := String(tree.(*DDL)) - - if sql != got { - t.Errorf("want:\n%s\ngot:\n%s", sql, got) - } - } - - sql := "create table t garbage" - tree, err := Parse(sql) - if err != nil { - t.Errorf("input: %s, err: %v", sql, err) - } - - tree, err = ParseStrictDDL(sql) - if tree != nil || err == nil { - t.Errorf("ParseStrictDDL unexpectedly accepted input %s", sql) - } - - testCases := []struct { - input string - output string - }{{ - // test key_block_size - input: "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique key by_username2 (username) key_block_size=8,\n" + - " unique by_username3 (username) key_block_size = 4\n" + - ")", - output: "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique key by_username2 (username) key_block_size 8,\n" + - " unique by_username3 (username) key_block_size 4\n" + - ")", - }, - } - for _, tcase := range testCases { - tree, err := ParseStrictDDL(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - if got, want := String(tree.(*DDL)), tcase.output; got != want { - t.Errorf("Parse(%s):\n%s, want\n%s", tcase.input, got, want) - } - } -} - -func TestCreateTableEscaped(t *testing.T) { - testCases := []struct { - input string - output string - }{{ - input: "create table `a`(`id` int, primary key(`id`))", - output: "create table a (\n" + - "\tid int,\n" + - "\tprimary key (id)\n" + - ")", - }, { - input: "create table `insert`(`update` int, primary key(`delete`))", - output: "create table `insert` (\n" + - "\t`update` int,\n" + - "\tprimary key (`delete`)\n" + - ")", - }} - for _, tcase := range testCases { - tree, err := ParseStrictDDL(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - if got, want := String(tree.(*DDL)), tcase.output; got != want { - t.Errorf("Parse(%s):\n%s, want\n%s", tcase.input, got, want) - } - } -} - -var ( - invalidSQL = []struct { - input string - output string - excludeMulti bool // Don't use in the ParseNext multi-statement parsing tests. - }{{ - input: "select $ from t", - output: "syntax error at position 9 near '$'", - }, { - input: "select : from t", - output: "syntax error at position 9 near ':'", - }, { - input: "select 0xH from t", - output: "syntax error at position 10 near '0x'", - }, { - input: "select x'78 from t", - output: "syntax error at position 12 near '78'", - }, { - input: "select x'777' from t", - output: "syntax error at position 14 near '777'", - }, { - input: "select * from t where :1 = 2", - output: "syntax error at position 24 near ':'", - }, { - input: "select * from t where :. = 2", - output: "syntax error at position 24 near ':'", - }, { - input: "select * from t where ::1 = 2", - output: "syntax error at position 25 near '::'", - }, { - input: "select * from t where ::. = 2", - output: "syntax error at position 25 near '::'", - }, { - input: "update a set c = values(1)", - output: "syntax error at position 26 near '1'", - }, { - input: "select(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(", - output: "max nesting level reached at position 406", - }, { - input: "select(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(", - output: "syntax error at position 404", - }, { - // This construct is considered invalid due to a grammar conflict. - input: "insert into a select * from b join c on duplicate key update d=e", - output: "syntax error at position 54 near 'key'", - }, { - input: "select * from a left join b", - output: "syntax error at position 28", - }, { - input: "select * from a natural join b on c = d", - output: "syntax error at position 34 near 'on'", - }, { - input: "select * from a natural join b using (c)", - output: "syntax error at position 37 near 'using'", - }, { - input: "select next id from a", - output: "expecting value after next at position 15 near 'id'", - }, { - input: "select next 1+1 values from a", - output: "syntax error at position 15", - }, { - input: "insert into a values (select * from b)", - output: "syntax error at position 29 near 'select'", - }, { - input: "select database", - output: "syntax error at position 16", - }, { - input: "select mod from t", - output: "syntax error at position 16 near 'from'", - }, { - input: "select 1 from t where div 5", - output: "syntax error at position 26 near 'div'", - }, { - input: "select 1 from t where binary", - output: "syntax error at position 29", - }, { - input: "select match(a1, a2) against ('foo' in boolean mode with query expansion) from t", - output: "syntax error at position 57 near 'with'", - }, { - input: "select /* reserved keyword as unqualified column */ * from t where key = 'test'", - output: "syntax error at position 71 near 'key'", - }, { - input: "select /* vitess-reserved keyword as unqualified column */ * from t where escape = 'test'", - output: "syntax error at position 81 near 'escape'", - }, { - input: "(select /* parenthesized select */ * from t)", - output: "syntax error at position 45", - }, { - input: "select * from t where id = ((select a from t1 union select b from t2) order by a limit 1)", - output: "syntax error at position 76 near 'order'", - }, { - input: "select /* straight_join using */ 1 from t1 straight_join t2 using (a)", - output: "syntax error at position 66 near 'using'", - }, { - input: "select 'aa", - output: "syntax error at position 11 near 'aa'", - excludeMulti: true, - }, { - input: "select 'aa\\", - output: "syntax error at position 12 near 'aa'", - excludeMulti: true, - }, { - input: "select /* aa", - output: "syntax error at position 13 near '/* aa'", - excludeMulti: true, - }} -) - -func TestErrors(t *testing.T) { - for _, tcase := range invalidSQL { - _, err := Parse(tcase.input) - if err == nil || err.Error() != tcase.output { - t.Errorf("%s: %v, want %s", tcase.input, err, tcase.output) - } - } -} - -// Benchmark run on 6/23/17, prior to improvements: -// BenchmarkParse1-4 100000 16334 ns/op -// BenchmarkParse2-4 30000 44121 ns/op - -func BenchmarkParse1(b *testing.B) { - sql := "select 'abcd', 20, 30.0, eid from a where 1=eid and name='3'" - for i := 0; i < b.N; i++ { - ast, err := Parse(sql) - if err != nil { - b.Fatal(err) - } - _ = String(ast) - } -} - -func BenchmarkParse2(b *testing.B) { - sql := "select aaaa, bbb, ccc, ddd, eeee, ffff, gggg, hhhh, iiii from tttt, ttt1, ttt3 where aaaa = bbbb and bbbb = cccc and dddd+1 = eeee group by fff, gggg having hhhh = iiii and iiii = jjjj order by kkkk, llll limit 3, 4" - for i := 0; i < b.N; i++ { - ast, err := Parse(sql) - if err != nil { - b.Fatal(err) - } - _ = String(ast) - } -} - -var benchQuery string - -func init() { - // benchQuerySize is the approximate size of the query. - benchQuerySize := 1000000 - - // Size of value is 1/10 size of query. Then we add - // 10 such values to the where clause. - var baseval bytes.Buffer - for i := 0; i < benchQuerySize/100; i++ { - // Add an escape character: This will force the upcoming - // tokenizer improvement to still create a copy of the string. - // Then we can see if avoiding the copy will be worth it. - baseval.WriteString("\\'123456789") - } - - var buf bytes.Buffer - buf.WriteString("select a from t1 where v = 1") - for i := 0; i < 10; i++ { - fmt.Fprintf(&buf, " and v%d = \"%d%s\"", i, i, baseval.String()) - } - benchQuery = buf.String() -} - -func BenchmarkParse3(b *testing.B) { - for i := 0; i < b.N; i++ { - if _, err := Parse(benchQuery); err != nil { - b.Fatal(err) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go deleted file mode 100644 index dc0e1ac0..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestNewParsedQuery(t *testing.T) { - stmt, err := Parse("select * from a where id =:id") - if err != nil { - t.Error(err) - return - } - pq := NewParsedQuery(stmt) - want := &ParsedQuery{ - Query: "select * from a where id = :id", - bindLocations: []bindLocation{{offset: 27, length: 3}}, - } - if !reflect.DeepEqual(pq, want) { - t.Errorf("GenerateParsedQuery: %+v, want %+v", pq, want) - } -} - -func TestGenerateQuery(t *testing.T) { - tcases := []struct { - desc string - query string - bindVars map[string]*querypb.BindVariable - extras map[string]Encodable - output string - }{ - { - desc: "no substitutions", - query: "select * from a where id = 2", - bindVars: map[string]*querypb.BindVariable{ - "id": sqltypes.Int64BindVariable(1), - }, - output: "select * from a where id = 2", - }, { - desc: "missing bind var", - query: "select * from a where id1 = :id1 and id2 = :id2", - bindVars: map[string]*querypb.BindVariable{ - "id1": sqltypes.Int64BindVariable(1), - }, - output: "missing bind var id2", - }, { - desc: "simple bindvar substitution", - query: "select * from a where id1 = :id1 and id2 = :id2", - bindVars: map[string]*querypb.BindVariable{ - "id1": sqltypes.Int64BindVariable(1), - "id2": sqltypes.NullBindVariable, - }, - output: "select * from a where id1 = 1 and id2 = null", - }, { - desc: "tuple *querypb.BindVariable", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{1, "aa"}), - }, - output: "select * from a where id in (1, 'aa')", - }, { - desc: "list bind vars 0 arguments", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{}), - }, - output: "empty list supplied for vals", - }, { - desc: "non-list bind var supplied", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.Int64BindVariable(1), - }, - output: "unexpected list arg type (INT64) for key vals", - }, { - desc: "list bind var for non-list", - query: "select * from a where id = :vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{1}), - }, - output: "unexpected arg type (TUPLE) for non-list key vals", - }, { - desc: "single column tuple equality", - query: "select * from a where b = :equality", - extras: map[string]Encodable{ - "equality": &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk")}, - Rows: [][]sqltypes.Value{ - {sqltypes.NewInt64(1)}, - {sqltypes.NewVarBinary("aa")}, - }, - }, - }, - output: "select * from a where b = pk in (1, 'aa')", - }, { - desc: "multi column tuple equality", - query: "select * from a where b = :equality", - extras: map[string]Encodable{ - "equality": &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk1"), NewColIdent("pk2")}, - Rows: [][]sqltypes.Value{ - { - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("aa"), - }, - { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bb"), - }, - }, - }, - }, - output: "select * from a where b = (pk1 = 1 and pk2 = 'aa') or (pk1 = 2 and pk2 = 'bb')", - }, - } - - for _, tcase := range tcases { - tree, err := Parse(tcase.query) - if err != nil { - t.Errorf("parse failed for %s: %v", tcase.desc, err) - continue - } - buf := NewTrackedBuffer(nil) - buf.Myprintf("%v", tree) - pq := buf.ParsedQuery() - bytes, err := pq.GenerateQuery(tcase.bindVars, tcase.extras) - var got string - if err != nil { - got = err.Error() - } else { - got = string(bytes) - } - if got != tcase.output { - t.Errorf("for test case: %s, got: '%s', want '%s'", tcase.desc, got, tcase.output) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/bytes2.patch b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/bytes2.patch deleted file mode 100644 index e69de29b..00000000 diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch deleted file mode 100644 index abf19eac..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch +++ /dev/null @@ -1,1315 +0,0 @@ -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/proto/query/query.pb.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/querypb/query.pb.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/proto/query/query.pb.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/querypb/query.pb.go 2017-10-18 18:06:33.000000000 -0700 -@@ -62,30 +62,24 @@ - SplitQueryResponse - StreamHealthRequest - RealtimeStats -- AggregateStats - StreamHealthResponse - UpdateStreamRequest - UpdateStreamResponse - TransactionMetadata - */ --package query -+package querypb - --import proto "github.com/golang/protobuf/proto" --import fmt "fmt" --import math "math" --import topodata "vitess.io/vitess/go/vt/proto/topodata" --import vtrpc "vitess.io/vitess/go/vt/proto/vtrpc" -- --// 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.ProtoPackageIsVersion2 // please upgrade the proto package -+import "strconv" -+ -+// EnumName is a helper function to simplify printing protocol buffer enums -+// by name. Given an enum map and a value, it returns a useful string. -+func EnumName(m map[int32]string, v int32) string { -+ s, ok := m[v] -+ if ok { -+ return s -+ } -+ return strconv.Itoa(int(v)) -+} - - // Flags sent from the MySQL C API - type MySqlFlag int32 -@@ -159,9 +153,8 @@ - } - - func (x MySqlFlag) String() string { -- return proto.EnumName(MySqlFlag_name, int32(x)) -+ return EnumName(MySqlFlag_name, int32(x)) - } --func (MySqlFlag) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - - // Flag allows us to qualify types by their common properties. - type Flag int32 -@@ -196,9 +189,8 @@ - } - - func (x Flag) String() string { -- return proto.EnumName(Flag_name, int32(x)) -+ return EnumName(Flag_name, int32(x)) - } --func (Flag) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - - // Type defines the various supported data types in bind vars - // and query results. -@@ -375,9 +367,8 @@ - } - - func (x Type) String() string { -- return proto.EnumName(Type_name, int32(x)) -+ return EnumName(Type_name, int32(x)) - } --func (Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - - // TransactionState represents the state of a distributed transaction. - type TransactionState int32 -@@ -403,9 +394,8 @@ - } - - func (x TransactionState) String() string { -- return proto.EnumName(TransactionState_name, int32(x)) -+ return EnumName(TransactionState_name, int32(x)) - } --func (TransactionState) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - - type ExecuteOptions_IncludedFields int32 - -@@ -427,10 +417,7 @@ - } - - func (x ExecuteOptions_IncludedFields) String() string { -- return proto.EnumName(ExecuteOptions_IncludedFields_name, int32(x)) --} --func (ExecuteOptions_IncludedFields) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{6, 0} -+ return EnumName(ExecuteOptions_IncludedFields_name, int32(x)) - } - - type ExecuteOptions_Workload int32 -@@ -456,9 +443,8 @@ - } - - func (x ExecuteOptions_Workload) String() string { -- return proto.EnumName(ExecuteOptions_Workload_name, int32(x)) -+ return EnumName(ExecuteOptions_Workload_name, int32(x)) - } --func (ExecuteOptions_Workload) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{6, 1} } - - type ExecuteOptions_TransactionIsolation int32 - -@@ -486,10 +472,7 @@ - } - - func (x ExecuteOptions_TransactionIsolation) String() string { -- return proto.EnumName(ExecuteOptions_TransactionIsolation_name, int32(x)) --} --func (ExecuteOptions_TransactionIsolation) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{6, 2} -+ return EnumName(ExecuteOptions_TransactionIsolation_name, int32(x)) - } - - // The category of one statement. -@@ -513,10 +496,7 @@ - } - - func (x StreamEvent_Statement_Category) String() string { -- return proto.EnumName(StreamEvent_Statement_Category_name, int32(x)) --} --func (StreamEvent_Statement_Category) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{11, 0, 0} -+ return EnumName(StreamEvent_Statement_Category_name, int32(x)) - } - - type SplitQueryRequest_Algorithm int32 -@@ -536,27 +516,22 @@ - } - - func (x SplitQueryRequest_Algorithm) String() string { -- return proto.EnumName(SplitQueryRequest_Algorithm_name, int32(x)) --} --func (SplitQueryRequest_Algorithm) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{49, 0} -+ return EnumName(SplitQueryRequest_Algorithm_name, int32(x)) - } - -+/* - // Target describes what the client expects the tablet is. - // If the tablet does not match, an error is returned. - type Target struct { - Keyspace string `protobuf:"bytes,1,opt,name=keyspace" json:"keyspace,omitempty"` - Shard string `protobuf:"bytes,2,opt,name=shard" json:"shard,omitempty"` - TabletType topodata.TabletType `protobuf:"varint,3,opt,name=tablet_type,json=tabletType,enum=topodata.TabletType" json:"tablet_type,omitempty"` -- // cell is used for routing queries between vtgate and vttablets. It -- // is not used when Target is part of the Session sent by the client. -- Cell string `protobuf:"bytes,4,opt,name=cell" json:"cell,omitempty"` - } - - func (m *Target) Reset() { *m = Target{} } --func (m *Target) String() string { return proto.CompactTextString(m) } --func (*Target) ProtoMessage() {} --func (*Target) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } -+func (m *Target) String() string { return "TODO" } -+ -+ - - func (m *Target) GetKeyspace() string { - if m != nil { -@@ -579,12 +554,6 @@ - return topodata.TabletType_UNKNOWN - } - --func (m *Target) GetCell() string { -- if m != nil { -- return m.Cell -- } -- return "" --} - - // VTGateCallerID is sent by VTGate to VTTablet to describe the - // caller. If possible, this information is secure. For instance, -@@ -600,9 +569,9 @@ - } - - func (m *VTGateCallerID) Reset() { *m = VTGateCallerID{} } --func (m *VTGateCallerID) String() string { return proto.CompactTextString(m) } --func (*VTGateCallerID) ProtoMessage() {} --func (*VTGateCallerID) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } -+func (m *VTGateCallerID) String() string { return "TODO" } -+ -+ - - func (m *VTGateCallerID) GetUsername() string { - if m != nil { -@@ -634,9 +603,9 @@ - } - - func (m *EventToken) Reset() { *m = EventToken{} } --func (m *EventToken) String() string { return proto.CompactTextString(m) } --func (*EventToken) ProtoMessage() {} --func (*EventToken) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } -+func (m *EventToken) String() string { return "TODO" } -+ -+ - - func (m *EventToken) GetTimestamp() int64 { - if m != nil { -@@ -658,6 +627,7 @@ - } - return "" - } -+*/ - - // Value represents a typed value. - type Value struct { -@@ -665,10 +635,8 @@ - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - } - --func (m *Value) Reset() { *m = Value{} } --func (m *Value) String() string { return proto.CompactTextString(m) } --func (*Value) ProtoMessage() {} --func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } -+func (m *Value) Reset() { *m = Value{} } -+func (m *Value) String() string { return "TODO" } - - func (m *Value) GetType() Type { - if m != nil { -@@ -692,10 +660,8 @@ - Values []*Value `protobuf:"bytes,3,rep,name=values" json:"values,omitempty"` - } - --func (m *BindVariable) Reset() { *m = BindVariable{} } --func (m *BindVariable) String() string { return proto.CompactTextString(m) } --func (*BindVariable) ProtoMessage() {} --func (*BindVariable) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } -+func (m *BindVariable) Reset() { *m = BindVariable{} } -+func (m *BindVariable) String() string { return "TODO" } - - func (m *BindVariable) GetType() Type { - if m != nil { -@@ -727,10 +693,8 @@ - BindVariables map[string]*BindVariable `protobuf:"bytes,2,rep,name=bind_variables,json=bindVariables" json:"bind_variables,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - } - --func (m *BoundQuery) Reset() { *m = BoundQuery{} } --func (m *BoundQuery) String() string { return proto.CompactTextString(m) } --func (*BoundQuery) ProtoMessage() {} --func (*BoundQuery) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } -+func (m *BoundQuery) Reset() { *m = BoundQuery{} } -+func (m *BoundQuery) String() string { return "TODO" } - - func (m *BoundQuery) GetSql() string { - if m != nil { -@@ -746,6 +710,7 @@ - return nil - } - -+/* - // ExecuteOptions is passed around for all Execute calls. - type ExecuteOptions struct { - // If set, we will try to include an EventToken with the responses. -@@ -774,15 +739,12 @@ - // vitess also sets a rowcount limit on queries, the smallest value wins. - SqlSelectLimit int64 `protobuf:"varint,8,opt,name=sql_select_limit,json=sqlSelectLimit" json:"sql_select_limit,omitempty"` - TransactionIsolation ExecuteOptions_TransactionIsolation `protobuf:"varint,9,opt,name=transaction_isolation,json=transactionIsolation,enum=query.ExecuteOptions_TransactionIsolation" json:"transaction_isolation,omitempty"` -- // skip_query_plan_cache specifies if the query plan shoud be cached by vitess. -- // By default all query plans are cached. -- SkipQueryPlanCache bool `protobuf:"varint,10,opt,name=skip_query_plan_cache,json=skipQueryPlanCache" json:"skip_query_plan_cache,omitempty"` - } - - func (m *ExecuteOptions) Reset() { *m = ExecuteOptions{} } --func (m *ExecuteOptions) String() string { return proto.CompactTextString(m) } --func (*ExecuteOptions) ProtoMessage() {} --func (*ExecuteOptions) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } -+func (m *ExecuteOptions) String() string { return "TODO" } -+ -+ - - func (m *ExecuteOptions) GetIncludeEventToken() bool { - if m != nil { -@@ -833,13 +795,6 @@ - return ExecuteOptions_DEFAULT - } - --func (m *ExecuteOptions) GetSkipQueryPlanCache() bool { -- if m != nil { -- return m.SkipQueryPlanCache -- } -- return false --} -- - // Field describes a single column returned by a query - type Field struct { - // name of the field as returned by mysql C API -@@ -864,9 +819,9 @@ - } - - func (m *Field) Reset() { *m = Field{} } --func (m *Field) String() string { return proto.CompactTextString(m) } --func (*Field) ProtoMessage() {} --func (*Field) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } -+func (m *Field) String() string { return "TODO" } -+ -+ - - func (m *Field) GetName() string { - if m != nil { -@@ -950,9 +905,9 @@ - } - - func (m *Row) Reset() { *m = Row{} } --func (m *Row) String() string { return proto.CompactTextString(m) } --func (*Row) ProtoMessage() {} --func (*Row) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } -+func (m *Row) String() string { return "TODO" } -+ -+ - - func (m *Row) GetLengths() []int64 { - if m != nil { -@@ -980,9 +935,9 @@ - } - - func (m *ResultExtras) Reset() { *m = ResultExtras{} } --func (m *ResultExtras) String() string { return proto.CompactTextString(m) } --func (*ResultExtras) ProtoMessage() {} --func (*ResultExtras) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } -+func (m *ResultExtras) String() string { return "TODO" } -+ -+ - - func (m *ResultExtras) GetEventToken() *EventToken { - if m != nil { -@@ -1016,9 +971,9 @@ - } - - func (m *QueryResult) Reset() { *m = QueryResult{} } --func (m *QueryResult) String() string { return proto.CompactTextString(m) } --func (*QueryResult) ProtoMessage() {} --func (*QueryResult) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } -+func (m *QueryResult) String() string { return "TODO" } -+ -+ - - func (m *QueryResult) GetFields() []*Field { - if m != nil { -@@ -1066,9 +1021,9 @@ - } - - func (m *StreamEvent) Reset() { *m = StreamEvent{} } --func (m *StreamEvent) String() string { return proto.CompactTextString(m) } --func (*StreamEvent) ProtoMessage() {} --func (*StreamEvent) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } -+func (m *StreamEvent) String() string { return "TODO" } -+ -+ - - func (m *StreamEvent) GetStatements() []*StreamEvent_Statement { - if m != nil { -@@ -1097,9 +1052,9 @@ - } - - func (m *StreamEvent_Statement) Reset() { *m = StreamEvent_Statement{} } --func (m *StreamEvent_Statement) String() string { return proto.CompactTextString(m) } --func (*StreamEvent_Statement) ProtoMessage() {} --func (*StreamEvent_Statement) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11, 0} } -+func (m *StreamEvent_Statement) String() string { return "TODO" } -+ -+ - - func (m *StreamEvent_Statement) GetCategory() StreamEvent_Statement_Category { - if m != nil { -@@ -1136,6 +1091,7 @@ - return nil - } - -+ - // ExecuteRequest is the payload to Execute - type ExecuteRequest struct { - EffectiveCallerId *vtrpc.CallerID `protobuf:"bytes,1,opt,name=effective_caller_id,json=effectiveCallerId" json:"effective_caller_id,omitempty"` -@@ -1147,9 +1103,9 @@ - } - - func (m *ExecuteRequest) Reset() { *m = ExecuteRequest{} } --func (m *ExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*ExecuteRequest) ProtoMessage() {} --func (*ExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{12} } -+func (m *ExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *ExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1199,9 +1155,9 @@ - } - - func (m *ExecuteResponse) Reset() { *m = ExecuteResponse{} } --func (m *ExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*ExecuteResponse) ProtoMessage() {} --func (*ExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } -+func (m *ExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *ExecuteResponse) GetResult() *QueryResult { - if m != nil { -@@ -1221,9 +1177,9 @@ - } - - func (m *ResultWithError) Reset() { *m = ResultWithError{} } --func (m *ResultWithError) String() string { return proto.CompactTextString(m) } --func (*ResultWithError) ProtoMessage() {} --func (*ResultWithError) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} } -+func (m *ResultWithError) String() string { return "TODO" } -+ -+ - - func (m *ResultWithError) GetError() *vtrpc.RPCError { - if m != nil { -@@ -1251,9 +1207,9 @@ - } - - func (m *ExecuteBatchRequest) Reset() { *m = ExecuteBatchRequest{} } --func (m *ExecuteBatchRequest) String() string { return proto.CompactTextString(m) } --func (*ExecuteBatchRequest) ProtoMessage() {} --func (*ExecuteBatchRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} } -+func (m *ExecuteBatchRequest) String() string { return "TODO" } -+ -+ - - func (m *ExecuteBatchRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1310,9 +1266,9 @@ - } - - func (m *ExecuteBatchResponse) Reset() { *m = ExecuteBatchResponse{} } --func (m *ExecuteBatchResponse) String() string { return proto.CompactTextString(m) } --func (*ExecuteBatchResponse) ProtoMessage() {} --func (*ExecuteBatchResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} } -+func (m *ExecuteBatchResponse) String() string { return "TODO" } -+ -+ - - func (m *ExecuteBatchResponse) GetResults() []*QueryResult { - if m != nil { -@@ -1331,9 +1287,9 @@ - } - - func (m *StreamExecuteRequest) Reset() { *m = StreamExecuteRequest{} } --func (m *StreamExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*StreamExecuteRequest) ProtoMessage() {} --func (*StreamExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} } -+func (m *StreamExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *StreamExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1376,9 +1332,9 @@ - } - - func (m *StreamExecuteResponse) Reset() { *m = StreamExecuteResponse{} } --func (m *StreamExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*StreamExecuteResponse) ProtoMessage() {} --func (*StreamExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18} } -+func (m *StreamExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *StreamExecuteResponse) GetResult() *QueryResult { - if m != nil { -@@ -1396,9 +1352,9 @@ - } - - func (m *BeginRequest) Reset() { *m = BeginRequest{} } --func (m *BeginRequest) String() string { return proto.CompactTextString(m) } --func (*BeginRequest) ProtoMessage() {} --func (*BeginRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{19} } -+func (m *BeginRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1434,9 +1390,9 @@ - } - - func (m *BeginResponse) Reset() { *m = BeginResponse{} } --func (m *BeginResponse) String() string { return proto.CompactTextString(m) } --func (*BeginResponse) ProtoMessage() {} --func (*BeginResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{20} } -+func (m *BeginResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginResponse) GetTransactionId() int64 { - if m != nil { -@@ -1454,9 +1410,9 @@ - } - - func (m *CommitRequest) Reset() { *m = CommitRequest{} } --func (m *CommitRequest) String() string { return proto.CompactTextString(m) } --func (*CommitRequest) ProtoMessage() {} --func (*CommitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{21} } -+func (m *CommitRequest) String() string { return "TODO" } -+ -+ - - func (m *CommitRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1491,9 +1447,9 @@ - } - - func (m *CommitResponse) Reset() { *m = CommitResponse{} } --func (m *CommitResponse) String() string { return proto.CompactTextString(m) } --func (*CommitResponse) ProtoMessage() {} --func (*CommitResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{22} } -+func (m *CommitResponse) String() string { return "TODO" } -+ -+ - - // RollbackRequest is the payload to Rollback - type RollbackRequest struct { -@@ -1504,9 +1460,9 @@ - } - - func (m *RollbackRequest) Reset() { *m = RollbackRequest{} } --func (m *RollbackRequest) String() string { return proto.CompactTextString(m) } --func (*RollbackRequest) ProtoMessage() {} --func (*RollbackRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{23} } -+func (m *RollbackRequest) String() string { return "TODO" } -+ -+ - - func (m *RollbackRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1541,9 +1497,9 @@ - } - - func (m *RollbackResponse) Reset() { *m = RollbackResponse{} } --func (m *RollbackResponse) String() string { return proto.CompactTextString(m) } --func (*RollbackResponse) ProtoMessage() {} --func (*RollbackResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{24} } -+func (m *RollbackResponse) String() string { return "TODO" } -+ -+ - - // PrepareRequest is the payload to Prepare - type PrepareRequest struct { -@@ -1555,9 +1511,9 @@ - } - - func (m *PrepareRequest) Reset() { *m = PrepareRequest{} } --func (m *PrepareRequest) String() string { return proto.CompactTextString(m) } --func (*PrepareRequest) ProtoMessage() {} --func (*PrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{25} } -+func (m *PrepareRequest) String() string { return "TODO" } -+ -+ - - func (m *PrepareRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1599,9 +1555,9 @@ - } - - func (m *PrepareResponse) Reset() { *m = PrepareResponse{} } --func (m *PrepareResponse) String() string { return proto.CompactTextString(m) } --func (*PrepareResponse) ProtoMessage() {} --func (*PrepareResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{26} } -+func (m *PrepareResponse) String() string { return "TODO" } -+ -+ - - // CommitPreparedRequest is the payload to CommitPrepared - type CommitPreparedRequest struct { -@@ -1612,9 +1568,9 @@ - } - - func (m *CommitPreparedRequest) Reset() { *m = CommitPreparedRequest{} } --func (m *CommitPreparedRequest) String() string { return proto.CompactTextString(m) } --func (*CommitPreparedRequest) ProtoMessage() {} --func (*CommitPreparedRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{27} } -+func (m *CommitPreparedRequest) String() string { return "TODO" } -+ -+ - - func (m *CommitPreparedRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1649,9 +1605,9 @@ - } - - func (m *CommitPreparedResponse) Reset() { *m = CommitPreparedResponse{} } --func (m *CommitPreparedResponse) String() string { return proto.CompactTextString(m) } --func (*CommitPreparedResponse) ProtoMessage() {} --func (*CommitPreparedResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{28} } -+func (m *CommitPreparedResponse) String() string { return "TODO" } -+ -+ - - // RollbackPreparedRequest is the payload to RollbackPrepared - type RollbackPreparedRequest struct { -@@ -1663,9 +1619,9 @@ - } - - func (m *RollbackPreparedRequest) Reset() { *m = RollbackPreparedRequest{} } --func (m *RollbackPreparedRequest) String() string { return proto.CompactTextString(m) } --func (*RollbackPreparedRequest) ProtoMessage() {} --func (*RollbackPreparedRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{29} } -+func (m *RollbackPreparedRequest) String() string { return "TODO" } -+ -+ - - func (m *RollbackPreparedRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1707,9 +1663,9 @@ - } - - func (m *RollbackPreparedResponse) Reset() { *m = RollbackPreparedResponse{} } --func (m *RollbackPreparedResponse) String() string { return proto.CompactTextString(m) } --func (*RollbackPreparedResponse) ProtoMessage() {} --func (*RollbackPreparedResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{30} } -+func (m *RollbackPreparedResponse) String() string { return "TODO" } -+ -+ - - // CreateTransactionRequest is the payload to CreateTransaction - type CreateTransactionRequest struct { -@@ -1721,9 +1677,9 @@ - } - - func (m *CreateTransactionRequest) Reset() { *m = CreateTransactionRequest{} } --func (m *CreateTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*CreateTransactionRequest) ProtoMessage() {} --func (*CreateTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{31} } -+func (m *CreateTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *CreateTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1765,9 +1721,9 @@ - } - - func (m *CreateTransactionResponse) Reset() { *m = CreateTransactionResponse{} } --func (m *CreateTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*CreateTransactionResponse) ProtoMessage() {} --func (*CreateTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{32} } -+func (m *CreateTransactionResponse) String() string { return "TODO" } -+ -+ - - // StartCommitRequest is the payload to StartCommit - type StartCommitRequest struct { -@@ -1779,9 +1735,9 @@ - } - - func (m *StartCommitRequest) Reset() { *m = StartCommitRequest{} } --func (m *StartCommitRequest) String() string { return proto.CompactTextString(m) } --func (*StartCommitRequest) ProtoMessage() {} --func (*StartCommitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{33} } -+func (m *StartCommitRequest) String() string { return "TODO" } -+ -+ - - func (m *StartCommitRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1823,9 +1779,9 @@ - } - - func (m *StartCommitResponse) Reset() { *m = StartCommitResponse{} } --func (m *StartCommitResponse) String() string { return proto.CompactTextString(m) } --func (*StartCommitResponse) ProtoMessage() {} --func (*StartCommitResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{34} } -+func (m *StartCommitResponse) String() string { return "TODO" } -+ -+ - - // SetRollbackRequest is the payload to SetRollback - type SetRollbackRequest struct { -@@ -1837,9 +1793,9 @@ - } - - func (m *SetRollbackRequest) Reset() { *m = SetRollbackRequest{} } --func (m *SetRollbackRequest) String() string { return proto.CompactTextString(m) } --func (*SetRollbackRequest) ProtoMessage() {} --func (*SetRollbackRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{35} } -+func (m *SetRollbackRequest) String() string { return "TODO" } -+ -+ - - func (m *SetRollbackRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1881,9 +1837,9 @@ - } - - func (m *SetRollbackResponse) Reset() { *m = SetRollbackResponse{} } --func (m *SetRollbackResponse) String() string { return proto.CompactTextString(m) } --func (*SetRollbackResponse) ProtoMessage() {} --func (*SetRollbackResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{36} } -+func (m *SetRollbackResponse) String() string { return "TODO" } -+ -+ - - // ConcludeTransactionRequest is the payload to ConcludeTransaction - type ConcludeTransactionRequest struct { -@@ -1894,9 +1850,9 @@ - } - - func (m *ConcludeTransactionRequest) Reset() { *m = ConcludeTransactionRequest{} } --func (m *ConcludeTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*ConcludeTransactionRequest) ProtoMessage() {} --func (*ConcludeTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{37} } -+func (m *ConcludeTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *ConcludeTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1931,9 +1887,9 @@ - } - - func (m *ConcludeTransactionResponse) Reset() { *m = ConcludeTransactionResponse{} } --func (m *ConcludeTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*ConcludeTransactionResponse) ProtoMessage() {} --func (*ConcludeTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{38} } -+func (m *ConcludeTransactionResponse) String() string { return "TODO" } -+ -+ - - // ReadTransactionRequest is the payload to ReadTransaction - type ReadTransactionRequest struct { -@@ -1944,9 +1900,9 @@ - } - - func (m *ReadTransactionRequest) Reset() { *m = ReadTransactionRequest{} } --func (m *ReadTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*ReadTransactionRequest) ProtoMessage() {} --func (*ReadTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{39} } -+func (m *ReadTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *ReadTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1982,9 +1938,9 @@ - } - - func (m *ReadTransactionResponse) Reset() { *m = ReadTransactionResponse{} } --func (m *ReadTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*ReadTransactionResponse) ProtoMessage() {} --func (*ReadTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{40} } -+func (m *ReadTransactionResponse) String() string { return "TODO" } -+ -+ - - func (m *ReadTransactionResponse) GetMetadata() *TransactionMetadata { - if m != nil { -@@ -2003,9 +1959,9 @@ - } - - func (m *BeginExecuteRequest) Reset() { *m = BeginExecuteRequest{} } --func (m *BeginExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteRequest) ProtoMessage() {} --func (*BeginExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{41} } -+func (m *BeginExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2054,9 +2010,9 @@ - } - - func (m *BeginExecuteResponse) Reset() { *m = BeginExecuteResponse{} } --func (m *BeginExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteResponse) ProtoMessage() {} --func (*BeginExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{42} } -+func (m *BeginExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteResponse) GetError() *vtrpc.RPCError { - if m != nil { -@@ -2090,9 +2046,9 @@ - } - - func (m *BeginExecuteBatchRequest) Reset() { *m = BeginExecuteBatchRequest{} } --func (m *BeginExecuteBatchRequest) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteBatchRequest) ProtoMessage() {} --func (*BeginExecuteBatchRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{43} } -+func (m *BeginExecuteBatchRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteBatchRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2148,9 +2104,9 @@ - } - - func (m *BeginExecuteBatchResponse) Reset() { *m = BeginExecuteBatchResponse{} } --func (m *BeginExecuteBatchResponse) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteBatchResponse) ProtoMessage() {} --func (*BeginExecuteBatchResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{44} } -+func (m *BeginExecuteBatchResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteBatchResponse) GetError() *vtrpc.RPCError { - if m != nil { -@@ -2183,9 +2139,9 @@ - } - - func (m *MessageStreamRequest) Reset() { *m = MessageStreamRequest{} } --func (m *MessageStreamRequest) String() string { return proto.CompactTextString(m) } --func (*MessageStreamRequest) ProtoMessage() {} --func (*MessageStreamRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{45} } -+func (m *MessageStreamRequest) String() string { return "TODO" } -+ -+ - - func (m *MessageStreamRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2221,9 +2177,9 @@ - } - - func (m *MessageStreamResponse) Reset() { *m = MessageStreamResponse{} } --func (m *MessageStreamResponse) String() string { return proto.CompactTextString(m) } --func (*MessageStreamResponse) ProtoMessage() {} --func (*MessageStreamResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{46} } -+func (m *MessageStreamResponse) String() string { return "TODO" } -+ -+ - - func (m *MessageStreamResponse) GetResult() *QueryResult { - if m != nil { -@@ -2243,9 +2199,9 @@ - } - - func (m *MessageAckRequest) Reset() { *m = MessageAckRequest{} } --func (m *MessageAckRequest) String() string { return proto.CompactTextString(m) } --func (*MessageAckRequest) ProtoMessage() {} --func (*MessageAckRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{47} } -+func (m *MessageAckRequest) String() string { return "TODO" } -+ -+ - - func (m *MessageAckRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2291,9 +2247,9 @@ - } - - func (m *MessageAckResponse) Reset() { *m = MessageAckResponse{} } --func (m *MessageAckResponse) String() string { return proto.CompactTextString(m) } --func (*MessageAckResponse) ProtoMessage() {} --func (*MessageAckResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{48} } -+func (m *MessageAckResponse) String() string { return "TODO" } -+ -+ - - func (m *MessageAckResponse) GetResult() *QueryResult { - if m != nil { -@@ -2317,9 +2273,9 @@ - } - - func (m *SplitQueryRequest) Reset() { *m = SplitQueryRequest{} } --func (m *SplitQueryRequest) String() string { return proto.CompactTextString(m) } --func (*SplitQueryRequest) ProtoMessage() {} --func (*SplitQueryRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{49} } -+func (m *SplitQueryRequest) String() string { return "TODO" } -+ -+ - - func (m *SplitQueryRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2386,9 +2342,9 @@ - } - - func (m *QuerySplit) Reset() { *m = QuerySplit{} } --func (m *QuerySplit) String() string { return proto.CompactTextString(m) } --func (*QuerySplit) ProtoMessage() {} --func (*QuerySplit) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{50} } -+func (m *QuerySplit) String() string { return "TODO" } -+ -+ - - func (m *QuerySplit) GetQuery() *BoundQuery { - if m != nil { -@@ -2411,9 +2367,9 @@ - } - - func (m *SplitQueryResponse) Reset() { *m = SplitQueryResponse{} } --func (m *SplitQueryResponse) String() string { return proto.CompactTextString(m) } --func (*SplitQueryResponse) ProtoMessage() {} --func (*SplitQueryResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{51} } -+func (m *SplitQueryResponse) String() string { return "TODO" } -+ -+ - - func (m *SplitQueryResponse) GetQueries() []*QuerySplit { - if m != nil { -@@ -2427,12 +2383,11 @@ - } - - func (m *StreamHealthRequest) Reset() { *m = StreamHealthRequest{} } --func (m *StreamHealthRequest) String() string { return proto.CompactTextString(m) } --func (*StreamHealthRequest) ProtoMessage() {} --func (*StreamHealthRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{52} } -+func (m *StreamHealthRequest) String() string { return "TODO" } -+ - --// RealtimeStats contains information about the tablet status. --// It is only valid for a single tablet. -+ -+// RealtimeStats contains information about the tablet status - type RealtimeStats struct { - // health_error is the last error we got from health check, - // or empty is the server is healthy. This is used for subset selection, -@@ -2464,9 +2419,9 @@ - } - - func (m *RealtimeStats) Reset() { *m = RealtimeStats{} } --func (m *RealtimeStats) String() string { return proto.CompactTextString(m) } --func (*RealtimeStats) ProtoMessage() {} --func (*RealtimeStats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{53} } -+func (m *RealtimeStats) String() string { return "TODO" } -+ -+ - - func (m *RealtimeStats) GetHealthError() string { - if m != nil { -@@ -2510,80 +2465,17 @@ - return 0 - } - --// AggregateStats contains information about the health of a group of --// tablets for a Target. It is used to propagate stats from a vtgate --// to another, or from the Gateway layer of a vtgate to the routing --// layer. --type AggregateStats struct { -- // healthy_tablet_count is the number of healthy tablets in the group. -- HealthyTabletCount int32 `protobuf:"varint,1,opt,name=healthy_tablet_count,json=healthyTabletCount" json:"healthy_tablet_count,omitempty"` -- // unhealthy_tablet_count is the number of unhealthy tablets in the group. -- UnhealthyTabletCount int32 `protobuf:"varint,2,opt,name=unhealthy_tablet_count,json=unhealthyTabletCount" json:"unhealthy_tablet_count,omitempty"` -- // seconds_behind_master_min is the minimum of the -- // seconds_behind_master values of the healthy tablets. It is unset -- // if the tablet type is master. -- SecondsBehindMasterMin uint32 `protobuf:"varint,3,opt,name=seconds_behind_master_min,json=secondsBehindMasterMin" json:"seconds_behind_master_min,omitempty"` -- // seconds_behind_master_max is the maximum of the -- // seconds_behind_master values of the healthy tablets. It is unset -- // if the tablet type is master. -- SecondsBehindMasterMax uint32 `protobuf:"varint,4,opt,name=seconds_behind_master_max,json=secondsBehindMasterMax" json:"seconds_behind_master_max,omitempty"` --} -- --func (m *AggregateStats) Reset() { *m = AggregateStats{} } --func (m *AggregateStats) String() string { return proto.CompactTextString(m) } --func (*AggregateStats) ProtoMessage() {} --func (*AggregateStats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{54} } -- --func (m *AggregateStats) GetHealthyTabletCount() int32 { -- if m != nil { -- return m.HealthyTabletCount -- } -- return 0 --} -- --func (m *AggregateStats) GetUnhealthyTabletCount() int32 { -- if m != nil { -- return m.UnhealthyTabletCount -- } -- return 0 --} -- --func (m *AggregateStats) GetSecondsBehindMasterMin() uint32 { -- if m != nil { -- return m.SecondsBehindMasterMin -- } -- return 0 --} -- --func (m *AggregateStats) GetSecondsBehindMasterMax() uint32 { -- if m != nil { -- return m.SecondsBehindMasterMax -- } -- return 0 --} -- --// StreamHealthResponse is streamed by StreamHealth on a regular basis. --// When StreamHealth is used between a vtgate and vttablet: --// - target describes the tablet. --// - realtime_stats is set. --// - aggregate_stats is not set. --// When StreamHealth is used between two vtgates: --// - target describes the group of tablets. --// - realtime_stats is not set. --// - aggregate_stats is set. -+// StreamHealthResponse is streamed by StreamHealth on a regular basis - type StreamHealthResponse struct { - // target is the current server type. Only queries with that exact Target -- // record will be accepted (the cell may not match, however). -+ // record will be accepted. - Target *Target `protobuf:"bytes,1,opt,name=target" json:"target,omitempty"` - // serving is true iff the tablet is serving. A tablet may not be serving - // if filtered replication is enabled on a master for instance, - // or if a replica should not be used because the keyspace is being resharded. - Serving bool `protobuf:"varint,2,opt,name=serving" json:"serving,omitempty"` -- // tablet_externally_reparented_timestamp can be interpreted as the -- // last time we knew that this tablet was the MASTER of this shard -- // (if StreamHealthResponse describes a group of tablets, between -- // two vtgates, only one master will be present in the group, and -- // this is this master's value). -+ // tablet_externally_reparented_timestamp can be interpreted as the last time -+ // we knew that this tablet was the MASTER of this shard. - // - // It is used by vtgate when determining the current MASTER of a shard. - // If vtgate sees more than one MASTER tablet, this timestamp is used -@@ -2606,12 +2498,8 @@ - // OR - // d) 0 if the vttablet was never a MASTER. - TabletExternallyReparentedTimestamp int64 `protobuf:"varint,3,opt,name=tablet_externally_reparented_timestamp,json=tabletExternallyReparentedTimestamp" json:"tablet_externally_reparented_timestamp,omitempty"` -- // realtime_stats contains information about the tablet status. -- // It is only filled in if the information is about a tablet. -+ // realtime_stats contains information about the tablet status - RealtimeStats *RealtimeStats `protobuf:"bytes,4,opt,name=realtime_stats,json=realtimeStats" json:"realtime_stats,omitempty"` -- // AggregateStats constains information about the group of tablet status. -- // It is only filled in if the information is about a group of tablets. -- AggregateStats *AggregateStats `protobuf:"bytes,6,opt,name=aggregate_stats,json=aggregateStats" json:"aggregate_stats,omitempty"` - // tablet_alias is the alias of the sending tablet. The discovery/healthcheck.go - // code uses it to verify that it's talking to the correct tablet and that it - // hasn't changed in the meantime e.g. due to tablet restarts where ports or -@@ -2620,9 +2508,9 @@ - } - - func (m *StreamHealthResponse) Reset() { *m = StreamHealthResponse{} } --func (m *StreamHealthResponse) String() string { return proto.CompactTextString(m) } --func (*StreamHealthResponse) ProtoMessage() {} --func (*StreamHealthResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{55} } -+func (m *StreamHealthResponse) String() string { return "TODO" } -+ -+ - - func (m *StreamHealthResponse) GetTarget() *Target { - if m != nil { -@@ -2652,13 +2540,6 @@ - return nil - } - --func (m *StreamHealthResponse) GetAggregateStats() *AggregateStats { -- if m != nil { -- return m.AggregateStats -- } -- return nil --} -- - func (m *StreamHealthResponse) GetTabletAlias() *topodata.TabletAlias { - if m != nil { - return m.TabletAlias -@@ -2682,9 +2563,9 @@ - } - - func (m *UpdateStreamRequest) Reset() { *m = UpdateStreamRequest{} } --func (m *UpdateStreamRequest) String() string { return proto.CompactTextString(m) } --func (*UpdateStreamRequest) ProtoMessage() {} --func (*UpdateStreamRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{56} } -+func (m *UpdateStreamRequest) String() string { return "TODO" } -+ -+ - - func (m *UpdateStreamRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2727,9 +2608,9 @@ - } - - func (m *UpdateStreamResponse) Reset() { *m = UpdateStreamResponse{} } --func (m *UpdateStreamResponse) String() string { return proto.CompactTextString(m) } --func (*UpdateStreamResponse) ProtoMessage() {} --func (*UpdateStreamResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{57} } -+func (m *UpdateStreamResponse) String() string { return "TODO" } -+ -+ - - func (m *UpdateStreamResponse) GetEvent() *StreamEvent { - if m != nil { -@@ -2747,9 +2628,9 @@ - } - - func (m *TransactionMetadata) Reset() { *m = TransactionMetadata{} } --func (m *TransactionMetadata) String() string { return proto.CompactTextString(m) } --func (*TransactionMetadata) ProtoMessage() {} --func (*TransactionMetadata) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{58} } -+func (m *TransactionMetadata) String() string { return "TODO" } -+ -+ - - func (m *TransactionMetadata) GetDtid() string { - if m != nil { -@@ -2835,7 +2716,6 @@ - proto.RegisterType((*SplitQueryResponse)(nil), "query.SplitQueryResponse") - proto.RegisterType((*StreamHealthRequest)(nil), "query.StreamHealthRequest") - proto.RegisterType((*RealtimeStats)(nil), "query.RealtimeStats") -- proto.RegisterType((*AggregateStats)(nil), "query.AggregateStats") - proto.RegisterType((*StreamHealthResponse)(nil), "query.StreamHealthResponse") - proto.RegisterType((*UpdateStreamRequest)(nil), "query.UpdateStreamRequest") - proto.RegisterType((*UpdateStreamResponse)(nil), "query.UpdateStreamResponse") -@@ -2851,207 +2731,4 @@ - proto.RegisterEnum("query.SplitQueryRequest_Algorithm", SplitQueryRequest_Algorithm_name, SplitQueryRequest_Algorithm_value) - } - --func init() { proto.RegisterFile("query.proto", fileDescriptor0) } -- --var fileDescriptor0 = []byte{ -- // 3183 bytes of a gzipped FileDescriptorProto -- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x5a, 0xcb, 0x73, 0x1b, 0xc7, -- 0x99, 0xd7, 0xe0, 0x41, 0x02, 0x1f, 0x08, 0xb0, 0xd9, 0x20, 0x25, 0x88, 0xf2, 0x83, 0x3b, 0xb6, -- 0x6c, 0x2e, 0xed, 0xe5, 0xca, 0x94, 0x56, 0xab, 0xb5, 0x77, 0xbd, 0x1a, 0x82, 0x43, 0x19, 0x16, -- 0x5e, 0x6a, 0x0c, 0x24, 0xcb, 0xe5, 0xaa, 0xa9, 0x21, 0xd0, 0x02, 0xa7, 0x38, 0xc0, 0x40, 0x33, -- 0x03, 0x51, 0xbc, 0x69, 0xd7, 0x71, 0xde, 0x0f, 0xe7, 0xe9, 0x38, 0xa9, 0x38, 0xa9, 0xca, 0x3d, -- 0x7f, 0x43, 0x2a, 0x7f, 0x40, 0x6e, 0x39, 0x24, 0x39, 0xe4, 0x90, 0x4a, 0xe5, 0x90, 0x2a, 0x57, -- 0x4e, 0x39, 0xe4, 0x90, 0x4a, 0xf5, 0x63, 0x06, 0x03, 0x12, 0x7a, 0x58, 0xc9, 0x85, 0xb2, 0x4f, -- 0xe8, 0xfe, 0xbe, 0xaf, 0x1f, 0xbf, 0xdf, 0xf7, 0xcd, 0xd7, 0x8d, 0xee, 0x86, 0xdc, 0xed, 0x11, -- 0xf5, 0x0e, 0xd6, 0x87, 0x9e, 0x1b, 0xb8, 0x38, 0xcd, 0x2b, 0xcb, 0x85, 0xc0, 0x1d, 0xba, 0x5d, -- 0x2b, 0xb0, 0x84, 0x78, 0x39, 0x77, 0x27, 0xf0, 0x86, 0x1d, 0x51, 0x51, 0xdf, 0x53, 0x60, 0xc6, -- 0xb0, 0xbc, 0x1e, 0x0d, 0xf0, 0x32, 0x64, 0xf6, 0xe8, 0x81, 0x3f, 0xb4, 0x3a, 0xb4, 0xa4, 0xac, -- 0x28, 0xab, 0x59, 0x12, 0xd5, 0xf1, 0x22, 0xa4, 0xfd, 0x5d, 0xcb, 0xeb, 0x96, 0x12, 0x5c, 0x21, -- 0x2a, 0xf8, 0x3f, 0x20, 0x17, 0x58, 0x3b, 0x0e, 0x0d, 0xcc, 0xe0, 0x60, 0x48, 0x4b, 0xc9, 0x15, -- 0x65, 0xb5, 0xb0, 0xb1, 0xb8, 0x1e, 0x8d, 0x67, 0x70, 0xa5, 0x71, 0x30, 0xa4, 0x04, 0x82, 0xa8, -- 0x8c, 0x31, 0xa4, 0x3a, 0xd4, 0x71, 0x4a, 0x29, 0xde, 0x17, 0x2f, 0xab, 0x5b, 0x50, 0xb8, 0x6e, -- 0x5c, 0xb1, 0x02, 0x5a, 0xb6, 0x1c, 0x87, 0x7a, 0x95, 0x2d, 0x36, 0x9d, 0x91, 0x4f, 0xbd, 0x81, -- 0xd5, 0x8f, 0xa6, 0x13, 0xd6, 0xf1, 0x49, 0x98, 0xe9, 0x79, 0xee, 0x68, 0xe8, 0x97, 0x12, 0x2b, -- 0xc9, 0xd5, 0x2c, 0x91, 0x35, 0xf5, 0x1d, 0x00, 0xfd, 0x0e, 0x1d, 0x04, 0x86, 0xbb, 0x47, 0x07, -- 0xf8, 0x29, 0xc8, 0x06, 0x76, 0x9f, 0xfa, 0x81, 0xd5, 0x1f, 0xf2, 0x2e, 0x92, 0x64, 0x2c, 0xb8, -- 0x0f, 0xa4, 0x65, 0xc8, 0x0c, 0x5d, 0xdf, 0x0e, 0x6c, 0x77, 0xc0, 0xf1, 0x64, 0x49, 0x54, 0x57, -- 0x5f, 0x87, 0xf4, 0x75, 0xcb, 0x19, 0x51, 0xfc, 0x2c, 0xa4, 0x38, 0x60, 0x85, 0x03, 0xce, 0xad, -- 0x0b, 0xd2, 0x39, 0x4e, 0xae, 0x60, 0x7d, 0xdf, 0x61, 0x96, 0xbc, 0xef, 0x39, 0x22, 0x2a, 0xea, -- 0x1e, 0xcc, 0x6d, 0xda, 0x83, 0xee, 0x75, 0xcb, 0xb3, 0x19, 0x19, 0x8f, 0xd9, 0x0d, 0x7e, 0x1e, -- 0x66, 0x78, 0xc1, 0x2f, 0x25, 0x57, 0x92, 0xab, 0xb9, 0x8d, 0x39, 0xd9, 0x90, 0xcf, 0x8d, 0x48, -- 0x9d, 0xfa, 0x0b, 0x05, 0x60, 0xd3, 0x1d, 0x0d, 0xba, 0xd7, 0x98, 0x12, 0x23, 0x48, 0xfa, 0xb7, -- 0x1d, 0x49, 0x24, 0x2b, 0xe2, 0xab, 0x50, 0xd8, 0xb1, 0x07, 0x5d, 0xf3, 0x8e, 0x9c, 0x8e, 0xe0, -- 0x32, 0xb7, 0xf1, 0xbc, 0xec, 0x6e, 0xdc, 0x78, 0x3d, 0x3e, 0x6b, 0x5f, 0x1f, 0x04, 0xde, 0x01, -- 0xc9, 0xef, 0xc4, 0x65, 0xcb, 0x6d, 0xc0, 0x47, 0x8d, 0xd8, 0xa0, 0x7b, 0xf4, 0x20, 0x1c, 0x74, -- 0x8f, 0x1e, 0xe0, 0x7f, 0x8d, 0x23, 0xca, 0x6d, 0x14, 0xc3, 0xb1, 0x62, 0x6d, 0x25, 0xcc, 0x57, -- 0x13, 0x97, 0x14, 0xf5, 0x4f, 0x69, 0x28, 0xe8, 0x77, 0x69, 0x67, 0x14, 0xd0, 0xc6, 0x90, 0xf9, -- 0xc0, 0xc7, 0xeb, 0x50, 0xb4, 0x07, 0x1d, 0x67, 0xd4, 0xa5, 0x26, 0x65, 0xae, 0x36, 0x03, 0xe6, -- 0x6b, 0xde, 0x5f, 0x86, 0x2c, 0x48, 0x55, 0x2c, 0x08, 0x34, 0x28, 0x76, 0xdc, 0xfe, 0xd0, 0xf2, -- 0x26, 0xed, 0x93, 0x7c, 0xfc, 0x05, 0x39, 0xfe, 0xd8, 0x9e, 0x2c, 0x48, 0xeb, 0x58, 0x17, 0x35, -- 0x98, 0x97, 0xfd, 0x76, 0xcd, 0x5b, 0x36, 0x75, 0xba, 0x3e, 0x0f, 0xdd, 0x42, 0x44, 0xd5, 0xe4, -- 0x14, 0xd7, 0x2b, 0xd2, 0x78, 0x9b, 0xdb, 0x92, 0x82, 0x3d, 0x51, 0xc7, 0x6b, 0xb0, 0xd0, 0x71, -- 0x6c, 0x36, 0x95, 0x5b, 0x8c, 0x62, 0xd3, 0x73, 0xf7, 0xfd, 0x52, 0x9a, 0xcf, 0x7f, 0x5e, 0x28, -- 0xb6, 0x99, 0x9c, 0xb8, 0xfb, 0x3e, 0x7e, 0x15, 0x32, 0xfb, 0xae, 0xb7, 0xe7, 0xb8, 0x56, 0xb7, -- 0x34, 0xc3, 0xc7, 0x7c, 0x66, 0xfa, 0x98, 0x37, 0xa4, 0x15, 0x89, 0xec, 0xf1, 0x2a, 0x20, 0xff, -- 0xb6, 0x63, 0xfa, 0xd4, 0xa1, 0x9d, 0xc0, 0x74, 0xec, 0xbe, 0x1d, 0x94, 0x32, 0xfc, 0x2b, 0x28, -- 0xf8, 0xb7, 0x9d, 0x16, 0x17, 0x57, 0x99, 0x14, 0x9b, 0xb0, 0x14, 0x78, 0xd6, 0xc0, 0xb7, 0x3a, -- 0xac, 0x33, 0xd3, 0xf6, 0x5d, 0xc7, 0xe2, 0x5f, 0x40, 0x96, 0x0f, 0xb9, 0x36, 0x7d, 0x48, 0x63, -- 0xdc, 0xa4, 0x12, 0xb6, 0x20, 0x8b, 0xc1, 0x14, 0x29, 0x7e, 0x05, 0x96, 0xfc, 0x3d, 0x7b, 0x68, -- 0xf2, 0x7e, 0xcc, 0xa1, 0x63, 0x0d, 0xcc, 0x8e, 0xd5, 0xd9, 0xa5, 0x25, 0xe0, 0xb0, 0x31, 0x53, -- 0xf2, 0x50, 0x6b, 0x3a, 0xd6, 0xa0, 0xcc, 0x34, 0xea, 0x6b, 0x50, 0x98, 0xe4, 0x11, 0x2f, 0x40, -- 0xde, 0xb8, 0xd9, 0xd4, 0x4d, 0xad, 0xbe, 0x65, 0xd6, 0xb5, 0x9a, 0x8e, 0x4e, 0xe0, 0x3c, 0x64, -- 0xb9, 0xa8, 0x51, 0xaf, 0xde, 0x44, 0x0a, 0x9e, 0x85, 0xa4, 0x56, 0xad, 0xa2, 0x84, 0x7a, 0x09, -- 0x32, 0x21, 0x21, 0x78, 0x1e, 0x72, 0xed, 0x7a, 0xab, 0xa9, 0x97, 0x2b, 0xdb, 0x15, 0x7d, 0x0b, -- 0x9d, 0xc0, 0x19, 0x48, 0x35, 0xaa, 0x46, 0x13, 0x29, 0xa2, 0xa4, 0x35, 0x51, 0x82, 0xb5, 0xdc, -- 0xda, 0xd4, 0x50, 0x52, 0x0d, 0x60, 0x71, 0x1a, 0x2e, 0x9c, 0x83, 0xd9, 0x2d, 0x7d, 0x5b, 0x6b, -- 0x57, 0x0d, 0x74, 0x02, 0x17, 0x61, 0x9e, 0xe8, 0x4d, 0x5d, 0x33, 0xb4, 0xcd, 0xaa, 0x6e, 0x12, -- 0x5d, 0xdb, 0x42, 0x0a, 0xc6, 0x50, 0x60, 0x25, 0xb3, 0xdc, 0xa8, 0xd5, 0x2a, 0x86, 0xa1, 0x6f, -- 0xa1, 0x04, 0x5e, 0x04, 0xc4, 0x65, 0xed, 0xfa, 0x58, 0x9a, 0xc4, 0x08, 0xe6, 0x5a, 0x3a, 0xa9, -- 0x68, 0xd5, 0xca, 0xdb, 0xac, 0x03, 0x94, 0x7a, 0x33, 0x95, 0x51, 0x50, 0x42, 0xfd, 0x20, 0x01, -- 0x69, 0x8e, 0x95, 0x65, 0xc8, 0x58, 0xde, 0xe3, 0xe5, 0x28, 0x5b, 0x24, 0x1e, 0x90, 0x2d, 0x78, -- 0x92, 0x95, 0x79, 0x4b, 0x54, 0xf0, 0x19, 0xc8, 0xba, 0x5e, 0xcf, 0x14, 0x1a, 0x91, 0x71, 0x33, -- 0xae, 0xd7, 0xe3, 0xa9, 0x99, 0x65, 0x3b, 0x96, 0xa8, 0x77, 0x2c, 0x9f, 0xf2, 0x08, 0xcc, 0x92, -- 0xa8, 0x8e, 0x4f, 0x03, 0xb3, 0x33, 0xf9, 0x3c, 0x66, 0xb8, 0x6e, 0xd6, 0xf5, 0x7a, 0x75, 0x36, -- 0x95, 0xe7, 0x20, 0xdf, 0x71, 0x9d, 0x51, 0x7f, 0x60, 0x3a, 0x74, 0xd0, 0x0b, 0x76, 0x4b, 0xb3, -- 0x2b, 0xca, 0x6a, 0x9e, 0xcc, 0x09, 0x61, 0x95, 0xcb, 0x70, 0x09, 0x66, 0x3b, 0xbb, 0x96, 0xe7, -- 0x53, 0x11, 0x75, 0x79, 0x12, 0x56, 0xf9, 0xa8, 0xb4, 0x63, 0xf7, 0x2d, 0xc7, 0xe7, 0x11, 0x96, -- 0x27, 0x51, 0x9d, 0x81, 0xb8, 0xe5, 0x58, 0x3d, 0x9f, 0x47, 0x46, 0x9e, 0x88, 0x8a, 0xfa, 0x9f, -- 0x90, 0x24, 0xee, 0x3e, 0xeb, 0x52, 0x0c, 0xe8, 0x97, 0x94, 0x95, 0xe4, 0x2a, 0x26, 0x61, 0x95, -- 0x2d, 0x08, 0x32, 0x27, 0x8a, 0x54, 0x19, 0x66, 0xc1, 0x77, 0x60, 0x8e, 0x50, 0x7f, 0xe4, 0x04, -- 0xfa, 0xdd, 0xc0, 0xb3, 0x7c, 0xbc, 0x01, 0xb9, 0x78, 0x16, 0x50, 0xee, 0x97, 0x05, 0x80, 0x8e, -- 0x3f, 0xff, 0x12, 0xcc, 0xde, 0xf2, 0xa8, 0xbf, 0x4b, 0x3d, 0x99, 0x65, 0xc2, 0x2a, 0xcb, 0xb1, -- 0x39, 0x1e, 0xb6, 0x62, 0x0c, 0x96, 0x99, 0x65, 0x7e, 0x50, 0x26, 0x32, 0x33, 0x77, 0x2a, 0x91, -- 0x3a, 0xc6, 0x1e, 0xfb, 0xe4, 0x4d, 0xeb, 0xd6, 0x2d, 0xda, 0x09, 0xa8, 0x58, 0x80, 0x52, 0x64, -- 0x8e, 0x09, 0x35, 0x29, 0x63, 0x6e, 0xb3, 0x07, 0x3e, 0xf5, 0x02, 0xd3, 0xee, 0x72, 0x87, 0xa6, -- 0x48, 0x46, 0x08, 0x2a, 0x5d, 0xfc, 0x0c, 0xa4, 0x78, 0xd2, 0x48, 0xf1, 0x51, 0x40, 0x8e, 0x42, -- 0xdc, 0x7d, 0xc2, 0xe5, 0xf8, 0x25, 0x98, 0xa1, 0x1c, 0x2f, 0x77, 0xea, 0x38, 0xcd, 0xc6, 0xa9, -- 0x20, 0xd2, 0x44, 0xfd, 0x49, 0x12, 0x72, 0xad, 0xc0, 0xa3, 0x56, 0x9f, 0xe3, 0xc7, 0xff, 0x0d, -- 0xe0, 0x07, 0x56, 0x40, 0xfb, 0x74, 0x10, 0x84, 0x40, 0x9e, 0x92, 0x1d, 0xc4, 0xec, 0xd6, 0x5b, -- 0xa1, 0x11, 0x89, 0xd9, 0x1f, 0x26, 0x38, 0xf1, 0x08, 0x04, 0x2f, 0x7f, 0x94, 0x80, 0x6c, 0xd4, -- 0x1b, 0xd6, 0x20, 0xd3, 0xb1, 0x02, 0xda, 0x73, 0xbd, 0x03, 0xb9, 0x32, 0x9e, 0x7d, 0xd0, 0xe8, -- 0xeb, 0x65, 0x69, 0x4c, 0xa2, 0x66, 0xf8, 0x69, 0x10, 0xdb, 0x0d, 0x11, 0xbc, 0x62, 0x7d, 0xcf, -- 0x72, 0x09, 0x0f, 0xdf, 0x57, 0x01, 0x0f, 0x3d, 0xbb, 0x6f, 0x79, 0x07, 0xe6, 0x1e, 0x3d, 0x08, -- 0x53, 0x7a, 0x72, 0x8a, 0xcb, 0x90, 0xb4, 0xbb, 0x4a, 0x0f, 0x64, 0x12, 0xba, 0x34, 0xd9, 0x56, -- 0x06, 0xdd, 0x51, 0x47, 0xc4, 0x5a, 0xf2, 0x75, 0xd9, 0x0f, 0x57, 0xe0, 0x34, 0x8f, 0x4f, 0x56, -- 0x54, 0x5f, 0x84, 0x4c, 0x38, 0x79, 0x9c, 0x85, 0xb4, 0xee, 0x79, 0xae, 0x87, 0x4e, 0xf0, 0x5c, -- 0x54, 0xab, 0x8a, 0x74, 0xb6, 0xb5, 0xc5, 0xd2, 0xd9, 0xcf, 0x13, 0xd1, 0x32, 0x48, 0xe8, 0xed, -- 0x11, 0xf5, 0x03, 0xfc, 0xbf, 0x50, 0xa4, 0x3c, 0x56, 0xec, 0x3b, 0xd4, 0xec, 0xf0, 0x3d, 0x13, -- 0x8b, 0x14, 0x11, 0xd0, 0xf3, 0xeb, 0x62, 0x8b, 0x17, 0xee, 0xa5, 0xc8, 0x42, 0x64, 0x2b, 0x45, -- 0x5d, 0xac, 0x43, 0xd1, 0xee, 0xf7, 0x69, 0xd7, 0xb6, 0x82, 0x78, 0x07, 0xc2, 0x61, 0x4b, 0xe1, -- 0x96, 0x62, 0x62, 0x4b, 0x46, 0x16, 0xa2, 0x16, 0x51, 0x37, 0x67, 0x61, 0x26, 0xe0, 0xdb, 0x47, -- 0xb9, 0xa2, 0xe6, 0xc3, 0xbc, 0xc4, 0x85, 0x44, 0x2a, 0xf1, 0x8b, 0x20, 0x36, 0xa3, 0x3c, 0x03, -- 0x8d, 0x03, 0x62, 0xbc, 0xc7, 0x20, 0x42, 0x8f, 0xcf, 0x42, 0x61, 0x62, 0x29, 0xea, 0x72, 0xc2, -- 0x92, 0x24, 0x1f, 0x5f, 0x57, 0xba, 0xf8, 0xdf, 0x61, 0xd6, 0x15, 0xcb, 0x10, 0xcf, 0x4d, 0xe3, -- 0x19, 0x4f, 0xae, 0x51, 0x24, 0xb4, 0x52, 0xff, 0x07, 0xe6, 0x23, 0x06, 0xfd, 0xa1, 0x3b, 0xf0, -- 0x29, 0x5e, 0x83, 0x19, 0x8f, 0x7f, 0x10, 0x92, 0x35, 0x2c, 0xbb, 0x88, 0x7d, 0xd1, 0x44, 0x5a, -- 0xa8, 0x5d, 0x98, 0x17, 0x92, 0x1b, 0x76, 0xb0, 0xcb, 0x1d, 0x85, 0xcf, 0x42, 0x9a, 0xb2, 0xc2, -- 0x21, 0xce, 0x49, 0xb3, 0xcc, 0xf5, 0x44, 0x68, 0x63, 0xa3, 0x24, 0x1e, 0x3a, 0xca, 0x9f, 0x13, -- 0x50, 0x94, 0xb3, 0xdc, 0xb4, 0x82, 0xce, 0xee, 0x31, 0x75, 0xf6, 0x4b, 0x30, 0xcb, 0xe4, 0x76, -- 0xf4, 0x61, 0x4c, 0x71, 0x77, 0x68, 0xc1, 0x1c, 0x6e, 0xf9, 0x66, 0xcc, 0xbb, 0x72, 0x2b, 0x94, -- 0xb7, 0xfc, 0xd8, 0x42, 0x3c, 0x25, 0x2e, 0x66, 0x1e, 0x12, 0x17, 0xb3, 0x8f, 0x14, 0x17, 0x5b, -- 0xb0, 0x38, 0xc9, 0xb8, 0x0c, 0x8e, 0x97, 0x61, 0x56, 0x38, 0x25, 0x4c, 0x81, 0xd3, 0xfc, 0x16, -- 0x9a, 0xa8, 0x3f, 0x4e, 0xc0, 0xa2, 0xcc, 0x4e, 0x9f, 0x8e, 0xcf, 0x34, 0xc6, 0x73, 0xfa, 0x91, -- 0x78, 0x2e, 0xc3, 0xd2, 0x21, 0x82, 0x1e, 0xe3, 0x2b, 0xfc, 0x58, 0x81, 0xb9, 0x4d, 0xda, 0xb3, -- 0x07, 0xc7, 0x94, 0xde, 0x18, 0x6b, 0xa9, 0x47, 0x62, 0xed, 0x22, 0xe4, 0x25, 0x5e, 0xc9, 0xd6, -- 0xd1, 0xcf, 0x40, 0x99, 0xf2, 0x19, 0xa8, 0x7f, 0x50, 0x20, 0x5f, 0x76, 0xfb, 0x7d, 0x3b, 0x38, -- 0xa6, 0x4c, 0x1d, 0xc5, 0x99, 0x9a, 0x86, 0x13, 0x41, 0x21, 0x84, 0x29, 0x08, 0x52, 0xff, 0xa8, -- 0xc0, 0x3c, 0x71, 0x1d, 0x67, 0xc7, 0xea, 0xec, 0x3d, 0xd9, 0xd8, 0x31, 0xa0, 0x31, 0x50, 0x89, -- 0xfe, 0xaf, 0x0a, 0x14, 0x9a, 0x1e, 0x65, 0xff, 0x5f, 0x9f, 0x68, 0xf0, 0xec, 0x0f, 0x52, 0x37, -- 0x90, 0x9b, 0x83, 0x2c, 0xe1, 0x65, 0x75, 0x01, 0xe6, 0x23, 0xec, 0x92, 0x8f, 0xdf, 0x28, 0xb0, -- 0x24, 0x02, 0x44, 0x6a, 0xba, 0xc7, 0x94, 0x96, 0x10, 0x6f, 0x2a, 0x86, 0xb7, 0x04, 0x27, 0x0f, -- 0x63, 0x93, 0xb0, 0xdf, 0x4d, 0xc0, 0xa9, 0x30, 0x36, 0x8e, 0x39, 0xf0, 0x7f, 0x20, 0x1e, 0x96, -- 0xa1, 0x74, 0x94, 0x04, 0xc9, 0xd0, 0xfb, 0x09, 0x28, 0x95, 0x3d, 0x6a, 0x05, 0x34, 0xb6, 0xc9, -- 0x78, 0x72, 0x62, 0x03, 0xbf, 0x02, 0x73, 0x43, 0xcb, 0x0b, 0xec, 0x8e, 0x3d, 0xb4, 0xd8, 0xdf, -- 0xb8, 0x34, 0xdf, 0xc3, 0x1c, 0xea, 0x60, 0xc2, 0x44, 0x3d, 0x03, 0xa7, 0xa7, 0x30, 0x22, 0xf9, -- 0xfa, 0x9b, 0x02, 0xb8, 0x15, 0x58, 0x5e, 0xf0, 0x29, 0x58, 0x55, 0xa6, 0x06, 0xd3, 0x12, 0x14, -- 0x27, 0xf0, 0xc7, 0x79, 0xa1, 0xc1, 0xa7, 0x62, 0xc5, 0xb9, 0x2f, 0x2f, 0x71, 0xfc, 0x92, 0x97, -- 0xdf, 0x29, 0xb0, 0x5c, 0x76, 0xc5, 0xf9, 0xdd, 0x13, 0xf9, 0x85, 0xa9, 0x4f, 0xc3, 0x99, 0xa9, -- 0x00, 0x25, 0x01, 0xbf, 0x55, 0xe0, 0x24, 0xa1, 0x56, 0xf7, 0xc9, 0x04, 0x7f, 0x0d, 0x4e, 0x1d, -- 0x01, 0x27, 0x77, 0xa8, 0x17, 0x21, 0xd3, 0xa7, 0x81, 0xd5, 0xb5, 0x02, 0x4b, 0x42, 0x5a, 0x0e, -- 0xfb, 0x1d, 0x5b, 0xd7, 0xa4, 0x05, 0x89, 0x6c, 0xd5, 0x8f, 0x12, 0x50, 0xe4, 0x7b, 0xdd, 0xcf, -- 0xfe, 0x41, 0x4d, 0xff, 0x2f, 0xf0, 0xbe, 0x02, 0x8b, 0x93, 0x04, 0x45, 0xff, 0x09, 0xfe, 0xd9, -- 0x07, 0x11, 0x53, 0x12, 0x42, 0x72, 0xda, 0x16, 0xf4, 0x97, 0x09, 0x28, 0xc5, 0xa7, 0xf4, 0xd9, -- 0xa1, 0xc5, 0xe4, 0xa1, 0xc5, 0x27, 0x3e, 0xa5, 0xfa, 0x40, 0x81, 0xd3, 0x53, 0x08, 0xfd, 0x64, -- 0x8e, 0x8e, 0x1d, 0x5d, 0x24, 0x1e, 0x7a, 0x74, 0xf1, 0xa8, 0xae, 0xfe, 0xb5, 0x02, 0x8b, 0x35, -- 0xea, 0xfb, 0x56, 0x8f, 0x8a, 0xff, 0xf1, 0xc7, 0x37, 0x9b, 0xf1, 0x43, 0xe1, 0xd4, 0xf8, 0x66, -- 0x45, 0x2d, 0xc3, 0xd2, 0x21, 0x68, 0x8f, 0x71, 0x36, 0xf1, 0x17, 0x05, 0x16, 0x64, 0x2f, 0xda, -- 0xb1, 0xdd, 0x08, 0x4c, 0x61, 0x07, 0x3f, 0x03, 0x49, 0xbb, 0x1b, 0xee, 0x20, 0x27, 0xef, 0x9a, -- 0x99, 0x42, 0xbd, 0x0c, 0x38, 0x8e, 0xfb, 0x31, 0xa8, 0xfb, 0x55, 0x12, 0x16, 0x5a, 0x43, 0xc7, -- 0x0e, 0xa4, 0xf2, 0xc9, 0x4e, 0xfc, 0xff, 0x02, 0x73, 0x3e, 0x03, 0x6b, 0x8a, 0xdb, 0x32, 0x4e, -- 0x6c, 0x96, 0xe4, 0xb8, 0xac, 0xcc, 0x45, 0xf8, 0x59, 0xc8, 0x85, 0x26, 0xa3, 0x41, 0x20, 0x4f, -- 0x3a, 0x41, 0x5a, 0x8c, 0x06, 0x01, 0xbe, 0x00, 0xa7, 0x06, 0xa3, 0x3e, 0xbf, 0x39, 0x36, 0x87, -- 0xd4, 0x0b, 0xef, 0x55, 0x2d, 0x2f, 0xbc, 0xe1, 0x2d, 0x0e, 0x46, 0x7d, 0xe2, 0xee, 0xfb, 0x4d, -- 0xea, 0x89, 0x7b, 0x55, 0xcb, 0x0b, 0xf0, 0x65, 0xc8, 0x5a, 0x4e, 0xcf, 0xf5, 0xec, 0x60, 0xb7, -- 0x2f, 0xaf, 0x76, 0xd5, 0xf0, 0x6a, 0xe5, 0x30, 0xfd, 0xeb, 0x5a, 0x68, 0x49, 0xc6, 0x8d, 0xd4, -- 0x97, 0x21, 0x1b, 0xc9, 0x31, 0x82, 0x39, 0xfd, 0x5a, 0x5b, 0xab, 0x9a, 0xad, 0x66, 0xb5, 0x62, -- 0xb4, 0xc4, 0x75, 0xec, 0x76, 0xbb, 0x5a, 0x35, 0x5b, 0x65, 0xad, 0x8e, 0x14, 0x95, 0x00, 0xf0, -- 0x2e, 0x79, 0xe7, 0x63, 0x82, 0x94, 0x87, 0x10, 0x74, 0x06, 0xb2, 0x9e, 0xbb, 0x2f, 0xb1, 0x27, -- 0x38, 0x9c, 0x8c, 0xe7, 0xee, 0x73, 0xe4, 0xaa, 0x06, 0x38, 0x3e, 0x57, 0x19, 0x6d, 0xb1, 0xe4, -- 0xad, 0x4c, 0x24, 0xef, 0xf1, 0xf8, 0x51, 0xf2, 0x16, 0x5b, 0x79, 0xf6, 0x9d, 0xbf, 0x41, 0x2d, -- 0x27, 0x08, 0xd7, 0x2b, 0xf5, 0xa7, 0x09, 0xc8, 0x13, 0x26, 0xb1, 0xfb, 0xb4, 0x15, 0x58, 0x81, -- 0xcf, 0x3c, 0xb5, 0xcb, 0x4d, 0xcc, 0x71, 0xda, 0xcd, 0x92, 0x9c, 0x90, 0x89, 0x4b, 0x80, 0x0d, -- 0x58, 0xf2, 0x69, 0xc7, 0x1d, 0x74, 0x7d, 0x73, 0x87, 0xee, 0xda, 0x83, 0xae, 0xd9, 0xb7, 0xfc, -- 0x40, 0xde, 0x14, 0xe6, 0x49, 0x51, 0x2a, 0x37, 0xb9, 0xae, 0xc6, 0x55, 0xf8, 0x1c, 0x2c, 0xee, -- 0xd8, 0x03, 0xc7, 0xed, 0x99, 0x43, 0xc7, 0x3a, 0xa0, 0x9e, 0x2f, 0xa1, 0xb2, 0xf0, 0x4a, 0x13, -- 0x2c, 0x74, 0x4d, 0xa1, 0x12, 0xee, 0x7e, 0x1b, 0xd6, 0xa6, 0x8e, 0x62, 0xde, 0xb2, 0x9d, 0x80, -- 0x7a, 0xb4, 0x6b, 0x7a, 0x74, 0xe8, 0xd8, 0x1d, 0x71, 0x69, 0x2f, 0xf6, 0xee, 0x2f, 0x4c, 0x19, -- 0x7a, 0x5b, 0x9a, 0x93, 0xb1, 0x35, 0x63, 0xbb, 0x33, 0x1c, 0x99, 0x23, 0xf6, 0x01, 0xf3, 0x55, -- 0x4c, 0x21, 0x99, 0xce, 0x70, 0xd4, 0x66, 0x75, 0x8c, 0x20, 0x79, 0x7b, 0x28, 0x16, 0x2f, 0x85, -- 0xb0, 0xa2, 0xfa, 0xb1, 0x02, 0x05, 0xad, 0xd7, 0xf3, 0x68, 0xcf, 0x0a, 0x24, 0x4d, 0xe7, 0x60, -- 0x51, 0x50, 0x72, 0x60, 0xca, 0xd7, 0x40, 0x02, 0x8f, 0x22, 0xf0, 0x48, 0x9d, 0x78, 0x0b, 0x14, -- 0x86, 0xef, 0xc9, 0xd1, 0x60, 0x6a, 0x9b, 0x04, 0x6f, 0xb3, 0x18, 0x69, 0xe3, 0xad, 0xfe, 0x0b, -- 0x4e, 0x4f, 0x67, 0xa1, 0x6f, 0x8b, 0xf7, 0x1c, 0x79, 0x72, 0x72, 0x0a, 0xe8, 0x9a, 0x3d, 0x78, -- 0x40, 0x53, 0xeb, 0x2e, 0xe7, 0xeb, 0x3e, 0x4d, 0xad, 0xbb, 0xea, 0xef, 0xa3, 0xa3, 0xfd, 0x30, -- 0x5c, 0xa2, 0xd5, 0x38, 0xcc, 0x0b, 0xca, 0x83, 0xf2, 0x42, 0x09, 0x66, 0x7d, 0xea, 0xdd, 0xb1, -- 0x07, 0xbd, 0xf0, 0xf6, 0x58, 0x56, 0x71, 0x0b, 0x5e, 0x90, 0xd8, 0xe9, 0xdd, 0x80, 0x7a, 0x03, -- 0xcb, 0x71, 0x0e, 0x4c, 0x71, 0x50, 0x31, 0x08, 0x68, 0xd7, 0x1c, 0xbf, 0x5d, 0x12, 0x2b, 0xf2, -- 0x73, 0xc2, 0x5a, 0x8f, 0x8c, 0x49, 0x64, 0x6b, 0x44, 0xaf, 0x9a, 0x5e, 0x83, 0x82, 0x27, 0x83, -- 0xd8, 0xf4, 0x99, 0x7b, 0x64, 0x3e, 0x5a, 0x8c, 0xae, 0x80, 0x63, 0x11, 0x4e, 0xf2, 0xde, 0x44, -- 0xc0, 0xbf, 0x0e, 0xf3, 0x56, 0xe8, 0x5b, 0xd9, 0x7a, 0x72, 0xdf, 0x32, 0xe9, 0x79, 0x52, 0xb0, -- 0x26, 0x23, 0xe1, 0x12, 0xcc, 0x49, 0x44, 0x96, 0x63, 0x5b, 0xe3, 0x8d, 0xed, 0xa1, 0x07, 0x61, -- 0x1a, 0x53, 0x12, 0xf9, 0x74, 0x8c, 0x57, 0xd8, 0xff, 0xe8, 0x62, 0x7b, 0xd8, 0xe5, 0x3d, 0x1d, -- 0xe3, 0xdd, 0x45, 0xfc, 0xf5, 0x58, 0x6a, 0xf2, 0xf5, 0xd8, 0xe4, 0x6b, 0xb4, 0xf4, 0xa1, 0xd7, -- 0x68, 0xea, 0x65, 0x58, 0x9c, 0xc4, 0x2f, 0xa3, 0x6c, 0x15, 0xd2, 0xfc, 0xa6, 0xfc, 0xd0, 0x32, -- 0x1a, 0xbb, 0x0a, 0x27, 0xc2, 0x40, 0xfd, 0x99, 0x02, 0xc5, 0x29, 0x7f, 0xb1, 0xa2, 0xff, 0x6f, -- 0x4a, 0xec, 0x78, 0xe8, 0xdf, 0x20, 0xcd, 0xef, 0xec, 0xe5, 0x63, 0x92, 0x53, 0x47, 0xff, 0xa1, -- 0xf1, 0xfb, 0x75, 0x22, 0xac, 0x58, 0x22, 0xe4, 0x01, 0xd5, 0xe1, 0xe7, 0x43, 0xe1, 0x0e, 0x31, -- 0xc7, 0x64, 0xe2, 0xc8, 0xe8, 0xe8, 0x81, 0x53, 0xea, 0xa1, 0x07, 0x4e, 0x6b, 0xdf, 0x4a, 0x42, -- 0xb6, 0x76, 0xd0, 0xba, 0xed, 0x6c, 0x3b, 0x56, 0x8f, 0x5f, 0x80, 0xd7, 0x9a, 0xc6, 0x4d, 0x74, -- 0x02, 0x2f, 0x40, 0xbe, 0xde, 0x30, 0xcc, 0x3a, 0x5b, 0x4a, 0xb6, 0xab, 0xda, 0x15, 0xa4, 0xb0, -- 0xb5, 0xa6, 0x49, 0x2a, 0xe6, 0x55, 0xfd, 0xa6, 0x90, 0x24, 0x70, 0x11, 0xe6, 0xdb, 0xf5, 0xca, -- 0xb5, 0xb6, 0x3e, 0x16, 0xa6, 0xf0, 0x12, 0x2c, 0xd4, 0xda, 0x55, 0xa3, 0xd2, 0xac, 0xc6, 0xc4, -- 0x19, 0xb6, 0x2e, 0x6d, 0x56, 0x1b, 0x9b, 0xa2, 0x8a, 0x58, 0xff, 0xed, 0x7a, 0xab, 0x72, 0xa5, -- 0xae, 0x6f, 0x09, 0xd1, 0x0a, 0x13, 0xbd, 0xad, 0x93, 0xc6, 0x76, 0x25, 0x1c, 0xf2, 0x32, 0x46, -- 0x90, 0xdb, 0xac, 0xd4, 0x35, 0x22, 0x7b, 0xb9, 0xa7, 0xe0, 0x02, 0x64, 0xf5, 0x7a, 0xbb, 0x26, -- 0xeb, 0x09, 0x5c, 0x82, 0xa2, 0xd6, 0x36, 0x1a, 0x66, 0xa5, 0x5e, 0x26, 0x7a, 0x4d, 0xaf, 0x1b, -- 0x52, 0x93, 0xc2, 0x45, 0x28, 0x18, 0x95, 0x9a, 0xde, 0x32, 0xb4, 0x5a, 0x53, 0x0a, 0xd9, 0x2c, -- 0x32, 0x2d, 0x3d, 0xb4, 0x41, 0x78, 0x19, 0x96, 0xea, 0x0d, 0x53, 0x3e, 0x2a, 0x32, 0xaf, 0x6b, -- 0xd5, 0xb6, 0x2e, 0x75, 0x2b, 0xf8, 0x14, 0xe0, 0x46, 0xdd, 0x6c, 0x37, 0xb7, 0x34, 0x43, 0x37, -- 0xeb, 0x8d, 0x1b, 0x52, 0x71, 0x19, 0x17, 0x20, 0x33, 0x9e, 0xc1, 0x3d, 0xc6, 0x42, 0xbe, 0xa9, -- 0x11, 0x63, 0x0c, 0xf6, 0xde, 0x3d, 0x46, 0x16, 0x5c, 0x21, 0x8d, 0x76, 0x73, 0x6c, 0xb6, 0x00, -- 0x39, 0x49, 0x96, 0x14, 0xa5, 0x98, 0x68, 0xb3, 0x52, 0x2f, 0x47, 0xf3, 0xbb, 0x97, 0x59, 0x4e, -- 0x20, 0x65, 0x6d, 0x0f, 0x52, 0xdc, 0x1d, 0x19, 0x48, 0xd5, 0x1b, 0x75, 0x1d, 0x9d, 0xc0, 0xf3, -- 0x00, 0x95, 0x56, 0xa5, 0x6e, 0xe8, 0x57, 0x88, 0x56, 0x65, 0xb0, 0xb9, 0x20, 0x24, 0x90, 0xa1, -- 0x9d, 0x83, 0xd9, 0x4a, 0x6b, 0xbb, 0xda, 0xd0, 0x0c, 0x09, 0xb3, 0xd2, 0xba, 0xd6, 0x6e, 0x18, -- 0x4c, 0x89, 0x70, 0x0e, 0x66, 0x2a, 0x2d, 0x43, 0x7f, 0xcb, 0x60, 0xb8, 0xb8, 0x4e, 0xb0, 0x8a, -- 0xee, 0x5d, 0x5e, 0xfb, 0x30, 0x09, 0x29, 0xfe, 0x22, 0x34, 0x0f, 0x59, 0xee, 0x6d, 0xe3, 0x66, -- 0x93, 0x0d, 0x99, 0x85, 0x54, 0xa5, 0x6e, 0x5c, 0x42, 0xff, 0x97, 0xc0, 0x00, 0xe9, 0x36, 0x2f, -- 0xff, 0xff, 0x0c, 0x2b, 0x57, 0xea, 0xc6, 0x2b, 0x17, 0xd1, 0xbb, 0x09, 0xd6, 0x6d, 0x5b, 0x54, -- 0x3e, 0x17, 0x2a, 0x36, 0x2e, 0xa0, 0xf7, 0x22, 0xc5, 0xc6, 0x05, 0xf4, 0xf9, 0x50, 0x71, 0x7e, -- 0x03, 0x7d, 0x21, 0x52, 0x9c, 0xdf, 0x40, 0x5f, 0x0c, 0x15, 0x17, 0x2f, 0xa0, 0x2f, 0x45, 0x8a, -- 0x8b, 0x17, 0xd0, 0x97, 0x67, 0x18, 0x16, 0x8e, 0xe4, 0xfc, 0x06, 0xfa, 0x4a, 0x26, 0xaa, 0x5d, -- 0xbc, 0x80, 0xbe, 0x9a, 0x61, 0xfe, 0x8f, 0xbc, 0x8a, 0xbe, 0x86, 0xd8, 0x34, 0x99, 0x83, 0xd0, -- 0xd7, 0x79, 0x91, 0xa9, 0xd0, 0x37, 0x10, 0xc3, 0xc8, 0xa4, 0xbc, 0xfa, 0x3e, 0xd7, 0xdc, 0xd4, -- 0x35, 0x82, 0xbe, 0x39, 0x23, 0xde, 0x90, 0x95, 0x2b, 0x35, 0xad, 0x8a, 0x30, 0x6f, 0xc1, 0x58, -- 0xf9, 0xf6, 0x39, 0x56, 0x64, 0xe1, 0x89, 0xbe, 0xd3, 0x64, 0x03, 0x5e, 0xd7, 0x48, 0xf9, 0x0d, -- 0x8d, 0xa0, 0xef, 0x9e, 0x63, 0x03, 0x5e, 0xd7, 0x88, 0xe4, 0xeb, 0x7b, 0x4d, 0x66, 0xc8, 0x55, -- 0x1f, 0x9c, 0x63, 0x93, 0x96, 0xf2, 0xef, 0x37, 0x71, 0x06, 0x92, 0x9b, 0x15, 0x03, 0x7d, 0xc8, -- 0x47, 0x63, 0x21, 0x8a, 0x7e, 0x80, 0x98, 0xb0, 0xa5, 0x1b, 0xe8, 0x87, 0x4c, 0x98, 0x36, 0xda, -- 0xcd, 0xaa, 0x8e, 0x9e, 0x62, 0x93, 0xbb, 0xa2, 0x37, 0x6a, 0xba, 0x41, 0x6e, 0xa2, 0x1f, 0x71, -- 0xf3, 0x37, 0x5b, 0x8d, 0x3a, 0xfa, 0x08, 0xe1, 0x02, 0x80, 0xfe, 0x56, 0x93, 0xe8, 0xad, 0x56, -- 0xa5, 0x51, 0x47, 0xcf, 0xae, 0x6d, 0x03, 0x3a, 0x9c, 0x0e, 0x18, 0x80, 0x76, 0xfd, 0x6a, 0xbd, -- 0x71, 0xa3, 0x8e, 0x4e, 0xb0, 0x4a, 0x93, 0xe8, 0x4d, 0x8d, 0xe8, 0x48, 0xc1, 0x00, 0x33, 0xe2, -- 0x85, 0x1b, 0x4a, 0xe0, 0x39, 0xc8, 0x90, 0x46, 0xb5, 0xba, 0xa9, 0x95, 0xaf, 0xa2, 0xe4, 0xe6, -- 0x02, 0xcc, 0xdb, 0xee, 0xfa, 0x1d, 0x3b, 0xa0, 0xbe, 0x2f, 0xde, 0x1c, 0xef, 0xcc, 0xf0, 0x9f, -- 0xf3, 0x7f, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xde, 0xe3, 0xd2, 0x1e, 0xad, 0x2c, 0x00, 0x00, --} -+*/ diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch deleted file mode 100644 index 9cdc14e0..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch +++ /dev/null @@ -1,316 +0,0 @@ -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .git -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .gitignore -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .travis.yml -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: CONTRIBUTORS.md -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: LICENSE.md -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: README.md -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer.go 2018-06-06 07:45:09.000000000 -0700 -@@ -19,15 +19,13 @@ - // analyzer.go contains utility analysis functions. - - import ( -+ "errors" - "fmt" - "strconv" - "strings" - "unicode" - -- "vitess.io/vitess/go/sqltypes" -- "vitess.io/vitess/go/vt/vterrors" -- -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // These constants are used to identify the SQL statement type. -@@ -219,7 +217,7 @@ - case IntVal: - n, err := sqltypes.NewIntegral(string(node.Val)) - if err != nil { -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err) -+ return sqltypes.PlanValue{}, fmt.Errorf("%v", err) - } - return sqltypes.PlanValue{Value: n}, nil - case StrVal: -@@ -227,7 +225,7 @@ - case HexVal: - v, err := node.HexDecode() - if err != nil { -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err) -+ return sqltypes.PlanValue{}, fmt.Errorf("%v", err) - } - return sqltypes.PlanValue{Value: sqltypes.MakeTrusted(sqltypes.VarBinary, v)}, nil - } -@@ -243,7 +241,7 @@ - return sqltypes.PlanValue{}, err - } - if innerpv.ListKey != "" || innerpv.Values != nil { -- return sqltypes.PlanValue{}, vterrors.New(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: nested lists") -+ return sqltypes.PlanValue{}, errors.New("unsupported: nested lists") - } - pv.Values = append(pv.Values, innerpv) - } -@@ -251,7 +249,7 @@ - case *NullVal: - return sqltypes.PlanValue{}, nil - } -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "expression is too complex '%v'", String(node)) -+ return sqltypes.PlanValue{}, fmt.Errorf("expression is too complex '%v'", String(node)) - } - - // StringIn is a convenience function that returns -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer_test.go 2018-06-06 07:45:09.000000000 -0700 -@@ -21,7 +21,7 @@ - "strings" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestPreview(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast.go 2018-06-06 07:45:09.000000000 -0700 -@@ -22,14 +22,11 @@ - "encoding/json" - "fmt" - "io" -+ "log" - "strings" - -- "vitess.io/vitess/go/sqltypes" -- "vitess.io/vitess/go/vt/log" -- "vitess.io/vitess/go/vt/vterrors" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // Instructions for creating new types: If a type -@@ -52,11 +49,11 @@ - tokenizer := NewStringTokenizer(sql) - if yyParse(tokenizer) != 0 { - if tokenizer.partialDDL != nil { -- log.Warningf("ignoring error parsing DDL '%s': %v", sql, tokenizer.LastError) -+ log.Printf("ignoring error parsing DDL '%s': %v", sql, tokenizer.LastError) - tokenizer.ParseTree = tokenizer.partialDDL - return tokenizer.ParseTree, nil - } -- return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, tokenizer.LastError.Error()) -+ return nil, tokenizer.LastError - } - return tokenizer.ParseTree, nil - } -@@ -2249,7 +2246,7 @@ - return NewStrVal(value.ToBytes()), nil - default: - // We cannot support sqltypes.Expression, or any other invalid type. -- return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "cannot convert value %v to AST", value) -+ return nil, fmt.Errorf("cannot convert value %v to AST", value) - } - } - -@@ -3394,6 +3391,20 @@ - return nil - } - -+// Backtick produces a backticked literal given an input string. -+func Backtick(in string) string { -+ var buf bytes.Buffer -+ buf.WriteByte('`') -+ for _, c := range in { -+ buf.WriteRune(c) -+ if c == '`' { -+ buf.WriteByte('`') -+ } -+ } -+ buf.WriteByte('`') -+ return buf.String() -+} -+ - func formatID(buf *TrackedBuffer, original, lowered string) { - isDbSystemVariable := false - if len(original) > 1 && original[:2] == "@@" { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast_test.go 2018-06-05 07:41:09.000000000 -0700 -@@ -24,7 +24,7 @@ - "testing" - "unsafe" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestAppend(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments.go 2018-06-06 07:45:09.000000000 -0700 -@@ -145,7 +145,7 @@ - // Single line comment - index := strings.Index(sql, "\n") - if index == -1 { -- return "" -+ return sql - } - sql = sql[index+1:] - } -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments_test.go 2018-06-06 07:45:08.000000000 -0700 -@@ -187,7 +187,7 @@ - outSQL: "bar", - }, { - input: "-- /* foo */ bar", -- outSQL: "", -+ outSQL: "-- /* foo */ bar", - }, { - input: "foo -- bar */", - outSQL: "foo -- bar */", -@@ -201,7 +201,7 @@ - outSQL: "a", - }, { - input: `-- foo bar`, -- outSQL: "", -+ outSQL: "-- foo bar", - }} - for _, testCase := range testCases { - gotSQL := StripLeadingComments(testCase.input) -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: dependency -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable.go 2017-10-18 18:06:33.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "bytes" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // This file contains types that are 'Encodable'. -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable_test.go 2017-10-18 18:06:33.000000000 -0700 -@@ -20,7 +20,7 @@ - "bytes" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestEncodable(t *testing.T) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: github_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer.go 2017-10-18 18:06:33.000000000 -0700 -@@ -19,9 +19,9 @@ - import ( - "fmt" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // Normalize changes the statement to use bind values, and -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer_test.go 2017-11-27 22:10:51.000000000 -0800 -@@ -21,8 +21,8 @@ - "reflect" - "testing" - -- "vitess.io/vitess/go/sqltypes" -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestNormalize(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query.go 2017-10-22 13:30:37.000000000 -0700 -@@ -18,12 +18,10 @@ - - import ( - "bytes" -- "encoding/json" - "fmt" - -- "vitess.io/vitess/go/sqltypes" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // ParsedQuery represents a parsed query where -@@ -71,12 +69,6 @@ - return buf.Bytes(), nil - } - --// MarshalJSON is a custom JSON marshaler for ParsedQuery. --// Note that any queries longer that 512 bytes will be truncated. --func (pq *ParsedQuery) MarshalJSON() ([]byte, error) { -- return json.Marshal(TruncateForUI(pq.Query)) --} -- - // EncodeValue encodes one bind variable value into the query. - func EncodeValue(buf *bytes.Buffer, value *querypb.BindVariable) { - if value.Type != querypb.Type_TUPLE { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query_test.go 2017-10-18 18:06:33.000000000 -0700 -@@ -20,9 +20,9 @@ - "reflect" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestNewParsedQuery(t *testing.T) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: patches -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: quick -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/redact_query.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//redact_query.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/redact_query.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//redact_query.go 2018-06-06 07:42:56.000000000 -0700 -@@ -1,6 +1,6 @@ - package sqlparser - --import querypb "vitess.io/vitess/go/vt/proto/query" -+import querypb "github.com/xwb1989/sqlparser/dependency/querypb" - - // RedactSQLQuery returns a sql string with the params stripped out for display - func RedactSQLQuery(sql string) (string, error) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: tests -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/token.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//token.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/token.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//token.go 2018-06-06 07:45:09.000000000 -0700 -@@ -22,8 +22,8 @@ - "fmt" - "io" - -- "vitess.io/vitess/go/bytes2" -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/bytes2" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - const ( -Only in /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/: truncate_query.go -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: y.output diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch deleted file mode 100644 index 215ba9d8..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch +++ /dev/null @@ -1,290 +0,0 @@ -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: arithmetic.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: arithmetic_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,11 +19,10 @@ - import ( - "errors" - "fmt" -+ "reflect" - "strconv" - -- "github.com/golang/protobuf/proto" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // NullBindVariable is a bindvar with NULL value. -@@ -253,9 +252,8 @@ - } - - // BindVariablesEqual compares two maps of bind variables. --// For protobuf messages we have to use "proto.Equal". - func BindVariablesEqual(x, y map[string]*querypb.BindVariable) bool { -- return proto.Equal(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y}) -+ return reflect.DeepEqual(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y}) - } - - // CopyBindVariables returns a shallow-copy of the given bindVariables map. -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -21,16 +21,14 @@ - "strings" - "testing" - -- "github.com/golang/protobuf/proto" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestProtoConversions(t *testing.T) { - v := TestValue(Int64, "1") - got := ValueToProto(v) - want := &querypb.Value{Type: Int64, Value: []byte("1")} -- if !proto.Equal(got, want) { -+ if !reflect.DeepEqual(got, want) { - t.Errorf("ValueToProto: %v, want %v", got, want) - } - gotback := ProtoToValue(got) -@@ -240,7 +238,7 @@ - t.Errorf("ToBindVar(%T(%v)) error: nil, want %s", tcase.in, tcase.in, tcase.err) - continue - } -- if !proto.Equal(bv, tcase.out) { -+ if !reflect.DeepEqual(bv, tcase.out) { - t.Errorf("ToBindVar(%T(%v)): %v, want %s", tcase.in, tcase.in, bv, tcase.out) - } - } -@@ -523,7 +521,7 @@ - v, err = BindVariableToValue(&querypb.BindVariable{Type: querypb.Type_TUPLE}) - wantErr := "cannot convert a TUPLE bind var into a value" - if err == nil || err.Error() != wantErr { -- t.Errorf(" BindVarToValue(TUPLE): (%v, %v), want %s", v, err, wantErr) -+ t.Errorf(" BindVarToValue(TUPLE): %v, want %s", err, wantErr) - } - } - -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: event_token.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: event_token_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value.go 2018-06-04 08:05:24.000000000 -0700 -@@ -18,10 +18,10 @@ - - import ( - "encoding/json" -+ "errors" -+ "fmt" - -- querypb "vitess.io/vitess/go/vt/proto/query" -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -- "vitess.io/vitess/go/vt/vterrors" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // PlanValue represents a value or a list of values for -@@ -87,7 +87,7 @@ - case pv.ListKey != "" || pv.Values != nil: - // This code is unreachable because the parser does not allow - // multi-value constructs where a single value is expected. -- return NULL, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "a list was supplied where a single value was expected") -+ return NULL, errors.New("a list was supplied where a single value was expected") - } - return NULL, nil - } -@@ -95,10 +95,10 @@ - func (pv PlanValue) lookupValue(bindVars map[string]*querypb.BindVariable) (*querypb.BindVariable, error) { - bv, ok := bindVars[pv.Key] - if !ok { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "missing bind var %s", pv.Key) -+ return nil, fmt.Errorf("missing bind var %s", pv.Key) - } - if bv.Type == querypb.Type_TUPLE { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "TUPLE was supplied for single value bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("TUPLE was supplied for single value bind var %s", pv.ListKey) - } - return bv, nil - } -@@ -129,16 +129,16 @@ - } - // This code is unreachable because the parser does not allow - // single value constructs where multiple values are expected. -- return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "a single value was supplied where a list was expected") -+ return nil, errors.New("a single value was supplied where a list was expected") - } - - func (pv PlanValue) lookupList(bindVars map[string]*querypb.BindVariable) (*querypb.BindVariable, error) { - bv, ok := bindVars[pv.ListKey] - if !ok { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "missing bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("missing bind var %s", pv.ListKey) - } - if bv.Type != querypb.Type_TUPLE { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "single value was supplied for TUPLE bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("single value was supplied for TUPLE bind var %s", pv.ListKey) - } - return bv, nil - } -@@ -171,7 +171,7 @@ - case l: - return nil - default: -- return vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "mismatch in number of column values") -+ return errors.New("mismatch in number of column values") - } - } - -@@ -221,7 +221,7 @@ - rows[i] = make([]Value, len(pvs)) - } - -- // Using j because we're resolving by columns. -+ // Using j becasue we're resolving by columns. - for j, pv := range pvs { - switch { - case pv.Key != "": -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -21,7 +21,7 @@ - "strings" - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestPlanValueIsNull(t *testing.T) { -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: proto3.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: proto3_test.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: query_response.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: result.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: result_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/testing.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/testing.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/testing.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/testing.go 2018-06-04 08:06:27.000000000 -0700 -@@ -17,17 +17,14 @@ - package sqltypes - - import ( -- "bytes" -- "fmt" -- "strings" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ querypb "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // Functions in this file should only be used for testing. - // This is an experiment to see if test code bloat can be - // reduced and readability improved. - -+/* - // MakeTestFields builds a []*querypb.Field for testing. - // fields := sqltypes.MakeTestFields( - // "a|b", -@@ -110,6 +107,7 @@ - } - return results - } -+*/ - - // TestBindVariable makes a *querypb.BindVariable from - // an interface{}.It panics on invalid input. -@@ -131,6 +129,7 @@ - return MakeTrusted(typ, []byte(val)) - } - -+/* - // PrintResults prints []*Results into a string. - // This function should only be used for testing. - func PrintResults(results []*Result) string { -@@ -152,3 +151,4 @@ - } - return splits - } -+*/ -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "fmt" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // This file provides wrappers and support -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestTypeValues(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value.go 2018-06-04 08:05:24.000000000 -0700 -@@ -23,10 +23,10 @@ - "fmt" - "strconv" - -- "vitess.io/vitess/go/bytes2" -- "vitess.io/vitess/go/hack" -+ "github.com/xwb1989/sqlparser/dependency/bytes2" -+ "github.com/xwb1989/sqlparser/dependency/hack" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - var ( -@@ -48,7 +48,7 @@ - } - - // Value can store any SQL value. If the value represents --// an integral type, the bytes are always stored as a canonical -+// an integral type, the bytes are always stored as a cannonical - // representation that matches how MySQL returns such values. - type Value struct { - typ querypb.Type -@@ -126,7 +126,7 @@ - return MakeTrusted(VarBinary, []byte(v)) - } - --// NewIntegral builds an integral type from a string representation. -+// NewIntegral builds an integral type from a string representaion. - // The type will be Int64 or Uint64. Int64 will be preferred where possible. - func NewIntegral(val string) (n Value, err error) { - signed, err := strconv.ParseInt(val, 0, 64) -@@ -169,7 +169,7 @@ - return v.typ - } - --// Raw returns the internal representation of the value. For newer types, -+// Raw returns the internal represenation of the value. For newer types, - // this may not match MySQL's representation. - func (v Value) Raw() []byte { - return v.val -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -22,7 +22,7 @@ - "strings" - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - const ( diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go deleted file mode 100644 index f6a1c93f..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "testing" -) - -func readable(node Expr) string { - switch node := node.(type) { - case *OrExpr: - return fmt.Sprintf("(%s or %s)", readable(node.Left), readable(node.Right)) - case *AndExpr: - return fmt.Sprintf("(%s and %s)", readable(node.Left), readable(node.Right)) - case *BinaryExpr: - return fmt.Sprintf("(%s %s %s)", readable(node.Left), node.Operator, readable(node.Right)) - case *IsExpr: - return fmt.Sprintf("(%s %s)", readable(node.Expr), node.Operator) - default: - return String(node) - } -} - -func TestAndOrPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select * from a where a=b and c=d or e=f", - output: "((a = b and c = d) or e = f)", - }, { - input: "select * from a where a=b or c=d and e=f", - output: "(a = b or (c = d and e = f))", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).Where.Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} - -func TestPlusStarPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select 1+2*3 from a", - output: "(1 + (2 * 3))", - }, { - input: "select 1*2+3 from a", - output: "((1 * 2) + 3)", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).SelectExprs[0].(*AliasedExpr).Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} - -func TestIsPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select * from a where a+b is true", - output: "((a + b) is true)", - }, { - input: "select * from a where a=1 and b=2 is true", - output: "(a = 1 and (b = 2 is true))", - }, { - input: "select * from a where (a=1 and b=2) is true", - output: "((a = 1 and b = 2) is true)", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).Where.Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go deleted file mode 100644 index 553e6ee0..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package sqlparser - -import ( - "testing" -) - -func TestRedactSQLStatements(t *testing.T) { - sql := "select a,b,c from t where x = 1234 and y = 1234 and z = 'apple'" - redactedSQL, err := RedactSQLQuery(sql) - if err != nil { - t.Fatalf("redacting sql failed: %v", err) - } - - if redactedSQL != "select a, b, c from t where x = :redacted1 and y = :redacted1 and z = :redacted2" { - t.Fatalf("Unknown sql redaction: %v", redactedSQL) - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go deleted file mode 100644 index 93543545..00000000 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "testing" -) - -func TestLiteralID(t *testing.T) { - testcases := []struct { - in string - id int - out string - }{{ - in: "`aa`", - id: ID, - out: "aa", - }, { - in: "```a```", - id: ID, - out: "`a`", - }, { - in: "`a``b`", - id: ID, - out: "a`b", - }, { - in: "`a``b`c", - id: ID, - out: "a`b", - }, { - in: "`a``b", - id: LEX_ERROR, - out: "a`b", - }, { - in: "`a``b``", - id: LEX_ERROR, - out: "a`b`", - }, { - in: "``", - id: LEX_ERROR, - out: "", - }} - - for _, tcase := range testcases { - tkn := NewStringTokenizer(tcase.in) - id, out := tkn.Scan() - if tcase.id != id || string(out) != tcase.out { - t.Errorf("Scan(%s): %d, %s, want %d, %s", tcase.in, id, out, tcase.id, tcase.out) - } - } -} - -func tokenName(id int) string { - if id == STRING { - return "STRING" - } else if id == LEX_ERROR { - return "LEX_ERROR" - } - return fmt.Sprintf("%d", id) -} - -func TestString(t *testing.T) { - testcases := []struct { - in string - id int - want string - }{{ - in: "''", - id: STRING, - want: "", - }, { - in: "''''", - id: STRING, - want: "'", - }, { - in: "'hello'", - id: STRING, - want: "hello", - }, { - in: "'\\n'", - id: STRING, - want: "\n", - }, { - in: "'\\nhello\\n'", - id: STRING, - want: "\nhello\n", - }, { - in: "'a''b'", - id: STRING, - want: "a'b", - }, { - in: "'a\\'b'", - id: STRING, - want: "a'b", - }, { - in: "'\\'", - id: LEX_ERROR, - want: "'", - }, { - in: "'", - id: LEX_ERROR, - want: "", - }, { - in: "'hello\\'", - id: LEX_ERROR, - want: "hello'", - }, { - in: "'hello", - id: LEX_ERROR, - want: "hello", - }, { - in: "'hello\\", - id: LEX_ERROR, - want: "hello", - }} - - for _, tcase := range testcases { - id, got := NewStringTokenizer(tcase.in).Scan() - if tcase.id != id || string(got) != tcase.want { - t.Errorf("Scan(%q) = (%s, %q), want (%s, %q)", tcase.in, tokenName(id), got, tokenName(tcase.id), tcase.want) - } - } -} - -func TestSplitStatement(t *testing.T) { - testcases := []struct { - in string - sql string - rem string - }{{ - in: "select * from table", - sql: "select * from table", - }, { - in: "select * from table; ", - sql: "select * from table", - rem: " ", - }, { - in: "select * from table; select * from table2;", - sql: "select * from table", - rem: " select * from table2;", - }, { - in: "select * from /* comment */ table;", - sql: "select * from /* comment */ table", - }, { - in: "select * from /* comment ; */ table;", - sql: "select * from /* comment ; */ table", - }, { - in: "select * from table where semi = ';';", - sql: "select * from table where semi = ';'", - }, { - in: "-- select * from table", - sql: "-- select * from table", - }, { - in: " ", - sql: " ", - }, { - in: "", - sql: "", - }} - - for _, tcase := range testcases { - sql, rem, err := SplitStatement(tcase.in) - if err != nil { - t.Errorf("EndOfStatementPosition(%s): ERROR: %v", tcase.in, err) - continue - } - - if tcase.sql != sql { - t.Errorf("EndOfStatementPosition(%s) got sql \"%s\" want \"%s\"", tcase.in, sql, tcase.sql) - } - - if tcase.rem != rem { - t.Errorf("EndOfStatementPosition(%s) got remainder \"%s\" want \"%s\"", tcase.in, rem, tcase.rem) - } - } -} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml new file mode 100644 index 00000000..6d4d1be7 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml @@ -0,0 +1,15 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + enabled: yes # must be yes|true to enable this status + target: 100 # specify the target coverage for each commit status + # option: "auto" (must increase from parent commit or pull request base) + # option: "X%" a static target percentage to hit + if_not_found: success # if parent is not found report status as success, error, or failure + if_ci_failed: error # if ci fails report status as success, error, or failure + diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore new file mode 100644 index 00000000..0a4504f1 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +/vendor +/cover +cover.out +lint.log + +# Binaries +*.test + +# Profiling output +*.prof diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml new file mode 100644 index 00000000..58957222 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml @@ -0,0 +1,23 @@ +sudo: false +language: go +go_import_path: go.uber.org/atomic + +go: + - 1.7 + - 1.8 + - 1.9 + +cache: + directories: + - vendor + +install: + - make install_ci + +script: + - make test_ci + - scripts/test-ubergo.sh + - make lint + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/LICENSE.txt b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/LICENSE.txt similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/LICENSE.txt rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/LICENSE.txt diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/Makefile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/Makefile similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/Makefile rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/Makefile diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/README.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/README.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/atomic.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/atomic.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/atomic.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/atomic.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/glide.lock b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.lock similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/glide.lock rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.lock diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml new file mode 100644 index 00000000..4cf608ec --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml @@ -0,0 +1,6 @@ +package: go.uber.org/atomic +testImport: +- package: github.com/stretchr/testify + subpackages: + - assert + - require diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/string.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/string.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/string.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/string.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml new file mode 100644 index 00000000..6d4d1be7 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml @@ -0,0 +1,15 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + enabled: yes # must be yes|true to enable this status + target: 100 # specify the target coverage for each commit status + # option: "auto" (must increase from parent commit or pull request base) + # option: "X%" a static target percentage to hit + if_not_found: success # if parent is not found report status as success, error, or failure + if_ci_failed: error # if ci fails report status as success, error, or failure + diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore new file mode 100644 index 00000000..61ead866 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml new file mode 100644 index 00000000..5ffa8fed --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml @@ -0,0 +1,33 @@ +sudo: false +language: go +go_import_path: go.uber.org/multierr + +env: + global: + - GO15VENDOREXPERIMENT=1 + +go: + - 1.7 + - 1.8 + - tip + +cache: + directories: + - vendor + +before_install: +- go version + +install: +- | + set -e + make install_ci + +script: +- | + set -e + make lint + make test_ci + +after_success: +- bash <(curl -s https://codecov.io/bash) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/CHANGELOG.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/CHANGELOG.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/CHANGELOG.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/CHANGELOG.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/LICENSE.txt b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/LICENSE.txt similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/LICENSE.txt rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/LICENSE.txt diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/Makefile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/Makefile similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/Makefile rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/Makefile diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/README.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/README.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/error.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/error.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/error.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/error.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/glide.lock b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.lock similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/glide.lock rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.lock diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml new file mode 100644 index 00000000..6ef084ec --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml @@ -0,0 +1,8 @@ +package: go.uber.org/multierr +import: +- package: go.uber.org/atomic + version: ^1 +testImport: +- package: github.com/stretchr/testify + subpackages: + - assert diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/AUTHORS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/AUTHORS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/AUTHORS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/AUTHORS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/CONTRIBUTORS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/CONTRIBUTORS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/CONTRIBUTORS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/CONTRIBUTORS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/PATENTS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/PATENTS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/PATENTS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/PATENTS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore new file mode 100644 index 00000000..e3e0fc6f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore @@ -0,0 +1,2 @@ +_obj/ +unix.test diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/README.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/README.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/affinity_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/affinity_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/affinity_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/affinity_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/aliases.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/aliases.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/aliases.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/aliases.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_386.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_386.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_386.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_386.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_386.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_386.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_386.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_386.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_386.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_386.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_386.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_386.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s new file mode 100644 index 00000000..88f71255 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s @@ -0,0 +1,44 @@ +// Copyright 2014 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. + +// +build linux +// +build ppc64 ppc64le +// +build !gccgo + +#include "textflag.h" + +// +// System calls for ppc64, Linux +// + +// Just jump to package syscall's implementation for all these functions. +// The runtime may know about them. + +TEXT ·SyscallNoError(SB),NOSPLIT,$0-48 + BL runtime·entersyscall(SB) + MOVD a1+8(FP), R3 + MOVD a2+16(FP), R4 + MOVD a3+24(FP), R5 + MOVD R0, R6 + MOVD R0, R7 + MOVD R0, R8 + MOVD trap+0(FP), R9 // syscall entry + SYSCALL R9 + MOVD R3, r1+32(FP) + MOVD R4, r2+40(FP) + BL runtime·exitsyscall(SB) + RET + +TEXT ·RawSyscallNoError(SB),NOSPLIT,$0-48 + MOVD a1+8(FP), R3 + MOVD a2+16(FP), R4 + MOVD a3+24(FP), R5 + MOVD R0, R6 + MOVD R0, R7 + MOVD R0, R8 + MOVD trap+0(FP), R9 // syscall entry + SYSCALL R9 + MOVD R3, r1+32(FP) + MOVD R4, r2+40(FP) + RET diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_s390x.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_s390x.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_s390x.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_s390x.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_386.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_386.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_386.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_386.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_386.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_386.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_386.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_386.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/bluetooth_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/bluetooth_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/bluetooth_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/bluetooth_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/cap_freebsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/cap_freebsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/cap_freebsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/cap_freebsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/constants.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/constants.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/constants.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/constants.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_darwin.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_darwin.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_darwin.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_darwin.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_dragonfly.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_dragonfly.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_dragonfly.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_dragonfly.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_freebsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_freebsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_freebsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_freebsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_netbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_netbsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_netbsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_netbsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_openbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_openbsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_openbsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_openbsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dirent.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dirent.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dirent.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dirent.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_big.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_big.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_big.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_big.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_little.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_little.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_little.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_little.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/env_unix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/env_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/env_unix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/env_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_c.c b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_c.c similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_c.c rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_c.c diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ioctl.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ioctl.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ioctl.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ioctl.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mkall.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkall.sh similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mkall.sh rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkall.sh diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh new file mode 100644 index 00000000..aa860fa2 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh @@ -0,0 +1,656 @@ +#!/usr/bin/env bash +# 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. + +# Generate Go code listing errors and other #defined constant +# values (ENAMETOOLONG etc.), by asking the preprocessor +# about the definitions. + +unset LANG +export LC_ALL=C +export LC_CTYPE=C + +if test -z "$GOARCH" -o -z "$GOOS"; then + echo 1>&2 "GOARCH or GOOS not defined in environment" + exit 1 +fi + +# Check that we are using the new build system if we should +if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then + if [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then + echo 1>&2 "In the new build system, mkerrors should not be called directly." + echo 1>&2 "See README.md" + exit 1 + fi +fi + +if [[ "$GOOS" = "aix" ]]; then + CC=${CC:-gcc} +else + CC=${CC:-cc} +fi + +if [[ "$GOOS" = "solaris" ]]; then + # Assumes GNU versions of utilities in PATH. + export PATH=/usr/gnu/bin:$PATH +fi + +uname=$(uname) + +includes_AIX=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AF_LOCAL AF_UNIX +' + +includes_Darwin=' +#define _DARWIN_C_SOURCE +#define KERNEL +#define _DARWIN_USE_64_BIT_INODE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + +includes_DragonFly=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + +includes_FreeBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if __FreeBSD__ >= 10 +#define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 +#undef SIOCAIFADDR +#define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data +#undef SIOCSIFPHYADDR +#define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data +#endif +' + +includes_Linux=' +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#ifndef __LP64__ +#define _FILE_OFFSET_BITS 64 +#endif +#define _GNU_SOURCE + +// is broken on powerpc64, as it fails to include definitions of +// these structures. We just include them copied from . +#if defined(__powerpc__) +struct sgttyb { + char sg_ispeed; + char sg_ospeed; + char sg_erase; + char sg_kill; + short sg_flags; +}; + +struct tchars { + char t_intrc; + char t_quitc; + char t_startc; + char t_stopc; + char t_eofc; + char t_brkc; +}; + +struct ltchars { + char t_suspc; + char t_dsuspc; + char t_rprntc; + char t_flushc; + char t_werasc; + char t_lnextc; +}; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef MSG_FASTOPEN +#define MSG_FASTOPEN 0x20000000 +#endif + +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS 0xc +#endif + +#ifndef PTRACE_SETREGS +#define PTRACE_SETREGS 0xd +#endif + +#ifndef SOL_NETLINK +#define SOL_NETLINK 270 +#endif + +#ifdef SOL_BLUETOOTH +// SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h +// but it is already in bluetooth_linux.go +#undef SOL_BLUETOOTH +#endif + +// Certain constants are missing from the fs/crypto UAPI +#define FS_KEY_DESC_PREFIX "fscrypt:" +#define FS_KEY_DESC_PREFIX_SIZE 8 +#define FS_MAX_KEY_SIZE 64 + +// XDP socket constants do not appear to be picked up otherwise. +// Copied from samples/bpf/xdpsock_user.c. +#ifndef SOL_XDP +#define SOL_XDP 283 +#endif + +#ifndef AF_XDP +#define AF_XDP 44 +#endif +' + +includes_NetBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Needed since refers to it... +#define schedppq 1 +' + +includes_OpenBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// We keep some constants not supported in OpenBSD 5.5 and beyond for +// the promise of compatibility. +#define EMUL_ENABLED 0x1 +#define EMUL_NATIVE 0x2 +#define IPV6_FAITH 0x1d +#define IPV6_OPTIONS 0x1 +#define IPV6_RTHDR_STRICT 0x1 +#define IPV6_SOCKOPT_RESERVED1 0x3 +#define SIOCGIFGENERIC 0xc020693a +#define SIOCSIFGENERIC 0x80206939 +#define WALTSIG 0x4 +' + +includes_SunOS=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + + +includes=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' +ccflags="$@" + +# Write go tool cgo -godefs input. +( + echo package unix + echo + echo '/*' + indirect="includes_$(uname)" + echo "${!indirect} $includes" + echo '*/' + echo 'import "C"' + echo 'import "syscall"' + echo + echo 'const (' + + # The gcc command line prints all the #defines + # it encounters while processing the input + echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | + awk ' + $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} + + $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers + $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} + $2 ~ /^(SCM_SRCRT)$/ {next} + $2 ~ /^(MAP_FAILED)$/ {next} + $2 ~ /^ELF_.*$/ {next}# contains ELF_ARCH, etc. + + $2 ~ /^EXTATTR_NAMESPACE_NAMES/ || + $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} + + $2 !~ /^ECCAPBITS/ && + $2 !~ /^ETH_/ && + $2 !~ /^EPROC_/ && + $2 !~ /^EQUIV_/ && + $2 !~ /^EXPR_/ && + $2 ~ /^E[A-Z0-9_]+$/ || + $2 ~ /^B[0-9_]+$/ || + $2 ~ /^(OLD|NEW)DEV$/ || + $2 == "BOTHER" || + $2 ~ /^CI?BAUD(EX)?$/ || + $2 == "IBSHIFT" || + $2 ~ /^V[A-Z0-9]+$/ || + $2 ~ /^CS[A-Z0-9]/ || + $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || + $2 ~ /^IGN/ || + $2 ~ /^IX(ON|ANY|OFF)$/ || + $2 ~ /^IN(LCR|PCK)$/ || + $2 !~ "X86_CR3_PCID_NOFLUSH" && + $2 ~ /(^FLU?SH)|(FLU?SH$)/ || + $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || + $2 == "BRKINT" || + $2 == "HUPCL" || + $2 == "PENDIN" || + $2 == "TOSTOP" || + $2 == "XCASE" || + $2 == "ALTWERASE" || + $2 == "NOKERNINFO" || + $2 ~ /^PAR/ || + $2 ~ /^SIG[^_]/ || + $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || + $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || + $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || + $2 ~ /^O?XTABS$/ || + $2 ~ /^TC[IO](ON|OFF)$/ || + $2 ~ /^IN_/ || + $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || + $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || + $2 ~ /^TP_STATUS_/ || + $2 ~ /^FALLOC_/ || + $2 == "ICMPV6_FILTER" || + $2 == "SOMAXCONN" || + $2 == "NAME_MAX" || + $2 == "IFNAMSIZ" || + $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ || + $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ || + $2 ~ /^HW_MACHINE$/ || + $2 ~ /^SYSCTL_VERS/ || + $2 !~ "MNT_BITS" && + $2 ~ /^(MS|MNT|UMOUNT)_/ || + $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || + $2 ~ /^(O|F|E?FD|NAME|S|PTRACE|PT)_/ || + $2 ~ /^KEXEC_/ || + $2 ~ /^LINUX_REBOOT_CMD_/ || + $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || + $2 ~ /^MODULE_INIT_/ || + $2 !~ "NLA_TYPE_MASK" && + $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || + $2 ~ /^SIOC/ || + $2 ~ /^TIOC/ || + $2 ~ /^TCGET/ || + $2 ~ /^TCSET/ || + $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || + $2 !~ "RTF_BITS" && + $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || + $2 ~ /^BIOC/ || + $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || + $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ || + $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || + $2 ~ /^CLONE_[A-Z_]+/ || + $2 !~ /^(BPF_TIMEVAL)$/ && + $2 ~ /^(BPF|DLT)_/ || + $2 ~ /^CLOCK_/ || + $2 ~ /^CAN_/ || + $2 ~ /^CAP_/ || + $2 ~ /^ALG_/ || + $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE|IOC_(GET|SET)_ENCRYPTION)/ || + $2 ~ /^GRND_/ || + $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || + $2 ~ /^KEYCTL_/ || + $2 ~ /^PERF_EVENT_IOC_/ || + $2 ~ /^SECCOMP_MODE_/ || + $2 ~ /^SPLICE_/ || + $2 ~ /^SYNC_FILE_RANGE_/ || + $2 !~ /^AUDIT_RECORD_MAGIC/ && + $2 !~ /IOC_MAGIC/ && + $2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ || + $2 ~ /^(VM|VMADDR)_/ || + $2 ~ /^IOCTL_VM_SOCKETS_/ || + $2 ~ /^(TASKSTATS|TS)_/ || + $2 ~ /^CGROUPSTATS_/ || + $2 ~ /^GENL_/ || + $2 ~ /^STATX_/ || + $2 ~ /^RENAME/ || + $2 ~ /^UBI_IOC[A-Z]/ || + $2 ~ /^UTIME_/ || + $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || + $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || + $2 ~ /^FSOPT_/ || + $2 ~ /^WDIOC_/ || + $2 ~ /^NFN/ || + $2 ~ /^XDP_/ || + $2 ~ /^(HDIO|WIN|SMART)_/ || + $2 !~ "WMESGLEN" && + $2 ~ /^W[A-Z0-9]+$/ || + $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} + $2 ~ /^__WCOREFLAG$/ {next} + $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} + + {next} + ' | sort + + echo ')' +) >_const.go + +# Pull out the error names for later. +errors=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | + sort +) + +# Pull out the signal names for later. +signals=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | + sort +) + +# Again, writing regexps to a file. +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | + sort >_error.grep +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | + sort >_signal.grep + +echo '// mkerrors.sh' "$@" +echo '// Code generated by the command above; see README.md. DO NOT EDIT.' +echo +echo "// +build ${GOARCH},${GOOS}" +echo +go tool cgo -godefs -- "$@" _const.go >_error.out +cat _error.out | grep -vf _error.grep | grep -vf _signal.grep +echo +echo '// Errors' +echo 'const (' +cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' +echo ')' + +echo +echo '// Signals' +echo 'const (' +cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' +echo ')' + +# Run C program to print error and syscall strings. +( + echo -E " +#include +#include +#include +#include +#include +#include + +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + +enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below + +struct tuple { + int num; + const char *name; +}; + +struct tuple errors[] = { +" + for i in $errors + do + echo -E ' {'$i', "'$i'" },' + done + + echo -E " +}; + +struct tuple signals[] = { +" + for i in $signals + do + echo -E ' {'$i', "'$i'" },' + done + + # Use -E because on some systems bash builtin interprets \n itself. + echo -E ' +}; + +static int +tuplecmp(const void *a, const void *b) +{ + return ((struct tuple *)a)->num - ((struct tuple *)b)->num; +} + +int +main(void) +{ + int i, e; + char buf[1024], *p; + + printf("\n\n// Error table\n"); + printf("var errorList = [...]struct {\n"); + printf("\tnum syscall.Errno\n"); + printf("\tname string\n"); + printf("\tdesc string\n"); + printf("} {\n"); + qsort(errors, nelem(errors), sizeof errors[0], tuplecmp); + for(i=0; i 0 && errors[i-1].num == e) + continue; + strcpy(buf, strerror(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf); + } + printf("}\n\n"); + + printf("\n\n// Signal table\n"); + printf("var signalList = [...]struct {\n"); + printf("\tnum syscall.Signal\n"); + printf("\tname string\n"); + printf("\tdesc string\n"); + printf("} {\n"); + qsort(signals, nelem(signals), sizeof signals[0], tuplecmp); + for(i=0; i 0 && signals[i-1].num == e) + continue; + strcpy(buf, strsignal(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + // cut trailing : number. + p = strrchr(buf, ":"[0]); + if(p) + *p = '\0'; + printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf); + } + printf("}\n\n"); + + return 0; +} + +' +) >_errors.c + +$CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go new file mode 100644 index 00000000..6d263cf1 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go @@ -0,0 +1,106 @@ +// 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. + +// +build ignore + +// mkpost processes the output of cgo -godefs to +// modify the generated types. It is used to clean up +// the sys API in an architecture specific manner. +// +// mkpost is run after cgo -godefs; see README.md. +package main + +import ( + "bytes" + "fmt" + "go/format" + "io/ioutil" + "log" + "os" + "regexp" +) + +func main() { + // Get the OS and architecture (using GOARCH_TARGET if it exists) + goos := os.Getenv("GOOS") + goarch := os.Getenv("GOARCH_TARGET") + if goarch == "" { + goarch = os.Getenv("GOARCH") + } + // Check that we are using the new build system if we should be. + if goos == "linux" && goarch != "sparc64" { + if os.Getenv("GOLANG_SYS_BUILD") != "docker" { + os.Stderr.WriteString("In the new build system, mkpost should not be called directly.\n") + os.Stderr.WriteString("See README.md\n") + os.Exit(1) + } + } + + b, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Fatal(err) + } + + // Intentionally export __val fields in Fsid and Sigset_t + valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__val(\s+\S+\s+)}`) + b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$3}")) + + // Intentionally export __fds_bits field in FdSet + fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`) + b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}")) + + // If we have empty Ptrace structs, we should delete them. Only s390x emits + // nonempty Ptrace structs. + ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) + b = ptraceRexexp.ReplaceAll(b, nil) + + // Replace the control_regs union with a blank identifier for now. + controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`) + b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64")) + + // Remove fields that are added by glibc + // Note that this is unstable as the identifers are private. + removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`) + b = removeFieldsRegex.ReplaceAll(b, []byte("_")) + + // Convert [65]int8 to [65]byte in Utsname members to simplify + // conversion to string; see golang.org/issue/20753 + convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`) + b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte")) + + // Convert [1024]int8 to [1024]byte in Ptmget members + convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`) + b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte")) + + // Remove spare fields (e.g. in Statx_t) + spareFieldsRegex := regexp.MustCompile(`X__spare\S*`) + b = spareFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove cgo padding fields + removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`) + b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove padding, hidden, or unused fields + removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`) + b = removeFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove the first line of warning from cgo + b = b[bytes.IndexByte(b, '\n')+1:] + // Modify the command in the header to include: + // mkpost, our own warning, and a build tag. + replacement := fmt.Sprintf(`$1 | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build %s,%s`, goarch, goos) + cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`) + b = cgoCommandRegex.ReplaceAll(b, []byte(replacement)) + + // gofmt + b, err = format.Source(b) + if err != nil { + log.Fatal(err) + } + + os.Stdout.Write(b) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_pledge.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_pledge.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_pledge.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_pledge.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_unveil.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_unveil.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_unveil.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_unveil.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/pagesize_unix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/pagesize_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/pagesize_unix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/pagesize_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_unix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_unix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/str.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/str.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/str.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/str.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_bsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_bsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_bsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_bsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go new file mode 100644 index 00000000..75651057 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go @@ -0,0 +1,531 @@ +// 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. + +// DragonFly BSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import "unsafe" + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 + Rcf uint16 + Route [16]uint16 + raw RawSockaddrDatalink +} + +// Translate "kern.hostname" to []_C_int{0,1,2,3}. +func nametomib(name string) (mib []_C_int, err error) { + const siz = unsafe.Sizeof(mib[0]) + + // NOTE(rsc): It seems strange to set the buffer to have + // size CTL_MAXNAME+2 but use only CTL_MAXNAME + // as the size. I don't know why the +2 is here, but the + // kernel uses +2 for its own implementation of this function. + // I am scared that if we don't include the +2 here, the kernel + // will silently write 2 words farther than we specify + // and we'll get memory corruption. + var buf [CTL_MAXNAME + 2]_C_int + n := uintptr(CTL_MAXNAME) * siz + + p := (*byte)(unsafe.Pointer(&buf[0])) + bytes, err := ByteSliceFromString(name) + if err != nil { + return nil, err + } + + // Magic sysctl: "setting" 0.3 to a string name + // lets you read back the array of integers form. + if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { + return nil, err + } + return buf[0 : n/siz], nil +} + +//sysnb pipe() (r int, w int, err error) + +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + p[0], p[1], err = pipe() + return +} + +//sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) +func Pread(fd int, p []byte, offset int64) (n int, err error) { + return extpread(fd, p, 0, offset) +} + +//sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + return extpwrite(fd, p, 0, offset) +} + +func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) { + var rsa RawSockaddrAny + var len _Socklen = SizeofSockaddrAny + nfd, err = accept4(fd, &rsa, &len, flags) + if err != nil { + return + } + if len > SizeofSockaddrAny { + panic("RawSockaddrAny too small") + } + sa, err = anyToSockaddr(fd, &rsa) + if err != nil { + Close(nfd) + nfd = 0 + } + return +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { + var _p0 unsafe.Pointer + var bufsize uintptr + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + } + r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func sysctlUname(mib []_C_int, old *byte, oldlen *uintptr) error { + err := sysctl(mib, old, oldlen, nil, 0) + if err != nil { + // Utsname members on Dragonfly are only 32 bytes and + // the syscall returns ENOMEM in case the actual value + // is longer. + if err == ENOMEM { + err = nil + } + } + return err +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctlUname(mib, &uname.Sysname[0], &n); err != nil { + return err + } + uname.Sysname[unsafe.Sizeof(uname.Sysname)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctlUname(mib, &uname.Nodename[0], &n); err != nil { + return err + } + uname.Nodename[unsafe.Sizeof(uname.Nodename)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctlUname(mib, &uname.Release[0], &n); err != nil { + return err + } + uname.Release[unsafe.Sizeof(uname.Release)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctlUname(mib, &uname.Version[0], &n); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctlUname(mib, &uname.Machine[0], &n); err != nil { + return err + } + uname.Machine[unsafe.Sizeof(uname.Machine)-1] = 0 + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fstatfs(fd int, stat *Statfs_t) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) +//sys Getdtablesize() (size int) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(fd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sys Setlogin(name string) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setresgid(rgid int, egid int, sgid int) (err error) +//sysnb Setresuid(ruid int, euid int, suid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Statfs(path string, stat *Statfs_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Undelete(path string) (err error) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + * TODO(jsing): Update this list for DragonFly. + */ +// Profil +// Sigaction +// Sigprocmask +// Getlogin +// Sigpending +// Sigaltstack +// Reboot +// Execve +// Vfork +// Sbrk +// Sstk +// Ovadvise +// Mincore +// Setitimer +// Swapon +// Select +// Sigsuspend +// Readv +// Writev +// Nfssvc +// Getfh +// Quotactl +// Mount +// Csops +// Waitid +// Add_profil +// Kdebug_trace +// Sigreturn +// Atsocket +// Kqueue_from_portset_np +// Kqueue_portset +// Getattrlist +// Setattrlist +// Getdirentriesattr +// Searchfs +// Delete +// Copyfile +// Watchevent +// Waitevent +// Modwatch +// Getxattr +// Fgetxattr +// Setxattr +// Fsetxattr +// Removexattr +// Fremovexattr +// Listxattr +// Flistxattr +// Fsctl +// Initgroups +// Posix_spawn +// Nfsclnt +// Fhopen +// Minherit +// Semsys +// Msgsys +// Shmsys +// Semctl +// Semget +// Semop +// Msgctl +// Msgget +// Msgsnd +// Msgrcv +// Shmat +// Shmctl +// Shmdt +// Shmget +// Shm_open +// Shm_unlink +// Sem_open +// Sem_close +// Sem_unlink +// Sem_wait +// Sem_trywait +// Sem_post +// Sem_getvalue +// Sem_init +// Sem_destroy +// Open_extended +// Umask_extended +// Stat_extended +// Lstat_extended +// Fstat_extended +// Chmod_extended +// Fchmod_extended +// Access_extended +// Settid +// Gettid +// Setsgroups +// Getsgroups +// Setwgroups +// Getwgroups +// Mkfifo_extended +// Mkdir_extended +// Identitysvc +// Shared_region_check_np +// Shared_region_map_np +// __pthread_mutex_destroy +// __pthread_mutex_init +// __pthread_mutex_lock +// __pthread_mutex_trylock +// __pthread_mutex_unlock +// __pthread_cond_init +// __pthread_cond_destroy +// __pthread_cond_broadcast +// __pthread_cond_signal +// Setsid_with_pid +// __pthread_cond_timedwait +// Aio_fsync +// Aio_return +// Aio_suspend +// Aio_cancel +// Aio_error +// Aio_read +// Aio_write +// Lio_listio +// __pthread_cond_wait +// Iopolicysys +// __pthread_kill +// __pthread_sigmask +// __sigwait +// __disable_threadsignal +// __pthread_markcancel +// __pthread_canceled +// __semwait_signal +// Proc_info +// Stat64_extended +// Lstat64_extended +// Fstat64_extended +// __pthread_chdir +// __pthread_fchdir +// Audit +// Auditon +// Getauid +// Setauid +// Getaudit +// Setaudit +// Getaudit_addr +// Setaudit_addr +// Auditctl +// Bsdthread_create +// Bsdthread_terminate +// Stack_snapshot +// Bsdthread_register +// Workq_open +// Workq_ops +// __mac_execve +// __mac_syscall +// __mac_get_file +// __mac_set_file +// __mac_get_link +// __mac_set_link +// __mac_get_proc +// __mac_set_proc +// __mac_get_fd +// __mac_set_fd +// __mac_get_pid +// __mac_get_lcid +// __mac_get_lctx +// __mac_set_lctx +// Setlcid +// Read_nocancel +// Write_nocancel +// Open_nocancel +// Close_nocancel +// Wait4_nocancel +// Recvmsg_nocancel +// Sendmsg_nocancel +// Recvfrom_nocancel +// Accept_nocancel +// Fcntl_nocancel +// Select_nocancel +// Fsync_nocancel +// Connect_nocancel +// Sigsuspend_nocancel +// Readv_nocancel +// Writev_nocancel +// Sendto_nocancel +// Pread_nocancel +// Pwrite_nocancel +// Waitid_nocancel +// Msgsnd_nocancel +// Msgrcv_nocancel +// Sem_wait_nocancel +// Aio_suspend_nocancel +// __sigwait_nocancel +// __semwait_signal_nocancel +// __mac_mount +// __mac_get_mount +// __mac_getfsstat diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go new file mode 100644 index 00000000..059327a3 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go @@ -0,0 +1,615 @@ +// Copyright 2009,2010 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. + +// NetBSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import ( + "runtime" + "syscall" + "unsafe" +) + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 + raw RawSockaddrDatalink +} + +func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) + +func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) { + var olen uintptr + + // Get a list of all sysctl nodes below the given MIB by performing + // a sysctl for the given MIB with CTL_QUERY appended. + mib = append(mib, CTL_QUERY) + qnode := Sysctlnode{Flags: SYSCTL_VERS_1} + qp := (*byte)(unsafe.Pointer(&qnode)) + sz := unsafe.Sizeof(qnode) + if err = sysctl(mib, nil, &olen, qp, sz); err != nil { + return nil, err + } + + // Now that we know the size, get the actual nodes. + nodes = make([]Sysctlnode, olen/sz) + np := (*byte)(unsafe.Pointer(&nodes[0])) + if err = sysctl(mib, np, &olen, qp, sz); err != nil { + return nil, err + } + + return nodes, nil +} + +func nametomib(name string) (mib []_C_int, err error) { + // Split name into components. + var parts []string + last := 0 + for i := 0; i < len(name); i++ { + if name[i] == '.' { + parts = append(parts, name[last:i]) + last = i + 1 + } + } + parts = append(parts, name[last:]) + + // Discover the nodes and construct the MIB OID. + for partno, part := range parts { + nodes, err := sysctlNodes(mib) + if err != nil { + return nil, err + } + for _, node := range nodes { + n := make([]byte, 0) + for i := range node.Name { + if node.Name[i] != 0 { + n = append(n, byte(node.Name[i])) + } + } + if string(n) == part { + mib = append(mib, _C_int(node.Num)) + break + } + } + if len(mib) != partno+1 { + return nil, EINVAL + } + } + + return mib, nil +} + +func SysctlClockinfo(name string) (*Clockinfo, error) { + mib, err := sysctlmib(name) + if err != nil { + return nil, err + } + + n := uintptr(SizeofClockinfo) + var ci Clockinfo + if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { + return nil, err + } + if n != SizeofClockinfo { + return nil, EIO + } + return &ci, nil +} + +//sysnb pipe() (fd1 int, fd2 int, err error) +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + p[0], p[1], err = pipe() + return +} + +//sys getdents(fd int, buf []byte) (n int, err error) +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + return getdents(fd, buf) +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +// TODO +func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + return -1, ENOSYS +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) { + var value Ptmget + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + runtime.KeepAlive(value) + return &value, err +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { + return err + } + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) +//sys ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) +//sys ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) +//sys ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_POSIX_FADVISE +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mkfifoat(dirfd int, path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys Pread(fd int, p []byte, offset int64) (n int, err error) +//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Renameat(fromfd int, from string, tofd int, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + */ +// ____semctl13 +// __clone +// __fhopen40 +// __fhstat40 +// __fhstatvfs140 +// __fstat30 +// __getcwd +// __getfh30 +// __getlogin +// __lstat30 +// __mount50 +// __msgctl13 +// __msync13 +// __ntp_gettime30 +// __posix_chown +// __posix_fchown +// __posix_lchown +// __posix_rename +// __setlogin +// __shmctl13 +// __sigaction_sigtramp +// __sigaltstack14 +// __sigpending14 +// __sigprocmask14 +// __sigsuspend14 +// __sigtimedwait +// __stat30 +// __syscall +// __vfork14 +// _ksem_close +// _ksem_destroy +// _ksem_getvalue +// _ksem_init +// _ksem_open +// _ksem_post +// _ksem_trywait +// _ksem_unlink +// _ksem_wait +// _lwp_continue +// _lwp_create +// _lwp_ctl +// _lwp_detach +// _lwp_exit +// _lwp_getname +// _lwp_getprivate +// _lwp_kill +// _lwp_park +// _lwp_self +// _lwp_setname +// _lwp_setprivate +// _lwp_suspend +// _lwp_unpark +// _lwp_unpark_all +// _lwp_wait +// _lwp_wakeup +// _pset_bind +// _sched_getaffinity +// _sched_getparam +// _sched_setaffinity +// _sched_setparam +// acct +// aio_cancel +// aio_error +// aio_fsync +// aio_read +// aio_return +// aio_suspend +// aio_write +// break +// clock_getres +// clock_gettime +// clock_settime +// compat_09_ogetdomainname +// compat_09_osetdomainname +// compat_09_ouname +// compat_10_omsgsys +// compat_10_osemsys +// compat_10_oshmsys +// compat_12_fstat12 +// compat_12_getdirentries +// compat_12_lstat12 +// compat_12_msync +// compat_12_oreboot +// compat_12_oswapon +// compat_12_stat12 +// compat_13_sigaction13 +// compat_13_sigaltstack13 +// compat_13_sigpending13 +// compat_13_sigprocmask13 +// compat_13_sigreturn13 +// compat_13_sigsuspend13 +// compat_14___semctl +// compat_14_msgctl +// compat_14_shmctl +// compat_16___sigaction14 +// compat_16___sigreturn14 +// compat_20_fhstatfs +// compat_20_fstatfs +// compat_20_getfsstat +// compat_20_statfs +// compat_30___fhstat30 +// compat_30___fstat13 +// compat_30___lstat13 +// compat_30___stat13 +// compat_30_fhopen +// compat_30_fhstat +// compat_30_fhstatvfs1 +// compat_30_getdents +// compat_30_getfh +// compat_30_ntp_gettime +// compat_30_socket +// compat_40_mount +// compat_43_fstat43 +// compat_43_lstat43 +// compat_43_oaccept +// compat_43_ocreat +// compat_43_oftruncate +// compat_43_ogetdirentries +// compat_43_ogetdtablesize +// compat_43_ogethostid +// compat_43_ogethostname +// compat_43_ogetkerninfo +// compat_43_ogetpagesize +// compat_43_ogetpeername +// compat_43_ogetrlimit +// compat_43_ogetsockname +// compat_43_okillpg +// compat_43_olseek +// compat_43_ommap +// compat_43_oquota +// compat_43_orecv +// compat_43_orecvfrom +// compat_43_orecvmsg +// compat_43_osend +// compat_43_osendmsg +// compat_43_osethostid +// compat_43_osethostname +// compat_43_osetrlimit +// compat_43_osigblock +// compat_43_osigsetmask +// compat_43_osigstack +// compat_43_osigvec +// compat_43_otruncate +// compat_43_owait +// compat_43_stat43 +// execve +// extattr_delete_fd +// extattr_delete_file +// extattr_delete_link +// extattr_get_fd +// extattr_get_file +// extattr_get_link +// extattr_list_fd +// extattr_list_file +// extattr_list_link +// extattr_set_fd +// extattr_set_file +// extattr_set_link +// extattrctl +// fchroot +// fdatasync +// fgetxattr +// fktrace +// flistxattr +// fork +// fremovexattr +// fsetxattr +// fstatvfs1 +// fsync_range +// getcontext +// getitimer +// getvfsstat +// getxattr +// ktrace +// lchflags +// lchmod +// lfs_bmapv +// lfs_markv +// lfs_segclean +// lfs_segwait +// lgetxattr +// lio_listio +// listxattr +// llistxattr +// lremovexattr +// lseek +// lsetxattr +// lutimes +// madvise +// mincore +// minherit +// modctl +// mq_close +// mq_getattr +// mq_notify +// mq_open +// mq_receive +// mq_send +// mq_setattr +// mq_timedreceive +// mq_timedsend +// mq_unlink +// mremap +// msgget +// msgrcv +// msgsnd +// nfssvc +// ntp_adjtime +// pmc_control +// pmc_get_info +// pollts +// preadv +// profil +// pselect +// pset_assign +// pset_create +// pset_destroy +// ptrace +// pwritev +// quotactl +// rasctl +// readv +// reboot +// removexattr +// sa_enable +// sa_preempt +// sa_register +// sa_setconcurrency +// sa_stacks +// sa_yield +// sbrk +// sched_yield +// semconfig +// semget +// semop +// setcontext +// setitimer +// setxattr +// shmat +// shmdt +// shmget +// sstk +// statvfs1 +// swapctl +// sysarch +// syscall +// timer_create +// timer_delete +// timer_getoverrun +// timer_gettime +// timer_settime +// undelete +// utrace +// uuidgen +// vadvise +// vfork +// writev diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go new file mode 100644 index 00000000..5a398f81 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go @@ -0,0 +1,392 @@ +// Copyright 2009,2010 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. + +// OpenBSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import ( + "sort" + "syscall" + "unsafe" +) + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [24]int8 + raw RawSockaddrDatalink +} + +func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) + +func nametomib(name string) (mib []_C_int, err error) { + i := sort.Search(len(sysctlMib), func(i int) bool { + return sysctlMib[i].ctlname >= name + }) + if i < len(sysctlMib) && sysctlMib[i].ctlname == name { + return sysctlMib[i].ctloid, nil + } + return nil, EINVAL +} + +func SysctlUvmexp(name string) (*Uvmexp, error) { + mib, err := sysctlmib(name) + if err != nil { + return nil, err + } + + n := uintptr(SizeofUvmexp) + var u Uvmexp + if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil { + return nil, err + } + if n != SizeofUvmexp { + return nil, EIO + } + return &u, nil +} + +//sysnb pipe(p *[2]_C_int) (err error) +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + var pp [2]_C_int + err = pipe(&pp) + p[0] = int(pp[0]) + p[1] = int(pp[1]) + return +} + +//sys getdents(fd int, buf []byte) (n int, err error) +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + return getdents(fd, buf) +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +// TODO +func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + return -1, ENOSYS +} + +func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { + var _p0 unsafe.Pointer + var bufsize uintptr + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + } + r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +//sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) + +func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + if len(fds) == 0 { + return ppoll(nil, 0, timeout, sigmask) + } + return ppoll(&fds[0], len(fds), timeout, sigmask) +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { + return err + } + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fstatfs(fd int, stat *Statfs_t) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrtable() (rtable int, err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mkfifoat(dirfd int, path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys Pread(fd int, p []byte, offset int64) (n int, err error) +//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Renameat(fromfd int, from string, tofd int, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sys Setlogin(name string) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setresgid(rgid int, egid int, sgid int) (err error) +//sysnb Setresuid(ruid int, euid int, suid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setrtable(rtable int) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Statfs(path string, stat *Statfs_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + */ +// __getcwd +// __semctl +// __syscall +// __sysctl +// adjfreq +// break +// clock_getres +// clock_gettime +// clock_settime +// closefrom +// execve +// fcntl +// fhopen +// fhstat +// fhstatfs +// fork +// futimens +// getfh +// getgid +// getitimer +// getlogin +// getresgid +// getresuid +// getthrid +// ktrace +// lfs_bmapv +// lfs_markv +// lfs_segclean +// lfs_segwait +// mincore +// minherit +// mount +// mquery +// msgctl +// msgget +// msgrcv +// msgsnd +// nfssvc +// nnpfspioctl +// preadv +// profil +// pwritev +// quotactl +// readv +// reboot +// renameat +// rfork +// sched_yield +// semget +// semop +// setgroups +// setitimer +// setsockopt +// shmat +// shmctl +// shmdt +// shmget +// sigaction +// sigaltstack +// sigpending +// sigprocmask +// sigreturn +// sigsuspend +// sysarch +// syscall +// threxit +// thrsigdivert +// thrsleep +// thrwakeup +// vfork +// writev diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_unix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_unix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go new file mode 100644 index 00000000..1c70d1b6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go @@ -0,0 +1,15 @@ +// 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. + +// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build !gccgo,!ppc64le,!ppc64 + +package unix + +import "syscall" + +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go new file mode 100644 index 00000000..86dc765a --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go @@ -0,0 +1,24 @@ +// Copyright 2018 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. + +// +build linux +// +build ppc64le ppc64 +// +build !gccgo + +package unix + +import "syscall" + +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.Syscall(trap, a1, a2, a3) +} +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.Syscall6(trap, a1, a2, a3, a4, a5, a6) +} +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.RawSyscall(trap, a1, a2, a3) +} +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.RawSyscall6(trap, a1, a2, a3, a4, a5, a6) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/timestruct.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/timestruct.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/timestruct.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/timestruct.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_aix.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_aix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_aix.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_aix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_darwin.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_darwin.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_darwin.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_darwin.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_dragonfly.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_dragonfly.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_dragonfly.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_dragonfly.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go new file mode 100644 index 00000000..74707989 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go @@ -0,0 +1,356 @@ +// 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. + +// +build ignore + +/* +Input to cgo -godefs. See README.md +*/ + +// +godefs map struct_in_addr [4]byte /* in_addr */ +// +godefs map struct_in6_addr [16]byte /* in6_addr */ + +package unix + +/* +#define _WANT_FREEBSD11_STAT 1 +#define _WANT_FREEBSD11_STATFS 1 +#define _WANT_FREEBSD11_DIRENT 1 +#define _WANT_FREEBSD11_KEVENT 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +union sockaddr_all { + struct sockaddr s1; // this one gets used for fields + struct sockaddr_in s2; // these pad it out + struct sockaddr_in6 s3; + struct sockaddr_un s4; + struct sockaddr_dl s5; +}; + +struct sockaddr_any { + struct sockaddr addr; + char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; +}; + +// This structure is a duplicate of if_data on FreeBSD 8-STABLE. +// See /usr/include/net/if.h. +struct if_data8 { + u_char ifi_type; + u_char ifi_physical; + u_char ifi_addrlen; + u_char ifi_hdrlen; + u_char ifi_link_state; + u_char ifi_spare_char1; + u_char ifi_spare_char2; + u_char ifi_datalen; + u_long ifi_mtu; + u_long ifi_metric; + u_long ifi_baudrate; + u_long ifi_ipackets; + u_long ifi_ierrors; + u_long ifi_opackets; + u_long ifi_oerrors; + u_long ifi_collisions; + u_long ifi_ibytes; + u_long ifi_obytes; + u_long ifi_imcasts; + u_long ifi_omcasts; + u_long ifi_iqdrops; + u_long ifi_noproto; + u_long ifi_hwassist; +// FIXME: these are now unions, so maybe need to change definitions? +#undef ifi_epoch + time_t ifi_epoch; +#undef ifi_lastchange + struct timeval ifi_lastchange; +}; + +// This structure is a duplicate of if_msghdr on FreeBSD 8-STABLE. +// See /usr/include/net/if.h. +struct if_msghdr8 { + u_short ifm_msglen; + u_char ifm_version; + u_char ifm_type; + int ifm_addrs; + int ifm_flags; + u_short ifm_index; + struct if_data8 ifm_data; +}; +*/ +import "C" + +// Machine characteristics + +const ( + SizeofPtr = C.sizeofPtr + SizeofShort = C.sizeof_short + SizeofInt = C.sizeof_int + SizeofLong = C.sizeof_long + SizeofLongLong = C.sizeof_longlong +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +// Time + +type Timespec C.struct_timespec + +type Timeval C.struct_timeval + +// Processes + +type Rusage C.struct_rusage + +type Rlimit C.struct_rlimit + +type _Gid_t C.gid_t + +// Files + +const ( + _statfsVersion = C.STATFS_VERSION + _dirblksiz = C.DIRBLKSIZ +) + +type Stat_t C.struct_stat + +type stat_freebsd11_t C.struct_freebsd11_stat + +type Statfs_t C.struct_statfs + +type statfs_freebsd11_t C.struct_freebsd11_statfs + +type Flock_t C.struct_flock + +type Dirent C.struct_dirent + +type dirent_freebsd11 C.struct_freebsd11_dirent + +type Fsid C.struct_fsid + +// File system limits + +const ( + PathMax = C.PATH_MAX +) + +// Advice to Fadvise + +const ( + FADV_NORMAL = C.POSIX_FADV_NORMAL + FADV_RANDOM = C.POSIX_FADV_RANDOM + FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL + FADV_WILLNEED = C.POSIX_FADV_WILLNEED + FADV_DONTNEED = C.POSIX_FADV_DONTNEED + FADV_NOREUSE = C.POSIX_FADV_NOREUSE +) + +// Sockets + +type RawSockaddrInet4 C.struct_sockaddr_in + +type RawSockaddrInet6 C.struct_sockaddr_in6 + +type RawSockaddrUnix C.struct_sockaddr_un + +type RawSockaddrDatalink C.struct_sockaddr_dl + +type RawSockaddr C.struct_sockaddr + +type RawSockaddrAny C.struct_sockaddr_any + +type _Socklen C.socklen_t + +type Linger C.struct_linger + +type Iovec C.struct_iovec + +type IPMreq C.struct_ip_mreq + +type IPMreqn C.struct_ip_mreqn + +type IPv6Mreq C.struct_ipv6_mreq + +type Msghdr C.struct_msghdr + +type Cmsghdr C.struct_cmsghdr + +type Inet6Pktinfo C.struct_in6_pktinfo + +type IPv6MTUInfo C.struct_ip6_mtuinfo + +type ICMPv6Filter C.struct_icmp6_filter + +const ( + SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in + SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 + SizeofSockaddrAny = C.sizeof_struct_sockaddr_any + SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un + SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl + SizeofLinger = C.sizeof_struct_linger + SizeofIPMreq = C.sizeof_struct_ip_mreq + SizeofIPMreqn = C.sizeof_struct_ip_mreqn + SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq + SizeofMsghdr = C.sizeof_struct_msghdr + SizeofCmsghdr = C.sizeof_struct_cmsghdr + SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo + SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo + SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter +) + +// Ptrace requests + +const ( + PTRACE_TRACEME = C.PT_TRACE_ME + PTRACE_CONT = C.PT_CONTINUE + PTRACE_KILL = C.PT_KILL +) + +// Events (kqueue, kevent) + +type Kevent_t C.struct_kevent_freebsd11 + +// Select + +type FdSet C.fd_set + +// Routing and interface messages + +const ( + sizeofIfMsghdr = C.sizeof_struct_if_msghdr + SizeofIfMsghdr = C.sizeof_struct_if_msghdr8 + sizeofIfData = C.sizeof_struct_if_data + SizeofIfData = C.sizeof_struct_if_data8 + SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr + SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr + SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr + SizeofRtMsghdr = C.sizeof_struct_rt_msghdr + SizeofRtMetrics = C.sizeof_struct_rt_metrics +) + +type ifMsghdr C.struct_if_msghdr + +type IfMsghdr C.struct_if_msghdr8 + +type ifData C.struct_if_data + +type IfData C.struct_if_data8 + +type IfaMsghdr C.struct_ifa_msghdr + +type IfmaMsghdr C.struct_ifma_msghdr + +type IfAnnounceMsghdr C.struct_if_announcemsghdr + +type RtMsghdr C.struct_rt_msghdr + +type RtMetrics C.struct_rt_metrics + +// Berkeley packet filter + +const ( + SizeofBpfVersion = C.sizeof_struct_bpf_version + SizeofBpfStat = C.sizeof_struct_bpf_stat + SizeofBpfZbuf = C.sizeof_struct_bpf_zbuf + SizeofBpfProgram = C.sizeof_struct_bpf_program + SizeofBpfInsn = C.sizeof_struct_bpf_insn + SizeofBpfHdr = C.sizeof_struct_bpf_hdr + SizeofBpfZbufHeader = C.sizeof_struct_bpf_zbuf_header +) + +type BpfVersion C.struct_bpf_version + +type BpfStat C.struct_bpf_stat + +type BpfZbuf C.struct_bpf_zbuf + +type BpfProgram C.struct_bpf_program + +type BpfInsn C.struct_bpf_insn + +type BpfHdr C.struct_bpf_hdr + +type BpfZbufHeader C.struct_bpf_zbuf_header + +// Terminal handling + +type Termios C.struct_termios + +type Winsize C.struct_winsize + +// fchmodat-like syscalls. + +const ( + AT_FDCWD = C.AT_FDCWD + AT_REMOVEDIR = C.AT_REMOVEDIR + AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW + AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW +) + +// poll + +type PollFd C.struct_pollfd + +const ( + POLLERR = C.POLLERR + POLLHUP = C.POLLHUP + POLLIN = C.POLLIN + POLLINIGNEOF = C.POLLINIGNEOF + POLLNVAL = C.POLLNVAL + POLLOUT = C.POLLOUT + POLLPRI = C.POLLPRI + POLLRDBAND = C.POLLRDBAND + POLLRDNORM = C.POLLRDNORM + POLLWRBAND = C.POLLWRBAND + POLLWRNORM = C.POLLWRNORM +) + +// Capabilities + +type CapRights C.struct_cap_rights + +// Uname + +type Utsname C.struct_utsname diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go new file mode 100644 index 00000000..2dd4f954 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go @@ -0,0 +1,289 @@ +// 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. + +// +build ignore + +/* +Input to cgo -godefs. See README.md +*/ + +// +godefs map struct_in_addr [4]byte /* in_addr */ +// +godefs map struct_in6_addr [16]byte /* in6_addr */ + +package unix + +/* +#define KERNEL +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +union sockaddr_all { + struct sockaddr s1; // this one gets used for fields + struct sockaddr_in s2; // these pad it out + struct sockaddr_in6 s3; + struct sockaddr_un s4; + struct sockaddr_dl s5; +}; + +struct sockaddr_any { + struct sockaddr addr; + char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; +}; + +*/ +import "C" + +// Machine characteristics + +const ( + SizeofPtr = C.sizeofPtr + SizeofShort = C.sizeof_short + SizeofInt = C.sizeof_int + SizeofLong = C.sizeof_long + SizeofLongLong = C.sizeof_longlong +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +// Time + +type Timespec C.struct_timespec + +type Timeval C.struct_timeval + +// Processes + +type Rusage C.struct_rusage + +type Rlimit C.struct_rlimit + +type _Gid_t C.gid_t + +// Files + +type Stat_t C.struct_stat + +type Statfs_t C.struct_statfs + +type Flock_t C.struct_flock + +type Dirent C.struct_dirent + +type Fsid C.fsid_t + +// File system limits + +const ( + PathMax = C.PATH_MAX +) + +// Advice to Fadvise + +const ( + FADV_NORMAL = C.POSIX_FADV_NORMAL + FADV_RANDOM = C.POSIX_FADV_RANDOM + FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL + FADV_WILLNEED = C.POSIX_FADV_WILLNEED + FADV_DONTNEED = C.POSIX_FADV_DONTNEED + FADV_NOREUSE = C.POSIX_FADV_NOREUSE +) + +// Sockets + +type RawSockaddrInet4 C.struct_sockaddr_in + +type RawSockaddrInet6 C.struct_sockaddr_in6 + +type RawSockaddrUnix C.struct_sockaddr_un + +type RawSockaddrDatalink C.struct_sockaddr_dl + +type RawSockaddr C.struct_sockaddr + +type RawSockaddrAny C.struct_sockaddr_any + +type _Socklen C.socklen_t + +type Linger C.struct_linger + +type Iovec C.struct_iovec + +type IPMreq C.struct_ip_mreq + +type IPv6Mreq C.struct_ipv6_mreq + +type Msghdr C.struct_msghdr + +type Cmsghdr C.struct_cmsghdr + +type Inet6Pktinfo C.struct_in6_pktinfo + +type IPv6MTUInfo C.struct_ip6_mtuinfo + +type ICMPv6Filter C.struct_icmp6_filter + +const ( + SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in + SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 + SizeofSockaddrAny = C.sizeof_struct_sockaddr_any + SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un + SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl + SizeofLinger = C.sizeof_struct_linger + SizeofIPMreq = C.sizeof_struct_ip_mreq + SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq + SizeofMsghdr = C.sizeof_struct_msghdr + SizeofCmsghdr = C.sizeof_struct_cmsghdr + SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo + SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo + SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter +) + +// Ptrace requests + +const ( + PTRACE_TRACEME = C.PT_TRACE_ME + PTRACE_CONT = C.PT_CONTINUE + PTRACE_KILL = C.PT_KILL +) + +// Events (kqueue, kevent) + +type Kevent_t C.struct_kevent + +// Select + +type FdSet C.fd_set + +// Routing and interface messages + +const ( + SizeofIfMsghdr = C.sizeof_struct_if_msghdr + SizeofIfData = C.sizeof_struct_if_data + SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr + SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr + SizeofRtMsghdr = C.sizeof_struct_rt_msghdr + SizeofRtMetrics = C.sizeof_struct_rt_metrics +) + +type IfMsghdr C.struct_if_msghdr + +type IfData C.struct_if_data + +type IfaMsghdr C.struct_ifa_msghdr + +type IfAnnounceMsghdr C.struct_if_announcemsghdr + +type RtMsghdr C.struct_rt_msghdr + +type RtMetrics C.struct_rt_metrics + +type Mclpool C.struct_mclpool + +// Berkeley packet filter + +const ( + SizeofBpfVersion = C.sizeof_struct_bpf_version + SizeofBpfStat = C.sizeof_struct_bpf_stat + SizeofBpfProgram = C.sizeof_struct_bpf_program + SizeofBpfInsn = C.sizeof_struct_bpf_insn + SizeofBpfHdr = C.sizeof_struct_bpf_hdr +) + +type BpfVersion C.struct_bpf_version + +type BpfStat C.struct_bpf_stat + +type BpfProgram C.struct_bpf_program + +type BpfInsn C.struct_bpf_insn + +type BpfHdr C.struct_bpf_hdr + +type BpfTimeval C.struct_bpf_timeval + +// Terminal handling + +type Termios C.struct_termios + +type Winsize C.struct_winsize + +type Ptmget C.struct_ptmget + +// fchmodat-like syscalls. + +const ( + AT_FDCWD = C.AT_FDCWD + AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW +) + +// poll + +type PollFd C.struct_pollfd + +const ( + POLLERR = C.POLLERR + POLLHUP = C.POLLHUP + POLLIN = C.POLLIN + POLLNVAL = C.POLLNVAL + POLLOUT = C.POLLOUT + POLLPRI = C.POLLPRI + POLLRDBAND = C.POLLRDBAND + POLLRDNORM = C.POLLRDNORM + POLLWRBAND = C.POLLWRBAND + POLLWRNORM = C.POLLWRNORM +) + +// Sysctl + +type Sysctlnode C.struct_sysctlnode + +// Uname + +type Utsname C.struct_utsname + +// Clockinfo + +const SizeofClockinfo = C.sizeof_struct_clockinfo + +type Clockinfo C.struct_clockinfo diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_openbsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_openbsd.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_openbsd.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_openbsd.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_solaris.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_solaris.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_solaris.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_solaris.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go new file mode 100644 index 00000000..30c1d71f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go @@ -0,0 +1,240 @@ +// Copyright 2018 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. + +// +build freebsd netbsd + +package unix + +import ( + "strings" + "unsafe" +) + +// Derive extattr namespace and attribute name + +func xattrnamespace(fullattr string) (ns int, attr string, err error) { + s := strings.IndexByte(fullattr, '.') + if s == -1 { + return -1, "", ENOATTR + } + + namespace := fullattr[0:s] + attr = fullattr[s+1:] + + switch namespace { + case "user": + return EXTATTR_NAMESPACE_USER, attr, nil + case "system": + return EXTATTR_NAMESPACE_SYSTEM, attr, nil + default: + return -1, "", ENOATTR + } +} + +func initxattrdest(dest []byte, idx int) (d unsafe.Pointer) { + if len(dest) > idx { + return unsafe.Pointer(&dest[idx]) + } else { + return unsafe.Pointer(_zero) + } +} + +// FreeBSD and NetBSD implement their own syscalls to handle extended attributes + +func Getxattr(file string, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetFile(file, nsid, a, uintptr(d), destsize) +} + +func Fgetxattr(fd int, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetFd(fd, nsid, a, uintptr(d), destsize) +} + +func Lgetxattr(link string, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetLink(link, nsid, a, uintptr(d), destsize) +} + +// flags are unused on FreeBSD + +func Fsetxattr(fd int, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetFd(fd, nsid, a, uintptr(d), datasiz) + return +} + +func Setxattr(file string, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetFile(file, nsid, a, uintptr(d), datasiz) + return +} + +func Lsetxattr(link string, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetLink(link, nsid, a, uintptr(d), datasiz) + return +} + +func Removexattr(file string, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteFile(file, nsid, a) + return +} + +func Fremovexattr(fd int, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteFd(fd, nsid, a) + return +} + +func Lremovexattr(link string, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteLink(link, nsid, a) + return +} + +func Listxattr(file string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + // FreeBSD won't allow you to list xattrs from multiple namespaces + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListFile(file, nsid, uintptr(d), destsiz) + + /* Errors accessing system attrs are ignored so that + * we can implement the Linux-like behavior of omitting errors that + * we don't have read permissions on + * + * Linux will still error if we ask for user attributes on a file that + * we don't have read permissions on, so don't ignore those errors + */ + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} + +func Flistxattr(fd int, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListFd(fd, nsid, uintptr(d), destsiz) + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} + +func Llistxattr(link string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListLink(link, nsid, uintptr(d), destsiz) + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptrace386_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptrace386_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptrace386_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptrace386_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracearm_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracearm_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracearm_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracearm_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemips_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemips_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemips_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemips_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go new file mode 100644 index 00000000..96a67134 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go @@ -0,0 +1,1639 @@ +// mksyscall.pl -dragonfly -tags dragonfly,amd64 syscall_bsd.go syscall_dragonfly.go syscall_dragonfly_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build dragonfly,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (r int, w int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + r = int(r0) + w = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func extpread(fd int, p []byte, flags int, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_EXTPREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_EXTPWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getdtablesize() (size int) { + r0, _, _ := Syscall(SYS_GETDTABLESIZE, 0, 0, 0) + size = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(fd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Undelete(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNDELETE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) { + r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go new file mode 100644 index 00000000..9ed7c71f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -l32 -netbsd -tags netbsd,386 syscall_bsd.go syscall_netbsd.go syscall_netbsd_386.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,386 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall9(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), 0, uintptr(length), uintptr(length>>32), uintptr(advice), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go new file mode 100644 index 00000000..613b7fd9 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -netbsd -tags netbsd,amd64 syscall_bsd.go syscall_netbsd.go syscall_netbsd_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall6(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), 0, uintptr(length), uintptr(advice)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go new file mode 100644 index 00000000..08475087 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -l32 -netbsd -arm -tags netbsd,arm syscall_bsd.go syscall_netbsd.go syscall_netbsd_arm.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,arm + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall9(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), 0, uintptr(length), uintptr(length>>32), uintptr(advice), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go new file mode 100644 index 00000000..414cd13c --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -l32 -openbsd -tags openbsd,386 syscall_bsd.go syscall_openbsd.go syscall_openbsd_386.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,386 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go new file mode 100644 index 00000000..846f5fa6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -openbsd -tags openbsd,amd64 syscall_bsd.go syscall_openbsd.go syscall_openbsd_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go new file mode 100644 index 00000000..59911659 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -l32 -openbsd -arm -tags openbsd,arm syscall_bsd.go syscall_openbsd.go syscall_openbsd_arm.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,arm + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go new file mode 100644 index 00000000..c146c1ad --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go @@ -0,0 +1,603 @@ +// cgo -godefs types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build 386,freebsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int32 + Nsec int32 +} + +type Timeval struct { + Sec int32 + Usec int32 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim_ext int32 + Atim Timespec + Mtim_ext int32 + Mtim Timespec + Ctim_ext int32 + Ctim Timespec + Btim_ext int32 + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec + _ [8]byte +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter int16 + Flags uint16 + Fflags uint32 + Data int32 + Udata *byte +} + +type FdSet struct { + Bits [32]uint32 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0x60 + sizeofIfData = 0x98 + SizeofIfData = 0x50 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x5c + SizeofRtMetrics = 0x38 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint32 + Metric uint32 + Baudrate uint32 + Ipackets uint32 + Ierrors uint32 + Opackets uint32 + Oerrors uint32 + Collisions uint32 + Ibytes uint32 + Obytes uint32 + Imcasts uint32 + Omcasts uint32 + Iqdrops uint32 + Noproto uint32 + Hwassist uint32 + Epoch int32 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint32 + Mtu uint32 + Hopcount uint32 + Expire uint32 + Recvpipe uint32 + Sendpipe uint32 + Ssthresh uint32 + Rtt uint32 + Rttvar uint32 + Pksent uint32 + Weight uint32 + Filler [3]uint32 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0xc + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint32 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [2]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go new file mode 100644 index 00000000..ac33a8dd --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go @@ -0,0 +1,602 @@ +// cgo -godefs types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build amd64,freebsd + +package unix + +const ( + SizeofPtr = 0x8 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x8 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int64 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint64 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + _ [4]byte + Iov *Iovec + Iovlen int32 + _ [4]byte + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x30 + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint64 + Filter int16 + Flags uint16 + Fflags uint32 + Data int64 + Udata *byte +} + +type FdSet struct { + Bits [16]uint64 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0xa8 + sizeofIfData = 0x98 + SizeofIfData = 0x98 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x98 + SizeofRtMetrics = 0x70 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Hwassist uint64 + Epoch int64 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint64 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Expire uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Pksent uint64 + Weight uint64 + Filler [3]uint64 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0x18 + SizeofBpfProgram = 0x10 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint64 +} + +type BpfProgram struct { + Len uint32 + _ [4]byte + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go new file mode 100644 index 00000000..e27511a6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go @@ -0,0 +1,602 @@ +// cgo -godefs -- -fsigned-char types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build arm,freebsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 + _ [4]byte +} + +type Timeval struct { + Sec int64 + Usec int32 + _ [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter int16 + Flags uint16 + Fflags uint32 + Data int32 + Udata *byte +} + +type FdSet struct { + Bits [32]uint32 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0x70 + sizeofIfData = 0x98 + SizeofIfData = 0x60 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x5c + SizeofRtMetrics = 0x38 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint32 + Metric uint32 + Baudrate uint32 + Ipackets uint32 + Ierrors uint32 + Opackets uint32 + Oerrors uint32 + Collisions uint32 + Ibytes uint32 + Obytes uint32 + Imcasts uint32 + Omcasts uint32 + Iqdrops uint32 + Noproto uint32 + Hwassist uint32 + _ [4]byte + Epoch int64 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint32 + Mtu uint32 + Hopcount uint32 + Expire uint32 + Recvpipe uint32 + Sendpipe uint32 + Ssthresh uint32 + Rtt uint32 + Rttvar uint32 + Pksent uint32 + Weight uint32 + Filler [3]uint32 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0xc + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint32 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go new file mode 100644 index 00000000..2dae0c17 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go @@ -0,0 +1,465 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build 386,netbsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 +} + +type Timeval struct { + Sec int64 + Usec int32 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter uint32 + Flags uint32 + Fflags uint32 + Data int64 + Udata int32 +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x84 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData + Pad_cgo_1 [4]byte +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [2]byte +} + +type BpfTimeval struct { + Sec int32 + Usec int32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go new file mode 100644 index 00000000..1f0e76c0 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go @@ -0,0 +1,472 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build amd64,netbsd + +package unix + +const ( + SizeofPtr = 0x8 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x8 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int32 + Pad_cgo_0 [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Pad_cgo_0 [4]byte + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Pad_cgo_1 [4]byte + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 + Pad_cgo_2 [4]byte +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint64 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Pad_cgo_0 [4]byte + Iov *Iovec + Iovlen int32 + Pad_cgo_1 [4]byte + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x30 + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint64 + Filter uint32 + Flags uint32 + Fflags uint32 + Pad_cgo_0 [4]byte + Data int64 + Udata int64 +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x88 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x10 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Pad_cgo_0 [4]byte + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [6]byte +} + +type BpfTimeval struct { + Sec int64 + Usec int64 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go new file mode 100644 index 00000000..53f2159c --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go @@ -0,0 +1,470 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build arm,netbsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 + Pad_cgo_0 [4]byte +} + +type Timeval struct { + Sec int64 + Usec int32 + Pad_cgo_0 [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Pad_cgo_0 [4]byte + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Pad_cgo_1 [4]byte + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 + Pad_cgo_2 [4]byte +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter uint32 + Flags uint32 + Fflags uint32 + Data int64 + Udata int32 + Pad_cgo_0 [4]byte +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x88 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [2]byte +} + +type BpfTimeval struct { + Sec int32 + Usec int32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/AUTHORS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/AUTHORS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/AUTHORS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/AUTHORS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/CONTRIBUTORS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/CONTRIBUTORS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/CONTRIBUTORS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/CONTRIBUTORS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/PATENTS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/PATENTS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/PATENTS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/PATENTS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/transform/transform.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/transform/transform.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/transform/transform.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/transform/transform.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bidi.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bidi.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bidi.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bidi.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bracket.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bracket.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bracket.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bracket.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/core.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/core.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/core.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/core.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/prop.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/prop.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/prop.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/prop.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/trieval.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/trieval.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/trieval.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/trieval.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/composition.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/composition.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/composition.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/composition.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/forminfo.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/forminfo.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/forminfo.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/forminfo.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/input.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/input.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/input.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/input.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/iter.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/iter.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/iter.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/iter.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/maketables.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/maketables.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/maketables.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/maketables.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/normalize.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/normalize.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/normalize.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/normalize.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/readwriter.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/readwriter.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/readwriter.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/readwriter.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/transform.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/transform.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/transform.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/transform.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/trie.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/trie.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/trie.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/trie.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/triegen.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/triegen.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/triegen.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/triegen.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml new file mode 100644 index 00000000..f443eec9 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml @@ -0,0 +1,37 @@ +language: go + +matrix: + include: + - go: 1.11.x + env: VET=1 GO111MODULE=on + - go: 1.11.x + env: RACE=1 GO111MODULE=on + - go: 1.11.x + env: RUN386=1 + - go: 1.11.x + env: GRPC_GO_RETRY=on + - go: 1.10.x + - go: 1.9.x + - go: 1.9.x + env: GAE=1 + +go_import_path: google.golang.org/grpc + +before_install: + - if [[ "${GO111MODULE}" = "on" ]]; then mkdir "${HOME}/go"; export GOPATH="${HOME}/go"; fi + - if [[ -n "${RUN386}" ]]; then export GOARCH=386; fi + - if [[ "${TRAVIS_EVENT_TYPE}" = "cron" && -z "${RUN386}" ]]; then RACE=1; fi + - if [[ "${TRAVIS_EVENT_TYPE}" != "cron" ]]; then VET_SKIP_PROTO=1; fi + +install: + - try3() { eval "$*" || eval "$*" || eval "$*"; } + - try3 'if [[ "${GO111MODULE}" = "on" ]]; then go mod download; else make testdeps; fi' + - if [[ "${GAE}" = 1 ]]; then source ./install_gae.sh; make testappenginedeps; fi + - if [[ "${VET}" = 1 ]]; then ./vet.sh -install; fi + +script: + - set -e + - if [[ "${VET}" = 1 ]]; then ./vet.sh; fi + - if [[ "${GAE}" = 1 ]]; then make testappengine; exit 0; fi + - if [[ "${RACE}" = 1 ]]; then make testrace; exit 0; fi + - make test diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/AUTHORS b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/AUTHORS similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/AUTHORS rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/AUTHORS diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/CONTRIBUTING.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/CONTRIBUTING.md similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/CONTRIBUTING.md rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/CONTRIBUTING.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/LICENSE b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/LICENSE rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/LICENSE diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/Makefile b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/Makefile similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/Makefile rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/Makefile diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md new file mode 100644 index 00000000..e3fb3c75 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md @@ -0,0 +1,67 @@ +# gRPC-Go + +[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc) [![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go) + +The Go implementation of [gRPC](https://grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start: Go](https://grpc.io/docs/quickstart/go.html) guide. + +Installation +------------ + +To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run: + +``` +$ go get -u google.golang.org/grpc +``` + +Prerequisites +------------- + +gRPC-Go requires Go 1.9 or later. + +Constraints +----------- +The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](http://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants. + +Documentation +------------- +See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/). + +Performance +----------- +See the current benchmarks for some of the languages supported in [this dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696). + +Status +------ +General Availability [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages). + +FAQ +--- + +#### Compiling error, undefined: grpc.SupportPackageIsVersion + +Please update proto package, gRPC package and rebuild the proto files: + - `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}` + - `go get -u google.golang.org/grpc` + - `protoc --go_out=plugins=grpc:. *.proto` + +#### How to turn on logging + +The default logger is controlled by the environment variables. Turn everything +on by setting: + +``` +GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info +``` + +#### The RPC failed with error `"code = Unavailable desc = transport is closing"` + +This error means the connection the RPC is using was closed, and there are many +possible reasons, including: + 1. mis-configured transport credentials, connection failed on handshaking + 1. bytes disrupted, possibly by a proxy in between + 1. server shutdown + +It can be tricky to debug this because the error happens on the client side but +the root cause of the connection being closed is on the server side. Turn on +logging on __both client and server__, and see if there are any transport +errors. diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/backoff.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/backoff.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/backoff.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/backoff.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go new file mode 100644 index 00000000..a78e702b --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go @@ -0,0 +1,391 @@ +/* + * + * Copyright 2016 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 grpc + +import ( + "context" + "net" + "sync" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/naming" + "google.golang.org/grpc/status" +) + +// Address represents a server the client connects to. +// +// Deprecated: please use package balancer. +type Address struct { + // Addr is the server address on which a connection will be established. + Addr string + // Metadata is the information associated with Addr, which may be used + // to make load balancing decision. + Metadata interface{} +} + +// BalancerConfig specifies the configurations for Balancer. +// +// Deprecated: please use package balancer. +type BalancerConfig struct { + // DialCreds is the transport credential the Balancer implementation can + // use to dial to a remote load balancer server. The Balancer implementations + // can ignore this if it does not need to talk to another party securely. + DialCreds credentials.TransportCredentials + // Dialer is the custom dialer the Balancer implementation can use to dial + // to a remote load balancer server. The Balancer implementations + // can ignore this if it doesn't need to talk to remote balancer. + Dialer func(context.Context, string) (net.Conn, error) +} + +// BalancerGetOptions configures a Get call. +// +// Deprecated: please use package balancer. +type BalancerGetOptions struct { + // BlockingWait specifies whether Get should block when there is no + // connected address. + BlockingWait bool +} + +// Balancer chooses network addresses for RPCs. +// +// Deprecated: please use package balancer. +type Balancer interface { + // Start does the initialization work to bootstrap a Balancer. For example, + // this function may start the name resolution and watch the updates. It will + // be called when dialing. + Start(target string, config BalancerConfig) error + // Up informs the Balancer that gRPC has a connection to the server at + // addr. It returns down which is called once the connection to addr gets + // lost or closed. + // TODO: It is not clear how to construct and take advantage of the meaningful error + // parameter for down. Need realistic demands to guide. + Up(addr Address) (down func(error)) + // Get gets the address of a server for the RPC corresponding to ctx. + // i) If it returns a connected address, gRPC internals issues the RPC on the + // connection to this address; + // ii) If it returns an address on which the connection is under construction + // (initiated by Notify(...)) but not connected, gRPC internals + // * fails RPC if the RPC is fail-fast and connection is in the TransientFailure or + // Shutdown state; + // or + // * issues RPC on the connection otherwise. + // iii) If it returns an address on which the connection does not exist, gRPC + // internals treats it as an error and will fail the corresponding RPC. + // + // Therefore, the following is the recommended rule when writing a custom Balancer. + // If opts.BlockingWait is true, it should return a connected address or + // block if there is no connected address. It should respect the timeout or + // cancellation of ctx when blocking. If opts.BlockingWait is false (for fail-fast + // RPCs), it should return an address it has notified via Notify(...) immediately + // instead of blocking. + // + // The function returns put which is called once the rpc has completed or failed. + // put can collect and report RPC stats to a remote load balancer. + // + // This function should only return the errors Balancer cannot recover by itself. + // gRPC internals will fail the RPC if an error is returned. + Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) + // Notify returns a channel that is used by gRPC internals to watch the addresses + // gRPC needs to connect. The addresses might be from a name resolver or remote + // load balancer. gRPC internals will compare it with the existing connected + // addresses. If the address Balancer notified is not in the existing connected + // addresses, gRPC starts to connect the address. If an address in the existing + // connected addresses is not in the notification list, the corresponding connection + // is shutdown gracefully. Otherwise, there are no operations to take. Note that + // the Address slice must be the full list of the Addresses which should be connected. + // It is NOT delta. + Notify() <-chan []Address + // Close shuts down the balancer. + Close() error +} + +// RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch +// the name resolution updates and updates the addresses available correspondingly. +// +// Deprecated: please use package balancer/roundrobin. +func RoundRobin(r naming.Resolver) Balancer { + return &roundRobin{r: r} +} + +type addrInfo struct { + addr Address + connected bool +} + +type roundRobin struct { + r naming.Resolver + w naming.Watcher + addrs []*addrInfo // all the addresses the client should potentially connect + mu sync.Mutex + addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to. + next int // index of the next address to return for Get() + waitCh chan struct{} // the channel to block when there is no connected address available + done bool // The Balancer is closed. +} + +func (rr *roundRobin) watchAddrUpdates() error { + updates, err := rr.w.Next() + if err != nil { + grpclog.Warningf("grpc: the naming watcher stops working due to %v.", err) + return err + } + rr.mu.Lock() + defer rr.mu.Unlock() + for _, update := range updates { + addr := Address{ + Addr: update.Addr, + Metadata: update.Metadata, + } + switch update.Op { + case naming.Add: + var exist bool + for _, v := range rr.addrs { + if addr == v.addr { + exist = true + grpclog.Infoln("grpc: The name resolver wanted to add an existing address: ", addr) + break + } + } + if exist { + continue + } + rr.addrs = append(rr.addrs, &addrInfo{addr: addr}) + case naming.Delete: + for i, v := range rr.addrs { + if addr == v.addr { + copy(rr.addrs[i:], rr.addrs[i+1:]) + rr.addrs = rr.addrs[:len(rr.addrs)-1] + break + } + } + default: + grpclog.Errorln("Unknown update.Op ", update.Op) + } + } + // Make a copy of rr.addrs and write it onto rr.addrCh so that gRPC internals gets notified. + open := make([]Address, len(rr.addrs)) + for i, v := range rr.addrs { + open[i] = v.addr + } + if rr.done { + return ErrClientConnClosing + } + select { + case <-rr.addrCh: + default: + } + rr.addrCh <- open + return nil +} + +func (rr *roundRobin) Start(target string, config BalancerConfig) error { + rr.mu.Lock() + defer rr.mu.Unlock() + if rr.done { + return ErrClientConnClosing + } + if rr.r == nil { + // If there is no name resolver installed, it is not needed to + // do name resolution. In this case, target is added into rr.addrs + // as the only address available and rr.addrCh stays nil. + rr.addrs = append(rr.addrs, &addrInfo{addr: Address{Addr: target}}) + return nil + } + w, err := rr.r.Resolve(target) + if err != nil { + return err + } + rr.w = w + rr.addrCh = make(chan []Address, 1) + go func() { + for { + if err := rr.watchAddrUpdates(); err != nil { + return + } + } + }() + return nil +} + +// Up sets the connected state of addr and sends notification if there are pending +// Get() calls. +func (rr *roundRobin) Up(addr Address) func(error) { + rr.mu.Lock() + defer rr.mu.Unlock() + var cnt int + for _, a := range rr.addrs { + if a.addr == addr { + if a.connected { + return nil + } + a.connected = true + } + if a.connected { + cnt++ + } + } + // addr is only one which is connected. Notify the Get() callers who are blocking. + if cnt == 1 && rr.waitCh != nil { + close(rr.waitCh) + rr.waitCh = nil + } + return func(err error) { + rr.down(addr, err) + } +} + +// down unsets the connected state of addr. +func (rr *roundRobin) down(addr Address, err error) { + rr.mu.Lock() + defer rr.mu.Unlock() + for _, a := range rr.addrs { + if addr == a.addr { + a.connected = false + break + } + } +} + +// Get returns the next addr in the rotation. +func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) { + var ch chan struct{} + rr.mu.Lock() + if rr.done { + rr.mu.Unlock() + err = ErrClientConnClosing + return + } + + if len(rr.addrs) > 0 { + if rr.next >= len(rr.addrs) { + rr.next = 0 + } + next := rr.next + for { + a := rr.addrs[next] + next = (next + 1) % len(rr.addrs) + if a.connected { + addr = a.addr + rr.next = next + rr.mu.Unlock() + return + } + if next == rr.next { + // Has iterated all the possible address but none is connected. + break + } + } + } + if !opts.BlockingWait { + if len(rr.addrs) == 0 { + rr.mu.Unlock() + err = status.Errorf(codes.Unavailable, "there is no address available") + return + } + // Returns the next addr on rr.addrs for failfast RPCs. + addr = rr.addrs[rr.next].addr + rr.next++ + rr.mu.Unlock() + return + } + // Wait on rr.waitCh for non-failfast RPCs. + if rr.waitCh == nil { + ch = make(chan struct{}) + rr.waitCh = ch + } else { + ch = rr.waitCh + } + rr.mu.Unlock() + for { + select { + case <-ctx.Done(): + err = ctx.Err() + return + case <-ch: + rr.mu.Lock() + if rr.done { + rr.mu.Unlock() + err = ErrClientConnClosing + return + } + + if len(rr.addrs) > 0 { + if rr.next >= len(rr.addrs) { + rr.next = 0 + } + next := rr.next + for { + a := rr.addrs[next] + next = (next + 1) % len(rr.addrs) + if a.connected { + addr = a.addr + rr.next = next + rr.mu.Unlock() + return + } + if next == rr.next { + // Has iterated all the possible address but none is connected. + break + } + } + } + // The newly added addr got removed by Down() again. + if rr.waitCh == nil { + ch = make(chan struct{}) + rr.waitCh = ch + } else { + ch = rr.waitCh + } + rr.mu.Unlock() + } + } +} + +func (rr *roundRobin) Notify() <-chan []Address { + return rr.addrCh +} + +func (rr *roundRobin) Close() error { + rr.mu.Lock() + defer rr.mu.Unlock() + if rr.done { + return errBalancerClosed + } + rr.done = true + if rr.w != nil { + rr.w.Close() + } + if rr.waitCh != nil { + close(rr.waitCh) + rr.waitCh = nil + } + if rr.addrCh != nil { + close(rr.addrCh) + } + return nil +} + +// pickFirst is used to test multi-addresses in one addrConn in which all addresses share the same addrConn. +// It is a wrapper around roundRobin balancer. The logic of all methods works fine because balancer.Get() +// returns the only address Up by resetTransport(). +type pickFirst struct { + *roundRobin +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go new file mode 100644 index 00000000..1bf46aaf --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go @@ -0,0 +1,290 @@ +/* + * + * 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 balancer defines APIs for load balancing in gRPC. +// All APIs in this package are experimental. +package balancer + +import ( + "context" + "errors" + "net" + "strings" + + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/resolver" +) + +var ( + // m is a map from name to balancer builder. + m = make(map[string]Builder) +) + +// Register registers the balancer builder to the balancer map. b.Name +// (lowercased) will be used as the name registered with this builder. +// +// NOTE: this function must only be called during initialization time (i.e. in +// an init() function), and is not thread-safe. If multiple Balancers are +// registered with the same name, the one registered last will take effect. +func Register(b Builder) { + m[strings.ToLower(b.Name())] = b +} + +// Get returns the resolver builder registered with the given name. +// Note that the compare is done in a case-insenstive fashion. +// If no builder is register with the name, nil will be returned. +func Get(name string) Builder { + if b, ok := m[strings.ToLower(name)]; ok { + return b + } + return nil +} + +// SubConn represents a gRPC sub connection. +// Each sub connection contains a list of addresses. gRPC will +// try to connect to them (in sequence), and stop trying the +// remainder once one connection is successful. +// +// The reconnect backoff will be applied on the list, not a single address. +// For example, try_on_all_addresses -> backoff -> try_on_all_addresses. +// +// All SubConns start in IDLE, and will not try to connect. To trigger +// the connecting, Balancers must call Connect. +// When the connection encounters an error, it will reconnect immediately. +// When the connection becomes IDLE, it will not reconnect unless Connect is +// called. +// +// This interface is to be implemented by gRPC. Users should not need a +// brand new implementation of this interface. For the situations like +// testing, the new implementation should embed this interface. This allows +// gRPC to add new methods to this interface. +type SubConn interface { + // UpdateAddresses updates the addresses used in this SubConn. + // gRPC checks if currently-connected address is still in the new list. + // If it's in the list, the connection will be kept. + // If it's not in the list, the connection will gracefully closed, and + // a new connection will be created. + // + // This will trigger a state transition for the SubConn. + UpdateAddresses([]resolver.Address) + // Connect starts the connecting for this SubConn. + Connect() +} + +// NewSubConnOptions contains options to create new SubConn. +type NewSubConnOptions struct { + // CredsBundle is the credentials bundle that will be used in the created + // SubConn. If it's nil, the original creds from grpc DialOptions will be + // used. + CredsBundle credentials.Bundle + // HealthCheckEnabled indicates whether health check service should be + // enabled on this SubConn + HealthCheckEnabled bool +} + +// ClientConn represents a gRPC ClientConn. +// +// This interface is to be implemented by gRPC. Users should not need a +// brand new implementation of this interface. For the situations like +// testing, the new implementation should embed this interface. This allows +// gRPC to add new methods to this interface. +type ClientConn interface { + // NewSubConn is called by balancer to create a new SubConn. + // It doesn't block and wait for the connections to be established. + // Behaviors of the SubConn can be controlled by options. + NewSubConn([]resolver.Address, NewSubConnOptions) (SubConn, error) + // RemoveSubConn removes the SubConn from ClientConn. + // The SubConn will be shutdown. + RemoveSubConn(SubConn) + + // UpdateBalancerState is called by balancer to nofity gRPC that some internal + // state in balancer has changed. + // + // gRPC will update the connectivity state of the ClientConn, and will call pick + // on the new picker to pick new SubConn. + UpdateBalancerState(s connectivity.State, p Picker) + + // ResolveNow is called by balancer to notify gRPC to do a name resolving. + ResolveNow(resolver.ResolveNowOption) + + // Target returns the dial target for this ClientConn. + Target() string +} + +// BuildOptions contains additional information for Build. +type BuildOptions struct { + // DialCreds is the transport credential the Balancer implementation can + // use to dial to a remote load balancer server. The Balancer implementations + // can ignore this if it does not need to talk to another party securely. + DialCreds credentials.TransportCredentials + // CredsBundle is the credentials bundle that the Balancer can use. + CredsBundle credentials.Bundle + // Dialer is the custom dialer the Balancer implementation can use to dial + // to a remote load balancer server. The Balancer implementations + // can ignore this if it doesn't need to talk to remote balancer. + Dialer func(context.Context, string) (net.Conn, error) + // ChannelzParentID is the entity parent's channelz unique identification number. + ChannelzParentID int64 +} + +// Builder creates a balancer. +type Builder interface { + // Build creates a new balancer with the ClientConn. + Build(cc ClientConn, opts BuildOptions) Balancer + // Name returns the name of balancers built by this builder. + // It will be used to pick balancers (for example in service config). + Name() string +} + +// PickOptions contains addition information for the Pick operation. +type PickOptions struct { + // FullMethodName is the method name that NewClientStream() is called + // with. The canonical format is /service/Method. + FullMethodName string + // Header contains the metadata from the RPC's client header. The metadata + // should not be modified; make a copy first if needed. + Header metadata.MD +} + +// DoneInfo contains additional information for done. +type DoneInfo struct { + // Err is the rpc error the RPC finished with. It could be nil. + Err error + // Trailer contains the metadata from the RPC's trailer, if present. + Trailer metadata.MD + // BytesSent indicates if any bytes have been sent to the server. + BytesSent bool + // BytesReceived indicates if any byte has been received from the server. + BytesReceived bool +} + +var ( + // ErrNoSubConnAvailable indicates no SubConn is available for pick(). + // gRPC will block the RPC until a new picker is available via UpdateBalancerState(). + ErrNoSubConnAvailable = errors.New("no SubConn is available") + // ErrTransientFailure indicates all SubConns are in TransientFailure. + // WaitForReady RPCs will block, non-WaitForReady RPCs will fail. + ErrTransientFailure = errors.New("all SubConns are in TransientFailure") +) + +// Picker is used by gRPC to pick a SubConn to send an RPC. +// Balancer is expected to generate a new picker from its snapshot every time its +// internal state has changed. +// +// The pickers used by gRPC can be updated by ClientConn.UpdateBalancerState(). +type Picker interface { + // Pick returns the SubConn to be used to send the RPC. + // The returned SubConn must be one returned by NewSubConn(). + // + // This functions is expected to return: + // - a SubConn that is known to be READY; + // - ErrNoSubConnAvailable if no SubConn is available, but progress is being + // made (for example, some SubConn is in CONNECTING mode); + // - other errors if no active connecting is happening (for example, all SubConn + // are in TRANSIENT_FAILURE mode). + // + // If a SubConn is returned: + // - If it is READY, gRPC will send the RPC on it; + // - If it is not ready, or becomes not ready after it's returned, gRPC will block + // until UpdateBalancerState() is called and will call pick on the new picker. + // + // If the returned error is not nil: + // - If the error is ErrNoSubConnAvailable, gRPC will block until UpdateBalancerState() + // - If the error is ErrTransientFailure: + // - If the RPC is wait-for-ready, gRPC will block until UpdateBalancerState() + // is called to pick again; + // - Otherwise, RPC will fail with unavailable error. + // - Else (error is other non-nil error): + // - The RPC will fail with unavailable error. + // + // The returned done() function will be called once the rpc has finished, with the + // final status of that RPC. + // done may be nil if balancer doesn't care about the RPC status. + Pick(ctx context.Context, opts PickOptions) (conn SubConn, done func(DoneInfo), err error) +} + +// Balancer takes input from gRPC, manages SubConns, and collects and aggregates +// the connectivity states. +// +// It also generates and updates the Picker used by gRPC to pick SubConns for RPCs. +// +// HandleSubConnectionStateChange, HandleResolvedAddrs and Close are guaranteed +// to be called synchronously from the same goroutine. +// There's no guarantee on picker.Pick, it may be called anytime. +type Balancer interface { + // HandleSubConnStateChange is called by gRPC when the connectivity state + // of sc has changed. + // Balancer is expected to aggregate all the state of SubConn and report + // that back to gRPC. + // Balancer should also generate and update Pickers when its internal state has + // been changed by the new state. + HandleSubConnStateChange(sc SubConn, state connectivity.State) + // HandleResolvedAddrs is called by gRPC to send updated resolved addresses to + // balancers. + // Balancer can create new SubConn or remove SubConn with the addresses. + // An empty address slice and a non-nil error will be passed if the resolver returns + // non-nil error to gRPC. + HandleResolvedAddrs([]resolver.Address, error) + // Close closes the balancer. The balancer is not required to call + // ClientConn.RemoveSubConn for its existing SubConns. + Close() +} + +// ConnectivityStateEvaluator takes the connectivity states of multiple SubConns +// and returns one aggregated connectivity state. +// +// It's not thread safe. +type ConnectivityStateEvaluator struct { + numReady uint64 // Number of addrConns in ready state. + numConnecting uint64 // Number of addrConns in connecting state. + numTransientFailure uint64 // Number of addrConns in transientFailure. +} + +// RecordTransition records state change happening in subConn and based on that +// it evaluates what aggregated state should be. +// +// - If at least one SubConn in Ready, the aggregated state is Ready; +// - Else if at least one SubConn in Connecting, the aggregated state is Connecting; +// - Else the aggregated state is TransientFailure. +// +// Idle and Shutdown are not considered. +func (cse *ConnectivityStateEvaluator) RecordTransition(oldState, newState connectivity.State) connectivity.State { + // Update counters. + for idx, state := range []connectivity.State{oldState, newState} { + updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. + switch state { + case connectivity.Ready: + cse.numReady += updateVal + case connectivity.Connecting: + cse.numConnecting += updateVal + case connectivity.TransientFailure: + cse.numTransientFailure += updateVal + } + } + + // Evaluate. + if cse.numReady > 0 { + return connectivity.Ready + } + if cse.numConnecting > 0 { + return connectivity.Connecting + } + return connectivity.TransientFailure +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go new file mode 100644 index 00000000..5f55b274 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go @@ -0,0 +1,212 @@ +/* + * + * 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 base + +import ( + "context" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +type baseBuilder struct { + name string + pickerBuilder PickerBuilder + config Config +} + +func (bb *baseBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { + return &baseBalancer{ + cc: cc, + pickerBuilder: bb.pickerBuilder, + + subConns: make(map[resolver.Address]balancer.SubConn), + scStates: make(map[balancer.SubConn]connectivity.State), + csEvltr: &connectivityStateEvaluator{}, + // Initialize picker to a picker that always return + // ErrNoSubConnAvailable, because when state of a SubConn changes, we + // may call UpdateBalancerState with this picker. + picker: NewErrPicker(balancer.ErrNoSubConnAvailable), + config: bb.config, + } +} + +func (bb *baseBuilder) Name() string { + return bb.name +} + +type baseBalancer struct { + cc balancer.ClientConn + pickerBuilder PickerBuilder + + csEvltr *connectivityStateEvaluator + state connectivity.State + + subConns map[resolver.Address]balancer.SubConn + scStates map[balancer.SubConn]connectivity.State + picker balancer.Picker + config Config +} + +func (b *baseBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) { + if err != nil { + grpclog.Infof("base.baseBalancer: HandleResolvedAddrs called with error %v", err) + return + } + grpclog.Infoln("base.baseBalancer: got new resolved addresses: ", addrs) + // addrsSet is the set converted from addrs, it's used for quick lookup of an address. + addrsSet := make(map[resolver.Address]struct{}) + for _, a := range addrs { + addrsSet[a] = struct{}{} + if _, ok := b.subConns[a]; !ok { + // a is a new address (not existing in b.subConns). + sc, err := b.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{HealthCheckEnabled: b.config.HealthCheck}) + if err != nil { + grpclog.Warningf("base.baseBalancer: failed to create new SubConn: %v", err) + continue + } + b.subConns[a] = sc + b.scStates[sc] = connectivity.Idle + sc.Connect() + } + } + for a, sc := range b.subConns { + // a was removed by resolver. + if _, ok := addrsSet[a]; !ok { + b.cc.RemoveSubConn(sc) + delete(b.subConns, a) + // Keep the state of this sc in b.scStates until sc's state becomes Shutdown. + // The entry will be deleted in HandleSubConnStateChange. + } + } +} + +// regeneratePicker takes a snapshot of the balancer, and generates a picker +// from it. The picker is +// - errPicker with ErrTransientFailure if the balancer is in TransientFailure, +// - built by the pickerBuilder with all READY SubConns otherwise. +func (b *baseBalancer) regeneratePicker() { + if b.state == connectivity.TransientFailure { + b.picker = NewErrPicker(balancer.ErrTransientFailure) + return + } + readySCs := make(map[resolver.Address]balancer.SubConn) + + // Filter out all ready SCs from full subConn map. + for addr, sc := range b.subConns { + if st, ok := b.scStates[sc]; ok && st == connectivity.Ready { + readySCs[addr] = sc + } + } + b.picker = b.pickerBuilder.Build(readySCs) +} + +func (b *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + grpclog.Infof("base.baseBalancer: handle SubConn state change: %p, %v", sc, s) + oldS, ok := b.scStates[sc] + if !ok { + grpclog.Infof("base.baseBalancer: got state changes for an unknown SubConn: %p, %v", sc, s) + return + } + b.scStates[sc] = s + switch s { + case connectivity.Idle: + sc.Connect() + case connectivity.Shutdown: + // When an address was removed by resolver, b called RemoveSubConn but + // kept the sc's state in scStates. Remove state for this sc here. + delete(b.scStates, sc) + } + + oldAggrState := b.state + b.state = b.csEvltr.recordTransition(oldS, s) + + // Regenerate picker when one of the following happens: + // - this sc became ready from not-ready + // - this sc became not-ready from ready + // - the aggregated state of balancer became TransientFailure from non-TransientFailure + // - the aggregated state of balancer became non-TransientFailure from TransientFailure + if (s == connectivity.Ready) != (oldS == connectivity.Ready) || + (b.state == connectivity.TransientFailure) != (oldAggrState == connectivity.TransientFailure) { + b.regeneratePicker() + } + + b.cc.UpdateBalancerState(b.state, b.picker) +} + +// Close is a nop because base balancer doesn't have internal state to clean up, +// and it doesn't need to call RemoveSubConn for the SubConns. +func (b *baseBalancer) Close() { +} + +// NewErrPicker returns a picker that always returns err on Pick(). +func NewErrPicker(err error) balancer.Picker { + return &errPicker{err: err} +} + +type errPicker struct { + err error // Pick() always returns this err. +} + +func (p *errPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + return nil, nil, p.err +} + +// connectivityStateEvaluator gets updated by addrConns when their +// states transition, based on which it evaluates the state of +// ClientConn. +type connectivityStateEvaluator struct { + numReady uint64 // Number of addrConns in ready state. + numConnecting uint64 // Number of addrConns in connecting state. + numTransientFailure uint64 // Number of addrConns in transientFailure. +} + +// recordTransition records state change happening in every subConn and based on +// that it evaluates what aggregated state should be. +// It can only transition between Ready, Connecting and TransientFailure. Other states, +// Idle and Shutdown are transitioned into by ClientConn; in the beginning of the connection +// before any subConn is created ClientConn is in idle state. In the end when ClientConn +// closes it is in Shutdown state. +// +// recordTransition should only be called synchronously from the same goroutine. +func (cse *connectivityStateEvaluator) recordTransition(oldState, newState connectivity.State) connectivity.State { + // Update counters. + for idx, state := range []connectivity.State{oldState, newState} { + updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. + switch state { + case connectivity.Ready: + cse.numReady += updateVal + case connectivity.Connecting: + cse.numConnecting += updateVal + case connectivity.TransientFailure: + cse.numTransientFailure += updateVal + } + } + + // Evaluate. + if cse.numReady > 0 { + return connectivity.Ready + } + if cse.numConnecting > 0 { + return connectivity.Connecting + } + return connectivity.TransientFailure +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go new file mode 100644 index 00000000..34b1f299 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go @@ -0,0 +1,64 @@ +/* + * + * 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 base defines a balancer base that can be used to build balancers with +// different picking algorithms. +// +// The base balancer creates a new SubConn for each resolved address. The +// provided picker will only be notified about READY SubConns. +// +// This package is the base of round_robin balancer, its purpose is to be used +// to build round_robin like balancers with complex picking algorithms. +// Balancers with more complicated logic should try to implement a balancer +// builder from scratch. +// +// All APIs in this package are experimental. +package base + +import ( + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/resolver" +) + +// PickerBuilder creates balancer.Picker. +type PickerBuilder interface { + // Build takes a slice of ready SubConns, and returns a picker that will be + // used by gRPC to pick a SubConn. + Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker +} + +// NewBalancerBuilder returns a balancer builder. The balancers +// built by this builder will use the picker builder to build pickers. +func NewBalancerBuilder(name string, pb PickerBuilder) balancer.Builder { + return NewBalancerBuilderWithConfig(name, pb, Config{}) +} + +// Config contains the config info about the base balancer builder. +type Config struct { + // HealthCheck indicates whether health checking should be enabled for this specific balancer. + HealthCheck bool +} + +// NewBalancerBuilderWithConfig returns a base balancer builder configured by the provided config. +func NewBalancerBuilderWithConfig(name string, pb PickerBuilder, config Config) balancer.Builder { + return &baseBuilder{ + name: name, + pickerBuilder: pb, + config: config, + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go new file mode 100644 index 00000000..57aea9fb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go @@ -0,0 +1,79 @@ +/* + * + * 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 roundrobin defines a roundrobin balancer. Roundrobin balancer is +// installed as one of the default balancers in gRPC, users don't need to +// explicitly install this balancer. +package roundrobin + +import ( + "context" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/balancer/base" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// Name is the name of round_robin balancer. +const Name = "round_robin" + +// newBuilder creates a new roundrobin balancer builder. +func newBuilder() balancer.Builder { + return base.NewBalancerBuilderWithConfig(Name, &rrPickerBuilder{}, base.Config{HealthCheck: true}) +} + +func init() { + balancer.Register(newBuilder()) +} + +type rrPickerBuilder struct{} + +func (*rrPickerBuilder) Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker { + grpclog.Infof("roundrobinPicker: newPicker called with readySCs: %v", readySCs) + var scs []balancer.SubConn + for _, sc := range readySCs { + scs = append(scs, sc) + } + return &rrPicker{ + subConns: scs, + } +} + +type rrPicker struct { + // subConns is the snapshot of the roundrobin balancer when this picker was + // created. The slice is immutable. Each Get() will do a round robin + // selection from it and return the selected SubConn. + subConns []balancer.SubConn + + mu sync.Mutex + next int +} + +func (p *rrPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + if len(p.subConns) <= 0 { + return nil, nil, balancer.ErrNoSubConnAvailable + } + + p.mu.Lock() + sc := p.subConns[p.next] + p.next = (p.next + 1) % len(p.subConns) + p.mu.Unlock() + return sc, nil, nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go new file mode 100644 index 00000000..77b68477 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go @@ -0,0 +1,306 @@ +/* + * + * 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 grpc + +import ( + "fmt" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// scStateUpdate contains the subConn and the new state it changed to. +type scStateUpdate struct { + sc balancer.SubConn + state connectivity.State +} + +// scStateUpdateBuffer is an unbounded channel for scStateChangeTuple. +// TODO make a general purpose buffer that uses interface{}. +type scStateUpdateBuffer struct { + c chan *scStateUpdate + mu sync.Mutex + backlog []*scStateUpdate +} + +func newSCStateUpdateBuffer() *scStateUpdateBuffer { + return &scStateUpdateBuffer{ + c: make(chan *scStateUpdate, 1), + } +} + +func (b *scStateUpdateBuffer) put(t *scStateUpdate) { + b.mu.Lock() + defer b.mu.Unlock() + if len(b.backlog) == 0 { + select { + case b.c <- t: + return + default: + } + } + b.backlog = append(b.backlog, t) +} + +func (b *scStateUpdateBuffer) load() { + b.mu.Lock() + defer b.mu.Unlock() + if len(b.backlog) > 0 { + select { + case b.c <- b.backlog[0]: + b.backlog[0] = nil + b.backlog = b.backlog[1:] + default: + } + } +} + +// get returns the channel that the scStateUpdate will be sent to. +// +// Upon receiving, the caller should call load to send another +// scStateChangeTuple onto the channel if there is any. +func (b *scStateUpdateBuffer) get() <-chan *scStateUpdate { + return b.c +} + +// resolverUpdate contains the new resolved addresses or error if there's +// any. +type resolverUpdate struct { + addrs []resolver.Address + err error +} + +// ccBalancerWrapper is a wrapper on top of cc for balancers. +// It implements balancer.ClientConn interface. +type ccBalancerWrapper struct { + cc *ClientConn + balancer balancer.Balancer + stateChangeQueue *scStateUpdateBuffer + resolverUpdateCh chan *resolverUpdate + done chan struct{} + + mu sync.Mutex + subConns map[*acBalancerWrapper]struct{} +} + +func newCCBalancerWrapper(cc *ClientConn, b balancer.Builder, bopts balancer.BuildOptions) *ccBalancerWrapper { + ccb := &ccBalancerWrapper{ + cc: cc, + stateChangeQueue: newSCStateUpdateBuffer(), + resolverUpdateCh: make(chan *resolverUpdate, 1), + done: make(chan struct{}), + subConns: make(map[*acBalancerWrapper]struct{}), + } + go ccb.watcher() + ccb.balancer = b.Build(ccb, bopts) + return ccb +} + +// watcher balancer functions sequentially, so the balancer can be implemented +// lock-free. +func (ccb *ccBalancerWrapper) watcher() { + for { + select { + case t := <-ccb.stateChangeQueue.get(): + ccb.stateChangeQueue.load() + select { + case <-ccb.done: + ccb.balancer.Close() + return + default: + } + ccb.balancer.HandleSubConnStateChange(t.sc, t.state) + case t := <-ccb.resolverUpdateCh: + select { + case <-ccb.done: + ccb.balancer.Close() + return + default: + } + ccb.balancer.HandleResolvedAddrs(t.addrs, t.err) + case <-ccb.done: + } + + select { + case <-ccb.done: + ccb.balancer.Close() + ccb.mu.Lock() + scs := ccb.subConns + ccb.subConns = nil + ccb.mu.Unlock() + for acbw := range scs { + ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain) + } + return + default: + } + } +} + +func (ccb *ccBalancerWrapper) close() { + close(ccb.done) +} + +func (ccb *ccBalancerWrapper) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + // When updating addresses for a SubConn, if the address in use is not in + // the new addresses, the old ac will be tearDown() and a new ac will be + // created. tearDown() generates a state change with Shutdown state, we + // don't want the balancer to receive this state change. So before + // tearDown() on the old ac, ac.acbw (acWrapper) will be set to nil, and + // this function will be called with (nil, Shutdown). We don't need to call + // balancer method in this case. + if sc == nil { + return + } + ccb.stateChangeQueue.put(&scStateUpdate{ + sc: sc, + state: s, + }) +} + +func (ccb *ccBalancerWrapper) handleResolvedAddrs(addrs []resolver.Address, err error) { + select { + case <-ccb.resolverUpdateCh: + default: + } + ccb.resolverUpdateCh <- &resolverUpdate{ + addrs: addrs, + err: err, + } +} + +func (ccb *ccBalancerWrapper) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { + if len(addrs) <= 0 { + return nil, fmt.Errorf("grpc: cannot create SubConn with empty address list") + } + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return nil, fmt.Errorf("grpc: ClientConn balancer wrapper was closed") + } + ac, err := ccb.cc.newAddrConn(addrs, opts) + if err != nil { + return nil, err + } + acbw := &acBalancerWrapper{ac: ac} + acbw.ac.mu.Lock() + ac.acbw = acbw + acbw.ac.mu.Unlock() + ccb.subConns[acbw] = struct{}{} + return acbw, nil +} + +func (ccb *ccBalancerWrapper) RemoveSubConn(sc balancer.SubConn) { + acbw, ok := sc.(*acBalancerWrapper) + if !ok { + return + } + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return + } + delete(ccb.subConns, acbw) + ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain) +} + +func (ccb *ccBalancerWrapper) UpdateBalancerState(s connectivity.State, p balancer.Picker) { + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return + } + // Update picker before updating state. Even though the ordering here does + // not matter, it can lead to multiple calls of Pick in the common start-up + // case where we wait for ready and then perform an RPC. If the picker is + // updated later, we could call the "connecting" picker when the state is + // updated, and then call the "ready" picker after the picker gets updated. + ccb.cc.blockingpicker.updatePicker(p) + ccb.cc.csMgr.updateState(s) +} + +func (ccb *ccBalancerWrapper) ResolveNow(o resolver.ResolveNowOption) { + ccb.cc.resolveNow(o) +} + +func (ccb *ccBalancerWrapper) Target() string { + return ccb.cc.target +} + +// acBalancerWrapper is a wrapper on top of ac for balancers. +// It implements balancer.SubConn interface. +type acBalancerWrapper struct { + mu sync.Mutex + ac *addrConn +} + +func (acbw *acBalancerWrapper) UpdateAddresses(addrs []resolver.Address) { + acbw.mu.Lock() + defer acbw.mu.Unlock() + if len(addrs) <= 0 { + acbw.ac.tearDown(errConnDrain) + return + } + if !acbw.ac.tryUpdateAddrs(addrs) { + cc := acbw.ac.cc + opts := acbw.ac.scopts + acbw.ac.mu.Lock() + // Set old ac.acbw to nil so the Shutdown state update will be ignored + // by balancer. + // + // TODO(bar) the state transition could be wrong when tearDown() old ac + // and creating new ac, fix the transition. + acbw.ac.acbw = nil + acbw.ac.mu.Unlock() + acState := acbw.ac.getState() + acbw.ac.tearDown(errConnDrain) + + if acState == connectivity.Shutdown { + return + } + + ac, err := cc.newAddrConn(addrs, opts) + if err != nil { + grpclog.Warningf("acBalancerWrapper: UpdateAddresses: failed to newAddrConn: %v", err) + return + } + acbw.ac = ac + ac.mu.Lock() + ac.acbw = acbw + ac.mu.Unlock() + if acState != connectivity.Idle { + ac.connect() + } + } +} + +func (acbw *acBalancerWrapper) Connect() { + acbw.mu.Lock() + defer acbw.mu.Unlock() + acbw.ac.connect() +} + +func (acbw *acBalancerWrapper) getAddrConn() *addrConn { + acbw.mu.Lock() + defer acbw.mu.Unlock() + return acbw.ac +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go new file mode 100644 index 00000000..ca07c154 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go @@ -0,0 +1,328 @@ +/* + * + * 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 grpc + +import ( + "context" + "strings" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" + "google.golang.org/grpc/status" +) + +type balancerWrapperBuilder struct { + b Balancer // The v1 balancer. +} + +func (bwb *balancerWrapperBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { + targetAddr := cc.Target() + targetSplitted := strings.Split(targetAddr, ":///") + if len(targetSplitted) >= 2 { + targetAddr = targetSplitted[1] + } + + bwb.b.Start(targetAddr, BalancerConfig{ + DialCreds: opts.DialCreds, + Dialer: opts.Dialer, + }) + _, pickfirst := bwb.b.(*pickFirst) + bw := &balancerWrapper{ + balancer: bwb.b, + pickfirst: pickfirst, + cc: cc, + targetAddr: targetAddr, + startCh: make(chan struct{}), + conns: make(map[resolver.Address]balancer.SubConn), + connSt: make(map[balancer.SubConn]*scState), + csEvltr: &balancer.ConnectivityStateEvaluator{}, + state: connectivity.Idle, + } + cc.UpdateBalancerState(connectivity.Idle, bw) + go bw.lbWatcher() + return bw +} + +func (bwb *balancerWrapperBuilder) Name() string { + return "wrapper" +} + +type scState struct { + addr Address // The v1 address type. + s connectivity.State + down func(error) +} + +type balancerWrapper struct { + balancer Balancer // The v1 balancer. + pickfirst bool + + cc balancer.ClientConn + targetAddr string // Target without the scheme. + + mu sync.Mutex + conns map[resolver.Address]balancer.SubConn + connSt map[balancer.SubConn]*scState + // This channel is closed when handling the first resolver result. + // lbWatcher blocks until this is closed, to avoid race between + // - NewSubConn is created, cc wants to notify balancer of state changes; + // - Build hasn't return, cc doesn't have access to balancer. + startCh chan struct{} + + // To aggregate the connectivity state. + csEvltr *balancer.ConnectivityStateEvaluator + state connectivity.State +} + +// lbWatcher watches the Notify channel of the balancer and manages +// connections accordingly. +func (bw *balancerWrapper) lbWatcher() { + <-bw.startCh + notifyCh := bw.balancer.Notify() + if notifyCh == nil { + // There's no resolver in the balancer. Connect directly. + a := resolver.Address{ + Addr: bw.targetAddr, + Type: resolver.Backend, + } + sc, err := bw.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", a, err) + } else { + bw.mu.Lock() + bw.conns[a] = sc + bw.connSt[sc] = &scState{ + addr: Address{Addr: bw.targetAddr}, + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + return + } + + for addrs := range notifyCh { + grpclog.Infof("balancerWrapper: got update addr from Notify: %v\n", addrs) + if bw.pickfirst { + var ( + oldA resolver.Address + oldSC balancer.SubConn + ) + bw.mu.Lock() + for oldA, oldSC = range bw.conns { + break + } + bw.mu.Unlock() + if len(addrs) <= 0 { + if oldSC != nil { + // Teardown old sc. + bw.mu.Lock() + delete(bw.conns, oldA) + delete(bw.connSt, oldSC) + bw.mu.Unlock() + bw.cc.RemoveSubConn(oldSC) + } + continue + } + + var newAddrs []resolver.Address + for _, a := range addrs { + newAddr := resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, // All addresses from balancer are all backends. + ServerName: "", + Metadata: a.Metadata, + } + newAddrs = append(newAddrs, newAddr) + } + if oldSC == nil { + // Create new sc. + sc, err := bw.cc.NewSubConn(newAddrs, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", newAddrs, err) + } else { + bw.mu.Lock() + // For pickfirst, there should be only one SubConn, so the + // address doesn't matter. All states updating (up and down) + // and picking should all happen on that only SubConn. + bw.conns[resolver.Address{}] = sc + bw.connSt[sc] = &scState{ + addr: addrs[0], // Use the first address. + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + } else { + bw.mu.Lock() + bw.connSt[oldSC].addr = addrs[0] + bw.mu.Unlock() + oldSC.UpdateAddresses(newAddrs) + } + } else { + var ( + add []resolver.Address // Addresses need to setup connections. + del []balancer.SubConn // Connections need to tear down. + ) + resAddrs := make(map[resolver.Address]Address) + for _, a := range addrs { + resAddrs[resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, // All addresses from balancer are all backends. + ServerName: "", + Metadata: a.Metadata, + }] = a + } + bw.mu.Lock() + for a := range resAddrs { + if _, ok := bw.conns[a]; !ok { + add = append(add, a) + } + } + for a, c := range bw.conns { + if _, ok := resAddrs[a]; !ok { + del = append(del, c) + delete(bw.conns, a) + // Keep the state of this sc in bw.connSt until its state becomes Shutdown. + } + } + bw.mu.Unlock() + for _, a := range add { + sc, err := bw.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", a, err) + } else { + bw.mu.Lock() + bw.conns[a] = sc + bw.connSt[sc] = &scState{ + addr: resAddrs[a], + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + } + for _, c := range del { + bw.cc.RemoveSubConn(c) + } + } + } +} + +func (bw *balancerWrapper) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + bw.mu.Lock() + defer bw.mu.Unlock() + scSt, ok := bw.connSt[sc] + if !ok { + return + } + if s == connectivity.Idle { + sc.Connect() + } + oldS := scSt.s + scSt.s = s + if oldS != connectivity.Ready && s == connectivity.Ready { + scSt.down = bw.balancer.Up(scSt.addr) + } else if oldS == connectivity.Ready && s != connectivity.Ready { + if scSt.down != nil { + scSt.down(errConnClosing) + } + } + sa := bw.csEvltr.RecordTransition(oldS, s) + if bw.state != sa { + bw.state = sa + } + bw.cc.UpdateBalancerState(bw.state, bw) + if s == connectivity.Shutdown { + // Remove state for this sc. + delete(bw.connSt, sc) + } +} + +func (bw *balancerWrapper) HandleResolvedAddrs([]resolver.Address, error) { + bw.mu.Lock() + defer bw.mu.Unlock() + select { + case <-bw.startCh: + default: + close(bw.startCh) + } + // There should be a resolver inside the balancer. + // All updates here, if any, are ignored. +} + +func (bw *balancerWrapper) Close() { + bw.mu.Lock() + defer bw.mu.Unlock() + select { + case <-bw.startCh: + default: + close(bw.startCh) + } + bw.balancer.Close() +} + +// The picker is the balancerWrapper itself. +// Pick should never return ErrNoSubConnAvailable. +// It either blocks or returns error, consistent with v1 balancer Get(). +func (bw *balancerWrapper) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + failfast := true // Default failfast is true. + if ss, ok := rpcInfoFromContext(ctx); ok { + failfast = ss.failfast + } + a, p, err := bw.balancer.Get(ctx, BalancerGetOptions{BlockingWait: !failfast}) + if err != nil { + return nil, nil, err + } + var done func(balancer.DoneInfo) + if p != nil { + done = func(i balancer.DoneInfo) { p() } + } + var sc balancer.SubConn + bw.mu.Lock() + defer bw.mu.Unlock() + if bw.pickfirst { + // Get the first sc in conns. + for _, sc = range bw.conns { + break + } + } else { + var ok bool + sc, ok = bw.conns[resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, + ServerName: "", + Metadata: a.Metadata, + }] + if !ok && failfast { + return nil, nil, status.Errorf(codes.Unavailable, "there is no connection available") + } + if s, ok := bw.connSt[sc]; failfast && (!ok || s.s != connectivity.Ready) { + // If the returned sc is not ready and RPC is failfast, + // return error, and this RPC will fail. + return nil, nil, status.Errorf(codes.Unavailable, "there is no connection available") + } + } + + return sc, done, nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go new file mode 100644 index 00000000..f393bb66 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go @@ -0,0 +1,900 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: grpc/binarylog/grpc_binarylog_v1/binarylog.proto + +package grpc_binarylog_v1 // import "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import duration "github.com/golang/protobuf/ptypes/duration" +import timestamp "github.com/golang/protobuf/ptypes/timestamp" + +// 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.ProtoPackageIsVersion2 // please upgrade the proto package + +// Enumerates the type of event +// Note the terminology is different from the RPC semantics +// definition, but the same meaning is expressed here. +type GrpcLogEntry_EventType int32 + +const ( + GrpcLogEntry_EVENT_TYPE_UNKNOWN GrpcLogEntry_EventType = 0 + // Header sent from client to server + GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER GrpcLogEntry_EventType = 1 + // Header sent from server to client + GrpcLogEntry_EVENT_TYPE_SERVER_HEADER GrpcLogEntry_EventType = 2 + // Message sent from client to server + GrpcLogEntry_EVENT_TYPE_CLIENT_MESSAGE GrpcLogEntry_EventType = 3 + // Message sent from server to client + GrpcLogEntry_EVENT_TYPE_SERVER_MESSAGE GrpcLogEntry_EventType = 4 + // A signal that client is done sending + GrpcLogEntry_EVENT_TYPE_CLIENT_HALF_CLOSE GrpcLogEntry_EventType = 5 + // Trailer indicates the end of the RPC. + // On client side, this event means a trailer was either received + // from the network or the gRPC library locally generated a status + // to inform the application about a failure. + // On server side, this event means the server application requested + // to send a trailer. Note: EVENT_TYPE_CANCEL may still arrive after + // this due to races on server side. + GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER GrpcLogEntry_EventType = 6 + // A signal that the RPC is cancelled. On client side, this + // indicates the client application requests a cancellation. + // On server side, this indicates that cancellation was detected. + // Note: This marks the end of the RPC. Events may arrive after + // this due to races. For example, on client side a trailer + // may arrive even though the application requested to cancel the RPC. + GrpcLogEntry_EVENT_TYPE_CANCEL GrpcLogEntry_EventType = 7 +) + +var GrpcLogEntry_EventType_name = map[int32]string{ + 0: "EVENT_TYPE_UNKNOWN", + 1: "EVENT_TYPE_CLIENT_HEADER", + 2: "EVENT_TYPE_SERVER_HEADER", + 3: "EVENT_TYPE_CLIENT_MESSAGE", + 4: "EVENT_TYPE_SERVER_MESSAGE", + 5: "EVENT_TYPE_CLIENT_HALF_CLOSE", + 6: "EVENT_TYPE_SERVER_TRAILER", + 7: "EVENT_TYPE_CANCEL", +} +var GrpcLogEntry_EventType_value = map[string]int32{ + "EVENT_TYPE_UNKNOWN": 0, + "EVENT_TYPE_CLIENT_HEADER": 1, + "EVENT_TYPE_SERVER_HEADER": 2, + "EVENT_TYPE_CLIENT_MESSAGE": 3, + "EVENT_TYPE_SERVER_MESSAGE": 4, + "EVENT_TYPE_CLIENT_HALF_CLOSE": 5, + "EVENT_TYPE_SERVER_TRAILER": 6, + "EVENT_TYPE_CANCEL": 7, +} + +func (x GrpcLogEntry_EventType) String() string { + return proto.EnumName(GrpcLogEntry_EventType_name, int32(x)) +} +func (GrpcLogEntry_EventType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0, 0} +} + +// Enumerates the entity that generates the log entry +type GrpcLogEntry_Logger int32 + +const ( + GrpcLogEntry_LOGGER_UNKNOWN GrpcLogEntry_Logger = 0 + GrpcLogEntry_LOGGER_CLIENT GrpcLogEntry_Logger = 1 + GrpcLogEntry_LOGGER_SERVER GrpcLogEntry_Logger = 2 +) + +var GrpcLogEntry_Logger_name = map[int32]string{ + 0: "LOGGER_UNKNOWN", + 1: "LOGGER_CLIENT", + 2: "LOGGER_SERVER", +} +var GrpcLogEntry_Logger_value = map[string]int32{ + "LOGGER_UNKNOWN": 0, + "LOGGER_CLIENT": 1, + "LOGGER_SERVER": 2, +} + +func (x GrpcLogEntry_Logger) String() string { + return proto.EnumName(GrpcLogEntry_Logger_name, int32(x)) +} +func (GrpcLogEntry_Logger) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0, 1} +} + +type Address_Type int32 + +const ( + Address_TYPE_UNKNOWN Address_Type = 0 + // address is in 1.2.3.4 form + Address_TYPE_IPV4 Address_Type = 1 + // address is in IPv6 canonical form (RFC5952 section 4) + // The scope is NOT included in the address string. + Address_TYPE_IPV6 Address_Type = 2 + // address is UDS string + Address_TYPE_UNIX Address_Type = 3 +) + +var Address_Type_name = map[int32]string{ + 0: "TYPE_UNKNOWN", + 1: "TYPE_IPV4", + 2: "TYPE_IPV6", + 3: "TYPE_UNIX", +} +var Address_Type_value = map[string]int32{ + "TYPE_UNKNOWN": 0, + "TYPE_IPV4": 1, + "TYPE_IPV6": 2, + "TYPE_UNIX": 3, +} + +func (x Address_Type) String() string { + return proto.EnumName(Address_Type_name, int32(x)) +} +func (Address_Type) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{7, 0} +} + +// Log entry we store in binary logs +type GrpcLogEntry struct { + // The timestamp of the binary log message + Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + // Uniquely identifies a call. The value must not be 0 in order to disambiguate + // from an unset value. + // Each call may have several log entries, they will all have the same call_id. + // Nothing is guaranteed about their value other than they are unique across + // different RPCs in the same gRPC process. + CallId uint64 `protobuf:"varint,2,opt,name=call_id,json=callId,proto3" json:"call_id,omitempty"` + // The entry sequence id for this call. The first GrpcLogEntry has a + // value of 1, to disambiguate from an unset value. The purpose of + // this field is to detect missing entries in environments where + // durability or ordering is not guaranteed. + SequenceIdWithinCall uint64 `protobuf:"varint,3,opt,name=sequence_id_within_call,json=sequenceIdWithinCall,proto3" json:"sequence_id_within_call,omitempty"` + Type GrpcLogEntry_EventType `protobuf:"varint,4,opt,name=type,proto3,enum=grpc.binarylog.v1.GrpcLogEntry_EventType" json:"type,omitempty"` + Logger GrpcLogEntry_Logger `protobuf:"varint,5,opt,name=logger,proto3,enum=grpc.binarylog.v1.GrpcLogEntry_Logger" json:"logger,omitempty"` + // The logger uses one of the following fields to record the payload, + // according to the type of the log entry. + // + // Types that are valid to be assigned to Payload: + // *GrpcLogEntry_ClientHeader + // *GrpcLogEntry_ServerHeader + // *GrpcLogEntry_Message + // *GrpcLogEntry_Trailer + Payload isGrpcLogEntry_Payload `protobuf_oneof:"payload"` + // true if payload does not represent the full message or metadata. + PayloadTruncated bool `protobuf:"varint,10,opt,name=payload_truncated,json=payloadTruncated,proto3" json:"payload_truncated,omitempty"` + // Peer address information, will only be recorded on the first + // incoming event. On client side, peer is logged on + // EVENT_TYPE_SERVER_HEADER normally or EVENT_TYPE_SERVER_TRAILER in + // the case of trailers-only. On server side, peer is always + // logged on EVENT_TYPE_CLIENT_HEADER. + Peer *Address `protobuf:"bytes,11,opt,name=peer,proto3" json:"peer,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GrpcLogEntry) Reset() { *m = GrpcLogEntry{} } +func (m *GrpcLogEntry) String() string { return proto.CompactTextString(m) } +func (*GrpcLogEntry) ProtoMessage() {} +func (*GrpcLogEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0} +} +func (m *GrpcLogEntry) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GrpcLogEntry.Unmarshal(m, b) +} +func (m *GrpcLogEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GrpcLogEntry.Marshal(b, m, deterministic) +} +func (dst *GrpcLogEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrpcLogEntry.Merge(dst, src) +} +func (m *GrpcLogEntry) XXX_Size() int { + return xxx_messageInfo_GrpcLogEntry.Size(m) +} +func (m *GrpcLogEntry) XXX_DiscardUnknown() { + xxx_messageInfo_GrpcLogEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_GrpcLogEntry proto.InternalMessageInfo + +func (m *GrpcLogEntry) GetTimestamp() *timestamp.Timestamp { + if m != nil { + return m.Timestamp + } + return nil +} + +func (m *GrpcLogEntry) GetCallId() uint64 { + if m != nil { + return m.CallId + } + return 0 +} + +func (m *GrpcLogEntry) GetSequenceIdWithinCall() uint64 { + if m != nil { + return m.SequenceIdWithinCall + } + return 0 +} + +func (m *GrpcLogEntry) GetType() GrpcLogEntry_EventType { + if m != nil { + return m.Type + } + return GrpcLogEntry_EVENT_TYPE_UNKNOWN +} + +func (m *GrpcLogEntry) GetLogger() GrpcLogEntry_Logger { + if m != nil { + return m.Logger + } + return GrpcLogEntry_LOGGER_UNKNOWN +} + +type isGrpcLogEntry_Payload interface { + isGrpcLogEntry_Payload() +} + +type GrpcLogEntry_ClientHeader struct { + ClientHeader *ClientHeader `protobuf:"bytes,6,opt,name=client_header,json=clientHeader,proto3,oneof"` +} + +type GrpcLogEntry_ServerHeader struct { + ServerHeader *ServerHeader `protobuf:"bytes,7,opt,name=server_header,json=serverHeader,proto3,oneof"` +} + +type GrpcLogEntry_Message struct { + Message *Message `protobuf:"bytes,8,opt,name=message,proto3,oneof"` +} + +type GrpcLogEntry_Trailer struct { + Trailer *Trailer `protobuf:"bytes,9,opt,name=trailer,proto3,oneof"` +} + +func (*GrpcLogEntry_ClientHeader) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_ServerHeader) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_Message) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_Trailer) isGrpcLogEntry_Payload() {} + +func (m *GrpcLogEntry) GetPayload() isGrpcLogEntry_Payload { + if m != nil { + return m.Payload + } + return nil +} + +func (m *GrpcLogEntry) GetClientHeader() *ClientHeader { + if x, ok := m.GetPayload().(*GrpcLogEntry_ClientHeader); ok { + return x.ClientHeader + } + return nil +} + +func (m *GrpcLogEntry) GetServerHeader() *ServerHeader { + if x, ok := m.GetPayload().(*GrpcLogEntry_ServerHeader); ok { + return x.ServerHeader + } + return nil +} + +func (m *GrpcLogEntry) GetMessage() *Message { + if x, ok := m.GetPayload().(*GrpcLogEntry_Message); ok { + return x.Message + } + return nil +} + +func (m *GrpcLogEntry) GetTrailer() *Trailer { + if x, ok := m.GetPayload().(*GrpcLogEntry_Trailer); ok { + return x.Trailer + } + return nil +} + +func (m *GrpcLogEntry) GetPayloadTruncated() bool { + if m != nil { + return m.PayloadTruncated + } + return false +} + +func (m *GrpcLogEntry) GetPeer() *Address { + if m != nil { + return m.Peer + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*GrpcLogEntry) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _GrpcLogEntry_OneofMarshaler, _GrpcLogEntry_OneofUnmarshaler, _GrpcLogEntry_OneofSizer, []interface{}{ + (*GrpcLogEntry_ClientHeader)(nil), + (*GrpcLogEntry_ServerHeader)(nil), + (*GrpcLogEntry_Message)(nil), + (*GrpcLogEntry_Trailer)(nil), + } +} + +func _GrpcLogEntry_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*GrpcLogEntry) + // payload + switch x := m.Payload.(type) { + case *GrpcLogEntry_ClientHeader: + b.EncodeVarint(6<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.ClientHeader); err != nil { + return err + } + case *GrpcLogEntry_ServerHeader: + b.EncodeVarint(7<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.ServerHeader); err != nil { + return err + } + case *GrpcLogEntry_Message: + b.EncodeVarint(8<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Message); err != nil { + return err + } + case *GrpcLogEntry_Trailer: + b.EncodeVarint(9<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Trailer); err != nil { + return err + } + case nil: + default: + return fmt.Errorf("GrpcLogEntry.Payload has unexpected type %T", x) + } + return nil +} + +func _GrpcLogEntry_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*GrpcLogEntry) + switch tag { + case 6: // payload.client_header + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ClientHeader) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_ClientHeader{msg} + return true, err + case 7: // payload.server_header + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ServerHeader) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_ServerHeader{msg} + return true, err + case 8: // payload.message + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Message) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_Message{msg} + return true, err + case 9: // payload.trailer + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Trailer) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_Trailer{msg} + return true, err + default: + return false, nil + } +} + +func _GrpcLogEntry_OneofSizer(msg proto.Message) (n int) { + m := msg.(*GrpcLogEntry) + // payload + switch x := m.Payload.(type) { + case *GrpcLogEntry_ClientHeader: + s := proto.Size(x.ClientHeader) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_ServerHeader: + s := proto.Size(x.ServerHeader) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_Message: + s := proto.Size(x.Message) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_Trailer: + s := proto.Size(x.Trailer) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type ClientHeader struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + // The name of the RPC method, which looks something like: + // // + // Note the leading "/" character. + MethodName string `protobuf:"bytes,2,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` + // A single process may be used to run multiple virtual + // servers with different identities. + // The authority is the name of such a server identitiy. + // It is typically a portion of the URI in the form of + // or : . + Authority string `protobuf:"bytes,3,opt,name=authority,proto3" json:"authority,omitempty"` + // the RPC timeout + Timeout *duration.Duration `protobuf:"bytes,4,opt,name=timeout,proto3" json:"timeout,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ClientHeader) Reset() { *m = ClientHeader{} } +func (m *ClientHeader) String() string { return proto.CompactTextString(m) } +func (*ClientHeader) ProtoMessage() {} +func (*ClientHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{1} +} +func (m *ClientHeader) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ClientHeader.Unmarshal(m, b) +} +func (m *ClientHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ClientHeader.Marshal(b, m, deterministic) +} +func (dst *ClientHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientHeader.Merge(dst, src) +} +func (m *ClientHeader) XXX_Size() int { + return xxx_messageInfo_ClientHeader.Size(m) +} +func (m *ClientHeader) XXX_DiscardUnknown() { + xxx_messageInfo_ClientHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientHeader proto.InternalMessageInfo + +func (m *ClientHeader) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *ClientHeader) GetMethodName() string { + if m != nil { + return m.MethodName + } + return "" +} + +func (m *ClientHeader) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *ClientHeader) GetTimeout() *duration.Duration { + if m != nil { + return m.Timeout + } + return nil +} + +type ServerHeader struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerHeader) Reset() { *m = ServerHeader{} } +func (m *ServerHeader) String() string { return proto.CompactTextString(m) } +func (*ServerHeader) ProtoMessage() {} +func (*ServerHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{2} +} +func (m *ServerHeader) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerHeader.Unmarshal(m, b) +} +func (m *ServerHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerHeader.Marshal(b, m, deterministic) +} +func (dst *ServerHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerHeader.Merge(dst, src) +} +func (m *ServerHeader) XXX_Size() int { + return xxx_messageInfo_ServerHeader.Size(m) +} +func (m *ServerHeader) XXX_DiscardUnknown() { + xxx_messageInfo_ServerHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerHeader proto.InternalMessageInfo + +func (m *ServerHeader) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +type Trailer struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + // The gRPC status code. + StatusCode uint32 `protobuf:"varint,2,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` + // An original status message before any transport specific + // encoding. + StatusMessage string `protobuf:"bytes,3,opt,name=status_message,json=statusMessage,proto3" json:"status_message,omitempty"` + // The value of the 'grpc-status-details-bin' metadata key. If + // present, this is always an encoded 'google.rpc.Status' message. + StatusDetails []byte `protobuf:"bytes,4,opt,name=status_details,json=statusDetails,proto3" json:"status_details,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Trailer) Reset() { *m = Trailer{} } +func (m *Trailer) String() string { return proto.CompactTextString(m) } +func (*Trailer) ProtoMessage() {} +func (*Trailer) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{3} +} +func (m *Trailer) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Trailer.Unmarshal(m, b) +} +func (m *Trailer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Trailer.Marshal(b, m, deterministic) +} +func (dst *Trailer) XXX_Merge(src proto.Message) { + xxx_messageInfo_Trailer.Merge(dst, src) +} +func (m *Trailer) XXX_Size() int { + return xxx_messageInfo_Trailer.Size(m) +} +func (m *Trailer) XXX_DiscardUnknown() { + xxx_messageInfo_Trailer.DiscardUnknown(m) +} + +var xxx_messageInfo_Trailer proto.InternalMessageInfo + +func (m *Trailer) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *Trailer) GetStatusCode() uint32 { + if m != nil { + return m.StatusCode + } + return 0 +} + +func (m *Trailer) GetStatusMessage() string { + if m != nil { + return m.StatusMessage + } + return "" +} + +func (m *Trailer) GetStatusDetails() []byte { + if m != nil { + return m.StatusDetails + } + return nil +} + +// Message payload, used by CLIENT_MESSAGE and SERVER_MESSAGE +type Message struct { + // Length of the message. It may not be the same as the length of the + // data field, as the logging payload can be truncated or omitted. + Length uint32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + // May be truncated or omitted. + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +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_binarylog_264c8c9c551ce911, []int{4} +} +func (m *Message) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Message.Unmarshal(m, b) +} +func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Message.Marshal(b, m, deterministic) +} +func (dst *Message) XXX_Merge(src proto.Message) { + xxx_messageInfo_Message.Merge(dst, src) +} +func (m *Message) XXX_Size() int { + return xxx_messageInfo_Message.Size(m) +} +func (m *Message) XXX_DiscardUnknown() { + xxx_messageInfo_Message.DiscardUnknown(m) +} + +var xxx_messageInfo_Message proto.InternalMessageInfo + +func (m *Message) GetLength() uint32 { + if m != nil { + return m.Length + } + return 0 +} + +func (m *Message) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +// A list of metadata pairs, used in the payload of client header, +// server header, and server trailer. +// Implementations may omit some entries to honor the header limits +// of GRPC_BINARY_LOG_CONFIG. +// +// Header keys added by gRPC are omitted. To be more specific, +// implementations will not log the following entries, and this is +// not to be treated as a truncation: +// - entries handled by grpc that are not user visible, such as those +// that begin with 'grpc-' (with exception of grpc-trace-bin) +// or keys like 'lb-token' +// - transport specific entries, including but not limited to: +// ':path', ':authority', 'content-encoding', 'user-agent', 'te', etc +// - entries added for call credentials +// +// Implementations must always log grpc-trace-bin if it is present. +// Practically speaking it will only be visible on server side because +// grpc-trace-bin is managed by low level client side mechanisms +// inaccessible from the application level. On server side, the +// header is just a normal metadata key. +// The pair will not count towards the size limit. +type Metadata struct { + Entry []*MetadataEntry `protobuf:"bytes,1,rep,name=entry,proto3" json:"entry,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Metadata) Reset() { *m = Metadata{} } +func (m *Metadata) String() string { return proto.CompactTextString(m) } +func (*Metadata) ProtoMessage() {} +func (*Metadata) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{5} +} +func (m *Metadata) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Metadata.Unmarshal(m, b) +} +func (m *Metadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Metadata.Marshal(b, m, deterministic) +} +func (dst *Metadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_Metadata.Merge(dst, src) +} +func (m *Metadata) XXX_Size() int { + return xxx_messageInfo_Metadata.Size(m) +} +func (m *Metadata) XXX_DiscardUnknown() { + xxx_messageInfo_Metadata.DiscardUnknown(m) +} + +var xxx_messageInfo_Metadata proto.InternalMessageInfo + +func (m *Metadata) GetEntry() []*MetadataEntry { + if m != nil { + return m.Entry + } + return nil +} + +// A metadata key value pair +type MetadataEntry struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + 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 *MetadataEntry) Reset() { *m = MetadataEntry{} } +func (m *MetadataEntry) String() string { return proto.CompactTextString(m) } +func (*MetadataEntry) ProtoMessage() {} +func (*MetadataEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{6} +} +func (m *MetadataEntry) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_MetadataEntry.Unmarshal(m, b) +} +func (m *MetadataEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_MetadataEntry.Marshal(b, m, deterministic) +} +func (dst *MetadataEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MetadataEntry.Merge(dst, src) +} +func (m *MetadataEntry) XXX_Size() int { + return xxx_messageInfo_MetadataEntry.Size(m) +} +func (m *MetadataEntry) XXX_DiscardUnknown() { + xxx_messageInfo_MetadataEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_MetadataEntry proto.InternalMessageInfo + +func (m *MetadataEntry) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *MetadataEntry) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +// Address information +type Address struct { + Type Address_Type `protobuf:"varint,1,opt,name=type,proto3,enum=grpc.binarylog.v1.Address_Type" json:"type,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // only for TYPE_IPV4 and TYPE_IPV6 + IpPort uint32 `protobuf:"varint,3,opt,name=ip_port,json=ipPort,proto3" json:"ip_port,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Address) Reset() { *m = Address{} } +func (m *Address) String() string { return proto.CompactTextString(m) } +func (*Address) ProtoMessage() {} +func (*Address) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{7} +} +func (m *Address) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Address.Unmarshal(m, b) +} +func (m *Address) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Address.Marshal(b, m, deterministic) +} +func (dst *Address) XXX_Merge(src proto.Message) { + xxx_messageInfo_Address.Merge(dst, src) +} +func (m *Address) XXX_Size() int { + return xxx_messageInfo_Address.Size(m) +} +func (m *Address) XXX_DiscardUnknown() { + xxx_messageInfo_Address.DiscardUnknown(m) +} + +var xxx_messageInfo_Address proto.InternalMessageInfo + +func (m *Address) GetType() Address_Type { + if m != nil { + return m.Type + } + return Address_TYPE_UNKNOWN +} + +func (m *Address) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Address) GetIpPort() uint32 { + if m != nil { + return m.IpPort + } + return 0 +} + +func init() { + proto.RegisterType((*GrpcLogEntry)(nil), "grpc.binarylog.v1.GrpcLogEntry") + proto.RegisterType((*ClientHeader)(nil), "grpc.binarylog.v1.ClientHeader") + proto.RegisterType((*ServerHeader)(nil), "grpc.binarylog.v1.ServerHeader") + proto.RegisterType((*Trailer)(nil), "grpc.binarylog.v1.Trailer") + proto.RegisterType((*Message)(nil), "grpc.binarylog.v1.Message") + proto.RegisterType((*Metadata)(nil), "grpc.binarylog.v1.Metadata") + proto.RegisterType((*MetadataEntry)(nil), "grpc.binarylog.v1.MetadataEntry") + proto.RegisterType((*Address)(nil), "grpc.binarylog.v1.Address") + proto.RegisterEnum("grpc.binarylog.v1.GrpcLogEntry_EventType", GrpcLogEntry_EventType_name, GrpcLogEntry_EventType_value) + proto.RegisterEnum("grpc.binarylog.v1.GrpcLogEntry_Logger", GrpcLogEntry_Logger_name, GrpcLogEntry_Logger_value) + proto.RegisterEnum("grpc.binarylog.v1.Address_Type", Address_Type_name, Address_Type_value) +} + +func init() { + proto.RegisterFile("grpc/binarylog/grpc_binarylog_v1/binarylog.proto", fileDescriptor_binarylog_264c8c9c551ce911) +} + +var fileDescriptor_binarylog_264c8c9c551ce911 = []byte{ + // 900 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x51, 0x6f, 0xe3, 0x44, + 0x10, 0x3e, 0x37, 0x69, 0xdc, 0x4c, 0x92, 0xca, 0x5d, 0x95, 0x3b, 0x5f, 0x29, 0x34, 0xb2, 0x04, + 0x0a, 0x42, 0x72, 0xb9, 0x94, 0xeb, 0xf1, 0x02, 0x52, 0x92, 0xfa, 0xd2, 0x88, 0x5c, 0x1a, 0x6d, + 0x72, 0x3d, 0x40, 0x48, 0xd6, 0x36, 0x5e, 0x1c, 0x0b, 0xc7, 0x6b, 0xd6, 0x9b, 0xa0, 0xfc, 0x2c, + 0xde, 0x90, 0xee, 0x77, 0xf1, 0x8e, 0xbc, 0x6b, 0x27, 0xa6, 0x69, 0x0f, 0x09, 0xde, 0x3c, 0xdf, + 0x7c, 0xf3, 0xcd, 0xee, 0x78, 0x66, 0x16, 0xbe, 0xf2, 0x79, 0x3c, 0x3b, 0xbf, 0x0b, 0x22, 0xc2, + 0xd7, 0x21, 0xf3, 0xcf, 0x53, 0xd3, 0xdd, 0x98, 0xee, 0xea, 0xc5, 0xd6, 0x67, 0xc7, 0x9c, 0x09, + 0x86, 0x8e, 0x52, 0x8a, 0xbd, 0x45, 0x57, 0x2f, 0x4e, 0x3e, 0xf5, 0x19, 0xf3, 0x43, 0x7a, 0x2e, + 0x09, 0x77, 0xcb, 0x5f, 0xce, 0xbd, 0x25, 0x27, 0x22, 0x60, 0x91, 0x0a, 0x39, 0x39, 0xbb, 0xef, + 0x17, 0xc1, 0x82, 0x26, 0x82, 0x2c, 0x62, 0x45, 0xb0, 0xde, 0xeb, 0x50, 0xef, 0xf3, 0x78, 0x36, + 0x64, 0xbe, 0x13, 0x09, 0xbe, 0x46, 0xdf, 0x40, 0x75, 0xc3, 0x31, 0xb5, 0xa6, 0xd6, 0xaa, 0xb5, + 0x4f, 0x6c, 0xa5, 0x62, 0xe7, 0x2a, 0xf6, 0x34, 0x67, 0xe0, 0x2d, 0x19, 0x3d, 0x03, 0x7d, 0x46, + 0xc2, 0xd0, 0x0d, 0x3c, 0x73, 0xaf, 0xa9, 0xb5, 0xca, 0xb8, 0x92, 0x9a, 0x03, 0x0f, 0xbd, 0x84, + 0x67, 0x09, 0xfd, 0x6d, 0x49, 0xa3, 0x19, 0x75, 0x03, 0xcf, 0xfd, 0x3d, 0x10, 0xf3, 0x20, 0x72, + 0x53, 0xa7, 0x59, 0x92, 0xc4, 0xe3, 0xdc, 0x3d, 0xf0, 0xde, 0x49, 0x67, 0x8f, 0x84, 0x21, 0xfa, + 0x16, 0xca, 0x62, 0x1d, 0x53, 0xb3, 0xdc, 0xd4, 0x5a, 0x87, 0xed, 0x2f, 0xec, 0x9d, 0xdb, 0xdb, + 0xc5, 0x83, 0xdb, 0xce, 0x8a, 0x46, 0x62, 0xba, 0x8e, 0x29, 0x96, 0x61, 0xe8, 0x3b, 0xa8, 0x84, + 0xcc, 0xf7, 0x29, 0x37, 0xf7, 0xa5, 0xc0, 0xe7, 0xff, 0x26, 0x30, 0x94, 0x6c, 0x9c, 0x45, 0xa1, + 0xd7, 0xd0, 0x98, 0x85, 0x01, 0x8d, 0x84, 0x3b, 0xa7, 0xc4, 0xa3, 0xdc, 0xac, 0xc8, 0x62, 0x9c, + 0x3d, 0x20, 0xd3, 0x93, 0xbc, 0x6b, 0x49, 0xbb, 0x7e, 0x82, 0xeb, 0xb3, 0x82, 0x9d, 0xea, 0x24, + 0x94, 0xaf, 0x28, 0xcf, 0x75, 0xf4, 0x47, 0x75, 0x26, 0x92, 0xb7, 0xd5, 0x49, 0x0a, 0x36, 0xba, + 0x04, 0x7d, 0x41, 0x93, 0x84, 0xf8, 0xd4, 0x3c, 0xc8, 0x7f, 0xcb, 0x8e, 0xc2, 0x1b, 0xc5, 0xb8, + 0x7e, 0x82, 0x73, 0x72, 0x1a, 0x27, 0x38, 0x09, 0x42, 0xca, 0xcd, 0xea, 0xa3, 0x71, 0x53, 0xc5, + 0x48, 0xe3, 0x32, 0x32, 0xfa, 0x12, 0x8e, 0x62, 0xb2, 0x0e, 0x19, 0xf1, 0x5c, 0xc1, 0x97, 0xd1, + 0x8c, 0x08, 0xea, 0x99, 0xd0, 0xd4, 0x5a, 0x07, 0xd8, 0xc8, 0x1c, 0xd3, 0x1c, 0x47, 0x36, 0x94, + 0x63, 0x4a, 0xb9, 0x59, 0x7b, 0x34, 0x43, 0xc7, 0xf3, 0x38, 0x4d, 0x12, 0x2c, 0x79, 0xd6, 0x5f, + 0x1a, 0x54, 0x37, 0x3f, 0x0c, 0x3d, 0x05, 0xe4, 0xdc, 0x3a, 0xa3, 0xa9, 0x3b, 0xfd, 0x71, 0xec, + 0xb8, 0x6f, 0x47, 0xdf, 0x8f, 0x6e, 0xde, 0x8d, 0x8c, 0x27, 0xe8, 0x14, 0xcc, 0x02, 0xde, 0x1b, + 0x0e, 0xd2, 0xef, 0x6b, 0xa7, 0x73, 0xe5, 0x60, 0x43, 0xbb, 0xe7, 0x9d, 0x38, 0xf8, 0xd6, 0xc1, + 0xb9, 0x77, 0x0f, 0x7d, 0x02, 0xcf, 0x77, 0x63, 0xdf, 0x38, 0x93, 0x49, 0xa7, 0xef, 0x18, 0xa5, + 0x7b, 0xee, 0x2c, 0x38, 0x77, 0x97, 0x51, 0x13, 0x4e, 0x1f, 0xc8, 0xdc, 0x19, 0xbe, 0x76, 0x7b, + 0xc3, 0x9b, 0x89, 0x63, 0xec, 0x3f, 0x2c, 0x30, 0xc5, 0x9d, 0xc1, 0xd0, 0xc1, 0x46, 0x05, 0x7d, + 0x04, 0x47, 0x45, 0x81, 0xce, 0xa8, 0xe7, 0x0c, 0x0d, 0xdd, 0xea, 0x42, 0x45, 0xb5, 0x19, 0x42, + 0x70, 0x38, 0xbc, 0xe9, 0xf7, 0x1d, 0x5c, 0xb8, 0xef, 0x11, 0x34, 0x32, 0x4c, 0x65, 0x34, 0xb4, + 0x02, 0xa4, 0x52, 0x18, 0x7b, 0xdd, 0x2a, 0xe8, 0x59, 0xfd, 0xad, 0xf7, 0x1a, 0xd4, 0x8b, 0xcd, + 0x87, 0x5e, 0xc1, 0xc1, 0x82, 0x0a, 0xe2, 0x11, 0x41, 0xb2, 0xe1, 0xfd, 0xf8, 0xc1, 0x2e, 0x51, + 0x14, 0xbc, 0x21, 0xa3, 0x33, 0xa8, 0x2d, 0xa8, 0x98, 0x33, 0xcf, 0x8d, 0xc8, 0x82, 0xca, 0x01, + 0xae, 0x62, 0x50, 0xd0, 0x88, 0x2c, 0x28, 0x3a, 0x85, 0x2a, 0x59, 0x8a, 0x39, 0xe3, 0x81, 0x58, + 0xcb, 0xb1, 0xad, 0xe2, 0x2d, 0x80, 0x2e, 0x40, 0x4f, 0x17, 0x01, 0x5b, 0x0a, 0x39, 0xae, 0xb5, + 0xf6, 0xf3, 0x9d, 0x9d, 0x71, 0x95, 0x6d, 0x26, 0x9c, 0x33, 0xad, 0x3e, 0xd4, 0x8b, 0x1d, 0xff, + 0x9f, 0x0f, 0x6f, 0xfd, 0xa1, 0x81, 0x9e, 0x75, 0xf0, 0xff, 0xaa, 0x40, 0x22, 0x88, 0x58, 0x26, + 0xee, 0x8c, 0x79, 0xaa, 0x02, 0x0d, 0x0c, 0x0a, 0xea, 0x31, 0x8f, 0xa2, 0xcf, 0xe0, 0x30, 0x23, + 0xe4, 0x73, 0xa8, 0xca, 0xd0, 0x50, 0x68, 0x36, 0x7a, 0x05, 0x9a, 0x47, 0x05, 0x09, 0xc2, 0x44, + 0x56, 0xa4, 0x9e, 0xd3, 0xae, 0x14, 0x68, 0xbd, 0x04, 0x3d, 0x8f, 0x78, 0x0a, 0x95, 0x90, 0x46, + 0xbe, 0x98, 0xcb, 0x03, 0x37, 0x70, 0x66, 0x21, 0x04, 0x65, 0x79, 0x8d, 0x3d, 0x19, 0x2f, 0xbf, + 0xad, 0x2e, 0x1c, 0xe4, 0x67, 0x47, 0x97, 0xb0, 0x4f, 0xd3, 0xcd, 0x65, 0x6a, 0xcd, 0x52, 0xab, + 0xd6, 0x6e, 0x7e, 0xe0, 0x9e, 0x72, 0xc3, 0x61, 0x45, 0xb7, 0x5e, 0x41, 0xe3, 0x1f, 0x38, 0x32, + 0xa0, 0xf4, 0x2b, 0x5d, 0xcb, 0xec, 0x55, 0x9c, 0x7e, 0xa2, 0x63, 0xd8, 0x5f, 0x91, 0x70, 0x49, + 0xb3, 0xdc, 0xca, 0xb0, 0xfe, 0xd4, 0x40, 0xcf, 0xe6, 0x18, 0x5d, 0x64, 0xdb, 0x59, 0x93, 0xcb, + 0xf5, 0xec, 0xf1, 0x89, 0xb7, 0x0b, 0x3b, 0xd9, 0x04, 0x9d, 0x28, 0x34, 0xeb, 0xb0, 0xdc, 0x4c, + 0x1f, 0x8f, 0x20, 0x76, 0x63, 0xc6, 0x85, 0xac, 0x6a, 0x03, 0x57, 0x82, 0x78, 0xcc, 0xb8, 0xb0, + 0x1c, 0x28, 0xcb, 0x1d, 0x61, 0x40, 0xfd, 0xde, 0x76, 0x68, 0x40, 0x55, 0x22, 0x83, 0xf1, 0xed, + 0xd7, 0x86, 0x56, 0x34, 0x2f, 0x8d, 0xbd, 0x8d, 0xf9, 0x76, 0x34, 0xf8, 0xc1, 0x28, 0x75, 0x7f, + 0x86, 0xe3, 0x80, 0xed, 0x1e, 0xb2, 0x7b, 0xd8, 0x95, 0xd6, 0x90, 0xf9, 0xe3, 0xb4, 0x51, 0xc7, + 0xda, 0x4f, 0xed, 0xac, 0x71, 0x7d, 0x16, 0x92, 0xc8, 0xb7, 0x19, 0x57, 0x4f, 0xf3, 0x87, 0x5e, + 0xea, 0xbb, 0x8a, 0xec, 0xf2, 0x8b, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xf6, 0x4b, 0x50, + 0xd4, 0x07, 0x00, 0x00, +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go new file mode 100644 index 00000000..100f05dc --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go @@ -0,0 +1,74 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" +) + +// Invoke sends the RPC request on the wire and returns after response is +// received. This is typically called by generated code. +// +// All errors returned by Invoke are compatible with the status package. +func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error { + // allow interceptor to see all applicable call options, which means those + // configured as defaults from dial option as well as per-call options + opts = combine(cc.dopts.callOptions, opts) + + if cc.dopts.unaryInt != nil { + return cc.dopts.unaryInt(ctx, method, args, reply, cc, invoke, opts...) + } + return invoke(ctx, method, args, reply, cc, opts...) +} + +func combine(o1 []CallOption, o2 []CallOption) []CallOption { + // we don't use append because o1 could have extra capacity whose + // elements would be overwritten, which could cause inadvertent + // sharing (and race connditions) between concurrent calls + if len(o1) == 0 { + return o2 + } else if len(o2) == 0 { + return o1 + } + ret := make([]CallOption, len(o1)+len(o2)) + copy(ret, o1) + copy(ret[len(o1):], o2) + return ret +} + +// Invoke sends the RPC request on the wire and returns after response is +// received. This is typically called by generated code. +// +// DEPRECATED: Use ClientConn.Invoke instead. +func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) error { + return cc.Invoke(ctx, method, args, reply, opts...) +} + +var unaryStreamDesc = &StreamDesc{ServerStreams: false, ClientStreams: false} + +func invoke(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error { + cs, err := newClientStream(ctx, unaryStreamDesc, cc, method, opts...) + if err != nil { + return err + } + if err := cs.SendMsg(req); err != nil { + return err + } + return cs.RecvMsg(reply) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go new file mode 100644 index 00000000..84b6dbe3 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go @@ -0,0 +1,1508 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "fmt" + "math" + "net" + "reflect" + "strings" + "sync" + "sync/atomic" + "time" + + "google.golang.org/grpc/balancer" + _ "google.golang.org/grpc/balancer/roundrobin" // To register roundrobin. + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/envconfig" + "google.golang.org/grpc/internal/grpcsync" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/resolver" + _ "google.golang.org/grpc/resolver/dns" // To register dns resolver. + _ "google.golang.org/grpc/resolver/passthrough" // To register passthrough resolver. + "google.golang.org/grpc/status" +) + +const ( + // minimum time to give a connection to complete + minConnectTimeout = 20 * time.Second + // must match grpclbName in grpclb/grpclb.go + grpclbName = "grpclb" +) + +var ( + // ErrClientConnClosing indicates that the operation is illegal because + // the ClientConn is closing. + // + // Deprecated: this error should not be relied upon by users; use the status + // code of Canceled instead. + ErrClientConnClosing = status.Error(codes.Canceled, "grpc: the client connection is closing") + // errConnDrain indicates that the connection starts to be drained and does not accept any new RPCs. + errConnDrain = errors.New("grpc: the connection is drained") + // errConnClosing indicates that the connection is closing. + errConnClosing = errors.New("grpc: the connection is closing") + // errBalancerClosed indicates that the balancer is closed. + errBalancerClosed = errors.New("grpc: balancer is closed") + // We use an accessor so that minConnectTimeout can be + // atomically read and updated while testing. + getMinConnectTimeout = func() time.Duration { + return minConnectTimeout + } +) + +// The following errors are returned from Dial and DialContext +var ( + // errNoTransportSecurity indicates that there is no transport security + // being set for ClientConn. Users should either set one or explicitly + // call WithInsecure DialOption to disable security. + errNoTransportSecurity = errors.New("grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)") + // errTransportCredsAndBundle indicates that creds bundle is used together + // with other individual Transport Credentials. + errTransportCredsAndBundle = errors.New("grpc: credentials.Bundle may not be used with individual TransportCredentials") + // errTransportCredentialsMissing indicates that users want to transmit security + // information (e.g., oauth2 token) which requires secure connection on an insecure + // connection. + errTransportCredentialsMissing = errors.New("grpc: the credentials require transport level security (use grpc.WithTransportCredentials() to set)") + // errCredentialsConflict indicates that grpc.WithTransportCredentials() + // and grpc.WithInsecure() are both called for a connection. + errCredentialsConflict = errors.New("grpc: transport credentials are set for an insecure connection (grpc.WithTransportCredentials() and grpc.WithInsecure() are both called)") +) + +const ( + defaultClientMaxReceiveMessageSize = 1024 * 1024 * 4 + defaultClientMaxSendMessageSize = math.MaxInt32 + // http2IOBufSize specifies the buffer size for sending frames. + defaultWriteBufSize = 32 * 1024 + defaultReadBufSize = 32 * 1024 +) + +// Dial creates a client connection to the given target. +func Dial(target string, opts ...DialOption) (*ClientConn, error) { + return DialContext(context.Background(), target, opts...) +} + +// DialContext creates a client connection to the given target. By default, it's +// a non-blocking dial (the function won't wait for connections to be +// established, and connecting happens in the background). To make it a blocking +// dial, use WithBlock() dial option. +// +// In the non-blocking case, the ctx does not act against the connection. It +// only controls the setup steps. +// +// In the blocking case, ctx can be used to cancel or expire the pending +// connection. Once this function returns, the cancellation and expiration of +// ctx will be noop. Users should call ClientConn.Close to terminate all the +// pending operations after this function returns. +// +// The target name syntax is defined in +// https://github.com/grpc/grpc/blob/master/doc/naming.md. +// e.g. to use dns resolver, a "dns:///" prefix should be applied to the target. +func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) { + cc := &ClientConn{ + target: target, + csMgr: &connectivityStateManager{}, + conns: make(map[*addrConn]struct{}), + dopts: defaultDialOptions(), + blockingpicker: newPickerWrapper(), + czData: new(channelzData), + firstResolveEvent: grpcsync.NewEvent(), + } + cc.retryThrottler.Store((*retryThrottler)(nil)) + cc.ctx, cc.cancel = context.WithCancel(context.Background()) + + for _, opt := range opts { + opt.apply(&cc.dopts) + } + + if channelz.IsOn() { + if cc.dopts.channelzParentID != 0 { + cc.channelzID = channelz.RegisterChannel(&channelzChannel{cc}, cc.dopts.channelzParentID, target) + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Channel Created", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Nested Channel(id:%d) created", cc.channelzID), + Severity: channelz.CtINFO, + }, + }) + } else { + cc.channelzID = channelz.RegisterChannel(&channelzChannel{cc}, 0, target) + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Channel Created", + Severity: channelz.CtINFO, + }) + } + cc.csMgr.channelzID = cc.channelzID + } + + if !cc.dopts.insecure { + if cc.dopts.copts.TransportCredentials == nil && cc.dopts.copts.CredsBundle == nil { + return nil, errNoTransportSecurity + } + if cc.dopts.copts.TransportCredentials != nil && cc.dopts.copts.CredsBundle != nil { + return nil, errTransportCredsAndBundle + } + } else { + if cc.dopts.copts.TransportCredentials != nil || cc.dopts.copts.CredsBundle != nil { + return nil, errCredentialsConflict + } + for _, cd := range cc.dopts.copts.PerRPCCredentials { + if cd.RequireTransportSecurity() { + return nil, errTransportCredentialsMissing + } + } + } + + cc.mkp = cc.dopts.copts.KeepaliveParams + + if cc.dopts.copts.Dialer == nil { + cc.dopts.copts.Dialer = newProxyDialer( + func(ctx context.Context, addr string) (net.Conn, error) { + network, addr := parseDialTarget(addr) + return (&net.Dialer{}).DialContext(ctx, network, addr) + }, + ) + } + + if cc.dopts.copts.UserAgent != "" { + cc.dopts.copts.UserAgent += " " + grpcUA + } else { + cc.dopts.copts.UserAgent = grpcUA + } + + if cc.dopts.timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, cc.dopts.timeout) + defer cancel() + } + + defer func() { + select { + case <-ctx.Done(): + conn, err = nil, ctx.Err() + default: + } + + if err != nil { + cc.Close() + } + }() + + scSet := false + if cc.dopts.scChan != nil { + // Try to get an initial service config. + select { + case sc, ok := <-cc.dopts.scChan: + if ok { + cc.sc = sc + scSet = true + } + default: + } + } + if cc.dopts.bs == nil { + cc.dopts.bs = backoff.Exponential{ + MaxDelay: DefaultBackoffConfig.MaxDelay, + } + } + if cc.dopts.resolverBuilder == nil { + // Only try to parse target when resolver builder is not already set. + cc.parsedTarget = parseTarget(cc.target) + grpclog.Infof("parsed scheme: %q", cc.parsedTarget.Scheme) + cc.dopts.resolverBuilder = resolver.Get(cc.parsedTarget.Scheme) + if cc.dopts.resolverBuilder == nil { + // If resolver builder is still nil, the parse target's scheme is + // not registered. Fallback to default resolver and set Endpoint to + // the original unparsed target. + grpclog.Infof("scheme %q not registered, fallback to default scheme", cc.parsedTarget.Scheme) + cc.parsedTarget = resolver.Target{ + Scheme: resolver.GetDefaultScheme(), + Endpoint: target, + } + cc.dopts.resolverBuilder = resolver.Get(cc.parsedTarget.Scheme) + } + } else { + cc.parsedTarget = resolver.Target{Endpoint: target} + } + creds := cc.dopts.copts.TransportCredentials + if creds != nil && creds.Info().ServerName != "" { + cc.authority = creds.Info().ServerName + } else if cc.dopts.insecure && cc.dopts.authority != "" { + cc.authority = cc.dopts.authority + } else { + // Use endpoint from "scheme://authority/endpoint" as the default + // authority for ClientConn. + cc.authority = cc.parsedTarget.Endpoint + } + + if cc.dopts.scChan != nil && !scSet { + // Blocking wait for the initial service config. + select { + case sc, ok := <-cc.dopts.scChan: + if ok { + cc.sc = sc + } + case <-ctx.Done(): + return nil, ctx.Err() + } + } + if cc.dopts.scChan != nil { + go cc.scWatcher() + } + + var credsClone credentials.TransportCredentials + if creds := cc.dopts.copts.TransportCredentials; creds != nil { + credsClone = creds.Clone() + } + cc.balancerBuildOpts = balancer.BuildOptions{ + DialCreds: credsClone, + CredsBundle: cc.dopts.copts.CredsBundle, + Dialer: cc.dopts.copts.Dialer, + ChannelzParentID: cc.channelzID, + } + + // Build the resolver. + rWrapper, err := newCCResolverWrapper(cc) + if err != nil { + return nil, fmt.Errorf("failed to build resolver: %v", err) + } + + cc.mu.Lock() + cc.resolverWrapper = rWrapper + cc.mu.Unlock() + // A blocking dial blocks until the clientConn is ready. + if cc.dopts.block { + for { + s := cc.GetState() + if s == connectivity.Ready { + break + } else if cc.dopts.copts.FailOnNonTempDialError && s == connectivity.TransientFailure { + if err = cc.blockingpicker.connectionError(); err != nil { + terr, ok := err.(interface { + Temporary() bool + }) + if ok && !terr.Temporary() { + return nil, err + } + } + } + if !cc.WaitForStateChange(ctx, s) { + // ctx got timeout or canceled. + return nil, ctx.Err() + } + } + } + + return cc, nil +} + +// connectivityStateManager keeps the connectivity.State of ClientConn. +// This struct will eventually be exported so the balancers can access it. +type connectivityStateManager struct { + mu sync.Mutex + state connectivity.State + notifyChan chan struct{} + channelzID int64 +} + +// updateState updates the connectivity.State of ClientConn. +// If there's a change it notifies goroutines waiting on state change to +// happen. +func (csm *connectivityStateManager) updateState(state connectivity.State) { + csm.mu.Lock() + defer csm.mu.Unlock() + if csm.state == connectivity.Shutdown { + return + } + if csm.state == state { + return + } + csm.state = state + if channelz.IsOn() { + channelz.AddTraceEvent(csm.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel Connectivity change to %v", state), + Severity: channelz.CtINFO, + }) + } + if csm.notifyChan != nil { + // There are other goroutines waiting on this channel. + close(csm.notifyChan) + csm.notifyChan = nil + } +} + +func (csm *connectivityStateManager) getState() connectivity.State { + csm.mu.Lock() + defer csm.mu.Unlock() + return csm.state +} + +func (csm *connectivityStateManager) getNotifyChan() <-chan struct{} { + csm.mu.Lock() + defer csm.mu.Unlock() + if csm.notifyChan == nil { + csm.notifyChan = make(chan struct{}) + } + return csm.notifyChan +} + +// ClientConn represents a client connection to an RPC server. +type ClientConn struct { + ctx context.Context + cancel context.CancelFunc + + target string + parsedTarget resolver.Target + authority string + dopts dialOptions + csMgr *connectivityStateManager + + balancerBuildOpts balancer.BuildOptions + blockingpicker *pickerWrapper + + mu sync.RWMutex + resolverWrapper *ccResolverWrapper + sc ServiceConfig + scRaw string + conns map[*addrConn]struct{} + // Keepalive parameter can be updated if a GoAway is received. + mkp keepalive.ClientParameters + curBalancerName string + preBalancerName string // previous balancer name. + curAddresses []resolver.Address + balancerWrapper *ccBalancerWrapper + retryThrottler atomic.Value + + firstResolveEvent *grpcsync.Event + + channelzID int64 // channelz unique identification number + czData *channelzData +} + +// WaitForStateChange waits until the connectivity.State of ClientConn changes from sourceState or +// ctx expires. A true value is returned in former case and false in latter. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) WaitForStateChange(ctx context.Context, sourceState connectivity.State) bool { + ch := cc.csMgr.getNotifyChan() + if cc.csMgr.getState() != sourceState { + return true + } + select { + case <-ctx.Done(): + return false + case <-ch: + return true + } +} + +// GetState returns the connectivity.State of ClientConn. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) GetState() connectivity.State { + return cc.csMgr.getState() +} + +func (cc *ClientConn) scWatcher() { + for { + select { + case sc, ok := <-cc.dopts.scChan: + if !ok { + return + } + cc.mu.Lock() + // TODO: load balance policy runtime change is ignored. + // We may revist this decision in the future. + cc.sc = sc + cc.scRaw = "" + cc.mu.Unlock() + case <-cc.ctx.Done(): + return + } + } +} + +// waitForResolvedAddrs blocks until the resolver has provided addresses or the +// context expires. Returns nil unless the context expires first; otherwise +// returns a status error based on the context. +func (cc *ClientConn) waitForResolvedAddrs(ctx context.Context) error { + // This is on the RPC path, so we use a fast path to avoid the + // more-expensive "select" below after the resolver has returned once. + if cc.firstResolveEvent.HasFired() { + return nil + } + select { + case <-cc.firstResolveEvent.Done(): + return nil + case <-ctx.Done(): + return status.FromContextError(ctx.Err()).Err() + case <-cc.ctx.Done(): + return ErrClientConnClosing + } +} + +func (cc *ClientConn) handleResolvedAddrs(addrs []resolver.Address, err error) { + cc.mu.Lock() + defer cc.mu.Unlock() + if cc.conns == nil { + // cc was closed. + return + } + + if reflect.DeepEqual(cc.curAddresses, addrs) { + return + } + + cc.curAddresses = addrs + cc.firstResolveEvent.Fire() + + if cc.dopts.balancerBuilder == nil { + // Only look at balancer types and switch balancer if balancer dial + // option is not set. + var isGRPCLB bool + for _, a := range addrs { + if a.Type == resolver.GRPCLB { + isGRPCLB = true + break + } + } + var newBalancerName string + if isGRPCLB { + newBalancerName = grpclbName + } else { + // Address list doesn't contain grpclb address. Try to pick a + // non-grpclb balancer. + newBalancerName = cc.curBalancerName + // If current balancer is grpclb, switch to the previous one. + if newBalancerName == grpclbName { + newBalancerName = cc.preBalancerName + } + // The following could be true in two cases: + // - the first time handling resolved addresses + // (curBalancerName="") + // - the first time handling non-grpclb addresses + // (curBalancerName="grpclb", preBalancerName="") + if newBalancerName == "" { + newBalancerName = PickFirstBalancerName + } + } + cc.switchBalancer(newBalancerName) + } else if cc.balancerWrapper == nil { + // Balancer dial option was set, and this is the first time handling + // resolved addresses. Build a balancer with dopts.balancerBuilder. + cc.balancerWrapper = newCCBalancerWrapper(cc, cc.dopts.balancerBuilder, cc.balancerBuildOpts) + } + + cc.balancerWrapper.handleResolvedAddrs(addrs, nil) +} + +// switchBalancer starts the switching from current balancer to the balancer +// with the given name. +// +// It will NOT send the current address list to the new balancer. If needed, +// caller of this function should send address list to the new balancer after +// this function returns. +// +// Caller must hold cc.mu. +func (cc *ClientConn) switchBalancer(name string) { + if cc.conns == nil { + return + } + + if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) { + return + } + + grpclog.Infof("ClientConn switching balancer to %q", name) + if cc.dopts.balancerBuilder != nil { + grpclog.Infoln("ignoring balancer switching: Balancer DialOption used instead") + return + } + // TODO(bar switching) change this to two steps: drain and close. + // Keep track of sc in wrapper. + if cc.balancerWrapper != nil { + cc.balancerWrapper.close() + } + + builder := balancer.Get(name) + // TODO(yuxuanli): If user send a service config that does not contain a valid balancer name, should + // we reuse previous one? + if channelz.IsOn() { + if builder == nil { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel switches to new LB policy %q due to fallback from invalid balancer name", PickFirstBalancerName), + Severity: channelz.CtWarning, + }) + } else { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel switches to new LB policy %q", name), + Severity: channelz.CtINFO, + }) + } + } + if builder == nil { + grpclog.Infof("failed to get balancer builder for: %v, using pick_first instead", name) + builder = newPickfirstBuilder() + } + + cc.preBalancerName = cc.curBalancerName + cc.curBalancerName = builder.Name() + cc.balancerWrapper = newCCBalancerWrapper(cc, builder, cc.balancerBuildOpts) +} + +func (cc *ClientConn) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return + } + // TODO(bar switching) send updates to all balancer wrappers when balancer + // gracefully switching is supported. + cc.balancerWrapper.handleSubConnStateChange(sc, s) + cc.mu.Unlock() +} + +// newAddrConn creates an addrConn for addrs and adds it to cc.conns. +// +// Caller needs to make sure len(addrs) > 0. +func (cc *ClientConn) newAddrConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (*addrConn, error) { + ac := &addrConn{ + cc: cc, + addrs: addrs, + scopts: opts, + dopts: cc.dopts, + czData: new(channelzData), + successfulHandshake: true, // make the first nextAddr() call _not_ move addrIdx up by 1 + resetBackoff: make(chan struct{}), + } + ac.ctx, ac.cancel = context.WithCancel(cc.ctx) + // Track ac in cc. This needs to be done before any getTransport(...) is called. + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return nil, ErrClientConnClosing + } + if channelz.IsOn() { + ac.channelzID = channelz.RegisterSubChannel(ac, cc.channelzID, "") + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel Created", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel(id:%d) created", ac.channelzID), + Severity: channelz.CtINFO, + }, + }) + } + cc.conns[ac] = struct{}{} + cc.mu.Unlock() + return ac, nil +} + +// removeAddrConn removes the addrConn in the subConn from clientConn. +// It also tears down the ac with the given error. +func (cc *ClientConn) removeAddrConn(ac *addrConn, err error) { + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return + } + delete(cc.conns, ac) + cc.mu.Unlock() + ac.tearDown(err) +} + +func (cc *ClientConn) channelzMetric() *channelz.ChannelInternalMetric { + return &channelz.ChannelInternalMetric{ + State: cc.GetState(), + Target: cc.target, + CallsStarted: atomic.LoadInt64(&cc.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&cc.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&cc.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&cc.czData.lastCallStartedTime)), + } +} + +// Target returns the target string of the ClientConn. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) Target() string { + return cc.target +} + +func (cc *ClientConn) incrCallsStarted() { + atomic.AddInt64(&cc.czData.callsStarted, 1) + atomic.StoreInt64(&cc.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (cc *ClientConn) incrCallsSucceeded() { + atomic.AddInt64(&cc.czData.callsSucceeded, 1) +} + +func (cc *ClientConn) incrCallsFailed() { + atomic.AddInt64(&cc.czData.callsFailed, 1) +} + +// connect starts creating a transport. +// It does nothing if the ac is not IDLE. +// TODO(bar) Move this to the addrConn section. +func (ac *addrConn) connect() error { + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return errConnClosing + } + if ac.state != connectivity.Idle { + ac.mu.Unlock() + return nil + } + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.mu.Unlock() + + // Start a goroutine connecting to the server asynchronously. + go ac.resetTransport(false) + return nil +} + +// tryUpdateAddrs tries to update ac.addrs with the new addresses list. +// +// It checks whether current connected address of ac is in the new addrs list. +// - If true, it updates ac.addrs and returns true. The ac will keep using +// the existing connection. +// - If false, it does nothing and returns false. +func (ac *addrConn) tryUpdateAddrs(addrs []resolver.Address) bool { + ac.mu.Lock() + defer ac.mu.Unlock() + grpclog.Infof("addrConn: tryUpdateAddrs curAddr: %v, addrs: %v", ac.curAddr, addrs) + if ac.state == connectivity.Shutdown { + ac.addrs = addrs + return true + } + + var curAddrFound bool + for _, a := range addrs { + if reflect.DeepEqual(ac.curAddr, a) { + curAddrFound = true + break + } + } + grpclog.Infof("addrConn: tryUpdateAddrs curAddrFound: %v", curAddrFound) + if curAddrFound { + ac.addrs = addrs + ac.addrIdx = 0 // Start reconnecting from beginning in the new list. + } + + return curAddrFound +} + +// GetMethodConfig gets the method config of the input method. +// If there's an exact match for input method (i.e. /service/method), we return +// the corresponding MethodConfig. +// If there isn't an exact match for the input method, we look for the default config +// under the service (i.e /service/). If there is a default MethodConfig for +// the service, we return it. +// Otherwise, we return an empty MethodConfig. +func (cc *ClientConn) GetMethodConfig(method string) MethodConfig { + // TODO: Avoid the locking here. + cc.mu.RLock() + defer cc.mu.RUnlock() + m, ok := cc.sc.Methods[method] + if !ok { + i := strings.LastIndex(method, "/") + m = cc.sc.Methods[method[:i+1]] + } + return m +} + +func (cc *ClientConn) healthCheckConfig() *healthCheckConfig { + cc.mu.RLock() + defer cc.mu.RUnlock() + return cc.sc.healthCheckConfig +} + +func (cc *ClientConn) getTransport(ctx context.Context, failfast bool, method string) (transport.ClientTransport, func(balancer.DoneInfo), error) { + hdr, _ := metadata.FromOutgoingContext(ctx) + t, done, err := cc.blockingpicker.pick(ctx, failfast, balancer.PickOptions{ + FullMethodName: method, + Header: hdr, + }) + if err != nil { + return nil, nil, toRPCErr(err) + } + return t, done, nil +} + +// handleServiceConfig parses the service config string in JSON format to Go native +// struct ServiceConfig, and store both the struct and the JSON string in ClientConn. +func (cc *ClientConn) handleServiceConfig(js string) error { + if cc.dopts.disableServiceConfig { + return nil + } + if cc.scRaw == js { + return nil + } + if channelz.IsOn() { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + // The special formatting of \"%s\" instead of %q is to provide nice printing of service config + // for human consumption. + Desc: fmt.Sprintf("Channel has a new service config \"%s\"", js), + Severity: channelz.CtINFO, + }) + } + sc, err := parseServiceConfig(js) + if err != nil { + return err + } + cc.mu.Lock() + // Check if the ClientConn is already closed. Some fields (e.g. + // balancerWrapper) are set to nil when closing the ClientConn, and could + // cause nil pointer panic if we don't have this check. + if cc.conns == nil { + cc.mu.Unlock() + return nil + } + cc.scRaw = js + cc.sc = sc + + if sc.retryThrottling != nil { + newThrottler := &retryThrottler{ + tokens: sc.retryThrottling.MaxTokens, + max: sc.retryThrottling.MaxTokens, + thresh: sc.retryThrottling.MaxTokens / 2, + ratio: sc.retryThrottling.TokenRatio, + } + cc.retryThrottler.Store(newThrottler) + } else { + cc.retryThrottler.Store((*retryThrottler)(nil)) + } + + if sc.LB != nil && *sc.LB != grpclbName { // "grpclb" is not a valid balancer option in service config. + if cc.curBalancerName == grpclbName { + // If current balancer is grpclb, there's at least one grpclb + // balancer address in the resolved list. Don't switch the balancer, + // but change the previous balancer name, so if a new resolved + // address list doesn't contain grpclb address, balancer will be + // switched to *sc.LB. + cc.preBalancerName = *sc.LB + } else { + cc.switchBalancer(*sc.LB) + cc.balancerWrapper.handleResolvedAddrs(cc.curAddresses, nil) + } + } + + cc.mu.Unlock() + return nil +} + +func (cc *ClientConn) resolveNow(o resolver.ResolveNowOption) { + cc.mu.RLock() + r := cc.resolverWrapper + cc.mu.RUnlock() + if r == nil { + return + } + go r.resolveNow(o) +} + +// ResetConnectBackoff wakes up all subchannels in transient failure and causes +// them to attempt another connection immediately. It also resets the backoff +// times used for subsequent attempts regardless of the current state. +// +// In general, this function should not be used. Typical service or network +// outages result in a reasonable client reconnection strategy by default. +// However, if a previously unavailable network becomes available, this may be +// used to trigger an immediate reconnect. +// +// This API is EXPERIMENTAL. +func (cc *ClientConn) ResetConnectBackoff() { + cc.mu.Lock() + defer cc.mu.Unlock() + for ac := range cc.conns { + ac.resetConnectBackoff() + } +} + +// Close tears down the ClientConn and all underlying connections. +func (cc *ClientConn) Close() error { + defer cc.cancel() + + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return ErrClientConnClosing + } + conns := cc.conns + cc.conns = nil + cc.csMgr.updateState(connectivity.Shutdown) + + rWrapper := cc.resolverWrapper + cc.resolverWrapper = nil + bWrapper := cc.balancerWrapper + cc.balancerWrapper = nil + cc.mu.Unlock() + + cc.blockingpicker.close() + + if rWrapper != nil { + rWrapper.close() + } + if bWrapper != nil { + bWrapper.close() + } + + for ac := range conns { + ac.tearDown(ErrClientConnClosing) + } + if channelz.IsOn() { + ted := &channelz.TraceEventDesc{ + Desc: "Channel Deleted", + Severity: channelz.CtINFO, + } + if cc.dopts.channelzParentID != 0 { + ted.Parent = &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Nested channel(id:%d) deleted", cc.channelzID), + Severity: channelz.CtINFO, + } + } + channelz.AddTraceEvent(cc.channelzID, ted) + // TraceEvent needs to be called before RemoveEntry, as TraceEvent may add trace reference to + // the entity beng deleted, and thus prevent it from being deleted right away. + channelz.RemoveEntry(cc.channelzID) + } + return nil +} + +// addrConn is a network connection to a given address. +type addrConn struct { + ctx context.Context + cancel context.CancelFunc + + cc *ClientConn + dopts dialOptions + acbw balancer.SubConn + scopts balancer.NewSubConnOptions + + // transport is set when there's a viable transport (note: ac state may not be READY as LB channel + // health checking may require server to report healthy to set ac to READY), and is reset + // to nil when the current transport should no longer be used to create a stream (e.g. after GoAway + // is received, transport is closed, ac has been torn down). + transport transport.ClientTransport // The current transport. + + mu sync.Mutex + addrIdx int // The index in addrs list to start reconnecting from. + curAddr resolver.Address // The current address. + addrs []resolver.Address // All addresses that the resolver resolved to. + + // Use updateConnectivityState for updating addrConn's connectivity state. + state connectivity.State + + tearDownErr error // The reason this addrConn is torn down. + + backoffIdx int + // backoffDeadline is the time until which resetTransport needs to + // wait before increasing backoffIdx count. + backoffDeadline time.Time + // connectDeadline is the time by which all connection + // negotiations must complete. + connectDeadline time.Time + + resetBackoff chan struct{} + + channelzID int64 // channelz unique identification number + czData *channelzData + + successfulHandshake bool + + healthCheckEnabled bool +} + +// Note: this requires a lock on ac.mu. +func (ac *addrConn) updateConnectivityState(s connectivity.State) { + ac.state = s + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel Connectivity change to %v", s), + Severity: channelz.CtINFO, + }) + } +} + +// adjustParams updates parameters used to create transports upon +// receiving a GoAway. +func (ac *addrConn) adjustParams(r transport.GoAwayReason) { + switch r { + case transport.GoAwayTooManyPings: + v := 2 * ac.dopts.copts.KeepaliveParams.Time + ac.cc.mu.Lock() + if v > ac.cc.mkp.Time { + ac.cc.mkp.Time = v + } + ac.cc.mu.Unlock() + } +} + +// resetTransport makes sure that a healthy ac.transport exists. +// +// The transport will close itself when it encounters an error, or on GOAWAY, or on deadline waiting for handshake, or +// when the clientconn is closed. Each iteration creating a new transport will try a different address that the balancer +// assigned to the addrConn, until it has tried all addresses. Once it has tried all addresses, it will re-resolve to +// get a new address list. If an error is received, the list is re-resolved and the next reset attempt will try from the +// beginning. This method has backoff built in. The backoff amount starts at 0 and increases each time resolution occurs +// (addresses are exhausted). The backoff amount is reset to 0 each time a handshake is received. +// +// If the DialOption WithWaitForHandshake was set, resetTransport returns successfully only after handshake is received. +func (ac *addrConn) resetTransport(resolveNow bool) { + for { + // If this is the first in a line of resets, we want to resolve immediately. The only other time we + // want to reset is if we have tried all the addresses handed to us. + if resolveNow { + ac.mu.Lock() + ac.cc.resolveNow(resolver.ResolveNowOption{}) + ac.mu.Unlock() + } + + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + // The transport that was used before is no longer viable. + ac.transport = nil + // If the connection is READY, a failure must have occurred. + // Otherwise, we'll consider this is a transient failure when: + // We've exhausted all addresses + // We're in CONNECTING + // And it's not the very first addr to try TODO(deklerk) find a better way to do this than checking ac.successfulHandshake + if ac.state == connectivity.Ready || (ac.addrIdx == len(ac.addrs)-1 && ac.state == connectivity.Connecting && !ac.successfulHandshake) { + ac.updateConnectivityState(connectivity.TransientFailure) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + ac.transport = nil + ac.mu.Unlock() + + if err := ac.nextAddr(); err != nil { + return + } + + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + backoffIdx := ac.backoffIdx + backoffFor := ac.dopts.bs.Backoff(backoffIdx) + + // This will be the duration that dial gets to finish. + dialDuration := getMinConnectTimeout() + if backoffFor > dialDuration { + // Give dial more time as we keep failing to connect. + dialDuration = backoffFor + } + start := time.Now() + connectDeadline := start.Add(dialDuration) + ac.backoffDeadline = start.Add(backoffFor) + ac.connectDeadline = connectDeadline + + ac.mu.Unlock() + + ac.cc.mu.RLock() + ac.dopts.copts.KeepaliveParams = ac.cc.mkp + ac.cc.mu.RUnlock() + + ac.mu.Lock() + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + if ac.state != connectivity.Connecting { + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + + addr := ac.addrs[ac.addrIdx] + copts := ac.dopts.copts + if ac.scopts.CredsBundle != nil { + copts.CredsBundle = ac.scopts.CredsBundle + } + ac.mu.Unlock() + + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel picks a new address %q to connect", addr.Addr), + Severity: channelz.CtINFO, + }) + } + + if err := ac.createTransport(backoffIdx, addr, copts, connectDeadline); err != nil { + continue + } + + return + } +} + +// createTransport creates a connection to one of the backends in addrs. +func (ac *addrConn) createTransport(backoffNum int, addr resolver.Address, copts transport.ConnectOptions, connectDeadline time.Time) error { + oneReset := sync.Once{} + skipReset := make(chan struct{}) + allowedToReset := make(chan struct{}) + prefaceReceived := make(chan struct{}) + onCloseCalled := make(chan struct{}) + + var prefaceMu sync.Mutex + var serverPrefaceReceived bool + var clientPrefaceWrote bool + + hcCtx, hcCancel := context.WithCancel(ac.ctx) + + onGoAway := func(r transport.GoAwayReason) { + hcCancel() + ac.mu.Lock() + ac.adjustParams(r) + ac.mu.Unlock() + select { + case <-skipReset: // The outer resetTransport loop will handle reconnection. + return + case <-allowedToReset: // We're in the clear to reset. + go oneReset.Do(func() { ac.resetTransport(false) }) + } + } + + prefaceTimer := time.NewTimer(connectDeadline.Sub(time.Now())) + + onClose := func() { + hcCancel() + close(onCloseCalled) + prefaceTimer.Stop() + + select { + case <-skipReset: // The outer resetTransport loop will handle reconnection. + return + case <-allowedToReset: // We're in the clear to reset. + oneReset.Do(func() { ac.resetTransport(false) }) + } + } + + target := transport.TargetInfo{ + Addr: addr.Addr, + Metadata: addr.Metadata, + Authority: ac.cc.authority, + } + + onPrefaceReceipt := func() { + close(prefaceReceived) + prefaceTimer.Stop() + + // TODO(deklerk): optimization; does anyone else actually use this lock? maybe we can just remove it for this scope + ac.mu.Lock() + + prefaceMu.Lock() + serverPrefaceReceived = true + if clientPrefaceWrote { + ac.successfulHandshake = true + } + prefaceMu.Unlock() + + ac.mu.Unlock() + } + + connectCtx, cancel := context.WithDeadline(ac.ctx, connectDeadline) + defer cancel() + if channelz.IsOn() { + copts.ChannelzParentID = ac.channelzID + } + + newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, target, copts, onPrefaceReceipt, onGoAway, onClose) + + if err == nil { + prefaceMu.Lock() + clientPrefaceWrote = true + if serverPrefaceReceived || ac.dopts.reqHandshake == envconfig.RequireHandshakeOff { + ac.successfulHandshake = true + } + prefaceMu.Unlock() + + if ac.dopts.reqHandshake == envconfig.RequireHandshakeOn { + select { + case <-prefaceTimer.C: + // We didn't get the preface in time. + newTr.Close() + err = errors.New("timed out waiting for server handshake") + case <-prefaceReceived: + // We got the preface - huzzah! things are good. + case <-onCloseCalled: + // The transport has already closed - noop. + close(allowedToReset) + return nil + } + } else if ac.dopts.reqHandshake == envconfig.RequireHandshakeHybrid { + go func() { + select { + case <-prefaceTimer.C: + // We didn't get the preface in time. + newTr.Close() + case <-prefaceReceived: + // We got the preface just in the nick of time - huzzah! + case <-onCloseCalled: + // The transport has already closed - noop. + } + }() + } + } + + if err != nil { + // newTr is either nil, or closed. + ac.cc.blockingpicker.updateConnectionError(err) + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + // ac.tearDown(...) has been invoked. + ac.mu.Unlock() + + // We don't want to reset during this close because we prefer to kick out of this function and let the loop + // in resetTransport take care of reconnecting. + close(skipReset) + + return errConnClosing + } + ac.mu.Unlock() + grpclog.Warningf("grpc: addrConn.createTransport failed to connect to %v. Err :%v. Reconnecting...", addr, err) + + // We don't want to reset during this close because we prefer to kick out of this function and let the loop + // in resetTransport take care of reconnecting. + close(skipReset) + + return err + } + + // Now there is a viable transport to be use, so set ac.transport to reflect the new viable transport. + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + close(skipReset) + newTr.Close() + return nil + } + ac.transport = newTr + ac.mu.Unlock() + + healthCheckConfig := ac.cc.healthCheckConfig() + // LB channel health checking is only enabled when all the four requirements below are met: + // 1. it is not disabled by the user with the WithDisableHealthCheck DialOption, + // 2. the internal.HealthCheckFunc is set by importing the grpc/healthcheck package, + // 3. a service config with non-empty healthCheckConfig field is provided, + // 4. the current load balancer allows it. + if !ac.cc.dopts.disableHealthCheck && healthCheckConfig != nil && ac.scopts.HealthCheckEnabled { + if internal.HealthCheckFunc != nil { + go ac.startHealthCheck(hcCtx, newTr, addr, healthCheckConfig.ServiceName) + close(allowedToReset) + return nil + } + // TODO: add a link to the health check doc in the error message. + grpclog.Error("the client side LB channel health check function has not been set.") + } + + // No LB channel health check case + ac.mu.Lock() + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + + // unblock onGoAway/onClose callback. + close(skipReset) + return errConnClosing + } + + ac.updateConnectivityState(connectivity.Ready) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.curAddr = addr + + ac.mu.Unlock() + + // Ok, _now_ we will finally let the transport reset if it encounters a closable error. Without this, the reader + // goroutine failing races with all the code in this method that sets the connection to "ready". + close(allowedToReset) + return nil +} + +func (ac *addrConn) startHealthCheck(ctx context.Context, newTr transport.ClientTransport, addr resolver.Address, serviceName string) { + // Set up the health check helper functions + newStream := func() (interface{}, error) { + return ac.newClientStream(ctx, &StreamDesc{ServerStreams: true}, "/grpc.health.v1.Health/Watch", newTr) + } + firstReady := true + reportHealth := func(ok bool) { + ac.mu.Lock() + defer ac.mu.Unlock() + if ac.transport != newTr { + return + } + if ok { + if firstReady { + firstReady = false + ac.curAddr = addr + } + if ac.state != connectivity.Ready { + ac.updateConnectivityState(connectivity.Ready) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + } else { + if ac.state != connectivity.TransientFailure { + ac.updateConnectivityState(connectivity.TransientFailure) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + } + } + + err := internal.HealthCheckFunc(ctx, newStream, reportHealth, serviceName) + if err != nil { + if status.Code(err) == codes.Unimplemented { + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel health check is unimplemented at server side, thus health check is disabled", + Severity: channelz.CtError, + }) + } + grpclog.Error("Subchannel health check is unimplemented at server side, thus health check is disabled") + } else { + grpclog.Errorf("HealthCheckFunc exits with unexpected error %v", err) + } + } +} + +// nextAddr increments the addrIdx if there are more addresses to try. If +// there are no more addrs to try it will re-resolve, set addrIdx to 0, and +// increment the backoffIdx. +// +// nextAddr must be called without ac.mu being held. +func (ac *addrConn) nextAddr() error { + ac.mu.Lock() + + // If a handshake has been observed, we want the next usage to start at + // index 0 immediately. + if ac.successfulHandshake { + ac.successfulHandshake = false + ac.backoffDeadline = time.Time{} + ac.connectDeadline = time.Time{} + ac.addrIdx = 0 + ac.backoffIdx = 0 + ac.mu.Unlock() + return nil + } + + if ac.addrIdx < len(ac.addrs)-1 { + ac.addrIdx++ + ac.mu.Unlock() + return nil + } + + ac.addrIdx = 0 + ac.backoffIdx++ + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return errConnClosing + } + ac.cc.resolveNow(resolver.ResolveNowOption{}) + backoffDeadline := ac.backoffDeadline + b := ac.resetBackoff + ac.mu.Unlock() + timer := time.NewTimer(backoffDeadline.Sub(time.Now())) + select { + case <-timer.C: + case <-b: + timer.Stop() + case <-ac.ctx.Done(): + timer.Stop() + return ac.ctx.Err() + } + return nil +} + +func (ac *addrConn) resetConnectBackoff() { + ac.mu.Lock() + close(ac.resetBackoff) + ac.backoffIdx = 0 + ac.resetBackoff = make(chan struct{}) + ac.mu.Unlock() +} + +// getReadyTransport returns the transport if ac's state is READY. +// Otherwise it returns nil, false. +// If ac's state is IDLE, it will trigger ac to connect. +func (ac *addrConn) getReadyTransport() (transport.ClientTransport, bool) { + ac.mu.Lock() + if ac.state == connectivity.Ready && ac.transport != nil { + t := ac.transport + ac.mu.Unlock() + return t, true + } + var idle bool + if ac.state == connectivity.Idle { + idle = true + } + ac.mu.Unlock() + // Trigger idle ac to connect. + if idle { + ac.connect() + } + return nil, false +} + +// tearDown starts to tear down the addrConn. +// TODO(zhaoq): Make this synchronous to avoid unbounded memory consumption in +// some edge cases (e.g., the caller opens and closes many addrConn's in a +// tight loop. +// tearDown doesn't remove ac from ac.cc.conns. +func (ac *addrConn) tearDown(err error) { + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + curTr := ac.transport + ac.transport = nil + // We have to set the state to Shutdown before anything else to prevent races + // between setting the state and logic that waits on context cancelation / etc. + ac.updateConnectivityState(connectivity.Shutdown) + ac.cancel() + ac.tearDownErr = err + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.curAddr = resolver.Address{} + if err == errConnDrain && curTr != nil { + // GracefulClose(...) may be executed multiple times when + // i) receiving multiple GoAway frames from the server; or + // ii) there are concurrent name resolver/Balancer triggered + // address removal and GoAway. + // We have to unlock and re-lock here because GracefulClose => Close => onClose, which requires locking ac.mu. + ac.mu.Unlock() + curTr.GracefulClose() + ac.mu.Lock() + } + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel Deleted", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchanel(id:%d) deleted", ac.channelzID), + Severity: channelz.CtINFO, + }, + }) + // TraceEvent needs to be called before RemoveEntry, as TraceEvent may add trace reference to + // the entity beng deleted, and thus prevent it from being deleted right away. + channelz.RemoveEntry(ac.channelzID) + } + ac.mu.Unlock() +} + +func (ac *addrConn) getState() connectivity.State { + ac.mu.Lock() + defer ac.mu.Unlock() + return ac.state +} + +func (ac *addrConn) ChannelzMetric() *channelz.ChannelInternalMetric { + ac.mu.Lock() + addr := ac.curAddr.Addr + ac.mu.Unlock() + return &channelz.ChannelInternalMetric{ + State: ac.getState(), + Target: addr, + CallsStarted: atomic.LoadInt64(&ac.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&ac.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&ac.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&ac.czData.lastCallStartedTime)), + } +} + +func (ac *addrConn) incrCallsStarted() { + atomic.AddInt64(&ac.czData.callsStarted, 1) + atomic.StoreInt64(&ac.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (ac *addrConn) incrCallsSucceeded() { + atomic.AddInt64(&ac.czData.callsSucceeded, 1) +} + +func (ac *addrConn) incrCallsFailed() { + atomic.AddInt64(&ac.czData.callsFailed, 1) +} + +type retryThrottler struct { + max float64 + thresh float64 + ratio float64 + + mu sync.Mutex + tokens float64 // TODO(dfawley): replace with atomic and remove lock. +} + +// throttle subtracts a retry token from the pool and returns whether a retry +// should be throttled (disallowed) based upon the retry throttling policy in +// the service config. +func (rt *retryThrottler) throttle() bool { + if rt == nil { + return false + } + rt.mu.Lock() + defer rt.mu.Unlock() + rt.tokens-- + if rt.tokens < 0 { + rt.tokens = 0 + } + return rt.tokens <= rt.thresh +} + +func (rt *retryThrottler) successfulRPC() { + if rt == nil { + return + } + rt.mu.Lock() + defer rt.mu.Unlock() + rt.tokens += rt.ratio + if rt.tokens > rt.max { + rt.tokens = rt.max + } +} + +type channelzChannel struct { + cc *ClientConn +} + +func (c *channelzChannel) ChannelzMetric() *channelz.ChannelInternalMetric { + return c.cc.channelzMetric() +} + +// ErrClientConnTimeout indicates that the ClientConn cannot establish the +// underlying connections within the specified timeout. +// +// Deprecated: This error is never returned by grpc and should not be +// referenced by users. +var ErrClientConnTimeout = errors.New("grpc: timed out when dialing") diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codec.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codec.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codec.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codec.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codegen.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codegen.sh similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codegen.sh rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codegen.sh diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/code_string.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/code_string.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/code_string.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/code_string.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/codes.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/codes.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/codes.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/codes.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go new file mode 100644 index 00000000..b1d7dbc5 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go @@ -0,0 +1,73 @@ +/* + * + * 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 connectivity defines connectivity semantics. +// For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md. +// All APIs in this package are experimental. +package connectivity + +import ( + "context" + + "google.golang.org/grpc/grpclog" +) + +// State indicates the state of connectivity. +// It can be the state of a ClientConn or SubConn. +type State int + +func (s State) String() string { + switch s { + case Idle: + return "IDLE" + case Connecting: + return "CONNECTING" + case Ready: + return "READY" + case TransientFailure: + return "TRANSIENT_FAILURE" + case Shutdown: + return "SHUTDOWN" + default: + grpclog.Errorf("unknown connectivity state: %d", s) + return "Invalid-State" + } +} + +const ( + // Idle indicates the ClientConn is idle. + Idle State = iota + // Connecting indicates the ClienConn is connecting. + Connecting + // Ready indicates the ClientConn is ready for work. + Ready + // TransientFailure indicates the ClientConn has seen a failure but expects to recover. + TransientFailure + // Shutdown indicates the ClientConn has started shutting down. + Shutdown +) + +// Reporter reports the connectivity states. +type Reporter interface { + // CurrentState returns the current state of the reporter. + CurrentState() State + // WaitForStateChange blocks until the reporter's state is different from the given state, + // and returns true. + // It returns false if <-ctx.Done() can proceed (ctx got timeout or got canceled). + WaitForStateChange(context.Context, State) bool +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go new file mode 100644 index 00000000..a8515604 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go @@ -0,0 +1,328 @@ +/* + * + * Copyright 2014 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 credentials implements various credentials supported by gRPC library, +// which encapsulate all the state needed by a client to authenticate with a +// server and make various assertions, e.g., about the client's identity, role, +// or whether it is authorized to make a particular call. +package credentials // import "google.golang.org/grpc/credentials" + +import ( + "context" + "crypto/tls" + "crypto/x509" + "errors" + "fmt" + "io/ioutil" + "net" + "strings" + + "github.com/golang/protobuf/proto" + "google.golang.org/grpc/credentials/internal" +) + +// alpnProtoStr are the specified application level protocols for gRPC. +var alpnProtoStr = []string{"h2"} + +// PerRPCCredentials defines the common interface for the credentials which need to +// attach security information to every RPC (e.g., oauth2). +type PerRPCCredentials interface { + // GetRequestMetadata gets the current request metadata, refreshing + // tokens if required. This should be called by the transport layer on + // each request, and the data should be populated in headers or other + // context. If a status code is returned, it will be used as the status + // for the RPC. uri is the URI of the entry point for the request. + // When supported by the underlying implementation, ctx can be used for + // timeout and cancellation. + // TODO(zhaoq): Define the set of the qualified keys instead of leaving + // it as an arbitrary string. + GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) + // RequireTransportSecurity indicates whether the credentials requires + // transport security. + RequireTransportSecurity() bool +} + +// ProtocolInfo provides information regarding the gRPC wire protocol version, +// security protocol, security protocol version in use, server name, etc. +type ProtocolInfo struct { + // ProtocolVersion is the gRPC wire protocol version. + ProtocolVersion string + // SecurityProtocol is the security protocol in use. + SecurityProtocol string + // SecurityVersion is the security protocol version. + SecurityVersion string + // ServerName is the user-configured server name. + ServerName string +} + +// AuthInfo defines the common interface for the auth information the users are interested in. +type AuthInfo interface { + AuthType() string +} + +// ErrConnDispatched indicates that rawConn has been dispatched out of gRPC +// and the caller should not close rawConn. +var ErrConnDispatched = errors.New("credentials: rawConn is dispatched out of gRPC") + +// TransportCredentials defines the common interface for all the live gRPC wire +// protocols and supported transport security protocols (e.g., TLS, SSL). +type TransportCredentials interface { + // ClientHandshake does the authentication handshake specified by the corresponding + // authentication protocol on rawConn for clients. It returns the authenticated + // connection and the corresponding auth information about the connection. + // Implementations must use the provided context to implement timely cancellation. + // gRPC will try to reconnect if the error returned is a temporary error + // (io.EOF, context.DeadlineExceeded or err.Temporary() == true). + // If the returned error is a wrapper error, implementations should make sure that + // the error implements Temporary() to have the correct retry behaviors. + // + // If the returned net.Conn is closed, it MUST close the net.Conn provided. + ClientHandshake(context.Context, string, net.Conn) (net.Conn, AuthInfo, error) + // ServerHandshake does the authentication handshake for servers. It returns + // the authenticated connection and the corresponding auth information about + // the connection. + // + // If the returned net.Conn is closed, it MUST close the net.Conn provided. + ServerHandshake(net.Conn) (net.Conn, AuthInfo, error) + // Info provides the ProtocolInfo of this TransportCredentials. + Info() ProtocolInfo + // Clone makes a copy of this TransportCredentials. + Clone() TransportCredentials + // OverrideServerName overrides the server name used to verify the hostname on the returned certificates from the server. + // gRPC internals also use it to override the virtual hosting name if it is set. + // It must be called before dialing. Currently, this is only used by grpclb. + OverrideServerName(string) error +} + +// Bundle is a combination of TransportCredentials and PerRPCCredentials. +// +// It also contains a mode switching method, so it can be used as a combination +// of different credential policies. +// +// Bundle cannot be used together with individual TransportCredentials. +// PerRPCCredentials from Bundle will be appended to other PerRPCCredentials. +// +// This API is experimental. +type Bundle interface { + TransportCredentials() TransportCredentials + PerRPCCredentials() PerRPCCredentials + // NewWithMode should make a copy of Bundle, and switch mode. Modifying the + // existing Bundle may cause races. + // + // NewWithMode returns nil if the requested mode is not supported. + NewWithMode(mode string) (Bundle, error) +} + +// TLSInfo contains the auth information for a TLS authenticated connection. +// It implements the AuthInfo interface. +type TLSInfo struct { + State tls.ConnectionState +} + +// AuthType returns the type of TLSInfo as a string. +func (t TLSInfo) AuthType() string { + return "tls" +} + +// GetSecurityValue returns security info requested by channelz. +func (t TLSInfo) GetSecurityValue() ChannelzSecurityValue { + v := &TLSChannelzSecurityValue{ + StandardName: cipherSuiteLookup[t.State.CipherSuite], + } + // Currently there's no way to get LocalCertificate info from tls package. + if len(t.State.PeerCertificates) > 0 { + v.RemoteCertificate = t.State.PeerCertificates[0].Raw + } + return v +} + +// tlsCreds is the credentials required for authenticating a connection using TLS. +type tlsCreds struct { + // TLS configuration + config *tls.Config +} + +func (c tlsCreds) Info() ProtocolInfo { + return ProtocolInfo{ + SecurityProtocol: "tls", + SecurityVersion: "1.2", + ServerName: c.config.ServerName, + } +} + +func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawConn net.Conn) (_ net.Conn, _ AuthInfo, err error) { + // use local cfg to avoid clobbering ServerName if using multiple endpoints + cfg := cloneTLSConfig(c.config) + if cfg.ServerName == "" { + colonPos := strings.LastIndex(authority, ":") + if colonPos == -1 { + colonPos = len(authority) + } + cfg.ServerName = authority[:colonPos] + } + conn := tls.Client(rawConn, cfg) + errChannel := make(chan error, 1) + go func() { + errChannel <- conn.Handshake() + }() + select { + case err := <-errChannel: + if err != nil { + return nil, nil, err + } + case <-ctx.Done(): + return nil, nil, ctx.Err() + } + return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState()}, nil +} + +func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) { + conn := tls.Server(rawConn, c.config) + if err := conn.Handshake(); err != nil { + return nil, nil, err + } + return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState()}, nil +} + +func (c *tlsCreds) Clone() TransportCredentials { + return NewTLS(c.config) +} + +func (c *tlsCreds) OverrideServerName(serverNameOverride string) error { + c.config.ServerName = serverNameOverride + return nil +} + +// NewTLS uses c to construct a TransportCredentials based on TLS. +func NewTLS(c *tls.Config) TransportCredentials { + tc := &tlsCreds{cloneTLSConfig(c)} + tc.config.NextProtos = alpnProtoStr + return tc +} + +// NewClientTLSFromCert constructs TLS credentials from the input certificate for client. +// serverNameOverride is for testing only. If set to a non empty string, +// it will override the virtual host name of authority (e.g. :authority header field) in requests. +func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) TransportCredentials { + return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}) +} + +// NewClientTLSFromFile constructs TLS credentials from the input certificate file for client. +// serverNameOverride is for testing only. If set to a non empty string, +// it will override the virtual host name of authority (e.g. :authority header field) in requests. +func NewClientTLSFromFile(certFile, serverNameOverride string) (TransportCredentials, error) { + b, err := ioutil.ReadFile(certFile) + if err != nil { + return nil, err + } + cp := x509.NewCertPool() + if !cp.AppendCertsFromPEM(b) { + return nil, fmt.Errorf("credentials: failed to append certificates") + } + return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}), nil +} + +// NewServerTLSFromCert constructs TLS credentials from the input certificate for server. +func NewServerTLSFromCert(cert *tls.Certificate) TransportCredentials { + return NewTLS(&tls.Config{Certificates: []tls.Certificate{*cert}}) +} + +// NewServerTLSFromFile constructs TLS credentials from the input certificate file and key +// file for server. +func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error) { + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + if err != nil { + return nil, err + } + return NewTLS(&tls.Config{Certificates: []tls.Certificate{cert}}), nil +} + +// ChannelzSecurityInfo defines the interface that security protocols should implement +// in order to provide security info to channelz. +type ChannelzSecurityInfo interface { + GetSecurityValue() ChannelzSecurityValue +} + +// ChannelzSecurityValue defines the interface that GetSecurityValue() return value +// should satisfy. This interface should only be satisfied by *TLSChannelzSecurityValue +// and *OtherChannelzSecurityValue. +type ChannelzSecurityValue interface { + isChannelzSecurityValue() +} + +// TLSChannelzSecurityValue defines the struct that TLS protocol should return +// from GetSecurityValue(), containing security info like cipher and certificate used. +type TLSChannelzSecurityValue struct { + StandardName string + LocalCertificate []byte + RemoteCertificate []byte +} + +func (*TLSChannelzSecurityValue) isChannelzSecurityValue() {} + +// OtherChannelzSecurityValue defines the struct that non-TLS protocol should return +// from GetSecurityValue(), which contains protocol specific security info. Note +// the Value field will be sent to users of channelz requesting channel info, and +// thus sensitive info should better be avoided. +type OtherChannelzSecurityValue struct { + Name string + Value proto.Message +} + +func (*OtherChannelzSecurityValue) isChannelzSecurityValue() {} + +var cipherSuiteLookup = map[uint16]string{ + tls.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA", + tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA", + tls.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA", + tls.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA", + tls.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256", + tls.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384", + tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA", + tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + tls.TLS_FALLBACK_SCSV: "TLS_FALLBACK_SCSV", + tls.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", +} + +// cloneTLSConfig returns a shallow clone of the exported +// fields of cfg, ignoring the unexported sync.Once, which +// contains a mutex and must not be copied. +// +// If cfg is nil, a new zero tls.Config is returned. +// +// TODO: inline this function if possible. +func cloneTLSConfig(cfg *tls.Config) *tls.Config { + if cfg == nil { + return &tls.Config{} + } + + return cfg.Clone() +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go new file mode 100644 index 00000000..2f4472be --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go @@ -0,0 +1,61 @@ +// +build !appengine + +/* + * + * 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 internal contains credentials-internal code. +package internal + +import ( + "net" + "syscall" +) + +type sysConn = syscall.Conn + +// syscallConn keeps reference of rawConn to support syscall.Conn for channelz. +// SyscallConn() (the method in interface syscall.Conn) is explicitly +// implemented on this type, +// +// Interface syscall.Conn is implemented by most net.Conn implementations (e.g. +// TCPConn, UnixConn), but is not part of net.Conn interface. So wrapper conns +// that embed net.Conn don't implement syscall.Conn. (Side note: tls.Conn +// doesn't embed net.Conn, so even if syscall.Conn is part of net.Conn, it won't +// help here). +type syscallConn struct { + net.Conn + // sysConn is a type alias of syscall.Conn. It's necessary because the name + // `Conn` collides with `net.Conn`. + sysConn +} + +// WrapSyscallConn tries to wrap rawConn and newConn into a net.Conn that +// implements syscall.Conn. rawConn will be used to support syscall, and newConn +// will be used for read/write. +// +// This function returns newConn if rawConn doesn't implement syscall.Conn. +func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn { + sysConn, ok := rawConn.(syscall.Conn) + if !ok { + return newConn + } + return &syscallConn{ + Conn: newConn, + sysConn: sysConn, + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go new file mode 100644 index 00000000..d4346e9e --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go @@ -0,0 +1,30 @@ +// +build appengine + +/* + * + * 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 internal + +import ( + "net" +) + +// WrapSyscallConn returns newConn on appengine. +func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn { + return newConn +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go new file mode 100644 index 00000000..fe00a254 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go @@ -0,0 +1,480 @@ +/* + * + * 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 grpc + +import ( + "context" + "fmt" + "net" + "time" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/internal" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/envconfig" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/resolver" + "google.golang.org/grpc/stats" +) + +// dialOptions configure a Dial call. dialOptions are set by the DialOption +// values passed to Dial. +type dialOptions struct { + unaryInt UnaryClientInterceptor + streamInt StreamClientInterceptor + cp Compressor + dc Decompressor + bs backoff.Strategy + block bool + insecure bool + timeout time.Duration + scChan <-chan ServiceConfig + authority string + copts transport.ConnectOptions + callOptions []CallOption + // This is used by v1 balancer dial option WithBalancer to support v1 + // balancer, and also by WithBalancerName dial option. + balancerBuilder balancer.Builder + // This is to support grpclb. + resolverBuilder resolver.Builder + reqHandshake envconfig.RequireHandshakeSetting + channelzParentID int64 + disableServiceConfig bool + disableRetry bool + disableHealthCheck bool +} + +// DialOption configures how we set up the connection. +type DialOption interface { + apply(*dialOptions) +} + +// EmptyDialOption does not alter the dial configuration. It can be embedded in +// another structure to build custom dial options. +// +// This API is EXPERIMENTAL. +type EmptyDialOption struct{} + +func (EmptyDialOption) apply(*dialOptions) {} + +// funcDialOption wraps a function that modifies dialOptions into an +// implementation of the DialOption interface. +type funcDialOption struct { + f func(*dialOptions) +} + +func (fdo *funcDialOption) apply(do *dialOptions) { + fdo.f(do) +} + +func newFuncDialOption(f func(*dialOptions)) *funcDialOption { + return &funcDialOption{ + f: f, + } +} + +// WithWaitForHandshake blocks until the initial settings frame is received from +// the server before assigning RPCs to the connection. +// +// Deprecated: this will become the default behavior in the 1.17 release, and +// will be removed after the 1.18 release. To override the default behavior in +// the 1.17 release, either use this dial option or set the environment +// variable GRPC_GO_READY_BEFORE_HANDSHAKE=on. +func WithWaitForHandshake() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.reqHandshake = envconfig.RequireHandshakeOn + }) +} + +// WithWriteBufferSize determines how much data can be batched before doing a +// write on the wire. The corresponding memory allocation for this buffer will +// be twice the size to keep syscalls low. The default value for this buffer is +// 32KB. +// +// Zero will disable the write buffer such that each write will be on underlying +// connection. Note: A Send call may not directly translate to a write. +func WithWriteBufferSize(s int) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.WriteBufferSize = s + }) +} + +// WithReadBufferSize lets you set the size of read buffer, this determines how +// much data can be read at most for each read syscall. +// +// The default value for this buffer is 32KB. Zero will disable read buffer for +// a connection so data framer can access the underlying conn directly. +func WithReadBufferSize(s int) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.ReadBufferSize = s + }) +} + +// WithInitialWindowSize returns a DialOption which sets the value for initial +// window size on a stream. The lower bound for window size is 64K and any value +// smaller than that will be ignored. +func WithInitialWindowSize(s int32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.InitialWindowSize = s + }) +} + +// WithInitialConnWindowSize returns a DialOption which sets the value for +// initial window size on a connection. The lower bound for window size is 64K +// and any value smaller than that will be ignored. +func WithInitialConnWindowSize(s int32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.InitialConnWindowSize = s + }) +} + +// WithMaxMsgSize returns a DialOption which sets the maximum message size the +// client can receive. +// +// Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead. +func WithMaxMsgSize(s int) DialOption { + return WithDefaultCallOptions(MaxCallRecvMsgSize(s)) +} + +// WithDefaultCallOptions returns a DialOption which sets the default +// CallOptions for calls over the connection. +func WithDefaultCallOptions(cos ...CallOption) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.callOptions = append(o.callOptions, cos...) + }) +} + +// WithCodec returns a DialOption which sets a codec for message marshaling and +// unmarshaling. +// +// Deprecated: use WithDefaultCallOptions(CallCustomCodec(c)) instead. +func WithCodec(c Codec) DialOption { + return WithDefaultCallOptions(CallCustomCodec(c)) +} + +// WithCompressor returns a DialOption which sets a Compressor to use for +// message compression. It has lower priority than the compressor set by the +// UseCompressor CallOption. +// +// Deprecated: use UseCompressor instead. +func WithCompressor(cp Compressor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.cp = cp + }) +} + +// WithDecompressor returns a DialOption which sets a Decompressor to use for +// incoming message decompression. If incoming response messages are encoded +// using the decompressor's Type(), it will be used. Otherwise, the message +// encoding will be used to look up the compressor registered via +// encoding.RegisterCompressor, which will then be used to decompress the +// message. If no compressor is registered for the encoding, an Unimplemented +// status error will be returned. +// +// Deprecated: use encoding.RegisterCompressor instead. +func WithDecompressor(dc Decompressor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.dc = dc + }) +} + +// WithBalancer returns a DialOption which sets a load balancer with the v1 API. +// Name resolver will be ignored if this DialOption is specified. +// +// Deprecated: use the new balancer APIs in balancer package and +// WithBalancerName. +func WithBalancer(b Balancer) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.balancerBuilder = &balancerWrapperBuilder{ + b: b, + } + }) +} + +// WithBalancerName sets the balancer that the ClientConn will be initialized +// with. Balancer registered with balancerName will be used. This function +// panics if no balancer was registered by balancerName. +// +// The balancer cannot be overridden by balancer option specified by service +// config. +// +// This is an EXPERIMENTAL API. +func WithBalancerName(balancerName string) DialOption { + builder := balancer.Get(balancerName) + if builder == nil { + panic(fmt.Sprintf("grpc.WithBalancerName: no balancer is registered for name %v", balancerName)) + } + return newFuncDialOption(func(o *dialOptions) { + o.balancerBuilder = builder + }) +} + +// withResolverBuilder is only for grpclb. +func withResolverBuilder(b resolver.Builder) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.resolverBuilder = b + }) +} + +// WithServiceConfig returns a DialOption which has a channel to read the +// service configuration. +// +// Deprecated: service config should be received through name resolver, as +// specified here. +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +func WithServiceConfig(c <-chan ServiceConfig) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.scChan = c + }) +} + +// WithBackoffMaxDelay configures the dialer to use the provided maximum delay +// when backing off after failed connection attempts. +func WithBackoffMaxDelay(md time.Duration) DialOption { + return WithBackoffConfig(BackoffConfig{MaxDelay: md}) +} + +// WithBackoffConfig configures the dialer to use the provided backoff +// parameters after connection failures. +// +// Use WithBackoffMaxDelay until more parameters on BackoffConfig are opened up +// for use. +func WithBackoffConfig(b BackoffConfig) DialOption { + return withBackoff(backoff.Exponential{ + MaxDelay: b.MaxDelay, + }) +} + +// withBackoff sets the backoff strategy used for connectRetryNum after a failed +// connection attempt. +// +// This can be exported if arbitrary backoff strategies are allowed by gRPC. +func withBackoff(bs backoff.Strategy) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.bs = bs + }) +} + +// WithBlock returns a DialOption which makes caller of Dial blocks until the +// underlying connection is up. Without this, Dial returns immediately and +// connecting the server happens in background. +func WithBlock() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.block = true + }) +} + +// WithInsecure returns a DialOption which disables transport security for this +// ClientConn. Note that transport security is required unless WithInsecure is +// set. +func WithInsecure() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.insecure = true + }) +} + +// WithTransportCredentials returns a DialOption which configures a connection +// level security credentials (e.g., TLS/SSL). This should not be used together +// with WithCredentialsBundle. +func WithTransportCredentials(creds credentials.TransportCredentials) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.TransportCredentials = creds + }) +} + +// WithPerRPCCredentials returns a DialOption which sets credentials and places +// auth state on each outbound RPC. +func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.PerRPCCredentials = append(o.copts.PerRPCCredentials, creds) + }) +} + +// WithCredentialsBundle returns a DialOption to set a credentials bundle for +// the ClientConn.WithCreds. This should not be used together with +// WithTransportCredentials. +// +// This API is experimental. +func WithCredentialsBundle(b credentials.Bundle) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.CredsBundle = b + }) +} + +// WithTimeout returns a DialOption that configures a timeout for dialing a +// ClientConn initially. This is valid if and only if WithBlock() is present. +// +// Deprecated: use DialContext and context.WithTimeout instead. +func WithTimeout(d time.Duration) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.timeout = d + }) +} + +func withContextDialer(f func(context.Context, string) (net.Conn, error)) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.Dialer = f + }) +} + +func init() { + internal.WithContextDialer = withContextDialer + internal.WithResolverBuilder = withResolverBuilder +} + +// WithDialer returns a DialOption that specifies a function to use for dialing +// network addresses. If FailOnNonTempDialError() is set to true, and an error +// is returned by f, gRPC checks the error's Temporary() method to decide if it +// should try to reconnect to the network address. +func WithDialer(f func(string, time.Duration) (net.Conn, error)) DialOption { + return withContextDialer( + func(ctx context.Context, addr string) (net.Conn, error) { + if deadline, ok := ctx.Deadline(); ok { + return f(addr, deadline.Sub(time.Now())) + } + return f(addr, 0) + }) +} + +// WithStatsHandler returns a DialOption that specifies the stats handler for +// all the RPCs and underlying network connections in this ClientConn. +func WithStatsHandler(h stats.Handler) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.StatsHandler = h + }) +} + +// FailOnNonTempDialError returns a DialOption that specifies if gRPC fails on +// non-temporary dial errors. If f is true, and dialer returns a non-temporary +// error, gRPC will fail the connection to the network address and won't try to +// reconnect. The default value of FailOnNonTempDialError is false. +// +// FailOnNonTempDialError only affects the initial dial, and does not do +// anything useful unless you are also using WithBlock(). +// +// This is an EXPERIMENTAL API. +func FailOnNonTempDialError(f bool) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.FailOnNonTempDialError = f + }) +} + +// WithUserAgent returns a DialOption that specifies a user agent string for all +// the RPCs. +func WithUserAgent(s string) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.UserAgent = s + }) +} + +// WithKeepaliveParams returns a DialOption that specifies keepalive parameters +// for the client transport. +func WithKeepaliveParams(kp keepalive.ClientParameters) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.KeepaliveParams = kp + }) +} + +// WithUnaryInterceptor returns a DialOption that specifies the interceptor for +// unary RPCs. +func WithUnaryInterceptor(f UnaryClientInterceptor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.unaryInt = f + }) +} + +// WithStreamInterceptor returns a DialOption that specifies the interceptor for +// streaming RPCs. +func WithStreamInterceptor(f StreamClientInterceptor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.streamInt = f + }) +} + +// WithAuthority returns a DialOption that specifies the value to be used as the +// :authority pseudo-header. This value only works with WithInsecure and has no +// effect if TransportCredentials are present. +func WithAuthority(a string) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.authority = a + }) +} + +// WithChannelzParentID returns a DialOption that specifies the channelz ID of +// current ClientConn's parent. This function is used in nested channel creation +// (e.g. grpclb dial). +func WithChannelzParentID(id int64) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.channelzParentID = id + }) +} + +// WithDisableServiceConfig returns a DialOption that causes grpc to ignore any +// service config provided by the resolver and provides a hint to the resolver +// to not fetch service configs. +func WithDisableServiceConfig() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableServiceConfig = true + }) +} + +// WithDisableRetry returns a DialOption that disables retries, even if the +// service config enables them. This does not impact transparent retries, which +// will happen automatically if no data is written to the wire or if the RPC is +// unprocessed by the remote server. +// +// Retry support is currently disabled by default, but will be enabled by +// default in the future. Until then, it may be enabled by setting the +// environment variable "GRPC_GO_RETRY" to "on". +// +// This API is EXPERIMENTAL. +func WithDisableRetry() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableRetry = true + }) +} + +// WithMaxHeaderListSize returns a DialOption that specifies the maximum +// (uncompressed) size of header list that the client is prepared to accept. +func WithMaxHeaderListSize(s uint32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.MaxHeaderListSize = &s + }) +} + +// WithDisableHealthCheck disables the LB channel health checking for all SubConns of this ClientConn. +// +// This API is EXPERIMENTAL. +func WithDisableHealthCheck() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableHealthCheck = true + }) +} +func defaultDialOptions() dialOptions { + return dialOptions{ + disableRetry: !envconfig.Retry, + reqHandshake: envconfig.RequireHandshake, + copts: transport.ConnectOptions{ + WriteBufferSize: defaultWriteBufSize, + ReadBufferSize: defaultReadBufSize, + }, + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/doc.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/doc.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/encoding.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/encoding.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/encoding.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/encoding.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/proto/proto.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/proto/proto.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/proto/proto.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/proto/proto.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod new file mode 100644 index 00000000..f296dcf4 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod @@ -0,0 +1,20 @@ +module google.golang.org/grpc + +require ( + cloud.google.com/go v0.26.0 // indirect + github.com/client9/misspell v0.3.4 + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b + github.com/golang/mock v1.1.1 + github.com/golang/protobuf v1.2.0 + github.com/kisielk/gotool v1.0.0 // indirect + golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 + golang.org/x/net v0.0.0-20180826012351-8a410e7b638d + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be + golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect + golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 + golang.org/x/text v0.3.0 // indirect + golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 + google.golang.org/appengine v1.1.0 // indirect + google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 + honnef.co/go/tools v0.0.0-20180728063816-88497007e858 +) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum new file mode 100644 index 00000000..bfb6bb7c --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum @@ -0,0 +1,32 @@ +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/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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 h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/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-20180828015842-6cd1fcedba52 h1:JG/0uqcGdTNgq7FdU+61l5Pdmb8putNZlXb65bJBROs= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858 h1:wN+eVZ7U+gqdqkec6C6VXR1OFf9a5Ul9ETzeYsYv20g= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/grpclog.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/grpclog.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/grpclog.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/grpclog.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/logger.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/logger.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/logger.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/loggerv2.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/loggerv2.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/loggerv2.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/loggerv2.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/install_gae.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/install_gae.sh similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/install_gae.sh rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/install_gae.sh diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go new file mode 100644 index 00000000..8b735002 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go @@ -0,0 +1,77 @@ +/* + * + * Copyright 2016 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 grpc + +import ( + "context" +) + +// UnaryInvoker is called by UnaryClientInterceptor to complete RPCs. +type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error + +// UnaryClientInterceptor intercepts the execution of a unary RPC on the client. invoker is the handler to complete the RPC +// and it is the responsibility of the interceptor to call it. +// This is an EXPERIMENTAL API. +type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error + +// Streamer is called by StreamClientInterceptor to create a ClientStream. +type Streamer func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) + +// StreamClientInterceptor intercepts the creation of ClientStream. It may return a custom ClientStream to intercept all I/O +// operations. streamer is the handler to create a ClientStream and it is the responsibility of the interceptor to call it. +// This is an EXPERIMENTAL API. +type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error) + +// UnaryServerInfo consists of various information about a unary RPC on +// server side. All per-rpc information may be mutated by the interceptor. +type UnaryServerInfo struct { + // Server is the service implementation the user provides. This is read-only. + Server interface{} + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string +} + +// UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal +// execution of a unary RPC. If a UnaryHandler returns an error, it should be produced by the +// status package, or else gRPC will use codes.Unknown as the status code and err.Error() as +// the status message of the RPC. +type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error) + +// UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info +// contains all the information of this RPC the interceptor can operate on. And handler is the wrapper +// of the service method implementation. It is the responsibility of the interceptor to invoke handler +// to complete the RPC. +type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error) + +// StreamServerInfo consists of various information about a streaming RPC on +// server side. All per-rpc information may be mutated by the interceptor. +type StreamServerInfo struct { + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // IsClientStream indicates whether the RPC is a client streaming RPC. + IsClientStream bool + // IsServerStream indicates whether the RPC is a server streaming RPC. + IsServerStream bool +} + +// StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server. +// info contains all the information of this RPC the interceptor can operate on. And handler is the +// service method implementation. It is the responsibility of the interceptor to invoke handler to +// complete the RPC. +type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/backoff/backoff.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/backoff/backoff.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/backoff/backoff.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/backoff/backoff.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go new file mode 100644 index 00000000..fee6aecd --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go @@ -0,0 +1,167 @@ +/* + * + * 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 binarylog implementation binary logging as defined in +// https://github.com/grpc/proposal/blob/master/A16-binary-logging.md. +package binarylog + +import ( + "fmt" + "os" + + "google.golang.org/grpc/grpclog" +) + +// Logger is the global binary logger. It can be used to get binary logger for +// each method. +type Logger interface { + getMethodLogger(methodName string) *MethodLogger +} + +// binLogger is the global binary logger for the binary. One of this should be +// built at init time from the configuration (environment varialbe or flags). +// +// It is used to get a methodLogger for each individual method. +var binLogger Logger + +// SetLogger sets the binarg logger. +// +// Only call this at init time. +func SetLogger(l Logger) { + binLogger = l +} + +// GetMethodLogger returns the methodLogger for the given methodName. +// +// methodName should be in the format of "/service/method". +// +// Each methodLogger returned by this method is a new instance. This is to +// generate sequence id within the call. +func GetMethodLogger(methodName string) *MethodLogger { + if binLogger == nil { + return nil + } + return binLogger.getMethodLogger(methodName) +} + +func init() { + const envStr = "GRPC_BINARY_LOG_FILTER" + configStr := os.Getenv(envStr) + binLogger = NewLoggerFromConfigString(configStr) +} + +type methodLoggerConfig struct { + // Max length of header and message. + hdr, msg uint64 +} + +type logger struct { + all *methodLoggerConfig + services map[string]*methodLoggerConfig + methods map[string]*methodLoggerConfig + + blacklist map[string]struct{} +} + +// newEmptyLogger creates an empty logger. The map fields need to be filled in +// using the set* functions. +func newEmptyLogger() *logger { + return &logger{} +} + +// Set method logger for "*". +func (l *logger) setDefaultMethodLogger(ml *methodLoggerConfig) error { + if l.all != nil { + return fmt.Errorf("conflicting global rules found") + } + l.all = ml + return nil +} + +// Set method logger for "service/*". +// +// New methodLogger with same service overrides the old one. +func (l *logger) setServiceMethodLogger(service string, ml *methodLoggerConfig) error { + if _, ok := l.services[service]; ok { + return fmt.Errorf("conflicting rules for service %v found", service) + } + if l.services == nil { + l.services = make(map[string]*methodLoggerConfig) + } + l.services[service] = ml + return nil +} + +// Set method logger for "service/method". +// +// New methodLogger with same method overrides the old one. +func (l *logger) setMethodMethodLogger(method string, ml *methodLoggerConfig) error { + if _, ok := l.blacklist[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if _, ok := l.methods[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if l.methods == nil { + l.methods = make(map[string]*methodLoggerConfig) + } + l.methods[method] = ml + return nil +} + +// Set blacklist method for "-service/method". +func (l *logger) setBlacklist(method string) error { + if _, ok := l.blacklist[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if _, ok := l.methods[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if l.blacklist == nil { + l.blacklist = make(map[string]struct{}) + } + l.blacklist[method] = struct{}{} + return nil +} + +// getMethodLogger returns the methodLogger for the given methodName. +// +// methodName should be in the format of "/service/method". +// +// Each methodLogger returned by this method is a new instance. This is to +// generate sequence id within the call. +func (l *logger) getMethodLogger(methodName string) *MethodLogger { + s, m, err := parseMethodName(methodName) + if err != nil { + grpclog.Infof("binarylogging: failed to parse %q: %v", methodName, err) + return nil + } + if ml, ok := l.methods[s+"/"+m]; ok { + return newMethodLogger(ml.hdr, ml.msg) + } + if _, ok := l.blacklist[s+"/"+m]; ok { + return nil + } + if ml, ok := l.services[s]; ok { + return newMethodLogger(ml.hdr, ml.msg) + } + if l.all == nil { + return nil + } + return newMethodLogger(l.all.hdr, l.all.msg) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go new file mode 100644 index 00000000..1ee00a39 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go @@ -0,0 +1,42 @@ +/* + * + * 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. + * + */ + +// This file contains exported variables/functions that are exported for testing +// only. +// +// An ideal way for this would be to put those in a *_test.go but in binarylog +// package. But this doesn't work with staticcheck with go module. Error was: +// "MdToMetadataProto not declared by package binarylog". This could be caused +// by the way staticcheck looks for files for a certain package, which doesn't +// support *_test.go files. +// +// Move those to binary_test.go when staticcheck is fixed. + +package binarylog + +var ( + // AllLogger is a logger that logs all headers/messages for all RPCs. It's + // for testing only. + AllLogger = NewLoggerFromConfigString("*") + // MdToMetadataProto converts metadata to a binary logging proto message. + // It's for testing only. + MdToMetadataProto = mdToMetadataProto + // AddrToProto converts an address to a binary logging proto message. It's + // for testing only. + AddrToProto = addrToProto +) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go new file mode 100644 index 00000000..eb188eae --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go @@ -0,0 +1,210 @@ +/* + * + * 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 binarylog + +import ( + "errors" + "fmt" + "regexp" + "strconv" + "strings" + + "google.golang.org/grpc/grpclog" +) + +// NewLoggerFromConfigString reads the string and build a logger. It can be used +// to build a new logger and assign it to binarylog.Logger. +// +// Example filter config strings: +// - "" Nothing will be logged +// - "*" All headers and messages will be fully logged. +// - "*{h}" Only headers will be logged. +// - "*{m:256}" Only the first 256 bytes of each message will be logged. +// - "Foo/*" Logs every method in service Foo +// - "Foo/*,-Foo/Bar" Logs every method in service Foo except method /Foo/Bar +// - "Foo/*,Foo/Bar{m:256}" Logs the first 256 bytes of each message in method +// /Foo/Bar, logs all headers and messages in every other method in service +// Foo. +// +// If two configs exist for one certain method or service, the one specified +// later overrides the privous config. +func NewLoggerFromConfigString(s string) Logger { + if s == "" { + return nil + } + l := newEmptyLogger() + methods := strings.Split(s, ",") + for _, method := range methods { + if err := l.fillMethodLoggerWithConfigString(method); err != nil { + grpclog.Warningf("failed to parse binary log config: %v", err) + return nil + } + } + return l +} + +// fillMethodLoggerWithConfigString parses config, creates methodLogger and adds +// it to the right map in the logger. +func (l *logger) fillMethodLoggerWithConfigString(config string) error { + // "" is invalid. + if config == "" { + return errors.New("empty string is not a valid method binary logging config") + } + + // "-service/method", blacklist, no * or {} allowed. + if config[0] == '-' { + s, m, suffix, err := parseMethodConfigAndSuffix(config[1:]) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + if m == "*" { + return fmt.Errorf("invalid config: %q, %v", config, "* not allowd in blacklist config") + } + if suffix != "" { + return fmt.Errorf("invalid config: %q, %v", config, "header/message limit not allowed in blacklist config") + } + if err := l.setBlacklist(s + "/" + m); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + return nil + } + + // "*{h:256;m:256}" + if config[0] == '*' { + hdr, msg, err := parseHeaderMessageLengthConfig(config[1:]) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + if err := l.setDefaultMethodLogger(&methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + return nil + } + + s, m, suffix, err := parseMethodConfigAndSuffix(config) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + hdr, msg, err := parseHeaderMessageLengthConfig(suffix) + if err != nil { + return fmt.Errorf("invalid header/message length config: %q, %v", suffix, err) + } + if m == "*" { + if err := l.setServiceMethodLogger(s, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + } else { + if err := l.setMethodMethodLogger(s+"/"+m, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + } + return nil +} + +const ( + // TODO: this const is only used by env_config now. But could be useful for + // other config. Move to binarylog.go if necessary. + maxUInt = ^uint64(0) + + // For "p.s/m" plus any suffix. Suffix will be parsed again. See test for + // expected output. + longMethodConfigRegexpStr = `^([\w./]+)/((?:\w+)|[*])(.+)?$` + + // For suffix from above, "{h:123,m:123}". See test for expected output. + optionalLengthRegexpStr = `(?::(\d+))?` // Optional ":123". + headerConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `}$` + messageConfigRegexpStr = `^{m` + optionalLengthRegexpStr + `}$` + headerMessageConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `;m` + optionalLengthRegexpStr + `}$` +) + +var ( + longMethodConfigRegexp = regexp.MustCompile(longMethodConfigRegexpStr) + headerConfigRegexp = regexp.MustCompile(headerConfigRegexpStr) + messageConfigRegexp = regexp.MustCompile(messageConfigRegexpStr) + headerMessageConfigRegexp = regexp.MustCompile(headerMessageConfigRegexpStr) +) + +// Turn "service/method{h;m}" into "service", "method", "{h;m}". +func parseMethodConfigAndSuffix(c string) (service, method, suffix string, _ error) { + // Regexp result: + // + // in: "p.s/m{h:123,m:123}", + // out: []string{"p.s/m{h:123,m:123}", "p.s", "m", "{h:123,m:123}"}, + match := longMethodConfigRegexp.FindStringSubmatch(c) + if match == nil { + return "", "", "", fmt.Errorf("%q contains invalid substring", c) + } + service = match[1] + method = match[2] + suffix = match[3] + return +} + +// Turn "{h:123;m:345}" into 123, 345. +// +// Return maxUInt if length is unspecified. +func parseHeaderMessageLengthConfig(c string) (hdrLenStr, msgLenStr uint64, err error) { + if c == "" { + return maxUInt, maxUInt, nil + } + // Header config only. + if match := headerConfigRegexp.FindStringSubmatch(c); match != nil { + if s := match[1]; s != "" { + hdrLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("failed to convert %q to uint", s) + } + return hdrLenStr, 0, nil + } + return maxUInt, 0, nil + } + + // Message config only. + if match := messageConfigRegexp.FindStringSubmatch(c); match != nil { + if s := match[1]; s != "" { + msgLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + return 0, msgLenStr, nil + } + return 0, maxUInt, nil + } + + // Header and message config both. + if match := headerMessageConfigRegexp.FindStringSubmatch(c); match != nil { + // Both hdr and msg are specified, but one or two of them might be empty. + hdrLenStr = maxUInt + msgLenStr = maxUInt + if s := match[1]; s != "" { + hdrLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + } + if s := match[2]; s != "" { + msgLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + } + return hdrLenStr, msgLenStr, nil + } + return 0, 0, fmt.Errorf("%q contains invalid substring", c) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go new file mode 100644 index 00000000..b06cdd4d --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go @@ -0,0 +1,426 @@ +/* + * + * 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 binarylog + +import ( + "net" + "strings" + "sync/atomic" + "time" + + "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes" + pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +type callIDGenerator struct { + id uint64 +} + +func (g *callIDGenerator) next() uint64 { + id := atomic.AddUint64(&g.id, 1) + return id +} + +// reset is for testing only, and doesn't need to be thread safe. +func (g *callIDGenerator) reset() { + g.id = 0 +} + +var idGen callIDGenerator + +// MethodLogger is the sub-logger for each method. +type MethodLogger struct { + headerMaxLen, messageMaxLen uint64 + + callID uint64 + idWithinCallGen *callIDGenerator + + sink Sink // TODO(blog): make this plugable. +} + +func newMethodLogger(h, m uint64) *MethodLogger { + return &MethodLogger{ + headerMaxLen: h, + messageMaxLen: m, + + callID: idGen.next(), + idWithinCallGen: &callIDGenerator{}, + + sink: defaultSink, // TODO(blog): make it plugable. + } +} + +// Log creates a proto binary log entry, and logs it to the sink. +func (ml *MethodLogger) Log(c LogEntryConfig) { + m := c.toProto() + timestamp, _ := ptypes.TimestampProto(time.Now()) + m.Timestamp = timestamp + m.CallId = ml.callID + m.SequenceIdWithinCall = ml.idWithinCallGen.next() + + switch pay := m.Payload.(type) { + case *pb.GrpcLogEntry_ClientHeader: + m.PayloadTruncated = ml.truncateMetadata(pay.ClientHeader.GetMetadata()) + case *pb.GrpcLogEntry_ServerHeader: + m.PayloadTruncated = ml.truncateMetadata(pay.ServerHeader.GetMetadata()) + case *pb.GrpcLogEntry_Message: + m.PayloadTruncated = ml.truncateMessage(pay.Message) + } + + ml.sink.Write(m) +} + +func (ml *MethodLogger) truncateMetadata(mdPb *pb.Metadata) (truncated bool) { + if ml.headerMaxLen == maxUInt { + return false + } + var ( + bytesLimit = ml.headerMaxLen + index int + ) + // At the end of the loop, index will be the first entry where the total + // size is greater than the limit: + // + // len(entry[:index]) <= ml.hdr && len(entry[:index+1]) > ml.hdr. + for ; index < len(mdPb.Entry); index++ { + entry := mdPb.Entry[index] + if entry.Key == "grpc-trace-bin" { + // "grpc-trace-bin" is a special key. It's kept in the log entry, + // but not counted towards the size limit. + continue + } + currentEntryLen := uint64(len(entry.Value)) + if currentEntryLen > bytesLimit { + break + } + bytesLimit -= currentEntryLen + } + truncated = index < len(mdPb.Entry) + mdPb.Entry = mdPb.Entry[:index] + return truncated +} + +func (ml *MethodLogger) truncateMessage(msgPb *pb.Message) (truncated bool) { + if ml.messageMaxLen == maxUInt { + return false + } + if ml.messageMaxLen >= uint64(len(msgPb.Data)) { + return false + } + msgPb.Data = msgPb.Data[:ml.messageMaxLen] + return true +} + +// LogEntryConfig represents the configuration for binary log entry. +type LogEntryConfig interface { + toProto() *pb.GrpcLogEntry +} + +// ClientHeader configs the binary log entry to be a ClientHeader entry. +type ClientHeader struct { + OnClientSide bool + Header metadata.MD + MethodName string + Authority string + Timeout time.Duration + // PeerAddr is required only when it's on server side. + PeerAddr net.Addr +} + +func (c *ClientHeader) toProto() *pb.GrpcLogEntry { + // This function doesn't need to set all the fields (e.g. seq ID). The Log + // function will set the fields when necessary. + clientHeader := &pb.ClientHeader{ + Metadata: mdToMetadataProto(c.Header), + MethodName: c.MethodName, + Authority: c.Authority, + } + if c.Timeout > 0 { + clientHeader.Timeout = ptypes.DurationProto(c.Timeout) + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER, + Payload: &pb.GrpcLogEntry_ClientHeader{ + ClientHeader: clientHeader, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// ServerHeader configs the binary log entry to be a ServerHeader entry. +type ServerHeader struct { + OnClientSide bool + Header metadata.MD + // PeerAddr is required only when it's on client side. + PeerAddr net.Addr +} + +func (c *ServerHeader) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_HEADER, + Payload: &pb.GrpcLogEntry_ServerHeader{ + ServerHeader: &pb.ServerHeader{ + Metadata: mdToMetadataProto(c.Header), + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// ClientMessage configs the binary log entry to be a ClientMessage entry. +type ClientMessage struct { + OnClientSide bool + // Message can be a proto.Message or []byte. Other messages formats are not + // supported. + Message interface{} +} + +func (c *ClientMessage) toProto() *pb.GrpcLogEntry { + var ( + data []byte + err error + ) + if m, ok := c.Message.(proto.Message); ok { + data, err = proto.Marshal(m) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal proto message: %v", err) + } + } else if b, ok := c.Message.([]byte); ok { + data = b + } else { + grpclog.Infof("binarylogging: message to log is neither proto.message nor []byte") + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_MESSAGE, + Payload: &pb.GrpcLogEntry_Message{ + Message: &pb.Message{ + Length: uint32(len(data)), + Data: data, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ServerMessage configs the binary log entry to be a ServerMessage entry. +type ServerMessage struct { + OnClientSide bool + // Message can be a proto.Message or []byte. Other messages formats are not + // supported. + Message interface{} +} + +func (c *ServerMessage) toProto() *pb.GrpcLogEntry { + var ( + data []byte + err error + ) + if m, ok := c.Message.(proto.Message); ok { + data, err = proto.Marshal(m) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal proto message: %v", err) + } + } else if b, ok := c.Message.([]byte); ok { + data = b + } else { + grpclog.Infof("binarylogging: message to log is neither proto.message nor []byte") + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_MESSAGE, + Payload: &pb.GrpcLogEntry_Message{ + Message: &pb.Message{ + Length: uint32(len(data)), + Data: data, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ClientHalfClose configs the binary log entry to be a ClientHalfClose entry. +type ClientHalfClose struct { + OnClientSide bool +} + +func (c *ClientHalfClose) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_HALF_CLOSE, + Payload: nil, // No payload here. + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ServerTrailer configs the binary log entry to be a ServerTrailer entry. +type ServerTrailer struct { + OnClientSide bool + Trailer metadata.MD + // Err is the status error. + Err error + // PeerAddr is required only when it's on client side and the RPC is trailer + // only. + PeerAddr net.Addr +} + +func (c *ServerTrailer) toProto() *pb.GrpcLogEntry { + st, ok := status.FromError(c.Err) + if !ok { + grpclog.Info("binarylogging: error in trailer is not a status error") + } + var ( + detailsBytes []byte + err error + ) + stProto := st.Proto() + if stProto != nil && len(stProto.Details) != 0 { + detailsBytes, err = proto.Marshal(stProto) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal status proto: %v", err) + } + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER, + Payload: &pb.GrpcLogEntry_Trailer{ + Trailer: &pb.Trailer{ + Metadata: mdToMetadataProto(c.Trailer), + StatusCode: uint32(st.Code()), + StatusMessage: st.Message(), + StatusDetails: detailsBytes, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// Cancel configs the binary log entry to be a Cancel entry. +type Cancel struct { + OnClientSide bool +} + +func (c *Cancel) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CANCEL, + Payload: nil, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// metadataKeyOmit returns whether the metadata entry with this key should be +// omitted. +func metadataKeyOmit(key string) bool { + switch key { + case "lb-token", ":path", ":authority", "content-encoding", "content-type", "user-agent", "te": + return true + case "grpc-trace-bin": // grpc-trace-bin is special because it's visiable to users. + return false + } + if strings.HasPrefix(key, "grpc-") { + return true + } + return false +} + +func mdToMetadataProto(md metadata.MD) *pb.Metadata { + ret := &pb.Metadata{} + for k, vv := range md { + if metadataKeyOmit(k) { + continue + } + for _, v := range vv { + ret.Entry = append(ret.Entry, + &pb.MetadataEntry{ + Key: k, + Value: []byte(v), + }, + ) + } + } + return ret +} + +func addrToProto(addr net.Addr) *pb.Address { + ret := &pb.Address{} + switch a := addr.(type) { + case *net.TCPAddr: + if a.IP.To4() != nil { + ret.Type = pb.Address_TYPE_IPV4 + } else if a.IP.To16() != nil { + ret.Type = pb.Address_TYPE_IPV6 + } else { + ret.Type = pb.Address_TYPE_UNKNOWN + // Do not set address and port fields. + break + } + ret.Address = a.IP.String() + ret.IpPort = uint32(a.Port) + case *net.UnixAddr: + ret.Type = pb.Address_TYPE_UNIX + ret.Address = a.String() + default: + ret.Type = pb.Address_TYPE_UNKNOWN + } + return ret +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh new file mode 100644 index 00000000..113d40cb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# 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. + +set -eux -o pipefail + +TMP=$(mktemp -d) + +function finish { + rm -rf "$TMP" +} +trap finish EXIT + +pushd "$TMP" +mkdir -p grpc/binarylog/grpc_binarylog_v1 +curl https://raw.githubusercontent.com/grpc/grpc-proto/master/grpc/binlog/v1/binarylog.proto > grpc/binarylog/grpc_binarylog_v1/binarylog.proto + +protoc --go_out=plugins=grpc,paths=source_relative:. -I. grpc/binarylog/grpc_binarylog_v1/*.proto +popd +rm -f ./grpc_binarylog_v1/*.pb.go +cp "$TMP"/grpc/binarylog/grpc_binarylog_v1/*.pb.go ../../binarylog/grpc_binarylog_v1/ + diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go new file mode 100644 index 00000000..20d044f0 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go @@ -0,0 +1,162 @@ +/* + * + * 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 binarylog + +import ( + "bufio" + "encoding/binary" + "fmt" + "io" + "io/ioutil" + "sync" + "time" + + "github.com/golang/protobuf/proto" + pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + "google.golang.org/grpc/grpclog" +) + +var ( + defaultSink Sink = &noopSink{} // TODO(blog): change this default (file in /tmp). +) + +// SetDefaultSink sets the sink where binary logs will be written to. +// +// Not thread safe. Only set during initialization. +func SetDefaultSink(s Sink) { + if defaultSink != nil { + defaultSink.Close() + } + defaultSink = s +} + +// Sink writes log entry into the binary log sink. +type Sink interface { + // Write will be called to write the log entry into the sink. + // + // It should be thread-safe so it can be called in parallel. + Write(*pb.GrpcLogEntry) error + // Close will be called when the Sink is replaced by a new Sink. + Close() error +} + +type noopSink struct{} + +func (ns *noopSink) Write(*pb.GrpcLogEntry) error { return nil } +func (ns *noopSink) Close() error { return nil } + +// newWriterSink creates a binary log sink with the given writer. +// +// Write() marshalls the proto message and writes it to the given writer. Each +// message is prefixed with a 4 byte big endian unsigned integer as the length. +// +// No buffer is done, Close() doesn't try to close the writer. +func newWriterSink(w io.Writer) *writerSink { + return &writerSink{out: w} +} + +type writerSink struct { + out io.Writer +} + +func (ws *writerSink) Write(e *pb.GrpcLogEntry) error { + b, err := proto.Marshal(e) + if err != nil { + grpclog.Infof("binary logging: failed to marshal proto message: %v", err) + } + hdr := make([]byte, 4) + binary.BigEndian.PutUint32(hdr, uint32(len(b))) + if _, err := ws.out.Write(hdr); err != nil { + return err + } + if _, err := ws.out.Write(b); err != nil { + return err + } + return nil +} + +func (ws *writerSink) Close() error { return nil } + +type bufWriteCloserSink struct { + mu sync.Mutex + closer io.Closer + out *writerSink // out is built on buf. + buf *bufio.Writer // buf is kept for flush. + + writeStartOnce sync.Once + writeTicker *time.Ticker +} + +func (fs *bufWriteCloserSink) Write(e *pb.GrpcLogEntry) error { + // Start the write loop when Write is called. + fs.writeStartOnce.Do(fs.startFlushGoroutine) + fs.mu.Lock() + if err := fs.out.Write(e); err != nil { + fs.mu.Unlock() + return err + } + fs.mu.Unlock() + return nil +} + +const ( + bufFlushDuration = 60 * time.Second +) + +func (fs *bufWriteCloserSink) startFlushGoroutine() { + fs.writeTicker = time.NewTicker(bufFlushDuration) + go func() { + for range fs.writeTicker.C { + fs.mu.Lock() + fs.buf.Flush() + fs.mu.Unlock() + } + }() +} + +func (fs *bufWriteCloserSink) Close() error { + if fs.writeTicker != nil { + fs.writeTicker.Stop() + } + fs.mu.Lock() + fs.buf.Flush() + fs.closer.Close() + fs.out.Close() + fs.mu.Unlock() + return nil +} + +func newBufWriteCloserSink(o io.WriteCloser) Sink { + bufW := bufio.NewWriter(o) + return &bufWriteCloserSink{ + closer: o, + out: newWriterSink(bufW), + buf: bufW, + } +} + +// NewTempFileSink creates a temp file and returns a Sink that writes to this +// file. +func NewTempFileSink() (Sink, error) { + tempFile, err := ioutil.TempFile("/tmp", "grpcgo_binarylog_*.txt") + if err != nil { + return nil, fmt.Errorf("failed to create temp file: %v", err) + } + return newBufWriteCloserSink(tempFile), nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go new file mode 100644 index 00000000..15dc7803 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go @@ -0,0 +1,41 @@ +/* + * + * 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 binarylog + +import ( + "errors" + "strings" +) + +// parseMethodName splits service and method from the input. It expects format +// "/service/method". +// +// TODO: move to internal/grpcutil. +func parseMethodName(methodName string) (service, method string, _ error) { + if !strings.HasPrefix(methodName, "/") { + return "", "", errors.New("invalid method name: should start with /") + } + methodName = methodName[1:] + + pos := strings.LastIndex(methodName, "/") + if pos < 0 { + return "", "", errors.New("invalid method name: suffix /method is missing") + } + return methodName[:pos], methodName[pos+1:], nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go new file mode 100644 index 00000000..3021a31a --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go @@ -0,0 +1,668 @@ +/* + * + * 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 channelz defines APIs for enabling channelz service, entry +// registration/deletion, and accessing channelz data. It also defines channelz +// metric struct formats. +// +// All APIs in this package are experimental. +package channelz + +import ( + "sort" + "sync" + "sync/atomic" + "time" + + "google.golang.org/grpc/grpclog" +) + +const ( + defaultMaxTraceEntry int32 = 30 +) + +var ( + db dbWrapper + idGen idGenerator + // EntryPerPage defines the number of channelz entries to be shown on a web page. + EntryPerPage = 50 + curState int32 + maxTraceEntry = defaultMaxTraceEntry +) + +// TurnOn turns on channelz data collection. +func TurnOn() { + if !IsOn() { + NewChannelzStorage() + atomic.StoreInt32(&curState, 1) + } +} + +// IsOn returns whether channelz data collection is on. +func IsOn() bool { + return atomic.CompareAndSwapInt32(&curState, 1, 1) +} + +// SetMaxTraceEntry sets maximum number of trace entry per entity (i.e. channel/subchannel). +// Setting it to 0 will disable channel tracing. +func SetMaxTraceEntry(i int32) { + atomic.StoreInt32(&maxTraceEntry, i) +} + +// ResetMaxTraceEntryToDefault resets the maximum number of trace entry per entity to default. +func ResetMaxTraceEntryToDefault() { + atomic.StoreInt32(&maxTraceEntry, defaultMaxTraceEntry) +} + +func getMaxTraceEntry() int { + i := atomic.LoadInt32(&maxTraceEntry) + return int(i) +} + +// dbWarpper wraps around a reference to internal channelz data storage, and +// provide synchronized functionality to set and get the reference. +type dbWrapper struct { + mu sync.RWMutex + DB *channelMap +} + +func (d *dbWrapper) set(db *channelMap) { + d.mu.Lock() + d.DB = db + d.mu.Unlock() +} + +func (d *dbWrapper) get() *channelMap { + d.mu.RLock() + defer d.mu.RUnlock() + return d.DB +} + +// NewChannelzStorage initializes channelz data storage and id generator. +// +// Note: This function is exported for testing purpose only. User should not call +// it in most cases. +func NewChannelzStorage() { + db.set(&channelMap{ + topLevelChannels: make(map[int64]struct{}), + channels: make(map[int64]*channel), + listenSockets: make(map[int64]*listenSocket), + normalSockets: make(map[int64]*normalSocket), + servers: make(map[int64]*server), + subChannels: make(map[int64]*subChannel), + }) + idGen.reset() +} + +// GetTopChannels returns a slice of top channel's ChannelMetric, along with a +// boolean indicating whether there's more top channels to be queried for. +// +// The arg id specifies that only top channel with id at or above it will be included +// in the result. The returned slice is up to a length of EntryPerPage, and is +// sorted in ascending id order. +func GetTopChannels(id int64) ([]*ChannelMetric, bool) { + return db.get().GetTopChannels(id) +} + +// GetServers returns a slice of server's ServerMetric, along with a +// boolean indicating whether there's more servers to be queried for. +// +// The arg id specifies that only server with id at or above it will be included +// in the result. The returned slice is up to a length of EntryPerPage, and is +// sorted in ascending id order. +func GetServers(id int64) ([]*ServerMetric, bool) { + return db.get().GetServers(id) +} + +// GetServerSockets returns a slice of server's (identified by id) normal socket's +// SocketMetric, along with a boolean indicating whether there's more sockets to +// be queried for. +// +// The arg startID specifies that only sockets with id at or above it will be +// included in the result. The returned slice is up to a length of EntryPerPage, +// and is sorted in ascending id order. +func GetServerSockets(id int64, startID int64) ([]*SocketMetric, bool) { + return db.get().GetServerSockets(id, startID) +} + +// GetChannel returns the ChannelMetric for the channel (identified by id). +func GetChannel(id int64) *ChannelMetric { + return db.get().GetChannel(id) +} + +// GetSubChannel returns the SubChannelMetric for the subchannel (identified by id). +func GetSubChannel(id int64) *SubChannelMetric { + return db.get().GetSubChannel(id) +} + +// GetSocket returns the SocketInternalMetric for the socket (identified by id). +func GetSocket(id int64) *SocketMetric { + return db.get().GetSocket(id) +} + +// RegisterChannel registers the given channel c in channelz database with ref +// as its reference name, and add it to the child list of its parent (identified +// by pid). pid = 0 means no parent. It returns the unique channelz tracking id +// assigned to this channel. +func RegisterChannel(c Channel, pid int64, ref string) int64 { + id := idGen.genID() + cn := &channel{ + refName: ref, + c: c, + subChans: make(map[int64]string), + nestedChans: make(map[int64]string), + id: id, + pid: pid, + trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())}, + } + if pid == 0 { + db.get().addChannel(id, cn, true, pid, ref) + } else { + db.get().addChannel(id, cn, false, pid, ref) + } + return id +} + +// RegisterSubChannel registers the given channel c in channelz database with ref +// as its reference name, and add it to the child list of its parent (identified +// by pid). It returns the unique channelz tracking id assigned to this subchannel. +func RegisterSubChannel(c Channel, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a SubChannel's parent id cannot be 0") + return 0 + } + id := idGen.genID() + sc := &subChannel{ + refName: ref, + c: c, + sockets: make(map[int64]string), + id: id, + pid: pid, + trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())}, + } + db.get().addSubChannel(id, sc, pid, ref) + return id +} + +// RegisterServer registers the given server s in channelz database. It returns +// the unique channelz tracking id assigned to this server. +func RegisterServer(s Server, ref string) int64 { + id := idGen.genID() + svr := &server{ + refName: ref, + s: s, + sockets: make(map[int64]string), + listenSockets: make(map[int64]string), + id: id, + } + db.get().addServer(id, svr) + return id +} + +// RegisterListenSocket registers the given listen socket s in channelz database +// with ref as its reference name, and add it to the child list of its parent +// (identified by pid). It returns the unique channelz tracking id assigned to +// this listen socket. +func RegisterListenSocket(s Socket, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a ListenSocket's parent id cannot be 0") + return 0 + } + id := idGen.genID() + ls := &listenSocket{refName: ref, s: s, id: id, pid: pid} + db.get().addListenSocket(id, ls, pid, ref) + return id +} + +// RegisterNormalSocket registers the given normal socket s in channelz database +// with ref as its reference name, and add it to the child list of its parent +// (identified by pid). It returns the unique channelz tracking id assigned to +// this normal socket. +func RegisterNormalSocket(s Socket, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a NormalSocket's parent id cannot be 0") + return 0 + } + id := idGen.genID() + ns := &normalSocket{refName: ref, s: s, id: id, pid: pid} + db.get().addNormalSocket(id, ns, pid, ref) + return id +} + +// RemoveEntry removes an entry with unique channelz trakcing id to be id from +// channelz database. +func RemoveEntry(id int64) { + db.get().removeEntry(id) +} + +// TraceEventDesc is what the caller of AddTraceEvent should provide to describe the event to be added +// to the channel trace. +// The Parent field is optional. It is used for event that will be recorded in the entity's parent +// trace also. +type TraceEventDesc struct { + Desc string + Severity Severity + Parent *TraceEventDesc +} + +// AddTraceEvent adds trace related to the entity with specified id, using the provided TraceEventDesc. +func AddTraceEvent(id int64, desc *TraceEventDesc) { + if getMaxTraceEntry() == 0 { + return + } + db.get().traceEvent(id, desc) +} + +// channelMap is the storage data structure for channelz. +// Methods of channelMap can be divided in two two categories with respect to locking. +// 1. Methods acquire the global lock. +// 2. Methods that can only be called when global lock is held. +// A second type of method need always to be called inside a first type of method. +type channelMap struct { + mu sync.RWMutex + topLevelChannels map[int64]struct{} + servers map[int64]*server + channels map[int64]*channel + subChannels map[int64]*subChannel + listenSockets map[int64]*listenSocket + normalSockets map[int64]*normalSocket +} + +func (c *channelMap) addServer(id int64, s *server) { + c.mu.Lock() + s.cm = c + c.servers[id] = s + c.mu.Unlock() +} + +func (c *channelMap) addChannel(id int64, cn *channel, isTopChannel bool, pid int64, ref string) { + c.mu.Lock() + cn.cm = c + cn.trace.cm = c + c.channels[id] = cn + if isTopChannel { + c.topLevelChannels[id] = struct{}{} + } else { + c.findEntry(pid).addChild(id, cn) + } + c.mu.Unlock() +} + +func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64, ref string) { + c.mu.Lock() + sc.cm = c + sc.trace.cm = c + c.subChannels[id] = sc + c.findEntry(pid).addChild(id, sc) + c.mu.Unlock() +} + +func (c *channelMap) addListenSocket(id int64, ls *listenSocket, pid int64, ref string) { + c.mu.Lock() + ls.cm = c + c.listenSockets[id] = ls + c.findEntry(pid).addChild(id, ls) + c.mu.Unlock() +} + +func (c *channelMap) addNormalSocket(id int64, ns *normalSocket, pid int64, ref string) { + c.mu.Lock() + ns.cm = c + c.normalSockets[id] = ns + c.findEntry(pid).addChild(id, ns) + c.mu.Unlock() +} + +// removeEntry triggers the removal of an entry, which may not indeed delete the entry, if it has to +// wait on the deletion of its children and until no other entity's channel trace references it. +// It may lead to a chain of entry deletion. For example, deleting the last socket of a gracefully +// shutting down server will lead to the server being also deleted. +func (c *channelMap) removeEntry(id int64) { + c.mu.Lock() + c.findEntry(id).triggerDelete() + c.mu.Unlock() +} + +// c.mu must be held by the caller +func (c *channelMap) decrTraceRefCount(id int64) { + e := c.findEntry(id) + if v, ok := e.(tracedChannel); ok { + v.decrTraceRefCount() + e.deleteSelfIfReady() + } +} + +// c.mu must be held by the caller. +func (c *channelMap) findEntry(id int64) entry { + var v entry + var ok bool + if v, ok = c.channels[id]; ok { + return v + } + if v, ok = c.subChannels[id]; ok { + return v + } + if v, ok = c.servers[id]; ok { + return v + } + if v, ok = c.listenSockets[id]; ok { + return v + } + if v, ok = c.normalSockets[id]; ok { + return v + } + return &dummyEntry{idNotFound: id} +} + +// c.mu must be held by the caller +// deleteEntry simply deletes an entry from the channelMap. Before calling this +// method, caller must check this entry is ready to be deleted, i.e removeEntry() +// has been called on it, and no children still exist. +// Conditionals are ordered by the expected frequency of deletion of each entity +// type, in order to optimize performance. +func (c *channelMap) deleteEntry(id int64) { + var ok bool + if _, ok = c.normalSockets[id]; ok { + delete(c.normalSockets, id) + return + } + if _, ok = c.subChannels[id]; ok { + delete(c.subChannels, id) + return + } + if _, ok = c.channels[id]; ok { + delete(c.channels, id) + delete(c.topLevelChannels, id) + return + } + if _, ok = c.listenSockets[id]; ok { + delete(c.listenSockets, id) + return + } + if _, ok = c.servers[id]; ok { + delete(c.servers, id) + return + } +} + +func (c *channelMap) traceEvent(id int64, desc *TraceEventDesc) { + c.mu.Lock() + child := c.findEntry(id) + childTC, ok := child.(tracedChannel) + if !ok { + c.mu.Unlock() + return + } + childTC.getChannelTrace().append(&TraceEvent{Desc: desc.Desc, Severity: desc.Severity, Timestamp: time.Now()}) + if desc.Parent != nil { + parent := c.findEntry(child.getParentID()) + var chanType RefChannelType + switch child.(type) { + case *channel: + chanType = RefChannel + case *subChannel: + chanType = RefSubChannel + } + if parentTC, ok := parent.(tracedChannel); ok { + parentTC.getChannelTrace().append(&TraceEvent{ + Desc: desc.Parent.Desc, + Severity: desc.Parent.Severity, + Timestamp: time.Now(), + RefID: id, + RefName: childTC.getRefName(), + RefType: chanType, + }) + childTC.incrTraceRefCount() + } + } + c.mu.Unlock() +} + +type int64Slice []int64 + +func (s int64Slice) Len() int { return len(s) } +func (s int64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s int64Slice) Less(i, j int) bool { return s[i] < s[j] } + +func copyMap(m map[int64]string) map[int64]string { + n := make(map[int64]string) + for k, v := range m { + n[k] = v + } + return n +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func (c *channelMap) GetTopChannels(id int64) ([]*ChannelMetric, bool) { + c.mu.RLock() + l := len(c.topLevelChannels) + ids := make([]int64, 0, l) + cns := make([]*channel, 0, min(l, EntryPerPage)) + + for k := range c.topLevelChannels { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= id }) + count := 0 + var end bool + var t []*ChannelMetric + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if cn, ok := c.channels[v]; ok { + cns = append(cns, cn) + t = append(t, &ChannelMetric{ + NestedChans: copyMap(cn.nestedChans), + SubChans: copyMap(cn.subChans), + }) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + + for i, cn := range cns { + t[i].ChannelData = cn.c.ChannelzMetric() + t[i].ID = cn.id + t[i].RefName = cn.refName + t[i].Trace = cn.trace.dumpData() + } + return t, end +} + +func (c *channelMap) GetServers(id int64) ([]*ServerMetric, bool) { + c.mu.RLock() + l := len(c.servers) + ids := make([]int64, 0, l) + ss := make([]*server, 0, min(l, EntryPerPage)) + for k := range c.servers { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= id }) + count := 0 + var end bool + var s []*ServerMetric + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if svr, ok := c.servers[v]; ok { + ss = append(ss, svr) + s = append(s, &ServerMetric{ + ListenSockets: copyMap(svr.listenSockets), + }) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + + for i, svr := range ss { + s[i].ServerData = svr.s.ChannelzMetric() + s[i].ID = svr.id + s[i].RefName = svr.refName + } + return s, end +} + +func (c *channelMap) GetServerSockets(id int64, startID int64) ([]*SocketMetric, bool) { + var svr *server + var ok bool + c.mu.RLock() + if svr, ok = c.servers[id]; !ok { + // server with id doesn't exist. + c.mu.RUnlock() + return nil, true + } + svrskts := svr.sockets + l := len(svrskts) + ids := make([]int64, 0, l) + sks := make([]*normalSocket, 0, min(l, EntryPerPage)) + for k := range svrskts { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= startID }) + count := 0 + var end bool + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if ns, ok := c.normalSockets[v]; ok { + sks = append(sks, ns) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + var s []*SocketMetric + for _, ns := range sks { + sm := &SocketMetric{} + sm.SocketData = ns.s.ChannelzMetric() + sm.ID = ns.id + sm.RefName = ns.refName + s = append(s, sm) + } + return s, end +} + +func (c *channelMap) GetChannel(id int64) *ChannelMetric { + cm := &ChannelMetric{} + var cn *channel + var ok bool + c.mu.RLock() + if cn, ok = c.channels[id]; !ok { + // channel with id doesn't exist. + c.mu.RUnlock() + return nil + } + cm.NestedChans = copyMap(cn.nestedChans) + cm.SubChans = copyMap(cn.subChans) + // cn.c can be set to &dummyChannel{} when deleteSelfFromMap is called. Save a copy of cn.c when + // holding the lock to prevent potential data race. + chanCopy := cn.c + c.mu.RUnlock() + cm.ChannelData = chanCopy.ChannelzMetric() + cm.ID = cn.id + cm.RefName = cn.refName + cm.Trace = cn.trace.dumpData() + return cm +} + +func (c *channelMap) GetSubChannel(id int64) *SubChannelMetric { + cm := &SubChannelMetric{} + var sc *subChannel + var ok bool + c.mu.RLock() + if sc, ok = c.subChannels[id]; !ok { + // subchannel with id doesn't exist. + c.mu.RUnlock() + return nil + } + cm.Sockets = copyMap(sc.sockets) + // sc.c can be set to &dummyChannel{} when deleteSelfFromMap is called. Save a copy of sc.c when + // holding the lock to prevent potential data race. + chanCopy := sc.c + c.mu.RUnlock() + cm.ChannelData = chanCopy.ChannelzMetric() + cm.ID = sc.id + cm.RefName = sc.refName + cm.Trace = sc.trace.dumpData() + return cm +} + +func (c *channelMap) GetSocket(id int64) *SocketMetric { + sm := &SocketMetric{} + c.mu.RLock() + if ls, ok := c.listenSockets[id]; ok { + c.mu.RUnlock() + sm.SocketData = ls.s.ChannelzMetric() + sm.ID = ls.id + sm.RefName = ls.refName + return sm + } + if ns, ok := c.normalSockets[id]; ok { + c.mu.RUnlock() + sm.SocketData = ns.s.ChannelzMetric() + sm.ID = ns.id + sm.RefName = ns.refName + return sm + } + c.mu.RUnlock() + return nil +} + +type idGenerator struct { + id int64 +} + +func (i *idGenerator) reset() { + atomic.StoreInt64(&i.id, 0) +} + +func (i *idGenerator) genID() int64 { + return atomic.AddInt64(&i.id, 1) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/channelz/types.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/channelz/types.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go new file mode 100644 index 00000000..692dd618 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go @@ -0,0 +1,53 @@ +// +build !appengine + +/* + * + * 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 channelz + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// SocketOptionData defines the struct to hold socket option data, and related +// getter function to obtain info from fd. +type SocketOptionData struct { + Linger *unix.Linger + RecvTimeout *unix.Timeval + SendTimeout *unix.Timeval + TCPInfo *unix.TCPInfo +} + +// Getsockopt defines the function to get socket options requested by channelz. +// It is to be passed to syscall.RawConn.Control(). +func (s *SocketOptionData) Getsockopt(fd uintptr) { + if v, err := unix.GetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER); err == nil { + s.Linger = v + } + if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVTIMEO); err == nil { + s.RecvTimeout = v + } + if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDTIMEO); err == nil { + s.SendTimeout = v + } + if v, err := unix.GetsockoptTCPInfo(int(fd), syscall.SOL_TCP, syscall.TCP_INFO); err == nil { + s.TCPInfo = v + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go new file mode 100644 index 00000000..79edbefc --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go @@ -0,0 +1,44 @@ +// +build !linux appengine + +/* + * + * 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 channelz + +import ( + "sync" + + "google.golang.org/grpc/grpclog" +) + +var once sync.Once + +// SocketOptionData defines the struct to hold socket option data, and related +// getter function to obtain info from fd. +// Windows OS doesn't support Socket Option +type SocketOptionData struct { +} + +// Getsockopt defines the function to get socket options requested by channelz. +// It is to be passed to syscall.RawConn.Control(). +// Windows OS doesn't support Socket Option +func (s *SocketOptionData) Getsockopt(fd uintptr) { + once.Do(func() { + grpclog.Warningln("Channelz: socket options are not supported on non-linux os and appengine.") + }) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go new file mode 100644 index 00000000..fdf409d5 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go @@ -0,0 +1,39 @@ +// +build linux,!appengine + +/* + * + * 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 channelz + +import ( + "syscall" +) + +// GetSocketOption gets the socket option info of the conn. +func GetSocketOption(socket interface{}) *SocketOptionData { + c, ok := socket.(syscall.Conn) + if !ok { + return nil + } + data := &SocketOptionData{} + if rawConn, err := c.SyscallConn(); err == nil { + rawConn.Control(data.Getsockopt) + return data + } + return nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go new file mode 100644 index 00000000..8864a081 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go @@ -0,0 +1,26 @@ +// +build !linux appengine + +/* + * + * 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 channelz + +// GetSocketOption gets the socket option info of the conn. +func GetSocketOption(c interface{}) *SocketOptionData { + return nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go new file mode 100644 index 00000000..a3e02b66 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go @@ -0,0 +1,69 @@ +/* + * + * 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 envconfig contains grpc settings configured by environment variables. +package envconfig + +import ( + "os" + "strings" +) + +const ( + prefix = "GRPC_GO_" + retryStr = prefix + "RETRY" + requireHandshakeStr = prefix + "REQUIRE_HANDSHAKE" +) + +// RequireHandshakeSetting describes the settings for handshaking. +type RequireHandshakeSetting int + +const ( + // RequireHandshakeHybrid (default, deprecated) indicates to wait for + // handshake before considering a connection ready, but wait before + // considering successful. + RequireHandshakeHybrid RequireHandshakeSetting = iota + // RequireHandshakeOn (default after the 1.17 release) indicates to wait + // for handshake before considering a connection ready/successful. + RequireHandshakeOn + // RequireHandshakeOff indicates to not wait for handshake before + // considering a connection ready/successful. + RequireHandshakeOff +) + +var ( + // Retry is set if retry is explicitly enabled via "GRPC_GO_RETRY=on". + Retry = strings.EqualFold(os.Getenv(retryStr), "on") + // RequireHandshake is set based upon the GRPC_GO_REQUIRE_HANDSHAKE + // environment variable. + // + // Will be removed after the 1.18 release. + RequireHandshake RequireHandshakeSetting +) + +func init() { + switch strings.ToLower(os.Getenv(requireHandshakeStr)) { + case "on": + RequireHandshake = RequireHandshakeOn + case "off": + RequireHandshake = RequireHandshakeOff + case "hybrid": + // Will be removed after the 1.17 release. + RequireHandshake = RequireHandshakeHybrid + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go new file mode 100644 index 00000000..fbe697c3 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go @@ -0,0 +1,61 @@ +/* + * + * 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 grpcsync implements additional synchronization primitives built upon +// the sync package. +package grpcsync + +import ( + "sync" + "sync/atomic" +) + +// Event represents a one-time event that may occur in the future. +type Event struct { + fired int32 + c chan struct{} + o sync.Once +} + +// Fire causes e to complete. It is safe to call multiple times, and +// concurrently. It returns true iff this call to Fire caused the signaling +// channel returned by Done to close. +func (e *Event) Fire() bool { + ret := false + e.o.Do(func() { + atomic.StoreInt32(&e.fired, 1) + close(e.c) + ret = true + }) + return ret +} + +// Done returns a channel that will be closed when Fire is called. +func (e *Event) Done() <-chan struct{} { + return e.c +} + +// HasFired returns true if Fire has been called. +func (e *Event) HasFired() bool { + return atomic.LoadInt32(&e.fired) == 1 +} + +// NewEvent returns a new, ready-to-use Event. +func NewEvent() *Event { + return &Event{c: make(chan struct{})} +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go new file mode 100644 index 00000000..f8932b1d --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go @@ -0,0 +1,43 @@ +/* + * Copyright 2016 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 internal contains gRPC-internal code, to avoid polluting +// the godoc of the top-level grpc package. It must not import any grpc +// symbols to avoid circular dependencies. +package internal + +import "context" + +var ( + // WithContextDialer is exported by clientconn.go + WithContextDialer interface{} // func(context.Context, string) (net.Conn, error) grpc.DialOption + // WithResolverBuilder is exported by clientconn.go + WithResolverBuilder interface{} // func (resolver.Builder) grpc.DialOption + // HealthCheckFunc is used to provide client-side LB channel health checking + HealthCheckFunc func(ctx context.Context, newStream func() (interface{}, error), reportHealth func(bool), serviceName string) error +) + +const ( + // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode. + CredsBundleModeFallback = "fallback" + // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer + // mode. + CredsBundleModeBalancer = "balancer" + // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode + // that supports backend returned by grpclb balancer. + CredsBundleModeBackendFromBalancer = "backend-from-balancer" +) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go new file mode 100644 index 00000000..43281a3e --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go @@ -0,0 +1,114 @@ +// +build !appengine + +/* + * + * 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 syscall provides functionalities that grpc uses to get low-level operating system +// stats/info. +package syscall + +import ( + "fmt" + "net" + "syscall" + "time" + + "golang.org/x/sys/unix" + "google.golang.org/grpc/grpclog" +) + +// GetCPUTime returns the how much CPU time has passed since the start of this process. +func GetCPUTime() int64 { + var ts unix.Timespec + if err := unix.ClockGettime(unix.CLOCK_PROCESS_CPUTIME_ID, &ts); err != nil { + grpclog.Fatal(err) + } + return ts.Nano() +} + +// Rusage is an alias for syscall.Rusage under linux non-appengine environment. +type Rusage syscall.Rusage + +// GetRusage returns the resource usage of current process. +func GetRusage() (rusage *Rusage) { + rusage = new(Rusage) + syscall.Getrusage(syscall.RUSAGE_SELF, (*syscall.Rusage)(rusage)) + return +} + +// CPUTimeDiff returns the differences of user CPU time and system CPU time used +// between two Rusage structs. +func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) { + f := (*syscall.Rusage)(first) + l := (*syscall.Rusage)(latest) + var ( + utimeDiffs = l.Utime.Sec - f.Utime.Sec + utimeDiffus = l.Utime.Usec - f.Utime.Usec + stimeDiffs = l.Stime.Sec - f.Stime.Sec + stimeDiffus = l.Stime.Usec - f.Stime.Usec + ) + + uTimeElapsed := float64(utimeDiffs) + float64(utimeDiffus)*1.0e-6 + sTimeElapsed := float64(stimeDiffs) + float64(stimeDiffus)*1.0e-6 + + return uTimeElapsed, sTimeElapsed +} + +// SetTCPUserTimeout sets the TCP user timeout on a connection's socket +func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error { + tcpconn, ok := conn.(*net.TCPConn) + if !ok { + // not a TCP connection. exit early + return nil + } + rawConn, err := tcpconn.SyscallConn() + if err != nil { + return fmt.Errorf("error getting raw connection: %v", err) + } + err = rawConn.Control(func(fd uintptr) { + err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout/time.Millisecond)) + }) + if err != nil { + return fmt.Errorf("error setting option on socket: %v", err) + } + + return nil +} + +// GetTCPUserTimeout gets the TCP user timeout on a connection's socket +func GetTCPUserTimeout(conn net.Conn) (opt int, err error) { + tcpconn, ok := conn.(*net.TCPConn) + if !ok { + err = fmt.Errorf("conn is not *net.TCPConn. got %T", conn) + return + } + rawConn, err := tcpconn.SyscallConn() + if err != nil { + err = fmt.Errorf("error getting raw connection: %v", err) + return + } + err = rawConn.Control(func(fd uintptr) { + opt, err = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT) + }) + if err != nil { + err = fmt.Errorf("error getting option on socket: %v", err) + return + } + + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go new file mode 100644 index 00000000..61678feb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go @@ -0,0 +1,63 @@ +// +build !linux appengine + +/* + * + * 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 syscall + +import ( + "net" + "time" + + "google.golang.org/grpc/grpclog" +) + +func init() { + grpclog.Info("CPU time info is unavailable on non-linux or appengine environment.") +} + +// GetCPUTime returns the how much CPU time has passed since the start of this process. +// It always returns 0 under non-linux or appengine environment. +func GetCPUTime() int64 { + return 0 +} + +// Rusage is an empty struct under non-linux or appengine environment. +type Rusage struct{} + +// GetRusage is a no-op function under non-linux or appengine environment. +func GetRusage() (rusage *Rusage) { + return nil +} + +// CPUTimeDiff returns the differences of user CPU time and system CPU time used +// between two Rusage structs. It a no-op function for non-linux or appengine environment. +func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) { + return 0, 0 +} + +// SetTCPUserTimeout is a no-op function under non-linux or appengine environments +func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error { + return nil +} + +// GetTCPUserTimeout is a no-op function under non-linux or appengine environments +// a negative return value indicates the operation is not supported +func GetTCPUserTimeout(conn net.Conn) (int, error) { + return -1, nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go new file mode 100644 index 00000000..070680ed --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go @@ -0,0 +1,141 @@ +/* + * + * 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 transport + +import ( + "sync" + "time" +) + +const ( + // bdpLimit is the maximum value the flow control windows will be increased + // to. TCP typically limits this to 4MB, but some systems go up to 16MB. + // Since this is only a limit, it is safe to make it optimistic. + bdpLimit = (1 << 20) * 16 + // alpha is a constant factor used to keep a moving average + // of RTTs. + alpha = 0.9 + // If the current bdp sample is greater than or equal to + // our beta * our estimated bdp and the current bandwidth + // sample is the maximum bandwidth observed so far, we + // increase our bbp estimate by a factor of gamma. + beta = 0.66 + // To put our bdp to be smaller than or equal to twice the real BDP, + // we should multiply our current sample with 4/3, however to round things out + // we use 2 as the multiplication factor. + gamma = 2 +) + +// Adding arbitrary data to ping so that its ack can be identified. +// Easter-egg: what does the ping message say? +var bdpPing = &ping{data: [8]byte{2, 4, 16, 16, 9, 14, 7, 7}} + +type bdpEstimator struct { + // sentAt is the time when the ping was sent. + sentAt time.Time + + mu sync.Mutex + // bdp is the current bdp estimate. + bdp uint32 + // sample is the number of bytes received in one measurement cycle. + sample uint32 + // bwMax is the maximum bandwidth noted so far (bytes/sec). + bwMax float64 + // bool to keep track of the beginning of a new measurement cycle. + isSent bool + // Callback to update the window sizes. + updateFlowControl func(n uint32) + // sampleCount is the number of samples taken so far. + sampleCount uint64 + // round trip time (seconds) + rtt float64 +} + +// timesnap registers the time bdp ping was sent out so that +// network rtt can be calculated when its ack is received. +// It is called (by controller) when the bdpPing is +// being written on the wire. +func (b *bdpEstimator) timesnap(d [8]byte) { + if bdpPing.data != d { + return + } + b.sentAt = time.Now() +} + +// add adds bytes to the current sample for calculating bdp. +// It returns true only if a ping must be sent. This can be used +// by the caller (handleData) to make decision about batching +// a window update with it. +func (b *bdpEstimator) add(n uint32) bool { + b.mu.Lock() + defer b.mu.Unlock() + if b.bdp == bdpLimit { + return false + } + if !b.isSent { + b.isSent = true + b.sample = n + b.sentAt = time.Time{} + b.sampleCount++ + return true + } + b.sample += n + return false +} + +// calculate is called when an ack for a bdp ping is received. +// Here we calculate the current bdp and bandwidth sample and +// decide if the flow control windows should go up. +func (b *bdpEstimator) calculate(d [8]byte) { + // Check if the ping acked for was the bdp ping. + if bdpPing.data != d { + return + } + b.mu.Lock() + rttSample := time.Since(b.sentAt).Seconds() + if b.sampleCount < 10 { + // Bootstrap rtt with an average of first 10 rtt samples. + b.rtt += (rttSample - b.rtt) / float64(b.sampleCount) + } else { + // Heed to the recent past more. + b.rtt += (rttSample - b.rtt) * float64(alpha) + } + b.isSent = false + // The number of bytes accumulated so far in the sample is smaller + // than or equal to 1.5 times the real BDP on a saturated connection. + bwCurrent := float64(b.sample) / (b.rtt * float64(1.5)) + if bwCurrent > b.bwMax { + b.bwMax = bwCurrent + } + // If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is + // greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we + // should update our perception of the network BDP. + if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit { + sampleFloat := float64(b.sample) + b.bdp = uint32(gamma * sampleFloat) + if b.bdp > bdpLimit { + b.bdp = bdpLimit + } + bdp := b.bdp + b.mu.Unlock() + b.updateFlowControl(bdp) + return + } + b.mu.Unlock() +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/controlbuf.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/controlbuf.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/controlbuf.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/controlbuf.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/defaults.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/defaults.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/defaults.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/defaults.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go new file mode 100644 index 00000000..73b41ea7 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -0,0 +1,449 @@ +/* + * + * Copyright 2016 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. + * + */ + +// This file is the implementation of a gRPC server using HTTP/2 which +// uses the standard Go http2 Server implementation (via the +// http.Handler interface), rather than speaking low-level HTTP/2 +// frames itself. It is the implementation of *grpc.Server.ServeHTTP. + +package transport + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "net/http" + "strings" + "sync" + "time" + + "github.com/golang/protobuf/proto" + "golang.org/x/net/http2" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// NewServerHandlerTransport returns a ServerTransport handling gRPC +// from inside an http.Handler. It requires that the http Server +// supports HTTP/2. +func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request, stats stats.Handler) (ServerTransport, error) { + if r.ProtoMajor != 2 { + return nil, errors.New("gRPC requires HTTP/2") + } + if r.Method != "POST" { + return nil, errors.New("invalid gRPC request method") + } + contentType := r.Header.Get("Content-Type") + // TODO: do we assume contentType is lowercase? we did before + contentSubtype, validContentType := contentSubtype(contentType) + if !validContentType { + return nil, errors.New("invalid gRPC request content-type") + } + if _, ok := w.(http.Flusher); !ok { + return nil, errors.New("gRPC requires a ResponseWriter supporting http.Flusher") + } + if _, ok := w.(http.CloseNotifier); !ok { + return nil, errors.New("gRPC requires a ResponseWriter supporting http.CloseNotifier") + } + + st := &serverHandlerTransport{ + rw: w, + req: r, + closedCh: make(chan struct{}), + writes: make(chan func()), + contentType: contentType, + contentSubtype: contentSubtype, + stats: stats, + } + + if v := r.Header.Get("grpc-timeout"); v != "" { + to, err := decodeTimeout(v) + if err != nil { + return nil, status.Errorf(codes.Internal, "malformed time-out: %v", err) + } + st.timeoutSet = true + st.timeout = to + } + + metakv := []string{"content-type", contentType} + if r.Host != "" { + metakv = append(metakv, ":authority", r.Host) + } + for k, vv := range r.Header { + k = strings.ToLower(k) + if isReservedHeader(k) && !isWhitelistedHeader(k) { + continue + } + for _, v := range vv { + v, err := decodeMetadataHeader(k, v) + if err != nil { + return nil, status.Errorf(codes.Internal, "malformed binary metadata: %v", err) + } + metakv = append(metakv, k, v) + } + } + st.headerMD = metadata.Pairs(metakv...) + + return st, nil +} + +// serverHandlerTransport is an implementation of ServerTransport +// which replies to exactly one gRPC request (exactly one HTTP request), +// using the net/http.Handler interface. This http.Handler is guaranteed +// at this point to be speaking over HTTP/2, so it's able to speak valid +// gRPC. +type serverHandlerTransport struct { + rw http.ResponseWriter + req *http.Request + timeoutSet bool + timeout time.Duration + didCommonHeaders bool + + headerMD metadata.MD + + closeOnce sync.Once + closedCh chan struct{} // closed on Close + + // writes is a channel of code to run serialized in the + // ServeHTTP (HandleStreams) goroutine. The channel is closed + // when WriteStatus is called. + writes chan func() + + // block concurrent WriteStatus calls + // e.g. grpc/(*serverStream).SendMsg/RecvMsg + writeStatusMu sync.Mutex + + // we just mirror the request content-type + contentType string + // we store both contentType and contentSubtype so we don't keep recreating them + // TODO make sure this is consistent across handler_server and http2_server + contentSubtype string + + stats stats.Handler +} + +func (ht *serverHandlerTransport) Close() error { + ht.closeOnce.Do(ht.closeCloseChanOnce) + return nil +} + +func (ht *serverHandlerTransport) closeCloseChanOnce() { close(ht.closedCh) } + +func (ht *serverHandlerTransport) RemoteAddr() net.Addr { return strAddr(ht.req.RemoteAddr) } + +// strAddr is a net.Addr backed by either a TCP "ip:port" string, or +// the empty string if unknown. +type strAddr string + +func (a strAddr) Network() string { + if a != "" { + // Per the documentation on net/http.Request.RemoteAddr, if this is + // set, it's set to the IP:port of the peer (hence, TCP): + // https://golang.org/pkg/net/http/#Request + // + // If we want to support Unix sockets later, we can + // add our own grpc-specific convention within the + // grpc codebase to set RemoteAddr to a different + // format, or probably better: we can attach it to the + // context and use that from serverHandlerTransport.RemoteAddr. + return "tcp" + } + return "" +} + +func (a strAddr) String() string { return string(a) } + +// do runs fn in the ServeHTTP goroutine. +func (ht *serverHandlerTransport) do(fn func()) error { + // Avoid a panic writing to closed channel. Imperfect but maybe good enough. + select { + case <-ht.closedCh: + return ErrConnClosing + default: + select { + case ht.writes <- fn: + return nil + case <-ht.closedCh: + return ErrConnClosing + } + } +} + +func (ht *serverHandlerTransport) WriteStatus(s *Stream, st *status.Status) error { + ht.writeStatusMu.Lock() + defer ht.writeStatusMu.Unlock() + + err := ht.do(func() { + ht.writeCommonHeaders(s) + + // And flush, in case no header or body has been sent yet. + // This forces a separation of headers and trailers if this is the + // first call (for example, in end2end tests's TestNoService). + ht.rw.(http.Flusher).Flush() + + h := ht.rw.Header() + h.Set("Grpc-Status", fmt.Sprintf("%d", st.Code())) + if m := st.Message(); m != "" { + h.Set("Grpc-Message", encodeGrpcMessage(m)) + } + + if p := st.Proto(); p != nil && len(p.Details) > 0 { + stBytes, err := proto.Marshal(p) + if err != nil { + // TODO: return error instead, when callers are able to handle it. + panic(err) + } + + h.Set("Grpc-Status-Details-Bin", encodeBinHeader(stBytes)) + } + + if md := s.Trailer(); len(md) > 0 { + for k, vv := range md { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + // http2 ResponseWriter mechanism to send undeclared Trailers after + // the headers have possibly been written. + h.Add(http2.TrailerPrefix+k, encodeMetadataHeader(k, v)) + } + } + } + }) + + if err == nil { // transport has not been closed + if ht.stats != nil { + ht.stats.HandleRPC(s.Context(), &stats.OutTrailer{}) + } + close(ht.writes) + } + ht.Close() + return err +} + +// writeCommonHeaders sets common headers on the first write +// call (Write, WriteHeader, or WriteStatus). +func (ht *serverHandlerTransport) writeCommonHeaders(s *Stream) { + if ht.didCommonHeaders { + return + } + ht.didCommonHeaders = true + + h := ht.rw.Header() + h["Date"] = nil // suppress Date to make tests happy; TODO: restore + h.Set("Content-Type", ht.contentType) + + // Predeclare trailers we'll set later in WriteStatus (after the body). + // This is a SHOULD in the HTTP RFC, and the way you add (known) + // Trailers per the net/http.ResponseWriter contract. + // See https://golang.org/pkg/net/http/#ResponseWriter + // and https://golang.org/pkg/net/http/#example_ResponseWriter_trailers + h.Add("Trailer", "Grpc-Status") + h.Add("Trailer", "Grpc-Message") + h.Add("Trailer", "Grpc-Status-Details-Bin") + + if s.sendCompress != "" { + h.Set("Grpc-Encoding", s.sendCompress) + } +} + +func (ht *serverHandlerTransport) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + return ht.do(func() { + ht.writeCommonHeaders(s) + ht.rw.Write(hdr) + ht.rw.Write(data) + ht.rw.(http.Flusher).Flush() + }) +} + +func (ht *serverHandlerTransport) WriteHeader(s *Stream, md metadata.MD) error { + err := ht.do(func() { + ht.writeCommonHeaders(s) + h := ht.rw.Header() + for k, vv := range md { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + v = encodeMetadataHeader(k, v) + h.Add(k, v) + } + } + ht.rw.WriteHeader(200) + ht.rw.(http.Flusher).Flush() + }) + + if err == nil { + if ht.stats != nil { + ht.stats.HandleRPC(s.Context(), &stats.OutHeader{}) + } + } + return err +} + +func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream), traceCtx func(context.Context, string) context.Context) { + // With this transport type there will be exactly 1 stream: this HTTP request. + + ctx := ht.req.Context() + var cancel context.CancelFunc + if ht.timeoutSet { + ctx, cancel = context.WithTimeout(ctx, ht.timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + + // requestOver is closed when either the request's context is done + // or the status has been written via WriteStatus. + requestOver := make(chan struct{}) + + // clientGone receives a single value if peer is gone, either + // because the underlying connection is dead or because the + // peer sends an http2 RST_STREAM. + clientGone := ht.rw.(http.CloseNotifier).CloseNotify() + go func() { + select { + case <-requestOver: + case <-ht.closedCh: + case <-clientGone: + } + cancel() + ht.Close() + }() + + req := ht.req + + s := &Stream{ + id: 0, // irrelevant + requestRead: func(int) {}, + cancel: cancel, + buf: newRecvBuffer(), + st: ht, + method: req.URL.Path, + recvCompress: req.Header.Get("grpc-encoding"), + contentSubtype: ht.contentSubtype, + } + pr := &peer.Peer{ + Addr: ht.RemoteAddr(), + } + if req.TLS != nil { + pr.AuthInfo = credentials.TLSInfo{State: *req.TLS} + } + ctx = metadata.NewIncomingContext(ctx, ht.headerMD) + s.ctx = peer.NewContext(ctx, pr) + if ht.stats != nil { + s.ctx = ht.stats.TagRPC(s.ctx, &stats.RPCTagInfo{FullMethodName: s.method}) + inHeader := &stats.InHeader{ + FullMethod: s.method, + RemoteAddr: ht.RemoteAddr(), + Compression: s.recvCompress, + } + ht.stats.HandleRPC(s.ctx, inHeader) + } + s.trReader = &transportReader{ + reader: &recvBufferReader{ctx: s.ctx, ctxDone: s.ctx.Done(), recv: s.buf}, + windowHandler: func(int) {}, + } + + // readerDone is closed when the Body.Read-ing goroutine exits. + readerDone := make(chan struct{}) + go func() { + defer close(readerDone) + + // TODO: minimize garbage, optimize recvBuffer code/ownership + const readSize = 8196 + for buf := make([]byte, readSize); ; { + n, err := req.Body.Read(buf) + if n > 0 { + s.buf.put(recvMsg{data: buf[:n:n]}) + buf = buf[n:] + } + if err != nil { + s.buf.put(recvMsg{err: mapRecvMsgError(err)}) + return + } + if len(buf) == 0 { + buf = make([]byte, readSize) + } + } + }() + + // startStream is provided by the *grpc.Server's serveStreams. + // It starts a goroutine serving s and exits immediately. + // The goroutine that is started is the one that then calls + // into ht, calling WriteHeader, Write, WriteStatus, Close, etc. + startStream(s) + + ht.runStream() + close(requestOver) + + // Wait for reading goroutine to finish. + req.Body.Close() + <-readerDone +} + +func (ht *serverHandlerTransport) runStream() { + for { + select { + case fn, ok := <-ht.writes: + if !ok { + return + } + fn() + case <-ht.closedCh: + return + } + } +} + +func (ht *serverHandlerTransport) IncrMsgSent() {} + +func (ht *serverHandlerTransport) IncrMsgRecv() {} + +func (ht *serverHandlerTransport) Drain() { + panic("Drain() is not implemented") +} + +// mapRecvMsgError returns the non-nil err into the appropriate +// error value as expected by callers of *grpc.parser.recvMsg. +// In particular, in can only be: +// * io.EOF +// * io.ErrUnexpectedEOF +// * of type transport.ConnectionError +// * an error from the status package +func mapRecvMsgError(err error) error { + if err == io.EOF || err == io.ErrUnexpectedEOF { + return err + } + if se, ok := err.(http2.StreamError); ok { + if code, ok := http2ErrConvTab[se.Code]; ok { + return status.Error(code, se.Error()) + } + } + if strings.Contains(err.Error(), "body closed by handler") { + return status.Error(codes.Canceled, err.Error()) + } + return connectionErrorf(true, err, err.Error()) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go new file mode 100644 index 00000000..39208b14 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -0,0 +1,1377 @@ +/* + * + * Copyright 2014 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 transport + +import ( + "context" + "fmt" + "io" + "math" + "net" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + + "golang.org/x/net/http2" + "golang.org/x/net/http2/hpack" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/syscall" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// http2Client implements the ClientTransport interface with HTTP2. +type http2Client struct { + ctx context.Context + cancel context.CancelFunc + ctxDone <-chan struct{} // Cache the ctx.Done() chan. + userAgent string + md interface{} + conn net.Conn // underlying communication channel + loopy *loopyWriter + remoteAddr net.Addr + localAddr net.Addr + authInfo credentials.AuthInfo // auth info about the connection + + readerDone chan struct{} // sync point to enable testing. + writerDone chan struct{} // sync point to enable testing. + // goAway is closed to notify the upper layer (i.e., addrConn.transportMonitor) + // that the server sent GoAway on this transport. + goAway chan struct{} + // awakenKeepalive is used to wake up keepalive when after it has gone dormant. + awakenKeepalive chan struct{} + + framer *framer + // controlBuf delivers all the control related tasks (e.g., window + // updates, reset streams, and various settings) to the controller. + controlBuf *controlBuffer + fc *trInFlow + // The scheme used: https if TLS is on, http otherwise. + scheme string + + isSecure bool + + perRPCCreds []credentials.PerRPCCredentials + + // Boolean to keep track of reading activity on transport. + // 1 is true and 0 is false. + activity uint32 // Accessed atomically. + kp keepalive.ClientParameters + keepaliveEnabled bool + + statsHandler stats.Handler + + initialWindowSize int32 + + // configured by peer through SETTINGS_MAX_HEADER_LIST_SIZE + maxSendHeaderListSize *uint32 + + bdpEst *bdpEstimator + // onSuccess is a callback that client transport calls upon + // receiving server preface to signal that a succefull HTTP2 + // connection was established. + onSuccess func() + + maxConcurrentStreams uint32 + streamQuota int64 + streamsQuotaAvailable chan struct{} + waitingStreams uint32 + nextID uint32 + + mu sync.Mutex // guard the following variables + state transportState + activeStreams map[uint32]*Stream + // prevGoAway ID records the Last-Stream-ID in the previous GOAway frame. + prevGoAwayID uint32 + // goAwayReason records the http2.ErrCode and debug data received with the + // GoAway frame. + goAwayReason GoAwayReason + + // Fields below are for channelz metric collection. + channelzID int64 // channelz unique identification number + czData *channelzData + + onGoAway func(GoAwayReason) + onClose func() +} + +func dial(ctx context.Context, fn func(context.Context, string) (net.Conn, error), addr string) (net.Conn, error) { + if fn != nil { + return fn(ctx, addr) + } + return (&net.Dialer{}).DialContext(ctx, "tcp", addr) +} + +func isTemporary(err error) bool { + switch err := err.(type) { + case interface { + Temporary() bool + }: + return err.Temporary() + case interface { + Timeout() bool + }: + // Timeouts may be resolved upon retry, and are thus treated as + // temporary. + return err.Timeout() + } + return true +} + +// newHTTP2Client constructs a connected ClientTransport to addr based on HTTP2 +// and starts to receive messages on it. Non-nil error returns if construction +// fails. +func newHTTP2Client(connectCtx, ctx context.Context, addr TargetInfo, opts ConnectOptions, onSuccess func(), onGoAway func(GoAwayReason), onClose func()) (_ *http2Client, err error) { + scheme := "http" + ctx, cancel := context.WithCancel(ctx) + defer func() { + if err != nil { + cancel() + } + }() + + conn, err := dial(connectCtx, opts.Dialer, addr.Addr) + if err != nil { + if opts.FailOnNonTempDialError { + return nil, connectionErrorf(isTemporary(err), err, "transport: error while dialing: %v", err) + } + return nil, connectionErrorf(true, err, "transport: Error while dialing %v", err) + } + // Any further errors will close the underlying connection + defer func(conn net.Conn) { + if err != nil { + conn.Close() + } + }(conn) + kp := opts.KeepaliveParams + // Validate keepalive parameters. + if kp.Time == 0 { + kp.Time = defaultClientKeepaliveTime + } + if kp.Timeout == 0 { + kp.Timeout = defaultClientKeepaliveTimeout + } + keepaliveEnabled := false + if kp.Time != infinity { + if err = syscall.SetTCPUserTimeout(conn, kp.Timeout); err != nil { + return nil, connectionErrorf(false, err, "transport: failed to set TCP_USER_TIMEOUT: %v", err) + } + keepaliveEnabled = true + } + var ( + isSecure bool + authInfo credentials.AuthInfo + ) + transportCreds := opts.TransportCredentials + perRPCCreds := opts.PerRPCCredentials + + if b := opts.CredsBundle; b != nil { + if t := b.TransportCredentials(); t != nil { + transportCreds = t + } + if t := b.PerRPCCredentials(); t != nil { + perRPCCreds = append(perRPCCreds, t) + } + } + if transportCreds != nil { + scheme = "https" + conn, authInfo, err = transportCreds.ClientHandshake(connectCtx, addr.Authority, conn) + if err != nil { + return nil, connectionErrorf(isTemporary(err), err, "transport: authentication handshake failed: %v", err) + } + isSecure = true + } + dynamicWindow := true + icwz := int32(initialWindowSize) + if opts.InitialConnWindowSize >= defaultWindowSize { + icwz = opts.InitialConnWindowSize + dynamicWindow = false + } + writeBufSize := opts.WriteBufferSize + readBufSize := opts.ReadBufferSize + maxHeaderListSize := defaultClientMaxHeaderListSize + if opts.MaxHeaderListSize != nil { + maxHeaderListSize = *opts.MaxHeaderListSize + } + t := &http2Client{ + ctx: ctx, + ctxDone: ctx.Done(), // Cache Done chan. + cancel: cancel, + userAgent: opts.UserAgent, + md: addr.Metadata, + conn: conn, + remoteAddr: conn.RemoteAddr(), + localAddr: conn.LocalAddr(), + authInfo: authInfo, + readerDone: make(chan struct{}), + writerDone: make(chan struct{}), + goAway: make(chan struct{}), + awakenKeepalive: make(chan struct{}, 1), + framer: newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize), + fc: &trInFlow{limit: uint32(icwz)}, + scheme: scheme, + activeStreams: make(map[uint32]*Stream), + isSecure: isSecure, + perRPCCreds: perRPCCreds, + kp: kp, + statsHandler: opts.StatsHandler, + initialWindowSize: initialWindowSize, + onSuccess: onSuccess, + nextID: 1, + maxConcurrentStreams: defaultMaxStreamsClient, + streamQuota: defaultMaxStreamsClient, + streamsQuotaAvailable: make(chan struct{}, 1), + czData: new(channelzData), + onGoAway: onGoAway, + onClose: onClose, + keepaliveEnabled: keepaliveEnabled, + } + t.controlBuf = newControlBuffer(t.ctxDone) + if opts.InitialWindowSize >= defaultWindowSize { + t.initialWindowSize = opts.InitialWindowSize + dynamicWindow = false + } + if dynamicWindow { + t.bdpEst = &bdpEstimator{ + bdp: initialWindowSize, + updateFlowControl: t.updateFlowControl, + } + } + // Make sure awakenKeepalive can't be written upon. + // keepalive routine will make it writable, if need be. + t.awakenKeepalive <- struct{}{} + if t.statsHandler != nil { + t.ctx = t.statsHandler.TagConn(t.ctx, &stats.ConnTagInfo{ + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + }) + connBegin := &stats.ConnBegin{ + Client: true, + } + t.statsHandler.HandleConn(t.ctx, connBegin) + } + if channelz.IsOn() { + t.channelzID = channelz.RegisterNormalSocket(t, opts.ChannelzParentID, fmt.Sprintf("%s -> %s", t.localAddr, t.remoteAddr)) + } + if t.keepaliveEnabled { + go t.keepalive() + } + // Start the reader goroutine for incoming message. Each transport has + // a dedicated goroutine which reads HTTP2 frame from network. Then it + // dispatches the frame to the corresponding stream entity. + go t.reader() + + // Send connection preface to server. + n, err := t.conn.Write(clientPreface) + if err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write client preface: %v", err) + } + if n != len(clientPreface) { + t.Close() + return nil, connectionErrorf(true, err, "transport: preface mismatch, wrote %d bytes; want %d", n, len(clientPreface)) + } + var ss []http2.Setting + + if t.initialWindowSize != defaultWindowSize { + ss = append(ss, http2.Setting{ + ID: http2.SettingInitialWindowSize, + Val: uint32(t.initialWindowSize), + }) + } + if opts.MaxHeaderListSize != nil { + ss = append(ss, http2.Setting{ + ID: http2.SettingMaxHeaderListSize, + Val: *opts.MaxHeaderListSize, + }) + } + err = t.framer.fr.WriteSettings(ss...) + if err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write initial settings frame: %v", err) + } + // Adjust the connection flow control window if needed. + if delta := uint32(icwz - defaultWindowSize); delta > 0 { + if err := t.framer.fr.WriteWindowUpdate(0, delta); err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write window update: %v", err) + } + } + + t.framer.writer.Flush() + go func() { + t.loopy = newLoopyWriter(clientSide, t.framer, t.controlBuf, t.bdpEst) + err := t.loopy.run() + if err != nil { + errorf("transport: loopyWriter.run returning. Err: %v", err) + } + // If it's a connection error, let reader goroutine handle it + // since there might be data in the buffers. + if _, ok := err.(net.Error); !ok { + t.conn.Close() + } + close(t.writerDone) + }() + return t, nil +} + +func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr) *Stream { + // TODO(zhaoq): Handle uint32 overflow of Stream.id. + s := &Stream{ + done: make(chan struct{}), + method: callHdr.Method, + sendCompress: callHdr.SendCompress, + buf: newRecvBuffer(), + headerChan: make(chan struct{}), + contentSubtype: callHdr.ContentSubtype, + } + s.wq = newWriteQuota(defaultWriteQuota, s.done) + s.requestRead = func(n int) { + t.adjustWindow(s, uint32(n)) + } + // The client side stream context should have exactly the same life cycle with the user provided context. + // That means, s.ctx should be read-only. And s.ctx is done iff ctx is done. + // So we use the original context here instead of creating a copy. + s.ctx = ctx + s.trReader = &transportReader{ + reader: &recvBufferReader{ + ctx: s.ctx, + ctxDone: s.ctx.Done(), + recv: s.buf, + }, + windowHandler: func(n int) { + t.updateWindow(s, uint32(n)) + }, + } + return s +} + +func (t *http2Client) getPeer() *peer.Peer { + pr := &peer.Peer{ + Addr: t.remoteAddr, + } + // Attach Auth info if there is any. + if t.authInfo != nil { + pr.AuthInfo = t.authInfo + } + return pr +} + +func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) ([]hpack.HeaderField, error) { + aud := t.createAudience(callHdr) + authData, err := t.getTrAuthData(ctx, aud) + if err != nil { + return nil, err + } + callAuthData, err := t.getCallAuthData(ctx, aud, callHdr) + if err != nil { + return nil, err + } + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + // Make the slice of certain predictable size to reduce allocations made by append. + hfLen := 7 // :method, :scheme, :path, :authority, content-type, user-agent, te + hfLen += len(authData) + len(callAuthData) + headerFields := make([]hpack.HeaderField, 0, hfLen) + headerFields = append(headerFields, hpack.HeaderField{Name: ":method", Value: "POST"}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":scheme", Value: t.scheme}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":path", Value: callHdr.Method}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":authority", Value: callHdr.Host}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(callHdr.ContentSubtype)}) + headerFields = append(headerFields, hpack.HeaderField{Name: "user-agent", Value: t.userAgent}) + headerFields = append(headerFields, hpack.HeaderField{Name: "te", Value: "trailers"}) + if callHdr.PreviousAttempts > 0 { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-previous-rpc-attempts", Value: strconv.Itoa(callHdr.PreviousAttempts)}) + } + + if callHdr.SendCompress != "" { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: callHdr.SendCompress}) + } + if dl, ok := ctx.Deadline(); ok { + // Send out timeout regardless its value. The server can detect timeout context by itself. + // TODO(mmukhi): Perhaps this field should be updated when actually writing out to the wire. + timeout := dl.Sub(time.Now()) + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-timeout", Value: encodeTimeout(timeout)}) + } + for k, v := range authData { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + for k, v := range callAuthData { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + if b := stats.OutgoingTags(ctx); b != nil { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-tags-bin", Value: encodeBinHeader(b)}) + } + if b := stats.OutgoingTrace(ctx); b != nil { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-trace-bin", Value: encodeBinHeader(b)}) + } + + if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok { + var k string + for _, vv := range added { + for i, v := range vv { + if i%2 == 0 { + k = v + continue + } + // HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set. + if isReservedHeader(k) { + continue + } + headerFields = append(headerFields, hpack.HeaderField{Name: strings.ToLower(k), Value: encodeMetadataHeader(k, v)}) + } + } + for k, vv := range md { + // HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + } + if md, ok := t.md.(*metadata.MD); ok { + for k, vv := range *md { + if isReservedHeader(k) { + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + } + return headerFields, nil +} + +func (t *http2Client) createAudience(callHdr *CallHdr) string { + // Create an audience string only if needed. + if len(t.perRPCCreds) == 0 && callHdr.Creds == nil { + return "" + } + // Construct URI required to get auth request metadata. + // Omit port if it is the default one. + host := strings.TrimSuffix(callHdr.Host, ":443") + pos := strings.LastIndex(callHdr.Method, "/") + if pos == -1 { + pos = len(callHdr.Method) + } + return "https://" + host + callHdr.Method[:pos] +} + +func (t *http2Client) getTrAuthData(ctx context.Context, audience string) (map[string]string, error) { + authData := map[string]string{} + for _, c := range t.perRPCCreds { + data, err := c.GetRequestMetadata(ctx, audience) + if err != nil { + if _, ok := status.FromError(err); ok { + return nil, err + } + + return nil, status.Errorf(codes.Unauthenticated, "transport: %v", err) + } + for k, v := range data { + // Capital header names are illegal in HTTP/2. + k = strings.ToLower(k) + authData[k] = v + } + } + return authData, nil +} + +func (t *http2Client) getCallAuthData(ctx context.Context, audience string, callHdr *CallHdr) (map[string]string, error) { + callAuthData := map[string]string{} + // Check if credentials.PerRPCCredentials were provided via call options. + // Note: if these credentials are provided both via dial options and call + // options, then both sets of credentials will be applied. + if callCreds := callHdr.Creds; callCreds != nil { + if !t.isSecure && callCreds.RequireTransportSecurity() { + return nil, status.Error(codes.Unauthenticated, "transport: cannot send secure credentials on an insecure connection") + } + data, err := callCreds.GetRequestMetadata(ctx, audience) + if err != nil { + return nil, status.Errorf(codes.Internal, "transport: %v", err) + } + for k, v := range data { + // Capital header names are illegal in HTTP/2 + k = strings.ToLower(k) + callAuthData[k] = v + } + } + return callAuthData, nil +} + +// NewStream creates a stream and registers it into the transport as "active" +// streams. +func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Stream, err error) { + ctx = peer.NewContext(ctx, t.getPeer()) + headerFields, err := t.createHeaderFields(ctx, callHdr) + if err != nil { + return nil, err + } + s := t.newStream(ctx, callHdr) + cleanup := func(err error) { + if s.swapState(streamDone) == streamDone { + // If it was already done, return. + return + } + // The stream was unprocessed by the server. + atomic.StoreUint32(&s.unprocessed, 1) + s.write(recvMsg{err: err}) + close(s.done) + // If headerChan isn't closed, then close it. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + close(s.headerChan) + } + + } + hdr := &headerFrame{ + hf: headerFields, + endStream: false, + initStream: func(id uint32) (bool, error) { + t.mu.Lock() + if state := t.state; state != reachable { + t.mu.Unlock() + // Do a quick cleanup. + err := error(errStreamDrain) + if state == closing { + err = ErrConnClosing + } + cleanup(err) + return false, err + } + t.activeStreams[id] = s + if channelz.IsOn() { + atomic.AddInt64(&t.czData.streamsStarted, 1) + atomic.StoreInt64(&t.czData.lastStreamCreatedTime, time.Now().UnixNano()) + } + var sendPing bool + // If the number of active streams change from 0 to 1, then check if keepalive + // has gone dormant. If so, wake it up. + if len(t.activeStreams) == 1 && t.keepaliveEnabled { + select { + case t.awakenKeepalive <- struct{}{}: + sendPing = true + // Fill the awakenKeepalive channel again as this channel must be + // kept non-writable except at the point that the keepalive() + // goroutine is waiting either to be awaken or shutdown. + t.awakenKeepalive <- struct{}{} + default: + } + } + t.mu.Unlock() + return sendPing, nil + }, + onOrphaned: cleanup, + wq: s.wq, + } + firstTry := true + var ch chan struct{} + checkForStreamQuota := func(it interface{}) bool { + if t.streamQuota <= 0 { // Can go negative if server decreases it. + if firstTry { + t.waitingStreams++ + } + ch = t.streamsQuotaAvailable + return false + } + if !firstTry { + t.waitingStreams-- + } + t.streamQuota-- + h := it.(*headerFrame) + h.streamID = t.nextID + t.nextID += 2 + s.id = h.streamID + s.fc = &inFlow{limit: uint32(t.initialWindowSize)} + if t.streamQuota > 0 && t.waitingStreams > 0 { + select { + case t.streamsQuotaAvailable <- struct{}{}: + default: + } + } + return true + } + var hdrListSizeErr error + checkForHeaderListSize := func(it interface{}) bool { + if t.maxSendHeaderListSize == nil { + return true + } + hdrFrame := it.(*headerFrame) + var sz int64 + for _, f := range hdrFrame.hf { + if sz += int64(f.Size()); sz > int64(*t.maxSendHeaderListSize) { + hdrListSizeErr = status.Errorf(codes.Internal, "header list size to send violates the maximum size (%d bytes) set by server", *t.maxSendHeaderListSize) + return false + } + } + return true + } + for { + success, err := t.controlBuf.executeAndPut(func(it interface{}) bool { + if !checkForStreamQuota(it) { + return false + } + if !checkForHeaderListSize(it) { + return false + } + return true + }, hdr) + if err != nil { + return nil, err + } + if success { + break + } + if hdrListSizeErr != nil { + return nil, hdrListSizeErr + } + firstTry = false + select { + case <-ch: + case <-s.ctx.Done(): + return nil, ContextErr(s.ctx.Err()) + case <-t.goAway: + return nil, errStreamDrain + case <-t.ctx.Done(): + return nil, ErrConnClosing + } + } + if t.statsHandler != nil { + outHeader := &stats.OutHeader{ + Client: true, + FullMethod: callHdr.Method, + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + Compression: callHdr.SendCompress, + } + t.statsHandler.HandleRPC(s.ctx, outHeader) + } + return s, nil +} + +// CloseStream clears the footprint of a stream when the stream is not needed any more. +// This must not be executed in reader's goroutine. +func (t *http2Client) CloseStream(s *Stream, err error) { + var ( + rst bool + rstCode http2.ErrCode + ) + if err != nil { + rst = true + rstCode = http2.ErrCodeCancel + } + t.closeStream(s, err, rst, rstCode, status.Convert(err), nil, false) +} + +func (t *http2Client) closeStream(s *Stream, err error, rst bool, rstCode http2.ErrCode, st *status.Status, mdata map[string][]string, eosReceived bool) { + // Set stream status to done. + if s.swapState(streamDone) == streamDone { + // If it was already done, return. If multiple closeStream calls + // happen simultaneously, wait for the first to finish. + <-s.done + return + } + // status and trailers can be updated here without any synchronization because the stream goroutine will + // only read it after it sees an io.EOF error from read or write and we'll write those errors + // only after updating this. + s.status = st + if len(mdata) > 0 { + s.trailer = mdata + } + if err != nil { + // This will unblock reads eventually. + s.write(recvMsg{err: err}) + } + // If headerChan isn't closed, then close it. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + s.noHeaders = true + close(s.headerChan) + } + cleanup := &cleanupStream{ + streamID: s.id, + onWrite: func() { + t.mu.Lock() + if t.activeStreams != nil { + delete(t.activeStreams, s.id) + } + t.mu.Unlock() + if channelz.IsOn() { + if eosReceived { + atomic.AddInt64(&t.czData.streamsSucceeded, 1) + } else { + atomic.AddInt64(&t.czData.streamsFailed, 1) + } + } + }, + rst: rst, + rstCode: rstCode, + } + addBackStreamQuota := func(interface{}) bool { + t.streamQuota++ + if t.streamQuota > 0 && t.waitingStreams > 0 { + select { + case t.streamsQuotaAvailable <- struct{}{}: + default: + } + } + return true + } + t.controlBuf.executeAndPut(addBackStreamQuota, cleanup) + // This will unblock write. + close(s.done) +} + +// Close kicks off the shutdown process of the transport. This should be called +// only once on a transport. Once it is called, the transport should not be +// accessed any more. +// +// This method blocks until the addrConn that initiated this transport is +// re-connected. This happens because t.onClose() begins reconnect logic at the +// addrConn level and blocks until the addrConn is successfully connected. +func (t *http2Client) Close() error { + t.mu.Lock() + // Make sure we only Close once. + if t.state == closing { + t.mu.Unlock() + return nil + } + t.state = closing + streams := t.activeStreams + t.activeStreams = nil + t.mu.Unlock() + t.controlBuf.finish() + t.cancel() + err := t.conn.Close() + if channelz.IsOn() { + channelz.RemoveEntry(t.channelzID) + } + // Notify all active streams. + for _, s := range streams { + t.closeStream(s, ErrConnClosing, false, http2.ErrCodeNo, status.New(codes.Unavailable, ErrConnClosing.Desc), nil, false) + } + if t.statsHandler != nil { + connEnd := &stats.ConnEnd{ + Client: true, + } + t.statsHandler.HandleConn(t.ctx, connEnd) + } + go t.onClose() + return err +} + +// GracefulClose sets the state to draining, which prevents new streams from +// being created and causes the transport to be closed when the last active +// stream is closed. If there are no active streams, the transport is closed +// immediately. This does nothing if the transport is already draining or +// closing. +func (t *http2Client) GracefulClose() error { + t.mu.Lock() + // Make sure we move to draining only from active. + if t.state == draining || t.state == closing { + t.mu.Unlock() + return nil + } + t.state = draining + active := len(t.activeStreams) + t.mu.Unlock() + if active == 0 { + return t.Close() + } + t.controlBuf.put(&incomingGoAway{}) + return nil +} + +// Write formats the data into HTTP2 data frame(s) and sends it out. The caller +// should proceed only if Write returns nil. +func (t *http2Client) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + if opts.Last { + // If it's the last message, update stream state. + if !s.compareAndSwapState(streamActive, streamWriteDone) { + return errStreamDone + } + } else if s.getState() != streamActive { + return errStreamDone + } + df := &dataFrame{ + streamID: s.id, + endStream: opts.Last, + } + if hdr != nil || data != nil { // If it's not an empty data frame. + // Add some data to grpc message header so that we can equally + // distribute bytes across frames. + emptyLen := http2MaxFrameLen - len(hdr) + if emptyLen > len(data) { + emptyLen = len(data) + } + hdr = append(hdr, data[:emptyLen]...) + data = data[emptyLen:] + df.h, df.d = hdr, data + // TODO(mmukhi): The above logic in this if can be moved to loopyWriter's data handler. + if err := s.wq.get(int32(len(hdr) + len(data))); err != nil { + return err + } + } + return t.controlBuf.put(df) +} + +func (t *http2Client) getStream(f http2.Frame) (*Stream, bool) { + t.mu.Lock() + defer t.mu.Unlock() + s, ok := t.activeStreams[f.Header().StreamID] + return s, ok +} + +// adjustWindow sends out extra window update over the initial window size +// of stream if the application is requesting data larger in size than +// the window. +func (t *http2Client) adjustWindow(s *Stream, n uint32) { + if w := s.fc.maybeAdjust(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } +} + +// updateWindow adjusts the inbound quota for the stream. +// Window updates will be sent out when the cumulative quota +// exceeds the corresponding threshold. +func (t *http2Client) updateWindow(s *Stream, n uint32) { + if w := s.fc.onRead(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } +} + +// updateFlowControl updates the incoming flow control windows +// for the transport and the stream based on the current bdp +// estimation. +func (t *http2Client) updateFlowControl(n uint32) { + t.mu.Lock() + for _, s := range t.activeStreams { + s.fc.newLimit(n) + } + t.mu.Unlock() + updateIWS := func(interface{}) bool { + t.initialWindowSize = int32(n) + return true + } + t.controlBuf.executeAndPut(updateIWS, &outgoingWindowUpdate{streamID: 0, increment: t.fc.newLimit(n)}) + t.controlBuf.put(&outgoingSettings{ + ss: []http2.Setting{ + { + ID: http2.SettingInitialWindowSize, + Val: n, + }, + }, + }) +} + +func (t *http2Client) handleData(f *http2.DataFrame) { + size := f.Header().Length + var sendBDPPing bool + if t.bdpEst != nil { + sendBDPPing = t.bdpEst.add(size) + } + // Decouple connection's flow control from application's read. + // An update on connection's flow control should not depend on + // whether user application has read the data or not. Such a + // restriction is already imposed on the stream's flow control, + // and therefore the sender will be blocked anyways. + // Decoupling the connection flow control will prevent other + // active(fast) streams from starving in presence of slow or + // inactive streams. + // + if w := t.fc.onData(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + if sendBDPPing { + // Avoid excessive ping detection (e.g. in an L7 proxy) + // by sending a window update prior to the BDP ping. + + if w := t.fc.reset(); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + + t.controlBuf.put(bdpPing) + } + // Select the right stream to dispatch. + s, ok := t.getStream(f) + if !ok { + return + } + if size > 0 { + if err := s.fc.onData(size); err != nil { + t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil, false) + return + } + if f.Header().Flags.Has(http2.FlagDataPadded) { + if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + } + } + // TODO(bradfitz, zhaoq): A copy is required here because there is no + // guarantee f.Data() is consumed before the arrival of next frame. + // Can this copy be eliminated? + if len(f.Data()) > 0 { + data := make([]byte, len(f.Data())) + copy(data, f.Data()) + s.write(recvMsg{data: data}) + } + } + // The server has closed the stream without sending trailers. Record that + // the read direction is closed, and set the status appropriately. + if f.FrameHeader.Flags.Has(http2.FlagDataEndStream) { + t.closeStream(s, io.EOF, false, http2.ErrCodeNo, status.New(codes.Internal, "server closed the stream without sending trailers"), nil, true) + } +} + +func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) { + s, ok := t.getStream(f) + if !ok { + return + } + if f.ErrCode == http2.ErrCodeRefusedStream { + // The stream was unprocessed by the server. + atomic.StoreUint32(&s.unprocessed, 1) + } + statusCode, ok := http2ErrConvTab[f.ErrCode] + if !ok { + warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error %v", f.ErrCode) + statusCode = codes.Unknown + } + if statusCode == codes.Canceled { + // Our deadline was already exceeded, and that was likely the cause of + // this cancelation. Alter the status code accordingly. + if d, ok := s.ctx.Deadline(); ok && d.After(time.Now()) { + statusCode = codes.DeadlineExceeded + } + } + t.closeStream(s, io.EOF, false, http2.ErrCodeNo, status.Newf(statusCode, "stream terminated by RST_STREAM with error code: %v", f.ErrCode), nil, false) +} + +func (t *http2Client) handleSettings(f *http2.SettingsFrame, isFirst bool) { + if f.IsAck() { + return + } + var maxStreams *uint32 + var ss []http2.Setting + var updateFuncs []func() + f.ForeachSetting(func(s http2.Setting) error { + switch s.ID { + case http2.SettingMaxConcurrentStreams: + maxStreams = new(uint32) + *maxStreams = s.Val + case http2.SettingMaxHeaderListSize: + updateFuncs = append(updateFuncs, func() { + t.maxSendHeaderListSize = new(uint32) + *t.maxSendHeaderListSize = s.Val + }) + default: + ss = append(ss, s) + } + return nil + }) + if isFirst && maxStreams == nil { + maxStreams = new(uint32) + *maxStreams = math.MaxUint32 + } + sf := &incomingSettings{ + ss: ss, + } + if maxStreams != nil { + updateStreamQuota := func() { + delta := int64(*maxStreams) - int64(t.maxConcurrentStreams) + t.maxConcurrentStreams = *maxStreams + t.streamQuota += delta + if delta > 0 && t.waitingStreams > 0 { + close(t.streamsQuotaAvailable) // wake all of them up. + t.streamsQuotaAvailable = make(chan struct{}, 1) + } + } + updateFuncs = append(updateFuncs, updateStreamQuota) + } + t.controlBuf.executeAndPut(func(interface{}) bool { + for _, f := range updateFuncs { + f() + } + return true + }, sf) +} + +func (t *http2Client) handlePing(f *http2.PingFrame) { + if f.IsAck() { + // Maybe it's a BDP ping. + if t.bdpEst != nil { + t.bdpEst.calculate(f.Data) + } + return + } + pingAck := &ping{ack: true} + copy(pingAck.data[:], f.Data[:]) + t.controlBuf.put(pingAck) +} + +func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) { + t.mu.Lock() + if t.state == closing { + t.mu.Unlock() + return + } + if f.ErrCode == http2.ErrCodeEnhanceYourCalm { + infof("Client received GoAway with http2.ErrCodeEnhanceYourCalm.") + } + id := f.LastStreamID + if id > 0 && id%2 != 1 { + t.mu.Unlock() + t.Close() + return + } + // A client can receive multiple GoAways from the server (see + // https://github.com/grpc/grpc-go/issues/1387). The idea is that the first + // GoAway will be sent with an ID of MaxInt32 and the second GoAway will be + // sent after an RTT delay with the ID of the last stream the server will + // process. + // + // Therefore, when we get the first GoAway we don't necessarily close any + // streams. While in case of second GoAway we close all streams created after + // the GoAwayId. This way streams that were in-flight while the GoAway from + // server was being sent don't get killed. + select { + case <-t.goAway: // t.goAway has been closed (i.e.,multiple GoAways). + // If there are multiple GoAways the first one should always have an ID greater than the following ones. + if id > t.prevGoAwayID { + t.mu.Unlock() + t.Close() + return + } + default: + t.setGoAwayReason(f) + close(t.goAway) + t.state = draining + t.controlBuf.put(&incomingGoAway{}) + + // This has to be a new goroutine because we're still using the current goroutine to read in the transport. + t.onGoAway(t.goAwayReason) + } + // All streams with IDs greater than the GoAwayId + // and smaller than the previous GoAway ID should be killed. + upperLimit := t.prevGoAwayID + if upperLimit == 0 { // This is the first GoAway Frame. + upperLimit = math.MaxUint32 // Kill all streams after the GoAway ID. + } + for streamID, stream := range t.activeStreams { + if streamID > id && streamID <= upperLimit { + // The stream was unprocessed by the server. + atomic.StoreUint32(&stream.unprocessed, 1) + t.closeStream(stream, errStreamDrain, false, http2.ErrCodeNo, statusGoAway, nil, false) + } + } + t.prevGoAwayID = id + active := len(t.activeStreams) + t.mu.Unlock() + if active == 0 { + t.Close() + } +} + +// setGoAwayReason sets the value of t.goAwayReason based +// on the GoAway frame received. +// It expects a lock on transport's mutext to be held by +// the caller. +func (t *http2Client) setGoAwayReason(f *http2.GoAwayFrame) { + t.goAwayReason = GoAwayNoReason + switch f.ErrCode { + case http2.ErrCodeEnhanceYourCalm: + if string(f.DebugData()) == "too_many_pings" { + t.goAwayReason = GoAwayTooManyPings + } + } +} + +func (t *http2Client) GetGoAwayReason() GoAwayReason { + t.mu.Lock() + defer t.mu.Unlock() + return t.goAwayReason +} + +func (t *http2Client) handleWindowUpdate(f *http2.WindowUpdateFrame) { + t.controlBuf.put(&incomingWindowUpdate{ + streamID: f.Header().StreamID, + increment: f.Increment, + }) +} + +// operateHeaders takes action on the decoded headers. +func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { + s, ok := t.getStream(frame) + if !ok { + return + } + atomic.StoreUint32(&s.bytesReceived, 1) + var state decodeState + if err := state.decodeHeader(frame); err != nil { + t.closeStream(s, err, true, http2.ErrCodeProtocol, status.New(codes.Internal, err.Error()), nil, false) + // Something wrong. Stops reading even when there is remaining. + return + } + + endStream := frame.StreamEnded() + var isHeader bool + defer func() { + if t.statsHandler != nil { + if isHeader { + inHeader := &stats.InHeader{ + Client: true, + WireLength: int(frame.Header().Length), + } + t.statsHandler.HandleRPC(s.ctx, inHeader) + } else { + inTrailer := &stats.InTrailer{ + Client: true, + WireLength: int(frame.Header().Length), + } + t.statsHandler.HandleRPC(s.ctx, inTrailer) + } + } + }() + // If headers haven't been received yet. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + if !endStream { + // Headers frame is not actually a trailers-only frame. + isHeader = true + // These values can be set without any synchronization because + // stream goroutine will read it only after seeing a closed + // headerChan which we'll close after setting this. + s.recvCompress = state.encoding + if len(state.mdata) > 0 { + s.header = state.mdata + } + } else { + s.noHeaders = true + } + close(s.headerChan) + } + if !endStream { + return + } + // if client received END_STREAM from server while stream was still active, send RST_STREAM + rst := s.getState() == streamActive + t.closeStream(s, io.EOF, rst, http2.ErrCodeNo, state.status(), state.mdata, true) +} + +// reader runs as a separate goroutine in charge of reading data from network +// connection. +// +// TODO(zhaoq): currently one reader per transport. Investigate whether this is +// optimal. +// TODO(zhaoq): Check the validity of the incoming frame sequence. +func (t *http2Client) reader() { + defer close(t.readerDone) + // Check the validity of server preface. + frame, err := t.framer.fr.ReadFrame() + if err != nil { + t.Close() // this kicks off resetTransport, so must be last before return + return + } + t.conn.SetReadDeadline(time.Time{}) // reset deadline once we get the settings frame (we didn't time out, yay!) + if t.keepaliveEnabled { + atomic.CompareAndSwapUint32(&t.activity, 0, 1) + } + sf, ok := frame.(*http2.SettingsFrame) + if !ok { + t.Close() // this kicks off resetTransport, so must be last before return + return + } + t.onSuccess() + t.handleSettings(sf, true) + + // loop to keep reading incoming messages on this transport. + for { + frame, err := t.framer.fr.ReadFrame() + if t.keepaliveEnabled { + atomic.CompareAndSwapUint32(&t.activity, 0, 1) + } + if err != nil { + // Abort an active stream if the http2.Framer returns a + // http2.StreamError. This can happen only if the server's response + // is malformed http2. + if se, ok := err.(http2.StreamError); ok { + t.mu.Lock() + s := t.activeStreams[se.StreamID] + t.mu.Unlock() + if s != nil { + // use error detail to provide better err message + code := http2ErrConvTab[se.Code] + msg := t.framer.fr.ErrorDetail().Error() + t.closeStream(s, status.Error(code, msg), true, http2.ErrCodeProtocol, status.New(code, msg), nil, false) + } + continue + } else { + // Transport error. + t.Close() + return + } + } + switch frame := frame.(type) { + case *http2.MetaHeadersFrame: + t.operateHeaders(frame) + case *http2.DataFrame: + t.handleData(frame) + case *http2.RSTStreamFrame: + t.handleRSTStream(frame) + case *http2.SettingsFrame: + t.handleSettings(frame, false) + case *http2.PingFrame: + t.handlePing(frame) + case *http2.GoAwayFrame: + t.handleGoAway(frame) + case *http2.WindowUpdateFrame: + t.handleWindowUpdate(frame) + default: + errorf("transport: http2Client.reader got unhandled frame type %v.", frame) + } + } +} + +// keepalive running in a separate goroutune makes sure the connection is alive by sending pings. +func (t *http2Client) keepalive() { + p := &ping{data: [8]byte{}} + timer := time.NewTimer(t.kp.Time) + for { + select { + case <-timer.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + timer.Reset(t.kp.Time) + continue + } + // Check if keepalive should go dormant. + t.mu.Lock() + if len(t.activeStreams) < 1 && !t.kp.PermitWithoutStream { + // Make awakenKeepalive writable. + <-t.awakenKeepalive + t.mu.Unlock() + select { + case <-t.awakenKeepalive: + // If the control gets here a ping has been sent + // need to reset the timer with keepalive.Timeout. + case <-t.ctx.Done(): + return + } + } else { + t.mu.Unlock() + if channelz.IsOn() { + atomic.AddInt64(&t.czData.kpCount, 1) + } + // Send ping. + t.controlBuf.put(p) + } + + // By the time control gets here a ping has been sent one way or the other. + timer.Reset(t.kp.Timeout) + select { + case <-timer.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + timer.Reset(t.kp.Time) + continue + } + t.Close() + return + case <-t.ctx.Done(): + if !timer.Stop() { + <-timer.C + } + return + } + case <-t.ctx.Done(): + if !timer.Stop() { + <-timer.C + } + return + } + } +} + +func (t *http2Client) Error() <-chan struct{} { + return t.ctx.Done() +} + +func (t *http2Client) GoAway() <-chan struct{} { + return t.goAway +} + +func (t *http2Client) ChannelzMetric() *channelz.SocketInternalMetric { + s := channelz.SocketInternalMetric{ + StreamsStarted: atomic.LoadInt64(&t.czData.streamsStarted), + StreamsSucceeded: atomic.LoadInt64(&t.czData.streamsSucceeded), + StreamsFailed: atomic.LoadInt64(&t.czData.streamsFailed), + MessagesSent: atomic.LoadInt64(&t.czData.msgSent), + MessagesReceived: atomic.LoadInt64(&t.czData.msgRecv), + KeepAlivesSent: atomic.LoadInt64(&t.czData.kpCount), + LastLocalStreamCreatedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastStreamCreatedTime)), + LastMessageSentTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgSentTime)), + LastMessageReceivedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgRecvTime)), + LocalFlowControlWindow: int64(t.fc.getSize()), + SocketOptions: channelz.GetSocketOption(t.conn), + LocalAddr: t.localAddr, + RemoteAddr: t.remoteAddr, + // RemoteName : + } + if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok { + s.Security = au.GetSecurityValue() + } + s.RemoteFlowControlWindow = t.getOutFlowWindow() + return &s +} + +func (t *http2Client) IncrMsgSent() { + atomic.AddInt64(&t.czData.msgSent, 1) + atomic.StoreInt64(&t.czData.lastMsgSentTime, time.Now().UnixNano()) +} + +func (t *http2Client) IncrMsgRecv() { + atomic.AddInt64(&t.czData.msgRecv, 1) + atomic.StoreInt64(&t.czData.lastMsgRecvTime, time.Now().UnixNano()) +} + +func (t *http2Client) getOutFlowWindow() int64 { + resp := make(chan uint32, 1) + timer := time.NewTimer(time.Second) + defer timer.Stop() + t.controlBuf.put(&outFlowControlSizeRequest{resp}) + select { + case sz := <-resp: + return int64(sz) + case <-t.ctxDone: + return -1 + case <-timer.C: + return -2 + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go new file mode 100644 index 00000000..df274039 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -0,0 +1,1180 @@ +/* + * + * Copyright 2014 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 transport + +import ( + "bytes" + "context" + "errors" + "fmt" + "io" + "math" + "net" + "strconv" + "sync" + "sync/atomic" + "time" + + "github.com/golang/protobuf/proto" + "golang.org/x/net/http2" + "golang.org/x/net/http2/hpack" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +var ( + // ErrIllegalHeaderWrite indicates that setting header is illegal because of + // the stream's state. + ErrIllegalHeaderWrite = errors.New("transport: the stream is done or WriteHeader was already called") + // ErrHeaderListSizeLimitViolation indicates that the header list size is larger + // than the limit set by peer. + ErrHeaderListSizeLimitViolation = errors.New("transport: trying to send header list size larger than the limit set by peer") +) + +// http2Server implements the ServerTransport interface with HTTP2. +type http2Server struct { + ctx context.Context + ctxDone <-chan struct{} // Cache the context.Done() chan + cancel context.CancelFunc + conn net.Conn + loopy *loopyWriter + readerDone chan struct{} // sync point to enable testing. + writerDone chan struct{} // sync point to enable testing. + remoteAddr net.Addr + localAddr net.Addr + maxStreamID uint32 // max stream ID ever seen + authInfo credentials.AuthInfo // auth info about the connection + inTapHandle tap.ServerInHandle + framer *framer + // The max number of concurrent streams. + maxStreams uint32 + // controlBuf delivers all the control related tasks (e.g., window + // updates, reset streams, and various settings) to the controller. + controlBuf *controlBuffer + fc *trInFlow + stats stats.Handler + // Flag to keep track of reading activity on transport. + // 1 is true and 0 is false. + activity uint32 // Accessed atomically. + // Keepalive and max-age parameters for the server. + kp keepalive.ServerParameters + + // Keepalive enforcement policy. + kep keepalive.EnforcementPolicy + // The time instance last ping was received. + lastPingAt time.Time + // Number of times the client has violated keepalive ping policy so far. + pingStrikes uint8 + // Flag to signify that number of ping strikes should be reset to 0. + // This is set whenever data or header frames are sent. + // 1 means yes. + resetPingStrikes uint32 // Accessed atomically. + initialWindowSize int32 + bdpEst *bdpEstimator + maxSendHeaderListSize *uint32 + + mu sync.Mutex // guard the following + + // drainChan is initialized when drain(...) is called the first time. + // After which the server writes out the first GoAway(with ID 2^31-1) frame. + // Then an independent goroutine will be launched to later send the second GoAway. + // During this time we don't want to write another first GoAway(with ID 2^31 -1) frame. + // Thus call to drain(...) will be a no-op if drainChan is already initialized since draining is + // already underway. + drainChan chan struct{} + state transportState + activeStreams map[uint32]*Stream + // idle is the time instant when the connection went idle. + // This is either the beginning of the connection or when the number of + // RPCs go down to 0. + // When the connection is busy, this value is set to 0. + idle time.Time + + // Fields below are for channelz metric collection. + channelzID int64 // channelz unique identification number + czData *channelzData +} + +// newHTTP2Server constructs a ServerTransport based on HTTP2. ConnectionError is +// returned if something goes wrong. +func newHTTP2Server(conn net.Conn, config *ServerConfig) (_ ServerTransport, err error) { + writeBufSize := config.WriteBufferSize + readBufSize := config.ReadBufferSize + maxHeaderListSize := defaultServerMaxHeaderListSize + if config.MaxHeaderListSize != nil { + maxHeaderListSize = *config.MaxHeaderListSize + } + framer := newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize) + // Send initial settings as connection preface to client. + var isettings []http2.Setting + // TODO(zhaoq): Have a better way to signal "no limit" because 0 is + // permitted in the HTTP2 spec. + maxStreams := config.MaxStreams + if maxStreams == 0 { + maxStreams = math.MaxUint32 + } else { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingMaxConcurrentStreams, + Val: maxStreams, + }) + } + dynamicWindow := true + iwz := int32(initialWindowSize) + if config.InitialWindowSize >= defaultWindowSize { + iwz = config.InitialWindowSize + dynamicWindow = false + } + icwz := int32(initialWindowSize) + if config.InitialConnWindowSize >= defaultWindowSize { + icwz = config.InitialConnWindowSize + dynamicWindow = false + } + if iwz != defaultWindowSize { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingInitialWindowSize, + Val: uint32(iwz)}) + } + if config.MaxHeaderListSize != nil { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingMaxHeaderListSize, + Val: *config.MaxHeaderListSize, + }) + } + if err := framer.fr.WriteSettings(isettings...); err != nil { + return nil, connectionErrorf(false, err, "transport: %v", err) + } + // Adjust the connection flow control window if needed. + if delta := uint32(icwz - defaultWindowSize); delta > 0 { + if err := framer.fr.WriteWindowUpdate(0, delta); err != nil { + return nil, connectionErrorf(false, err, "transport: %v", err) + } + } + kp := config.KeepaliveParams + if kp.MaxConnectionIdle == 0 { + kp.MaxConnectionIdle = defaultMaxConnectionIdle + } + if kp.MaxConnectionAge == 0 { + kp.MaxConnectionAge = defaultMaxConnectionAge + } + // Add a jitter to MaxConnectionAge. + kp.MaxConnectionAge += getJitter(kp.MaxConnectionAge) + if kp.MaxConnectionAgeGrace == 0 { + kp.MaxConnectionAgeGrace = defaultMaxConnectionAgeGrace + } + if kp.Time == 0 { + kp.Time = defaultServerKeepaliveTime + } + if kp.Timeout == 0 { + kp.Timeout = defaultServerKeepaliveTimeout + } + kep := config.KeepalivePolicy + if kep.MinTime == 0 { + kep.MinTime = defaultKeepalivePolicyMinTime + } + ctx, cancel := context.WithCancel(context.Background()) + t := &http2Server{ + ctx: ctx, + cancel: cancel, + ctxDone: ctx.Done(), + conn: conn, + remoteAddr: conn.RemoteAddr(), + localAddr: conn.LocalAddr(), + authInfo: config.AuthInfo, + framer: framer, + readerDone: make(chan struct{}), + writerDone: make(chan struct{}), + maxStreams: maxStreams, + inTapHandle: config.InTapHandle, + fc: &trInFlow{limit: uint32(icwz)}, + state: reachable, + activeStreams: make(map[uint32]*Stream), + stats: config.StatsHandler, + kp: kp, + idle: time.Now(), + kep: kep, + initialWindowSize: iwz, + czData: new(channelzData), + } + t.controlBuf = newControlBuffer(t.ctxDone) + if dynamicWindow { + t.bdpEst = &bdpEstimator{ + bdp: initialWindowSize, + updateFlowControl: t.updateFlowControl, + } + } + if t.stats != nil { + t.ctx = t.stats.TagConn(t.ctx, &stats.ConnTagInfo{ + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + }) + connBegin := &stats.ConnBegin{} + t.stats.HandleConn(t.ctx, connBegin) + } + if channelz.IsOn() { + t.channelzID = channelz.RegisterNormalSocket(t, config.ChannelzParentID, fmt.Sprintf("%s -> %s", t.remoteAddr, t.localAddr)) + } + t.framer.writer.Flush() + + defer func() { + if err != nil { + t.Close() + } + }() + + // Check the validity of client preface. + preface := make([]byte, len(clientPreface)) + if _, err := io.ReadFull(t.conn, preface); err != nil { + return nil, connectionErrorf(false, err, "transport: http2Server.HandleStreams failed to receive the preface from client: %v", err) + } + if !bytes.Equal(preface, clientPreface) { + return nil, connectionErrorf(false, nil, "transport: http2Server.HandleStreams received bogus greeting from client: %q", preface) + } + + frame, err := t.framer.fr.ReadFrame() + if err == io.EOF || err == io.ErrUnexpectedEOF { + return nil, err + } + if err != nil { + return nil, connectionErrorf(false, err, "transport: http2Server.HandleStreams failed to read initial settings frame: %v", err) + } + atomic.StoreUint32(&t.activity, 1) + sf, ok := frame.(*http2.SettingsFrame) + if !ok { + return nil, connectionErrorf(false, nil, "transport: http2Server.HandleStreams saw invalid preface type %T from client", frame) + } + t.handleSettings(sf) + + go func() { + t.loopy = newLoopyWriter(serverSide, t.framer, t.controlBuf, t.bdpEst) + t.loopy.ssGoAwayHandler = t.outgoingGoAwayHandler + if err := t.loopy.run(); err != nil { + errorf("transport: loopyWriter.run returning. Err: %v", err) + } + t.conn.Close() + close(t.writerDone) + }() + go t.keepalive() + return t, nil +} + +// operateHeader takes action on the decoded headers. +func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream), traceCtx func(context.Context, string) context.Context) (fatal bool) { + streamID := frame.Header().StreamID + state := decodeState{serverSide: true} + if err := state.decodeHeader(frame); err != nil { + if se, ok := status.FromError(err); ok { + t.controlBuf.put(&cleanupStream{ + streamID: streamID, + rst: true, + rstCode: statusCodeConvTab[se.Code()], + onWrite: func() {}, + }) + } + return false + } + + buf := newRecvBuffer() + s := &Stream{ + id: streamID, + st: t, + buf: buf, + fc: &inFlow{limit: uint32(t.initialWindowSize)}, + recvCompress: state.encoding, + method: state.method, + contentSubtype: state.contentSubtype, + } + if frame.StreamEnded() { + // s is just created by the caller. No lock needed. + s.state = streamReadDone + } + if state.timeoutSet { + s.ctx, s.cancel = context.WithTimeout(t.ctx, state.timeout) + } else { + s.ctx, s.cancel = context.WithCancel(t.ctx) + } + pr := &peer.Peer{ + Addr: t.remoteAddr, + } + // Attach Auth info if there is any. + if t.authInfo != nil { + pr.AuthInfo = t.authInfo + } + s.ctx = peer.NewContext(s.ctx, pr) + // Attach the received metadata to the context. + if len(state.mdata) > 0 { + s.ctx = metadata.NewIncomingContext(s.ctx, state.mdata) + } + if state.statsTags != nil { + s.ctx = stats.SetIncomingTags(s.ctx, state.statsTags) + } + if state.statsTrace != nil { + s.ctx = stats.SetIncomingTrace(s.ctx, state.statsTrace) + } + if t.inTapHandle != nil { + var err error + info := &tap.Info{ + FullMethodName: state.method, + } + s.ctx, err = t.inTapHandle(s.ctx, info) + if err != nil { + warningf("transport: http2Server.operateHeaders got an error from InTapHandle: %v", err) + t.controlBuf.put(&cleanupStream{ + streamID: s.id, + rst: true, + rstCode: http2.ErrCodeRefusedStream, + onWrite: func() {}, + }) + return false + } + } + t.mu.Lock() + if t.state != reachable { + t.mu.Unlock() + return false + } + if uint32(len(t.activeStreams)) >= t.maxStreams { + t.mu.Unlock() + t.controlBuf.put(&cleanupStream{ + streamID: streamID, + rst: true, + rstCode: http2.ErrCodeRefusedStream, + onWrite: func() {}, + }) + return false + } + if streamID%2 != 1 || streamID <= t.maxStreamID { + t.mu.Unlock() + // illegal gRPC stream id. + errorf("transport: http2Server.HandleStreams received an illegal stream id: %v", streamID) + return true + } + t.maxStreamID = streamID + t.activeStreams[streamID] = s + if len(t.activeStreams) == 1 { + t.idle = time.Time{} + } + t.mu.Unlock() + if channelz.IsOn() { + atomic.AddInt64(&t.czData.streamsStarted, 1) + atomic.StoreInt64(&t.czData.lastStreamCreatedTime, time.Now().UnixNano()) + } + s.requestRead = func(n int) { + t.adjustWindow(s, uint32(n)) + } + s.ctx = traceCtx(s.ctx, s.method) + if t.stats != nil { + s.ctx = t.stats.TagRPC(s.ctx, &stats.RPCTagInfo{FullMethodName: s.method}) + inHeader := &stats.InHeader{ + FullMethod: s.method, + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + Compression: s.recvCompress, + WireLength: int(frame.Header().Length), + } + t.stats.HandleRPC(s.ctx, inHeader) + } + s.ctxDone = s.ctx.Done() + s.wq = newWriteQuota(defaultWriteQuota, s.ctxDone) + s.trReader = &transportReader{ + reader: &recvBufferReader{ + ctx: s.ctx, + ctxDone: s.ctxDone, + recv: s.buf, + }, + windowHandler: func(n int) { + t.updateWindow(s, uint32(n)) + }, + } + // Register the stream with loopy. + t.controlBuf.put(®isterStream{ + streamID: s.id, + wq: s.wq, + }) + handle(s) + return false +} + +// HandleStreams receives incoming streams using the given handler. This is +// typically run in a separate goroutine. +// traceCtx attaches trace to ctx and returns the new context. +func (t *http2Server) HandleStreams(handle func(*Stream), traceCtx func(context.Context, string) context.Context) { + defer close(t.readerDone) + for { + frame, err := t.framer.fr.ReadFrame() + atomic.StoreUint32(&t.activity, 1) + if err != nil { + if se, ok := err.(http2.StreamError); ok { + warningf("transport: http2Server.HandleStreams encountered http2.StreamError: %v", se) + t.mu.Lock() + s := t.activeStreams[se.StreamID] + t.mu.Unlock() + if s != nil { + t.closeStream(s, true, se.Code, nil, false) + } else { + t.controlBuf.put(&cleanupStream{ + streamID: se.StreamID, + rst: true, + rstCode: se.Code, + onWrite: func() {}, + }) + } + continue + } + if err == io.EOF || err == io.ErrUnexpectedEOF { + t.Close() + return + } + warningf("transport: http2Server.HandleStreams failed to read frame: %v", err) + t.Close() + return + } + switch frame := frame.(type) { + case *http2.MetaHeadersFrame: + if t.operateHeaders(frame, handle, traceCtx) { + t.Close() + break + } + case *http2.DataFrame: + t.handleData(frame) + case *http2.RSTStreamFrame: + t.handleRSTStream(frame) + case *http2.SettingsFrame: + t.handleSettings(frame) + case *http2.PingFrame: + t.handlePing(frame) + case *http2.WindowUpdateFrame: + t.handleWindowUpdate(frame) + case *http2.GoAwayFrame: + // TODO: Handle GoAway from the client appropriately. + default: + errorf("transport: http2Server.HandleStreams found unhandled frame type %v.", frame) + } + } +} + +func (t *http2Server) getStream(f http2.Frame) (*Stream, bool) { + t.mu.Lock() + defer t.mu.Unlock() + if t.activeStreams == nil { + // The transport is closing. + return nil, false + } + s, ok := t.activeStreams[f.Header().StreamID] + if !ok { + // The stream is already done. + return nil, false + } + return s, true +} + +// adjustWindow sends out extra window update over the initial window size +// of stream if the application is requesting data larger in size than +// the window. +func (t *http2Server) adjustWindow(s *Stream, n uint32) { + if w := s.fc.maybeAdjust(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } + +} + +// updateWindow adjusts the inbound quota for the stream and the transport. +// Window updates will deliver to the controller for sending when +// the cumulative quota exceeds the corresponding threshold. +func (t *http2Server) updateWindow(s *Stream, n uint32) { + if w := s.fc.onRead(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, + increment: w, + }) + } +} + +// updateFlowControl updates the incoming flow control windows +// for the transport and the stream based on the current bdp +// estimation. +func (t *http2Server) updateFlowControl(n uint32) { + t.mu.Lock() + for _, s := range t.activeStreams { + s.fc.newLimit(n) + } + t.initialWindowSize = int32(n) + t.mu.Unlock() + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: t.fc.newLimit(n), + }) + t.controlBuf.put(&outgoingSettings{ + ss: []http2.Setting{ + { + ID: http2.SettingInitialWindowSize, + Val: n, + }, + }, + }) + +} + +func (t *http2Server) handleData(f *http2.DataFrame) { + size := f.Header().Length + var sendBDPPing bool + if t.bdpEst != nil { + sendBDPPing = t.bdpEst.add(size) + } + // Decouple connection's flow control from application's read. + // An update on connection's flow control should not depend on + // whether user application has read the data or not. Such a + // restriction is already imposed on the stream's flow control, + // and therefore the sender will be blocked anyways. + // Decoupling the connection flow control will prevent other + // active(fast) streams from starving in presence of slow or + // inactive streams. + if w := t.fc.onData(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + if sendBDPPing { + // Avoid excessive ping detection (e.g. in an L7 proxy) + // by sending a window update prior to the BDP ping. + if w := t.fc.reset(); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + t.controlBuf.put(bdpPing) + } + // Select the right stream to dispatch. + s, ok := t.getStream(f) + if !ok { + return + } + if size > 0 { + if err := s.fc.onData(size); err != nil { + t.closeStream(s, true, http2.ErrCodeFlowControl, nil, false) + return + } + if f.Header().Flags.Has(http2.FlagDataPadded) { + if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + } + } + // TODO(bradfitz, zhaoq): A copy is required here because there is no + // guarantee f.Data() is consumed before the arrival of next frame. + // Can this copy be eliminated? + if len(f.Data()) > 0 { + data := make([]byte, len(f.Data())) + copy(data, f.Data()) + s.write(recvMsg{data: data}) + } + } + if f.Header().Flags.Has(http2.FlagDataEndStream) { + // Received the end of stream from the client. + s.compareAndSwapState(streamActive, streamReadDone) + s.write(recvMsg{err: io.EOF}) + } +} + +func (t *http2Server) handleRSTStream(f *http2.RSTStreamFrame) { + s, ok := t.getStream(f) + if !ok { + return + } + t.closeStream(s, false, 0, nil, false) +} + +func (t *http2Server) handleSettings(f *http2.SettingsFrame) { + if f.IsAck() { + return + } + var ss []http2.Setting + var updateFuncs []func() + f.ForeachSetting(func(s http2.Setting) error { + switch s.ID { + case http2.SettingMaxHeaderListSize: + updateFuncs = append(updateFuncs, func() { + t.maxSendHeaderListSize = new(uint32) + *t.maxSendHeaderListSize = s.Val + }) + default: + ss = append(ss, s) + } + return nil + }) + t.controlBuf.executeAndPut(func(interface{}) bool { + for _, f := range updateFuncs { + f() + } + return true + }, &incomingSettings{ + ss: ss, + }) +} + +const ( + maxPingStrikes = 2 + defaultPingTimeout = 2 * time.Hour +) + +func (t *http2Server) handlePing(f *http2.PingFrame) { + if f.IsAck() { + if f.Data == goAwayPing.data && t.drainChan != nil { + close(t.drainChan) + return + } + // Maybe it's a BDP ping. + if t.bdpEst != nil { + t.bdpEst.calculate(f.Data) + } + return + } + pingAck := &ping{ack: true} + copy(pingAck.data[:], f.Data[:]) + t.controlBuf.put(pingAck) + + now := time.Now() + defer func() { + t.lastPingAt = now + }() + // A reset ping strikes means that we don't need to check for policy + // violation for this ping and the pingStrikes counter should be set + // to 0. + if atomic.CompareAndSwapUint32(&t.resetPingStrikes, 1, 0) { + t.pingStrikes = 0 + return + } + t.mu.Lock() + ns := len(t.activeStreams) + t.mu.Unlock() + if ns < 1 && !t.kep.PermitWithoutStream { + // Keepalive shouldn't be active thus, this new ping should + // have come after at least defaultPingTimeout. + if t.lastPingAt.Add(defaultPingTimeout).After(now) { + t.pingStrikes++ + } + } else { + // Check if keepalive policy is respected. + if t.lastPingAt.Add(t.kep.MinTime).After(now) { + t.pingStrikes++ + } + } + + if t.pingStrikes > maxPingStrikes { + // Send goaway and close the connection. + errorf("transport: Got too many pings from the client, closing the connection.") + t.controlBuf.put(&goAway{code: http2.ErrCodeEnhanceYourCalm, debugData: []byte("too_many_pings"), closeConn: true}) + } +} + +func (t *http2Server) handleWindowUpdate(f *http2.WindowUpdateFrame) { + t.controlBuf.put(&incomingWindowUpdate{ + streamID: f.Header().StreamID, + increment: f.Increment, + }) +} + +func appendHeaderFieldsFromMD(headerFields []hpack.HeaderField, md metadata.MD) []hpack.HeaderField { + for k, vv := range md { + if isReservedHeader(k) { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + return headerFields +} + +func (t *http2Server) checkForHeaderListSize(it interface{}) bool { + if t.maxSendHeaderListSize == nil { + return true + } + hdrFrame := it.(*headerFrame) + var sz int64 + for _, f := range hdrFrame.hf { + if sz += int64(f.Size()); sz > int64(*t.maxSendHeaderListSize) { + errorf("header list size to send violates the maximum size (%d bytes) set by client", *t.maxSendHeaderListSize) + return false + } + } + return true +} + +// WriteHeader sends the header metedata md back to the client. +func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error { + if s.updateHeaderSent() || s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + if md.Len() > 0 { + if s.header.Len() > 0 { + s.header = metadata.Join(s.header, md) + } else { + s.header = md + } + } + if err := t.writeHeaderLocked(s); err != nil { + s.hdrMu.Unlock() + return err + } + s.hdrMu.Unlock() + return nil +} + +func (t *http2Server) writeHeaderLocked(s *Stream) error { + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + headerFields := make([]hpack.HeaderField, 0, 2) // at least :status, content-type will be there if none else. + headerFields = append(headerFields, hpack.HeaderField{Name: ":status", Value: "200"}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(s.contentSubtype)}) + if s.sendCompress != "" { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: s.sendCompress}) + } + headerFields = appendHeaderFieldsFromMD(headerFields, s.header) + success, err := t.controlBuf.executeAndPut(t.checkForHeaderListSize, &headerFrame{ + streamID: s.id, + hf: headerFields, + endStream: false, + onWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + }) + if !success { + if err != nil { + return err + } + t.closeStream(s, true, http2.ErrCodeInternal, nil, false) + return ErrHeaderListSizeLimitViolation + } + if t.stats != nil { + // Note: WireLength is not set in outHeader. + // TODO(mmukhi): Revisit this later, if needed. + outHeader := &stats.OutHeader{} + t.stats.HandleRPC(s.Context(), outHeader) + } + return nil +} + +// WriteStatus sends stream status to the client and terminates the stream. +// There is no further I/O operations being able to perform on this stream. +// TODO(zhaoq): Now it indicates the end of entire stream. Revisit if early +// OK is adopted. +func (t *http2Server) WriteStatus(s *Stream, st *status.Status) error { + if s.getState() == streamDone { + return nil + } + s.hdrMu.Lock() + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + headerFields := make([]hpack.HeaderField, 0, 2) // grpc-status and grpc-message will be there if none else. + if !s.updateHeaderSent() { // No headers have been sent. + if len(s.header) > 0 { // Send a separate header frame. + if err := t.writeHeaderLocked(s); err != nil { + s.hdrMu.Unlock() + return err + } + } else { // Send a trailer only response. + headerFields = append(headerFields, hpack.HeaderField{Name: ":status", Value: "200"}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(s.contentSubtype)}) + } + } + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-status", Value: strconv.Itoa(int(st.Code()))}) + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-message", Value: encodeGrpcMessage(st.Message())}) + + if p := st.Proto(); p != nil && len(p.Details) > 0 { + stBytes, err := proto.Marshal(p) + if err != nil { + // TODO: return error instead, when callers are able to handle it. + grpclog.Errorf("transport: failed to marshal rpc status: %v, error: %v", p, err) + } else { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-status-details-bin", Value: encodeBinHeader(stBytes)}) + } + } + + // Attach the trailer metadata. + headerFields = appendHeaderFieldsFromMD(headerFields, s.trailer) + trailingHeader := &headerFrame{ + streamID: s.id, + hf: headerFields, + endStream: true, + onWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + } + s.hdrMu.Unlock() + success, err := t.controlBuf.execute(t.checkForHeaderListSize, trailingHeader) + if !success { + if err != nil { + return err + } + t.closeStream(s, true, http2.ErrCodeInternal, nil, false) + return ErrHeaderListSizeLimitViolation + } + t.closeStream(s, false, 0, trailingHeader, true) + if t.stats != nil { + t.stats.HandleRPC(s.Context(), &stats.OutTrailer{}) + } + return nil +} + +// Write converts the data into HTTP2 data frame and sends it out. Non-nil error +// is returns if it fails (e.g., framing error, transport error). +func (t *http2Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + if !s.isHeaderSent() { // Headers haven't been written yet. + if err := t.WriteHeader(s, nil); err != nil { + // TODO(mmukhi, dfawley): Make sure this is the right code to return. + return status.Errorf(codes.Internal, "transport: %v", err) + } + } else { + // Writing headers checks for this condition. + if s.getState() == streamDone { + // TODO(mmukhi, dfawley): Should the server write also return io.EOF? + s.cancel() + select { + case <-t.ctx.Done(): + return ErrConnClosing + default: + } + return ContextErr(s.ctx.Err()) + } + } + // Add some data to header frame so that we can equally distribute bytes across frames. + emptyLen := http2MaxFrameLen - len(hdr) + if emptyLen > len(data) { + emptyLen = len(data) + } + hdr = append(hdr, data[:emptyLen]...) + data = data[emptyLen:] + df := &dataFrame{ + streamID: s.id, + h: hdr, + d: data, + onEachWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + } + if err := s.wq.get(int32(len(hdr) + len(data))); err != nil { + select { + case <-t.ctx.Done(): + return ErrConnClosing + default: + } + return ContextErr(s.ctx.Err()) + } + return t.controlBuf.put(df) +} + +// keepalive running in a separate goroutine does the following: +// 1. Gracefully closes an idle connection after a duration of keepalive.MaxConnectionIdle. +// 2. Gracefully closes any connection after a duration of keepalive.MaxConnectionAge. +// 3. Forcibly closes a connection after an additive period of keepalive.MaxConnectionAgeGrace over keepalive.MaxConnectionAge. +// 4. Makes sure a connection is alive by sending pings with a frequency of keepalive.Time and closes a non-responsive connection +// after an additional duration of keepalive.Timeout. +func (t *http2Server) keepalive() { + p := &ping{} + var pingSent bool + maxIdle := time.NewTimer(t.kp.MaxConnectionIdle) + maxAge := time.NewTimer(t.kp.MaxConnectionAge) + keepalive := time.NewTimer(t.kp.Time) + // NOTE: All exit paths of this function should reset their + // respective timers. A failure to do so will cause the + // following clean-up to deadlock and eventually leak. + defer func() { + if !maxIdle.Stop() { + <-maxIdle.C + } + if !maxAge.Stop() { + <-maxAge.C + } + if !keepalive.Stop() { + <-keepalive.C + } + }() + for { + select { + case <-maxIdle.C: + t.mu.Lock() + idle := t.idle + if idle.IsZero() { // The connection is non-idle. + t.mu.Unlock() + maxIdle.Reset(t.kp.MaxConnectionIdle) + continue + } + val := t.kp.MaxConnectionIdle - time.Since(idle) + t.mu.Unlock() + if val <= 0 { + // The connection has been idle for a duration of keepalive.MaxConnectionIdle or more. + // Gracefully close the connection. + t.drain(http2.ErrCodeNo, []byte{}) + // Resetting the timer so that the clean-up doesn't deadlock. + maxIdle.Reset(infinity) + return + } + maxIdle.Reset(val) + case <-maxAge.C: + t.drain(http2.ErrCodeNo, []byte{}) + maxAge.Reset(t.kp.MaxConnectionAgeGrace) + select { + case <-maxAge.C: + // Close the connection after grace period. + t.Close() + // Resetting the timer so that the clean-up doesn't deadlock. + maxAge.Reset(infinity) + case <-t.ctx.Done(): + } + return + case <-keepalive.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + pingSent = false + keepalive.Reset(t.kp.Time) + continue + } + if pingSent { + t.Close() + // Resetting the timer so that the clean-up doesn't deadlock. + keepalive.Reset(infinity) + return + } + pingSent = true + if channelz.IsOn() { + atomic.AddInt64(&t.czData.kpCount, 1) + } + t.controlBuf.put(p) + keepalive.Reset(t.kp.Timeout) + case <-t.ctx.Done(): + return + } + } +} + +// Close starts shutting down the http2Server transport. +// TODO(zhaoq): Now the destruction is not blocked on any pending streams. This +// could cause some resource issue. Revisit this later. +func (t *http2Server) Close() error { + t.mu.Lock() + if t.state == closing { + t.mu.Unlock() + return errors.New("transport: Close() was already called") + } + t.state = closing + streams := t.activeStreams + t.activeStreams = nil + t.mu.Unlock() + t.controlBuf.finish() + t.cancel() + err := t.conn.Close() + if channelz.IsOn() { + channelz.RemoveEntry(t.channelzID) + } + // Cancel all active streams. + for _, s := range streams { + s.cancel() + } + if t.stats != nil { + connEnd := &stats.ConnEnd{} + t.stats.HandleConn(t.ctx, connEnd) + } + return err +} + +// closeStream clears the footprint of a stream when the stream is not needed +// any more. +func (t *http2Server) closeStream(s *Stream, rst bool, rstCode http2.ErrCode, hdr *headerFrame, eosReceived bool) { + if s.swapState(streamDone) == streamDone { + // If the stream was already done, return. + return + } + // In case stream sending and receiving are invoked in separate + // goroutines (e.g., bi-directional streaming), cancel needs to be + // called to interrupt the potential blocking on other goroutines. + s.cancel() + cleanup := &cleanupStream{ + streamID: s.id, + rst: rst, + rstCode: rstCode, + onWrite: func() { + t.mu.Lock() + if t.activeStreams != nil { + delete(t.activeStreams, s.id) + if len(t.activeStreams) == 0 { + t.idle = time.Now() + } + } + t.mu.Unlock() + if channelz.IsOn() { + if eosReceived { + atomic.AddInt64(&t.czData.streamsSucceeded, 1) + } else { + atomic.AddInt64(&t.czData.streamsFailed, 1) + } + } + }, + } + if hdr != nil { + hdr.cleanup = cleanup + t.controlBuf.put(hdr) + } else { + t.controlBuf.put(cleanup) + } +} + +func (t *http2Server) RemoteAddr() net.Addr { + return t.remoteAddr +} + +func (t *http2Server) Drain() { + t.drain(http2.ErrCodeNo, []byte{}) +} + +func (t *http2Server) drain(code http2.ErrCode, debugData []byte) { + t.mu.Lock() + defer t.mu.Unlock() + if t.drainChan != nil { + return + } + t.drainChan = make(chan struct{}) + t.controlBuf.put(&goAway{code: code, debugData: debugData, headsUp: true}) +} + +var goAwayPing = &ping{data: [8]byte{1, 6, 1, 8, 0, 3, 3, 9}} + +// Handles outgoing GoAway and returns true if loopy needs to put itself +// in draining mode. +func (t *http2Server) outgoingGoAwayHandler(g *goAway) (bool, error) { + t.mu.Lock() + if t.state == closing { // TODO(mmukhi): This seems unnecessary. + t.mu.Unlock() + // The transport is closing. + return false, ErrConnClosing + } + sid := t.maxStreamID + if !g.headsUp { + // Stop accepting more streams now. + t.state = draining + if len(t.activeStreams) == 0 { + g.closeConn = true + } + t.mu.Unlock() + if err := t.framer.fr.WriteGoAway(sid, g.code, g.debugData); err != nil { + return false, err + } + if g.closeConn { + // Abruptly close the connection following the GoAway (via + // loopywriter). But flush out what's inside the buffer first. + t.framer.writer.Flush() + return false, fmt.Errorf("transport: Connection closing") + } + return true, nil + } + t.mu.Unlock() + // For a graceful close, send out a GoAway with stream ID of MaxUInt32, + // Follow that with a ping and wait for the ack to come back or a timer + // to expire. During this time accept new streams since they might have + // originated before the GoAway reaches the client. + // After getting the ack or timer expiration send out another GoAway this + // time with an ID of the max stream server intends to process. + if err := t.framer.fr.WriteGoAway(math.MaxUint32, http2.ErrCodeNo, []byte{}); err != nil { + return false, err + } + if err := t.framer.fr.WritePing(false, goAwayPing.data); err != nil { + return false, err + } + go func() { + timer := time.NewTimer(time.Minute) + defer timer.Stop() + select { + case <-t.drainChan: + case <-timer.C: + case <-t.ctx.Done(): + return + } + t.controlBuf.put(&goAway{code: g.code, debugData: g.debugData}) + }() + return false, nil +} + +func (t *http2Server) ChannelzMetric() *channelz.SocketInternalMetric { + s := channelz.SocketInternalMetric{ + StreamsStarted: atomic.LoadInt64(&t.czData.streamsStarted), + StreamsSucceeded: atomic.LoadInt64(&t.czData.streamsSucceeded), + StreamsFailed: atomic.LoadInt64(&t.czData.streamsFailed), + MessagesSent: atomic.LoadInt64(&t.czData.msgSent), + MessagesReceived: atomic.LoadInt64(&t.czData.msgRecv), + KeepAlivesSent: atomic.LoadInt64(&t.czData.kpCount), + LastRemoteStreamCreatedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastStreamCreatedTime)), + LastMessageSentTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgSentTime)), + LastMessageReceivedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgRecvTime)), + LocalFlowControlWindow: int64(t.fc.getSize()), + SocketOptions: channelz.GetSocketOption(t.conn), + LocalAddr: t.localAddr, + RemoteAddr: t.remoteAddr, + // RemoteName : + } + if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok { + s.Security = au.GetSecurityValue() + } + s.RemoteFlowControlWindow = t.getOutFlowWindow() + return &s +} + +func (t *http2Server) IncrMsgSent() { + atomic.AddInt64(&t.czData.msgSent, 1) + atomic.StoreInt64(&t.czData.lastMsgSentTime, time.Now().UnixNano()) +} + +func (t *http2Server) IncrMsgRecv() { + atomic.AddInt64(&t.czData.msgRecv, 1) + atomic.StoreInt64(&t.czData.lastMsgRecvTime, time.Now().UnixNano()) +} + +func (t *http2Server) getOutFlowWindow() int64 { + resp := make(chan uint32) + timer := time.NewTimer(time.Second) + defer timer.Stop() + t.controlBuf.put(&outFlowControlSizeRequest{resp}) + select { + case sz := <-resp: + return int64(sz) + case <-t.ctxDone: + return -1 + case <-timer.C: + return -2 + } +} + +func getJitter(v time.Duration) time.Duration { + if v == infinity { + return 0 + } + // Generate a jitter between +/- 10% of the value. + r := int64(v / 10) + j := grpcrand.Int63n(2*r) - r + return time.Duration(j) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/http_util.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http_util.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/http_util.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http_util.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/log.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/log.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/log.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/log.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go new file mode 100644 index 00000000..4d7e8906 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -0,0 +1,736 @@ +/* + * + * Copyright 2014 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 transport defines and implements message oriented communication +// channel to complete various transactions (e.g., an RPC). It is meant for +// grpc-internal usage and is not intended to be imported directly by users. +package transport + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "sync" + "sync/atomic" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +// recvMsg represents the received msg from the transport. All transport +// protocol specific info has been removed. +type recvMsg struct { + data []byte + // nil: received some data + // io.EOF: stream is completed. data is nil. + // other non-nil error: transport failure. data is nil. + err error +} + +// recvBuffer is an unbounded channel of recvMsg structs. +// Note recvBuffer differs from controlBuffer only in that recvBuffer +// holds a channel of only recvMsg structs instead of objects implementing "item" interface. +// recvBuffer is written to much more often than +// controlBuffer and using strict recvMsg structs helps avoid allocation in "recvBuffer.put" +type recvBuffer struct { + c chan recvMsg + mu sync.Mutex + backlog []recvMsg + err error +} + +func newRecvBuffer() *recvBuffer { + b := &recvBuffer{ + c: make(chan recvMsg, 1), + } + return b +} + +func (b *recvBuffer) put(r recvMsg) { + b.mu.Lock() + if b.err != nil { + b.mu.Unlock() + // An error had occurred earlier, don't accept more + // data or errors. + return + } + b.err = r.err + if len(b.backlog) == 0 { + select { + case b.c <- r: + b.mu.Unlock() + return + default: + } + } + b.backlog = append(b.backlog, r) + b.mu.Unlock() +} + +func (b *recvBuffer) load() { + b.mu.Lock() + if len(b.backlog) > 0 { + select { + case b.c <- b.backlog[0]: + b.backlog[0] = recvMsg{} + b.backlog = b.backlog[1:] + default: + } + } + b.mu.Unlock() +} + +// get returns the channel that receives a recvMsg in the buffer. +// +// Upon receipt of a recvMsg, the caller should call load to send another +// recvMsg onto the channel if there is any. +func (b *recvBuffer) get() <-chan recvMsg { + return b.c +} + +// +// recvBufferReader implements io.Reader interface to read the data from +// recvBuffer. +type recvBufferReader struct { + ctx context.Context + ctxDone <-chan struct{} // cache of ctx.Done() (for performance). + recv *recvBuffer + last []byte // Stores the remaining data in the previous calls. + err error +} + +// Read reads the next len(p) bytes from last. If last is drained, it tries to +// read additional data from recv. It blocks if there no additional data available +// in recv. If Read returns any non-nil error, it will continue to return that error. +func (r *recvBufferReader) Read(p []byte) (n int, err error) { + if r.err != nil { + return 0, r.err + } + n, r.err = r.read(p) + return n, r.err +} + +func (r *recvBufferReader) read(p []byte) (n int, err error) { + if r.last != nil && len(r.last) > 0 { + // Read remaining data left in last call. + copied := copy(p, r.last) + r.last = r.last[copied:] + return copied, nil + } + select { + case <-r.ctxDone: + return 0, ContextErr(r.ctx.Err()) + case m := <-r.recv.get(): + r.recv.load() + if m.err != nil { + return 0, m.err + } + copied := copy(p, m.data) + r.last = m.data[copied:] + return copied, nil + } +} + +type streamState uint32 + +const ( + streamActive streamState = iota + streamWriteDone // EndStream sent + streamReadDone // EndStream received + streamDone // the entire stream is finished. +) + +// Stream represents an RPC in the transport layer. +type Stream struct { + id uint32 + st ServerTransport // nil for client side Stream + ctx context.Context // the associated context of the stream + cancel context.CancelFunc // always nil for client side Stream + done chan struct{} // closed at the end of stream to unblock writers. On the client side. + ctxDone <-chan struct{} // same as done chan but for server side. Cache of ctx.Done() (for performance) + method string // the associated RPC method of the stream + recvCompress string + sendCompress string + buf *recvBuffer + trReader io.Reader + fc *inFlow + wq *writeQuota + + // Callback to state application's intentions to read data. This + // is used to adjust flow control, if needed. + requestRead func(int) + + headerChan chan struct{} // closed to indicate the end of header metadata. + headerDone uint32 // set when headerChan is closed. Used to avoid closing headerChan multiple times. + + // hdrMu protects header and trailer metadata on the server-side. + hdrMu sync.Mutex + // On client side, header keeps the received header metadata. + // + // On server side, header keeps the header set by SetHeader(). The complete + // header will merged into this after t.WriteHeader() is called. + header metadata.MD + trailer metadata.MD // the key-value map of trailer metadata. + + noHeaders bool // set if the client never received headers (set only after the stream is done). + + // On the server-side, headerSent is atomically set to 1 when the headers are sent out. + headerSent uint32 + + state streamState + + // On client-side it is the status error received from the server. + // On server-side it is unused. + status *status.Status + + bytesReceived uint32 // indicates whether any bytes have been received on this stream + unprocessed uint32 // set if the server sends a refused stream or GOAWAY including this stream + + // contentSubtype is the content-subtype for requests. + // this must be lowercase or the behavior is undefined. + contentSubtype string +} + +// isHeaderSent is only valid on the server-side. +func (s *Stream) isHeaderSent() bool { + return atomic.LoadUint32(&s.headerSent) == 1 +} + +// updateHeaderSent updates headerSent and returns true +// if it was alreay set. It is valid only on server-side. +func (s *Stream) updateHeaderSent() bool { + return atomic.SwapUint32(&s.headerSent, 1) == 1 +} + +func (s *Stream) swapState(st streamState) streamState { + return streamState(atomic.SwapUint32((*uint32)(&s.state), uint32(st))) +} + +func (s *Stream) compareAndSwapState(oldState, newState streamState) bool { + return atomic.CompareAndSwapUint32((*uint32)(&s.state), uint32(oldState), uint32(newState)) +} + +func (s *Stream) getState() streamState { + return streamState(atomic.LoadUint32((*uint32)(&s.state))) +} + +func (s *Stream) waitOnHeader() error { + if s.headerChan == nil { + // On the server headerChan is always nil since a stream originates + // only after having received headers. + return nil + } + select { + case <-s.ctx.Done(): + return ContextErr(s.ctx.Err()) + case <-s.headerChan: + return nil + } +} + +// RecvCompress returns the compression algorithm applied to the inbound +// message. It is empty string if there is no compression applied. +func (s *Stream) RecvCompress() string { + if err := s.waitOnHeader(); err != nil { + return "" + } + return s.recvCompress +} + +// SetSendCompress sets the compression algorithm to the stream. +func (s *Stream) SetSendCompress(str string) { + s.sendCompress = str +} + +// Done returns a channel which is closed when it receives the final status +// from the server. +func (s *Stream) Done() <-chan struct{} { + return s.done +} + +// Header returns the header metadata of the stream. +// +// On client side, it acquires the key-value pairs of header metadata once it is +// available. It blocks until i) the metadata is ready or ii) there is no header +// metadata or iii) the stream is canceled/expired. +// +// On server side, it returns the out header after t.WriteHeader is called. +func (s *Stream) Header() (metadata.MD, error) { + if s.headerChan == nil && s.header != nil { + // On server side, return the header in stream. It will be the out + // header after t.WriteHeader is called. + return s.header.Copy(), nil + } + err := s.waitOnHeader() + // Even if the stream is closed, header is returned if available. + select { + case <-s.headerChan: + if s.header == nil { + return nil, nil + } + return s.header.Copy(), nil + default: + } + return nil, err +} + +// TrailersOnly blocks until a header or trailers-only frame is received and +// then returns true if the stream was trailers-only. If the stream ends +// before headers are received, returns true, nil. If a context error happens +// first, returns it as a status error. Client-side only. +func (s *Stream) TrailersOnly() (bool, error) { + err := s.waitOnHeader() + if err != nil { + return false, err + } + // if !headerDone, some other connection error occurred. + return s.noHeaders && atomic.LoadUint32(&s.headerDone) == 1, nil +} + +// Trailer returns the cached trailer metedata. Note that if it is not called +// after the entire stream is done, it could return an empty MD. Client +// side only. +// It can be safely read only after stream has ended that is either read +// or write have returned io.EOF. +func (s *Stream) Trailer() metadata.MD { + c := s.trailer.Copy() + return c +} + +// ContentSubtype returns the content-subtype for a request. For example, a +// content-subtype of "proto" will result in a content-type of +// "application/grpc+proto". This will always be lowercase. See +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. +func (s *Stream) ContentSubtype() string { + return s.contentSubtype +} + +// Context returns the context of the stream. +func (s *Stream) Context() context.Context { + return s.ctx +} + +// Method returns the method for the stream. +func (s *Stream) Method() string { + return s.method +} + +// Status returns the status received from the server. +// Status can be read safely only after the stream has ended, +// that is, after Done() is closed. +func (s *Stream) Status() *status.Status { + return s.status +} + +// SetHeader sets the header metadata. This can be called multiple times. +// Server side only. +// This should not be called in parallel to other data writes. +func (s *Stream) SetHeader(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + if s.isHeaderSent() || s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + s.header = metadata.Join(s.header, md) + s.hdrMu.Unlock() + return nil +} + +// SendHeader sends the given header metadata. The given metadata is +// combined with any metadata set by previous calls to SetHeader and +// then written to the transport stream. +func (s *Stream) SendHeader(md metadata.MD) error { + return s.st.WriteHeader(s, md) +} + +// SetTrailer sets the trailer metadata which will be sent with the RPC status +// by the server. This can be called multiple times. Server side only. +// This should not be called parallel to other data writes. +func (s *Stream) SetTrailer(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + if s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + s.trailer = metadata.Join(s.trailer, md) + s.hdrMu.Unlock() + return nil +} + +func (s *Stream) write(m recvMsg) { + s.buf.put(m) +} + +// Read reads all p bytes from the wire for this stream. +func (s *Stream) Read(p []byte) (n int, err error) { + // Don't request a read if there was an error earlier + if er := s.trReader.(*transportReader).er; er != nil { + return 0, er + } + s.requestRead(len(p)) + return io.ReadFull(s.trReader, p) +} + +// tranportReader reads all the data available for this Stream from the transport and +// passes them into the decoder, which converts them into a gRPC message stream. +// The error is io.EOF when the stream is done or another non-nil error if +// the stream broke. +type transportReader struct { + reader io.Reader + // The handler to control the window update procedure for both this + // particular stream and the associated transport. + windowHandler func(int) + er error +} + +func (t *transportReader) Read(p []byte) (n int, err error) { + n, err = t.reader.Read(p) + if err != nil { + t.er = err + return + } + t.windowHandler(n) + return +} + +// BytesReceived indicates whether any bytes have been received on this stream. +func (s *Stream) BytesReceived() bool { + return atomic.LoadUint32(&s.bytesReceived) == 1 +} + +// Unprocessed indicates whether the server did not process this stream -- +// i.e. it sent a refused stream or GOAWAY including this stream ID. +func (s *Stream) Unprocessed() bool { + return atomic.LoadUint32(&s.unprocessed) == 1 +} + +// GoString is implemented by Stream so context.String() won't +// race when printing %#v. +func (s *Stream) GoString() string { + return fmt.Sprintf("", s, s.method) +} + +// state of transport +type transportState int + +const ( + reachable transportState = iota + closing + draining +) + +// ServerConfig consists of all the configurations to establish a server transport. +type ServerConfig struct { + MaxStreams uint32 + AuthInfo credentials.AuthInfo + InTapHandle tap.ServerInHandle + StatsHandler stats.Handler + KeepaliveParams keepalive.ServerParameters + KeepalivePolicy keepalive.EnforcementPolicy + InitialWindowSize int32 + InitialConnWindowSize int32 + WriteBufferSize int + ReadBufferSize int + ChannelzParentID int64 + MaxHeaderListSize *uint32 +} + +// NewServerTransport creates a ServerTransport with conn or non-nil error +// if it fails. +func NewServerTransport(protocol string, conn net.Conn, config *ServerConfig) (ServerTransport, error) { + return newHTTP2Server(conn, config) +} + +// ConnectOptions covers all relevant options for communicating with the server. +type ConnectOptions struct { + // UserAgent is the application user agent. + UserAgent string + // Dialer specifies how to dial a network address. + Dialer func(context.Context, string) (net.Conn, error) + // FailOnNonTempDialError specifies if gRPC fails on non-temporary dial errors. + FailOnNonTempDialError bool + // PerRPCCredentials stores the PerRPCCredentials required to issue RPCs. + PerRPCCredentials []credentials.PerRPCCredentials + // TransportCredentials stores the Authenticator required to setup a client + // connection. Only one of TransportCredentials and CredsBundle is non-nil. + TransportCredentials credentials.TransportCredentials + // CredsBundle is the credentials bundle to be used. Only one of + // TransportCredentials and CredsBundle is non-nil. + CredsBundle credentials.Bundle + // KeepaliveParams stores the keepalive parameters. + KeepaliveParams keepalive.ClientParameters + // StatsHandler stores the handler for stats. + StatsHandler stats.Handler + // InitialWindowSize sets the initial window size for a stream. + InitialWindowSize int32 + // InitialConnWindowSize sets the initial window size for a connection. + InitialConnWindowSize int32 + // WriteBufferSize sets the size of write buffer which in turn determines how much data can be batched before it's written on the wire. + WriteBufferSize int + // ReadBufferSize sets the size of read buffer, which in turn determines how much data can be read at most for one read syscall. + ReadBufferSize int + // ChannelzParentID sets the addrConn id which initiate the creation of this client transport. + ChannelzParentID int64 + // MaxHeaderListSize sets the max (uncompressed) size of header list that is prepared to be received. + MaxHeaderListSize *uint32 +} + +// TargetInfo contains the information of the target such as network address and metadata. +type TargetInfo struct { + Addr string + Metadata interface{} + Authority string +} + +// NewClientTransport establishes the transport with the required ConnectOptions +// and returns it to the caller. +func NewClientTransport(connectCtx, ctx context.Context, target TargetInfo, opts ConnectOptions, onSuccess func(), onGoAway func(GoAwayReason), onClose func()) (ClientTransport, error) { + return newHTTP2Client(connectCtx, ctx, target, opts, onSuccess, onGoAway, onClose) +} + +// Options provides additional hints and information for message +// transmission. +type Options struct { + // Last indicates whether this write is the last piece for + // this stream. + Last bool +} + +// CallHdr carries the information of a particular RPC. +type CallHdr struct { + // Host specifies the peer's host. + Host string + + // Method specifies the operation to perform. + Method string + + // SendCompress specifies the compression algorithm applied on + // outbound message. + SendCompress string + + // Creds specifies credentials.PerRPCCredentials for a call. + Creds credentials.PerRPCCredentials + + // ContentSubtype specifies the content-subtype for a request. For example, a + // content-subtype of "proto" will result in a content-type of + // "application/grpc+proto". The value of ContentSubtype must be all + // lowercase, otherwise the behavior is undefined. See + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests + // for more details. + ContentSubtype string + + PreviousAttempts int // value of grpc-previous-rpc-attempts header to set +} + +// ClientTransport is the common interface for all gRPC client-side transport +// implementations. +type ClientTransport interface { + // Close tears down this transport. Once it returns, the transport + // should not be accessed any more. The caller must make sure this + // is called only once. + Close() error + + // GracefulClose starts to tear down the transport. It stops accepting + // new RPCs and wait the completion of the pending RPCs. + GracefulClose() error + + // Write sends the data for the given stream. A nil stream indicates + // the write is to be performed on the transport as a whole. + Write(s *Stream, hdr []byte, data []byte, opts *Options) error + + // NewStream creates a Stream for an RPC. + NewStream(ctx context.Context, callHdr *CallHdr) (*Stream, error) + + // CloseStream clears the footprint of a stream when the stream is + // not needed any more. The err indicates the error incurred when + // CloseStream is called. Must be called when a stream is finished + // unless the associated transport is closing. + CloseStream(stream *Stream, err error) + + // Error returns a channel that is closed when some I/O error + // happens. Typically the caller should have a goroutine to monitor + // this in order to take action (e.g., close the current transport + // and create a new one) in error case. It should not return nil + // once the transport is initiated. + Error() <-chan struct{} + + // GoAway returns a channel that is closed when ClientTransport + // receives the draining signal from the server (e.g., GOAWAY frame in + // HTTP/2). + GoAway() <-chan struct{} + + // GetGoAwayReason returns the reason why GoAway frame was received. + GetGoAwayReason() GoAwayReason + + // IncrMsgSent increments the number of message sent through this transport. + IncrMsgSent() + + // IncrMsgRecv increments the number of message received through this transport. + IncrMsgRecv() +} + +// ServerTransport is the common interface for all gRPC server-side transport +// implementations. +// +// Methods may be called concurrently from multiple goroutines, but +// Write methods for a given Stream will be called serially. +type ServerTransport interface { + // HandleStreams receives incoming streams using the given handler. + HandleStreams(func(*Stream), func(context.Context, string) context.Context) + + // WriteHeader sends the header metadata for the given stream. + // WriteHeader may not be called on all streams. + WriteHeader(s *Stream, md metadata.MD) error + + // Write sends the data for the given stream. + // Write may not be called on all streams. + Write(s *Stream, hdr []byte, data []byte, opts *Options) error + + // WriteStatus sends the status of a stream to the client. WriteStatus is + // the final call made on a stream and always occurs. + WriteStatus(s *Stream, st *status.Status) error + + // Close tears down the transport. Once it is called, the transport + // should not be accessed any more. All the pending streams and their + // handlers will be terminated asynchronously. + Close() error + + // RemoteAddr returns the remote network address. + RemoteAddr() net.Addr + + // Drain notifies the client this ServerTransport stops accepting new RPCs. + Drain() + + // IncrMsgSent increments the number of message sent through this transport. + IncrMsgSent() + + // IncrMsgRecv increments the number of message received through this transport. + IncrMsgRecv() +} + +// connectionErrorf creates an ConnectionError with the specified error description. +func connectionErrorf(temp bool, e error, format string, a ...interface{}) ConnectionError { + return ConnectionError{ + Desc: fmt.Sprintf(format, a...), + temp: temp, + err: e, + } +} + +// ConnectionError is an error that results in the termination of the +// entire connection and the retry of all the active streams. +type ConnectionError struct { + Desc string + temp bool + err error +} + +func (e ConnectionError) Error() string { + return fmt.Sprintf("connection error: desc = %q", e.Desc) +} + +// Temporary indicates if this connection error is temporary or fatal. +func (e ConnectionError) Temporary() bool { + return e.temp +} + +// Origin returns the original error of this connection error. +func (e ConnectionError) Origin() error { + // Never return nil error here. + // If the original error is nil, return itself. + if e.err == nil { + return e + } + return e.err +} + +var ( + // ErrConnClosing indicates that the transport is closing. + ErrConnClosing = connectionErrorf(true, nil, "transport is closing") + // errStreamDrain indicates that the stream is rejected because the + // connection is draining. This could be caused by goaway or balancer + // removing the address. + errStreamDrain = status.Error(codes.Unavailable, "the connection is draining") + // errStreamDone is returned from write at the client side to indiacte application + // layer of an error. + errStreamDone = errors.New("the stream is done") + // StatusGoAway indicates that the server sent a GOAWAY that included this + // stream's ID in unprocessed RPCs. + statusGoAway = status.New(codes.Unavailable, "the stream is rejected because server is draining the connection") +) + +// GoAwayReason contains the reason for the GoAway frame received. +type GoAwayReason uint8 + +const ( + // GoAwayInvalid indicates that no GoAway frame is received. + GoAwayInvalid GoAwayReason = 0 + // GoAwayNoReason is the default value when GoAway frame is received. + GoAwayNoReason GoAwayReason = 1 + // GoAwayTooManyPings indicates that a GoAway frame with + // ErrCodeEnhanceYourCalm was received and that the debug data said + // "too_many_pings". + GoAwayTooManyPings GoAwayReason = 2 +) + +// channelzData is used to store channelz related data for http2Client and http2Server. +// These fields cannot be embedded in the original structs (e.g. http2Client), since to do atomic +// operation on int64 variable on 32-bit machine, user is responsible to enforce memory alignment. +// Here, by grouping those int64 fields inside a struct, we are enforcing the alignment. +type channelzData struct { + kpCount int64 + // The number of streams that have started, including already finished ones. + streamsStarted int64 + // Client side: The number of streams that have ended successfully by receiving + // EoS bit set frame from server. + // Server side: The number of streams that have ended successfully by sending + // frame with EoS bit set. + streamsSucceeded int64 + streamsFailed int64 + // lastStreamCreatedTime stores the timestamp that the last stream gets created. It is of int64 type + // instead of time.Time since it's more costly to atomically update time.Time variable than int64 + // variable. The same goes for lastMsgSentTime and lastMsgRecvTime. + lastStreamCreatedTime int64 + msgSent int64 + msgRecv int64 + lastMsgSentTime int64 + lastMsgRecvTime int64 +} + +// ContextErr converts the error from context package into a status error. +func ContextErr(err error) error { + switch err { + case context.DeadlineExceeded: + return status.Error(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return status.Error(codes.Canceled, err.Error()) + } + return status.Errorf(codes.Internal, "Unexpected error from context packet: %v", err) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/keepalive/keepalive.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/keepalive/keepalive.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/keepalive/keepalive.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/keepalive/keepalive.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go new file mode 100644 index 00000000..cf6d1b94 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go @@ -0,0 +1,209 @@ +/* + * + * Copyright 2014 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 metadata define the structure of the metadata supported by gRPC library. +// Please refer to https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md +// for more information about custom-metadata. +package metadata // import "google.golang.org/grpc/metadata" + +import ( + "context" + "fmt" + "strings" +) + +// DecodeKeyValue returns k, v, nil. +// +// Deprecated: use k and v directly instead. +func DecodeKeyValue(k, v string) (string, string, error) { + return k, v, nil +} + +// MD is a mapping from metadata keys to values. Users should use the following +// two convenience functions New and Pairs to generate MD. +type MD map[string][]string + +// New creates an MD from a given key-value map. +// +// Only the following ASCII characters are allowed in keys: +// - digits: 0-9 +// - uppercase letters: A-Z (normalized to lower) +// - lowercase letters: a-z +// - special characters: -_. +// Uppercase letters are automatically converted to lowercase. +// +// Keys beginning with "grpc-" are reserved for grpc-internal use only and may +// result in errors if set in metadata. +func New(m map[string]string) MD { + md := MD{} + for k, val := range m { + key := strings.ToLower(k) + md[key] = append(md[key], val) + } + return md +} + +// Pairs returns an MD formed by the mapping of key, value ... +// Pairs panics if len(kv) is odd. +// +// Only the following ASCII characters are allowed in keys: +// - digits: 0-9 +// - uppercase letters: A-Z (normalized to lower) +// - lowercase letters: a-z +// - special characters: -_. +// Uppercase letters are automatically converted to lowercase. +// +// Keys beginning with "grpc-" are reserved for grpc-internal use only and may +// result in errors if set in metadata. +func Pairs(kv ...string) MD { + if len(kv)%2 == 1 { + panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv))) + } + md := MD{} + var key string + for i, s := range kv { + if i%2 == 0 { + key = strings.ToLower(s) + continue + } + md[key] = append(md[key], s) + } + return md +} + +// Len returns the number of items in md. +func (md MD) Len() int { + return len(md) +} + +// Copy returns a copy of md. +func (md MD) Copy() MD { + return Join(md) +} + +// Get obtains the values for a given key. +func (md MD) Get(k string) []string { + k = strings.ToLower(k) + return md[k] +} + +// Set sets the value of a given key with a slice of values. +func (md MD) Set(k string, vals ...string) { + if len(vals) == 0 { + return + } + k = strings.ToLower(k) + md[k] = vals +} + +// Append adds the values to key k, not overwriting what was already stored at that key. +func (md MD) Append(k string, vals ...string) { + if len(vals) == 0 { + return + } + k = strings.ToLower(k) + md[k] = append(md[k], vals...) +} + +// Join joins any number of mds into a single MD. +// The order of values for each key is determined by the order in which +// the mds containing those values are presented to Join. +func Join(mds ...MD) MD { + out := MD{} + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return out +} + +type mdIncomingKey struct{} +type mdOutgoingKey struct{} + +// NewIncomingContext creates a new context with incoming md attached. +func NewIncomingContext(ctx context.Context, md MD) context.Context { + return context.WithValue(ctx, mdIncomingKey{}, md) +} + +// NewOutgoingContext creates a new context with outgoing md attached. If used +// in conjunction with AppendToOutgoingContext, NewOutgoingContext will +// overwrite any previously-appended metadata. +func NewOutgoingContext(ctx context.Context, md MD) context.Context { + return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md}) +} + +// AppendToOutgoingContext returns a new context with the provided kv merged +// with any existing metadata in the context. Please refer to the +// documentation of Pairs for a description of kv. +func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context { + if len(kv)%2 == 1 { + panic(fmt.Sprintf("metadata: AppendToOutgoingContext got an odd number of input pairs for metadata: %d", len(kv))) + } + md, _ := ctx.Value(mdOutgoingKey{}).(rawMD) + added := make([][]string, len(md.added)+1) + copy(added, md.added) + added[len(added)-1] = make([]string, len(kv)) + copy(added[len(added)-1], kv) + return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md.md, added: added}) +} + +// FromIncomingContext returns the incoming metadata in ctx if it exists. The +// returned MD should not be modified. Writing to it may cause races. +// Modification should be made to copies of the returned MD. +func FromIncomingContext(ctx context.Context) (md MD, ok bool) { + md, ok = ctx.Value(mdIncomingKey{}).(MD) + return +} + +// FromOutgoingContextRaw returns the un-merged, intermediary contents +// of rawMD. Remember to perform strings.ToLower on the keys. The returned +// MD should not be modified. Writing to it may cause races. Modification +// should be made to copies of the returned MD. +// +// This is intended for gRPC-internal use ONLY. +func FromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) { + raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD) + if !ok { + return nil, nil, false + } + + return raw.md, raw.added, true +} + +// FromOutgoingContext returns the outgoing metadata in ctx if it exists. The +// returned MD should not be modified. Writing to it may cause races. +// Modification should be made to copies of the returned MD. +func FromOutgoingContext(ctx context.Context) (MD, bool) { + raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD) + if !ok { + return nil, false + } + + mds := make([]MD, 0, len(raw.added)+1) + mds = append(mds, raw.md) + for _, vv := range raw.added { + mds = append(mds, Pairs(vv...)) + } + return Join(mds...), ok +} + +type rawMD struct { + md MD + added [][]string +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go new file mode 100644 index 00000000..fd8cd3b5 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go @@ -0,0 +1,293 @@ +/* + * + * 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 naming + +import ( + "context" + "errors" + "fmt" + "net" + "strconv" + "time" + + "google.golang.org/grpc/grpclog" +) + +const ( + defaultPort = "443" + defaultFreq = time.Minute * 30 +) + +var ( + errMissingAddr = errors.New("missing address") + errWatcherClose = errors.New("watcher has been closed") + + lookupHost = net.DefaultResolver.LookupHost + lookupSRV = net.DefaultResolver.LookupSRV +) + +// 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 +} + +// 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) +} + +// dnsResolver handles name resolution for names following the DNS scheme +type dnsResolver struct { + // frequency of polling the DNS server that the watchers created by this resolver will use. + freq time.Duration +} + +// formatIP returns ok = false if addr is not a valid textual representation of an IP address. +// If addr is an IPv4 address, return the addr and ok = true. +// If addr is an IPv6 address, return the addr enclosed in square brackets and ok = true. +func formatIP(addr string) (addrIP string, ok bool) { + ip := net.ParseIP(addr) + if ip == nil { + return "", false + } + if ip.To4() != nil { + return addr, true + } + return "[" + addr + "]", true +} + +// parseTarget takes the user input target string, returns formatted host and port info. +// If target doesn't specify a port, set the port to be the defaultPort. +// If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets +// are strippd when setting the host. +// examples: +// target: "www.google.com" returns host: "www.google.com", port: "443" +// target: "ipv4-host:80" returns host: "ipv4-host", port: "80" +// target: "[ipv6-host]" returns host: "ipv6-host", port: "443" +// target: ":80" returns host: "localhost", port: "80" +// target: ":" returns host: "localhost", port: "443" +func parseTarget(target string) (host, port string, err error) { + if target == "" { + return "", "", errMissingAddr + } + + if ip := net.ParseIP(target); ip != nil { + // target is an IPv4 or IPv6(without brackets) address + return target, defaultPort, nil + } + if host, port, err := net.SplitHostPort(target); err == nil { + // target has port, i.e ipv4-host:port, [ipv6-host]:port, host-name:port + if host == "" { + // Keep consistent with net.Dial(): If the host is empty, as in ":80", the local system is assumed. + host = "localhost" + } + if port == "" { + // If the port field is empty(target ends with colon), e.g. "[::1]:", defaultPort is used. + port = defaultPort + } + return host, port, nil + } + if host, port, err := net.SplitHostPort(target + ":" + defaultPort); err == nil { + // target doesn't have port + return host, port, nil + } + return "", "", fmt.Errorf("invalid target address %v", target) +} + +// Resolve creates a watcher that watches the name resolution of the target. +func (r *dnsResolver) Resolve(target string) (Watcher, error) { + host, port, err := parseTarget(target) + if err != nil { + return nil, err + } + + if net.ParseIP(host) != nil { + ipWatcher := &ipWatcher{ + updateChan: make(chan *Update, 1), + } + host, _ = formatIP(host) + ipWatcher.updateChan <- &Update{Op: Add, Addr: host + ":" + port} + return ipWatcher, nil + } + + ctx, cancel := context.WithCancel(context.Background()) + return &dnsWatcher{ + r: r, + host: host, + port: port, + ctx: ctx, + cancel: cancel, + t: time.NewTimer(0), + }, nil +} + +// dnsWatcher watches for the name resolution update for a specific target +type dnsWatcher struct { + r *dnsResolver + host string + port string + // The latest resolved address set + curAddrs map[string]*Update + ctx context.Context + cancel context.CancelFunc + t *time.Timer +} + +// ipWatcher watches for the name resolution update for an IP address. +type ipWatcher struct { + updateChan chan *Update +} + +// Next returns the address resolution Update for the target. For IP address, +// the resolution is itself, thus polling name server is unnecessary. Therefore, +// Next() will return an Update the first time it is called, and will be blocked +// for all following calls as no Update exists until watcher is closed. +func (i *ipWatcher) Next() ([]*Update, error) { + u, ok := <-i.updateChan + if !ok { + return nil, errWatcherClose + } + return []*Update{u}, nil +} + +// Close closes the ipWatcher. +func (i *ipWatcher) Close() { + close(i.updateChan) +} + +// AddressType indicates the address type returned by name resolution. +type AddressType uint8 + +const ( + // Backend indicates the server is a backend server. + Backend AddressType = iota + // GRPCLB indicates the server is a grpclb load balancer. + GRPCLB +) + +// AddrMetadataGRPCLB contains the information the name resolver for grpclb should provide. The +// name resolver used by the grpclb balancer is required to provide this type of metadata in +// its address updates. +type AddrMetadataGRPCLB struct { + // AddrType is the type of server (grpc load balancer or backend). + AddrType AddressType + // ServerName is the name of the grpc load balancer. Used for authentication. + ServerName string +} + +// compileUpdate compares the old resolved addresses and newly resolved addresses, +// and generates an update list +func (w *dnsWatcher) compileUpdate(newAddrs map[string]*Update) []*Update { + var res []*Update + for a, u := range w.curAddrs { + if _, ok := newAddrs[a]; !ok { + u.Op = Delete + res = append(res, u) + } + } + for a, u := range newAddrs { + if _, ok := w.curAddrs[a]; !ok { + res = append(res, u) + } + } + return res +} + +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) + return nil + } + for _, s := range srvs { + lbAddrs, err := lookupHost(w.ctx, s.Target) + if err != nil { + grpclog.Warningf("grpc: failed load banlacer address dns lookup due to %v.\n", err) + continue + } + for _, a := range lbAddrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + strconv.Itoa(int(s.Port)) + newAddrs[addr] = &Update{Addr: addr, + Metadata: AddrMetadataGRPCLB{AddrType: GRPCLB, ServerName: s.Target}} + } + } + return newAddrs +} + +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) + return nil + } + for _, a := range addrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + w.port + newAddrs[addr] = &Update{Addr: addr} + } + return newAddrs +} + +func (w *dnsWatcher) lookup() []*Update { + newAddrs := w.lookupSRV() + if newAddrs == nil { + // If failed to get any balancer address (either no corresponding SRV for the + // target, or caused by failure during resolution/parsing of the balancer target), + // return any A record info available. + newAddrs = w.lookupHost() + } + result := w.compileUpdate(newAddrs) + w.curAddrs = newAddrs + return result +} + +// Next returns the resolved address update(delta) for the target. If there's no +// change, it will sleep for 30 mins and try to resolve again after that. +func (w *dnsWatcher) Next() ([]*Update, error) { + for { + select { + case <-w.ctx.Done(): + return nil, errWatcherClose + case <-w.t.C: + } + result := w.lookup() + // Next lookup should happen after an interval defined by w.r.freq. + w.t.Reset(w.r.freq) + if len(result) > 0 { + return result, nil + } + } +} + +func (w *dnsWatcher) Close() { + w.cancel() +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/naming/naming.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/naming.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/naming/naming.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/naming.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go new file mode 100644 index 00000000..e01d219f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go @@ -0,0 +1,51 @@ +/* + * + * Copyright 2014 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 peer defines various peer information associated with RPCs and +// corresponding utils. +package peer + +import ( + "context" + "net" + + "google.golang.org/grpc/credentials" +) + +// Peer contains the information of the peer for an RPC, such as the address +// and authentication information. +type Peer struct { + // Addr is the peer address. + Addr net.Addr + // AuthInfo is the authentication information of the transport. + // It is nil if there is no transport security being used. + AuthInfo credentials.AuthInfo +} + +type peerKey struct{} + +// NewContext creates a new context with peer information attached. +func NewContext(ctx context.Context, p *Peer) context.Context { + return context.WithValue(ctx, peerKey{}, p) +} + +// FromContext returns the peer information in ctx if it exists. +func FromContext(ctx context.Context) (p *Peer, ok bool) { + p, ok = ctx.Value(peerKey{}).(*Peer) + return +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go new file mode 100644 index 00000000..14f915d6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go @@ -0,0 +1,180 @@ +/* + * + * 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 grpc + +import ( + "context" + "io" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/status" +) + +// pickerWrapper is a wrapper of balancer.Picker. It blocks on certain pick +// actions and unblock when there's a picker update. +type pickerWrapper struct { + mu sync.Mutex + done bool + blockingCh chan struct{} + picker balancer.Picker + + // The latest connection happened. + connErrMu sync.Mutex + connErr error +} + +func newPickerWrapper() *pickerWrapper { + bp := &pickerWrapper{blockingCh: make(chan struct{})} + return bp +} + +func (bp *pickerWrapper) updateConnectionError(err error) { + bp.connErrMu.Lock() + bp.connErr = err + bp.connErrMu.Unlock() +} + +func (bp *pickerWrapper) connectionError() error { + bp.connErrMu.Lock() + err := bp.connErr + bp.connErrMu.Unlock() + return err +} + +// updatePicker is called by UpdateBalancerState. It unblocks all blocked pick. +func (bp *pickerWrapper) updatePicker(p balancer.Picker) { + bp.mu.Lock() + if bp.done { + bp.mu.Unlock() + return + } + bp.picker = p + // bp.blockingCh should never be nil. + close(bp.blockingCh) + bp.blockingCh = make(chan struct{}) + bp.mu.Unlock() +} + +func doneChannelzWrapper(acw *acBalancerWrapper, done func(balancer.DoneInfo)) func(balancer.DoneInfo) { + acw.mu.Lock() + ac := acw.ac + acw.mu.Unlock() + ac.incrCallsStarted() + return func(b balancer.DoneInfo) { + if b.Err != nil && b.Err != io.EOF { + ac.incrCallsFailed() + } else { + ac.incrCallsSucceeded() + } + if done != nil { + done(b) + } + } +} + +// pick returns the transport that will be used for the RPC. +// It may block in the following cases: +// - there's no picker +// - the current picker returns ErrNoSubConnAvailable +// - the current picker returns other errors and failfast is false. +// - the subConn returned by the current picker is not READY +// When one of these situations happens, pick blocks until the picker gets updated. +func (bp *pickerWrapper) pick(ctx context.Context, failfast bool, opts balancer.PickOptions) (transport.ClientTransport, func(balancer.DoneInfo), error) { + var ( + p balancer.Picker + ch chan struct{} + ) + + for { + bp.mu.Lock() + if bp.done { + bp.mu.Unlock() + return nil, nil, ErrClientConnClosing + } + + if bp.picker == nil { + ch = bp.blockingCh + } + if ch == bp.blockingCh { + // This could happen when either: + // - bp.picker is nil (the previous if condition), or + // - has called pick on the current picker. + bp.mu.Unlock() + select { + case <-ctx.Done(): + return nil, nil, ctx.Err() + case <-ch: + } + continue + } + + ch = bp.blockingCh + p = bp.picker + bp.mu.Unlock() + + subConn, done, err := p.Pick(ctx, opts) + + if err != nil { + switch err { + case balancer.ErrNoSubConnAvailable: + continue + case balancer.ErrTransientFailure: + if !failfast { + continue + } + return nil, nil, status.Errorf(codes.Unavailable, "%v, latest connection error: %v", err, bp.connectionError()) + default: + // err is some other error. + return nil, nil, toRPCErr(err) + } + } + + acw, ok := subConn.(*acBalancerWrapper) + if !ok { + grpclog.Infof("subconn returned from pick is not *acBalancerWrapper") + continue + } + if t, ok := acw.getAddrConn().getReadyTransport(); ok { + if channelz.IsOn() { + return t, doneChannelzWrapper(acw, done), nil + } + return t, done, nil + } + grpclog.Infof("blockingPicker: the picked transport is not ready, loop back to repick") + // If ok == false, ac.state is not READY. + // A valid picker always returns READY subConn. This means the state of ac + // just changed, and picker will be updated shortly. + // continue back to the beginning of the for loop to repick. + } +} + +func (bp *pickerWrapper) close() { + bp.mu.Lock() + defer bp.mu.Unlock() + if bp.done { + return + } + bp.done = true + close(bp.blockingCh) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go new file mode 100644 index 00000000..d1e38aad --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go @@ -0,0 +1,110 @@ +/* + * + * 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 grpc + +import ( + "context" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// PickFirstBalancerName is the name of the pick_first balancer. +const PickFirstBalancerName = "pick_first" + +func newPickfirstBuilder() balancer.Builder { + return &pickfirstBuilder{} +} + +type pickfirstBuilder struct{} + +func (*pickfirstBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { + return &pickfirstBalancer{cc: cc} +} + +func (*pickfirstBuilder) Name() string { + return PickFirstBalancerName +} + +type pickfirstBalancer struct { + cc balancer.ClientConn + sc balancer.SubConn +} + +func (b *pickfirstBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) { + if err != nil { + grpclog.Infof("pickfirstBalancer: HandleResolvedAddrs called with error %v", err) + return + } + if b.sc == nil { + b.sc, err = b.cc.NewSubConn(addrs, balancer.NewSubConnOptions{}) + if err != nil { + //TODO(yuxuanli): why not change the cc state to Idle? + grpclog.Errorf("pickfirstBalancer: failed to NewSubConn: %v", err) + return + } + b.cc.UpdateBalancerState(connectivity.Idle, &picker{sc: b.sc}) + b.sc.Connect() + } else { + b.sc.UpdateAddresses(addrs) + b.sc.Connect() + } +} + +func (b *pickfirstBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + grpclog.Infof("pickfirstBalancer: HandleSubConnStateChange: %p, %v", sc, s) + if b.sc != sc { + grpclog.Infof("pickfirstBalancer: ignored state change because sc is not recognized") + return + } + if s == connectivity.Shutdown { + b.sc = nil + return + } + + switch s { + case connectivity.Ready, connectivity.Idle: + b.cc.UpdateBalancerState(s, &picker{sc: sc}) + case connectivity.Connecting: + b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrNoSubConnAvailable}) + case connectivity.TransientFailure: + b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrTransientFailure}) + } +} + +func (b *pickfirstBalancer) Close() { +} + +type picker struct { + err error + sc balancer.SubConn +} + +func (p *picker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + if p.err != nil { + return nil, nil, p.err + } + return p.sc, nil, nil +} + +func init() { + balancer.Register(newPickfirstBuilder()) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go new file mode 100644 index 00000000..f8f69bfb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go @@ -0,0 +1,152 @@ +/* + * + * 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 grpc + +import ( + "bufio" + "context" + "encoding/base64" + "errors" + "fmt" + "io" + "net" + "net/http" + "net/http/httputil" + "net/url" +) + +const proxyAuthHeaderKey = "Proxy-Authorization" + +var ( + // errDisabled indicates that proxy is disabled for the address. + errDisabled = errors.New("proxy is disabled for the address") + // The following variable will be overwritten in the tests. + httpProxyFromEnvironment = http.ProxyFromEnvironment +) + +func mapAddress(ctx context.Context, address string) (*url.URL, error) { + req := &http.Request{ + URL: &url.URL{ + Scheme: "https", + Host: address, + }, + } + url, err := httpProxyFromEnvironment(req) + if err != nil { + return nil, err + } + if url == nil { + return nil, errDisabled + } + return url, nil +} + +// To read a response from a net.Conn, http.ReadResponse() takes a bufio.Reader. +// It's possible that this reader reads more than what's need for the response and stores +// those bytes in the buffer. +// bufConn wraps the original net.Conn and the bufio.Reader to make sure we don't lose the +// bytes in the buffer. +type bufConn struct { + net.Conn + r io.Reader +} + +func (c *bufConn) Read(b []byte) (int, error) { + return c.r.Read(b) +} + +func basicAuth(username, password string) string { + auth := username + ":" + password + return base64.StdEncoding.EncodeToString([]byte(auth)) +} + +func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, backendAddr string, proxyURL *url.URL) (_ net.Conn, err error) { + defer func() { + if err != nil { + conn.Close() + } + }() + + req := &http.Request{ + Method: http.MethodConnect, + URL: &url.URL{Host: backendAddr}, + Header: map[string][]string{"User-Agent": {grpcUA}}, + } + if t := proxyURL.User; t != nil { + u := t.Username() + p, _ := t.Password() + req.Header.Add(proxyAuthHeaderKey, "Basic "+basicAuth(u, p)) + } + + if err := sendHTTPRequest(ctx, req, conn); err != nil { + return nil, fmt.Errorf("failed to write the HTTP request: %v", err) + } + + r := bufio.NewReader(conn) + resp, err := http.ReadResponse(r, req) + if err != nil { + return nil, fmt.Errorf("reading server HTTP response: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + dump, err := httputil.DumpResponse(resp, true) + if err != nil { + return nil, fmt.Errorf("failed to do connect handshake, status code: %s", resp.Status) + } + return nil, fmt.Errorf("failed to do connect handshake, response: %q", dump) + } + + return &bufConn{Conn: conn, r: r}, nil +} + +// newProxyDialer returns a dialer that connects to proxy first if necessary. +// The returned dialer checks if a proxy is necessary, dial to the proxy with the +// provided dialer, does HTTP CONNECT handshake and returns the connection. +func newProxyDialer(dialer func(context.Context, string) (net.Conn, error)) func(context.Context, string) (net.Conn, error) { + return func(ctx context.Context, addr string) (conn net.Conn, err error) { + var newAddr string + proxyURL, err := mapAddress(ctx, addr) + if err != nil { + if err != errDisabled { + return nil, err + } + newAddr = addr + } else { + newAddr = proxyURL.Host + } + + conn, err = dialer(ctx, newAddr) + if err != nil { + return + } + if proxyURL != nil { + // proxy is disabled if proxyURL is nil. + conn, err = doHTTPConnectHandshake(ctx, conn, addr, proxyURL) + } + return + } +} + +func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { + req = req.WithContext(ctx) + if err := req.Write(conn); err != nil { + return fmt.Errorf("failed to write the HTTP request: %v", err) + } + return nil +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go new file mode 100644 index 00000000..f33189fe --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go @@ -0,0 +1,436 @@ +/* + * + * 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 dns implements a dns resolver to be installed as the default resolver +// in grpc. +package dns + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net" + "os" + "strconv" + "strings" + "sync" + "time" + + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/resolver" +) + +func init() { + resolver.Register(NewBuilder()) +} + +const ( + defaultPort = "443" + defaultFreq = time.Minute * 30 + defaultDNSSvrPort = "53" + golang = "GO" + // In DNS, service config is encoded in a TXT record via the mechanism + // described in RFC-1464 using the attribute name grpc_config. + txtAttribute = "grpc_config=" +) + +var ( + errMissingAddr = errors.New("dns resolver: missing address") + + // Addresses ending with a colon that is supposed to be the separator + // between host and port is not allowed. E.g. "::" is a valid address as + // it is an IPv6 address (host only) and "[::]:" is invalid as it ends with + // a colon as the host and port separator + errEndsWithColon = errors.New("dns resolver: missing port after port-separator colon") +) + +var ( + defaultResolver netResolver = net.DefaultResolver +) + +var customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) { + return func(ctx context.Context, network, address string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, authority) + } +} + +var customAuthorityResolver = func(authority string) (netResolver, error) { + host, port, err := parseTarget(authority, defaultDNSSvrPort) + if err != nil { + return nil, err + } + + authorityWithPort := net.JoinHostPort(host, port) + + return &net.Resolver{ + PreferGo: true, + Dial: customAuthorityDialler(authorityWithPort), + }, nil +} + +// NewBuilder creates a dnsBuilder which is used to factory DNS resolvers. +func NewBuilder() resolver.Builder { + return &dnsBuilder{minFreq: defaultFreq} +} + +type dnsBuilder struct { + // minimum frequency of polling the DNS server. + minFreq time.Duration +} + +// Build creates and starts a DNS resolver that watches the name resolution of the target. +func (b *dnsBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) { + host, port, err := parseTarget(target.Endpoint, defaultPort) + if err != nil { + return nil, err + } + + // IP address. + if net.ParseIP(host) != nil { + host, _ = formatIP(host) + addr := []resolver.Address{{Addr: host + ":" + port}} + i := &ipResolver{ + cc: cc, + ip: addr, + rn: make(chan struct{}, 1), + q: make(chan struct{}), + } + cc.NewAddress(addr) + go i.watcher() + return i, nil + } + + // DNS address (non-IP). + ctx, cancel := context.WithCancel(context.Background()) + d := &dnsResolver{ + freq: b.minFreq, + backoff: backoff.Exponential{MaxDelay: b.minFreq}, + host: host, + port: port, + ctx: ctx, + cancel: cancel, + cc: cc, + t: time.NewTimer(0), + rn: make(chan struct{}, 1), + disableServiceConfig: opts.DisableServiceConfig, + } + + if target.Authority == "" { + d.resolver = defaultResolver + } else { + d.resolver, err = customAuthorityResolver(target.Authority) + if err != nil { + return nil, err + } + } + + d.wg.Add(1) + go d.watcher() + return d, nil +} + +// Scheme returns the naming scheme of this resolver builder, which is "dns". +func (b *dnsBuilder) Scheme() string { + return "dns" +} + +type netResolver interface { + LookupHost(ctx context.Context, host string) (addrs []string, err error) + LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error) + LookupTXT(ctx context.Context, name string) (txts []string, err error) +} + +// ipResolver watches for the name resolution update for an IP address. +type ipResolver struct { + cc resolver.ClientConn + ip []resolver.Address + // rn channel is used by ResolveNow() to force an immediate resolution of the target. + rn chan struct{} + q chan struct{} +} + +// ResolveNow resend the address it stores, no resolution is needed. +func (i *ipResolver) ResolveNow(opt resolver.ResolveNowOption) { + select { + case i.rn <- struct{}{}: + default: + } +} + +// Close closes the ipResolver. +func (i *ipResolver) Close() { + close(i.q) +} + +func (i *ipResolver) watcher() { + for { + select { + case <-i.rn: + i.cc.NewAddress(i.ip) + case <-i.q: + return + } + } +} + +// dnsResolver watches for the name resolution update for a non-IP target. +type dnsResolver struct { + freq time.Duration + backoff backoff.Exponential + retryCount int + host string + port string + resolver netResolver + ctx context.Context + cancel context.CancelFunc + cc resolver.ClientConn + // rn channel is used by ResolveNow() to force an immediate resolution of the target. + rn chan struct{} + t *time.Timer + // wg is used to enforce Close() to return after the watcher() goroutine has finished. + // Otherwise, data race will be possible. [Race Example] in dns_resolver_test we + // replace the real lookup functions with mocked ones to facilitate testing. + // If Close() doesn't wait for watcher() goroutine finishes, race detector sometimes + // will warns lookup (READ the lookup function pointers) inside watcher() goroutine + // has data race with replaceNetFunc (WRITE the lookup function pointers). + wg sync.WaitGroup + disableServiceConfig bool +} + +// ResolveNow invoke an immediate resolution of the target that this dnsResolver watches. +func (d *dnsResolver) ResolveNow(opt resolver.ResolveNowOption) { + select { + case d.rn <- struct{}{}: + default: + } +} + +// Close closes the dnsResolver. +func (d *dnsResolver) Close() { + d.cancel() + d.wg.Wait() + d.t.Stop() +} + +func (d *dnsResolver) watcher() { + defer d.wg.Done() + for { + select { + case <-d.ctx.Done(): + return + case <-d.t.C: + case <-d.rn: + } + result, sc := d.lookup() + // Next lookup should happen within an interval defined by d.freq. It may be + // more often due to exponential retry on empty address list. + if len(result) == 0 { + d.retryCount++ + d.t.Reset(d.backoff.Backoff(d.retryCount)) + } else { + d.retryCount = 0 + d.t.Reset(d.freq) + } + d.cc.NewServiceConfig(sc) + d.cc.NewAddress(result) + } +} + +func (d *dnsResolver) lookupSRV() []resolver.Address { + var newAddrs []resolver.Address + _, srvs, err := d.resolver.LookupSRV(d.ctx, "grpclb", "tcp", d.host) + if err != nil { + grpclog.Infof("grpc: failed dns SRV record lookup due to %v.\n", err) + return nil + } + for _, s := range srvs { + lbAddrs, err := d.resolver.LookupHost(d.ctx, s.Target) + if err != nil { + grpclog.Infof("grpc: failed load balancer address dns lookup due to %v.\n", err) + continue + } + for _, a := range lbAddrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + strconv.Itoa(int(s.Port)) + newAddrs = append(newAddrs, resolver.Address{Addr: addr, Type: resolver.GRPCLB, ServerName: s.Target}) + } + } + return newAddrs +} + +func (d *dnsResolver) lookupTXT() string { + ss, err := d.resolver.LookupTXT(d.ctx, d.host) + if err != nil { + grpclog.Infof("grpc: failed dns TXT record lookup due to %v.\n", err) + return "" + } + var res string + for _, s := range ss { + res += s + } + + // TXT record must have "grpc_config=" attribute in order to be used as service config. + if !strings.HasPrefix(res, txtAttribute) { + grpclog.Warningf("grpc: TXT record %v missing %v attribute", res, txtAttribute) + return "" + } + return strings.TrimPrefix(res, txtAttribute) +} + +func (d *dnsResolver) lookupHost() []resolver.Address { + var newAddrs []resolver.Address + addrs, err := d.resolver.LookupHost(d.ctx, d.host) + if err != nil { + grpclog.Warningf("grpc: failed dns A record lookup due to %v.\n", err) + return nil + } + for _, a := range addrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + d.port + newAddrs = append(newAddrs, resolver.Address{Addr: addr}) + } + return newAddrs +} + +func (d *dnsResolver) lookup() ([]resolver.Address, string) { + newAddrs := d.lookupSRV() + // Support fallback to non-balancer address. + newAddrs = append(newAddrs, d.lookupHost()...) + if d.disableServiceConfig { + return newAddrs, "" + } + sc := d.lookupTXT() + return newAddrs, canaryingSC(sc) +} + +// formatIP returns ok = false if addr is not a valid textual representation of an IP address. +// If addr is an IPv4 address, return the addr and ok = true. +// If addr is an IPv6 address, return the addr enclosed in square brackets and ok = true. +func formatIP(addr string) (addrIP string, ok bool) { + ip := net.ParseIP(addr) + if ip == nil { + return "", false + } + if ip.To4() != nil { + return addr, true + } + return "[" + addr + "]", true +} + +// parseTarget takes the user input target string and default port, returns formatted host and port info. +// If target doesn't specify a port, set the port to be the defaultPort. +// If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets +// are strippd when setting the host. +// examples: +// target: "www.google.com" defaultPort: "443" returns host: "www.google.com", port: "443" +// target: "ipv4-host:80" defaultPort: "443" returns host: "ipv4-host", port: "80" +// target: "[ipv6-host]" defaultPort: "443" returns host: "ipv6-host", port: "443" +// target: ":80" defaultPort: "443" returns host: "localhost", port: "80" +func parseTarget(target, defaultPort string) (host, port string, err error) { + if target == "" { + return "", "", errMissingAddr + } + if ip := net.ParseIP(target); ip != nil { + // target is an IPv4 or IPv6(without brackets) address + return target, defaultPort, nil + } + if host, port, err = net.SplitHostPort(target); err == nil { + if port == "" { + // If the port field is empty (target ends with colon), e.g. "[::1]:", this is an error. + return "", "", errEndsWithColon + } + // target has port, i.e ipv4-host:port, [ipv6-host]:port, host-name:port + if host == "" { + // Keep consistent with net.Dial(): If the host is empty, as in ":80", the local system is assumed. + host = "localhost" + } + return host, port, nil + } + if host, port, err = net.SplitHostPort(target + ":" + defaultPort); err == nil { + // target doesn't have port + return host, port, nil + } + return "", "", fmt.Errorf("invalid target address %v, error info: %v", target, err) +} + +type rawChoice struct { + ClientLanguage *[]string `json:"clientLanguage,omitempty"` + Percentage *int `json:"percentage,omitempty"` + ClientHostName *[]string `json:"clientHostName,omitempty"` + ServiceConfig *json.RawMessage `json:"serviceConfig,omitempty"` +} + +func containsString(a *[]string, b string) bool { + if a == nil { + return true + } + for _, c := range *a { + if c == b { + return true + } + } + return false +} + +func chosenByPercentage(a *int) bool { + if a == nil { + return true + } + return grpcrand.Intn(100)+1 <= *a +} + +func canaryingSC(js string) string { + if js == "" { + return "" + } + var rcs []rawChoice + err := json.Unmarshal([]byte(js), &rcs) + if err != nil { + grpclog.Warningf("grpc: failed to parse service config json string due to %v.\n", err) + return "" + } + cliHostname, err := os.Hostname() + if err != nil { + grpclog.Warningf("grpc: failed to get client hostname due to %v.\n", err) + return "" + } + var sc string + for _, c := range rcs { + if !containsString(c.ClientLanguage, golang) || + !chosenByPercentage(c.Percentage) || + !containsString(c.ClientHostName, cliHostname) || + c.ServiceConfig == nil { + continue + } + sc = string(*c.ServiceConfig) + break + } + return sc +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/resolver.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/resolver.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/resolver.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/resolver.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go new file mode 100644 index 00000000..9d760253 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go @@ -0,0 +1,155 @@ +/* + * + * 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 grpc + +import ( + "fmt" + "strings" + + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/resolver" +) + +// ccResolverWrapper is a wrapper on top of cc for resolvers. +// It implements resolver.ClientConnection interface. +type ccResolverWrapper struct { + cc *ClientConn + resolver resolver.Resolver + addrCh chan []resolver.Address + scCh chan string + done chan struct{} + lastAddressesCount int +} + +// split2 returns the values from strings.SplitN(s, sep, 2). +// If sep is not found, it returns ("", s, false) instead. +func split2(s, sep string) (string, string, bool) { + spl := strings.SplitN(s, sep, 2) + if len(spl) < 2 { + return "", "", false + } + return spl[0], spl[1], true +} + +// parseTarget splits target into a struct containing scheme, authority and +// endpoint. +// +// If target is not a valid scheme://authority/endpoint, it returns {Endpoint: +// target}. +func parseTarget(target string) (ret resolver.Target) { + var ok bool + ret.Scheme, ret.Endpoint, ok = split2(target, "://") + if !ok { + return resolver.Target{Endpoint: target} + } + ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/") + if !ok { + return resolver.Target{Endpoint: target} + } + return ret +} + +// newCCResolverWrapper parses cc.target for scheme and gets the resolver +// builder for this scheme and builds the resolver. The monitoring goroutine +// for it is not started yet and can be created by calling start(). +// +// If withResolverBuilder dial option is set, the specified resolver will be +// used instead. +func newCCResolverWrapper(cc *ClientConn) (*ccResolverWrapper, error) { + rb := cc.dopts.resolverBuilder + if rb == nil { + return nil, fmt.Errorf("could not get resolver for scheme: %q", cc.parsedTarget.Scheme) + } + + ccr := &ccResolverWrapper{ + cc: cc, + addrCh: make(chan []resolver.Address, 1), + scCh: make(chan string, 1), + done: make(chan struct{}), + } + + var err error + ccr.resolver, err = rb.Build(cc.parsedTarget, ccr, resolver.BuildOption{DisableServiceConfig: cc.dopts.disableServiceConfig}) + if err != nil { + return nil, err + } + return ccr, nil +} + +func (ccr *ccResolverWrapper) resolveNow(o resolver.ResolveNowOption) { + ccr.resolver.ResolveNow(o) +} + +func (ccr *ccResolverWrapper) close() { + ccr.resolver.Close() + close(ccr.done) +} + +// NewAddress is called by the resolver implemenetion to send addresses to gRPC. +func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) { + select { + case <-ccr.done: + return + default: + } + grpclog.Infof("ccResolverWrapper: sending new addresses to cc: %v", addrs) + if channelz.IsOn() { + ccr.addChannelzTraceEvent(addrs) + } + ccr.cc.handleResolvedAddrs(addrs, nil) +} + +// NewServiceConfig is called by the resolver implemenetion to send service +// configs to gRPC. +func (ccr *ccResolverWrapper) NewServiceConfig(sc string) { + select { + case <-ccr.done: + return + default: + } + grpclog.Infof("ccResolverWrapper: got new service config: %v", sc) + ccr.cc.handleServiceConfig(sc) +} + +func (ccr *ccResolverWrapper) addChannelzTraceEvent(addrs []resolver.Address) { + if len(addrs) == 0 && ccr.lastAddressesCount != 0 { + channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Resolver returns an empty address list", + Severity: channelz.CtWarning, + }) + } else if len(addrs) != 0 && ccr.lastAddressesCount == 0 { + var s string + for i, a := range addrs { + if a.ServerName != "" { + s += a.Addr + "(" + a.ServerName + ")" + } else { + s += a.Addr + } + if i != len(addrs)-1 { + s += " " + } + } + channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Resolver returns a non-empty address list (previous one was empty) %q", s), + Severity: channelz.CtINFO, + }) + } + ccr.lastAddressesCount = len(addrs) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go new file mode 100644 index 00000000..86f00e5a --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go @@ -0,0 +1,815 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "bytes" + "compress/gzip" + "context" + "encoding/binary" + "fmt" + "io" + "io/ioutil" + "math" + "net/url" + "strings" + "sync" + "time" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// Compressor defines the interface gRPC uses to compress a message. +// +// Deprecated: use package encoding. +type Compressor interface { + // Do compresses p into w. + Do(w io.Writer, p []byte) error + // Type returns the compression algorithm the Compressor uses. + Type() string +} + +type gzipCompressor struct { + pool sync.Pool +} + +// NewGZIPCompressor creates a Compressor based on GZIP. +// +// Deprecated: use package encoding/gzip. +func NewGZIPCompressor() Compressor { + c, _ := NewGZIPCompressorWithLevel(gzip.DefaultCompression) + return c +} + +// NewGZIPCompressorWithLevel is like NewGZIPCompressor but specifies the gzip compression level instead +// of assuming DefaultCompression. +// +// The error returned will be nil if the level is valid. +// +// Deprecated: use package encoding/gzip. +func NewGZIPCompressorWithLevel(level int) (Compressor, error) { + if level < gzip.DefaultCompression || level > gzip.BestCompression { + return nil, fmt.Errorf("grpc: invalid compression level: %d", level) + } + return &gzipCompressor{ + pool: sync.Pool{ + New: func() interface{} { + w, err := gzip.NewWriterLevel(ioutil.Discard, level) + if err != nil { + panic(err) + } + return w + }, + }, + }, nil +} + +func (c *gzipCompressor) Do(w io.Writer, p []byte) error { + z := c.pool.Get().(*gzip.Writer) + defer c.pool.Put(z) + z.Reset(w) + if _, err := z.Write(p); err != nil { + return err + } + return z.Close() +} + +func (c *gzipCompressor) Type() string { + return "gzip" +} + +// Decompressor defines the interface gRPC uses to decompress a message. +// +// Deprecated: use package encoding. +type Decompressor interface { + // Do reads the data from r and uncompress them. + Do(r io.Reader) ([]byte, error) + // Type returns the compression algorithm the Decompressor uses. + Type() string +} + +type gzipDecompressor struct { + pool sync.Pool +} + +// NewGZIPDecompressor creates a Decompressor based on GZIP. +// +// Deprecated: use package encoding/gzip. +func NewGZIPDecompressor() Decompressor { + return &gzipDecompressor{} +} + +func (d *gzipDecompressor) Do(r io.Reader) ([]byte, error) { + var z *gzip.Reader + switch maybeZ := d.pool.Get().(type) { + case nil: + newZ, err := gzip.NewReader(r) + if err != nil { + return nil, err + } + z = newZ + case *gzip.Reader: + z = maybeZ + if err := z.Reset(r); err != nil { + d.pool.Put(z) + return nil, err + } + } + + defer func() { + z.Close() + d.pool.Put(z) + }() + return ioutil.ReadAll(z) +} + +func (d *gzipDecompressor) Type() string { + return "gzip" +} + +// callInfo contains all related configuration and information about an RPC. +type callInfo struct { + compressorType string + failFast bool + stream ClientStream + maxReceiveMessageSize *int + maxSendMessageSize *int + creds credentials.PerRPCCredentials + contentSubtype string + codec baseCodec + maxRetryRPCBufferSize int +} + +func defaultCallInfo() *callInfo { + return &callInfo{ + failFast: true, + maxRetryRPCBufferSize: 256 * 1024, // 256KB + } +} + +// CallOption configures a Call before it starts or extracts information from +// a Call after it completes. +type CallOption interface { + // before is called before the call is sent to any server. If before + // returns a non-nil error, the RPC fails with that error. + before(*callInfo) error + + // after is called after the call has completed. after cannot return an + // error, so any failures should be reported via output parameters. + after(*callInfo) +} + +// EmptyCallOption does not alter the Call configuration. +// It can be embedded in another structure to carry satellite data for use +// by interceptors. +type EmptyCallOption struct{} + +func (EmptyCallOption) before(*callInfo) error { return nil } +func (EmptyCallOption) after(*callInfo) {} + +// Header returns a CallOptions that retrieves the header metadata +// for a unary RPC. +func Header(md *metadata.MD) CallOption { + return HeaderCallOption{HeaderAddr: md} +} + +// HeaderCallOption is a CallOption for collecting response header metadata. +// The metadata field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type HeaderCallOption struct { + HeaderAddr *metadata.MD +} + +func (o HeaderCallOption) before(c *callInfo) error { return nil } +func (o HeaderCallOption) after(c *callInfo) { + if c.stream != nil { + *o.HeaderAddr, _ = c.stream.Header() + } +} + +// Trailer returns a CallOptions that retrieves the trailer metadata +// for a unary RPC. +func Trailer(md *metadata.MD) CallOption { + return TrailerCallOption{TrailerAddr: md} +} + +// TrailerCallOption is a CallOption for collecting response trailer metadata. +// The metadata field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type TrailerCallOption struct { + TrailerAddr *metadata.MD +} + +func (o TrailerCallOption) before(c *callInfo) error { return nil } +func (o TrailerCallOption) after(c *callInfo) { + if c.stream != nil { + *o.TrailerAddr = c.stream.Trailer() + } +} + +// Peer returns a CallOption that retrieves peer information for a unary RPC. +// The peer field will be populated *after* the RPC completes. +func Peer(p *peer.Peer) CallOption { + return PeerCallOption{PeerAddr: p} +} + +// PeerCallOption is a CallOption for collecting the identity of the remote +// peer. The peer field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type PeerCallOption struct { + PeerAddr *peer.Peer +} + +func (o PeerCallOption) before(c *callInfo) error { return nil } +func (o PeerCallOption) after(c *callInfo) { + if c.stream != nil { + if x, ok := peer.FromContext(c.stream.Context()); ok { + *o.PeerAddr = *x + } + } +} + +// FailFast configures the action to take when an RPC is attempted on broken +// connections or unreachable servers. If failFast is true, the RPC will fail +// immediately. Otherwise, the RPC client will block the call until a +// connection is available (or the call is canceled or times out) and will +// retry the call if it fails due to a transient error. gRPC will not retry if +// data was written to the wire unless the server indicates it did not process +// the data. Please refer to +// https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md. +// +// By default, RPCs are "Fail Fast". +func FailFast(failFast bool) CallOption { + return FailFastCallOption{FailFast: failFast} +} + +// FailFastCallOption is a CallOption for indicating whether an RPC should fail +// fast or not. +// This is an EXPERIMENTAL API. +type FailFastCallOption struct { + FailFast bool +} + +func (o FailFastCallOption) before(c *callInfo) error { + c.failFast = o.FailFast + return nil +} +func (o FailFastCallOption) after(c *callInfo) {} + +// MaxCallRecvMsgSize returns a CallOption which sets the maximum message size the client can receive. +func MaxCallRecvMsgSize(s int) CallOption { + return MaxRecvMsgSizeCallOption{MaxRecvMsgSize: s} +} + +// MaxRecvMsgSizeCallOption is a CallOption that indicates the maximum message +// size the client can receive. +// This is an EXPERIMENTAL API. +type MaxRecvMsgSizeCallOption struct { + MaxRecvMsgSize int +} + +func (o MaxRecvMsgSizeCallOption) before(c *callInfo) error { + c.maxReceiveMessageSize = &o.MaxRecvMsgSize + return nil +} +func (o MaxRecvMsgSizeCallOption) after(c *callInfo) {} + +// MaxCallSendMsgSize returns a CallOption which sets the maximum message size the client can send. +func MaxCallSendMsgSize(s int) CallOption { + return MaxSendMsgSizeCallOption{MaxSendMsgSize: s} +} + +// MaxSendMsgSizeCallOption is a CallOption that indicates the maximum message +// size the client can send. +// This is an EXPERIMENTAL API. +type MaxSendMsgSizeCallOption struct { + MaxSendMsgSize int +} + +func (o MaxSendMsgSizeCallOption) before(c *callInfo) error { + c.maxSendMessageSize = &o.MaxSendMsgSize + return nil +} +func (o MaxSendMsgSizeCallOption) after(c *callInfo) {} + +// PerRPCCredentials returns a CallOption that sets credentials.PerRPCCredentials +// for a call. +func PerRPCCredentials(creds credentials.PerRPCCredentials) CallOption { + return PerRPCCredsCallOption{Creds: creds} +} + +// PerRPCCredsCallOption is a CallOption that indicates the per-RPC +// credentials to use for the call. +// This is an EXPERIMENTAL API. +type PerRPCCredsCallOption struct { + Creds credentials.PerRPCCredentials +} + +func (o PerRPCCredsCallOption) before(c *callInfo) error { + c.creds = o.Creds + return nil +} +func (o PerRPCCredsCallOption) after(c *callInfo) {} + +// UseCompressor returns a CallOption which sets the compressor used when +// sending the request. If WithCompressor is also set, UseCompressor has +// higher priority. +// +// This API is EXPERIMENTAL. +func UseCompressor(name string) CallOption { + return CompressorCallOption{CompressorType: name} +} + +// CompressorCallOption is a CallOption that indicates the compressor to use. +// This is an EXPERIMENTAL API. +type CompressorCallOption struct { + CompressorType string +} + +func (o CompressorCallOption) before(c *callInfo) error { + c.compressorType = o.CompressorType + return nil +} +func (o CompressorCallOption) after(c *callInfo) {} + +// CallContentSubtype returns a CallOption that will set the content-subtype +// for a call. For example, if content-subtype is "json", the Content-Type over +// the wire will be "application/grpc+json". The content-subtype is converted +// to lowercase before being included in Content-Type. See Content-Type on +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. +// +// If CallCustomCodec is not also used, the content-subtype will be used to +// look up the Codec to use in the registry controlled by RegisterCodec. See +// the documentation on RegisterCodec for details on registration. The lookup +// of content-subtype is case-insensitive. If no such Codec is found, the call +// will result in an error with code codes.Internal. +// +// If CallCustomCodec is also used, that Codec will be used for all request and +// response messages, with the content-subtype set to the given contentSubtype +// here for requests. +func CallContentSubtype(contentSubtype string) CallOption { + return ContentSubtypeCallOption{ContentSubtype: strings.ToLower(contentSubtype)} +} + +// ContentSubtypeCallOption is a CallOption that indicates the content-subtype +// used for marshaling messages. +// This is an EXPERIMENTAL API. +type ContentSubtypeCallOption struct { + ContentSubtype string +} + +func (o ContentSubtypeCallOption) before(c *callInfo) error { + c.contentSubtype = o.ContentSubtype + return nil +} +func (o ContentSubtypeCallOption) after(c *callInfo) {} + +// CallCustomCodec returns a CallOption that will set the given Codec to be +// used for all request and response messages for a call. The result of calling +// String() will be used as the content-subtype in a case-insensitive manner. +// +// See Content-Type on +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. Also see the documentation on RegisterCodec and +// CallContentSubtype for more details on the interaction between Codec and +// content-subtype. +// +// This function is provided for advanced users; prefer to use only +// CallContentSubtype to select a registered codec instead. +func CallCustomCodec(codec Codec) CallOption { + return CustomCodecCallOption{Codec: codec} +} + +// CustomCodecCallOption is a CallOption that indicates the codec used for +// marshaling messages. +// This is an EXPERIMENTAL API. +type CustomCodecCallOption struct { + Codec Codec +} + +func (o CustomCodecCallOption) before(c *callInfo) error { + c.codec = o.Codec + return nil +} +func (o CustomCodecCallOption) after(c *callInfo) {} + +// MaxRetryRPCBufferSize returns a CallOption that limits the amount of memory +// used for buffering this RPC's requests for retry purposes. +// +// This API is EXPERIMENTAL. +func MaxRetryRPCBufferSize(bytes int) CallOption { + return MaxRetryRPCBufferSizeCallOption{bytes} +} + +// MaxRetryRPCBufferSizeCallOption is a CallOption indicating the amount of +// memory to be used for caching this RPC for retry purposes. +// This is an EXPERIMENTAL API. +type MaxRetryRPCBufferSizeCallOption struct { + MaxRetryRPCBufferSize int +} + +func (o MaxRetryRPCBufferSizeCallOption) before(c *callInfo) error { + c.maxRetryRPCBufferSize = o.MaxRetryRPCBufferSize + return nil +} +func (o MaxRetryRPCBufferSizeCallOption) after(c *callInfo) {} + +// The format of the payload: compressed or not? +type payloadFormat uint8 + +const ( + compressionNone payloadFormat = 0 // no compression + compressionMade payloadFormat = 1 // compressed +) + +// parser reads complete gRPC messages from the underlying reader. +type parser struct { + // r is the underlying reader. + // See the comment on recvMsg for the permissible + // error types. + r io.Reader + + // The header of a gRPC message. Find more detail at + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md + header [5]byte +} + +// recvMsg reads a complete gRPC message from the stream. +// +// It returns the message and its payload (compression/encoding) +// format. The caller owns the returned msg memory. +// +// If there is an error, possible values are: +// * io.EOF, when no messages remain +// * io.ErrUnexpectedEOF +// * of type transport.ConnectionError +// * an error from the status package +// No other error values or types must be returned, which also means +// that the underlying io.Reader must not return an incompatible +// error. +func (p *parser) recvMsg(maxReceiveMessageSize int) (pf payloadFormat, msg []byte, err error) { + if _, err := p.r.Read(p.header[:]); err != nil { + return 0, nil, err + } + + pf = payloadFormat(p.header[0]) + length := binary.BigEndian.Uint32(p.header[1:]) + + if length == 0 { + return pf, nil, nil + } + if int64(length) > int64(maxInt) { + return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max length allowed on current machine (%d vs. %d)", length, maxInt) + } + if int(length) > maxReceiveMessageSize { + return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", length, maxReceiveMessageSize) + } + // TODO(bradfitz,zhaoq): garbage. reuse buffer after proto decoding instead + // of making it for each message: + msg = make([]byte, int(length)) + if _, err := p.r.Read(msg); err != nil { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + return 0, nil, err + } + return pf, msg, nil +} + +// encode serializes msg and returns a buffer containing the message, or an +// error if it is too large to be transmitted by grpc. If msg is nil, it +// generates an empty message. +func encode(c baseCodec, msg interface{}) ([]byte, error) { + if msg == nil { // NOTE: typed nils will not be caught by this check + return nil, nil + } + b, err := c.Marshal(msg) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: error while marshaling: %v", err.Error()) + } + if uint(len(b)) > math.MaxUint32 { + return nil, status.Errorf(codes.ResourceExhausted, "grpc: message too large (%d bytes)", len(b)) + } + return b, nil +} + +// compress returns the input bytes compressed by compressor or cp. If both +// compressors are nil, returns nil. +// +// TODO(dfawley): eliminate cp parameter by wrapping Compressor in an encoding.Compressor. +func compress(in []byte, cp Compressor, compressor encoding.Compressor) ([]byte, error) { + if compressor == nil && cp == nil { + return nil, nil + } + wrapErr := func(err error) error { + return status.Errorf(codes.Internal, "grpc: error while compressing: %v", err.Error()) + } + cbuf := &bytes.Buffer{} + if compressor != nil { + z, err := compressor.Compress(cbuf) + if err != nil { + return nil, wrapErr(err) + } + if _, err := z.Write(in); err != nil { + return nil, wrapErr(err) + } + if err := z.Close(); err != nil { + return nil, wrapErr(err) + } + } else { + if err := cp.Do(cbuf, in); err != nil { + return nil, wrapErr(err) + } + } + return cbuf.Bytes(), nil +} + +const ( + payloadLen = 1 + sizeLen = 4 + headerLen = payloadLen + sizeLen +) + +// msgHeader returns a 5-byte header for the message being transmitted and the +// payload, which is compData if non-nil or data otherwise. +func msgHeader(data, compData []byte) (hdr []byte, payload []byte) { + hdr = make([]byte, headerLen) + if compData != nil { + hdr[0] = byte(compressionMade) + data = compData + } else { + hdr[0] = byte(compressionNone) + } + + // Write length of payload into buf + binary.BigEndian.PutUint32(hdr[payloadLen:], uint32(len(data))) + return hdr, data +} + +func outPayload(client bool, msg interface{}, data, payload []byte, t time.Time) *stats.OutPayload { + return &stats.OutPayload{ + Client: client, + Payload: msg, + Data: data, + Length: len(data), + WireLength: len(payload) + headerLen, + SentTime: t, + } +} + +func checkRecvPayload(pf payloadFormat, recvCompress string, haveCompressor bool) *status.Status { + switch pf { + case compressionNone: + case compressionMade: + if recvCompress == "" || recvCompress == encoding.Identity { + return status.New(codes.Internal, "grpc: compressed flag set with identity or empty encoding") + } + if !haveCompressor { + return status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", recvCompress) + } + default: + return status.Newf(codes.Internal, "grpc: received unexpected payload format %d", pf) + } + return nil +} + +type payloadInfo struct { + wireLength int // The compressed length got from wire. + uncompressedBytes []byte +} + +func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) ([]byte, error) { + pf, d, err := p.recvMsg(maxReceiveMessageSize) + if err != nil { + return nil, err + } + if payInfo != nil { + payInfo.wireLength = len(d) + } + + if st := checkRecvPayload(pf, s.RecvCompress(), compressor != nil || dc != nil); st != nil { + return nil, st.Err() + } + + if pf == compressionMade { + // To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor, + // use this decompressor as the default. + if dc != nil { + d, err = dc.Do(bytes.NewReader(d)) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + } else { + dcReader, err := compressor.Decompress(bytes.NewReader(d)) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + d, err = ioutil.ReadAll(dcReader) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + } + } + if len(d) > maxReceiveMessageSize { + // TODO: Revisit the error code. Currently keep it consistent with java + // implementation. + return nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", len(d), maxReceiveMessageSize) + } + return d, nil +} + +// For the two compressor parameters, both should not be set, but if they are, +// dc takes precedence over compressor. +// TODO(dfawley): wrap the old compressor/decompressor using the new API? +func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interface{}, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) error { + d, err := recvAndDecompress(p, s, dc, maxReceiveMessageSize, payInfo, compressor) + if err != nil { + return err + } + if err := c.Unmarshal(d, m); err != nil { + return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message %v", err) + } + if payInfo != nil { + payInfo.uncompressedBytes = d + } + return nil +} + +type rpcInfo struct { + failfast bool +} + +type rpcInfoContextKey struct{} + +func newContextWithRPCInfo(ctx context.Context, failfast bool) context.Context { + return context.WithValue(ctx, rpcInfoContextKey{}, &rpcInfo{failfast: failfast}) +} + +func rpcInfoFromContext(ctx context.Context) (s *rpcInfo, ok bool) { + s, ok = ctx.Value(rpcInfoContextKey{}).(*rpcInfo) + return +} + +// Code returns the error code for err if it was produced by the rpc system. +// Otherwise, it returns codes.Unknown. +// +// Deprecated: use status.FromError and Code method instead. +func Code(err error) codes.Code { + if s, ok := status.FromError(err); ok { + return s.Code() + } + return codes.Unknown +} + +// ErrorDesc returns the error description of err if it was produced by the rpc system. +// Otherwise, it returns err.Error() or empty string when err is nil. +// +// Deprecated: use status.FromError and Message method instead. +func ErrorDesc(err error) string { + if s, ok := status.FromError(err); ok { + return s.Message() + } + return err.Error() +} + +// Errorf returns an error containing an error code and a description; +// Errorf returns nil if c is OK. +// +// Deprecated: use status.Errorf instead. +func Errorf(c codes.Code, format string, a ...interface{}) error { + return status.Errorf(c, format, a...) +} + +// toRPCErr converts an error into an error from the status package. +func toRPCErr(err error) error { + if err == nil || err == io.EOF { + return err + } + if err == io.ErrUnexpectedEOF { + return status.Error(codes.Internal, err.Error()) + } + if _, ok := status.FromError(err); ok { + return err + } + switch e := err.(type) { + case transport.ConnectionError: + return status.Error(codes.Unavailable, e.Desc) + default: + switch err { + case context.DeadlineExceeded: + return status.Error(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return status.Error(codes.Canceled, err.Error()) + } + } + return status.Error(codes.Unknown, err.Error()) +} + +// setCallInfoCodec should only be called after CallOptions have been applied. +func setCallInfoCodec(c *callInfo) error { + if c.codec != nil { + // codec was already set by a CallOption; use it. + return nil + } + + if c.contentSubtype == "" { + // No codec specified in CallOptions; use proto by default. + c.codec = encoding.GetCodec(proto.Name) + return nil + } + + // c.contentSubtype is already lowercased in CallContentSubtype + c.codec = encoding.GetCodec(c.contentSubtype) + if c.codec == nil { + return status.Errorf(codes.Internal, "no codec registered for content-subtype %s", c.contentSubtype) + } + return nil +} + +// parseDialTarget returns the network and address to pass to dialer +func parseDialTarget(target string) (net string, addr string) { + net = "tcp" + + m1 := strings.Index(target, ":") + m2 := strings.Index(target, ":/") + + // handle unix:addr which will fail with url.Parse + if m1 >= 0 && m2 < 0 { + if n := target[0:m1]; n == "unix" { + net = n + addr = target[m1+1:] + return net, addr + } + } + if m2 >= 0 { + t, err := url.Parse(target) + if err != nil { + return net, target + } + scheme := t.Scheme + addr = t.Path + if scheme == "unix" { + net = scheme + if addr == "" { + addr = t.Host + } + return net, addr + } + } + + return net, target +} + +// channelzData is used to store channelz related data for ClientConn, addrConn and Server. +// These fields cannot be embedded in the original structs (e.g. ClientConn), since to do atomic +// operation on int64 variable on 32-bit machine, user is responsible to enforce memory alignment. +// Here, by grouping those int64 fields inside a struct, we are enforcing the alignment. +type channelzData struct { + callsStarted int64 + callsFailed int64 + callsSucceeded int64 + // lastCallStartedTime stores the timestamp that last call starts. It is of int64 type instead of + // time.Time since it's more costly to atomically update time.Time variable than int64 variable. + lastCallStartedTime int64 +} + +// The SupportPackageIsVersion variables are referenced from generated protocol +// buffer files to ensure compatibility with the gRPC version used. The latest +// support package version is 5. +// +// Older versions are kept for compatibility. They may be removed if +// compatibility cannot be maintained. +// +// These constants should not be referenced from any other code. +const ( + SupportPackageIsVersion3 = true + SupportPackageIsVersion4 = true + SupportPackageIsVersion5 = true +) + +const grpcUA = "grpc-go/" + Version diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go new file mode 100644 index 00000000..d705d7a8 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go @@ -0,0 +1,1486 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "fmt" + "io" + "math" + "net" + "net/http" + "reflect" + "runtime" + "strings" + "sync" + "sync/atomic" + "time" + + "golang.org/x/net/trace" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/binarylog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +const ( + defaultServerMaxReceiveMessageSize = 1024 * 1024 * 4 + defaultServerMaxSendMessageSize = math.MaxInt32 +) + +type methodHandler func(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor UnaryServerInterceptor) (interface{}, error) + +// MethodDesc represents an RPC service's method specification. +type MethodDesc struct { + MethodName string + Handler methodHandler +} + +// ServiceDesc represents an RPC service's specification. +type ServiceDesc struct { + ServiceName string + // The pointer to the service interface. Used to check whether the user + // provided implementation satisfies the interface requirements. + HandlerType interface{} + Methods []MethodDesc + Streams []StreamDesc + Metadata interface{} +} + +// service consists of the information of the server serving this service and +// the methods in this service. +type service struct { + server interface{} // the server for service methods + md map[string]*MethodDesc + sd map[string]*StreamDesc + mdata interface{} +} + +// Server is a gRPC server to serve RPC requests. +type Server struct { + opts options + + mu sync.Mutex // guards following + lis map[net.Listener]bool + conns map[io.Closer]bool + serve bool + drain bool + cv *sync.Cond // signaled when connections close for GracefulStop + m map[string]*service // service name -> service info + events trace.EventLog + + quit chan struct{} + done chan struct{} + quitOnce sync.Once + doneOnce sync.Once + channelzRemoveOnce sync.Once + serveWG sync.WaitGroup // counts active Serve goroutines for GracefulStop + + channelzID int64 // channelz unique identification number + czData *channelzData +} + +type options struct { + creds credentials.TransportCredentials + codec baseCodec + cp Compressor + dc Decompressor + unaryInt UnaryServerInterceptor + streamInt StreamServerInterceptor + inTapHandle tap.ServerInHandle + statsHandler stats.Handler + maxConcurrentStreams uint32 + maxReceiveMessageSize int + maxSendMessageSize int + unknownStreamDesc *StreamDesc + keepaliveParams keepalive.ServerParameters + keepalivePolicy keepalive.EnforcementPolicy + initialWindowSize int32 + initialConnWindowSize int32 + writeBufferSize int + readBufferSize int + connectionTimeout time.Duration + maxHeaderListSize *uint32 +} + +var defaultServerOptions = options{ + maxReceiveMessageSize: defaultServerMaxReceiveMessageSize, + maxSendMessageSize: defaultServerMaxSendMessageSize, + connectionTimeout: 120 * time.Second, + writeBufferSize: defaultWriteBufSize, + readBufferSize: defaultReadBufSize, +} + +// A ServerOption sets options such as credentials, codec and keepalive parameters, etc. +type ServerOption func(*options) + +// WriteBufferSize determines how much data can be batched before doing a write on the wire. +// The corresponding memory allocation for this buffer will be twice the size to keep syscalls low. +// The default value for this buffer is 32KB. +// Zero will disable the write buffer such that each write will be on underlying connection. +// Note: A Send call may not directly translate to a write. +func WriteBufferSize(s int) ServerOption { + return func(o *options) { + o.writeBufferSize = s + } +} + +// ReadBufferSize lets you set the size of read buffer, this determines how much data can be read at most +// for one read syscall. +// The default value for this buffer is 32KB. +// Zero will disable read buffer for a connection so data framer can access the underlying +// conn directly. +func ReadBufferSize(s int) ServerOption { + return func(o *options) { + o.readBufferSize = s + } +} + +// InitialWindowSize returns a ServerOption that sets window size for stream. +// The lower bound for window size is 64K and any value smaller than that will be ignored. +func InitialWindowSize(s int32) ServerOption { + return func(o *options) { + o.initialWindowSize = s + } +} + +// InitialConnWindowSize returns a ServerOption that sets window size for a connection. +// The lower bound for window size is 64K and any value smaller than that will be ignored. +func InitialConnWindowSize(s int32) ServerOption { + return func(o *options) { + o.initialConnWindowSize = s + } +} + +// KeepaliveParams returns a ServerOption that sets keepalive and max-age parameters for the server. +func KeepaliveParams(kp keepalive.ServerParameters) ServerOption { + return func(o *options) { + o.keepaliveParams = kp + } +} + +// KeepaliveEnforcementPolicy returns a ServerOption that sets keepalive enforcement policy for the server. +func KeepaliveEnforcementPolicy(kep keepalive.EnforcementPolicy) ServerOption { + return func(o *options) { + o.keepalivePolicy = kep + } +} + +// CustomCodec returns a ServerOption that sets a codec for message marshaling and unmarshaling. +// +// This will override any lookups by content-subtype for Codecs registered with RegisterCodec. +func CustomCodec(codec Codec) ServerOption { + return func(o *options) { + o.codec = codec + } +} + +// RPCCompressor returns a ServerOption that sets a compressor for outbound +// messages. For backward compatibility, all outbound messages will be sent +// using this compressor, regardless of incoming message compression. By +// default, server messages will be sent using the same compressor with which +// request messages were sent. +// +// Deprecated: use encoding.RegisterCompressor instead. +func RPCCompressor(cp Compressor) ServerOption { + return func(o *options) { + o.cp = cp + } +} + +// RPCDecompressor returns a ServerOption that sets a decompressor for inbound +// messages. It has higher priority than decompressors registered via +// encoding.RegisterCompressor. +// +// Deprecated: use encoding.RegisterCompressor instead. +func RPCDecompressor(dc Decompressor) ServerOption { + return func(o *options) { + o.dc = dc + } +} + +// MaxMsgSize returns a ServerOption to set the max message size in bytes the server can receive. +// If this is not set, gRPC uses the default limit. +// +// Deprecated: use MaxRecvMsgSize instead. +func MaxMsgSize(m int) ServerOption { + return MaxRecvMsgSize(m) +} + +// MaxRecvMsgSize returns a ServerOption to set the max message size in bytes the server can receive. +// If this is not set, gRPC uses the default 4MB. +func MaxRecvMsgSize(m int) ServerOption { + return func(o *options) { + o.maxReceiveMessageSize = m + } +} + +// MaxSendMsgSize returns a ServerOption to set the max message size in bytes the server can send. +// If this is not set, gRPC uses the default 4MB. +func MaxSendMsgSize(m int) ServerOption { + return func(o *options) { + o.maxSendMessageSize = m + } +} + +// MaxConcurrentStreams returns a ServerOption that will apply a limit on the number +// of concurrent streams to each ServerTransport. +func MaxConcurrentStreams(n uint32) ServerOption { + return func(o *options) { + o.maxConcurrentStreams = n + } +} + +// Creds returns a ServerOption that sets credentials for server connections. +func Creds(c credentials.TransportCredentials) ServerOption { + return func(o *options) { + o.creds = c + } +} + +// UnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the +// server. Only one unary interceptor can be installed. The construction of multiple +// interceptors (e.g., chaining) can be implemented at the caller. +func UnaryInterceptor(i UnaryServerInterceptor) ServerOption { + return func(o *options) { + if o.unaryInt != nil { + panic("The unary server interceptor was already set and may not be reset.") + } + o.unaryInt = i + } +} + +// StreamInterceptor returns a ServerOption that sets the StreamServerInterceptor for the +// server. Only one stream interceptor can be installed. +func StreamInterceptor(i StreamServerInterceptor) ServerOption { + return func(o *options) { + if o.streamInt != nil { + panic("The stream server interceptor was already set and may not be reset.") + } + o.streamInt = i + } +} + +// InTapHandle returns a ServerOption that sets the tap handle for all the server +// transport to be created. Only one can be installed. +func InTapHandle(h tap.ServerInHandle) ServerOption { + return func(o *options) { + if o.inTapHandle != nil { + panic("The tap handle was already set and may not be reset.") + } + o.inTapHandle = h + } +} + +// StatsHandler returns a ServerOption that sets the stats handler for the server. +func StatsHandler(h stats.Handler) ServerOption { + return func(o *options) { + o.statsHandler = h + } +} + +// UnknownServiceHandler returns a ServerOption that allows for adding a custom +// unknown service handler. The provided method is a bidi-streaming RPC service +// handler that will be invoked instead of returning the "unimplemented" gRPC +// error whenever a request is received for an unregistered service or method. +// The handling function has full access to the Context of the request and the +// stream, and the invocation bypasses interceptors. +func UnknownServiceHandler(streamHandler StreamHandler) ServerOption { + return func(o *options) { + o.unknownStreamDesc = &StreamDesc{ + StreamName: "unknown_service_handler", + Handler: streamHandler, + // We need to assume that the users of the streamHandler will want to use both. + ClientStreams: true, + ServerStreams: true, + } + } +} + +// ConnectionTimeout returns a ServerOption that sets the timeout for +// connection establishment (up to and including HTTP/2 handshaking) for all +// new connections. If this is not set, the default is 120 seconds. A zero or +// negative value will result in an immediate timeout. +// +// This API is EXPERIMENTAL. +func ConnectionTimeout(d time.Duration) ServerOption { + return func(o *options) { + o.connectionTimeout = d + } +} + +// MaxHeaderListSize returns a ServerOption that sets the max (uncompressed) size +// of header list that the server is prepared to accept. +func MaxHeaderListSize(s uint32) ServerOption { + return func(o *options) { + o.maxHeaderListSize = &s + } +} + +// NewServer creates a gRPC server which has no service registered and has not +// started to accept requests yet. +func NewServer(opt ...ServerOption) *Server { + opts := defaultServerOptions + for _, o := range opt { + o(&opts) + } + s := &Server{ + lis: make(map[net.Listener]bool), + opts: opts, + conns: make(map[io.Closer]bool), + m: make(map[string]*service), + quit: make(chan struct{}), + done: make(chan struct{}), + czData: new(channelzData), + } + s.cv = sync.NewCond(&s.mu) + if EnableTracing { + _, file, line, _ := runtime.Caller(1) + s.events = trace.NewEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line)) + } + + if channelz.IsOn() { + s.channelzID = channelz.RegisterServer(&channelzServer{s}, "") + } + return s +} + +// printf records an event in s's event log, unless s has been stopped. +// REQUIRES s.mu is held. +func (s *Server) printf(format string, a ...interface{}) { + if s.events != nil { + s.events.Printf(format, a...) + } +} + +// errorf records an error in s's event log, unless s has been stopped. +// REQUIRES s.mu is held. +func (s *Server) errorf(format string, a ...interface{}) { + if s.events != nil { + s.events.Errorf(format, a...) + } +} + +// RegisterService registers a service and its implementation to the gRPC +// server. It is called from the IDL generated code. This must be called before +// invoking Serve. +func (s *Server) RegisterService(sd *ServiceDesc, ss interface{}) { + ht := reflect.TypeOf(sd.HandlerType).Elem() + st := reflect.TypeOf(ss) + if !st.Implements(ht) { + grpclog.Fatalf("grpc: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht) + } + s.register(sd, ss) +} + +func (s *Server) register(sd *ServiceDesc, ss interface{}) { + s.mu.Lock() + defer s.mu.Unlock() + s.printf("RegisterService(%q)", sd.ServiceName) + if s.serve { + grpclog.Fatalf("grpc: Server.RegisterService after Server.Serve for %q", sd.ServiceName) + } + if _, ok := s.m[sd.ServiceName]; ok { + grpclog.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName) + } + srv := &service{ + server: ss, + md: make(map[string]*MethodDesc), + sd: make(map[string]*StreamDesc), + mdata: sd.Metadata, + } + for i := range sd.Methods { + d := &sd.Methods[i] + srv.md[d.MethodName] = d + } + for i := range sd.Streams { + d := &sd.Streams[i] + srv.sd[d.StreamName] = d + } + s.m[sd.ServiceName] = srv +} + +// MethodInfo contains the information of an RPC including its method name and type. +type MethodInfo struct { + // Name is the method name only, without the service name or package name. + Name string + // IsClientStream indicates whether the RPC is a client streaming RPC. + IsClientStream bool + // IsServerStream indicates whether the RPC is a server streaming RPC. + IsServerStream bool +} + +// ServiceInfo contains unary RPC method info, streaming RPC method info and metadata for a service. +type ServiceInfo struct { + Methods []MethodInfo + // Metadata is the metadata specified in ServiceDesc when registering service. + Metadata interface{} +} + +// GetServiceInfo returns a map from service names to ServiceInfo. +// Service names include the package names, in the form of .. +func (s *Server) GetServiceInfo() map[string]ServiceInfo { + ret := make(map[string]ServiceInfo) + for n, srv := range s.m { + methods := make([]MethodInfo, 0, len(srv.md)+len(srv.sd)) + for m := range srv.md { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: false, + IsServerStream: false, + }) + } + for m, d := range srv.sd { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: d.ClientStreams, + IsServerStream: d.ServerStreams, + }) + } + + ret[n] = ServiceInfo{ + Methods: methods, + Metadata: srv.mdata, + } + } + return ret +} + +// ErrServerStopped indicates that the operation is now illegal because of +// the server being stopped. +var ErrServerStopped = errors.New("grpc: the server has been stopped") + +func (s *Server) useTransportAuthenticator(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) { + if s.opts.creds == nil { + return rawConn, nil, nil + } + return s.opts.creds.ServerHandshake(rawConn) +} + +type listenSocket struct { + net.Listener + channelzID int64 +} + +func (l *listenSocket) ChannelzMetric() *channelz.SocketInternalMetric { + return &channelz.SocketInternalMetric{ + SocketOptions: channelz.GetSocketOption(l.Listener), + LocalAddr: l.Listener.Addr(), + } +} + +func (l *listenSocket) Close() error { + err := l.Listener.Close() + if channelz.IsOn() { + channelz.RemoveEntry(l.channelzID) + } + return err +} + +// Serve accepts incoming connections on the listener lis, creating a new +// ServerTransport and service goroutine for each. The service goroutines +// read gRPC requests and then call the registered handlers to reply to them. +// Serve returns when lis.Accept fails with fatal errors. lis will be closed when +// this method returns. +// Serve will return a non-nil error unless Stop or GracefulStop is called. +func (s *Server) Serve(lis net.Listener) error { + s.mu.Lock() + s.printf("serving") + s.serve = true + if s.lis == nil { + // Serve called after Stop or GracefulStop. + s.mu.Unlock() + lis.Close() + return ErrServerStopped + } + + s.serveWG.Add(1) + defer func() { + s.serveWG.Done() + select { + // Stop or GracefulStop called; block until done and return nil. + case <-s.quit: + <-s.done + default: + } + }() + + ls := &listenSocket{Listener: lis} + s.lis[ls] = true + + if channelz.IsOn() { + ls.channelzID = channelz.RegisterListenSocket(ls, s.channelzID, lis.Addr().String()) + } + s.mu.Unlock() + + defer func() { + s.mu.Lock() + if s.lis != nil && s.lis[ls] { + ls.Close() + delete(s.lis, ls) + } + s.mu.Unlock() + }() + + var tempDelay time.Duration // how long to sleep on accept failure + + for { + rawConn, err := lis.Accept() + if err != nil { + if ne, ok := err.(interface { + Temporary() bool + }); ok && ne.Temporary() { + if tempDelay == 0 { + tempDelay = 5 * time.Millisecond + } else { + tempDelay *= 2 + } + if max := 1 * time.Second; tempDelay > max { + tempDelay = max + } + s.mu.Lock() + s.printf("Accept error: %v; retrying in %v", err, tempDelay) + s.mu.Unlock() + timer := time.NewTimer(tempDelay) + select { + case <-timer.C: + case <-s.quit: + timer.Stop() + return nil + } + continue + } + s.mu.Lock() + s.printf("done serving; Accept = %v", err) + s.mu.Unlock() + + select { + case <-s.quit: + return nil + default: + } + return err + } + tempDelay = 0 + // Start a new goroutine to deal with rawConn so we don't stall this Accept + // loop goroutine. + // + // Make sure we account for the goroutine so GracefulStop doesn't nil out + // s.conns before this conn can be added. + s.serveWG.Add(1) + go func() { + s.handleRawConn(rawConn) + s.serveWG.Done() + }() + } +} + +// handleRawConn forks a goroutine to handle a just-accepted connection that +// has not had any I/O performed on it yet. +func (s *Server) handleRawConn(rawConn net.Conn) { + rawConn.SetDeadline(time.Now().Add(s.opts.connectionTimeout)) + conn, authInfo, err := s.useTransportAuthenticator(rawConn) + if err != nil { + s.mu.Lock() + s.errorf("ServerHandshake(%q) failed: %v", rawConn.RemoteAddr(), err) + s.mu.Unlock() + grpclog.Warningf("grpc: Server.Serve failed to complete security handshake from %q: %v", rawConn.RemoteAddr(), err) + // If serverHandshake returns ErrConnDispatched, keep rawConn open. + if err != credentials.ErrConnDispatched { + rawConn.Close() + } + rawConn.SetDeadline(time.Time{}) + return + } + + s.mu.Lock() + if s.conns == nil { + s.mu.Unlock() + conn.Close() + return + } + s.mu.Unlock() + + // Finish handshaking (HTTP2) + st := s.newHTTP2Transport(conn, authInfo) + if st == nil { + return + } + + rawConn.SetDeadline(time.Time{}) + if !s.addConn(st) { + return + } + go func() { + s.serveStreams(st) + s.removeConn(st) + }() +} + +// newHTTP2Transport sets up a http/2 transport (using the +// gRPC http2 server transport in transport/http2_server.go). +func (s *Server) newHTTP2Transport(c net.Conn, authInfo credentials.AuthInfo) transport.ServerTransport { + config := &transport.ServerConfig{ + MaxStreams: s.opts.maxConcurrentStreams, + AuthInfo: authInfo, + InTapHandle: s.opts.inTapHandle, + StatsHandler: s.opts.statsHandler, + KeepaliveParams: s.opts.keepaliveParams, + KeepalivePolicy: s.opts.keepalivePolicy, + InitialWindowSize: s.opts.initialWindowSize, + InitialConnWindowSize: s.opts.initialConnWindowSize, + WriteBufferSize: s.opts.writeBufferSize, + ReadBufferSize: s.opts.readBufferSize, + ChannelzParentID: s.channelzID, + MaxHeaderListSize: s.opts.maxHeaderListSize, + } + st, err := transport.NewServerTransport("http2", c, config) + if err != nil { + s.mu.Lock() + s.errorf("NewServerTransport(%q) failed: %v", c.RemoteAddr(), err) + s.mu.Unlock() + c.Close() + grpclog.Warningln("grpc: Server.Serve failed to create ServerTransport: ", err) + return nil + } + + return st +} + +func (s *Server) serveStreams(st transport.ServerTransport) { + defer st.Close() + var wg sync.WaitGroup + st.HandleStreams(func(stream *transport.Stream) { + wg.Add(1) + go func() { + defer wg.Done() + s.handleStream(st, stream, s.traceInfo(st, stream)) + }() + }, func(ctx context.Context, method string) context.Context { + if !EnableTracing { + return ctx + } + tr := trace.New("grpc.Recv."+methodFamily(method), method) + return trace.NewContext(ctx, tr) + }) + wg.Wait() +} + +var _ http.Handler = (*Server)(nil) + +// ServeHTTP implements the Go standard library's http.Handler +// interface by responding to the gRPC request r, by looking up +// the requested gRPC method in the gRPC server s. +// +// The provided HTTP request must have arrived on an HTTP/2 +// connection. When using the Go standard library's server, +// practically this means that the Request must also have arrived +// over TLS. +// +// To share one port (such as 443 for https) between gRPC and an +// existing http.Handler, use a root http.Handler such as: +// +// if r.ProtoMajor == 2 && strings.HasPrefix( +// r.Header.Get("Content-Type"), "application/grpc") { +// grpcServer.ServeHTTP(w, r) +// } else { +// yourMux.ServeHTTP(w, r) +// } +// +// Note that ServeHTTP uses Go's HTTP/2 server implementation which is totally +// separate from grpc-go's HTTP/2 server. Performance and features may vary +// between the two paths. ServeHTTP does not support some gRPC features +// available through grpc-go's HTTP/2 server, and it is currently EXPERIMENTAL +// and subject to change. +func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + st, err := transport.NewServerHandlerTransport(w, r, s.opts.statsHandler) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + if !s.addConn(st) { + return + } + defer s.removeConn(st) + s.serveStreams(st) +} + +// traceInfo returns a traceInfo and associates it with stream, if tracing is enabled. +// If tracing is not enabled, it returns nil. +func (s *Server) traceInfo(st transport.ServerTransport, stream *transport.Stream) (trInfo *traceInfo) { + tr, ok := trace.FromContext(stream.Context()) + if !ok { + return nil + } + + trInfo = &traceInfo{ + tr: tr, + } + trInfo.firstLine.client = false + trInfo.firstLine.remoteAddr = st.RemoteAddr() + + if dl, ok := stream.Context().Deadline(); ok { + trInfo.firstLine.deadline = dl.Sub(time.Now()) + } + return trInfo +} + +func (s *Server) addConn(c io.Closer) bool { + s.mu.Lock() + defer s.mu.Unlock() + if s.conns == nil { + c.Close() + return false + } + if s.drain { + // Transport added after we drained our existing conns: drain it + // immediately. + c.(transport.ServerTransport).Drain() + } + s.conns[c] = true + return true +} + +func (s *Server) removeConn(c io.Closer) { + s.mu.Lock() + defer s.mu.Unlock() + if s.conns != nil { + delete(s.conns, c) + s.cv.Broadcast() + } +} + +func (s *Server) channelzMetric() *channelz.ServerInternalMetric { + return &channelz.ServerInternalMetric{ + CallsStarted: atomic.LoadInt64(&s.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&s.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&s.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&s.czData.lastCallStartedTime)), + } +} + +func (s *Server) incrCallsStarted() { + atomic.AddInt64(&s.czData.callsStarted, 1) + atomic.StoreInt64(&s.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (s *Server) incrCallsSucceeded() { + atomic.AddInt64(&s.czData.callsSucceeded, 1) +} + +func (s *Server) incrCallsFailed() { + atomic.AddInt64(&s.czData.callsFailed, 1) +} + +func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Stream, msg interface{}, cp Compressor, opts *transport.Options, comp encoding.Compressor) error { + data, err := encode(s.getCodec(stream.ContentSubtype()), msg) + if err != nil { + grpclog.Errorln("grpc: server failed to encode response: ", err) + return err + } + compData, err := compress(data, cp, comp) + if err != nil { + grpclog.Errorln("grpc: server failed to compress response: ", err) + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > s.opts.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(payload), s.opts.maxSendMessageSize) + } + err = t.Write(stream, hdr, payload, opts) + if err == nil && s.opts.statsHandler != nil { + s.opts.statsHandler.HandleRPC(stream.Context(), outPayload(false, msg, data, payload, time.Now())) + } + return err +} + +func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, md *MethodDesc, trInfo *traceInfo) (err error) { + if channelz.IsOn() { + s.incrCallsStarted() + defer func() { + if err != nil && err != io.EOF { + s.incrCallsFailed() + } else { + s.incrCallsSucceeded() + } + }() + } + sh := s.opts.statsHandler + if sh != nil { + beginTime := time.Now() + begin := &stats.Begin{ + BeginTime: beginTime, + } + sh.HandleRPC(stream.Context(), begin) + defer func() { + end := &stats.End{ + BeginTime: beginTime, + EndTime: time.Now(), + } + if err != nil && err != io.EOF { + end.Error = toRPCErr(err) + } + sh.HandleRPC(stream.Context(), end) + }() + } + if trInfo != nil { + defer trInfo.tr.Finish() + trInfo.firstLine.client = false + trInfo.tr.LazyLog(&trInfo.firstLine, false) + defer func() { + if err != nil && err != io.EOF { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + }() + } + + binlog := binarylog.GetMethodLogger(stream.Method()) + if binlog != nil { + ctx := stream.Context() + md, _ := metadata.FromIncomingContext(ctx) + logEntry := &binarylog.ClientHeader{ + Header: md, + MethodName: stream.Method(), + PeerAddr: nil, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + if a := md[":authority"]; len(a) > 0 { + logEntry.Authority = a[0] + } + if peer, ok := peer.FromContext(ctx); ok { + logEntry.PeerAddr = peer.Addr + } + binlog.Log(logEntry) + } + + // comp and cp are used for compression. decomp and dc are used for + // decompression. If comp and decomp are both set, they are the same; + // however they are kept separate to ensure that at most one of the + // compressor/decompressor variable pairs are set for use later. + var comp, decomp encoding.Compressor + var cp Compressor + var dc Decompressor + + // If dc is set and matches the stream's compression, use it. Otherwise, try + // to find a matching registered compressor for decomp. + if rc := stream.RecvCompress(); s.opts.dc != nil && s.opts.dc.Type() == rc { + dc = s.opts.dc + } else if rc != "" && rc != encoding.Identity { + decomp = encoding.GetCompressor(rc) + if decomp == nil { + st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) + t.WriteStatus(stream, st) + return st.Err() + } + } + + // If cp is set, use it. Otherwise, attempt to compress the response using + // the incoming message compression method. + // + // NOTE: this needs to be ahead of all handling, https://github.com/grpc/grpc-go/issues/686. + if s.opts.cp != nil { + cp = s.opts.cp + stream.SetSendCompress(cp.Type()) + } else if rc := stream.RecvCompress(); rc != "" && rc != encoding.Identity { + // Legacy compressor not specified; attempt to respond with same encoding. + comp = encoding.GetCompressor(rc) + if comp != nil { + stream.SetSendCompress(rc) + } + } + + var payInfo *payloadInfo + if sh != nil || binlog != nil { + payInfo = &payloadInfo{} + } + d, err := recvAndDecompress(&parser{r: stream}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp) + if err != nil { + if st, ok := status.FromError(err); ok { + if e := t.WriteStatus(stream, st); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status %v", e) + } + } + return err + } + if channelz.IsOn() { + t.IncrMsgRecv() + } + df := func(v interface{}) error { + if err := s.getCodec(stream.ContentSubtype()).Unmarshal(d, v); err != nil { + return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err) + } + if sh != nil { + sh.HandleRPC(stream.Context(), &stats.InPayload{ + RecvTime: time.Now(), + Payload: v, + Data: d, + Length: len(d), + }) + } + if binlog != nil { + binlog.Log(&binarylog.ClientMessage{ + Message: d, + }) + } + if trInfo != nil { + trInfo.tr.LazyLog(&payload{sent: false, msg: v}, true) + } + return nil + } + ctx := NewContextWithServerTransportStream(stream.Context(), stream) + reply, appErr := md.Handler(srv.server, ctx, df, s.opts.unaryInt) + if appErr != nil { + appStatus, ok := status.FromError(appErr) + if !ok { + // Convert appErr if it is not a grpc status error. + appErr = status.Error(codes.Unknown, appErr.Error()) + appStatus, _ = status.FromError(appErr) + } + if trInfo != nil { + trInfo.tr.LazyLog(stringer(appStatus.Message()), true) + trInfo.tr.SetError() + } + if e := t.WriteStatus(stream, appStatus); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status: %v", e) + } + if binlog != nil { + if h, _ := stream.Header(); h.Len() > 0 { + // Only log serverHeader if there was header. Otherwise it can + // be trailer only. + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + } + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return appErr + } + if trInfo != nil { + trInfo.tr.LazyLog(stringer("OK"), false) + } + opts := &transport.Options{Last: true} + + if err := s.sendResponse(t, stream, reply, cp, opts, comp); err != nil { + if err == io.EOF { + // The entire stream is done (for unary RPC only). + return err + } + if s, ok := status.FromError(err); ok { + if e := t.WriteStatus(stream, s); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status: %v", e) + } + } else { + switch st := err.(type) { + case transport.ConnectionError: + // Nothing to do here. + default: + panic(fmt.Sprintf("grpc: Unexpected error (%T) from sendResponse: %v", st, st)) + } + } + if binlog != nil { + h, _ := stream.Header() + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return err + } + if binlog != nil { + h, _ := stream.Header() + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + binlog.Log(&binarylog.ServerMessage{ + Message: reply, + }) + } + if channelz.IsOn() { + t.IncrMsgSent() + } + if trInfo != nil { + trInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true) + } + // TODO: Should we be logging if writing status failed here, like above? + // Should the logging be in WriteStatus? Should we ignore the WriteStatus + // error or allow the stats handler to see it? + err = t.WriteStatus(stream, status.New(codes.OK, "")) + if binlog != nil { + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return err +} + +func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, sd *StreamDesc, trInfo *traceInfo) (err error) { + if channelz.IsOn() { + s.incrCallsStarted() + defer func() { + if err != nil && err != io.EOF { + s.incrCallsFailed() + } else { + s.incrCallsSucceeded() + } + }() + } + sh := s.opts.statsHandler + if sh != nil { + beginTime := time.Now() + begin := &stats.Begin{ + BeginTime: beginTime, + } + sh.HandleRPC(stream.Context(), begin) + defer func() { + end := &stats.End{ + BeginTime: beginTime, + EndTime: time.Now(), + } + if err != nil && err != io.EOF { + end.Error = toRPCErr(err) + } + sh.HandleRPC(stream.Context(), end) + }() + } + ctx := NewContextWithServerTransportStream(stream.Context(), stream) + ss := &serverStream{ + ctx: ctx, + t: t, + s: stream, + p: &parser{r: stream}, + codec: s.getCodec(stream.ContentSubtype()), + maxReceiveMessageSize: s.opts.maxReceiveMessageSize, + maxSendMessageSize: s.opts.maxSendMessageSize, + trInfo: trInfo, + statsHandler: sh, + } + + ss.binlog = binarylog.GetMethodLogger(stream.Method()) + if ss.binlog != nil { + md, _ := metadata.FromIncomingContext(ctx) + logEntry := &binarylog.ClientHeader{ + Header: md, + MethodName: stream.Method(), + PeerAddr: nil, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + if a := md[":authority"]; len(a) > 0 { + logEntry.Authority = a[0] + } + if peer, ok := peer.FromContext(ss.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + ss.binlog.Log(logEntry) + } + + // If dc is set and matches the stream's compression, use it. Otherwise, try + // to find a matching registered compressor for decomp. + if rc := stream.RecvCompress(); s.opts.dc != nil && s.opts.dc.Type() == rc { + ss.dc = s.opts.dc + } else if rc != "" && rc != encoding.Identity { + ss.decomp = encoding.GetCompressor(rc) + if ss.decomp == nil { + st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) + t.WriteStatus(ss.s, st) + return st.Err() + } + } + + // If cp is set, use it. Otherwise, attempt to compress the response using + // the incoming message compression method. + // + // NOTE: this needs to be ahead of all handling, https://github.com/grpc/grpc-go/issues/686. + if s.opts.cp != nil { + ss.cp = s.opts.cp + stream.SetSendCompress(s.opts.cp.Type()) + } else if rc := stream.RecvCompress(); rc != "" && rc != encoding.Identity { + // Legacy compressor not specified; attempt to respond with same encoding. + ss.comp = encoding.GetCompressor(rc) + if ss.comp != nil { + stream.SetSendCompress(rc) + } + } + + if trInfo != nil { + trInfo.tr.LazyLog(&trInfo.firstLine, false) + defer func() { + ss.mu.Lock() + if err != nil && err != io.EOF { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + ss.trInfo.tr.Finish() + ss.trInfo.tr = nil + ss.mu.Unlock() + }() + } + var appErr error + var server interface{} + if srv != nil { + server = srv.server + } + if s.opts.streamInt == nil { + appErr = sd.Handler(server, ss) + } else { + info := &StreamServerInfo{ + FullMethod: stream.Method(), + IsClientStream: sd.ClientStreams, + IsServerStream: sd.ServerStreams, + } + appErr = s.opts.streamInt(server, ss, info, sd.Handler) + } + if appErr != nil { + appStatus, ok := status.FromError(appErr) + if !ok { + appStatus = status.New(codes.Unknown, appErr.Error()) + appErr = appStatus.Err() + } + if trInfo != nil { + ss.mu.Lock() + ss.trInfo.tr.LazyLog(stringer(appStatus.Message()), true) + ss.trInfo.tr.SetError() + ss.mu.Unlock() + } + t.WriteStatus(ss.s, appStatus) + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ServerTrailer{ + Trailer: ss.s.Trailer(), + Err: appErr, + }) + } + // TODO: Should we log an error from WriteStatus here and below? + return appErr + } + if trInfo != nil { + ss.mu.Lock() + ss.trInfo.tr.LazyLog(stringer("OK"), false) + ss.mu.Unlock() + } + err = t.WriteStatus(ss.s, status.New(codes.OK, "")) + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ServerTrailer{ + Trailer: ss.s.Trailer(), + Err: appErr, + }) + } + return err +} + +func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Stream, trInfo *traceInfo) { + sm := stream.Method() + if sm != "" && sm[0] == '/' { + sm = sm[1:] + } + pos := strings.LastIndex(sm, "/") + if pos == -1 { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"Malformed method name %q", []interface{}{sm}}, true) + trInfo.tr.SetError() + } + errDesc := fmt.Sprintf("malformed method name: %q", stream.Method()) + if err := t.WriteStatus(stream, status.New(codes.ResourceExhausted, errDesc)); err != nil { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + grpclog.Warningf("grpc: Server.handleStream failed to write status: %v", err) + } + if trInfo != nil { + trInfo.tr.Finish() + } + return + } + service := sm[:pos] + method := sm[pos+1:] + + if srv, ok := s.m[service]; ok { + if md, ok := srv.md[method]; ok { + s.processUnaryRPC(t, stream, srv, md, trInfo) + return + } + if sd, ok := srv.sd[method]; ok { + s.processStreamingRPC(t, stream, srv, sd, trInfo) + return + } + } + // Unknown service, or known server unknown method. + if unknownDesc := s.opts.unknownStreamDesc; unknownDesc != nil { + s.processStreamingRPC(t, stream, nil, unknownDesc, trInfo) + return + } + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"Unknown service %v", []interface{}{service}}, true) + trInfo.tr.SetError() + } + errDesc := fmt.Sprintf("unknown service %v", service) + if err := t.WriteStatus(stream, status.New(codes.Unimplemented, errDesc)); err != nil { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + grpclog.Warningf("grpc: Server.handleStream failed to write status: %v", err) + } + if trInfo != nil { + trInfo.tr.Finish() + } +} + +// The key to save ServerTransportStream in the context. +type streamKey struct{} + +// NewContextWithServerTransportStream creates a new context from ctx and +// attaches stream to it. +// +// This API is EXPERIMENTAL. +func NewContextWithServerTransportStream(ctx context.Context, stream ServerTransportStream) context.Context { + return context.WithValue(ctx, streamKey{}, stream) +} + +// ServerTransportStream is a minimal interface that a transport stream must +// implement. This can be used to mock an actual transport stream for tests of +// handler code that use, for example, grpc.SetHeader (which requires some +// stream to be in context). +// +// See also NewContextWithServerTransportStream. +// +// This API is EXPERIMENTAL. +type ServerTransportStream interface { + Method() string + SetHeader(md metadata.MD) error + SendHeader(md metadata.MD) error + SetTrailer(md metadata.MD) error +} + +// ServerTransportStreamFromContext returns the ServerTransportStream saved in +// ctx. Returns nil if the given context has no stream associated with it +// (which implies it is not an RPC invocation context). +// +// This API is EXPERIMENTAL. +func ServerTransportStreamFromContext(ctx context.Context) ServerTransportStream { + s, _ := ctx.Value(streamKey{}).(ServerTransportStream) + return s +} + +// Stop stops the gRPC server. It immediately closes all open +// connections and listeners. +// It cancels all active RPCs on the server side and the corresponding +// pending RPCs on the client side will get notified by connection +// errors. +func (s *Server) Stop() { + s.quitOnce.Do(func() { + close(s.quit) + }) + + defer func() { + s.serveWG.Wait() + s.doneOnce.Do(func() { + close(s.done) + }) + }() + + s.channelzRemoveOnce.Do(func() { + if channelz.IsOn() { + channelz.RemoveEntry(s.channelzID) + } + }) + + s.mu.Lock() + listeners := s.lis + s.lis = nil + st := s.conns + s.conns = nil + // interrupt GracefulStop if Stop and GracefulStop are called concurrently. + s.cv.Broadcast() + s.mu.Unlock() + + for lis := range listeners { + lis.Close() + } + for c := range st { + c.Close() + } + + s.mu.Lock() + if s.events != nil { + s.events.Finish() + s.events = nil + } + s.mu.Unlock() +} + +// GracefulStop stops the gRPC server gracefully. It stops the server from +// accepting new connections and RPCs and blocks until all the pending RPCs are +// finished. +func (s *Server) GracefulStop() { + s.quitOnce.Do(func() { + close(s.quit) + }) + + defer func() { + s.doneOnce.Do(func() { + close(s.done) + }) + }() + + s.channelzRemoveOnce.Do(func() { + if channelz.IsOn() { + channelz.RemoveEntry(s.channelzID) + } + }) + s.mu.Lock() + if s.conns == nil { + s.mu.Unlock() + return + } + + for lis := range s.lis { + lis.Close() + } + s.lis = nil + if !s.drain { + for c := range s.conns { + c.(transport.ServerTransport).Drain() + } + s.drain = true + } + + // Wait for serving threads to be ready to exit. Only then can we be sure no + // new conns will be created. + s.mu.Unlock() + s.serveWG.Wait() + s.mu.Lock() + + for len(s.conns) != 0 { + s.cv.Wait() + } + s.conns = nil + if s.events != nil { + s.events.Finish() + s.events = nil + } + s.mu.Unlock() +} + +// contentSubtype must be lowercase +// cannot return nil +func (s *Server) getCodec(contentSubtype string) baseCodec { + if s.opts.codec != nil { + return s.opts.codec + } + if contentSubtype == "" { + return encoding.GetCodec(proto.Name) + } + codec := encoding.GetCodec(contentSubtype) + if codec == nil { + return encoding.GetCodec(proto.Name) + } + return codec +} + +// SetHeader sets the header metadata. +// When called multiple times, all the provided metadata will be merged. +// All the metadata will be sent out when one of the following happens: +// - grpc.SendHeader() is called; +// - The first response is sent out; +// - An RPC status is sent out (error or success). +func SetHeader(ctx context.Context, md metadata.MD) error { + if md.Len() == 0 { + return nil + } + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + return stream.SetHeader(md) +} + +// SendHeader sends header metadata. It may be called at most once. +// The provided md and headers set by SetHeader() will be sent. +func SendHeader(ctx context.Context, md metadata.MD) error { + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + if err := stream.SendHeader(md); err != nil { + return toRPCErr(err) + } + return nil +} + +// SetTrailer sets the trailer metadata that will be sent when an RPC returns. +// When called more than once, all the provided metadata will be merged. +func SetTrailer(ctx context.Context, md metadata.MD) error { + if md.Len() == 0 { + return nil + } + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + return stream.SetTrailer(md) +} + +// Method returns the method string for the server context. The returned +// string is in the format of "/service/method". +func Method(ctx context.Context) (string, bool) { + s := ServerTransportStreamFromContext(ctx) + if s == nil { + return "", false + } + return s.Method(), true +} + +type channelzServer struct { + s *Server +} + +func (c *channelzServer) ChannelzMetric() *channelz.ServerInternalMetric { + return c.s.channelzMetric() +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go new file mode 100644 index 00000000..162857e2 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go @@ -0,0 +1,372 @@ +/* + * + * 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 grpc + +import ( + "encoding/json" + "fmt" + "strconv" + "strings" + "time" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" +) + +const maxInt = int(^uint(0) >> 1) + +// MethodConfig defines the configuration recommended by the service providers for a +// particular method. +// +// Deprecated: Users should not use this struct. Service config should be received +// through name resolver, as specified here +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +type MethodConfig struct { + // WaitForReady indicates whether RPCs sent to this method should wait until + // the connection is ready by default (!failfast). The value specified via the + // gRPC client API will override the value set here. + WaitForReady *bool + // Timeout is the default timeout for RPCs sent to this method. The actual + // deadline used will be the minimum of the value specified here and the value + // set by the application via the gRPC client API. If either one is not set, + // then the other will be used. If neither is set, then the RPC has no deadline. + Timeout *time.Duration + // MaxReqSize is the maximum allowed payload size for an individual request in a + // stream (client->server) in bytes. The size which is measured is the serialized + // payload after per-message compression (but before stream compression) in bytes. + // The actual value used is the minimum of the value specified here and the value set + // by the application via the gRPC client API. If either one is not set, then the other + // will be used. If neither is set, then the built-in default is used. + MaxReqSize *int + // MaxRespSize is the maximum allowed payload size for an individual response in a + // stream (server->client) in bytes. + MaxRespSize *int + // RetryPolicy configures retry options for the method. + retryPolicy *retryPolicy +} + +// ServiceConfig is provided by the service provider and contains parameters for how +// clients that connect to the service should behave. +// +// Deprecated: Users should not use this struct. Service config should be received +// through name resolver, as specified here +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +type ServiceConfig struct { + // LB is the load balancer the service providers recommends. The balancer specified + // via grpc.WithBalancer will override this. + LB *string + + // Methods contains a map for the methods in this service. If there is an + // exact match for a method (i.e. /service/method) in the map, use the + // corresponding MethodConfig. If there's no exact match, look for the + // default config for the service (/service/) and use the corresponding + // MethodConfig if it exists. Otherwise, the method has no MethodConfig to + // use. + Methods map[string]MethodConfig + + // If a retryThrottlingPolicy is provided, gRPC will automatically throttle + // retry attempts and hedged RPCs when the client’s ratio of failures to + // successes exceeds a threshold. + // + // For each server name, the gRPC client will maintain a token_count which is + // initially set to maxTokens, and can take values between 0 and maxTokens. + // + // Every outgoing RPC (regardless of service or method invoked) will change + // token_count as follows: + // + // - Every failed RPC will decrement the token_count by 1. + // - Every successful RPC will increment the token_count by tokenRatio. + // + // If token_count is less than or equal to maxTokens / 2, then RPCs will not + // be retried and hedged RPCs will not be sent. + retryThrottling *retryThrottlingPolicy + // healthCheckConfig must be set as one of the requirement to enable LB channel + // health check. + healthCheckConfig *healthCheckConfig +} + +// healthCheckConfig defines the go-native version of the LB channel health check config. +type healthCheckConfig struct { + // serviceName is the service name to use in the health-checking request. + ServiceName string +} + +// retryPolicy defines the go-native version of the retry policy defined by the +// service config here: +// https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config +type retryPolicy struct { + // MaxAttempts is the maximum number of attempts, including the original RPC. + // + // This field is required and must be two or greater. + maxAttempts int + + // Exponential backoff parameters. The initial retry attempt will occur at + // random(0, initialBackoffMS). In general, the nth attempt will occur at + // random(0, + // min(initialBackoffMS*backoffMultiplier**(n-1), maxBackoffMS)). + // + // These fields are required and must be greater than zero. + initialBackoff time.Duration + maxBackoff time.Duration + backoffMultiplier float64 + + // The set of status codes which may be retried. + // + // Status codes are specified as strings, e.g., "UNAVAILABLE". + // + // This field is required and must be non-empty. + // Note: a set is used to store this for easy lookup. + retryableStatusCodes map[codes.Code]bool +} + +type jsonRetryPolicy struct { + MaxAttempts int + InitialBackoff string + MaxBackoff string + BackoffMultiplier float64 + RetryableStatusCodes []codes.Code +} + +// retryThrottlingPolicy defines the go-native version of the retry throttling +// policy defined by the service config here: +// https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config +type retryThrottlingPolicy struct { + // The number of tokens starts at maxTokens. The token_count will always be + // between 0 and maxTokens. + // + // This field is required and must be greater than zero. + MaxTokens float64 + // The amount of tokens to add on each successful RPC. Typically this will + // be some number between 0 and 1, e.g., 0.1. + // + // This field is required and must be greater than zero. Up to 3 decimal + // places are supported. + TokenRatio float64 +} + +func parseDuration(s *string) (*time.Duration, error) { + if s == nil { + return nil, nil + } + if !strings.HasSuffix(*s, "s") { + return nil, fmt.Errorf("malformed duration %q", *s) + } + ss := strings.SplitN((*s)[:len(*s)-1], ".", 3) + if len(ss) > 2 { + return nil, fmt.Errorf("malformed duration %q", *s) + } + // hasDigits is set if either the whole or fractional part of the number is + // present, since both are optional but one is required. + hasDigits := false + var d time.Duration + if len(ss[0]) > 0 { + i, err := strconv.ParseInt(ss[0], 10, 32) + if err != nil { + return nil, fmt.Errorf("malformed duration %q: %v", *s, err) + } + d = time.Duration(i) * time.Second + hasDigits = true + } + if len(ss) == 2 && len(ss[1]) > 0 { + if len(ss[1]) > 9 { + return nil, fmt.Errorf("malformed duration %q", *s) + } + f, err := strconv.ParseInt(ss[1], 10, 64) + if err != nil { + return nil, fmt.Errorf("malformed duration %q: %v", *s, err) + } + for i := 9; i > len(ss[1]); i-- { + f *= 10 + } + d += time.Duration(f) + hasDigits = true + } + if !hasDigits { + return nil, fmt.Errorf("malformed duration %q", *s) + } + + return &d, nil +} + +type jsonName struct { + Service *string + Method *string +} + +func (j jsonName) generatePath() (string, bool) { + if j.Service == nil { + return "", false + } + res := "/" + *j.Service + "/" + if j.Method != nil { + res += *j.Method + } + return res, true +} + +// TODO(lyuxuan): delete this struct after cleaning up old service config implementation. +type jsonMC struct { + Name *[]jsonName + WaitForReady *bool + Timeout *string + MaxRequestMessageBytes *int64 + MaxResponseMessageBytes *int64 + RetryPolicy *jsonRetryPolicy +} + +// TODO(lyuxuan): delete this struct after cleaning up old service config implementation. +type jsonSC struct { + LoadBalancingPolicy *string + MethodConfig *[]jsonMC + RetryThrottling *retryThrottlingPolicy + HealthCheckConfig *healthCheckConfig +} + +func parseServiceConfig(js string) (ServiceConfig, error) { + if len(js) == 0 { + return ServiceConfig{}, fmt.Errorf("no JSON service config provided") + } + var rsc jsonSC + err := json.Unmarshal([]byte(js), &rsc) + if err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + sc := ServiceConfig{ + LB: rsc.LoadBalancingPolicy, + Methods: make(map[string]MethodConfig), + retryThrottling: rsc.RetryThrottling, + healthCheckConfig: rsc.HealthCheckConfig, + } + if rsc.MethodConfig == nil { + return sc, nil + } + + for _, m := range *rsc.MethodConfig { + if m.Name == nil { + continue + } + d, err := parseDuration(m.Timeout) + if err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + + mc := MethodConfig{ + WaitForReady: m.WaitForReady, + Timeout: d, + } + if mc.retryPolicy, err = convertRetryPolicy(m.RetryPolicy); err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + if m.MaxRequestMessageBytes != nil { + if *m.MaxRequestMessageBytes > int64(maxInt) { + mc.MaxReqSize = newInt(maxInt) + } else { + mc.MaxReqSize = newInt(int(*m.MaxRequestMessageBytes)) + } + } + if m.MaxResponseMessageBytes != nil { + if *m.MaxResponseMessageBytes > int64(maxInt) { + mc.MaxRespSize = newInt(maxInt) + } else { + mc.MaxRespSize = newInt(int(*m.MaxResponseMessageBytes)) + } + } + for _, n := range *m.Name { + if path, valid := n.generatePath(); valid { + sc.Methods[path] = mc + } + } + } + + if sc.retryThrottling != nil { + if sc.retryThrottling.MaxTokens <= 0 || + sc.retryThrottling.MaxTokens >= 1000 || + sc.retryThrottling.TokenRatio <= 0 { + // Illegal throttling config; disable throttling. + sc.retryThrottling = nil + } + } + return sc, nil +} + +func convertRetryPolicy(jrp *jsonRetryPolicy) (p *retryPolicy, err error) { + if jrp == nil { + return nil, nil + } + ib, err := parseDuration(&jrp.InitialBackoff) + if err != nil { + return nil, err + } + mb, err := parseDuration(&jrp.MaxBackoff) + if err != nil { + return nil, err + } + + if jrp.MaxAttempts <= 1 || + *ib <= 0 || + *mb <= 0 || + jrp.BackoffMultiplier <= 0 || + len(jrp.RetryableStatusCodes) == 0 { + grpclog.Warningf("grpc: ignoring retry policy %v due to illegal configuration", jrp) + return nil, nil + } + + rp := &retryPolicy{ + maxAttempts: jrp.MaxAttempts, + initialBackoff: *ib, + maxBackoff: *mb, + backoffMultiplier: jrp.BackoffMultiplier, + retryableStatusCodes: make(map[codes.Code]bool), + } + if rp.maxAttempts > 5 { + // TODO(retry): Make the max maxAttempts configurable. + rp.maxAttempts = 5 + } + for _, code := range jrp.RetryableStatusCodes { + rp.retryableStatusCodes[code] = true + } + return rp, nil +} + +func min(a, b *int) *int { + if *a < *b { + return a + } + return b +} + +func getMaxSize(mcMax, doptMax *int, defaultVal int) *int { + if mcMax == nil && doptMax == nil { + return &defaultVal + } + if mcMax != nil && doptMax != nil { + return min(mcMax, doptMax) + } + if mcMax != nil { + return mcMax + } + return doptMax +} + +func newInt(b int) *int { + return &b +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go new file mode 100644 index 00000000..dc03731e --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go @@ -0,0 +1,63 @@ +/* + * + * Copyright 2016 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 stats + +import ( + "context" + "net" +) + +// ConnTagInfo defines the relevant information needed by connection context tagger. +type ConnTagInfo struct { + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr +} + +// RPCTagInfo defines the relevant information needed by RPC context tagger. +type RPCTagInfo struct { + // FullMethodName is the RPC method in the format of /package.service/method. + FullMethodName string + // FailFast indicates if this RPC is failfast. + // This field is only valid on client side, it's always false on server side. + FailFast bool +} + +// Handler defines the interface for the related stats handling (e.g., RPCs, connections). +type Handler interface { + // TagRPC can attach some information to the given context. + // The context used for the rest lifetime of the RPC will be derived from + // the returned context. + TagRPC(context.Context, *RPCTagInfo) context.Context + // HandleRPC processes the RPC stats. + HandleRPC(context.Context, RPCStats) + + // TagConn can attach some information to the given context. + // The returned context will be used for stats handling. + // For conn stats handling, the context used in HandleConn for this + // connection will be derived from the context returned. + // For RPC stats handling, + // - On server side, the context used in HandleRPC for all RPCs on this + // connection will be derived from the context returned. + // - On client side, the context is not derived from the context returned. + TagConn(context.Context, *ConnTagInfo) context.Context + // HandleConn processes the Conn stats. + HandleConn(context.Context, ConnStats) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go new file mode 100644 index 00000000..84f77daf --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go @@ -0,0 +1,295 @@ +/* + * + * Copyright 2016 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. + * + */ + +//go:generate protoc --go_out=plugins=grpc:. grpc_testing/test.proto + +// Package stats is for collecting and reporting various network and RPC stats. +// This package is for monitoring purpose only. All fields are read-only. +// All APIs are experimental. +package stats // import "google.golang.org/grpc/stats" + +import ( + "context" + "net" + "time" +) + +// RPCStats contains stats information about RPCs. +type RPCStats interface { + isRPCStats() + // IsClient returns true if this RPCStats is from client side. + IsClient() bool +} + +// Begin contains stats when an RPC begins. +// FailFast is only valid if this Begin is from client side. +type Begin struct { + // Client is true if this Begin is from client side. + Client bool + // BeginTime is the time when the RPC begins. + BeginTime time.Time + // FailFast indicates if this RPC is failfast. + FailFast bool +} + +// IsClient indicates if the stats information is from client side. +func (s *Begin) IsClient() bool { return s.Client } + +func (s *Begin) isRPCStats() {} + +// InPayload contains the information for an incoming payload. +type InPayload struct { + // Client is true if this InPayload is from client side. + Client bool + // Payload is the payload with original type. + Payload interface{} + // Data is the serialized message payload. + Data []byte + // Length is the length of uncompressed data. + Length int + // WireLength is the length of data on wire (compressed, signed, encrypted). + WireLength int + // RecvTime is the time when the payload is received. + RecvTime time.Time +} + +// IsClient indicates if the stats information is from client side. +func (s *InPayload) IsClient() bool { return s.Client } + +func (s *InPayload) isRPCStats() {} + +// InHeader contains stats when a header is received. +type InHeader struct { + // Client is true if this InHeader is from client side. + Client bool + // WireLength is the wire length of header. + WireLength int + + // The following fields are valid only if Client is false. + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr + // Compression is the compression algorithm used for the RPC. + Compression string +} + +// IsClient indicates if the stats information is from client side. +func (s *InHeader) IsClient() bool { return s.Client } + +func (s *InHeader) isRPCStats() {} + +// InTrailer contains stats when a trailer is received. +type InTrailer struct { + // Client is true if this InTrailer is from client side. + Client bool + // WireLength is the wire length of trailer. + WireLength int +} + +// IsClient indicates if the stats information is from client side. +func (s *InTrailer) IsClient() bool { return s.Client } + +func (s *InTrailer) isRPCStats() {} + +// OutPayload contains the information for an outgoing payload. +type OutPayload struct { + // Client is true if this OutPayload is from client side. + Client bool + // Payload is the payload with original type. + Payload interface{} + // Data is the serialized message payload. + Data []byte + // Length is the length of uncompressed data. + Length int + // WireLength is the length of data on wire (compressed, signed, encrypted). + WireLength int + // SentTime is the time when the payload is sent. + SentTime time.Time +} + +// IsClient indicates if this stats information is from client side. +func (s *OutPayload) IsClient() bool { return s.Client } + +func (s *OutPayload) isRPCStats() {} + +// OutHeader contains stats when a header is sent. +type OutHeader struct { + // Client is true if this OutHeader is from client side. + Client bool + + // The following fields are valid only if Client is true. + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr + // Compression is the compression algorithm used for the RPC. + Compression string +} + +// IsClient indicates if this stats information is from client side. +func (s *OutHeader) IsClient() bool { return s.Client } + +func (s *OutHeader) isRPCStats() {} + +// OutTrailer contains stats when a trailer is sent. +type OutTrailer struct { + // Client is true if this OutTrailer is from client side. + Client bool + // WireLength is the wire length of trailer. + WireLength int +} + +// IsClient indicates if this stats information is from client side. +func (s *OutTrailer) IsClient() bool { return s.Client } + +func (s *OutTrailer) isRPCStats() {} + +// End contains stats when an RPC ends. +type End struct { + // Client is true if this End is from client side. + Client bool + // BeginTime is the time when the RPC began. + BeginTime time.Time + // EndTime is the time when the RPC ends. + EndTime time.Time + // Error is the error the RPC ended with. It is an error generated from + // status.Status and can be converted back to status.Status using + // status.FromError if non-nil. + Error error +} + +// IsClient indicates if this is from client side. +func (s *End) IsClient() bool { return s.Client } + +func (s *End) isRPCStats() {} + +// ConnStats contains stats information about connections. +type ConnStats interface { + isConnStats() + // IsClient returns true if this ConnStats is from client side. + IsClient() bool +} + +// ConnBegin contains the stats of a connection when it is established. +type ConnBegin struct { + // Client is true if this ConnBegin is from client side. + Client bool +} + +// IsClient indicates if this is from client side. +func (s *ConnBegin) IsClient() bool { return s.Client } + +func (s *ConnBegin) isConnStats() {} + +// ConnEnd contains the stats of a connection when it ends. +type ConnEnd struct { + // Client is true if this ConnEnd is from client side. + Client bool +} + +// IsClient indicates if this is from client side. +func (s *ConnEnd) IsClient() bool { return s.Client } + +func (s *ConnEnd) isConnStats() {} + +type incomingTagsKey struct{} +type outgoingTagsKey struct{} + +// SetTags attaches stats tagging data to the context, which will be sent in +// the outgoing RPC with the header grpc-tags-bin. Subsequent calls to +// SetTags will overwrite the values from earlier calls. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func SetTags(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, outgoingTagsKey{}, b) +} + +// Tags returns the tags from the context for the inbound RPC. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func Tags(ctx context.Context) []byte { + b, _ := ctx.Value(incomingTagsKey{}).([]byte) + return b +} + +// SetIncomingTags attaches stats tagging data to the context, to be read by +// the application (not sent in outgoing RPCs). +// +// This is intended for gRPC-internal use ONLY. +func SetIncomingTags(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, incomingTagsKey{}, b) +} + +// OutgoingTags returns the tags from the context for the outbound RPC. +// +// This is intended for gRPC-internal use ONLY. +func OutgoingTags(ctx context.Context) []byte { + b, _ := ctx.Value(outgoingTagsKey{}).([]byte) + return b +} + +type incomingTraceKey struct{} +type outgoingTraceKey struct{} + +// SetTrace attaches stats tagging data to the context, which will be sent in +// the outgoing RPC with the header grpc-trace-bin. Subsequent calls to +// SetTrace will overwrite the values from earlier calls. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func SetTrace(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, outgoingTraceKey{}, b) +} + +// Trace returns the trace from the context for the inbound RPC. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func Trace(ctx context.Context) []byte { + b, _ := ctx.Value(incomingTraceKey{}).([]byte) + return b +} + +// SetIncomingTrace attaches stats tagging data to the context, to be read by +// the application (not sent in outgoing RPCs). It is intended for +// gRPC-internal use. +func SetIncomingTrace(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, incomingTraceKey{}, b) +} + +// OutgoingTrace returns the trace from the context for the outbound RPC. It is +// intended for gRPC-internal use. +func OutgoingTrace(ctx context.Context) []byte { + b, _ := ctx.Value(outgoingTraceKey{}).([]byte) + return b +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go new file mode 100644 index 00000000..ed36681b --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go @@ -0,0 +1,210 @@ +/* + * + * 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 status implements errors returned by gRPC. These errors are +// serialized and transmitted on the wire between server and client, and allow +// for additional data to be transmitted via the Details field in the status +// proto. gRPC service handlers should return an error created by this +// package, and gRPC clients should expect a corresponding error to be +// returned from the RPC call. +// +// This package upholds the invariants that a non-nil error may not +// contain an OK code, and an OK code must result in a nil error. +package status + +import ( + "context" + "errors" + "fmt" + + "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes" + spb "google.golang.org/genproto/googleapis/rpc/status" + "google.golang.org/grpc/codes" +) + +// statusError is an alias of a status proto. It implements error and Status, +// and a nil statusError should never be returned by this package. +type statusError spb.Status + +func (se *statusError) Error() string { + p := (*spb.Status)(se) + return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(p.GetCode()), p.GetMessage()) +} + +func (se *statusError) GRPCStatus() *Status { + return &Status{s: (*spb.Status)(se)} +} + +// Status represents an RPC status code, message, and details. It is immutable +// and should be created with New, Newf, or FromProto. +type Status struct { + s *spb.Status +} + +// Code returns the status code contained in s. +func (s *Status) Code() codes.Code { + if s == nil || s.s == nil { + return codes.OK + } + return codes.Code(s.s.Code) +} + +// Message returns the message contained in s. +func (s *Status) Message() string { + if s == nil || s.s == nil { + return "" + } + return s.s.Message +} + +// Proto returns s's status as an spb.Status proto message. +func (s *Status) Proto() *spb.Status { + if s == nil { + return nil + } + return proto.Clone(s.s).(*spb.Status) +} + +// Err returns an immutable error representing s; returns nil if s.Code() is +// OK. +func (s *Status) Err() error { + if s.Code() == codes.OK { + return nil + } + return (*statusError)(s.s) +} + +// New returns a Status representing c and msg. +func New(c codes.Code, msg string) *Status { + return &Status{s: &spb.Status{Code: int32(c), Message: msg}} +} + +// Newf returns New(c, fmt.Sprintf(format, a...)). +func Newf(c codes.Code, format string, a ...interface{}) *Status { + return New(c, fmt.Sprintf(format, a...)) +} + +// Error returns an error representing c and msg. If c is OK, returns nil. +func Error(c codes.Code, msg string) error { + return New(c, msg).Err() +} + +// Errorf returns Error(c, fmt.Sprintf(format, a...)). +func Errorf(c codes.Code, format string, a ...interface{}) error { + return Error(c, fmt.Sprintf(format, a...)) +} + +// ErrorProto returns an error representing s. If s.Code is OK, returns nil. +func ErrorProto(s *spb.Status) error { + return FromProto(s).Err() +} + +// FromProto returns a Status representing s. +func FromProto(s *spb.Status) *Status { + return &Status{s: proto.Clone(s).(*spb.Status)} +} + +// FromError returns a Status representing err if it was produced from this +// package or has a method `GRPCStatus() *Status`. Otherwise, ok is false and a +// Status is returned with codes.Unknown and the original error message. +func FromError(err error) (s *Status, ok bool) { + if err == nil { + return &Status{s: &spb.Status{Code: int32(codes.OK)}}, true + } + if se, ok := err.(interface { + GRPCStatus() *Status + }); ok { + return se.GRPCStatus(), true + } + return New(codes.Unknown, err.Error()), false +} + +// Convert is a convenience function which removes the need to handle the +// boolean return value from FromError. +func Convert(err error) *Status { + s, _ := FromError(err) + return s +} + +// WithDetails returns a new status with the provided details messages appended to the status. +// If any errors are encountered, it returns nil and the first error encountered. +func (s *Status) WithDetails(details ...proto.Message) (*Status, error) { + if s.Code() == codes.OK { + return nil, errors.New("no error details for status with code OK") + } + // s.Code() != OK implies that s.Proto() != nil. + p := s.Proto() + for _, detail := range details { + any, err := ptypes.MarshalAny(detail) + if err != nil { + return nil, err + } + p.Details = append(p.Details, any) + } + return &Status{s: p}, nil +} + +// Details returns a slice of details messages attached to the status. +// If a detail cannot be decoded, the error is returned in place of the detail. +func (s *Status) Details() []interface{} { + if s == nil || s.s == nil { + return nil + } + details := make([]interface{}, 0, len(s.s.Details)) + for _, any := range s.s.Details { + detail := &ptypes.DynamicAny{} + if err := ptypes.UnmarshalAny(any, detail); err != nil { + details = append(details, err) + continue + } + details = append(details, detail.Message) + } + return details +} + +// Code returns the Code of the error if it is a Status error, codes.OK if err +// is nil, or codes.Unknown otherwise. +func Code(err error) codes.Code { + // Don't use FromError to avoid allocation of OK status. + if err == nil { + return codes.OK + } + if se, ok := err.(interface { + GRPCStatus() *Status + }); ok { + return se.GRPCStatus().Code() + } + return codes.Unknown +} + +// FromContextError converts a context error into a Status. It returns a +// Status with codes.OK if err is nil, or a Status with codes.Unknown if err is +// non-nil and not a context error. +func FromContextError(err error) *Status { + switch err { + case nil: + return New(codes.OK, "") + case context.DeadlineExceeded: + return New(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return New(codes.Canceled, err.Error()) + default: + return New(codes.Unknown, err.Error()) + } +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go new file mode 100644 index 00000000..0c266d6f --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go @@ -0,0 +1,1489 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "io" + "math" + "strconv" + "sync" + "time" + + "golang.org/x/net/trace" + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/binarylog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// StreamHandler defines the handler called by gRPC server to complete the +// execution of a streaming RPC. If a StreamHandler returns an error, it +// should be produced by the status package, or else gRPC will use +// codes.Unknown as the status code and err.Error() as the status message +// of the RPC. +type StreamHandler func(srv interface{}, stream ServerStream) error + +// StreamDesc represents a streaming RPC service's method specification. +type StreamDesc struct { + StreamName string + Handler StreamHandler + + // At least one of these is true. + ServerStreams bool + ClientStreams bool +} + +// Stream defines the common interface a client or server stream has to satisfy. +// +// Deprecated: See ClientStream and ServerStream documentation instead. +type Stream interface { + // Deprecated: See ClientStream and ServerStream documentation instead. + Context() context.Context + // Deprecated: See ClientStream and ServerStream documentation instead. + SendMsg(m interface{}) error + // Deprecated: See ClientStream and ServerStream documentation instead. + RecvMsg(m interface{}) error +} + +// ClientStream defines the client-side behavior of a streaming RPC. +// +// All errors returned from ClientStream methods are compatible with the +// status package. +type ClientStream interface { + // Header returns the header metadata received from the server if there + // is any. It blocks if the metadata is not ready to read. + Header() (metadata.MD, error) + // Trailer returns the trailer metadata from the server, if there is any. + // It must only be called after stream.CloseAndRecv has returned, or + // stream.Recv has returned a non-nil error (including io.EOF). + Trailer() metadata.MD + // CloseSend closes the send direction of the stream. It closes the stream + // when non-nil error is met. It is also not safe to call CloseSend + // concurrently with SendMsg. + CloseSend() error + // Context returns the context for this stream. + // + // It should not be called until after Header or RecvMsg has returned. Once + // called, subsequent client-side retries are disabled. + Context() context.Context + // SendMsg is generally called by generated code. On error, SendMsg aborts + // the stream. If the error was generated by the client, the status is + // returned directly; otherwise, io.EOF is returned and the status of + // the stream may be discovered using RecvMsg. + // + // SendMsg blocks until: + // - There is sufficient flow control to schedule m with the transport, or + // - The stream is done, or + // - The stream breaks. + // + // SendMsg does not wait until the message is received by the server. An + // untimely stream closure may result in lost messages. To ensure delivery, + // users should ensure the RPC completed successfully using RecvMsg. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not safe + // to call SendMsg on the same stream in different goroutines. It is also + // not safe to call CloseSend concurrently with SendMsg. + SendMsg(m interface{}) error + // RecvMsg blocks until it receives a message into m or the stream is + // done. It returns io.EOF when the stream completes successfully. On + // any other error, the stream is aborted and the error contains the RPC + // status. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not + // safe to call RecvMsg on the same stream in different goroutines. + RecvMsg(m interface{}) error +} + +// NewStream creates a new Stream for the client side. This is typically +// called by generated code. ctx is used for the lifetime of the stream. +// +// To ensure resources are not leaked due to the stream returned, one of the following +// actions must be performed: +// +// 1. Call Close on the ClientConn. +// 2. Cancel the context provided. +// 3. Call RecvMsg until a non-nil error is returned. A protobuf-generated +// client-streaming RPC, for instance, might use the helper function +// CloseAndRecv (note that CloseSend does not Recv, therefore is not +// guaranteed to release all resources). +// 4. Receive a non-nil, non-io.EOF error from Header or SendMsg. +// +// If none of the above happen, a goroutine and a context will be leaked, and grpc +// will not call the optionally-configured stats handler with a stats.End message. +func (cc *ClientConn) NewStream(ctx context.Context, desc *StreamDesc, method string, opts ...CallOption) (ClientStream, error) { + // allow interceptor to see all applicable call options, which means those + // configured as defaults from dial option as well as per-call options + opts = combine(cc.dopts.callOptions, opts) + + if cc.dopts.streamInt != nil { + return cc.dopts.streamInt(ctx, desc, cc, method, newClientStream, opts...) + } + return newClientStream(ctx, desc, cc, method, opts...) +} + +// NewClientStream is a wrapper for ClientConn.NewStream. +func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) { + return cc.NewStream(ctx, desc, method, opts...) +} + +func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (_ ClientStream, err error) { + if channelz.IsOn() { + cc.incrCallsStarted() + defer func() { + if err != nil { + cc.incrCallsFailed() + } + }() + } + c := defaultCallInfo() + // Provide an opportunity for the first RPC to see the first service config + // provided by the resolver. + if err := cc.waitForResolvedAddrs(ctx); err != nil { + return nil, err + } + mc := cc.GetMethodConfig(method) + if mc.WaitForReady != nil { + c.failFast = !*mc.WaitForReady + } + + // Possible context leak: + // The cancel function for the child context we create will only be called + // when RecvMsg returns a non-nil error, if the ClientConn is closed, or if + // an error is generated by SendMsg. + // https://github.com/grpc/grpc-go/issues/1818. + var cancel context.CancelFunc + if mc.Timeout != nil && *mc.Timeout >= 0 { + ctx, cancel = context.WithTimeout(ctx, *mc.Timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer func() { + if err != nil { + cancel() + } + }() + + for _, o := range opts { + if err := o.before(c); err != nil { + return nil, toRPCErr(err) + } + } + c.maxSendMessageSize = getMaxSize(mc.MaxReqSize, c.maxSendMessageSize, defaultClientMaxSendMessageSize) + c.maxReceiveMessageSize = getMaxSize(mc.MaxRespSize, c.maxReceiveMessageSize, defaultClientMaxReceiveMessageSize) + if err := setCallInfoCodec(c); err != nil { + return nil, err + } + + callHdr := &transport.CallHdr{ + Host: cc.authority, + Method: method, + ContentSubtype: c.contentSubtype, + } + + // Set our outgoing compression according to the UseCompressor CallOption, if + // set. In that case, also find the compressor from the encoding package. + // Otherwise, use the compressor configured by the WithCompressor DialOption, + // if set. + var cp Compressor + var comp encoding.Compressor + if ct := c.compressorType; ct != "" { + callHdr.SendCompress = ct + if ct != encoding.Identity { + comp = encoding.GetCompressor(ct) + if comp == nil { + return nil, status.Errorf(codes.Internal, "grpc: Compressor is not installed for requested grpc-encoding %q", ct) + } + } + } else if cc.dopts.cp != nil { + callHdr.SendCompress = cc.dopts.cp.Type() + cp = cc.dopts.cp + } + if c.creds != nil { + callHdr.Creds = c.creds + } + var trInfo traceInfo + if EnableTracing { + trInfo.tr = trace.New("grpc.Sent."+methodFamily(method), method) + trInfo.firstLine.client = true + if deadline, ok := ctx.Deadline(); ok { + trInfo.firstLine.deadline = deadline.Sub(time.Now()) + } + trInfo.tr.LazyLog(&trInfo.firstLine, false) + ctx = trace.NewContext(ctx, trInfo.tr) + } + ctx = newContextWithRPCInfo(ctx, c.failFast) + sh := cc.dopts.copts.StatsHandler + var beginTime time.Time + if sh != nil { + ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{FullMethodName: method, FailFast: c.failFast}) + beginTime = time.Now() + begin := &stats.Begin{ + Client: true, + BeginTime: beginTime, + FailFast: c.failFast, + } + sh.HandleRPC(ctx, begin) + } + + cs := &clientStream{ + callHdr: callHdr, + ctx: ctx, + methodConfig: &mc, + opts: opts, + callInfo: c, + cc: cc, + desc: desc, + codec: c.codec, + cp: cp, + comp: comp, + cancel: cancel, + beginTime: beginTime, + firstAttempt: true, + } + if !cc.dopts.disableRetry { + cs.retryThrottler = cc.retryThrottler.Load().(*retryThrottler) + } + cs.binlog = binarylog.GetMethodLogger(method) + + cs.callInfo.stream = cs + // Only this initial attempt has stats/tracing. + // TODO(dfawley): move to newAttempt when per-attempt stats are implemented. + if err := cs.newAttemptLocked(sh, trInfo); err != nil { + cs.finish(err) + return nil, err + } + + op := func(a *csAttempt) error { return a.newStream() } + if err := cs.withRetry(op, func() { cs.bufferForRetryLocked(0, op) }); err != nil { + cs.finish(err) + return nil, err + } + + if cs.binlog != nil { + md, _ := metadata.FromOutgoingContext(ctx) + logEntry := &binarylog.ClientHeader{ + OnClientSide: true, + Header: md, + MethodName: method, + Authority: cs.cc.authority, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + cs.binlog.Log(logEntry) + } + + if desc != unaryStreamDesc { + // Listen on cc and stream contexts to cleanup when the user closes the + // ClientConn or cancels the stream context. In all other cases, an error + // should already be injected into the recv buffer by the transport, which + // the client will eventually receive, and then we will cancel the stream's + // context in clientStream.finish. + go func() { + select { + case <-cc.ctx.Done(): + cs.finish(ErrClientConnClosing) + case <-ctx.Done(): + cs.finish(toRPCErr(ctx.Err())) + } + }() + } + return cs, nil +} + +func (cs *clientStream) newAttemptLocked(sh stats.Handler, trInfo traceInfo) error { + cs.attempt = &csAttempt{ + cs: cs, + dc: cs.cc.dopts.dc, + statsHandler: sh, + trInfo: trInfo, + } + + if err := cs.ctx.Err(); err != nil { + return toRPCErr(err) + } + t, done, err := cs.cc.getTransport(cs.ctx, cs.callInfo.failFast, cs.callHdr.Method) + if err != nil { + return err + } + cs.attempt.t = t + cs.attempt.done = done + return nil +} + +func (a *csAttempt) newStream() error { + cs := a.cs + cs.callHdr.PreviousAttempts = cs.numRetries + s, err := a.t.NewStream(cs.ctx, cs.callHdr) + if err != nil { + return toRPCErr(err) + } + cs.attempt.s = s + cs.attempt.p = &parser{r: s} + return nil +} + +// clientStream implements a client side Stream. +type clientStream struct { + callHdr *transport.CallHdr + opts []CallOption + callInfo *callInfo + cc *ClientConn + desc *StreamDesc + + codec baseCodec + cp Compressor + comp encoding.Compressor + + cancel context.CancelFunc // cancels all attempts + + sentLast bool // sent an end stream + beginTime time.Time + + methodConfig *MethodConfig + + ctx context.Context // the application's context, wrapped by stats/tracing + + retryThrottler *retryThrottler // The throttler active when the RPC began. + + binlog *binarylog.MethodLogger // Binary logger, can be nil. + // serverHeaderBinlogged is a boolean for whether server header has been + // logged. Server header will be logged when the first time one of those + // happens: stream.Header(), stream.Recv(). + // + // It's only read and used by Recv() and Header(), so it doesn't need to be + // synchronized. + serverHeaderBinlogged bool + + mu sync.Mutex + firstAttempt bool // if true, transparent retry is valid + numRetries int // exclusive of transparent retry attempt(s) + numRetriesSincePushback int // retries since pushback; to reset backoff + finished bool // TODO: replace with atomic cmpxchg or sync.Once? + attempt *csAttempt // the active client stream attempt + // TODO(hedging): hedging will have multiple attempts simultaneously. + committed bool // active attempt committed for retry? + buffer []func(a *csAttempt) error // operations to replay on retry + bufferSize int // current size of buffer +} + +// csAttempt implements a single transport stream attempt within a +// clientStream. +type csAttempt struct { + cs *clientStream + t transport.ClientTransport + s *transport.Stream + p *parser + done func(balancer.DoneInfo) + + finished bool + dc Decompressor + decomp encoding.Compressor + decompSet bool + + mu sync.Mutex // guards trInfo.tr + // trInfo.tr is set when created (if EnableTracing is true), + // and cleared when the finish method is called. + trInfo traceInfo + + statsHandler stats.Handler +} + +func (cs *clientStream) commitAttemptLocked() { + cs.committed = true + cs.buffer = nil +} + +func (cs *clientStream) commitAttempt() { + cs.mu.Lock() + cs.commitAttemptLocked() + cs.mu.Unlock() +} + +// shouldRetry returns nil if the RPC should be retried; otherwise it returns +// the error that should be returned by the operation. +func (cs *clientStream) shouldRetry(err error) error { + if cs.attempt.s == nil && !cs.callInfo.failFast { + // In the event of any error from NewStream (attempt.s == nil), we + // never attempted to write anything to the wire, so we can retry + // indefinitely for non-fail-fast RPCs. + return nil + } + if cs.finished || cs.committed { + // RPC is finished or committed; cannot retry. + return err + } + // Wait for the trailers. + if cs.attempt.s != nil { + <-cs.attempt.s.Done() + } + if cs.firstAttempt && !cs.callInfo.failFast && (cs.attempt.s == nil || cs.attempt.s.Unprocessed()) { + // First attempt, wait-for-ready, stream unprocessed: transparently retry. + cs.firstAttempt = false + return nil + } + cs.firstAttempt = false + if cs.cc.dopts.disableRetry { + return err + } + + pushback := 0 + hasPushback := false + if cs.attempt.s != nil { + if to, toErr := cs.attempt.s.TrailersOnly(); toErr != nil { + // Context error; stop now. + return toErr + } else if !to { + return err + } + + // TODO(retry): Move down if the spec changes to not check server pushback + // before considering this a failure for throttling. + sps := cs.attempt.s.Trailer()["grpc-retry-pushback-ms"] + if len(sps) == 1 { + var e error + if pushback, e = strconv.Atoi(sps[0]); e != nil || pushback < 0 { + grpclog.Infof("Server retry pushback specified to abort (%q).", sps[0]) + cs.retryThrottler.throttle() // This counts as a failure for throttling. + return err + } + hasPushback = true + } else if len(sps) > 1 { + grpclog.Warningf("Server retry pushback specified multiple values (%q); not retrying.", sps) + cs.retryThrottler.throttle() // This counts as a failure for throttling. + return err + } + } + + var code codes.Code + if cs.attempt.s != nil { + code = cs.attempt.s.Status().Code() + } else { + code = status.Convert(err).Code() + } + + rp := cs.methodConfig.retryPolicy + if rp == nil || !rp.retryableStatusCodes[code] { + return err + } + + // Note: the ordering here is important; we count this as a failure + // only if the code matched a retryable code. + if cs.retryThrottler.throttle() { + return err + } + if cs.numRetries+1 >= rp.maxAttempts { + return err + } + + var dur time.Duration + if hasPushback { + dur = time.Millisecond * time.Duration(pushback) + cs.numRetriesSincePushback = 0 + } else { + fact := math.Pow(rp.backoffMultiplier, float64(cs.numRetriesSincePushback)) + cur := float64(rp.initialBackoff) * fact + if max := float64(rp.maxBackoff); cur > max { + cur = max + } + dur = time.Duration(grpcrand.Int63n(int64(cur))) + cs.numRetriesSincePushback++ + } + + // TODO(dfawley): we could eagerly fail here if dur puts us past the + // deadline, but unsure if it is worth doing. + t := time.NewTimer(dur) + select { + case <-t.C: + cs.numRetries++ + return nil + case <-cs.ctx.Done(): + t.Stop() + return status.FromContextError(cs.ctx.Err()).Err() + } +} + +// Returns nil if a retry was performed and succeeded; error otherwise. +func (cs *clientStream) retryLocked(lastErr error) error { + for { + cs.attempt.finish(lastErr) + if err := cs.shouldRetry(lastErr); err != nil { + cs.commitAttemptLocked() + return err + } + if err := cs.newAttemptLocked(nil, traceInfo{}); err != nil { + return err + } + if lastErr = cs.replayBufferLocked(); lastErr == nil { + return nil + } + } +} + +func (cs *clientStream) Context() context.Context { + cs.commitAttempt() + // No need to lock before using attempt, since we know it is committed and + // cannot change. + return cs.attempt.s.Context() +} + +func (cs *clientStream) withRetry(op func(a *csAttempt) error, onSuccess func()) error { + cs.mu.Lock() + for { + if cs.committed { + cs.mu.Unlock() + return op(cs.attempt) + } + a := cs.attempt + cs.mu.Unlock() + err := op(a) + cs.mu.Lock() + if a != cs.attempt { + // We started another attempt already. + continue + } + if err == io.EOF { + <-a.s.Done() + } + if err == nil || (err == io.EOF && a.s.Status().Code() == codes.OK) { + onSuccess() + cs.mu.Unlock() + return err + } + if err := cs.retryLocked(err); err != nil { + cs.mu.Unlock() + return err + } + } +} + +func (cs *clientStream) Header() (metadata.MD, error) { + var m metadata.MD + err := cs.withRetry(func(a *csAttempt) error { + var err error + m, err = a.s.Header() + return toRPCErr(err) + }, cs.commitAttemptLocked) + if err != nil { + cs.finish(err) + return nil, err + } + if cs.binlog != nil && !cs.serverHeaderBinlogged { + // Only log if binary log is on and header has not been logged. + logEntry := &binarylog.ServerHeader{ + OnClientSide: true, + Header: m, + PeerAddr: nil, + } + if peer, ok := peer.FromContext(cs.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + cs.binlog.Log(logEntry) + cs.serverHeaderBinlogged = true + } + return m, err +} + +func (cs *clientStream) Trailer() metadata.MD { + // On RPC failure, we never need to retry, because usage requires that + // RecvMsg() returned a non-nil error before calling this function is valid. + // We would have retried earlier if necessary. + // + // Commit the attempt anyway, just in case users are not following those + // directions -- it will prevent races and should not meaningfully impact + // performance. + cs.commitAttempt() + if cs.attempt.s == nil { + return nil + } + return cs.attempt.s.Trailer() +} + +func (cs *clientStream) replayBufferLocked() error { + a := cs.attempt + for _, f := range cs.buffer { + if err := f(a); err != nil { + return err + } + } + return nil +} + +func (cs *clientStream) bufferForRetryLocked(sz int, op func(a *csAttempt) error) { + // Note: we still will buffer if retry is disabled (for transparent retries). + if cs.committed { + return + } + cs.bufferSize += sz + if cs.bufferSize > cs.callInfo.maxRetryRPCBufferSize { + cs.commitAttemptLocked() + return + } + cs.buffer = append(cs.buffer, op) +} + +func (cs *clientStream) SendMsg(m interface{}) (err error) { + defer func() { + if err != nil && err != io.EOF { + // Call finish on the client stream for errors generated by this SendMsg + // call, as these indicate problems created by this client. (Transport + // errors are converted to an io.EOF error in csAttempt.sendMsg; the real + // error will be returned from RecvMsg eventually in that case, or be + // retried.) + cs.finish(err) + } + }() + if cs.sentLast { + return status.Errorf(codes.Internal, "SendMsg called after CloseSend") + } + if !cs.desc.ClientStreams { + cs.sentLast = true + } + data, err := encode(cs.codec, m) + if err != nil { + return err + } + compData, err := compress(data, cs.cp, cs.comp) + if err != nil { + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > *cs.callInfo.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payload), *cs.callInfo.maxSendMessageSize) + } + msgBytes := data // Store the pointer before setting to nil. For binary logging. + op := func(a *csAttempt) error { + err := a.sendMsg(m, hdr, payload, data) + // nil out the message and uncomp when replaying; they are only needed for + // stats which is disabled for subsequent attempts. + m, data = nil, nil + return err + } + err = cs.withRetry(op, func() { cs.bufferForRetryLocked(len(hdr)+len(payload), op) }) + if cs.binlog != nil && err == nil { + cs.binlog.Log(&binarylog.ClientMessage{ + OnClientSide: true, + Message: msgBytes, + }) + } + return +} + +func (cs *clientStream) RecvMsg(m interface{}) error { + if cs.binlog != nil && !cs.serverHeaderBinlogged { + // Call Header() to binary log header if it's not already logged. + cs.Header() + } + var recvInfo *payloadInfo + if cs.binlog != nil { + recvInfo = &payloadInfo{} + } + err := cs.withRetry(func(a *csAttempt) error { + return a.recvMsg(m, recvInfo) + }, cs.commitAttemptLocked) + if cs.binlog != nil && err == nil { + cs.binlog.Log(&binarylog.ServerMessage{ + OnClientSide: true, + Message: recvInfo.uncompressedBytes, + }) + } + if err != nil || !cs.desc.ServerStreams { + // err != nil or non-server-streaming indicates end of stream. + cs.finish(err) + + if cs.binlog != nil { + // finish will not log Trailer. Log Trailer here. + logEntry := &binarylog.ServerTrailer{ + OnClientSide: true, + Trailer: cs.Trailer(), + Err: err, + } + if logEntry.Err == io.EOF { + logEntry.Err = nil + } + if peer, ok := peer.FromContext(cs.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + cs.binlog.Log(logEntry) + } + } + return err +} + +func (cs *clientStream) CloseSend() error { + if cs.sentLast { + // TODO: return an error and finish the stream instead, due to API misuse? + return nil + } + cs.sentLast = true + op := func(a *csAttempt) error { + a.t.Write(a.s, nil, nil, &transport.Options{Last: true}) + // Always return nil; io.EOF is the only error that might make sense + // instead, but there is no need to signal the client to call RecvMsg + // as the only use left for the stream after CloseSend is to call + // RecvMsg. This also matches historical behavior. + return nil + } + cs.withRetry(op, func() { cs.bufferForRetryLocked(0, op) }) + if cs.binlog != nil { + cs.binlog.Log(&binarylog.ClientHalfClose{ + OnClientSide: true, + }) + } + // We never returned an error here for reasons. + return nil +} + +func (cs *clientStream) finish(err error) { + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + cs.mu.Lock() + if cs.finished { + cs.mu.Unlock() + return + } + cs.finished = true + cs.commitAttemptLocked() + cs.mu.Unlock() + // For binary logging. only log cancel in finish (could be caused by RPC ctx + // canceled or ClientConn closed). Trailer will be logged in RecvMsg. + // + // Only one of cancel or trailer needs to be logged. In the cases where + // users don't call RecvMsg, users must have already canceled the RPC. + if cs.binlog != nil && status.Code(err) == codes.Canceled { + cs.binlog.Log(&binarylog.Cancel{ + OnClientSide: true, + }) + } + if err == nil { + cs.retryThrottler.successfulRPC() + } + if channelz.IsOn() { + if err != nil { + cs.cc.incrCallsFailed() + } else { + cs.cc.incrCallsSucceeded() + } + } + if cs.attempt != nil { + cs.attempt.finish(err) + } + // after functions all rely upon having a stream. + if cs.attempt.s != nil { + for _, o := range cs.opts { + o.after(cs.callInfo) + } + } + cs.cancel() +} + +func (a *csAttempt) sendMsg(m interface{}, hdr, payld, data []byte) error { + cs := a.cs + if EnableTracing { + a.mu.Lock() + if a.trInfo.tr != nil { + a.trInfo.tr.LazyLog(&payload{sent: true, msg: m}, true) + } + a.mu.Unlock() + } + if err := a.t.Write(a.s, hdr, payld, &transport.Options{Last: !cs.desc.ClientStreams}); err != nil { + if !cs.desc.ClientStreams { + // For non-client-streaming RPCs, we return nil instead of EOF on error + // because the generated code requires it. finish is not called; RecvMsg() + // will call it with the stream's status independently. + return nil + } + return io.EOF + } + if a.statsHandler != nil { + a.statsHandler.HandleRPC(cs.ctx, outPayload(true, m, data, payld, time.Now())) + } + if channelz.IsOn() { + a.t.IncrMsgSent() + } + return nil +} + +func (a *csAttempt) recvMsg(m interface{}, payInfo *payloadInfo) (err error) { + cs := a.cs + if a.statsHandler != nil && payInfo == nil { + payInfo = &payloadInfo{} + } + + if !a.decompSet { + // Block until we receive headers containing received message encoding. + if ct := a.s.RecvCompress(); ct != "" && ct != encoding.Identity { + if a.dc == nil || a.dc.Type() != ct { + // No configured decompressor, or it does not match the incoming + // message encoding; attempt to find a registered compressor that does. + a.dc = nil + a.decomp = encoding.GetCompressor(ct) + } + } else { + // No compression is used; disable our decompressor. + a.dc = nil + } + // Only initialize this state once per stream. + a.decompSet = true + } + err = recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, payInfo, a.decomp) + if err != nil { + if err == io.EOF { + if statusErr := a.s.Status().Err(); statusErr != nil { + return statusErr + } + return io.EOF // indicates successful end of stream. + } + return toRPCErr(err) + } + if EnableTracing { + a.mu.Lock() + if a.trInfo.tr != nil { + a.trInfo.tr.LazyLog(&payload{sent: false, msg: m}, true) + } + a.mu.Unlock() + } + if a.statsHandler != nil { + a.statsHandler.HandleRPC(cs.ctx, &stats.InPayload{ + Client: true, + RecvTime: time.Now(), + Payload: m, + // TODO truncate large payload. + Data: payInfo.uncompressedBytes, + Length: len(payInfo.uncompressedBytes), + }) + } + if channelz.IsOn() { + a.t.IncrMsgRecv() + } + if cs.desc.ServerStreams { + // Subsequent messages should be received by subsequent RecvMsg calls. + return nil + } + // Special handling for non-server-stream rpcs. + // This recv expects EOF or errors, so we don't collect inPayload. + err = recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, nil, a.decomp) + if err == nil { + return toRPCErr(errors.New("grpc: client streaming protocol violation: get , want ")) + } + if err == io.EOF { + return a.s.Status().Err() // non-server streaming Recv returns nil on success + } + return toRPCErr(err) +} + +func (a *csAttempt) finish(err error) { + a.mu.Lock() + if a.finished { + a.mu.Unlock() + return + } + a.finished = true + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + if a.s != nil { + a.t.CloseStream(a.s, err) + } + + if a.done != nil { + br := false + var tr metadata.MD + if a.s != nil { + br = a.s.BytesReceived() + tr = a.s.Trailer() + } + a.done(balancer.DoneInfo{ + Err: err, + Trailer: tr, + BytesSent: a.s != nil, + BytesReceived: br, + }) + } + if a.statsHandler != nil { + end := &stats.End{ + Client: true, + BeginTime: a.cs.beginTime, + EndTime: time.Now(), + Error: err, + } + a.statsHandler.HandleRPC(a.cs.ctx, end) + } + if a.trInfo.tr != nil { + if err == nil { + a.trInfo.tr.LazyPrintf("RPC: [OK]") + } else { + a.trInfo.tr.LazyPrintf("RPC: [%v]", err) + a.trInfo.tr.SetError() + } + a.trInfo.tr.Finish() + a.trInfo.tr = nil + } + a.mu.Unlock() +} + +func (ac *addrConn) newClientStream(ctx context.Context, desc *StreamDesc, method string, t transport.ClientTransport, opts ...CallOption) (_ ClientStream, err error) { + ac.mu.Lock() + if ac.transport != t { + ac.mu.Unlock() + return nil, status.Error(codes.Canceled, "the provided transport is no longer valid to use") + } + // transition to CONNECTING state when an attempt starts + if ac.state != connectivity.Connecting { + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + ac.mu.Unlock() + + if t == nil { + // TODO: return RPC error here? + return nil, errors.New("transport provided is nil") + } + // defaultCallInfo contains unnecessary info(i.e. failfast, maxRetryRPCBufferSize), so we just initialize an empty struct. + c := &callInfo{} + + for _, o := range opts { + if err := o.before(c); err != nil { + return nil, toRPCErr(err) + } + } + c.maxReceiveMessageSize = getMaxSize(nil, c.maxReceiveMessageSize, defaultClientMaxReceiveMessageSize) + c.maxSendMessageSize = getMaxSize(nil, c.maxSendMessageSize, defaultServerMaxSendMessageSize) + + // Possible context leak: + // The cancel function for the child context we create will only be called + // when RecvMsg returns a non-nil error, if the ClientConn is closed, or if + // an error is generated by SendMsg. + // https://github.com/grpc/grpc-go/issues/1818. + ctx, cancel := context.WithCancel(ctx) + defer func() { + if err != nil { + cancel() + } + }() + + if err := setCallInfoCodec(c); err != nil { + return nil, err + } + + callHdr := &transport.CallHdr{ + Host: ac.cc.authority, + Method: method, + ContentSubtype: c.contentSubtype, + } + + // Set our outgoing compression according to the UseCompressor CallOption, if + // set. In that case, also find the compressor from the encoding package. + // Otherwise, use the compressor configured by the WithCompressor DialOption, + // if set. + var cp Compressor + var comp encoding.Compressor + if ct := c.compressorType; ct != "" { + callHdr.SendCompress = ct + if ct != encoding.Identity { + comp = encoding.GetCompressor(ct) + if comp == nil { + return nil, status.Errorf(codes.Internal, "grpc: Compressor is not installed for requested grpc-encoding %q", ct) + } + } + } else if ac.cc.dopts.cp != nil { + callHdr.SendCompress = ac.cc.dopts.cp.Type() + cp = ac.cc.dopts.cp + } + if c.creds != nil { + callHdr.Creds = c.creds + } + + as := &addrConnStream{ + callHdr: callHdr, + ac: ac, + ctx: ctx, + cancel: cancel, + opts: opts, + callInfo: c, + desc: desc, + codec: c.codec, + cp: cp, + comp: comp, + t: t, + } + + as.callInfo.stream = as + s, err := as.t.NewStream(as.ctx, as.callHdr) + if err != nil { + err = toRPCErr(err) + return nil, err + } + as.s = s + as.p = &parser{r: s} + ac.incrCallsStarted() + if desc != unaryStreamDesc { + // Listen on cc and stream contexts to cleanup when the user closes the + // ClientConn or cancels the stream context. In all other cases, an error + // should already be injected into the recv buffer by the transport, which + // the client will eventually receive, and then we will cancel the stream's + // context in clientStream.finish. + go func() { + select { + case <-ac.ctx.Done(): + as.finish(status.Error(codes.Canceled, "grpc: the SubConn is closing")) + case <-ctx.Done(): + as.finish(toRPCErr(ctx.Err())) + } + }() + } + return as, nil +} + +type addrConnStream struct { + s *transport.Stream + ac *addrConn + callHdr *transport.CallHdr + cancel context.CancelFunc + opts []CallOption + callInfo *callInfo + t transport.ClientTransport + ctx context.Context + sentLast bool + desc *StreamDesc + codec baseCodec + cp Compressor + comp encoding.Compressor + decompSet bool + dc Decompressor + decomp encoding.Compressor + p *parser + done func(balancer.DoneInfo) + mu sync.Mutex + finished bool +} + +func (as *addrConnStream) Header() (metadata.MD, error) { + m, err := as.s.Header() + if err != nil { + as.finish(toRPCErr(err)) + } + return m, err +} + +func (as *addrConnStream) Trailer() metadata.MD { + return as.s.Trailer() +} + +func (as *addrConnStream) CloseSend() error { + if as.sentLast { + // TODO: return an error and finish the stream instead, due to API misuse? + return nil + } + as.sentLast = true + + as.t.Write(as.s, nil, nil, &transport.Options{Last: true}) + // Always return nil; io.EOF is the only error that might make sense + // instead, but there is no need to signal the client to call RecvMsg + // as the only use left for the stream after CloseSend is to call + // RecvMsg. This also matches historical behavior. + return nil +} + +func (as *addrConnStream) Context() context.Context { + return as.s.Context() +} + +func (as *addrConnStream) SendMsg(m interface{}) (err error) { + defer func() { + if err != nil && err != io.EOF { + // Call finish on the client stream for errors generated by this SendMsg + // call, as these indicate problems created by this client. (Transport + // errors are converted to an io.EOF error in csAttempt.sendMsg; the real + // error will be returned from RecvMsg eventually in that case, or be + // retried.) + as.finish(err) + } + }() + if as.sentLast { + return status.Errorf(codes.Internal, "SendMsg called after CloseSend") + } + if !as.desc.ClientStreams { + as.sentLast = true + } + data, err := encode(as.codec, m) + if err != nil { + return err + } + compData, err := compress(data, as.cp, as.comp) + if err != nil { + return err + } + hdr, payld := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payld) > *as.callInfo.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payld), *as.callInfo.maxSendMessageSize) + } + + if err := as.t.Write(as.s, hdr, payld, &transport.Options{Last: !as.desc.ClientStreams}); err != nil { + if !as.desc.ClientStreams { + // For non-client-streaming RPCs, we return nil instead of EOF on error + // because the generated code requires it. finish is not called; RecvMsg() + // will call it with the stream's status independently. + return nil + } + return io.EOF + } + + if channelz.IsOn() { + as.t.IncrMsgSent() + } + return nil +} + +func (as *addrConnStream) RecvMsg(m interface{}) (err error) { + defer func() { + if err != nil || !as.desc.ServerStreams { + // err != nil or non-server-streaming indicates end of stream. + as.finish(err) + } + }() + + if !as.decompSet { + // Block until we receive headers containing received message encoding. + if ct := as.s.RecvCompress(); ct != "" && ct != encoding.Identity { + if as.dc == nil || as.dc.Type() != ct { + // No configured decompressor, or it does not match the incoming + // message encoding; attempt to find a registered compressor that does. + as.dc = nil + as.decomp = encoding.GetCompressor(ct) + } + } else { + // No compression is used; disable our decompressor. + as.dc = nil + } + // Only initialize this state once per stream. + as.decompSet = true + } + err = recv(as.p, as.codec, as.s, as.dc, m, *as.callInfo.maxReceiveMessageSize, nil, as.decomp) + if err != nil { + if err == io.EOF { + if statusErr := as.s.Status().Err(); statusErr != nil { + return statusErr + } + return io.EOF // indicates successful end of stream. + } + return toRPCErr(err) + } + + if channelz.IsOn() { + as.t.IncrMsgRecv() + } + if as.desc.ServerStreams { + // Subsequent messages should be received by subsequent RecvMsg calls. + return nil + } + + // Special handling for non-server-stream rpcs. + // This recv expects EOF or errors, so we don't collect inPayload. + err = recv(as.p, as.codec, as.s, as.dc, m, *as.callInfo.maxReceiveMessageSize, nil, as.decomp) + if err == nil { + return toRPCErr(errors.New("grpc: client streaming protocol violation: get , want ")) + } + if err == io.EOF { + return as.s.Status().Err() // non-server streaming Recv returns nil on success + } + return toRPCErr(err) +} + +func (as *addrConnStream) finish(err error) { + as.mu.Lock() + if as.finished { + as.mu.Unlock() + return + } + as.finished = true + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + if as.s != nil { + as.t.CloseStream(as.s, err) + } + + if err != nil { + as.ac.incrCallsFailed() + } else { + as.ac.incrCallsSucceeded() + } + as.cancel() + as.mu.Unlock() +} + +// ServerStream defines the server-side behavior of a streaming RPC. +// +// All errors returned from ServerStream methods are compatible with the +// status package. +type ServerStream interface { + // SetHeader sets the header metadata. It may be called multiple times. + // When call multiple times, all the provided metadata will be merged. + // All the metadata will be sent out when one of the following happens: + // - ServerStream.SendHeader() is called; + // - The first response is sent out; + // - An RPC status is sent out (error or success). + SetHeader(metadata.MD) error + // SendHeader sends the header metadata. + // The provided md and headers set by SetHeader() will be sent. + // It fails if called multiple times. + SendHeader(metadata.MD) error + // SetTrailer sets the trailer metadata which will be sent with the RPC status. + // When called more than once, all the provided metadata will be merged. + SetTrailer(metadata.MD) + // Context returns the context for this stream. + Context() context.Context + // SendMsg sends a message. On error, SendMsg aborts the stream and the + // error is returned directly. + // + // SendMsg blocks until: + // - There is sufficient flow control to schedule m with the transport, or + // - The stream is done, or + // - The stream breaks. + // + // SendMsg does not wait until the message is received by the client. An + // untimely stream closure may result in lost messages. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not safe + // to call SendMsg on the same stream in different goroutines. + SendMsg(m interface{}) error + // RecvMsg blocks until it receives a message into m or the stream is + // done. It returns io.EOF when the client has performed a CloseSend. On + // any non-EOF error, the stream is aborted and the error contains the + // RPC status. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not + // safe to call RecvMsg on the same stream in different goroutines. + RecvMsg(m interface{}) error +} + +// serverStream implements a server side Stream. +type serverStream struct { + ctx context.Context + t transport.ServerTransport + s *transport.Stream + p *parser + codec baseCodec + + cp Compressor + dc Decompressor + comp encoding.Compressor + decomp encoding.Compressor + + maxReceiveMessageSize int + maxSendMessageSize int + trInfo *traceInfo + + statsHandler stats.Handler + + binlog *binarylog.MethodLogger + // serverHeaderBinlogged indicates whether server header has been logged. It + // will happen when one of the following two happens: stream.SendHeader(), + // stream.Send(). + // + // It's only checked in send and sendHeader, doesn't need to be + // synchronized. + serverHeaderBinlogged bool + + mu sync.Mutex // protects trInfo.tr after the service handler runs. +} + +func (ss *serverStream) Context() context.Context { + return ss.ctx +} + +func (ss *serverStream) SetHeader(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + return ss.s.SetHeader(md) +} + +func (ss *serverStream) SendHeader(md metadata.MD) error { + err := ss.t.WriteHeader(ss.s, md) + if ss.binlog != nil && !ss.serverHeaderBinlogged { + h, _ := ss.s.Header() + ss.binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + ss.serverHeaderBinlogged = true + } + return err +} + +func (ss *serverStream) SetTrailer(md metadata.MD) { + if md.Len() == 0 { + return + } + ss.s.SetTrailer(md) +} + +func (ss *serverStream) SendMsg(m interface{}) (err error) { + defer func() { + if ss.trInfo != nil { + ss.mu.Lock() + if ss.trInfo.tr != nil { + if err == nil { + ss.trInfo.tr.LazyLog(&payload{sent: true, msg: m}, true) + } else { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + } + ss.mu.Unlock() + } + if err != nil && err != io.EOF { + st, _ := status.FromError(toRPCErr(err)) + ss.t.WriteStatus(ss.s, st) + // Non-user specified status was sent out. This should be an error + // case (as a server side Cancel maybe). + // + // This is not handled specifically now. User will return a final + // status from the service handler, we will log that error instead. + // This behavior is similar to an interceptor. + } + if channelz.IsOn() && err == nil { + ss.t.IncrMsgSent() + } + }() + data, err := encode(ss.codec, m) + if err != nil { + return err + } + compData, err := compress(data, ss.cp, ss.comp) + if err != nil { + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > ss.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payload), ss.maxSendMessageSize) + } + if err := ss.t.Write(ss.s, hdr, payload, &transport.Options{Last: false}); err != nil { + return toRPCErr(err) + } + if ss.binlog != nil { + if !ss.serverHeaderBinlogged { + h, _ := ss.s.Header() + ss.binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + ss.serverHeaderBinlogged = true + } + ss.binlog.Log(&binarylog.ServerMessage{ + Message: data, + }) + } + if ss.statsHandler != nil { + ss.statsHandler.HandleRPC(ss.s.Context(), outPayload(false, m, data, payload, time.Now())) + } + return nil +} + +func (ss *serverStream) RecvMsg(m interface{}) (err error) { + defer func() { + if ss.trInfo != nil { + ss.mu.Lock() + if ss.trInfo.tr != nil { + if err == nil { + ss.trInfo.tr.LazyLog(&payload{sent: false, msg: m}, true) + } else if err != io.EOF { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + } + ss.mu.Unlock() + } + if err != nil && err != io.EOF { + st, _ := status.FromError(toRPCErr(err)) + ss.t.WriteStatus(ss.s, st) + // Non-user specified status was sent out. This should be an error + // case (as a server side Cancel maybe). + // + // This is not handled specifically now. User will return a final + // status from the service handler, we will log that error instead. + // This behavior is similar to an interceptor. + } + if channelz.IsOn() && err == nil { + ss.t.IncrMsgRecv() + } + }() + var payInfo *payloadInfo + if ss.statsHandler != nil || ss.binlog != nil { + payInfo = &payloadInfo{} + } + if err := recv(ss.p, ss.codec, ss.s, ss.dc, m, ss.maxReceiveMessageSize, payInfo, ss.decomp); err != nil { + if err == io.EOF { + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ClientHalfClose{}) + } + return err + } + if err == io.ErrUnexpectedEOF { + err = status.Errorf(codes.Internal, io.ErrUnexpectedEOF.Error()) + } + return toRPCErr(err) + } + if ss.statsHandler != nil { + ss.statsHandler.HandleRPC(ss.s.Context(), &stats.InPayload{ + RecvTime: time.Now(), + Payload: m, + // TODO truncate large payload. + Data: payInfo.uncompressedBytes, + Length: len(payInfo.uncompressedBytes), + }) + } + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ClientMessage{ + Message: payInfo.uncompressedBytes, + }) + } + return nil +} + +// MethodFromServerStream returns the method string for the input stream. +// The returned string is in the format of "/service/method". +func MethodFromServerStream(stream ServerStream) (string, bool) { + return Method(stream.Context()) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go new file mode 100644 index 00000000..584360f6 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go @@ -0,0 +1,51 @@ +/* + * + * Copyright 2016 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 tap defines the function handles which are executed on the transport +// layer of gRPC-Go and related information. Everything here is EXPERIMENTAL. +package tap + +import ( + "context" +) + +// Info defines the relevant information needed by the handles. +type Info struct { + // FullMethodName is the string of grpc method (in the format of + // /package.service/method). + FullMethodName string + // TODO: More to be added. +} + +// ServerInHandle defines the function which runs before a new stream is created +// on the server side. If it returns a non-nil error, the stream will not be +// created and a RST_STREAM will be sent back to the client with REFUSED_STREAM. +// The client will receive an RPC error "code = Unavailable, desc = stream +// terminated by RST_STREAM with error code: REFUSED_STREAM". +// +// It's intended to be used in situations where you don't want to waste the +// resources to accept the new stream (e.g. rate-limiting). And the content of +// the error will be ignored and won't be sent back to the client. For other +// general usages, please use interceptors. +// +// Note that it is executed in the per-connection I/O goroutine(s) instead of +// per-RPC goroutine. Therefore, users should NOT have any +// blocking/time-consuming work in this handle. Otherwise all the RPCs would +// slow down. Also, for the same reason, this handle won't be called +// concurrently by gRPC. +type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/trace.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/trace.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/trace.go rename to functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/trace.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go new file mode 100644 index 00000000..260f27c8 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go @@ -0,0 +1,22 @@ +/* + * + * 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 grpc + +// Version is the current grpc version. +const Version = "1.17.0" diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh new file mode 100644 index 00000000..94d3d54e --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +if [[ `uname -a` = *"Darwin"* ]]; then + echo "It seems you are running on Mac. This script does not work on Mac. See https://github.com/grpc/grpc-go/issues/2047" + exit 1 +fi + +set -ex # Exit on error; debugging enabled. +set -o pipefail # Fail a pipe if any sub-command fails. + +die() { + echo "$@" >&2 + exit 1 +} + +# Check to make sure it's safe to modify the user's git repo. +if git status --porcelain | read; then + die "Uncommitted or untracked files found; commit changes first" +fi + +if [[ -d "${GOPATH}/src" ]]; then + die "\${GOPATH}/src (${GOPATH}/src) exists; this script will delete it." +fi + +# Undo any edits made by this script. +cleanup() { + rm -rf "${GOPATH}/src" + git reset --hard HEAD +} +trap cleanup EXIT + +fail_on_output() { + tee /dev/stderr | (! read) +} + +PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}" + +if [[ "$1" = "-install" ]]; then + # Check for module support + if go help mod >& /dev/null; then + go install \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/goimports \ + honnef.co/go/tools/cmd/staticcheck \ + github.com/client9/misspell/cmd/misspell \ + github.com/golang/protobuf/protoc-gen-go + else + # Ye olde `go get` incantation. + # Note: this gets the latest version of all tools (vs. the pinned versions + # with Go modules). + go get -u \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/goimports \ + honnef.co/go/tools/cmd/staticcheck \ + github.com/client9/misspell/cmd/misspell \ + github.com/golang/protobuf/protoc-gen-go + fi + if [[ -z "${VET_SKIP_PROTO}" ]]; then + if [[ "${TRAVIS}" = "true" ]]; then + PROTOBUF_VERSION=3.3.0 + PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip + pushd /home/travis + wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} + unzip ${PROTOC_FILENAME} + bin/protoc --version + popd + elif ! which protoc > /dev/null; then + die "Please install protoc into your path" + fi + fi + exit 0 +elif [[ "$#" -ne 0 ]]; then + die "Unknown argument(s): $*" +fi + +# - Ensure all source files contain a copyright message. +git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | fail_on_output + +# - Do not import math/rand for real library code. Use internal/grpcrand for +# thread safety. +git ls-files "*.go" | xargs grep -l '"math/rand"' 2>&1 | (! grep -v '^examples\|^stress\|grpcrand') + +# - Ensure all ptypes proto packages are renamed when importing. +git ls-files "*.go" | (! xargs grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/") + +# - Check imports that are illegal in appengine (until Go 1.11). +# TODO: Remove when we drop Go 1.10 support +go list -f {{.Dir}} ./... | xargs go run test/go_vet/vet.go + +# - gofmt, goimports, golint (with exceptions for generated code), go vet. +gofmt -s -d -l . 2>&1 | fail_on_output +goimports -l . 2>&1 | fail_on_output +golint ./... 2>&1 | (! grep -vE "(_mock|\.pb)\.go:") +go tool vet -all . + +# - Check that generated proto files are up to date. +if [[ -z "${VET_SKIP_PROTO}" ]]; then + PATH="/home/travis/bin:${PATH}" make proto && \ + git status --porcelain 2>&1 | fail_on_output || \ + (git status; git --no-pager diff; exit 1) +fi + +# - Check that our module is tidy. +if go help mod >& /dev/null; then + go mod tidy && \ + git status --porcelain 2>&1 | fail_on_output || \ + (git status; git --no-pager diff; exit 1) +fi + +# - Collection of static analysis checks +### HACK HACK HACK: Remove once staticcheck works with modules. +# Make a symlink in ${GOPATH}/src to its ${GOPATH}/pkg/mod equivalent for every package we use. +for x in $(find "${GOPATH}/pkg/mod" -name '*@*' | grep -v \/mod\/cache\/); do + pkg="$(echo ${x#"${GOPATH}/pkg/mod/"} | cut -f1 -d@)"; + # If multiple versions exist, just use the existing one. + if [[ -L "${GOPATH}/src/${pkg}" ]]; then continue; fi + mkdir -p "$(dirname "${GOPATH}/src/${pkg}")"; + ln -s $x "${GOPATH}/src/${pkg}"; +done +### END HACK HACK HACK + +# TODO(menghanl): fix errors in transport_test. +staticcheck -ignore ' +balancer.go:SA1019 +balancer_test.go:SA1019 +clientconn_test.go:SA1019 +balancer/roundrobin/roundrobin_test.go:SA1019 +benchmark/benchmain/main.go:SA1019 +internal/transport/handler_server.go:SA1019 +internal/transport/handler_server_test.go:SA1019 +internal/transport/transport_test.go:SA2002 +stats/stats_test.go:SA1019 +test/channelz_test.go:SA1019 +test/end2end_test.go:SA1019 +' ./... +misspell -error . diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml new file mode 100644 index 00000000..9f556934 --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml @@ -0,0 +1,12 @@ +language: go + +go: + - 1.4 + - 1.5 + - 1.6 + - 1.7 + - 1.8 + - 1.9 + - tip + +go_import_path: gopkg.in/yaml.v2 diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go index a14435e8..0ee738e1 100644 --- a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go @@ -13,6 +13,19 @@ import ( "unicode/utf8" ) +// jsonNumber is the interface of the encoding/json.Number datatype. +// Repeating the interface here avoids a dependency on encoding/json, and also +// supports other libraries like jsoniter, which use a similar datatype with +// the same interface. Detecting this interface is useful when dealing with +// structures containing json.Number, which is a string under the hood. The +// encoder should prefer the use of Int64(), Float64() and string(), in that +// order, when encoding this type. +type jsonNumber interface { + Float64() (float64, error) + Int64() (int64, error) + String() string +} + type encoder struct { emitter yaml_emitter_t event yaml_event_t @@ -89,6 +102,21 @@ func (e *encoder) marshal(tag string, in reflect.Value) { } iface := in.Interface() switch m := iface.(type) { + case jsonNumber: + integer, err := m.Int64() + if err == nil { + // In this case the json.Number is a valid int64 + in = reflect.ValueOf(integer) + break + } + float, err := m.Float64() + if err == nil { + // In this case the json.Number is a valid float64 + in = reflect.ValueOf(float) + break + } + // fallback case - no number could be obtained + in = reflect.ValueOf(m.String()) case time.Time, *time.Time: // Although time.Time implements TextMarshaler, // we don't want to treat it as a string for YAML diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt new file mode 100644 index 00000000..4e4e1ddb --- /dev/null +++ b/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt @@ -0,0 +1,134 @@ +# github.com/cespare/xxhash v1.1.0 +github.com/cespare/xxhash +# github.com/cpuguy83/go-md2man v1.0.8 +github.com/cpuguy83/go-md2man/md2man +# github.com/davecgh/go-spew v1.1.1 +github.com/davecgh/go-spew/spew +# github.com/ghodss/yaml v1.0.0 +github.com/ghodss/yaml +# github.com/golang/protobuf v1.2.0 +github.com/golang/protobuf/proto +github.com/golang/protobuf/ptypes +github.com/golang/protobuf/ptypes/any +github.com/golang/protobuf/ptypes/duration +github.com/golang/protobuf/ptypes/timestamp +# github.com/imdario/mergo v0.3.7 +github.com/imdario/mergo +# github.com/inconshreveable/mousetrap v1.0.0 +github.com/inconshreveable/mousetrap +# github.com/klauspost/compress v1.4.0 +github.com/klauspost/compress/flate +github.com/klauspost/compress/gzip +github.com/klauspost/compress/zlib +# github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e +github.com/klauspost/cpuid +# github.com/mattn/go-colorable v0.0.9 +github.com/mattn/go-colorable +# github.com/mattn/go-isatty v0.0.4 +github.com/mattn/go-isatty +# github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b +github.com/mgutz/ansi +# github.com/nuclio/logger v0.0.1 +github.com/nuclio/logger +# github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 +github.com/nuclio/nuclio-sdk-go +# github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 +github.com/nuclio/nuclio-test-go +# github.com/nuclio/zap v0.0.2 +github.com/nuclio/zap +# github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8 +github.com/pavius/zap +github.com/pavius/zap/zapcore +github.com/pavius/zap/internal/bufferpool +github.com/pavius/zap/buffer +github.com/pavius/zap/internal/color +github.com/pavius/zap/internal/exit +# github.com/pkg/errors v0.8.1 +github.com/pkg/errors +# github.com/pmezard/go-difflib v1.0.0 +github.com/pmezard/go-difflib/difflib +# github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a +github.com/rcrowley/go-metrics +# github.com/russross/blackfriday v1.5.2+incompatible +github.com/russross/blackfriday +# github.com/spf13/cobra v0.0.3 +github.com/spf13/cobra +github.com/spf13/cobra/doc +# github.com/spf13/pflag v1.0.3 +github.com/spf13/pflag +# github.com/stretchr/testify v1.3.0 +github.com/stretchr/testify/assert +github.com/stretchr/testify/suite +github.com/stretchr/testify/require +# github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 +github.com/v3io/frames +github.com/v3io/frames/pb +# github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 +github.com/v3io/v3io-go-http +# github.com/valyala/bytebufferpool v1.0.0 +github.com/valyala/bytebufferpool +# github.com/valyala/fasthttp v1.0.0 +github.com/valyala/fasthttp +github.com/valyala/fasthttp/fasthttputil +github.com/valyala/fasthttp/stackless +# github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 => github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 +github.com/xwb1989/sqlparser +github.com/xwb1989/sqlparser/dependency/bytes2 +github.com/xwb1989/sqlparser/dependency/querypb +github.com/xwb1989/sqlparser/dependency/sqltypes +github.com/xwb1989/sqlparser/dependency/hack +# go.uber.org/atomic v1.3.2 +go.uber.org/atomic +# go.uber.org/multierr v1.1.0 +go.uber.org/multierr +# golang.org/x/net v0.0.0-20181114220301-adae6a3d119a +golang.org/x/net/context +golang.org/x/net/trace +golang.org/x/net/internal/timeseries +golang.org/x/net/http2 +golang.org/x/net/http2/hpack +golang.org/x/net/http/httpguts +golang.org/x/net/idna +# golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 +golang.org/x/sys/unix +# golang.org/x/text v0.3.0 +golang.org/x/text/secure/bidirule +golang.org/x/text/unicode/bidi +golang.org/x/text/unicode/norm +golang.org/x/text/transform +# google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9 +google.golang.org/genproto/googleapis/rpc/status +# google.golang.org/grpc v1.17.0 +google.golang.org/grpc +google.golang.org/grpc/balancer +google.golang.org/grpc/balancer/roundrobin +google.golang.org/grpc/codes +google.golang.org/grpc/connectivity +google.golang.org/grpc/credentials +google.golang.org/grpc/encoding +google.golang.org/grpc/encoding/proto +google.golang.org/grpc/grpclog +google.golang.org/grpc/internal +google.golang.org/grpc/internal/backoff +google.golang.org/grpc/internal/binarylog +google.golang.org/grpc/internal/channelz +google.golang.org/grpc/internal/envconfig +google.golang.org/grpc/internal/grpcrand +google.golang.org/grpc/internal/grpcsync +google.golang.org/grpc/internal/transport +google.golang.org/grpc/keepalive +google.golang.org/grpc/metadata +google.golang.org/grpc/naming +google.golang.org/grpc/peer +google.golang.org/grpc/resolver +google.golang.org/grpc/resolver/dns +google.golang.org/grpc/resolver/passthrough +google.golang.org/grpc/stats +google.golang.org/grpc/status +google.golang.org/grpc/tap +google.golang.org/grpc/balancer/base +google.golang.org/grpc/credentials/internal +google.golang.org/grpc/binarylog/grpc_binarylog_v1 +google.golang.org/grpc/internal/syscall +# gopkg.in/yaml.v2 v2.2.2 +gopkg.in/yaml.v2 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/.travis.yml index 639fe101..87479c6f 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/.travis.yml +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/.travis.yml @@ -3,11 +3,14 @@ language: go go: - "1.12.x" +env: + - GO111MODULE=on TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" + script: - make test - make lint - - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io.yaml" TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" make integration - - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io_bench.yaml" TSDB_TEST_TABLE_PATH="TSDB_INTEGRATION_TESTS/$TRAVIS_BUILD_NUMBER" TSDB_BENCH_INGEST_CONFIG="$TRAVIS_BUILD_DIR/test/benchmark/testdata/tsdb-bench-test-config-ci.yaml" make bench + - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io.yaml" make integration + - V3IO_TSDB_CONFIG="$TRAVIS_BUILD_DIR/travis_v3io_bench.yaml" TSDB_BENCH_INGEST_CONFIG="$TRAVIS_BUILD_DIR/test/benchmark/testdata/tsdb-bench-test-config-ci.yaml" make bench before_deploy: - GOOS=linux GOARCH=amd64 make build diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile b/functions/query/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile index 008af0f8..443362b0 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/Jenkinsfile @@ -3,6 +3,7 @@ BUILD_FOLDER = "/go" attempts=15 git_project = "v3io-tsdb" git_project_user = "v3io" +git_project_upstream_user = "v3io" git_deploy_user = "iguazio-prod-git-user" git_deploy_user_token = "iguazio-prod-git-user-token" git_deploy_user_private_key = "iguazio-prod-git-user-private-key" @@ -14,7 +15,7 @@ def build_v3io_tsdb(TAG_VERSION) { def git_project = 'v3io-tsdb' stage('prepare sources') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { git(changelog: false, credentialsId: git_deploy_user_private_key, poll: false, url: "git@github.com:${git_project_user}/${git_project}.git") sh("git checkout ${TAG_VERSION}") } @@ -23,11 +24,11 @@ def build_v3io_tsdb(TAG_VERSION) { stage("build ${git_project} binaries in dood") { container('golang') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ - GOOS=linux GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin - GOOS=darwin GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin - GOOS=windows GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=linux GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=darwin GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin + GO111MODULE=on GOOS=windows GOARCH=amd64 TRAVIS_TAG=${TAG_VERSION} make bin ls -la /go/bin """ } @@ -59,35 +60,68 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { def git_project = 'tsdb-nuclio' stage('prepare sources') { container('jnlp') { - if(!fileExists("${BUILD_FOLDER}/src/github.com/v3io/${git_project}")) { - sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/v3io/${git_project}") + if (!fileExists("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}")) { + sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project_upstream_user}/${git_project}") } - if ( "${internal_status}" == "unstable" ) { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + if ("${internal_status}" == "unstable") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout development") } } else { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout master") } } - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { - sh """ - rm -rf functions/ingest/vendor/github.com/v3io/v3io-tsdb functions/query/vendor/github.com/v3io/v3io-tsdb - git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/ingest/vendor/github.com/v3io/v3io-tsdb - cd functions/ingest/vendor/github.com/v3io/v3io-tsdb - git checkout ${V3IO_TSDB_VERSION} - rm -rf .git vendor/github.com/nuclio vendor/github.com/v3io/frames/vendor/golang.org/x/net - cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project} - cp -R functions/ingest/vendor/github.com/v3io/v3io-tsdb functions/query/vendor/github.com/v3io/v3io-tsdb - """ - } } + parallel( + 'update tsdb in ingest': { + container('jnlp') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh """ + rm -rf functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + cd functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git checkout ${V3IO_TSDB_VERSION} + """ + } + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}/functions/ingest/vendor/github.com/${git_project_upstream_user}/v3io-tsdb") { + sh """ + GO111MODULE=on go mod vendor + rm -rf .git vendor/github.com/nuclio vendor/github.com/${git_project_upstream_user}/frames/vendor/golang.org/x/net vendor/golang.org/x/net + """ + } + } + }, + 'update tsdb in query': { + container('jnlp') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh """ + rm -rf functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + cd functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb + git checkout ${V3IO_TSDB_VERSION} + """ + } + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}/functions/query/vendor/github.com/${git_project_upstream_user}/v3io-tsdb") { + sh """ + GO111MODULE=on go mod vendor + rm -rf .git vendor/github.com/nuclio vendor/github.com/${git_project_upstream_user}/frames/vendor/golang.org/x/net vendor/golang.org/x/net + """ + } + } + } + ) } stage('git push') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ git config --global user.email '${GIT_USERNAME}@iguazio.com' git config --global user.name '${GIT_USERNAME}' @@ -96,7 +130,7 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { git add functions/ingest/vendor/github.com functions/query/vendor/github.com; """ try { - sh("git commit -am 'Updated TSDB to ${V3IO_TSDB_VERSION}'") + sh("git commit -m 'Updated TSDB to ${V3IO_TSDB_VERSION}'") } catch (err) { echo "Can not commit" } @@ -112,6 +146,9 @@ def build_nuclio(V3IO_TSDB_VERSION, internal_status="stable") { } } } + container('golang') { + sh("rm -rf ${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") + } } } } @@ -126,33 +163,37 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { stage('prepare sources') { container('jnlp') { - if(!fileExists("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}")) { - sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project}/${git_project}") + if (!fileExists("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}")) { + sh("cd ${BUILD_FOLDER}; git clone https://${GIT_TOKEN}@github.com/${git_project_user}/${git_project}.git src/github.com/${git_project_upstream_user}/${git_project}") } - if ( "${internal_status}" == "unstable" ) { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + if ("${internal_status}" == "unstable") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout development") } } else { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + sh("git stash") sh("git checkout master") } } - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { - sh """ - rm -rf vendor/github.com/v3io/v3io-tsdb/ - git clone https://${GIT_TOKEN}@github.com/${git_project_user}/v3io-tsdb.git vendor/github.com/v3io/v3io-tsdb - cd vendor/github.com/v3io/v3io-tsdb - git checkout ${V3IO_TSDB_VERSION} - rm -rf .git vendor/github.com/${git_project} vendor/github.com/v3io/frames/vendor/golang.org/x/net - """ + } + container('golang') { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { + if("${git_project_user}" != "${git_project_upstream_user}") { + sh("GO111MODULE=on go mod edit -replace github.com/${git_project_upstream_user}/v3io-tsdb=github.com/${git_project_user}/v3io-tsdb@${V3IO_TSDB_VERSION}") + sh("GO111MODULE=on go get") + } else { + sh("GO111MODULE=on go get github.com/${git_project_user}/v3io-tsdb@${V3IO_TSDB_VERSION}") + } + sh("GO111MODULE=on go mod vendor") } } } stage('git push') { container('jnlp') { - dir("${BUILD_FOLDER}/src/github.com/${git_project}/${git_project}") { + dir("${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") { sh """ git config --global user.email '${GIT_USERNAME}@iguazio.com' git config --global user.name '${GIT_USERNAME}' @@ -161,7 +202,7 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { git add vendor/github.com; """ try { - sh("git commit -am 'Updated TSDB to ${V3IO_TSDB_VERSION}'") + sh("git commit -m 'Updated TSDB to ${V3IO_TSDB_VERSION}'") } catch (err) { echo "Can not commit" } @@ -177,6 +218,9 @@ def build_prometheus(V3IO_TSDB_VERSION, internal_status="stable") { } } } + container('golang') { + sh("rm -rf ${BUILD_FOLDER}/src/github.com/${git_project_upstream_user}/${git_project}") + } } } } @@ -206,9 +250,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") if (github.check_tag_expiration(git_project, git_project_user, MAIN_TAG_VERSION, GIT_TOKEN)) { parallel( 'v3io-tsdb': { - podTemplate(label: "v3io-tsdb-${label}", inheritFrom: "${git_project}-${label}", containers: [ - containerTemplate(name: 'golang', image: 'golang:1.11') - ]) { + podTemplate(label: "v3io-tsdb-${label}", inheritFrom: "jnlp-docker-golang") { node("v3io-tsdb-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') @@ -219,7 +261,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") } }, 'tsdb-nuclio': { - podTemplate(label: "v3io-tsdb-nuclio-${label}", inheritFrom: "${git_project}-${label}") { + podTemplate(label: "v3io-tsdb-nuclio-${label}", inheritFrom: "jnlp-docker") { node("v3io-tsdb-nuclio-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') @@ -259,7 +301,7 @@ podTemplate(label: "${git_project}-${label}", inheritFrom: "jnlp-docker-golang") } }, 'prometheus': { - podTemplate(label: "v3io-tsdb-prometheus-${label}", inheritFrom: "${git_project}-${label}") { + podTemplate(label: "v3io-tsdb-prometheus-${label}", inheritFrom: "jnlp-docker") { node("v3io-tsdb-prometheus-${label}") { withCredentials([ string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/go.mod b/functions/query/vendor/github.com/v3io/v3io-tsdb/go.mod new file mode 100644 index 00000000..0becd8c3 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/go.mod @@ -0,0 +1,35 @@ +module github.com/v3io/v3io-tsdb + +go 1.12 + +require ( + github.com/cespare/xxhash v1.1.0 + github.com/cpuguy83/go-md2man v1.0.8 // indirect + github.com/ghodss/yaml v1.0.0 + github.com/imdario/mergo v0.3.7 + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/nuclio/logger v0.0.1 + github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 + github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 + github.com/nuclio/zap v0.0.2 + github.com/pkg/errors v0.8.1 + github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a + github.com/russross/blackfriday v1.5.2+incompatible // indirect + github.com/spf13/cobra v0.0.3 + github.com/spf13/pflag v1.0.3 // indirect + github.com/stretchr/testify v1.3.0 + github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 + github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 + github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 + golang.org/x/net v0.0.0-20181114220301-adae6a3d119a // indirect + golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect + golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 // indirect + google.golang.org/grpc v1.17.0 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect +) + +replace ( + github.com/xwb1989/sqlparser => github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 + labix.org/v2/mgo => github.com/go-mgo/mgo v0.0.0-20180705113738-7446a0344b7872c067b3d6e1b7642571eafbae17 + launchpad.net/gocheck => github.com/go-check/check v0.0.0-20180628173108-788fd78401277ebd861206a03c884797c6ec5541 +) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/go.sum b/functions/query/vendor/github.com/v3io/v3io-tsdb/go.sum new file mode 100644 index 00000000..88dd27e0 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/go.sum @@ -0,0 +1,125 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cpuguy83/go-md2man v1.0.8 h1:DwoNytLphI8hzS2Af4D0dfaEaiSq2bN05mEm4R6vf8M= +github.com/cpuguy83/go-md2man v1.0.8/go.mod h1:N6JayAiVKtlHSnuTCeuLSQVs75hb8q+dYQLjr7cDsKY= +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/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8= +github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM= +github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +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/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/nuclio/logger v0.0.0-20180410162335-ccc5ab971395/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo= +github.com/nuclio/logger v0.0.1 h1:e+vT/Ug65RC+u0QX2J+lq3P57ZBwJ1ZA6Q2LCEcViwE= +github.com/nuclio/logger v0.0.1/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo= +github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 h1:wSCJEH8mUQ3VTyUukbYdxmi0UMmB14Lu1GOlNOs0dWY= +github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324/go.mod h1:NqMgotiF6Y0Ho4+i5AvJhH3FRKAyL4IMaMv/eoUOkKQ= +github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 h1:OubDnFViat46haboYrm/rMyMcmctrAjJ+eFJGh4qXSA= +github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37/go.mod h1:aO4cdrk1L42/y4l7IPeNAcY+9bb060Sjpr56+LiTmMc= +github.com/nuclio/zap v0.0.0-20180228181516-4a2bd2f9ef28/go.mod h1:SUxPsgePvlyjx6c5MtGdB50pf0IQThtlyLwISLboeuc= +github.com/nuclio/zap v0.0.2 h1:rY5PkMOl8CTkqRqIPuxziBiKK6Mq/8oEurfgRnNtqf0= +github.com/nuclio/zap v0.0.2/go.mod h1:SUxPsgePvlyjx6c5MtGdB50pf0IQThtlyLwISLboeuc= +github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8 h1:1N/m7VjDY1Pd30Uwv6bLttZVFQm3n8RUK9Ylf2J+4a4= +github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8/go.mod h1:6FWOCx06uh50GClv8S2cfk3asqTJs3qq3ZNRtLZE77I= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +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/prometheus v2.5.0+incompatible h1:7QPitgO2kOFG8ecuRn9O/4L9+10He72rVRJvMXrE9Hg= +github.com/prometheus/prometheus v2.5.0+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/russross/blackfriday v1.5.2+incompatible h1:/YIL6L1Deczl4O/cQ7ZVdrdKwuB6y7EWpw9LkD8xofE= +github.com/russross/blackfriday v1.5.2+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 h1:Y/ABiIlS3tqLHsj0DZkkpMyvdoCmU1nwgQ0On6n6imk= +github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15/go.mod h1:6aKW4Wl4A+gQhXH0JRCVOLgwvcrLyk+fqEpemuie094= +github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 h1:myF4tU/HdFWU1UzMdf16cHRbownzsyvL7VKIHqkrSvo= +github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871/go.mod h1:QD2Bo64oyTWzeV8RFehXS0hZEDFgOK99/h2a6ErRu6E= +github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 h1:NJc63wM25iS+ci5z7LVwjWD4QM0QpTQw/fovKzatss0= +github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2/go.mod h1:GXYcR9MxgfbE3BJdkXki5EclvtS8Nxu2RQNLA8hMMog= +github.com/v3io/v3io-tsdb v0.0.0-20190328071546-4e85f3df2d205fc7368d54184bb2ceff949ab4bd/go.mod h1:A+5yKC16QxLf+Fy5v7VvIxSw+jwsKHLhUS7dCYFDLAA= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco= +github.com/valyala/fasthttp v1.0.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 h1:x6rhz8Y9CjbgQkccRGmELH6K+LJj7tOoh3XWeC1yaQM= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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 h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/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-20181026203630-95b1ffbd15a5 h1:x6r4Jo0KNzOOzYd8lbcRsqjuqEASK6ob3auvWYM4/8U= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 h1:mzjBh+S5frKOsOBobWIMAbXavqjmgO17k/2puhcFR94= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9 h1:26lptpu+T60F849wXfTQMz9ecFf6nTQM0J1JjLSga5U= +google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.16.0 h1:dz5IJGuC2BB7qXR5AyHNwAUBhZscK2xVez7mznh72sY= +google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= +google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +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.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go index ac93cd49..94c6f11d 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/aggregate/aggregationParams.go @@ -6,15 +6,23 @@ import ( ) type AggregationParams struct { - colName string // column name ("v" in timeseries) - aggrMask AggrType // the sum of aggregates (or between all aggregates) - rollupTime int64 // time per bucket (cell in the array) - Interval int64 // requested (query) aggregation step - buckets int // number of buckets in the array - overlapWindows []int // a list of overlapping windows (* interval), e.g. last 1hr, 6hr, 12hr, 24hr + colName string // column name ("v" in timeseries) + aggrMask AggrType // the sum of aggregates (or between all aggregates) + rollupTime int64 // time per bucket (cell in the array) + Interval int64 // requested (query) aggregation step + buckets int // number of buckets in the array + overlapWindows []int // a list of overlapping windows (* interval), e.g. last 1hr, 6hr, 12hr, 24hr + aggregationWindow int64 // a time window on which to calculate the aggregation per Interval + disableClientAggregation bool + useServerAggregateCoefficient int } -func NewAggregationParams(functions, col string, buckets int, interval, rollupTime int64, windows []int) (*AggregationParams, error) { +func NewAggregationParams(functions, col string, + buckets int, + interval, aggregationWindow, rollupTime int64, + windows []int, + disableClientAggregation bool, + useServerAggregateCoefficient int) (*AggregationParams, error) { aggregatesList := strings.Split(functions, ",") aggrMask, _, err := AggregatesFromStringListWithCount(aggregatesList) @@ -23,12 +31,15 @@ func NewAggregationParams(functions, col string, buckets int, interval, rollupTi } newAggregateSeries := AggregationParams{ - aggrMask: aggrMask, - colName: col, - buckets: buckets, - rollupTime: rollupTime, - Interval: interval, - overlapWindows: windows, + aggrMask: aggrMask, + colName: col, + buckets: buckets, + rollupTime: rollupTime, + aggregationWindow: aggregationWindow, + Interval: interval, + overlapWindows: windows, + disableClientAggregation: disableClientAggregation, + useServerAggregateCoefficient: useServerAggregateCoefficient, } return &newAggregateSeries, nil @@ -42,7 +53,8 @@ func (as *AggregationParams) CanAggregate(partitionAggr AggrType) bool { // if interval and rollup are not even divisors we need higher resolution (3x) to smooth the graph // when we add linear/spline graph projection we can reduce back to 1x return ((aggrMask & partitionAggr) == aggrMask) && - as.Interval >= as.rollupTime && (as.Interval%as.rollupTime == 0 || as.Interval/as.rollupTime > 3) + (as.Interval/as.rollupTime > int64(as.useServerAggregateCoefficient) || (as.Interval == as.rollupTime && as.disableClientAggregation)) && + (as.aggregationWindow == 0 || as.aggregationWindow >= as.rollupTime) } func (as *AggregationParams) GetAggrMask() AggrType { @@ -53,6 +65,14 @@ func (as *AggregationParams) GetRollupTime() int64 { return as.rollupTime } +func (as *AggregationParams) GetAggregationWindow() int64 { + return as.aggregationWindow +} + +func (as *AggregationParams) HasAggregationWindow() bool { + return as.aggregationWindow > 0 +} + func (as *AggregationParams) toAttrName(aggr AggrType) string { return fmt.Sprintf("_%v_%v", as.colName, aggr.String()) } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go index 8b9a83b0..94900869 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store.go @@ -58,6 +58,7 @@ type chunkStore struct { performanceReporter *performance.MetricReporter curChunk int + nextTid int64 lastTid int64 chunks [2]*attrAppender @@ -142,6 +143,7 @@ func (cs *chunkStore) getChunksState(mc *MetricsCache, metric *MetricState) (boo if !cs.isAggr() { cs.chunks[0].initialize(part, t) } + cs.nextTid = t cs.aggrList = aggregate.NewAggregatesList(part.AggrType()) // TODO: if policy to merge w old chunks needs to get prev chunk, vs restart appender @@ -214,10 +216,9 @@ func (cs *chunkStore) processGetResp(mc *MetricsCache, metric *MetricState, resp if cs.chunks[0].inRange(maxTime) && !mc.cfg.OverrideOld { cs.chunks[0].state |= chunkStateMerge } - - // Set Last TableId - indicate that there is no need to create metric object - cs.lastTid = cs.chunks[0].partition.GetStartTime() } + // Set Last TableId - indicate that there is no need to create metric object + cs.lastTid = cs.nextTid } // Append data to the right chunk and table based on the time and state @@ -255,6 +256,7 @@ func (cs *chunkStore) chunkByTime(t int64, isVariantEncoding bool) *attrAppender } nextPart, _ := part.NextPart(t) cur.initialize(nextPart, t) + cs.nextTid = t cur.appender = app cs.curChunk = cs.curChunk ^ 1 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go deleted file mode 100644 index 1248852e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/appender/store_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package appender - -import ( - "testing" -) - -func TestStore(t *testing.T) { - - //store := NewChunkStore() - //store.state = storeStateReady - //store.Append(1521531613002, 1.1) - //store.Append(1521531613002+3500000, 2.1) - - //lset := labels.Labels{labels.Label{Name: "__name__", Value: "http_req"}, - // labels.Label{Name: "method", Value: "post"}} - - //exp, tid := store.writeChunks(lset) - //println(exp, tid) - //store.ProcessWriteResp() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go index 21cb7cf1..e53810d6 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config.go @@ -33,6 +33,8 @@ import ( "github.com/pkg/errors" ) +var defaultDisableNginxMitigation = true + const ( V3ioConfigEnvironmentVariable = "V3IO_TSDB_CONFIG" DefaultConfigurationFileName = "v3io-tsdb-config.yaml" @@ -48,15 +50,16 @@ const ( defaultMinimumChunkSize = 200 // bytes defaultMaximumChunkSize = 32000 // bytes - DefaultShardingBucketsCount = 8 - DefaultStorageClass = "local" - DefaultIngestionRate = "" - DefaultAggregates = "" // no aggregates by default - DefaultAggregationGranularity = "1h" - DefaultLayerRetentionTime = "1y" - DefaultSampleRetentionTime = 0 - DefaultLogLevel = "info" - DefaultVerboseLevel = "debug" + DefaultShardingBucketsCount = 8 + DefaultStorageClass = "local" + DefaultIngestionRate = "" + DefaultAggregates = "" // no aggregates by default + DefaultAggregationGranularity = "1h" + DefaultLayerRetentionTime = "1y" + DefaultSampleRetentionTime = 0 + DefaultLogLevel = "info" + DefaultVerboseLevel = "debug" + DefaultUseServerAggregateCoefficient = 3 // KV attribute names MaxTimeAttrName = "_maxtime" @@ -137,8 +140,6 @@ type V3ioConfig struct { // Number of parallel V3IO worker routines for queries; // default = the minimum value between 8 and Workers QryWorkers int `json:"qryWorkers"` - // Max uncommitted (delayed) samples allowed per metric - MaxBehind int `json:"maxBehind"` // Override last chunk; by default, an append from the last point is attempted upon restart OverrideOld bool `json:"overrideOld"` // Default timeout duration, in seconds; default = 3,600 seconds (1 hour) @@ -163,7 +164,12 @@ type V3ioConfig struct { // Build Info BuildInfo *BuildInfo `json:"buildInfo,omitempty"` // Override nginx bug - DisableNginxMitigation bool `json:"disableNginxMitigation,omitempty"` + DisableNginxMitigation *bool `json:"disableNginxMitigation,omitempty"` + // explicitly always use client aggregation + UsePreciseAggregations bool `json:"usePreciseAggregations,omitempty"` + // Coefficient to decide whether or not to use server aggregates optimization + // use server aggregations if ` / > UseServerAggregateCoefficient` + UseServerAggregateCoefficient int `json:"useServerAggregateCoefficient,omitempty"` } type MetricsReporterConfig struct { @@ -276,6 +282,11 @@ func GetOrLoadFromStruct(cfg *V3ioConfig) (*V3ioConfig, error) { return instance, nil } +// Eagerly reloads TSDB configuration. Note: not thread-safe +func UpdateConfig(path string) { + instance, failure = loadConfig(path) +} + // Update the defaults when using an existing configuration structure (custom configuration) func WithDefaults(cfg *V3ioConfig) *V3ioConfig { initDefaults(cfg) @@ -417,4 +428,12 @@ func initDefaults(cfg *V3ioConfig) { if cfg.ShardingBucketsCount == 0 { cfg.ShardingBucketsCount = DefaultShardingBucketsCount } + + if cfg.UseServerAggregateCoefficient == 0 { + cfg.UseServerAggregateCoefficient = DefaultUseServerAggregateCoefficient + } + + if cfg.DisableNginxMitigation == nil { + cfg.DisableNginxMitigation = &defaultDisableNginxMitigation + } } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go index 4f1f2985..e7836faf 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/config/config_test.go @@ -1,3 +1,5 @@ +// +build unit + package config import ( diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go index cde2c401..fe5a9c6a 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/formatters.go @@ -4,6 +4,8 @@ import ( "encoding/csv" "fmt" "io" + "strconv" + "time" "github.com/pkg/errors" "github.com/v3io/v3io-tsdb/pkg/chunkenc" @@ -45,6 +47,13 @@ func (f textFormatter) Write(out io.Writer, set utils.SeriesSet) error { return nil } +func (f textFormatter) timeString(t int64) string { + if f.cfg.TimeFormat == "" { + return strconv.Itoa(int(t)) + } + return time.Unix(t/1000, 0).Format(f.cfg.TimeFormat) +} + type csvFormatter struct { baseFormatter } @@ -61,7 +70,7 @@ func (f csvFormatter) Write(out io.Writer, set utils.SeriesSet) error { for iter.Next() { t, v := iter.At() - writer.Write([]string{name, labelStr, fmt.Sprintf("%.6f", v), f.timeString(t)}) + _ = writer.Write([]string{name, labelStr, fmt.Sprintf("%.6f", v), strconv.FormatInt(t, 10)}) } if iter.Err() != nil { diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go index fee148fe..95a19506 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/formatter/type.go @@ -3,7 +3,6 @@ package formatter import ( "fmt" "io" - "strconv" "strings" "time" @@ -43,16 +42,9 @@ type baseFormatter struct { cfg *FormatterConfig } -func (f baseFormatter) timeString(t int64) string { - if f.cfg.TimeFormat == "" { - return strconv.Itoa(int(t)) - } - return time.Unix(t/1000, 0).UTC().Format(f.cfg.TimeFormat) -} - func labelsToStr(labels utils.Labels) (string, string) { name := "" - lbls := []string{} + var lbls []string for _, lbl := range labels { if lbl.Name == "__name__" { name = lbl.Value diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go index bd9f3288..0532fd8d 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/partmgr/partmgr.go @@ -30,7 +30,6 @@ import ( "sync" "github.com/pkg/errors" - "github.com/prometheus/prometheus/pkg/labels" "github.com/v3io/v3io-go-http" "github.com/v3io/v3io-tsdb/internal/pkg/performance" "github.com/v3io/v3io-tsdb/pkg/aggregate" @@ -362,7 +361,7 @@ func (p *DBPartition) GetMetricPath(name string, hash uint64, labelNames []strin } else { var namelessLabelNames []string for _, l := range labelNames { - if l != labels.MetricName { + if l != config.PrometheusMetricNameAttribute { namelessLabelNames = append(namelessLabelNames, l) } } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go index 6ff8d357..3484f820 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/chunkIterator.go @@ -12,7 +12,7 @@ import ( // Chunk-list series iterator type RawChunkIterator struct { - mint, maxt int64 + mint, maxt, aggregationWindow int64 chunks []chunkenc.Chunk encoding chunkenc.Encoding @@ -33,8 +33,16 @@ func newRawChunkIterator(queryResult *qryResults, log logger.Logger) utils.Serie maxt = int64(maxTime.(int)) } + var aggregationWindow int64 + if queryResult.query.aggregationParams != nil { + aggregationWindow = queryResult.query.aggregationParams.GetAggregationWindow() + } newIterator := RawChunkIterator{ - mint: queryResult.query.mint, maxt: maxt, log: log.GetChild("rawChunkIterator"), encoding: queryResult.encoding} + mint: queryResult.query.mint, + maxt: maxt, + aggregationWindow: aggregationWindow, + log: log.GetChild("rawChunkIterator"), + encoding: queryResult.encoding} newIterator.AddChunks(queryResult) @@ -56,8 +64,8 @@ func (it *RawChunkIterator) Seek(t int64) bool { } // Seek to the first valid value after t - if t < it.mint { - t = it.mint + if t < it.mint-it.aggregationWindow { + t = it.mint - it.aggregationWindow } // Check the first element @@ -115,7 +123,7 @@ func (it *RawChunkIterator) Next() bool { it.updatePrevPoint() if it.iter.Next() { t, _ := it.iter.At() - if t < it.mint { + if t < it.mint-it.aggregationWindow { if !it.Seek(it.mint) { return false } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go index 35ab857c..dda274a8 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/collector.go @@ -124,12 +124,11 @@ func aggregateClientAggregates(ctx *selectQueryContext, res *qryResults) { it := newRawChunkIterator(res, ctx.logger) for it.Next() { t, v := it.At() - currentCell := (t - ctx.queryParams.From) / res.query.aggregationParams.Interval - for _, col := range res.frame.columns { - if col.GetColumnSpec().metric == res.name { - _ = res.frame.setDataAt(col.Name(), int(currentCell), v) - } + if res.query.aggregationParams.HasAggregationWindow() { + windowAggregation(ctx, res, t, v) + } else { + intervalAggregation(ctx, res, t, v) } } } @@ -155,8 +154,8 @@ func aggregateServerAggregates(ctx *selectQueryContext, res *qryResults) { val := binary.LittleEndian.Uint64(bytes[i : i+8]) currentValueIndex := (i - 16) / 8 - // Calculate the last time in the current cell - currentValueTime := partitionStartTime + int64(currentValueIndex)*rollupInterval + (rollupInterval - 1) + // Calculate server side aggregate bucket by its median time + currentValueTime := partitionStartTime + int64(currentValueIndex)*rollupInterval + rollupInterval/2 currentCell := (currentValueTime - ctx.queryParams.From) / res.query.aggregationParams.Interval var floatVal float64 @@ -165,7 +164,18 @@ func aggregateServerAggregates(ctx *selectQueryContext, res *qryResults) { } else { floatVal = math.Float64frombits(val) } - _ = res.frame.setDataAt(col.Name(), int(currentCell), floatVal) + + bottomMargin := res.query.aggregationParams.Interval + if res.query.aggregationParams.HasAggregationWindow() { + bottomMargin = res.query.aggregationParams.GetAggregationWindow() + } + if currentValueTime >= ctx.queryParams.From-bottomMargin && currentValueTime <= ctx.queryParams.To+res.query.aggregationParams.Interval { + if !res.query.aggregationParams.HasAggregationWindow() { + _ = res.frame.setDataAt(col.Name(), int(currentCell), floatVal) + } else { + windowAggregationWithServerAggregates(ctx, res, col, currentValueTime, floatVal) + } + } } } } @@ -186,24 +196,28 @@ func downsampleRawData(ctx *selectQueryContext, res *qryResults, } for currCell := 0; currCell < col.Len(); currCell++ { currCellTime := int64(currCell)*ctx.queryParams.Step + ctx.queryParams.From - if it.Seek(currCellTime) { - t, v := it.At() - tCellIndex := (t - ctx.queryParams.From) / ctx.queryParams.Step - if t == currCellTime { - _ = res.frame.setDataAt(col.Name(), int(currCell), v) - } else if tCellIndex == int64(currCell) { - prevT, prevV := it.PeakBack() - - // In case it's the first point in the partition use the last point of the previous partition for the interpolation - if prevT == 0 { - prevT = previousPartitionLastTime - prevV = previousPartitionLastValue - } - interpolatedT, interpolatedV := col.GetInterpolationFunction()(prevT, t, currCellTime, prevV, v) + prev, err := col.getBuilder().At(currCell) + + // Only update a cell if it hasn't been set yet + if prev == nil || err != nil { + if it.Seek(currCellTime) { + t, v := it.At() + if t == currCellTime { + _ = res.frame.setDataAt(col.Name(), int(currCell), v) + } else { + prevT, prevV := it.PeakBack() + + // In case it's the first point in the partition use the last point of the previous partition for the interpolation + if prevT == 0 { + prevT = previousPartitionLastTime + prevV = previousPartitionLastValue + } + interpolatedT, interpolatedV := col.GetInterpolationFunction()(prevT, t, currCellTime, prevV, v) - // Check if the interpolation was successful in terms of exceeding tolerance - if !(interpolatedT == 0 && interpolatedV == 0) { - _ = res.frame.setDataAt(col.Name(), int(currCell), interpolatedV) + // Check if the interpolation was successful in terms of exceeding tolerance + if !(interpolatedT == 0 && interpolatedV == 0) { + _ = res.frame.setDataAt(col.Name(), int(currCell), interpolatedV) + } } } } @@ -263,3 +277,66 @@ func aggregateClientAggregatesCrossSeries(ctx *selectQueryContext, res *qryResul lastT, lastV := it.At() return lastT, lastV, nil } + +func intervalAggregation(ctx *selectQueryContext, res *qryResults, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, false) + aggregateAllColumns(res, currentCell, v) +} + +func windowAggregation(ctx *selectQueryContext, res *qryResults, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, true) + aggregationWindow := res.query.aggregationParams.GetAggregationWindow() + + if aggregationWindow > res.query.aggregationParams.Interval { + currentCellTime := ctx.queryParams.From + currentCell*res.query.aggregationParams.Interval + maximumAffectedTime := t + aggregationWindow + numAffectedCells := (maximumAffectedTime-currentCellTime)/res.query.aggregationParams.Interval + 1 // +1 to include the current cell + + for i := int64(0); i < numAffectedCells; i++ { + aggregateAllColumns(res, currentCell+i, v) + } + } else if aggregationWindow < res.query.aggregationParams.Interval { + if t+aggregationWindow >= ctx.queryParams.From+currentCell*res.query.aggregationParams.Interval { + aggregateAllColumns(res, currentCell, v) + } + } else { + aggregateAllColumns(res, currentCell, v) + } +} + +func windowAggregationWithServerAggregates(ctx *selectQueryContext, res *qryResults, column Column, t int64, v float64) { + currentCell := getRelativeCell(t, ctx.queryParams.From, res.query.aggregationParams.Interval, true) + + aggregationWindow := res.query.aggregationParams.GetAggregationWindow() + if aggregationWindow > res.query.aggregationParams.Interval { + currentCellTime := ctx.queryParams.From + currentCell*res.query.aggregationParams.Interval + maxAffectedTime := t + aggregationWindow + numAffectedCells := (maxAffectedTime-currentCellTime)/res.query.aggregationParams.Interval + 1 // +1 to include the current cell + + for i := int64(0); i < numAffectedCells; i++ { + _ = res.frame.setDataAt(column.Name(), int(currentCell+i), v) + } + } else { + _ = res.frame.setDataAt(column.Name(), int(currentCell), v) + } +} + +func getRelativeCell(time, beginning, interval int64, roundUp bool) int64 { + cell := (time - beginning) / interval + + if roundUp && (time-beginning)%interval > 0 { + cell++ + } + + return cell +} + +// Set data to all aggregated columns for the given metric +func aggregateAllColumns(res *qryResults, cell int64, value float64) { + for _, col := range res.frame.columns { + colSpec := col.GetColumnSpec() + if colSpec.metric == res.name && colSpec.function != 0 { + _ = res.frame.setDataAt(col.Name(), int(cell), value) + } + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go index 7aadc1ba..60acb589 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/frames.go @@ -433,9 +433,11 @@ func (d *dataFrame) rawSeriesToColumns() { seriesTodefaultValue := make([]interface{}, len(d.rawColumns)) currentTime := int64(math.MaxInt64) nextTime := int64(math.MaxInt64) + seriesHasMoreData := make([]bool, len(d.rawColumns)) for i, rawSeries := range d.rawColumns { if rawSeries.Iterator().Next() { + seriesHasMoreData[i] = true t, _ := rawSeries.Iterator().At() if t < nextTime { nextTime = t @@ -479,20 +481,19 @@ func (d *dataFrame) rawSeriesToColumns() { t, v = iter.At() } - hasMoreData := true if t == currentTime { columns[seriesIndex].Append(v) if iter.Next() { t, _ = iter.At() } else { nonExhaustedIterators-- - hasMoreData = false + seriesHasMoreData[seriesIndex] = false } } else { columns[seriesIndex].Append(seriesTodefaultValue[seriesIndex]) } - if hasMoreData && t < nextTime { + if seriesHasMoreData[seriesIndex] && t < nextTime { nextTime = t } } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go index 468c957f..5029bc18 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/interpolate_test.go @@ -1,3 +1,5 @@ +// +build unit + /* Copyright 2018 Iguazio Systems Ltd. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go new file mode 100644 index 00000000..075eb02d --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/client_aggregates_integration_test.go @@ -0,0 +1,715 @@ +// +build integration + +package pqueriertest + +import ( + "math" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testClientAggregatesSuite struct { + basicQueryTestSuite +} + +func TestClientAggregatesSuite(t *testing.T) { + suite.Run(t, new(testClientAggregatesSuite)) +} + +func (suite *testClientAggregatesSuite) TestQueryAggregateWithNameWildcard() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedData := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData, "diskio": expectedData} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Functions: "max,min,sum", Step: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + aggr := set.At().Labels().Get(aggregate.AggregateLabel) + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expectedData)*len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestQueryAggregateWithFilterOnMetricName() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedData := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Functions: "max", Step: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), Filter: "_name=='cpu'"} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + aggr := set.At().Labels().Get(aggregate.AggregateLabel) + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartitionNonConcreteAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, + "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "avg,stdvar", + Step: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestClientAggregatesMultiPartitionOneStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 25*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 20*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 12*tsdbtest.DaysInMillis, 30}, + {suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 40}, + {suite.basicQueryTime + 20*tsdbtest.DaysInMillis, 50}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"count": {{Time: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, Value: 5}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "count", + Step: 0, + From: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, + To: suite.basicQueryTime + 21*tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestGetEmptyResponse() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "i dont exist", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestSelectAggregatesByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "max"}, {Metric: "cpu", Function: "min"}, {Metric: "cpu", Function: "sum"}}, + Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestSelectAggregatesAndRawByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "": {{suite.basicQueryTime, 10}, {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu"}}, + Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestQueryAllData() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 2 * 60 * 1000, + From: 0, + To: math.MaxInt64} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestAggregatesWithZeroStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 40}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "sum": {{Time: suite.basicQueryTime, Value: 100}}, + "count": {{Time: suite.basicQueryTime, Value: 4}}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 4, seriesCount, "series count didn't match expected") +} + +func (suite *testClientAggregatesSuite) TestUsePreciseAggregationsConfig() { + suite.v3ioConfig.UsePreciseAggregations = true + defer func() { suite.v3ioConfig.UsePreciseAggregations = false }() + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter.") + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "max": {{Time: suite.basicQueryTime, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier v2.") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.NoError(err, "failed to exeute query,") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(3, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go new file mode 100644 index 00000000..bdff56eb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/cross_series_aggregation_integration_test.go @@ -0,0 +1,559 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testCrossSeriesAggregatesSuite struct { + basicQueryTestSuite +} + +func TestCrossSeriesAggregatesSuite(t *testing.T) { + suite.Run(t, new(testCrossSeriesAggregatesSuite)) +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesTimesFallsOnStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 20}, + {Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 60}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesWithInterpolation() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 40}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartitionExactlyOnStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, + {Time: suite.basicQueryTime, Value: 50}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 100}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}, + "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, + {Time: suite.basicQueryTime, Value: 25}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesMultiPartitionWithInterpolation() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 3*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime, 20}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime, 30}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 21}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 21}, + {Time: suite.basicQueryTime, Value: 50}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 61}}, + "count": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 2}, + {Time: suite.basicQueryTime, Value: 2}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 2}}, + "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 1}}, + "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 10.5}, + {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 10.5}, + {Time: suite.basicQueryTime, Value: 25}, + {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30.5}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu)),count_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 2 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis + selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesWithInterpolationOverTolerance() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 30}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: suite.basicQueryTime, Value: 30}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 70}}, + "min": {{Time: suite.basicQueryTime, Value: 10}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 30}}, + "max": {{Time: suite.basicQueryTime, Value: 20}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") + suite.NoError(err) + selectParams.Step = 5 * tsdbtest.MinuteInMillis + selectParams.From = suite.basicQueryTime + selectParams.To = suite.basicQueryTime + 10*tsdbtest.MinuteInMillis + for i := 0; i < len(selectParams.RequestedColumns); i++ { + selectParams.RequestedColumns[i].InterpolationTolerance = tsdbtest.MinuteInMillis + } + set, err := querierV2.Select(selectParams) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testCrossSeriesAggregatesSuite) TestCrossSeriesAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}}, + "min": {{Time: suite.basicQueryTime, Value: 10}}, + "max": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}, + "avg": {{Time: suite.basicQueryTime, Value: 15}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,max_all,count_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "Failed to execute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected[agg], data, "queried data does not match expected") + } + + suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go new file mode 100644 index 00000000..2e4066f3 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/dataframe_query_integration_test.go @@ -0,0 +1,626 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "math" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/frames" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testSelectDataframeSuite struct { + basicQueryTestSuite +} + +func TestSelectDataframeSuite(t *testing.T) { + suite.Run(t, new(testSelectDataframeSuite)) +} + +func (suite *testSelectDataframeSuite) TestAggregatesWithZeroStepSelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string]tsdbtest.DataPoint{"max": {Time: suite.basicQueryTime, Value: 40}, + "min": {Time: suite.basicQueryTime, Value: 10}, + "sum": {Time: suite.basicQueryTime, Value: 100}, + "count": {Time: suite.basicQueryTime, Value: 4}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 1, indexCol.Len()) + t, err := indexCol.TimeAt(0) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), suite.basicQueryTime, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + suite.Require().Equal(1, col.Len()) + currentColAggregate := strings.Split(col.Name(), "(")[0] + f, err := col.FloatAt(0) + assert.NoError(suite.T(), err) + suite.Require().Equal(expected[currentColAggregate].Value, f) + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestEmptyRawDataSelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 10*tsdbtest.MinuteInMillis, To: suite.basicQueryTime - 1*tsdbtest.MinuteInMillis} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + suite.Require().Equal(0, frame.Indices()[0].Len()) + + for _, colName := range frame.Names() { + col, _ := frame.Column(colName) + assert.Equal(suite.T(), 0, col.Len()) + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) Test2Series1EmptySelectDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 10}}}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"cpu": ingestedData, + "diskio": {{suite.basicQueryTime, math.NaN()}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), math.NaN()}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}}, + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params, _, _ := pquerier.ParseQuery("select cpu,diskio") + params.From = suite.basicQueryTime + params.To = suite.basicQueryTime + 4*tsdbtest.MinuteInMillis + + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), len(ingestedData), indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), ingestedData[i].Time, t.UnixNano()/int64(time.Millisecond)) + } + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + assert.Equal(suite.T(), len(ingestedData), col.Len()) + for i := 0; i < col.Len(); i++ { + currentExpected := expected[col.Name()][i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + assert.Equal(suite.T(), currentExpected, f) + } + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestStringAndFloatMetricsDataframe() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter") + + metricName1 := "cpu" + metricName2 := "log" + labels := utils.LabelsFromStringList("os", "linux") + labelsWithName := append(labels, utils.LabelsFromStringList("__name__", metricName2)...) + + expectedTimeColumn := []int64{suite.basicQueryTime, suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis} + logData := []interface{}{"a", "b", "c"} + expectedColumns := map[string][]interface{}{metricName1: {10.0, 20.0, 30.0}, + metricName2: logData} + appender, err := adapter.Appender() + suite.NoError(err, "failed to create v3io appender") + + ref, err := appender.Add(labelsWithName, expectedTimeColumn[0], logData[0]) + suite.NoError(err, "failed to add data to the TSDB appender") + for i := 1; i < len(expectedTimeColumn); i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], logData[i]) + } + + _, err = appender.WaitForCompletion(0) + suite.NoError(err, "failed to wait for TSDB append completion") + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier") + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} + iter, err := querierV2.SelectDataFrame(params) + suite.NoError(err, "failed to execute query") + + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().Equal(expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + var v interface{} + + column, err := frame.Column(columnName) + suite.NoError(err) + if column.DType() == frames.FloatType { + v, _ = column.FloatAt(i) + } else if column.DType() == frames.StringType { + v, _ = column.StringAt(i) + } else { + suite.Fail(fmt.Sprintf("column type is not as expected: %v", column.DType())) + } + + suite.Require().Equal(expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) + } + } + } +} + +func (suite *testSelectDataframeSuite) TestQueryDataFrameMultipleMetricsWithMultipleLabelSets() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}} + ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, + {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{ + fmt.Sprintf("%v-%v", metricName1, "linux"): {{suite.basicQueryTime, 10}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, math.NaN()}}, + fmt.Sprintf("%v-%v", metricName2, "linux"): {{suite.basicQueryTime, math.NaN()}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}}, + fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData3}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 2, indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", metricName1, "linux")][i].Time, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + currentExpectedData := expectedData[fmt.Sprintf("%v-%v", col.Name(), frame.Labels()["os"])] + assert.Equal(suite.T(), len(currentExpectedData), col.Len()) + currentExpected := currentExpectedData[i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + assert.Equal(suite.T(), currentExpected, f) + } + } + } + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestSelectDataframeAggregationsMetricsHaveBigGaps() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} + + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu1", + Labels: labels1, + Data: ingestedData1}, + tsdbtest.Metric{ + Name: "cpu2", + Labels: labels1, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} + expected := map[string][]float64{"count(cpu1)": {1, 1, math.NaN()}, + "count(cpu2)": {math.NaN(), math.NaN(), 1}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{ + Functions: "count", + Step: int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var dataFrameCount int + for set.NextFrame() { + dataFrameCount++ + frame, err := set.GetFrame() + suite.Require().NoError(err) + suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") + suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") + + indexCol := frame.Indices()[0] + + for i := 0; i < len(expected); i++ { + t, err := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().NoError(err) + suite.Require().Equal(expectedTime[i], timeMillis) + + for _, currName := range frame.Names() { + currCol, err := frame.Column(currName) + suite.Require().NoError(err) + currVal, err := currCol.FloatAt(i) + + suite.Require().NoError(err) + if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { + suite.Require().Equal(expected[currName][i], currVal) + } + } + } + } + + suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestSelectDataframeDaownsampleMetricsHaveBigGaps() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} + + ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu1", + Labels: labels1, + Data: ingestedData1}, + tsdbtest.Metric{ + Name: "cpu2", + Labels: labels1, + Data: ingestedData2}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis - 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis - 1*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 4*tsdbtest.DaysInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis - 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis - 1*tsdbtest.MinuteInMillis, + suite.basicQueryTime - 1*tsdbtest.DaysInMillis} + expected := map[string][]float64{"cpu1": {10, 20, 20, 20, math.NaN(), math.NaN(), math.NaN()}, + "cpu2": {math.NaN(), math.NaN(), math.NaN(), math.NaN(), 30, 30, 30}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{ + Step: int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, + To: suite.basicQueryTime} + set, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var dataFrameCount int + for set.NextFrame() { + dataFrameCount++ + frame, err := set.GetFrame() + suite.Require().NoError(err) + suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") + suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") + + indexCol := frame.Indices()[0] + + for i := 0; i < len(expected); i++ { + t, err := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + suite.Require().NoError(err) + suite.Require().Equal(expectedTime[i], timeMillis) + + for _, currName := range frame.Names() { + currCol, err := frame.Column(currName) + suite.Require().NoError(err) + currVal, err := currCol.FloatAt(i) + + suite.Require().NoError(err) + if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { + suite.Require().Equal(expected[currName][i], currVal) + } + } + } + } + + suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") +} + +func (suite *testSelectDataframeSuite) TestQueryDataFrameMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.NoError(err, "failed to create v3io adapter") + + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 15}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 18}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 22}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 26}} + + expectedData := map[string][]tsdbtest.DataPoint{ + metricName1: {{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 15}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 18}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, math.NaN()}}, + metricName2: {{suite.basicQueryTime, math.NaN()}, + {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 22}, + {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 26}}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.SelectDataFrame(params) + suite.NoError(err, "failed to exeute query") + + var seriesCount int + for set.NextFrame() { + seriesCount++ + frame, err := set.GetFrame() + suite.NoError(err) + + indexCol := frame.Indices()[0] + assert.Equal(suite.T(), 6, indexCol.Len()) + for i := 0; i < indexCol.Len(); i++ { + t, err := indexCol.TimeAt(i) + assert.NoError(suite.T(), err) + suite.Require().Equal(expectedData[metricName1][i].Time, t.UnixNano()/int64(time.Millisecond)) + + for _, colName := range frame.Names() { + col, err := frame.Column(colName) + suite.NoError(err) + currentExpectedData := expectedData[col.Name()] + suite.Require().Equal(len(currentExpectedData), col.Len()) + currentExpected := currentExpectedData[i].Value + f, err := col.FloatAt(i) + assert.NoError(suite.T(), err) + + if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { + suite.Require().Equal(currentExpected, f) + } + } + } + } + + suite.Require().Equal(1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go new file mode 100644 index 00000000..72d2f7ac --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/downsample_query_integration_test.go @@ -0,0 +1,183 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testDownsampleSuite struct { + basicQueryTestSuite +} + +func TestDownsampleSuite(t *testing.T) { + suite.Run(t, new(testDownsampleSuite)) +} + +func (suite *testDownsampleSuite) TestDownSampleNotReturningAggrAttr() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + labels := set.At().Labels() + suite.Require().Empty(labels.Get(aggregate.AggregateLabel)) + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testDownsampleSuite) TestRawDataSinglePartitionWithDownSample() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 8*tsdbtest.MinuteInMillis, 40}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Step: 2 * int64(tsdbtest.MinuteInMillis), + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testDownsampleSuite) TestRawDataDownSampleMultiPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T23:40:00Z"), 10}, + {suite.toMillis("2018-11-18T23:59:00Z"), 20}, + {suite.toMillis("2018-11-19T00:20:00Z"), 30}, + {suite.toMillis("2018-11-19T02:40:00Z"), 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expectedData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T22:00:00Z"), 10}, + {suite.toMillis("2018-11-19T00:00:00Z"), 30}, + {suite.toMillis("2018-11-19T02:00:00Z"), 40}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, + Step: 2 * int64(tsdbtest.HoursInMillis), + From: suite.toMillis("2018-11-18T22:00:00Z"), + To: suite.toMillis("2018-11-19T4:00:00Z")} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go new file mode 100644 index 00000000..c5f2bf44 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/get_labelsets_integration_test.go @@ -0,0 +1,208 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type getLabelSetsSuite struct { + suite.Suite + v3ioConfig *config.V3ioConfig + suiteTimestamp int64 + basicQueryTime int64 +} + +func TestGetLabelSetsSuite(t *testing.T) { + suite.Run(t, new(getLabelSetsSuite)) +} + +func (suite *getLabelSetsSuite) SetupSuite() { + v3ioConfig, err := tsdbtest.LoadV3ioConfig() + if err != nil { + suite.T().Fatalf("unable to load configuration. Error: %v", err) + } + + suite.v3ioConfig = v3ioConfig + suite.suiteTimestamp = time.Now().Unix() + suite.basicQueryTime, err = tsdbtest.DateStringToMillis("2018-07-21T10:00:00Z") + suite.NoError(err) +} + +func (suite *getLabelSetsSuite) SetupTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) +} + +func (suite *getLabelSetsSuite) TearDownTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + if !suite.T().Failed() { + tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) + } +} + +func (suite *getLabelSetsSuite) TestGetLabels() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsAllMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "diskio")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsAllSpecificMetric() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "diskio", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} + +func (suite *getLabelSetsSuite) TestGetLabelsWithFilter() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), + utils.LabelsFromStringList("os", "linux", "region", "asia"), + utils.LabelsFromStringList("os", "mac", "region", "europe")} + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels[0], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[1], + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels[2], + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), + utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + labelsList, err := querierV2.GetLabelSets("cpu", "os=='linux'") + if err != nil { + suite.T().Fatalf("failed to get label sets, err:%v\n", err) + } + + suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go new file mode 100644 index 00000000..2d58da27 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/integration_test_basic_test.go @@ -0,0 +1,68 @@ +// +build integration + +/* +Copyright 2018 Iguazio Systems Ltd. + +Licensed under the Apache License, Version 2.0 (the "License") with +an addition restriction as set forth herein. You may not use this +file except in compliance with the License. You may obtain a copy of +the License at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied. See the License for the specific language governing +permissions and limitations under the License. + +In addition, you may not use the software for any purposes that are +illegal under applicable law, and the grant of the foregoing license +under the Apache 2.0 license is conditioned upon your compliance with +such restriction. +*/ + +package pqueriertest + +import ( + "fmt" + "time" + + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" +) + +type basicQueryTestSuite struct { + suite.Suite + v3ioConfig *config.V3ioConfig + suiteTimestamp int64 + basicQueryTime int64 +} + +func (suite *basicQueryTestSuite) toMillis(date string) int64 { + time, err := tsdbtest.DateStringToMillis(date) + suite.NoError(err) + return time +} + +func (suite *basicQueryTestSuite) SetupSuite() { + v3ioConfig, err := tsdbtest.LoadV3ioConfig() + if err != nil { + suite.T().Fatalf("unable to load configuration. Error: %v", err) + } + + suite.v3ioConfig = v3ioConfig + suite.suiteTimestamp = time.Now().Unix() + suite.basicQueryTime = suite.toMillis("2018-07-21T21:40:00Z") +} + +func (suite *basicQueryTestSuite) SetupTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) +} + +func (suite *basicQueryTestSuite) TearDownTest() { + suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) + if !suite.T().Failed() { + tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go new file mode 100644 index 00000000..ef562e67 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/query_sql_integration_test.go @@ -0,0 +1,273 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testSQLSyntaxQuerySuite struct { + basicQueryTestSuite +} + +func TestSQLSyntaxQuerySuite(t *testing.T) { + suite.Run(t, new(testSQLSyntaxQuerySuite)) +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByOneLabelSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") + labels2 := utils.LabelsFromStringList("os", "mac", "region", "europe") + labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas") + labels4 := utils.LabelsFromStringList("os", "linux", "region", "asia") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels3, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels4, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string]map[string][]tsdbtest.DataPoint{ + "linux": { + "sum": {{Time: suite.basicQueryTime, Value: 30}}, + "count": {{Time: suite.basicQueryTime, Value: 3}}}, + "mac": { + "sum": {{Time: suite.basicQueryTime, Value: 10}}, + "count": {{Time: suite.basicQueryTime, Value: 1}}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: "os"} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "failed to exeute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + groupByValue := set.At().Labels().Get("os") + suite.Require().NoError(err) + + suite.Require().Equal(expected[groupByValue][agg], data, "queried data does not match expected") + } + + suite.Require().Equal(4, seriesCount, "series count didn't match expected") +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByMultipleLabelsSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "1") + labels2 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "2") + labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas", "version", "3") + labels4 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "1") + labels5 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "2") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels3, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels4, + Data: ingestedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels5, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + groupBy := []string{"os", "region"} + expected := map[string]map[string][]tsdbtest.DataPoint{ + "linux-europe": { + "sum": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}}, + "linux-americas": { + "sum": {{Time: suite.basicQueryTime, Value: 10}}, + "count": {{Time: suite.basicQueryTime, Value: 1}}}, + "mac-asia": { + "sum": {{Time: suite.basicQueryTime, Value: 20}}, + "count": {{Time: suite.basicQueryTime, Value: 2}}}} + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: strings.Join(groupBy, ",")} + set, err := querierV2.Select(params) + suite.Require().NoError(err, "failed to exeute query") + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + var groupByValue []string + for _, label := range groupBy { + groupByValue = append(groupByValue, set.At().Labels().Get(label)) + } + labelsStr := strings.Join(groupByValue, "-") + + suite.Require().NoError(err) + + suite.Require().Equal(expected[labelsStr][agg], data, "queried data does not match expected") + } + + suite.Require().Equal(6, seriesCount, "series count didn't match expected") +} + +func (suite *testSQLSyntaxQuerySuite) TestGroupByNotExistingLabel() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + suite.Require().NoError(err, "failed to create v3io adapter") + + labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + suite.Require().NoError(err, "failed to create querier v2") + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,count", + Step: 2 * 60 * 1000, + From: suite.basicQueryTime, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), + GroupBy: "something that does not exist"} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected fail but continued normally") + } +} + +func (suite *testSQLSyntaxQuerySuite) TestAggregateSeriesWithAlias() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + expectedResult := 40.0 + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + aliasName := "iguaz" + params, _, _ := pquerier.ParseQuery(fmt.Sprintf("select max(cpu) as %v", aliasName)) + + params.From = suite.basicQueryTime + params.To = suite.basicQueryTime + int64(numberOfEvents*eventsInterval) + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + assert.Equal(suite.T(), 1, len(data), "queried data does not match expected") + assert.Equal(suite.T(), expectedResult, data[0].Value, "queried data does not match expected") + + seriesName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + suite.Equal(aliasName, seriesName) + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go new file mode 100644 index 00000000..7070f3b7 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/raw_query_integration_test.go @@ -0,0 +1,634 @@ +// +build integration + +package pqueriertest + +import ( + "fmt" + "math" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/config" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testRawQuerySuite struct { + basicQueryTestSuite +} + +func TestRawQuerySuite(t *testing.T) { + suite.Run(t, new(testRawQuerySuite)) +} + +func (suite *testRawQuerySuite) TestRawDataSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestRawDataMultiplePartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 3*eventsInterval, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestFilterOnLabel() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 3*eventsInterval, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Filter: "os=='linux'", + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestQueryWithBadTimeParameters() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: expectedData}, + tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), To: suite.basicQueryTime} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected to get error but no error was returned") + } +} + +func (suite *testRawQuerySuite) TestQueryMetricWithDashInTheName() { // IG-8585 + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cool-cpu", + Labels: labels1, + Data: expectedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + _, err = querierV2.Select(params) + if err == nil { + suite.T().Fatalf("expected an error but finish succesfully") + } +} + +func (suite *testRawQuerySuite) TestSelectRawDataByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := ingestedData + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestRawDataMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*eventsInterval, 30}, + {suite.basicQueryTime + 4*eventsInterval, 40}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 3*eventsInterval, 30}, + {suite.basicQueryTime + 4*eventsInterval, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{metricName1: ingestData1, metricName2: ingestData2} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData[name], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDataFrameRawDataMultipleMetrics() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + expectedTimeColumn := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 5*tsdbtest.DaysInMillis, + suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, + suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, suite.basicQueryTime + 4*tsdbtest.MinuteInMillis} + expectedColumns := map[string][]float64{metricName1: {10, math.NaN(), 20, 30, math.NaN(), 40}, + metricName2: {math.NaN(), 10, math.NaN(), 20, 30, 40}} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, + From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + iter, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] // in tsdb we have only one index + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + column, err := frame.Column(columnName) + suite.NoError(err) + v, _ := column.FloatAt(i) + + expected := expectedColumns[column.Name()][i] + + // assert can not compare NaN, so we need to check it manually + if !(math.IsNaN(expected) && math.IsNaN(v)) { + assert.Equal(suite.T(), expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) + } + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestQueryMultipleMetricsWithMultipleLabelSets() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + metricName1 := "cpu" + metricName2 := "diskio" + labels1 := utils.LabelsFromStringList("os", "linux") + labels2 := utils.LabelsFromStringList("os", "mac") + numberOfEvents := 5 + eventsInterval := int64(tsdbtest.MinuteInMillis) + ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} + ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, + {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} + + expectedData := map[string][]tsdbtest.DataPoint{fmt.Sprintf("%v-%v", metricName1, "linux"): ingestData1, + fmt.Sprintf("%v-%v", metricName2, "linux"): ingestData2, + fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: metricName1, + Labels: labels1, + Data: ingestData1}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels1, + Data: ingestData2}, + tsdbtest.Metric{ + Name: metricName2, + Labels: labels2, + Data: ingestData3}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Filter: "1==1", + From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) + os := set.At().Labels().Get("os") + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", name, os)], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDifferentLabelSetsInDifferentPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels2 := utils.LabelsFromStringList("os", "mac") + + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 40}, + {suite.basicQueryTime, 40}} + + expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels2, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testRawQuerySuite) TestDifferentMetricsInDifferentPartitions() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 10}, + {suite.basicQueryTime, 40}} + + expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{ + tsdbtest.Metric{ + Name: "diskio", + Labels: labels1, + Data: ingestData2}, + }}) + + tsdbtest.InsertData(suite.T(), testParams) + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + data, err := tsdbtest.IteratorToSlice(iter) + if err != nil { + suite.T().Fatal(err) + } + + suite.Require().Equal(expected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go new file mode 100644 index 00000000..d9e5e0ea --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/server_aggregates_integration_test.go @@ -0,0 +1,384 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testServerAggregatesSuite struct { + basicQueryTestSuite +} + +func TestServerAggregatesSuite(t *testing.T) { + suite.Run(t, new(testServerAggregatesSuite)) +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesSinglePartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 100}}, + "min": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 10}}, + "max": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 40}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesSinglePartitionNegativeValues() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, -10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), -20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, -30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, -40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -100}}, + "min": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -40}}, + "max": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: -10}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesMultiPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + firstStepTime := suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis + secondStepTime := suite.basicQueryTime - 1*tsdbtest.HoursInMillis + + expected := map[string][]tsdbtest.DataPoint{ + "sum": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 90}}, + "min": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 20}}, + "max": {{Time: firstStepTime, Value: 10}, {Time: secondStepTime, Value: 40}}, + "sqr": {{Time: firstStepTime, Value: 100}, {Time: secondStepTime, Value: 2900}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum,max,min,sqr", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestRawAggregatesMultiPartitionNonConcreteAggregates() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, + {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + firstStepTime := suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis + secondStepTime := suite.basicQueryTime - 1*tsdbtest.HoursInMillis + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: firstStepTime, Value: 11}, {Time: secondStepTime, Value: 30}}, + "stdvar": {{Time: firstStepTime, Value: 2}, {Time: secondStepTime, Value: 100}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "avg,stdvar", + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestSelectServerAggregatesAndRawByRequestedColumns() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, Value: 100}}, + "": {{suite.basicQueryTime - 4*tsdbtest.HoursInMillis, 10}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu", Interpolator: "next", InterpolationTolerance: 5 * tsdbtest.HoursInMillis}}, + Step: 4 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime - 4*tsdbtest.HoursInMillis, + To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} + + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") +} + +func (suite *testServerAggregatesSuite) TestAggregatesWithDisabledClientAggregation() { + suite.v3ioConfig.DisableClientAggr = true + defer func() { suite.v3ioConfig.DisableClientAggr = false }() + + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + eventsInterval := 60 * 1000 + + ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - tsdbtest.DaysInMillis, 10}, + {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, + {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, + {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - tsdbtest.DaysInMillis, Value: 10}, + {Time: suite.basicQueryTime - tsdbtest.HoursInMillis, Value: 30}}} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", Functions: "avg", From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + currentExpected, ok := expected[agg] + suite.Require().Equal(true, ok, "got unexpected aggregate result") + assert.Equal(suite.T(), currentExpected, data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go new file mode 100644 index 00000000..3afd50b2 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/variant_type_query_integration_test.go @@ -0,0 +1,153 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testVariantTypeSuite struct { + basicQueryTestSuite +} + +func TestVariantTypeSuite(t *testing.T) { + suite.Run(t, new(testVariantTypeSuite)) +} + +func (suite *testVariantTypeSuite) TestVariantTypeQueryWithDataFrame() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + metricName := "log" + labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) + + dataToIngest := []string{"a", "b", "c", "d", "e"} + numberOfEvents := len(dataToIngest) + var expectedTimeColumn []int64 + for i := 0; i < numberOfEvents; i++ { + expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) + } + + appender, err := adapter.Appender() + if err != nil { + suite.T().Fatalf("failed to create v3io appender. reason: %s", err) + } + + ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) + if err != nil { + suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) + } + for i := 1; i < numberOfEvents; i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) + } + + if _, err := appender.WaitForCompletion(0); err != nil { + suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, + From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + iter, err := querierV2.SelectDataFrame(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.NextFrame() { + seriesCount++ + frame, err := iter.GetFrame() + suite.NoError(err) + indexCol := frame.Indices()[0] // in tsdb we have only one index + + for i := 0; i < indexCol.Len(); i++ { + t, _ := indexCol.TimeAt(i) + timeMillis := t.UnixNano() / int64(time.Millisecond) + assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) + for _, columnName := range frame.Names() { + column, err := frame.Column(columnName) + suite.NoError(err) + v, _ := column.StringAt(i) + + expected := dataToIngest[i] + + assert.Equal(suite.T(), expected, v, "column %v does not match at index %v", column.Name(), i) + } + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testVariantTypeSuite) TestVariantTypeQueryWithSeries() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + metricName := "log" + labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) + + dataToIngest := []string{"a", "b", "c", "d", "e"} + numberOfEvents := len(dataToIngest) + var expectedTimeColumn []int64 + for i := 0; i < numberOfEvents; i++ { + expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) + } + + appender, err := adapter.Appender() + if err != nil { + suite.T().Fatalf("failed to create v3io appender. reason: %s", err) + } + + ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) + if err != nil { + suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) + } + for i := 1; i < numberOfEvents; i++ { + appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) + } + + if _, err := appender.WaitForCompletion(0); err != nil { + suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) + } + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, + From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} + iter, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + var seriesCount int + for iter.Next() { + seriesCount++ + iter := iter.At().Iterator() + var i int + for iter.Next() { + t, v := iter.AtString() + assert.Equal(suite.T(), expectedTimeColumn[i], t, "time does not match at index %v", i) + assert.Equal(suite.T(), dataToIngest[i], v, "value does not match at index %v", i) + i++ + } + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go new file mode 100644 index 00000000..a8943199 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/pqueriertest/windowed_aggregation_integration_test.go @@ -0,0 +1,479 @@ +// +build integration + +package pqueriertest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "github.com/v3io/v3io-tsdb/pkg/aggregate" + "github.com/v3io/v3io-tsdb/pkg/pquerier" + "github.com/v3io/v3io-tsdb/pkg/tsdb" + "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" + "github.com/v3io/v3io-tsdb/pkg/utils" +) + +type testWindowAggregationSuite struct { + basicQueryTestSuite +} + +func TestWindowAggregationSuite(t *testing.T) { + suite.Run(t, new(testWindowAggregationSuite)) +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowBiggerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 390}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 6 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowSmallerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 120}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 170}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 2 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowEqualToStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.MinuteInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 300}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.MinuteInMillis, + AggregationWindow: 5 * tsdbtest.MinuteInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestClientWindowedAggregationWindowExceedsPartition() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + + ingestedData := []tsdbtest.DataPoint{{Time: suite.toMillis("2018-07-19T23:50:00Z"), Value: 1}, + {Time: suite.toMillis("2018-07-19T23:55:00Z"), Value: 2}, + {Time: suite.toMillis("2018-07-19T23:57:00Z"), Value: 3}, + {Time: suite.toMillis("2018-07-20T00:10:00Z"), Value: 4}, + {Time: suite.toMillis("2018-07-20T00:20:00Z"), Value: 5}, + {Time: suite.toMillis("2018-07-20T00:30:00Z"), Value: 6}, + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.toMillis("2018-07-20T00:10:00Z"), Value: 10}, + {Time: suite.toMillis("2018-07-20T00:20:00Z"), Value: 15}, + {Time: suite.toMillis("2018-07-20T00:30:00Z"), Value: 15}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 10 * tsdbtest.MinuteInMillis, + AggregationWindow: 30 * tsdbtest.MinuteInMillis, + From: suite.toMillis("2018-07-20T00:10:00Z"), + To: suite.toMillis("2018-07-20T00:30:00Z")} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowBiggerThanStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.HoursInMillis, Value: 350}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.HoursInMillis, + AggregationWindow: 6 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowEqualToStep() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 150}, + {Time: suite.basicQueryTime + 10*tsdbtest.HoursInMillis, Value: 300}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 5 * tsdbtest.HoursInMillis, + AggregationWindow: 5 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} + +func (suite *testWindowAggregationSuite) TestServerWindowedAggregationWindowEqualToRollupInterval() { + adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) + if err != nil { + suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) + } + + labels1 := utils.LabelsFromStringList("os", "linux") + numberOfEvents := 10 + + var ingestedData []tsdbtest.DataPoint + + for i := 0; i < numberOfEvents; i++ { + ingestedData = append(ingestedData, tsdbtest.DataPoint{Time: suite.basicQueryTime + int64(i)*tsdbtest.HoursInMillis, Value: 10 * float64(i)}) + } + + testParams := tsdbtest.NewTestParams(suite.T(), + tsdbtest.TestOption{ + Key: tsdbtest.OptTimeSeries, + Value: tsdbtest.TimeSeries{tsdbtest.Metric{ + Name: "cpu", + Labels: labels1, + Data: ingestedData}, + }}) + tsdbtest.InsertData(suite.T(), testParams) + + expected := map[string][]tsdbtest.DataPoint{"sum": { + {Time: suite.basicQueryTime, Value: 0}, + {Time: suite.basicQueryTime + 1*tsdbtest.HoursInMillis, Value: 10}, + {Time: suite.basicQueryTime + 2*tsdbtest.HoursInMillis, Value: 20}, + {Time: suite.basicQueryTime + 3*tsdbtest.HoursInMillis, Value: 30}, + {Time: suite.basicQueryTime + 4*tsdbtest.HoursInMillis, Value: 40}, + {Time: suite.basicQueryTime + 5*tsdbtest.HoursInMillis, Value: 50}, + {Time: suite.basicQueryTime + 6*tsdbtest.HoursInMillis, Value: 60}, + {Time: suite.basicQueryTime + 7*tsdbtest.HoursInMillis, Value: 70}, + {Time: suite.basicQueryTime + 8*tsdbtest.HoursInMillis, Value: 80}, + {Time: suite.basicQueryTime + 9*tsdbtest.HoursInMillis, Value: 90}, + }} + + querierV2, err := adapter.QuerierV2() + if err != nil { + suite.T().Fatalf("Failed to create querier v2, err: %v", err) + } + + params := &pquerier.SelectParams{Name: "cpu", + Functions: "sum", + Step: 1 * tsdbtest.HoursInMillis, + AggregationWindow: 1 * tsdbtest.HoursInMillis, + From: suite.basicQueryTime, + To: suite.basicQueryTime + 10*tsdbtest.HoursInMillis} + set, err := querierV2.Select(params) + if err != nil { + suite.T().Fatalf("Failed to exeute query, err: %v", err) + } + + var seriesCount int + for set.Next() { + seriesCount++ + iter := set.At().Iterator() + + data, err := tsdbtest.IteratorToSlice(iter) + agg := set.At().Labels().Get(aggregate.AggregateLabel) + if err != nil { + suite.T().Fatal(err) + } + + assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") + } + + assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go index 17649b45..b1c4dc85 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/querier.go @@ -39,21 +39,26 @@ type V3ioQuerier struct { } type SelectParams struct { - Name string - Functions string - From, To, Step int64 - Windows []int - Filter string - RequestedColumns []RequestedColumn - GroupBy string + Name string + Functions string + From, To, Step int64 + Windows []int + Filter string + RequestedColumns []RequestedColumn + GroupBy string + AggregationWindow int64 + UseOnlyClientAggr bool disableAllAggr bool disableClientAggr bool } -func (s *SelectParams) getRequestedColumns() []RequestedColumn { +func (s *SelectParams) getRequestedColumns() ([]RequestedColumn, error) { + if err := s.validateSelectParams(); err != nil { + return nil, err + } if s.RequestedColumns != nil { - return s.RequestedColumns + return s.RequestedColumns, nil } functions := strings.Split(s.Functions, ",") metricNames := strings.Split(s.Name, ",") @@ -68,14 +73,43 @@ func (s *SelectParams) getRequestedColumns() []RequestedColumn { index++ } } - return columns + return columns, nil +} + +func (s *SelectParams) validateSelectParams() error { + if s.UseOnlyClientAggr && s.disableClientAggr { + return errors.New("can not query, both `useOnlyClientAggr` and `disableClientAggr` flags are set") + } + + if s.RequestedColumns == nil { + functions := strings.Split(s.Functions, ",") + functionMap := make(map[string]bool, len(functions)) + for _, function := range functions { + trimmed := strings.TrimSpace(function) + if functionMap[trimmed] { + return fmt.Errorf("function '%v' was requested multiple time", trimmed) + } + functionMap[trimmed] = true + } + } else { + functionMap := make(map[string]bool, len(s.RequestedColumns)) + for _, col := range s.RequestedColumns { + trimmed := strings.TrimSpace(col.Function) + key := fmt.Sprintf("%v-%v", col.Metric, trimmed) + if functionMap[key] { + return fmt.Errorf("function '%v' for metric '%v' was requested multiple time", trimmed, col.Metric) + } + functionMap[key] = true + } + } + + return nil } func (q *V3ioQuerier) SelectProm(params *SelectParams, noAggr bool) (utils.SeriesSet, error) { params.disableClientAggr = true params.disableAllAggr = noAggr - iter, err := q.baseSelectQry(params, false) if err != nil || iter == nil { return utils.NullSeriesSet{}, err @@ -122,11 +156,17 @@ func (q *V3ioQuerier) baseSelectQry(params *SelectParams, showAggregateLabel boo return nil, errors.New("Query workers num must be a power of 2 and > 0 !") } + // If the config is set to use only client configuration override the query parameter. + if q.cfg.UsePreciseAggregations { + params.UseOnlyClientAggr = true + } + selectContext := selectQueryContext{ container: q.container, logger: q.logger, workers: q.cfg.QryWorkers, showAggregateLabel: showAggregateLabel, + v3ioConfig: q.cfg, } q.logger.Debug("Select query:\n\tMetric: %s\n\tStart Time: %s (%d)\n\tEnd Time: %s (%d)\n\tFunction: %s\n\t"+ @@ -138,7 +178,8 @@ func (q *V3ioQuerier) baseSelectQry(params *SelectParams, showAggregateLabel boo q.performanceReporter.WithTimer("QueryTimer", func() { params.Filter = strings.Replace(params.Filter, config.PrometheusMetricNameAttribute, config.MetricNameAttrName, -1) - parts := q.partitionMngr.PartsForRange(params.From, params.To, true) + // Get all partitions containing data relevant to the query. If the Aggregation Window parameter is specified take it in account. + parts := q.partitionMngr.PartsForRange(params.From-params.AggregationWindow, params.To, true) if len(parts) == 0 { return } @@ -174,6 +215,11 @@ func (q *V3ioQuerier) LabelValues(labelKey string) (result []string, err error) return } +// Stub +func (q *V3ioQuerier) LabelNames() ([]string, error) { + return nil, nil +} + func (q *V3ioQuerier) getMetricNames() ([]string, error) { input := v3io.GetItemsInput{ Path: filepath.Join(q.cfg.TablePath, config.NamesDirectory) + "/", // Need a trailing slash diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go deleted file mode 100644 index bcc17853..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/query_integration_test.go +++ /dev/null @@ -1,3490 +0,0 @@ -// +build integration - -/* -Copyright 2018 Iguazio Systems Ltd. - -Licensed under the Apache License, Version 2.0 (the "License") with -an addition restriction as set forth herein. You may not use this -file except in compliance with the License. You may obtain a copy of -the License at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. - -In addition, you may not use the software for any purposes that are -illegal under applicable law, and the grant of the foregoing license -under the Apache 2.0 license is conditioned upon your compliance with -such restriction. -*/ - -package pquerier_test - -import ( - "fmt" - "math" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - "github.com/v3io/frames" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/pquerier" - "github.com/v3io/v3io-tsdb/pkg/tsdb" - "github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type testQuerySuite struct { - suite.Suite - v3ioConfig *config.V3ioConfig - suiteTimestamp int64 - basicQueryTime int64 -} - -func (suite *testQuerySuite) SetupSuite() { - v3ioConfig, err := tsdbtest.LoadV3ioConfig() - if err != nil { - suite.T().Fatalf("unable to load configuration. Error: %v", err) - } - - suite.v3ioConfig = v3ioConfig - suite.suiteTimestamp = time.Now().Unix() - suite.basicQueryTime = suite.toMillis("2018-07-21T21:40:00Z") -} - -func (suite *testQuerySuite) SetupTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) -} - -func (suite *testQuerySuite) TearDownTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - if !suite.T().Failed() { - tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) - } -} - -func (suite *testQuerySuite) TestRawDataSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataMultiplePartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 3*eventsInterval, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestFilterOnLabel() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 3*eventsInterval, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Filter: "os=='linux'", - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryWithBadTimeParameters() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: expectedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), To: suite.basicQueryTime} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected to get error but no error was returned") - } -} - -func (suite *testQuerySuite) TestQueryMetricWithDashInTheName() { // IG-8585 - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cool-cpu", - Labels: labels1, - Data: expectedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected an error but finish succesfully") - } -} - -func (suite *testQuerySuite) TestQueryAggregateWithNameWildcard() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedData := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData, "diskio": expectedData} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Functions: "max,min,sum", Step: 2 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - aggr := set.At().Labels().Get(aggregate.AggregateLabel) - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expectedData)*len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryAggregateWithFilterOnMetricName() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedData := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - expected := map[string]map[string][]tsdbtest.DataPoint{"cpu": expectedData} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Functions: "max", Step: 2 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), Filter: "_name=='cpu'"} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - metricName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - aggr := set.At().Labels().Get(aggregate.AggregateLabel) - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[metricName][aggr], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDownSampleNotReturningAggrAttr() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - labels := set.At().Labels() - suite.Require().Empty(labels.Get(aggregate.AggregateLabel)) - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataSinglePartitionWithDownSample() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 9*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 6*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 8*tsdbtest.MinuteInMillis, 40}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Step: 2 * int64(tsdbtest.MinuteInMillis), From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataDownSampleMultiPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T23:40:00Z"), 10}, - {suite.toMillis("2018-11-18T23:59:00Z"), 20}, - {suite.toMillis("2018-11-19T00:20:00Z"), 30}, - {suite.toMillis("2018-11-19T02:40:00Z"), 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedData := []tsdbtest.DataPoint{{suite.toMillis("2018-11-18T22:00:00Z"), 10}, - {suite.toMillis("2018-11-19T00:00:00Z"), 30}, - {suite.toMillis("2018-11-19T02:00:00Z"), 40}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, - Step: 2 * int64(tsdbtest.HoursInMillis), - From: suite.toMillis("2018-11-18T22:00:00Z"), - To: suite.toMillis("2018-11-19T4:00:00Z")} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "max": {{Time: suite.basicQueryTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesWithQueryIntervalSameAsAggrGranularity() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - baseTime := suite.toMillis("2018-07-21T21:00:00Z") - ingestedData := []tsdbtest.DataPoint{{baseTime, 10}, - {int64(baseTime + tsdbtest.MinuteInMillis), 20}, - {baseTime + 2*tsdbtest.MinuteInMillis, 30}, - {baseTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: baseTime, Value: 100}}, - "min": {{Time: baseTime, Value: 10}}, - "max": {{Time: baseTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: baseTime, To: baseTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesSinglePartitionNegativeValues() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, -10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), -20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, -30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, -40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: -100}}, - "min": {{Time: suite.basicQueryTime, Value: -40}}, - "max": {{Time: suite.basicQueryTime, Value: -10}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}, - "sqr": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 100}, {Time: suite.basicQueryTime, Value: 2900}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawAggregatesMultiPartitionNonConcreteAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, - "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "avg,stdvar", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum,max,min", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 90}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 20}}, - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, {Time: suite.basicQueryTime, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,max,min", - Step: 5 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartitionNonConcreteAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + tsdbtest.MinuteInMillis, 12}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 11}, {Time: suite.basicQueryTime, Value: 30}}, - "stdvar": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, {Time: suite.basicQueryTime, Value: 100}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "avg,stdvar", - Step: 5 * tsdbtest.MinuteInMillis, - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestClientAggregatesMultiPartitionOneStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 25*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 20*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 12*tsdbtest.DaysInMillis, 30}, - {suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 40}, - {suite.basicQueryTime + 20*tsdbtest.DaysInMillis, 50}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"count": {{Time: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, Value: 5}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "count", - Step: 0, - From: suite.basicQueryTime - 25*tsdbtest.DaysInMillis, - To: suite.basicQueryTime + 21*tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGetEmptyResponse() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "i dont exist", Functions: "sum,max,min,sqr", Step: 1 * 60 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectAggregatesByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "max"}, {Metric: "cpu", Function: "min"}, {Metric: "cpu", Function: "sum"}}, - Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectRawDataByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := ingestedData - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu"}}, - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectAggregatesAndRawByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "": {{suite.basicQueryTime, 10}, {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu"}}, - Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectServerAggregatesAndRawByRequestedColumns() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 100}}, - "": {{suite.basicQueryTime, 10}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: "cpu", Function: "sum"}, {Metric: "cpu", Interpolator: "next"}}, - Step: 60 * tsdbtest.MinuteInMillis, From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestRawDataMultipleMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*eventsInterval, 30}, - {suite.basicQueryTime + 4*eventsInterval, 40}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 3*eventsInterval, 30}, - {suite.basicQueryTime + 4*eventsInterval, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{metricName1: ingestData1, metricName2: ingestData2} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData[name], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDataFrameRawDataMultipleMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - expectedTimeColumn := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 5*tsdbtest.DaysInMillis, - suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, - suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, suite.basicQueryTime + 4*tsdbtest.MinuteInMillis} - expectedColumns := map[string][]float64{metricName1: {10, math.NaN(), 20, 30, math.NaN(), 40}, - metricName2: {math.NaN(), 10, math.NaN(), 20, 30, 40}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime - 5*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + 2*tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}}}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime - 8*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - iter, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] // in tsdb we have only one index - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - column, err := frame.Column(columnName) - suite.NoError(err) - v, _ := column.FloatAt(i) - - expected := expectedColumns[column.Name()][i] - - // assert can not compare NaN, so we need to check it manually - if !(math.IsNaN(expected) && math.IsNaN(v)) { - assert.Equal(suite.T(), expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) - } - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryAllData() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,max,min", - Step: 2 * 60 * 1000, - From: 0, - To: math.MaxInt64} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestVariantTypeQueryWithDataFrame() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - metricName := "log" - labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) - - dataToIngest := []string{"a", "b", "c", "d", "e"} - numberOfEvents := len(dataToIngest) - var expectedTimeColumn []int64 - for i := 0; i < numberOfEvents; i++ { - expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) - } - - appender, err := adapter.Appender() - if err != nil { - suite.T().Fatalf("failed to create v3io appender. reason: %s", err) - } - - ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) - if err != nil { - suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) - } - for i := 1; i < numberOfEvents; i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) - } - - if _, err := appender.WaitForCompletion(0); err != nil { - suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, - From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - iter, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] // in tsdb we have only one index - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - assert.Equal(suite.T(), expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - column, err := frame.Column(columnName) - suite.NoError(err) - v, _ := column.StringAt(i) - - expected := dataToIngest[i] - - assert.Equal(suite.T(), expected, v, "column %v does not match at index %v", column.Name(), i) - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestVariantTypeQueryWithSeries() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - metricName := "log" - labels := utils.LabelsFromStringList("os", "linux", "__name__", metricName) - - dataToIngest := []string{"a", "b", "c", "d", "e"} - numberOfEvents := len(dataToIngest) - var expectedTimeColumn []int64 - for i := 0; i < numberOfEvents; i++ { - expectedTimeColumn = append(expectedTimeColumn, suite.basicQueryTime+int64(i)*tsdbtest.MinuteInMillis) - } - - appender, err := adapter.Appender() - if err != nil { - suite.T().Fatalf("failed to create v3io appender. reason: %s", err) - } - - ref, err := appender.Add(labels, expectedTimeColumn[0], dataToIngest[0]) - if err != nil { - suite.T().Fatalf("Failed to add data to the TSDB appender. Reason: %s", err) - } - for i := 1; i < numberOfEvents; i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], dataToIngest[i]) - } - - if _, err := appender.WaitForCompletion(0); err != nil { - suite.T().Fatalf("Failed to wait for TSDB append completion. Reason: %s", err) - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName}}, - From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - iter, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - var seriesCount int - for iter.Next() { - seriesCount++ - iter := iter.At().Iterator() - var i int - for iter.Next() { - t, v := iter.AtString() - assert.Equal(suite.T(), expectedTimeColumn[i], t, "time does not match at index %v", i) - assert.Equal(suite.T(), dataToIngest[i], v, "value does not match at index %v", i) - i++ - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"sum": {{Time: suite.basicQueryTime, Value: 30}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "max": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,max_all,count_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByOneLabelSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") - labels2 := utils.LabelsFromStringList("os", "mac", "region", "europe") - labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas") - labels4 := utils.LabelsFromStringList("os", "linux", "region", "asia") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels3, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels4, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string]map[string][]tsdbtest.DataPoint{ - "linux": { - "sum": {{Time: suite.basicQueryTime, Value: 30}}, - "count": {{Time: suite.basicQueryTime, Value: 3}}}, - "mac": { - "sum": {{Time: suite.basicQueryTime, Value: 10}}, - "count": {{Time: suite.basicQueryTime, Value: 1}}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: "os"} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "failed to exeute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - groupByValue := set.At().Labels().Get("os") - suite.Require().NoError(err) - - suite.Require().Equal(expected[groupByValue][agg], data, "queried data does not match expected") - } - - suite.Require().Equal(4, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByMultipleLabelsSinglePartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "1") - labels2 := utils.LabelsFromStringList("os", "linux", "region", "europe", "version", "2") - labels3 := utils.LabelsFromStringList("os", "linux", "region", "americas", "version", "3") - labels4 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "1") - labels5 := utils.LabelsFromStringList("os", "mac", "region", "asia", "version", "2") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels3, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels4, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels5, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - groupBy := []string{"os", "region"} - expected := map[string]map[string][]tsdbtest.DataPoint{ - "linux-europe": { - "sum": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}}, - "linux-americas": { - "sum": {{Time: suite.basicQueryTime, Value: 10}}, - "count": {{Time: suite.basicQueryTime, Value: 1}}}, - "mac-asia": { - "sum": {{Time: suite.basicQueryTime, Value: 20}}, - "count": {{Time: suite.basicQueryTime, Value: 2}}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: strings.Join(groupBy, ",")} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "failed to exeute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - var groupByValue []string - for _, label := range groupBy { - groupByValue = append(groupByValue, set.At().Labels().Get(label)) - } - labelsStr := strings.Join(groupByValue, "-") - - suite.Require().NoError(err) - - suite.Require().Equal(expected[labelsStr][agg], data, "queried data does not match expected") - } - - suite.Require().Equal(6, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestGroupByNotExistingLabel() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux", "region", "europe") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", - Functions: "sum,count", - Step: 2 * 60 * 1000, - From: suite.basicQueryTime, - To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval), - GroupBy: "something that does not exist"} - _, err = querierV2.Select(params) - if err == nil { - suite.T().Fatalf("expected fail but continued normally") - } -} - -func (suite *testQuerySuite) TestAggregatesWithZeroStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"max": {{Time: suite.basicQueryTime, Value: 40}}, - "min": {{Time: suite.basicQueryTime, Value: 10}}, - "sum": {{Time: suite.basicQueryTime, Value: 100}}, - "count": {{Time: suite.basicQueryTime, Value: 4}}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expected[agg], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 4, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregatesWithZeroStepSelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string]tsdbtest.DataPoint{"max": {Time: suite.basicQueryTime, Value: 40}, - "min": {Time: suite.basicQueryTime, Value: 10}, - "sum": {Time: suite.basicQueryTime, Value: 100}, - "count": {Time: suite.basicQueryTime, Value: 4}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max, sum,count,min", Step: 0, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), 1, indexCol.Len()) - t, err := indexCol.TimeAt(0) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), suite.basicQueryTime, t.UnixNano()/int64(time.Millisecond)) - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - suite.Require().Equal(1, col.Len()) - currentColAggregate := strings.Split(col.Name(), "(")[0] - f, err := col.FloatAt(0) - assert.NoError(suite.T(), err) - suite.Require().Equal(expected[currentColAggregate].Value, f) - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestEmptyRawDataSelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", From: suite.basicQueryTime - 10*tsdbtest.MinuteInMillis, To: suite.basicQueryTime - 1*tsdbtest.MinuteInMillis} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - suite.Require().Equal(0, frame.Indices()[0].Len()) - - for _, colName := range frame.Names() { - col, _ := frame.Column(colName) - assert.Equal(suite.T(), 0, col.Len()) - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) Test2Series1EmptySelectDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 10}}}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"cpu": ingestedData, - "diskio": {{suite.basicQueryTime, math.NaN()}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), math.NaN()}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, math.NaN()}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, math.NaN()}}, - } - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params, _, _ := pquerier.ParseQuery("select cpu,diskio") - params.From = suite.basicQueryTime - params.To = suite.basicQueryTime + 4*tsdbtest.MinuteInMillis - - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), len(ingestedData), indexCol.Len()) - for i := 0; i < indexCol.Len(); i++ { - t, err := indexCol.TimeAt(i) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), ingestedData[i].Time, t.UnixNano()/int64(time.Millisecond)) - } - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - assert.Equal(suite.T(), len(ingestedData), col.Len()) - for i := 0; i < col.Len(); i++ { - currentExpected := expected[col.Name()][i].Value - f, err := col.FloatAt(i) - assert.NoError(suite.T(), err) - - if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { - assert.Equal(suite.T(), currentExpected, f) - } - } - } - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregateSeriesWithAlias() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedResult := 40.0 - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - aliasName := "iguaz" - params, _, _ := pquerier.ParseQuery(fmt.Sprintf("select max(cpu) as %v", aliasName)) - - params.From = suite.basicQueryTime - params.To = suite.basicQueryTime + int64(numberOfEvents*eventsInterval) - - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - assert.Equal(suite.T(), 1, len(data), "queried data does not match expected") - assert.Equal(suite.T(), expectedResult, data[0].Value, "queried data does not match expected") - - seriesName := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - suite.Equal(aliasName, seriesName) - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestStringAndFloatMetricsDataframe() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.NoError(err, "failed to create v3io adapter") - - metricName1 := "cpu" - metricName2 := "log" - labels := utils.LabelsFromStringList("os", "linux") - labelsWithName := append(labels, utils.LabelsFromStringList("__name__", metricName2)...) - - expectedTimeColumn := []int64{suite.basicQueryTime, suite.basicQueryTime + tsdbtest.MinuteInMillis, suite.basicQueryTime + 2*tsdbtest.MinuteInMillis} - logData := []interface{}{"a", "b", "c"} - expectedColumns := map[string][]interface{}{metricName1: {10.0, 20.0, 30.0}, - metricName2: logData} - appender, err := adapter.Appender() - suite.NoError(err, "failed to create v3io appender") - - ref, err := appender.Add(labelsWithName, expectedTimeColumn[0], logData[0]) - suite.NoError(err, "failed to add data to the TSDB appender") - for i := 1; i < len(expectedTimeColumn); i++ { - appender.AddFast(labels, ref, expectedTimeColumn[i], logData[i]) - } - - _, err = appender.WaitForCompletion(0) - suite.NoError(err, "failed to wait for TSDB append completion") - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels, - Data: []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}}}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - suite.NoError(err, "failed to create querier") - - params := &pquerier.SelectParams{RequestedColumns: []pquerier.RequestedColumn{{Metric: metricName1}, {Metric: metricName2}}, - From: suite.basicQueryTime, To: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis} - iter, err := querierV2.SelectDataFrame(params) - suite.NoError(err, "failed to execute query") - - var seriesCount int - for iter.NextFrame() { - seriesCount++ - frame, err := iter.GetFrame() - suite.NoError(err) - indexCol := frame.Indices()[0] - - for i := 0; i < indexCol.Len(); i++ { - t, _ := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().Equal(expectedTimeColumn[i], timeMillis, "time column does not match at index %v", i) - for _, columnName := range frame.Names() { - var v interface{} - - column, err := frame.Column(columnName) - suite.NoError(err) - if column.DType() == frames.FloatType { - v, _ = column.FloatAt(i) - } else if column.DType() == frames.StringType { - v, _ = column.StringAt(i) - } else { - suite.Fail(fmt.Sprintf("column type is not as expected: %v", column.DType())) - } - - suite.Require().Equal(expectedColumns[column.Name()][i], v, "column %v does not match at index %v", column.Name(), i) - } - } - } -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesTimesFallsOnStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregates() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "avg": {{Time: suite.basicQueryTime, Value: 15}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 25}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 35}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "sum_all,min_all,avg_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartition() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "max": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 20}, - {Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 60}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - params := &pquerier.SelectParams{Name: "cpu", Functions: "max_all", Step: 2 * 60 * 1000, From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesWithInterpolation() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 40}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 20}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 4*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartitionExactlyOnStep() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, - {Time: suite.basicQueryTime, Value: 50}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 100}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 40}}, - "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, - {Time: suite.basicQueryTime, Value: 25}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 50}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesMultiPartitionWithInterpolation() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 3*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime, 20}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 60}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 20}, - {suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime, 30}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 1}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 30}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 21}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 21}, - {Time: suite.basicQueryTime, Value: 50}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 61}}, - "count": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 2}, - {Time: suite.basicQueryTime, Value: 2}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 2}}, - "min": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 1}}, - "avg": {{Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, Value: 15}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 2*tsdbtest.MinuteInMillis, Value: 1}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 4*tsdbtest.MinuteInMillis, Value: 10.5}, - {Time: suite.basicQueryTime - 7*tsdbtest.DaysInMillis + 6*tsdbtest.MinuteInMillis, Value: 10.5}, - {Time: suite.basicQueryTime, Value: 25}, - {Time: suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, Value: 30.5}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)),avg_all(prev(cpu)),count_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 2 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - 7*tsdbtest.DaysInMillis - selectParams.To = suite.basicQueryTime + 5*tsdbtest.MinuteInMillis - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestCrossSeriesAggregatesWithInterpolationOverTolerance() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}, - {suite.basicQueryTime + 1*tsdbtest.MinuteInMillis, 20}, - {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 30}} - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}, - {suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{ - "sum": {{Time: suite.basicQueryTime, Value: 30}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 70}}, - "min": {{Time: suite.basicQueryTime, Value: 10}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 30}}, - "max": {{Time: suite.basicQueryTime, Value: 20}, - {Time: suite.basicQueryTime + 5*tsdbtest.MinuteInMillis, Value: 30}, - {Time: suite.basicQueryTime + 10*tsdbtest.MinuteInMillis, Value: 40}}} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - selectParams, _, err := pquerier.ParseQuery("select sum_all(prev(cpu)), min_all(prev(cpu)), max_all(prev(cpu))") - suite.NoError(err) - selectParams.Step = 5 * tsdbtest.MinuteInMillis - selectParams.From = suite.basicQueryTime - selectParams.To = suite.basicQueryTime + 10*tsdbtest.MinuteInMillis - for i := 0; i < len(selectParams.RequestedColumns); i++ { - selectParams.RequestedColumns[i].InterpolationTolerance = tsdbtest.MinuteInMillis - } - set, err := querierV2.Select(selectParams) - suite.Require().NoError(err, "Failed to execute query") - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected[agg], data, "queried data does not match expected") - } - - suite.Require().Equal(len(expected), seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryMultipleMetricsWithMultipleLabelSets() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime, 20}} - ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, - {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{fmt.Sprintf("%v-%v", metricName1, "linux"): ingestData1, - fmt.Sprintf("%v-%v", metricName2, "linux"): ingestData2, - fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels1, - Data: ingestData2}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData3}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Filter: "1==1", - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - name := set.At().Labels().Get(config.PrometheusMetricNameAttribute) - os := set.At().Labels().Get("os") - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", name, os)], data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 3, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestQueryDataFrameMultipleMetricsWithMultipleLabelSets() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - metricName1 := "cpu" - metricName2 := "diskio" - labels1 := utils.LabelsFromStringList("os", "linux") - labels2 := utils.LabelsFromStringList("os", "mac") - numberOfEvents := 5 - eventsInterval := int64(tsdbtest.MinuteInMillis) - ingestData1 := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}} - ingestData3 := []tsdbtest.DataPoint{{suite.basicQueryTime, 30}, - {suite.basicQueryTime + tsdbtest.MinuteInMillis, 40}} - - expectedData := map[string][]tsdbtest.DataPoint{ - fmt.Sprintf("%v-%v", metricName1, "linux"): {{suite.basicQueryTime, 10}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, math.NaN()}}, - fmt.Sprintf("%v-%v", metricName2, "linux"): {{suite.basicQueryTime, math.NaN()}, {suite.basicQueryTime + tsdbtest.MinuteInMillis, 20}}, - fmt.Sprintf("%v-%v", metricName2, "mac"): ingestData3} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: metricName1, - Labels: labels1, - Data: ingestData1}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels1, - Data: ingestData2}, - tsdbtest.Metric{ - Name: metricName2, - Labels: labels2, - Data: ingestData3}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Filter: "1==1", - From: suite.basicQueryTime, To: suite.basicQueryTime + int64(numberOfEvents)*eventsInterval} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.NextFrame() { - seriesCount++ - frame, err := set.GetFrame() - suite.NoError(err) - - indexCol := frame.Indices()[0] - assert.Equal(suite.T(), 2, indexCol.Len()) - for i := 0; i < indexCol.Len(); i++ { - t, err := indexCol.TimeAt(i) - assert.NoError(suite.T(), err) - assert.Equal(suite.T(), expectedData[fmt.Sprintf("%v-%v", metricName1, "linux")][i].Time, t.UnixNano()/int64(time.Millisecond)) - - for _, colName := range frame.Names() { - col, err := frame.Column(colName) - suite.NoError(err) - currentExpectedData := expectedData[fmt.Sprintf("%v-%v", col.Name(), frame.Labels()["os"])] - assert.Equal(suite.T(), len(currentExpectedData), col.Len()) - currentExpected := currentExpectedData[i].Value - f, err := col.FloatAt(i) - assert.NoError(suite.T(), err) - - if !(math.IsNaN(currentExpected) && math.IsNaN(f)) { - assert.Equal(suite.T(), currentExpected, f) - } - } - } - } - - assert.Equal(suite.T(), 2, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestAggregatesWithDisabledClientAggregation() { - suite.v3ioConfig.DisableClientAggr = true - defer func() { suite.v3ioConfig.DisableClientAggr = false }() - - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - labels1 := utils.LabelsFromStringList("os", "linux") - numberOfEvents := 10 - eventsInterval := 60 * 1000 - - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime - tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime + tsdbtest.MinuteInMillis), 20}, - {suite.basicQueryTime + 2*tsdbtest.MinuteInMillis, 30}, - {suite.basicQueryTime + 3*tsdbtest.MinuteInMillis, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels1, - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expected := map[string][]tsdbtest.DataPoint{"avg": {{Time: suite.basicQueryTime - tsdbtest.DaysInMillis, Value: 10}, - {Time: suite.basicQueryTime, Value: 30}}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{Name: "cpu", Functions: "avg", From: suite.basicQueryTime - tsdbtest.DaysInMillis, To: suite.basicQueryTime + int64(numberOfEvents*eventsInterval)} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - - data, err := tsdbtest.IteratorToSlice(iter) - agg := set.At().Labels().Get(aggregate.AggregateLabel) - if err != nil { - suite.T().Fatal(err) - } - currentExpected, ok := expected[agg] - suite.Require().Equal(true, ok, "got unexpected aggregate result") - assert.Equal(suite.T(), currentExpected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDifferentLabelSetsInDifferentPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels2 := utils.LabelsFromStringList("os", "mac") - - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 40}, - {suite.basicQueryTime, 40}} - - expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels2, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestDifferentMetricsInDifferentPartitions() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - - ingestData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 9*tsdbtest.DaysInMillis - 1*tsdbtest.HoursInMillis, 10}, - {suite.basicQueryTime, 40}} - - expected := []tsdbtest.DataPoint{{suite.basicQueryTime, 40}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{ - tsdbtest.Metric{ - Name: "diskio", - Labels: labels1, - Data: ingestData2}, - }}) - - tsdbtest.InsertData(suite.T(), testParams) - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{From: suite.basicQueryTime - 9*tsdbtest.DaysInMillis, To: suite.basicQueryTime + tsdbtest.DaysInMillis} - set, err := querierV2.Select(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var seriesCount int - for set.Next() { - seriesCount++ - iter := set.At().Iterator() - data, err := tsdbtest.IteratorToSlice(iter) - if err != nil { - suite.T().Fatal(err) - } - - suite.Require().Equal(expected, data, "queried data does not match expected") - } - - assert.Equal(suite.T(), 1, seriesCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectDataframeAggregationsMetricsHaveBigGaps() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} - - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu1", - Labels: labels1, - Data: ingestedData1}, - tsdbtest.Metric{ - Name: "cpu2", - Labels: labels1, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} - expected := map[string][]float64{"count(cpu1)": {1, 1, math.NaN()}, - "count(cpu2)": {math.NaN(), math.NaN(), 1}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{ - Functions: "count", - Step: int64(tsdbtest.MinuteInMillis), - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var dataFrameCount int - for set.NextFrame() { - dataFrameCount++ - frame, err := set.GetFrame() - suite.Require().NoError(err) - suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") - suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") - - indexCol := frame.Indices()[0] - - for i := 0; i < len(expected); i++ { - t, err := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().NoError(err) - suite.Require().Equal(expectedTime[i], timeMillis) - - for _, currName := range frame.Names() { - currCol, err := frame.Column(currName) - suite.Require().NoError(err) - currVal, err := currCol.FloatAt(i) - - suite.Require().NoError(err) - if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { - suite.Require().Equal(expected[currName][i], currVal) - } - } - } - } - - suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) TestSelectDataframeDaownsampleMetricsHaveBigGaps() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - if err != nil { - suite.T().Fatalf("failed to create v3io adapter. reason: %s", err) - } - - labels1 := utils.LabelsFromStringList("os", "linux") - ingestedData1 := []tsdbtest.DataPoint{{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, 10}, - {int64(suite.basicQueryTime - 4*tsdbtest.DaysInMillis), 20}} - - ingestedData2 := []tsdbtest.DataPoint{{suite.basicQueryTime - 1*tsdbtest.DaysInMillis, 30}} - - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu1", - Labels: labels1, - Data: ingestedData1}, - tsdbtest.Metric{ - Name: "cpu2", - Labels: labels1, - Data: ingestedData2}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - - expectedTime := []int64{suite.basicQueryTime - 7*tsdbtest.DaysInMillis, suite.basicQueryTime - 4*tsdbtest.DaysInMillis, suite.basicQueryTime - 1*tsdbtest.DaysInMillis} - expected := map[string][]float64{"cpu1": {10, 20, math.NaN()}, - "cpu2": {math.NaN(), math.NaN(), 30}} - - querierV2, err := adapter.QuerierV2() - if err != nil { - suite.T().Fatalf("Failed to create querier v2, err: %v", err) - } - - params := &pquerier.SelectParams{ - Step: int64(tsdbtest.MinuteInMillis), - From: suite.basicQueryTime - 7*tsdbtest.DaysInMillis, - To: suite.basicQueryTime} - set, err := querierV2.SelectDataFrame(params) - if err != nil { - suite.T().Fatalf("Failed to exeute query, err: %v", err) - } - - var dataFrameCount int - for set.NextFrame() { - dataFrameCount++ - frame, err := set.GetFrame() - suite.Require().NoError(err) - suite.Require().Equal(len(expected), len(frame.Names()), "number of columns in frame does not match") - suite.Require().Equal(len(expectedTime), frame.Indices()[0].Len(), "columns size is not as expected") - - indexCol := frame.Indices()[0] - - for i := 0; i < len(expected); i++ { - t, err := indexCol.TimeAt(i) - timeMillis := t.UnixNano() / int64(time.Millisecond) - suite.Require().NoError(err) - suite.Require().Equal(expectedTime[i], timeMillis) - - for _, currName := range frame.Names() { - currCol, err := frame.Column(currName) - suite.Require().NoError(err) - currVal, err := currCol.FloatAt(i) - - suite.Require().NoError(err) - if !(math.IsNaN(currVal) && math.IsNaN(expected[currName][i])) { - suite.Require().Equal(expected[currName][i], currVal) - } - } - } - } - - suite.Require().Equal(1, dataFrameCount, "series count didn't match expected") -} - -func (suite *testQuerySuite) toMillis(date string) int64 { - time, err := tsdbtest.DateStringToMillis(date) - suite.NoError(err) - return time -} - -func TestQueryV2Suite(t *testing.T) { - suite.Run(t, new(testQuerySuite)) -} - -type getLabelSetsSuite struct { - suite.Suite - v3ioConfig *config.V3ioConfig - suiteTimestamp int64 - basicQueryTime int64 -} - -func (suite *getLabelSetsSuite) SetupSuite() { - v3ioConfig, err := tsdbtest.LoadV3ioConfig() - if err != nil { - suite.T().Fatalf("unable to load configuration. Error: %v", err) - } - - suite.v3ioConfig = v3ioConfig - suite.suiteTimestamp = time.Now().Unix() - suite.basicQueryTime, err = tsdbtest.DateStringToMillis("2018-07-21T10:00:00Z") - suite.NoError(err) -} - -func (suite *getLabelSetsSuite) SetupTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - tsdbtest.CreateTestTSDB(suite.T(), suite.v3ioConfig) -} - -func (suite *getLabelSetsSuite) TearDownTest() { - suite.v3ioConfig.TablePath = fmt.Sprintf("%s-%v", suite.T().Name(), suite.suiteTimestamp) - if !suite.T().Failed() { - tsdbtest.DeleteTSDB(suite.T(), suite.v3ioConfig) - } -} - -func (suite *getLabelSetsSuite) TestGetLabels() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsAllMetrics() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "mac", "region", "europe", config.PrometheusMetricNameAttribute, "diskio")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsAllSpecificMetric() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "diskio", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func (suite *getLabelSetsSuite) TestGetLabelsWithFilter() { - adapter, err := tsdb.NewV3ioAdapter(suite.v3ioConfig, nil, nil) - suite.Require().NoError(err, "failed to create v3io adapter") - - labels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe"), - utils.LabelsFromStringList("os", "linux", "region", "asia"), - utils.LabelsFromStringList("os", "mac", "region", "europe")} - ingestedData := []tsdbtest.DataPoint{{suite.basicQueryTime, 10}} - testParams := tsdbtest.NewTestParams(suite.T(), - tsdbtest.TestOption{ - Key: tsdbtest.OptTimeSeries, - Value: tsdbtest.TimeSeries{tsdbtest.Metric{ - Name: "cpu", - Labels: labels[0], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[1], - Data: ingestedData}, - tsdbtest.Metric{ - Name: "cpu", - Labels: labels[2], - Data: ingestedData}, - }}) - tsdbtest.InsertData(suite.T(), testParams) - expectedLabels := []utils.Labels{utils.LabelsFromStringList("os", "linux", "region", "europe", config.PrometheusMetricNameAttribute, "cpu"), - utils.LabelsFromStringList("os", "linux", "region", "asia", config.PrometheusMetricNameAttribute, "cpu")} - - querierV2, err := adapter.QuerierV2() - suite.Require().NoError(err, "failed to create querier v2") - - labelsList, err := querierV2.GetLabelSets("cpu", "os=='linux'") - if err != nil { - suite.T().Fatalf("failed to get label sets, err:%v\n", err) - } - - suite.ElementsMatch(expectedLabels, labelsList, "actual label sets does not match expected") -} - -func TestGetLabelSetsSuite(t *testing.T) { - suite.Run(t, new(getLabelSetsSuite)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go index 4e0ad994..7c31fe84 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/select.go @@ -22,9 +22,10 @@ import ( const defaultToleranceFactor = 2 type selectQueryContext struct { - logger logger.Logger - container *v3io.Container - workers int + logger logger.Logger + container *v3io.Container + workers int + v3ioConfig *config.V3ioConfig queryParams *SelectParams showAggregateLabel bool @@ -35,6 +36,10 @@ type selectQueryContext struct { totalColumns int isCrossSeriesAggregate bool + // In case one of the aggregates of one of the metrics should use client side aggregates + // but the user requested to disable client aggregations - return raw data for every requested metric + forceRawQuery bool + dataFrames map[uint64]*dataFrame frameList []*dataFrame requestChannels []chan *qryResults @@ -143,6 +148,9 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio mint = queryCtx.queryParams.From } + queryRawInsteadOfAggregates, doForceAllRawQuery := false, false + var index int + for metric := range queryCtx.columnsSpecByMetric { var aggregationParams *aggregate.AggregationParams functions, requestAggregatesAndRaw := queryCtx.metricsAggregatesToString(metric) @@ -158,8 +166,11 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio "v", partition.AggrBuckets(), queryCtx.queryParams.Step, + queryCtx.queryParams.AggregationWindow, partition.RollupTime(), - queryCtx.queryParams.Windows) + queryCtx.queryParams.Windows, + queryCtx.queryParams.disableClientAggr, + queryCtx.v3ioConfig.UseServerAggregateCoefficient) if err != nil { return nil, err @@ -168,21 +179,56 @@ func (queryCtx *selectQueryContext) queryPartition(partition *partmgr.DBPartitio } - newQuery := &partQuery{mint: mint, maxt: maxt, partition: partition, step: queryCtx.queryParams.Step} + newQuery := &partQuery{mint: mint, + maxt: maxt, + partition: partition, + step: queryCtx.queryParams.Step, + name: metric, + aggregatesAndChunk: requestAggregatesAndRaw} if aggregationParams != nil { // Cross series aggregations cannot use server side aggregates. - newQuery.useServerSideAggregates = aggregationParams.CanAggregate(partition.AggrType()) && !queryCtx.isCrossSeriesAggregate + newQuery.useServerSideAggregates = aggregationParams.CanAggregate(partition.AggrType()) && + !queryCtx.isCrossSeriesAggregate && + !queryCtx.queryParams.UseOnlyClientAggr if newQuery.useServerSideAggregates || !queryCtx.queryParams.disableClientAggr { newQuery.aggregationParams = aggregationParams } } - var preAggregateLabels []string if newQuery.useServerSideAggregates && !requestAggregatesAndRaw { - preAggregateLabels = queryCtx.parsePreAggregateLabels(partition) + newQuery.preAggregateLabels = queryCtx.parsePreAggregateLabels(partition) } - err = newQuery.getItems(queryCtx, metric, preAggregateLabels, requestAggregatesAndRaw) + queries = append(queries, newQuery) + + currentQueryShouldQueryRawInsteadOfAggregates := !newQuery.useServerSideAggregates && queryCtx.queryParams.disableClientAggr + if len(queryCtx.columnsSpecByMetric) == 1 && currentQueryShouldQueryRawInsteadOfAggregates { + doForceAllRawQuery = true + } else if index == 0 { + queryRawInsteadOfAggregates = currentQueryShouldQueryRawInsteadOfAggregates + } else if queryRawInsteadOfAggregates != currentQueryShouldQueryRawInsteadOfAggregates { + doForceAllRawQuery = true + } + index++ + } + + if doForceAllRawQuery { + queryCtx.forceRawQuery = true + for _, q := range queries { + q.aggregationParams = nil + q.useServerSideAggregates = false + err = q.getItems(queryCtx) + if err != nil { + break + } + } + } else { + for _, q := range queries { + err = q.getItems(queryCtx) + if err != nil { + break + } + } } return queries, err @@ -324,7 +370,12 @@ func (queryCtx *selectQueryContext) processQueryResults(query *partQuery) error func (queryCtx *selectQueryContext) createColumnSpecs() ([]columnMeta, map[string][]columnMeta, error) { var columnsSpec []columnMeta columnsSpecByMetric := make(map[string][]columnMeta) - for i, col := range queryCtx.queryParams.getRequestedColumns() { + requestedColumns, err := queryCtx.queryParams.getRequestedColumns() + if err != nil { + return nil, nil, err + } + + for i, col := range requestedColumns { _, ok := columnsSpecByMetric[col.Metric] if !ok { columnsSpecByMetric[col.Metric] = []columnMeta{} @@ -430,7 +481,9 @@ func (queryCtx *selectQueryContext) generateTimeColumn() Column { } func (queryCtx *selectQueryContext) isRawQuery() bool { - return (!queryCtx.hasAtLeastOneFunction() && queryCtx.queryParams.Step == 0) || queryCtx.queryParams.disableAllAggr + return (!queryCtx.hasAtLeastOneFunction() && queryCtx.queryParams.Step == 0) || + queryCtx.queryParams.disableAllAggr || + queryCtx.forceRawQuery } func (queryCtx *selectQueryContext) hasAtLeastOneFunction() bool { @@ -467,18 +520,22 @@ type partQuery struct { chunkTime int64 useServerSideAggregates bool aggregationParams *aggregate.AggregationParams + + name string + preAggregateLabels []string + aggregatesAndChunk bool } -func (query *partQuery) getItems(ctx *selectQueryContext, name string, preAggregateLabels []string, aggregatesAndChunk bool) error { +func (query *partQuery) getItems(ctx *selectQueryContext) error { path := query.partition.GetTablePath() - if len(preAggregateLabels) > 0 { - path = fmt.Sprintf("%sagg/%s/", path, strings.Join(preAggregateLabels, ",")) + if len(query.preAggregateLabels) > 0 { + path = fmt.Sprintf("%sagg/%s/", path, strings.Join(query.preAggregateLabels, ",")) } var shardingKeys []string - if name != "" { - shardingKeys = query.partition.GetShardingKeys(name) + if query.name != "" { + shardingKeys = query.partition.GetShardingKeys(query.name) } attrs := []string{config.LabelSetAttrName, config.EncodingAttrName, config.MetricNameAttrName, config.MaxTimeAttrName, config.ObjectNameAttrName} @@ -487,15 +544,15 @@ func (query *partQuery) getItems(ctx *selectQueryContext, name string, preAggreg } // It is possible to request both server aggregates and raw chunk data (to downsample) for the same metric // example: `select max(cpu), avg(cpu), cpu` with step = 1h - if !query.useServerSideAggregates || aggregatesAndChunk { - chunkAttr, chunk0Time := query.partition.Range2Attrs("v", query.mint, query.maxt) + if !query.useServerSideAggregates || query.aggregatesAndChunk { + chunkAttr, chunk0Time := query.partition.Range2Attrs("v", query.mint-ctx.queryParams.AggregationWindow, query.maxt) query.chunk0Time = chunk0Time query.attrs = append(query.attrs, chunkAttr...) } attrs = append(attrs, query.attrs...) - ctx.logger.DebugWith("Select - GetItems", "path", path, "attr", attrs, "filter", ctx.queryParams.Filter, "name", name) - input := v3io.GetItemsInput{Path: path, AttributeNames: attrs, Filter: ctx.queryParams.Filter, ShardingKey: name} + ctx.logger.DebugWith("Select - GetItems", "path", path, "attr", attrs, "filter", ctx.queryParams.Filter, "name", query.name) + input := v3io.GetItemsInput{Path: path, AttributeNames: attrs, Filter: ctx.queryParams.Filter, ShardingKey: query.name} iter, err := utils.NewAsyncItemsCursor(ctx.container, &input, ctx.workers, shardingKeys, ctx.logger) if err != nil { return err diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go index 9aed2e6b..8f3d32c8 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/selectQueryContext_test.go @@ -127,6 +127,41 @@ func TestCreateColumnSpecs(t *testing.T) { } } +func TestNegativeCreateColumnSpecs(t *testing.T) { + testCases := []struct { + desc string + params SelectParams + }{ + {params: SelectParams{Name: "cpu", Functions: "count, count"}}, + + {params: SelectParams{Name: "cpu", Functions: "count, max,count"}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "cpu", Function: "count"}}}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "diskio", Function: "count"}, + {Metric: "cpu", Function: "count"}}}}, + + {params: SelectParams{RequestedColumns: []RequestedColumn{{Metric: "cpu", Function: "count"}, + {Metric: "diskio", Function: "count"}, + {Metric: "cpu", Function: " count "}}}}, + + {params: SelectParams{Name: "cpu", Functions: "count, count", UseOnlyClientAggr: true, disableClientAggr: true}}, + } + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + ctx := selectQueryContext{} + ctx.queryParams = &test.params + _, _, err := ctx.createColumnSpecs() + + if err == nil { + t.Fatal("expected error but finished normally") + } + }) + } +} + func toAggr(str string) aggregate.AggrType { aggr, _ := aggregate.AggregateFromString(str) return aggr diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go index 48378b51..bb239726 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/pquerier/types.go @@ -27,11 +27,11 @@ func (q *qryResults) IsDownsample() bool { } func (q *qryResults) IsServerAggregates() bool { - return q.query.aggregationParams != nil && q.query.aggregationParams.CanAggregate(q.query.partition.AggrType()) + return q.query.aggregationParams != nil && q.query.useServerSideAggregates } func (q *qryResults) IsClientAggregates() bool { - return q.query.aggregationParams != nil && !q.query.aggregationParams.CanAggregate(q.query.partition.AggrType()) + return q.query.aggregationParams != nil && !q.query.useServerSideAggregates } type RequestedColumn struct { diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go index 829bc65f..bd77a960 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/multipart_test.go @@ -1,3 +1,5 @@ +// +build unit + package querier import ( @@ -66,6 +68,6 @@ func (suite *testIterSortMergerSuite) TestIterSortMerger() { suite.Require().Equal(uint64(3), iter.At().GetKey()) } -func TestAddSuite(t *testing.T) { +func TestIterSortMergerSuiteSuite(t *testing.T) { suite.Run(t, new(testIterSortMergerSuite)) } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go index d024f07b..ccec3e25 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/querier/querier.go @@ -259,6 +259,10 @@ func (q *V3ioQuerier) LabelValues(labelKey string) (result []string, err error) return } +func (q *V3ioQuerier) LabelNames() ([]string, error) { + return nil, nil +} + func (q *V3ioQuerier) Close() error { return nil } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go index 31f6a30b..fcf1aed3 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config.go @@ -2,10 +2,8 @@ package tsdbtest import ( "fmt" - "go/build" "os" "path/filepath" - "strings" "github.com/pkg/errors" "github.com/v3io/v3io-tsdb/pkg/config" @@ -30,19 +28,26 @@ func GetV3ioConfigPath() (string, error) { return localConfigFile, nil } - gopath := os.Getenv("GOPATH") - if gopath == "" { - gopath = build.Default.GOPATH - } - gopaths := strings.Split(gopath, string(os.PathListSeparator)) - for _, path := range gopaths { - gopathConfig := filepath.Join(path, relativeProjectPath, config.DefaultConfigurationFileName) - if _, err := os.Stat(gopathConfig); !os.IsNotExist(err) { - return gopathConfig, nil + // Look for a parent directory containing a makefile and the configuration file (presumed to be the project root). + dirPath := "./" + for { + _, err := os.Stat(dirPath + "Makefile") + if err == nil { + confFilePath := dirPath + config.DefaultConfigurationFileName + _, err = os.Stat(confFilePath) + if err == nil { + return confFilePath, nil + } + break // Bail out if we found the makefile but the config is not there. + } + absolute, err := filepath.Abs(dirPath) + if err != nil || absolute == "/" { // Bail out if we reached the root. + break } + dirPath += "../" } - return "", errors.Errorf("config file is not specified and could not be found in GOPATH=%v", gopath) + return "", errors.Errorf("config file is not specified and could not be found") } func LoadV3ioConfig() (*config.V3ioConfig, error) { diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go index 68c6f9a6..e8b7b2cc 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdb/tsdbtest/config_test.go @@ -69,7 +69,7 @@ func TestGetV3ioConfigPath(t *testing.T) { }}, {description: "get config from project root", - expectedPath: filepath.Join(projectHome, config.DefaultConfigurationFileName), + expectedPath: "./../../../v3io-tsdb-config.yaml", setup: func() func() { // Make this test agnostic to environment variables at runtime (store & recover on exit) configPathEnv := os.Getenv(config.V3ioConfigEnvironmentVariable) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go index 495e2f51..08e2661f 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/query.go @@ -21,7 +21,6 @@ such restriction. package tsdbctl import ( - "strconv" "strings" "time" @@ -34,19 +33,20 @@ import ( ) type queryCommandeer struct { - cmd *cobra.Command - rootCommandeer *RootCommandeer - name string - filter string - to string - from string - last string - windows string - functions string - step string - output string - oldQuerier bool - groupBy string + cmd *cobra.Command + rootCommandeer *RootCommandeer + name string + filter string + to string + from string + last string + functions string + step string + output string + oldQuerier bool + groupBy string + usePreciseAggregations bool + aggregationWindow string } func newQueryCommandeer(rootCommandeer *RootCommandeer) *queryCommandeer { @@ -100,23 +100,19 @@ Arguments: "Query filter, as an Iguazio Continuous Data Platform\nfilter expression. To reference a metric name from within\nthe query filter, use the \"__name__\" attribute.\nExamples: \"method=='get'\"; \"__name__='cpu' AND os=='win'\".") cmd.Flags().StringVarP(&commandeer.last, "last", "l", "", "Return data for the specified time period before the\ncurrent time, of the format \"[0-9]+[mhd]\" (where\n'm' = minutes, 'h' = hours, and 'd' = days>). When setting\nthis flag, don't set the -b|--begin or -e|--end flags.\nExamples: \"1h\"; \"15m\"; \"30d\" to return data for the last\n1 hour, 15 minutes, or 30 days.") - cmd.Flags().StringVarP(&commandeer.windows, "windows", "w", "", - "Overlapping windows of time to which to apply the aggregation\nfunctions (if defined - see the -a|--aggregates flag), as a\ncomma separated list of integer values (\"[0-9]+\").\nThe duration of each window is calculated by multiplying the\nvalue from the windows flag with the aggregation interval\n(see -i|--aggregation-interval). The windows' end time is\nthe query's end time (see -e|--end and -l|--last). If the\nwindow's duration extends beyond the query's start time (see\n-b|--begin and -l|--last), it will be shortened to fit the\nstart time. Example: -w \"1,2\" with -i \"2h\", -b 0, and the\ndefault end time (\"now\") defines overlapping aggregation\nwindows for the last 2 hours and 4 hours.") - // The default aggregates list for an overlapping-windows query is "avg", - // provided the TSDB instance has the "count" and "sum" aggregates, which - // make up the "avg" aggregate; ("count" is added automatically when adding - // any other aggregate). However, it was decided that documenting this - // would over complicate the documentation. + cmd.Flags().StringVarP(&commandeer.aggregationWindow, "aggregation-window", "w", "", + "Sliding time window for aggregation. Must be used in conjunction with `-a `. Examples: \"1h\"; \"150m\".") cmd.Flags().StringVarP(&commandeer.functions, "aggregates", "a", "", "Aggregation information to return, as a comma-separated\nlist of supported aggregation functions - count | avg |\nsum | min | max | stddev | stdvar | last | rate.\nFor cross series aggregations add an \"_all\" suffix for the wanted aggregate.\nNote: you can query either over time aggregates or cross series aggregate but not both in the same query.\nExample: \"sum,min,max,count\", \"sum_all,avg_all\".") cmd.Flags().StringVarP(&commandeer.step, "aggregation-interval", "i", "", "Aggregation interval for applying the aggregation functions\n(if set - see the -a|--aggregates flag), of the format\n\"[0-9]+[mhd]\" (where 'm' = minutes, 'h' = hours, and\n'd' = days). Examples: \"1h\"; \"150m\". (default =\n - )") cmd.Flags().StringVar(&commandeer.groupBy, "groupBy", "", "Comma separated list of labels to group the result by") + cmd.Flags().BoolVar(&commandeer.usePreciseAggregations, "use-precise-aggregations", false, + "Disable server aggregation optimizations for more accurate results.") cmd.Flags().BoolVarP(&commandeer.oldQuerier, "oldQuerier", "q", false, "use old querier") cmd.Flags().Lookup("oldQuerier").Hidden = true - cmd.Flags().Lookup("windows").Hidden = true // hidden, because only supported in old querier. commandeer.cmd = cmd return commandeer @@ -186,6 +182,10 @@ func (qc *queryCommandeer) newQuery(from, to, step int64) error { if err != nil { return errors.Wrap(err, "Failed to initialize the Querier object.") } + aggregationWindow, err := utils.Str2duration(qc.aggregationWindow) + if err != nil { + return errors.Wrap(err, "Failed to parse aggregation window") + } var selectParams *pquerier.SelectParams @@ -197,9 +197,13 @@ func (qc *queryCommandeer) newQuery(from, to, step int64) error { selectParams.Step = step selectParams.From = from selectParams.To = to + selectParams.UseOnlyClientAggr = qc.usePreciseAggregations + selectParams.AggregationWindow = aggregationWindow } else { selectParams = &pquerier.SelectParams{Name: qc.name, Functions: qc.functions, - Step: step, Filter: qc.filter, From: from, To: to, GroupBy: qc.groupBy} + Step: step, Filter: qc.filter, From: from, To: to, GroupBy: qc.groupBy, + UseOnlyClientAggr: qc.usePreciseAggregations, + AggregationWindow: aggregationWindow} } set, err := qry.Select(selectParams) @@ -225,22 +229,7 @@ func (qc *queryCommandeer) oldQuery(from, to, step int64) error { } var set utils.SeriesSet - if qc.windows == "" { - set, err = qry.Select(qc.name, qc.functions, step, qc.filter) - } else { - list := strings.Split(qc.windows, ",") - win := []int{} - for _, val := range list { - i, err := strconv.Atoi(val) - if err != nil { - return errors.Wrap(err, "Invalid window.") - } - win = append(win, i) - - } - - set, err = qry.SelectOverlap(qc.name, qc.functions, step, win, qc.filter) - } + set, err = qry.Select(qc.name, qc.functions, step, qc.filter) if err != nil { return errors.Wrap(err, "The query selection failed.") diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go index 43c245fa..53caa684 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl.go @@ -146,6 +146,16 @@ func (rc *RootCommandeer) populateConfig(cfg *config.V3ioConfig) error { if rc.accessKey != "" { cfg.AccessKey = rc.accessKey + } else if rc.password == "" { + envAccessKey := os.Getenv("V3IO_ACCESS_KEY") + if envAccessKey != "" { + cfg.AccessKey = envAccessKey + } + } + + envV3ioApi := os.Getenv("V3IO_API") + if envV3ioApi != "" { + cfg.WebApiEndpoint = envV3ioApi } if rc.v3ioPath != "" { diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go index 9be9e9f6..8e30bb2d 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/tsdbctl/tsdbctl_test.go @@ -23,6 +23,7 @@ such restriction. package tsdbctl import ( + "os" "testing" "github.com/pkg/errors" @@ -37,10 +38,9 @@ type testTsdbctlSuite struct { func (suite *testTsdbctlSuite) TestPopulateConfigWithTenant() { rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123"} - cfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{TablePath: "/x/y/z"}) - suite.Require().Nil(err) + cfg := &config.V3ioConfig{Username: "Vel@Odar", Password: "p455w0rd", TablePath: "/x/y/z"} - err = rc.populateConfig(cfg) + err := rc.populateConfig(cfg) suite.Require().Nil(err) metricReporter, err := performance.DefaultReporterInstance() @@ -55,34 +55,100 @@ func (suite *testTsdbctlSuite) TestPopulateConfigWithTenant() { v3ioPath: "localhost:80123/123", Reporter: metricReporter, } - expectedCfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{ + expectedCfg := &config.V3ioConfig{ WebApiEndpoint: "localhost:80123", Container: "123", TablePath: "/x/y/z", Username: "Vel@Odar", Password: "p455w0rd", - AccessKey: "acce55-key", - }) + LogLevel: "info", + } - suite.Require().Nil(err) suite.Require().Equal(expectedCfg, rc.v3iocfg) suite.Require().Equal(expectedRc, rc) } func (suite *testTsdbctlSuite) TestContainerConfig() { - rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123", container: "test"} - cfg, err := config.GetOrLoadFromStruct(&config.V3ioConfig{TablePath: "/x/y/z"}) - suite.Require().Nil(err) + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{v3ioPath: "Vel@Odar:p455w0rd@localhost:80123/123", container: "test", accessKey: "acce55-key"} + cfg := &config.V3ioConfig{Username: "Vel@Odar", Password: "p455w0rd", TablePath: "/x/y/z"} err = rc.populateConfig(cfg) - expectedCfg, _ := config.GetOrLoadFromStruct(&config.V3ioConfig{ + expectedCfg := &config.V3ioConfig{ WebApiEndpoint: "localhost:80123", Container: "test", TablePath: "/x/y/z", Username: "Vel@Odar", Password: "p455w0rd", AccessKey: "acce55-key", - }) + LogLevel: "info", + } + + suite.Require().Nil(err) + suite.Require().Equal(expectedCfg, rc.v3iocfg) +} + +func (suite *testTsdbctlSuite) TestConfigFromEnvVarsAndPassword() { + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{container: "test", username: "Vel@Odar", password: "p455w0rd"} + cfg := &config.V3ioConfig{TablePath: "/x/y/z"} + suite.Require().Nil(err) + + err = rc.populateConfig(cfg) + expectedCfg := &config.V3ioConfig{ + WebApiEndpoint: "host-from-env:123", + Container: "test", + TablePath: "/x/y/z", + Username: "Vel@Odar", + Password: "p455w0rd", + LogLevel: "info", + } + + suite.Require().Nil(err) + suite.Require().Equal(expectedCfg, rc.v3iocfg) +} + +func (suite *testTsdbctlSuite) TestConfigFromEnvVars() { + oldV3ioApi := os.Getenv("V3IO_API") + err := os.Setenv("V3IO_API", "host-from-env:123") + suite.Require().NoError(err) + defer os.Setenv("V3IO_API", oldV3ioApi) + + oldAccessKey := os.Getenv("V3IO_ACCESS_KEY") + err = os.Setenv("V3IO_ACCESS_KEY", "key-from-env") + suite.Require().NoError(err) + defer os.Setenv("V3IO_ACCESS_KEY", oldAccessKey) + + rc := RootCommandeer{container: "test"} + cfg := &config.V3ioConfig{TablePath: "/x/y/z"} + suite.Require().Nil(err) + + err = rc.populateConfig(cfg) + expectedCfg := &config.V3ioConfig{ + WebApiEndpoint: "host-from-env:123", + Container: "test", + TablePath: "/x/y/z", + AccessKey: "key-from-env", + LogLevel: "info", + } suite.Require().Nil(err) suite.Require().Equal(expectedCfg, rc.v3iocfg) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go index e786ccfb..5d1d949a 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/pkg/utils/asynciter.go @@ -189,7 +189,7 @@ func (ic *AsyncItemsCursor) processResponse() error { } // until IGZ-2.0 there is a bug in Nginx regarding range-scan, the following code is a mitigation for it. - if conf.DisableNginxMitigation { + if *conf.DisableNginxMitigation { ic.sendNextGetItemsOld(resp) } else { ic.sendNextGetItemsNew(resp) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go deleted file mode 100644 index 3db23645..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb.go +++ /dev/null @@ -1,300 +0,0 @@ -package promtsdb - -import ( - "context" - "fmt" - "strings" - - "github.com/nuclio/logger" - "github.com/pkg/errors" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/storage" - "github.com/v3io/v3io-go-http" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/appender" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/pquerier" - "github.com/v3io/v3io-tsdb/pkg/tsdb" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type V3ioPromAdapter struct { - db *tsdb.V3ioAdapter - logger logger.Logger -} - -func NewV3ioProm(cfg *config.V3ioConfig, container *v3io.Container, logger logger.Logger) (*V3ioPromAdapter, error) { - - if logger == nil { - newLogger, err := utils.NewLogger(cfg.LogLevel) - if err != nil { - return nil, errors.Wrap(err, "Unable to initialize logger.") - } - logger = newLogger - } - - adapter, err := tsdb.NewV3ioAdapter(cfg, container, logger) - newAdapter := V3ioPromAdapter{db: adapter, logger: logger.GetChild("v3io-prom-adapter")} - return &newAdapter, err -} - -func (a *V3ioPromAdapter) Appender() (storage.Appender, error) { - err := a.db.InitAppenderCache() - if err != nil { - return nil, err - } - - newAppender := v3ioAppender{metricsCache: a.db.MetricsCache} - return newAppender, nil -} - -func (a *V3ioPromAdapter) StartTime() (int64, error) { - return a.db.StartTime() -} - -func (a *V3ioPromAdapter) Close() error { - return nil -} - -func (a *V3ioPromAdapter) Querier(_ context.Context, mint, maxt int64) (storage.Querier, error) { - v3ioQuerier, err := a.db.QuerierV2() - promQuerier := V3ioPromQuerier{v3ioQuerier: v3ioQuerier, logger: a.logger.GetChild("v3io-prom-query"), mint: mint, maxt: maxt} - return &promQuerier, err -} - -type V3ioPromQuerier struct { - v3ioQuerier *pquerier.V3ioQuerier - logger logger.Logger - mint, maxt int64 -} - -// Select returns a set of series that matches the given label matchers. -func (promQuery *V3ioPromQuerier) Select(params *storage.SelectParams, oms ...*labels.Matcher) (storage.SeriesSet, error) { - name, filter, functions := match2filter(oms, promQuery.logger) - noAggr := false - - // if a nil params is passed we assume it's a metadata query, so we fetch only the different labelsets withtout data. - if params == nil { - labelSets, err := promQuery.v3ioQuerier.GetLabelSets(name, filter) - if err != nil { - return nil, err - } - - return &V3ioPromSeriesSet{newMetadataSeriesSet(labelSets)}, nil - } - - promQuery.logger.Debug("SelectParams: %+v", params) - - if params.Func != "" { - // only pass xx_over_time functions (just the xx part) - // TODO: support count/stdxx, require changes in Prometheus: promql/functions.go, not calc aggregate twice - if strings.HasSuffix(params.Func, "_over_time") { - f := params.Func[0:3] - if params.Step == 0 && (f == "min" || f == "max" || f == "sum" || f == "avg") { - functions = f - } else { - noAggr = true - } - } - } - - selectParams := &pquerier.SelectParams{Name: name, - Functions: functions, - Step: params.Step, - Filter: filter, - From: promQuery.mint, - To: promQuery.maxt} - - set, err := promQuery.v3ioQuerier.SelectProm(selectParams, noAggr) - return &V3ioPromSeriesSet{s: set}, err -} - -// LabelValues returns all potential values for a label name. -func (promQuery *V3ioPromQuerier) LabelValues(name string) ([]string, error) { - return promQuery.v3ioQuerier.LabelValues(name) -} - -// Close releases the resources of the Querier. -func (promQuery *V3ioPromQuerier) Close() error { - return nil -} - -func match2filter(oms []*labels.Matcher, logger logger.Logger) (string, string, string) { - var filter []string - agg := "" - name := "" - - for _, matcher := range oms { - logger.Debug("Matcher: %+v", matcher) - if matcher.Name == aggregate.AggregateLabel { - agg = matcher.Value - } else if matcher.Name == "__name__" && matcher.Type == labels.MatchEqual { - name = matcher.Value - } else { - switch matcher.Type { - case labels.MatchEqual: - filter = append(filter, fmt.Sprintf("%s=='%s'", matcher.Name, matcher.Value)) - case labels.MatchNotEqual: - filter = append(filter, fmt.Sprintf("%s!='%s'", matcher.Name, matcher.Value)) - case labels.MatchRegexp: - filter = append(filter, fmt.Sprintf("regexp_instr(%s,'%s') == 0", matcher.Name, matcher.Value)) - case labels.MatchNotRegexp: - filter = append(filter, fmt.Sprintf("regexp_instr(%s,'%s') != 0", matcher.Name, matcher.Value)) - - } - } - } - filterExp := strings.Join(filter, " and ") - return name, filterExp, agg -} - -type V3ioPromSeriesSet struct { - s utils.SeriesSet -} - -func (s *V3ioPromSeriesSet) Next() bool { return s.s.Next() } -func (s *V3ioPromSeriesSet) Err() error { return s.s.Err() } -func (s *V3ioPromSeriesSet) At() storage.Series { - series := s.s.At() - return &V3ioPromSeries{series} -} - -// Series represents a single time series. -type V3ioPromSeries struct { - s utils.Series -} - -// Labels returns the complete set of labels identifying the series. -func (s *V3ioPromSeries) Labels() labels.Labels { - lbls := labels.Labels{} - for _, l := range s.s.Labels() { - lbls = append(lbls, labels.Label{Name: l.Name, Value: l.Value}) - } - - return lbls -} - -// Iterator returns a new iterator of the data of the series. -func (s *V3ioPromSeries) Iterator() storage.SeriesIterator { - return &V3ioPromSeriesIterator{s: s.s.Iterator()} -} - -// SeriesIterator iterates over the data of a time series. -type V3ioPromSeriesIterator struct { - s utils.SeriesIterator -} - -// Seek advances the iterator forward to the given timestamp. -// If there's no value exactly at t, it advances to the first value -// after t. -func (s *V3ioPromSeriesIterator) Seek(t int64) bool { return s.s.Seek(t) } - -// Next advances the iterator by one. -func (s *V3ioPromSeriesIterator) Next() bool { return s.s.Next() } - -// At returns the current timestamp/value pair. -func (s *V3ioPromSeriesIterator) At() (t int64, v float64) { return s.s.At() } - -// error returns the current error. -func (s *V3ioPromSeriesIterator) Err() error { return s.s.Err() } - -type v3ioAppender struct { - metricsCache *appender.MetricsCache -} - -func (a v3ioAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error) { - lbls := Labels{lbls: &lset} - return a.metricsCache.Add(lbls, t, v) -} - -func (a v3ioAppender) AddFast(lset labels.Labels, ref uint64, t int64, v float64) error { - return a.metricsCache.AddFast(ref, t, v) -} - -func (a v3ioAppender) Commit() error { return nil } -func (a v3ioAppender) Rollback() error { return nil } - -type Labels struct { - lbls *labels.Labels -} - -// convert Label set to a string in the form key1=v1,key2=v2.. + name + hash -func (ls Labels) GetKey() (string, string, uint64) { - key := "" - name := "" - for _, lbl := range *ls.lbls { - if lbl.Name == "__name__" { - name = lbl.Value - } else { - key = key + lbl.Name + "=" + lbl.Value + "," - } - } - if len(key) == 0 { - return name, "", ls.lbls.Hash() - } - return name, key[:len(key)-1], ls.lbls.Hash() - -} - -// create update expression -func (ls Labels) GetExpr() string { - lblexpr := "" - for _, lbl := range *ls.lbls { - if lbl.Name != "__name__" { - lblexpr = lblexpr + fmt.Sprintf("%s='%s'; ", lbl.Name, lbl.Value) - } else { - lblexpr = lblexpr + fmt.Sprintf("_name='%s'; ", lbl.Value) - } - } - - return lblexpr -} - -func (ls Labels) LabelNames() []string { - var res []string - for _, l := range *ls.lbls { - res = append(res, l.Name) - } - return res -} - -func newMetadataSeriesSet(labels []utils.Labels) utils.SeriesSet { - return &metadataSeriesSet{labels: labels, currentIndex: -1, size: len(labels)} -} - -type metadataSeriesSet struct { - labels []utils.Labels - currentIndex int - size int -} - -func (ss *metadataSeriesSet) Next() bool { - ss.currentIndex++ - return ss.currentIndex < ss.size -} -func (ss *metadataSeriesSet) At() utils.Series { - return &metadataSeries{labels: ss.labels[ss.currentIndex]} -} -func (ss *metadataSeriesSet) Err() error { - return nil -} - -type metadataSeries struct { - labels utils.Labels -} - -func (s *metadataSeries) Labels() utils.Labels { return s.labels } -func (s *metadataSeries) Iterator() utils.SeriesIterator { return utils.NullSeriesIterator{} } -func (s *metadataSeries) GetKey() uint64 { return s.labels.Hash() } - -func (ls Labels) Filter(keep []string) utils.LabelsIfc { - var res labels.Labels - for _, l := range *ls.lbls { - for _, keepLabel := range keep { - if l.Name == labels.MetricName || l.Name == keepLabel { - res = append(res, l) - } - } - } - return Labels{lbls: &res} -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go deleted file mode 100644 index 2be95fe6..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_integration_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build integration - -package promtsdb - -import ( - "fmt" - "math/rand" - "testing" - "time" - - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/storage" - "github.com/v3io/v3io-tsdb/pkg/aggregate" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/partmgr" -) - -const basetime = 15222481971234 - -func TestTsdbIntegration(t *testing.T) { - t.Skip("Needs to be refactored - Doesnt test anything") - - d, h := partmgr.TimeToDHM(basetime) - fmt.Println("base=", d, h) - cfg, err := config.GetOrLoadFromFile("../v3io-tsdb-config.yaml") - if err != nil { - t.Fatal(err) - } - fmt.Println(cfg) - - adapter, err := NewV3ioProm(cfg, nil, nil) - if err != nil { - t.Fatal(err) - } - - //adapter.partitionMngr.GetHead().NextPart(0) - - appender, err := adapter.Appender() - if err != nil { - t.Fatal(err) - } - - lset := labels.Labels{labels.Label{Name: "__name__", Value: "http_req"}, - labels.Label{Name: "method", Value: "post"}} - - err = DoAppend(lset, appender, 50, 120) - if err != nil { - t.Fatal(err) - } - - //time.Sleep(time.Second * 5) - //return - - qry, err := adapter.Querier(nil, basetime-0*3600*1000, basetime+5*3600*1000) - if err != nil { - t.Fatal(err) - } - - match := labels.Matcher{Type: labels.MatchEqual, Name: "__name__", Value: "http_req"} - match2 := labels.Matcher{Type: labels.MatchEqual, Name: aggregate.AggregateLabel, Value: "count,avg,sum"} - //params := storage.SelectParams{Func: "count,avg,sum", Step: 1000 * 3600} - params := storage.SelectParams{Func: "", Step: 0} - set, err := qry.Select(¶ms, &match, &match2) - if err != nil { - t.Fatal(err) - } - - lasth := 0 - for set.Next() { - if set.Err() != nil { - t.Fatal(set.Err()) - } - - series := set.At() - fmt.Println("\nLables:", series.Labels()) - iter := series.Iterator() - //iter.Seek(basetime-1*3600*1000) - for iter.Next() { - - if iter.Err() != nil { - t.Fatal(iter.Err()) - } - - t, v := iter.At() - d, h := partmgr.TimeToDHM(t) - if h != lasth { - fmt.Println() - } - fmt.Printf("t=%d:%d,v=%.2f ", d, h, v) - lasth = h - } - fmt.Println() - } - -} - -func DoAppend(lset labels.Labels, app storage.Appender, num, interval int) error { - //return nil - //time.Sleep(time.Second * 1) - curTime := int64(basetime) - - ref, err := app.Add(lset, curTime, 2) - if err != nil { - return err - } - - for i := 0; i <= num; i++ { - time.Sleep(time.Millisecond * 80) - curTime += int64(interval * 1000) - t := curTime + int64(rand.Intn(100)) - 50 - _, h := partmgr.TimeToDHM(t) - v := rand.Float64()*10 + float64(h*100) - fmt.Printf("t-%d,v%3.2f ", t, v) - err = app.AddFast(lset, ref, t, v) - if err != nil { - return err - } - } - - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go deleted file mode 100644 index 0bd02f6a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/promtsdb/promtsdb_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build unit - -/* -Copyright 2018 Iguazio Systems Ltd. - -Licensed under the Apache License, Version 2.0 (the "License") with -an addition restriction as set forth herein. You may not use this -file except in compliance with the License. You may obtain a copy of -the License at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. - -In addition, you may not use the software for any purposes that are -illegal under applicable law, and the grant of the foregoing license -under the Apache 2.0 license is conditioned upon your compliance with -such restriction. -*/ - -package promtsdb - -import ( - "testing" - - "github.com/nuclio/logger" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/stretchr/testify/suite" - "github.com/v3io/v3io-tsdb/pkg/config" - "github.com/v3io/v3io-tsdb/pkg/utils" -) - -type testPromTsdbSuite struct { - suite.Suite - logger logger.Logger -} - -func (suite *testPromTsdbSuite) TestMatch2filterEmpty() { - - name, filter, aggr := match2filter(nil, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterEqual() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "field", Value: "literal"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("field=='literal'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterMultiple() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "field1", Value: "literal1"}, - {Type: labels.MatchNotEqual, Name: "field2", Value: "literal2"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal("field1=='literal1' and field2!='literal2'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterMultipleWithName() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchEqual, Name: "__name__", Value: "literal1"}, - {Type: labels.MatchNotEqual, Name: "field2", Value: "literal2"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("literal1", name) - suite.Require().Equal("field2!='literal2'", filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterRegex() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchRegexp, Name: "field", Value: ".*"}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal(`regexp_instr(field,'.*') == 0`, filter) - suite.Require().Equal("", aggr) -} - -func (suite *testPromTsdbSuite) TestMatch2filterRegexMultiple() { - - matchers := []*labels.Matcher{ - {Type: labels.MatchRegexp, Name: "field1", Value: ".*"}, - {Type: labels.MatchNotRegexp, Name: "field2", Value: "..."}, - } - name, filter, aggr := match2filter(matchers, suite.logger) - - suite.Require().Equal("", name) - suite.Require().Equal(`regexp_instr(field1,'.*') == 0 and regexp_instr(field2,'...') != 0`, filter) - suite.Require().Equal("", aggr) -} - -func TestPromTsdbSuite(t *testing.T) { - log, err := utils.NewLogger(config.DefaultLogLevel) - if err != nil { - t.Fatalf("Unable to initialize logger. Error: %v", err) - } - - testSuit := new(testPromTsdbSuite) - testSuit.logger = log - suite.Run(t, testSuit) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/README.md deleted file mode 100644 index 207b7b1d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/README.md +++ /dev/null @@ -1,21 +0,0 @@ -List of Dependencies ---- - -1 github.com/cespare/xxhash@569f7c8abf1f58d9043ab804d364483cb1c853b6 -2 github.com/cpuguy83/go-md2man@691ee98543af2f262f35fbb54bdd42f00b9b9cc5 -3 github.com/ghodss/yaml@c7ce16629ff4cd059ed96ed06419dd3856fd3577 -4 github.com/go-kit/kit@9890679578cab201bd981519c97365519193d1ce -5 github.com/go-logfmt/logfmt@390ab7935ee28ec6b286364bba9b4dd6410cb3d5 -6 github.com/nuclio/logger@ccc5ab971395c6eae9a743a678d7b1bcb8e70414 -7 github.com/nuclio/nuclio-sdk-go@f750b959d2f7ebec6ebd4bc6b5638307406a5888 -8 github.com/nuclio/nuclio-test-go@0ce6587f8e37fabf4fcacfec23545f0476a459e9 -9 github.com/nuclio/zap@4a2bd2f9ef28a241ed7e3a67afa4ee8a7f1fa1ed -10 github.com/pkg/errors@c059e472caf75dbe73903f6521a20abac245b17f -11 github.com/prometheus/common@c7de2306084e37d54b8be01f3541a8464345e9a5 -12 github.com/prometheus/prometheus@b75ec7e6ef3666695edfa7bc1d9fccd1fdaae82a -13 github.com/rcrowley/go-metrics@e2704e165165ec55d062f5919b4b29494e9fa790 -14 github.com/spf13/cobra@8d114be902bc9f08717804830a55c48378108a28 -15 github.com/spf13/pflag@298182f68c66c05229eb03ac171abe6e309ee79a -16 github.com/stretchr/testify@f35b8ab0b5a2cef36673838d662e249dd9c94686 -17 github.com/v3io/v3io-go-http@36f737b2e799f92019e40267e85f73a1dff37d09 -18 gopkg.in/yaml.v2@5420a8b6744d3b0345ab293f6fcba19c978f1183 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go deleted file mode 100644 index aa577163..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cespare/xxhash/xxhsum/xxhsum.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "fmt" - "io" - "os" - - "github.com/cespare/xxhash" -) - -func main() { - if contains(os.Args[1:], "-h") { - fmt.Fprintf(os.Stderr, `Usage: - %s [filenames] -If no filenames are provided or only - is given, input is read from stdin. -`, os.Args[0]) - os.Exit(1) - } - if len(os.Args) < 2 || len(os.Args) == 2 && string(os.Args[1]) == "-" { - printHash(os.Stdin, "-") - return - } - for _, path := range os.Args[1:] { - f, err := os.Open(path) - if err != nil { - fmt.Fprintln(os.Stderr, err) - continue - } - printHash(f, path) - f.Close() - } -} - -func contains(ss []string, s string) bool { - for _, s1 := range ss { - if s1 == s { - return true - } - } - return false -} - -func printHash(r io.Reader, name string) { - h := xxhash.New() - if _, err := io.Copy(h, r); err != nil { - fmt.Fprintln(os.Stderr, err) - return - } - fmt.Printf("%016x %s\n", h.Sum64(), name) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json deleted file mode 100644 index a5f83163..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/.gometalinter.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Vendor": true, - "Deadline": "2m", - "Sort": ["linter", "severity", "path", "line"], - "Enable": [ - "deadcode", - "errcheck", - "structcheck", - "unused", - "varcheck", - "unconvert", - "gofmt", - "goimports", - "golint", - "ineffassign", - "vet", - "goconst", - "megacheck" - ] -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile deleted file mode 100644 index 97bec828..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM golang:1.8 AS build -COPY . /go/src/github.com/cpuguy83/go-md2man -WORKDIR /go/src/github.com/cpuguy83/go-md2man -RUN CGO_ENABLED=0 go build - -FROM scratch -COPY --from=build /go/src/github.com/cpuguy83/go-md2man/go-md2man /go-md2man -ENTRYPOINT ["/go-md2man"] diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock deleted file mode 100644 index c793f305..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.lock +++ /dev/null @@ -1,21 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/russross/blackfriday" - packages = ["."] - revision = "cadec560ec52d93835bf2f15bd794700d3a2473b" - version = "v2.0.0" - -[[projects]] - branch = "master" - name = "github.com/shurcooL/sanitized_anchor_name" - packages = ["."] - revision = "86672fcb3f950f35f2e675df2240550f2a50762f" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "7e41574846e5cbae82c84bab5e2e655e842f4000964fcb68be48b2d2c55017f9" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml deleted file mode 100644 index 1ada6d87..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Gopkg.toml +++ /dev/null @@ -1,26 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/russross/blackfriday" - version = "2.0.0" diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile deleted file mode 100644 index 6e30faf8..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -check: - gometalinter --config .gometalinter.json ./... diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md deleted file mode 100644 index 29ed7c9e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/README.md +++ /dev/null @@ -1,21 +0,0 @@ -go-md2man -========= - -** Work in Progress ** -This still needs a lot of help to be complete, or even usable! - -Uses blackfriday to process markdown into man pages. - -### Usage - -./md2man -in /path/to/markdownfile.md -out /manfile/output/path - -### How to contribute - -We use [dep](https://github.com/golang/dep/) for vendoring Go packages. -See dep documentation for how to update. - -### TODO - -- Needs oh so much testing love -- Look into blackfriday's 2.0 API diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md deleted file mode 100644 index 16d1133a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/go-md2man.1.md +++ /dev/null @@ -1,23 +0,0 @@ -go-md2man 1 "January 2015" go-md2man "User Manual" -================================================== - -# NAME - go-md2man - Convert markdown files into manpages - -# SYNOPSIS - go-md2man -in=[/path/to/md/file] -out=[/path/to/output] - -# Description - go-md2man converts standard markdown formatted documents into manpages. It is - written purely in Go so as to reduce dependencies on 3rd party libs. - - By default, the input is stdin and the output is stdout. - -# Example - Convert the markdown file "go-md2man.1.md" into a manpage. - - go-md2man -in=go-md2man.1.md -out=go-md2man.1.out - -# HISTORY - January 2015, Originally compiled by Brian Goff( cpuguy83@gmail.com ) - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go deleted file mode 100644 index c35dd335..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "os" - - "github.com/cpuguy83/go-md2man/md2man" -) - -var inFilePath = flag.String("in", "", "Path to file to be processed (default: stdin)") -var outFilePath = flag.String("out", "", "Path to output processed file (default: stdout)") - -func main() { - var err error - flag.Parse() - - inFile := os.Stdin - if *inFilePath != "" { - inFile, err = os.Open(*inFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - } - defer inFile.Close() // nolint: errcheck - - doc, err := ioutil.ReadAll(inFile) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - out := md2man.Render(doc) - - outFile := os.Stdout - if *outFilePath != "" { - outFile, err = os.Create(*outFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - defer outFile.Close() // nolint: errcheck - } - _, err = outFile.Write(out) - if err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go index deaa27f7..af62279a 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go @@ -6,9 +6,15 @@ import ( // Render converts a markdown document into a roff formatted document. func Render(doc []byte) []byte { - renderer := NewRoffRenderer() + renderer := RoffRenderer(0) + extensions := 0 + extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS + extensions |= blackfriday.EXTENSION_TABLES + extensions |= blackfriday.EXTENSION_FENCED_CODE + extensions |= blackfriday.EXTENSION_AUTOLINK + extensions |= blackfriday.EXTENSION_SPACE_HEADERS + extensions |= blackfriday.EXTENSION_FOOTNOTES + extensions |= blackfriday.EXTENSION_TITLEBLOCK - return blackfriday.Run(doc, - []blackfriday.Option{blackfriday.WithRenderer(renderer), - blackfriday.WithExtensions(renderer.GetExtensions())}...) + return blackfriday.Markdown(doc, renderer, extensions) } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go index d8597cb3..8c29ec68 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/md2man/roff.go @@ -1,312 +1,252 @@ package md2man import ( + "bytes" "fmt" - "io" - "os" + "html" "strings" "github.com/russross/blackfriday" ) -// roffRenderer implements the blackfriday.Renderer interface for creating -// roff format (manpages) from markdown text type roffRenderer struct { - extensions blackfriday.Extensions - listCounters []int - firstHeader bool - defineTerm bool - listDepth int -} - -const ( - titleHeader = ".TH " - topLevelHeader = "\n\n.SH " - secondLevelHdr = "\n.SH " - otherHeader = "\n.SS " - crTag = "\n" - emphTag = "\\fI" - emphCloseTag = "\\fP" - strongTag = "\\fB" - strongCloseTag = "\\fP" - breakTag = "\n.br\n" - paraTag = "\n.PP\n" - hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n" - linkTag = "\n\\[la]" - linkCloseTag = "\\[ra]" - codespanTag = "\\fB\\fC" - codespanCloseTag = "\\fR" - codeTag = "\n.PP\n.RS\n\n.nf\n" - codeCloseTag = "\n.fi\n.RE\n" - quoteTag = "\n.PP\n.RS\n" - quoteCloseTag = "\n.RE\n" - listTag = "\n.RS\n" - listCloseTag = "\n.RE\n" - arglistTag = "\n.TP\n" - tableStart = "\n.TS\nallbox;\n" - tableEnd = ".TE\n" - tableCellStart = "T{\n" - tableCellEnd = "\nT}\n" -) + ListCounters []int +} -// NewRoffRenderer creates a new blackfriday Renderer for generating roff documents +// RoffRenderer creates a new blackfriday Renderer for generating roff documents // from markdown -func NewRoffRenderer() *roffRenderer { // nolint: golint - var extensions blackfriday.Extensions - - extensions |= blackfriday.NoIntraEmphasis - extensions |= blackfriday.Tables - extensions |= blackfriday.FencedCode - extensions |= blackfriday.SpaceHeadings - extensions |= blackfriday.Footnotes - extensions |= blackfriday.Titleblock - extensions |= blackfriday.DefinitionLists - return &roffRenderer{ - extensions: extensions, - } +func RoffRenderer(flags int) blackfriday.Renderer { + return &roffRenderer{} } -// GetExtensions returns the list of extensions used by this renderer implementation -func (r *roffRenderer) GetExtensions() blackfriday.Extensions { - return r.extensions +func (r *roffRenderer) GetFlags() int { + return 0 } -// RenderHeader handles outputting the header at document start -func (r *roffRenderer) RenderHeader(w io.Writer, ast *blackfriday.Node) { +func (r *roffRenderer) TitleBlock(out *bytes.Buffer, text []byte) { + out.WriteString(".TH ") + + splitText := bytes.Split(text, []byte("\n")) + for i, line := range splitText { + line = bytes.TrimPrefix(line, []byte("% ")) + if i == 0 { + line = bytes.Replace(line, []byte("("), []byte("\" \""), 1) + line = bytes.Replace(line, []byte(")"), []byte("\" \""), 1) + } + line = append([]byte("\""), line...) + line = append(line, []byte("\" ")...) + out.Write(line) + } + out.WriteString("\n") + // disable hyphenation - out(w, ".nh\n") + out.WriteString(".nh\n") + // disable justification (adjust text to left margin only) + out.WriteString(".ad l\n") } -// RenderFooter handles outputting the footer at the document end; the roff -// renderer has no footer information -func (r *roffRenderer) RenderFooter(w io.Writer, ast *blackfriday.Node) { +func (r *roffRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) { + out.WriteString("\n.PP\n.RS\n\n.nf\n") + escapeSpecialChars(out, text) + out.WriteString("\n.fi\n.RE\n") } -// RenderNode is called for each node in a markdown document; based on the node -// type the equivalent roff output is sent to the writer -func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus { +func (r *roffRenderer) BlockQuote(out *bytes.Buffer, text []byte) { + out.WriteString("\n.PP\n.RS\n") + out.Write(text) + out.WriteString("\n.RE\n") +} - var walkAction = blackfriday.GoToNext +func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) { // nolint: golint + out.Write(text) +} - switch node.Type { - case blackfriday.Text: - r.handleText(w, node, entering) - case blackfriday.Softbreak: - out(w, crTag) - case blackfriday.Hardbreak: - out(w, breakTag) - case blackfriday.Emph: - if entering { - out(w, emphTag) - } else { - out(w, emphCloseTag) - } - case blackfriday.Strong: - if entering { - out(w, strongTag) - } else { - out(w, strongCloseTag) - } - case blackfriday.Link: - if !entering { - out(w, linkTag+string(node.LinkData.Destination)+linkCloseTag) - } - case blackfriday.Image: - // ignore images - walkAction = blackfriday.SkipChildren - case blackfriday.Code: - out(w, codespanTag) - escapeSpecialChars(w, node.Literal) - out(w, codespanCloseTag) - case blackfriday.Document: - break - case blackfriday.Paragraph: - // roff .PP markers break lists - if r.listDepth > 0 { - return blackfriday.GoToNext - } - if entering { - out(w, paraTag) - } else { - out(w, crTag) - } - case blackfriday.BlockQuote: - if entering { - out(w, quoteTag) - } else { - out(w, quoteCloseTag) - } - case blackfriday.Heading: - r.handleHeading(w, node, entering) - case blackfriday.HorizontalRule: - out(w, hruleTag) - case blackfriday.List: - r.handleList(w, node, entering) - case blackfriday.Item: - r.handleItem(w, node, entering) - case blackfriday.CodeBlock: - out(w, codeTag) - escapeSpecialChars(w, node.Literal) - out(w, codeCloseTag) - case blackfriday.Table: - r.handleTable(w, node, entering) - case blackfriday.TableCell: - r.handleTableCell(w, node, entering) - case blackfriday.TableHead: - case blackfriday.TableBody: - case blackfriday.TableRow: - // no action as cell entries do all the nroff formatting - return blackfriday.GoToNext +func (r *roffRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) { + marker := out.Len() + + switch { + case marker == 0: + // This is the doc header + out.WriteString(".TH ") + case level == 1: + out.WriteString("\n\n.SH ") + case level == 2: + out.WriteString("\n.SH ") default: - fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String()) - } - return walkAction -} - -func (r *roffRenderer) handleText(w io.Writer, node *blackfriday.Node, entering bool) { - var ( - start, end string - ) - // handle special roff table cell text encapsulation - if node.Parent.Type == blackfriday.TableCell { - if len(node.Literal) > 30 { - start = tableCellStart - end = tableCellEnd - } else { - // end rows that aren't terminated by "tableCellEnd" with a cr if end of row - if node.Parent.Next == nil && !node.Parent.IsHeader { - end = crTag - } - } + out.WriteString("\n.SS ") } - out(w, start) - escapeSpecialChars(w, node.Literal) - out(w, end) -} - -func (r *roffRenderer) handleHeading(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - switch node.Level { - case 1: - if !r.firstHeader { - out(w, titleHeader) - r.firstHeader = true - break - } - out(w, topLevelHeader) - case 2: - out(w, secondLevelHdr) - default: - out(w, otherHeader) - } + + if !text() { + out.Truncate(marker) + return } } -func (r *roffRenderer) handleList(w io.Writer, node *blackfriday.Node, entering bool) { - openTag := listTag - closeTag := listCloseTag - if node.ListFlags&blackfriday.ListTypeDefinition != 0 { - // tags for definition lists handled within Item node - openTag = "" - closeTag = "" +func (r *roffRenderer) HRule(out *bytes.Buffer) { + out.WriteString("\n.ti 0\n\\l'\\n(.lu'\n") +} + +func (r *roffRenderer) List(out *bytes.Buffer, text func() bool, flags int) { + marker := out.Len() + r.ListCounters = append(r.ListCounters, 1) + out.WriteString("\n.RS\n") + if !text() { + out.Truncate(marker) + return } - if entering { - r.listDepth++ - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - r.listCounters = append(r.listCounters, 1) - } - out(w, openTag) + r.ListCounters = r.ListCounters[:len(r.ListCounters)-1] + out.WriteString("\n.RE\n") +} + +func (r *roffRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) { + if flags&blackfriday.LIST_TYPE_ORDERED != 0 { + out.WriteString(fmt.Sprintf(".IP \"%3d.\" 5\n", r.ListCounters[len(r.ListCounters)-1])) + r.ListCounters[len(r.ListCounters)-1]++ } else { - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - r.listCounters = r.listCounters[:len(r.listCounters)-1] - } - out(w, closeTag) - r.listDepth-- + out.WriteString(".IP \\(bu 2\n") + } + out.Write(text) + out.WriteString("\n") +} + +func (r *roffRenderer) Paragraph(out *bytes.Buffer, text func() bool) { + marker := out.Len() + out.WriteString("\n.PP\n") + if !text() { + out.Truncate(marker) + return + } + if marker != 0 { + out.WriteString("\n") } } -func (r *roffRenderer) handleItem(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - if node.ListFlags&blackfriday.ListTypeOrdered != 0 { - out(w, fmt.Sprintf(".IP \"%3d.\" 5\n", r.listCounters[len(r.listCounters)-1])) - r.listCounters[len(r.listCounters)-1]++ - } else if node.ListFlags&blackfriday.ListTypeDefinition != 0 { - // state machine for handling terms and following definitions - // since blackfriday does not distinguish them properly, nor - // does it seperate them into separate lists as it should - if !r.defineTerm { - out(w, arglistTag) - r.defineTerm = true - } else { - r.defineTerm = false - } - } else { - out(w, ".IP \\(bu 2\n") +func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { + out.WriteString("\n.TS\nallbox;\n") + + maxDelims := 0 + lines := strings.Split(strings.TrimRight(string(header), "\n")+"\n"+strings.TrimRight(string(body), "\n"), "\n") + for _, w := range lines { + curDelims := strings.Count(w, "\t") + if curDelims > maxDelims { + maxDelims = curDelims } - } else { - out(w, "\n") } + out.Write([]byte(strings.Repeat("l ", maxDelims+1) + "\n")) + out.Write([]byte(strings.Repeat("l ", maxDelims+1) + ".\n")) + out.Write(header) + if len(header) > 0 { + out.Write([]byte("\n")) + } + + out.Write(body) + out.WriteString("\n.TE\n") } -func (r *roffRenderer) handleTable(w io.Writer, node *blackfriday.Node, entering bool) { - if entering { - out(w, tableStart) - //call walker to count cells (and rows?) so format section can be produced - columns := countColumns(node) - out(w, strings.Repeat("l ", columns)+"\n") - out(w, strings.Repeat("l ", columns)+".\n") - } else { - out(w, tableEnd) +func (r *roffRenderer) TableRow(out *bytes.Buffer, text []byte) { + if out.Len() > 0 { + out.WriteString("\n") } + out.Write(text) } -func (r *roffRenderer) handleTableCell(w io.Writer, node *blackfriday.Node, entering bool) { - var ( - start, end string - ) - if node.IsHeader { - start = codespanTag - end = codespanCloseTag +func (r *roffRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { + if out.Len() > 0 { + out.WriteString("\t") } - if entering { - if node.Prev != nil && node.Prev.Type == blackfriday.TableCell { - out(w, "\t"+start) - } else { - out(w, start) - } - } else { - // need to carriage return if we are at the end of the header row - if node.IsHeader && node.Next == nil { - end = end + crTag - } - out(w, end) + if len(text) == 0 { + text = []byte{' '} } + out.Write([]byte("\\fB\\fC" + string(text) + "\\fR")) } -// because roff format requires knowing the column count before outputting any table -// data we need to walk a table tree and count the columns -func countColumns(node *blackfriday.Node) int { - var columns int - - node.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { - switch node.Type { - case blackfriday.TableRow: - if !entering { - return blackfriday.Terminate - } - case blackfriday.TableCell: - if entering { - columns++ - } - default: - } - return blackfriday.GoToNext - }) - return columns +func (r *roffRenderer) TableCell(out *bytes.Buffer, text []byte, align int) { + if out.Len() > 0 { + out.WriteString("\t") + } + if len(text) > 30 { + text = append([]byte("T{\n"), text...) + text = append(text, []byte("\nT}")...) + } + if len(text) == 0 { + text = []byte{' '} + } + out.Write(text) +} + +func (r *roffRenderer) Footnotes(out *bytes.Buffer, text func() bool) { + +} + +func (r *roffRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { + +} + +func (r *roffRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { + out.WriteString("\n\\[la]") + out.Write(link) + out.WriteString("\\[ra]") +} + +func (r *roffRenderer) CodeSpan(out *bytes.Buffer, text []byte) { + out.WriteString("\\fB\\fC") + escapeSpecialChars(out, text) + out.WriteString("\\fR") +} + +func (r *roffRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\fB") + out.Write(text) + out.WriteString("\\fP") } -func out(w io.Writer, output string) { - io.WriteString(w, output) // nolint: errcheck +func (r *roffRenderer) Emphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\fI") + out.Write(text) + out.WriteString("\\fP") +} + +func (r *roffRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { +} + +func (r *roffRenderer) LineBreak(out *bytes.Buffer) { + out.WriteString("\n.br\n") +} + +func (r *roffRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { + out.Write(content) + r.AutoLink(out, link, 0) +} + +func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) { // nolint: golint + out.Write(tag) +} + +func (r *roffRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) { + out.WriteString("\\s+2") + out.Write(text) + out.WriteString("\\s-2") +} + +func (r *roffRenderer) StrikeThrough(out *bytes.Buffer, text []byte) { +} + +func (r *roffRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { + +} + +func (r *roffRenderer) Entity(out *bytes.Buffer, entity []byte) { + out.WriteString(html.UnescapeString(string(entity))) +} + +func (r *roffRenderer) NormalText(out *bytes.Buffer, text []byte) { + escapeSpecialChars(out, text) +} + +func (r *roffRenderer) DocumentHeader(out *bytes.Buffer) { +} + +func (r *roffRenderer) DocumentFooter(out *bytes.Buffer) { } func needsBackslash(c byte) bool { @@ -318,11 +258,11 @@ func needsBackslash(c byte) bool { return false } -func escapeSpecialChars(w io.Writer, text []byte) { +func escapeSpecialChars(out *bytes.Buffer, text []byte) { for i := 0; i < len(text); i++ { // escape initial apostrophe or period if len(text) >= 1 && (text[0] == '\'' || text[0] == '.') { - out(w, "\\&") + out.WriteString("\\&") } // directly copy normal characters @@ -332,14 +272,14 @@ func escapeSpecialChars(w io.Writer, text []byte) { i++ } if i > org { - w.Write(text[org:i]) // nolint: errcheck + out.Write(text[org:i]) } // escape a character if i >= len(text) { break } - - w.Write([]byte{'\\', text[i]}) // nolint: errcheck + out.WriteByte('\\') + out.WriteByte(text[i]) } } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools deleted file mode 100755 index 8efe701e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/setup/dev-tools +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -eu -o pipefail - -go get -u github.com/alecthomas/gometalinter -gometalinter --install >/dev/null -go get -u github.com/golang/dep/cmd/dep diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor deleted file mode 100755 index ef29b4cd..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/script/validate/vendor +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -dep ensure - -DIFF_PATH="vendor/" -DIFF=$(git status --porcelain -- "$DIFF_PATH") - -if [ "$DIFF" ]; then - echo - echo "These files were modified:" - echo - echo "$DIFF" - echo - exit 1 -else - echo "$DIFF_PATH is correct" -fi diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md deleted file mode 100644 index 2e0db355..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/README.md +++ /dev/null @@ -1,283 +0,0 @@ -Blackfriday [![Build Status](https://travis-ci.org/russross/blackfriday.svg?branch=master)](https://travis-ci.org/russross/blackfriday) -=========== - -Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It -is paranoid about its input (so you can safely feed it user-supplied -data), it is fast, it supports common extensions (tables, smart -punctuation substitutions, etc.), and it is safe for all utf-8 -(unicode) input. - -HTML output is currently supported, along with Smartypants -extensions. - -It started as a translation from C of [Sundown][3]. - - -Installation ------------- - -Blackfriday is compatible with any modern Go release. With Go 1.7 and git -installed: - - go get gopkg.in/russross/blackfriday.v2 - -will download, compile, and install the package into your `$GOPATH` -directory hierarchy. Alternatively, you can achieve the same if you -import it into a project: - - import "gopkg.in/russross/blackfriday.v2" - -and `go get` without parameters. - - -Versions --------- - -Currently maintained and recommended version of Blackfriday is `v2`. It's being -developed on its own branch: https://github.com/russross/blackfriday/v2. You -should install and import it via [gopkg.in][6] at -`gopkg.in/russross/blackfriday.v2`. - -Version 2 offers a number of improvements over v1: - -* Cleaned up API -* A separate call to [`Parse`][4], which produces an abstract syntax tree for - the document -* Latest bug fixes -* Flexibility to easily add your own rendering extensions - -Potential drawbacks: - -* Our benchmarks show v2 to be slightly slower than v1. Currently in the - ballpark of around 15%. -* API breakage. If you can't afford modifying your code to adhere to the new API - and don't care too much about the new features, v2 is probably not for you. -* Several bug fixes are trailing behind and still need to be forward-ported to - v2. See issue [#348](https://github.com/russross/blackfriday/issues/348) for - tracking. - -Usage ------ - -For the most sensible markdown processing, it is as simple as getting your input -into a byte slice and calling: - -```go -output := blackfriday.Run(input) -``` - -Your input will be parsed and the output rendered with a set of most popular -extensions enabled. If you want the most basic feature set, corresponding with -the bare Markdown specification, use: - -```go -output := blackfriday.Run(input, blackfriday.WithNoExtensions()) -``` - -### Sanitize untrusted content - -Blackfriday itself does nothing to protect against malicious content. If you are -dealing with user-supplied markdown, we recommend running Blackfriday's output -through HTML sanitizer such as [Bluemonday][5]. - -Here's an example of simple usage of Blackfriday together with Bluemonday: - -```go -import ( - "github.com/microcosm-cc/bluemonday" - "github.com/russross/blackfriday" -) - -// ... -unsafe := blackfriday.Run(input) -html := bluemonday.UGCPolicy().SanitizeBytes(unsafe) -``` - -### Custom options - -If you want to customize the set of options, use `blackfriday.WithExtensions`, -`blackfriday.WithRenderer` and `blackfriday.WithRefOverride`. - -You can also check out `blackfriday-tool` for a more complete example -of how to use it. Download and install it using: - - go get github.com/russross/blackfriday-tool - -This is a simple command-line tool that allows you to process a -markdown file using a standalone program. You can also browse the -source directly on github if you are just looking for some example -code: - -* - -Note that if you have not already done so, installing -`blackfriday-tool` will be sufficient to download and install -blackfriday in addition to the tool itself. The tool binary will be -installed in `$GOPATH/bin`. This is a statically-linked binary that -can be copied to wherever you need it without worrying about -dependencies and library versions. - - -Features --------- - -All features of Sundown are supported, including: - -* **Compatibility**. The Markdown v1.0.3 test suite passes with - the `--tidy` option. Without `--tidy`, the differences are - mostly in whitespace and entity escaping, where blackfriday is - more consistent and cleaner. - -* **Common extensions**, including table support, fenced code - blocks, autolinks, strikethroughs, non-strict emphasis, etc. - -* **Safety**. Blackfriday is paranoid when parsing, making it safe - to feed untrusted user input without fear of bad things - happening. The test suite stress tests this and there are no - known inputs that make it crash. If you find one, please let me - know and send me the input that does it. - - NOTE: "safety" in this context means *runtime safety only*. In order to - protect yourself against JavaScript injection in untrusted content, see - [this example](https://github.com/russross/blackfriday#sanitize-untrusted-content). - -* **Fast processing**. It is fast enough to render on-demand in - most web applications without having to cache the output. - -* **Thread safety**. You can run multiple parsers in different - goroutines without ill effect. There is no dependence on global - shared state. - -* **Minimal dependencies**. Blackfriday only depends on standard - library packages in Go. The source code is pretty - self-contained, so it is easy to add to any project, including - Google App Engine projects. - -* **Standards compliant**. Output successfully validates using the - W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional. - - -Extensions ----------- - -In addition to the standard markdown syntax, this package -implements the following extensions: - -* **Intra-word emphasis supression**. The `_` character is - commonly used inside words when discussing code, so having - markdown interpret it as an emphasis command is usually the - wrong thing. Blackfriday lets you treat all emphasis markers as - normal characters when they occur inside a word. - -* **Tables**. Tables can be created by drawing them in the input - using a simple syntax: - - ``` - Name | Age - --------|------ - Bob | 27 - Alice | 23 - ``` - -* **Fenced code blocks**. In addition to the normal 4-space - indentation to mark code blocks, you can explicitly mark them - and supply a language (to make syntax highlighting simple). Just - mark it like this: - - ```go - func getTrue() bool { - return true - } - ``` - - You can use 3 or more backticks to mark the beginning of the - block, and the same number to mark the end of the block. - -* **Definition lists**. A simple definition list is made of a single-line - term followed by a colon and the definition for that term. - - Cat - : Fluffy animal everyone likes - - Internet - : Vector of transmission for pictures of cats - - Terms must be separated from the previous definition by a blank line. - -* **Footnotes**. A marker in the text that will become a superscript number; - a footnote definition that will be placed in a list of footnotes at the - end of the document. A footnote looks like this: - - This is a footnote.[^1] - - [^1]: the footnote text. - -* **Autolinking**. Blackfriday can find URLs that have not been - explicitly marked as links and turn them into links. - -* **Strikethrough**. Use two tildes (`~~`) to mark text that - should be crossed out. - -* **Hard line breaks**. With this extension enabled newlines in the input - translate into line breaks in the output. This extension is off by default. - -* **Smart quotes**. Smartypants-style punctuation substitution is - supported, turning normal double- and single-quote marks into - curly quotes, etc. - -* **LaTeX-style dash parsing** is an additional option, where `--` - is translated into `–`, and `---` is translated into - `—`. This differs from most smartypants processors, which - turn a single hyphen into an ndash and a double hyphen into an - mdash. - -* **Smart fractions**, where anything that looks like a fraction - is translated into suitable HTML (instead of just a few special - cases like most smartypant processors). For example, `4/5` - becomes `45`, which renders as - 45. - - -Other renderers ---------------- - -Blackfriday is structured to allow alternative rendering engines. Here -are a few of note: - -* [github_flavored_markdown](https://godoc.org/github.com/shurcooL/github_flavored_markdown): - provides a GitHub Flavored Markdown renderer with fenced code block - highlighting, clickable heading anchor links. - - It's not customizable, and its goal is to produce HTML output - equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode), - except the rendering is performed locally. - -* [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt, - but for markdown. - -* [LaTeX output](https://bitbucket.org/ambrevar/blackfriday-latex): - renders output as LaTeX. - - -Todo ----- - -* More unit testing -* Improve unicode support. It does not understand all unicode - rules (about what constitutes a letter, a punctuation symbol, - etc.), so it may fail to detect word boundaries correctly in - some instances. It is safe on all utf-8 input. - - -License -------- - -[Blackfriday is distributed under the Simplified BSD License](LICENSE.txt) - - - [1]: https://daringfireball.net/projects/markdown/ "Markdown" - [2]: https://golang.org/ "Go Language" - [3]: https://github.com/vmg/sundown "Sundown" - [4]: https://godoc.org/gopkg.in/russross/blackfriday.v2#Parse "Parse func" - [5]: https://github.com/microcosm-cc/bluemonday "Bluemonday" - [6]: https://labix.org/gopkg.in "gopkg.in" diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go deleted file mode 100644 index d7da33f2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/block.go +++ /dev/null @@ -1,1549 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// Functions to parse block-level elements. -// - -package blackfriday - -import ( - "bytes" - "html" - "regexp" - - "github.com/shurcooL/sanitized_anchor_name" -) - -const ( - charEntity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});" - escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]" -) - -var ( - reBackslashOrAmp = regexp.MustCompile("[\\&]") - reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity) -) - -// Parse block-level data. -// Note: this function and many that it calls assume that -// the input buffer ends with a newline. -func (p *Markdown) block(data []byte) { - // this is called recursively: enforce a maximum depth - if p.nesting >= p.maxNesting { - return - } - p.nesting++ - - // parse out one block-level construct at a time - for len(data) > 0 { - // prefixed heading: - // - // # Heading 1 - // ## Heading 2 - // ... - // ###### Heading 6 - if p.isPrefixHeading(data) { - data = data[p.prefixHeading(data):] - continue - } - - // block of preformatted HTML: - // - //
    - // ... - //
    - if data[0] == '<' { - if i := p.html(data, true); i > 0 { - data = data[i:] - continue - } - } - - // title block - // - // % stuff - // % more stuff - // % even more stuff - if p.extensions&Titleblock != 0 { - if data[0] == '%' { - if i := p.titleBlock(data, true); i > 0 { - data = data[i:] - continue - } - } - } - - // blank lines. note: returns the # of bytes to skip - if i := p.isEmpty(data); i > 0 { - data = data[i:] - continue - } - - // indented code block: - // - // func max(a, b int) int { - // if a > b { - // return a - // } - // return b - // } - if p.codePrefix(data) > 0 { - data = data[p.code(data):] - continue - } - - // fenced code block: - // - // ``` go - // func fact(n int) int { - // if n <= 1 { - // return n - // } - // return n * fact(n-1) - // } - // ``` - if p.extensions&FencedCode != 0 { - if i := p.fencedCodeBlock(data, true); i > 0 { - data = data[i:] - continue - } - } - - // horizontal rule: - // - // ------ - // or - // ****** - // or - // ______ - if p.isHRule(data) { - p.addBlock(HorizontalRule, nil) - var i int - for i = 0; i < len(data) && data[i] != '\n'; i++ { - } - data = data[i:] - continue - } - - // block quote: - // - // > A big quote I found somewhere - // > on the web - if p.quotePrefix(data) > 0 { - data = data[p.quote(data):] - continue - } - - // table: - // - // Name | Age | Phone - // ------|-----|--------- - // Bob | 31 | 555-1234 - // Alice | 27 | 555-4321 - if p.extensions&Tables != 0 { - if i := p.table(data); i > 0 { - data = data[i:] - continue - } - } - - // an itemized/unordered list: - // - // * Item 1 - // * Item 2 - // - // also works with + or - - if p.uliPrefix(data) > 0 { - data = data[p.list(data, 0):] - continue - } - - // a numbered/ordered list: - // - // 1. Item 1 - // 2. Item 2 - if p.oliPrefix(data) > 0 { - data = data[p.list(data, ListTypeOrdered):] - continue - } - - // definition lists: - // - // Term 1 - // : Definition a - // : Definition b - // - // Term 2 - // : Definition c - if p.extensions&DefinitionLists != 0 { - if p.dliPrefix(data) > 0 { - data = data[p.list(data, ListTypeDefinition):] - continue - } - } - - // anything else must look like a normal paragraph - // note: this finds underlined headings, too - data = data[p.paragraph(data):] - } - - p.nesting-- -} - -func (p *Markdown) addBlock(typ NodeType, content []byte) *Node { - p.closeUnmatchedBlocks() - container := p.addChild(typ, 0) - container.content = content - return container -} - -func (p *Markdown) isPrefixHeading(data []byte) bool { - if data[0] != '#' { - return false - } - - if p.extensions&SpaceHeadings != 0 { - level := 0 - for level < 6 && level < len(data) && data[level] == '#' { - level++ - } - if level == len(data) || data[level] != ' ' { - return false - } - } - return true -} - -func (p *Markdown) prefixHeading(data []byte) int { - level := 0 - for level < 6 && level < len(data) && data[level] == '#' { - level++ - } - i := skipChar(data, level, ' ') - end := skipUntilChar(data, i, '\n') - skip := end - id := "" - if p.extensions&HeadingIDs != 0 { - j, k := 0, 0 - // find start/end of heading id - for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ { - } - for k = j + 1; k < end && data[k] != '}'; k++ { - } - // extract heading id iff found - if j < end && k < end { - id = string(data[j+2 : k]) - end = j - skip = k + 1 - for end > 0 && data[end-1] == ' ' { - end-- - } - } - } - for end > 0 && data[end-1] == '#' { - if isBackslashEscaped(data, end-1) { - break - } - end-- - } - for end > 0 && data[end-1] == ' ' { - end-- - } - if end > i { - if id == "" && p.extensions&AutoHeadingIDs != 0 { - id = sanitized_anchor_name.Create(string(data[i:end])) - } - block := p.addBlock(Heading, data[i:end]) - block.HeadingID = id - block.Level = level - } - return skip -} - -func (p *Markdown) isUnderlinedHeading(data []byte) int { - // test of level 1 heading - if data[0] == '=' { - i := skipChar(data, 1, '=') - i = skipChar(data, i, ' ') - if i < len(data) && data[i] == '\n' { - return 1 - } - return 0 - } - - // test of level 2 heading - if data[0] == '-' { - i := skipChar(data, 1, '-') - i = skipChar(data, i, ' ') - if i < len(data) && data[i] == '\n' { - return 2 - } - return 0 - } - - return 0 -} - -func (p *Markdown) titleBlock(data []byte, doRender bool) int { - if data[0] != '%' { - return 0 - } - splitData := bytes.Split(data, []byte("\n")) - var i int - for idx, b := range splitData { - if !bytes.HasPrefix(b, []byte("%")) { - i = idx // - 1 - break - } - } - - data = bytes.Join(splitData[0:i], []byte("\n")) - consumed := len(data) - data = bytes.TrimPrefix(data, []byte("% ")) - data = bytes.Replace(data, []byte("\n% "), []byte("\n"), -1) - block := p.addBlock(Heading, data) - block.Level = 1 - block.IsTitleblock = true - - return consumed -} - -func (p *Markdown) html(data []byte, doRender bool) int { - var i, j int - - // identify the opening tag - if data[0] != '<' { - return 0 - } - curtag, tagfound := p.htmlFindTag(data[1:]) - - // handle special cases - if !tagfound { - // check for an HTML comment - if size := p.htmlComment(data, doRender); size > 0 { - return size - } - - // check for an
    tag - if size := p.htmlHr(data, doRender); size > 0 { - return size - } - - // no special case recognized - return 0 - } - - // look for an unindented matching closing tag - // followed by a blank line - found := false - /* - closetag := []byte("\n") - j = len(curtag) + 1 - for !found { - // scan for a closing tag at the beginning of a line - if skip := bytes.Index(data[j:], closetag); skip >= 0 { - j += skip + len(closetag) - } else { - break - } - - // see if it is the only thing on the line - if skip := p.isEmpty(data[j:]); skip > 0 { - // see if it is followed by a blank line/eof - j += skip - if j >= len(data) { - found = true - i = j - } else { - if skip := p.isEmpty(data[j:]); skip > 0 { - j += skip - found = true - i = j - } - } - } - } - */ - - // if not found, try a second pass looking for indented match - // but not if tag is "ins" or "del" (following original Markdown.pl) - if !found && curtag != "ins" && curtag != "del" { - i = 1 - for i < len(data) { - i++ - for i < len(data) && !(data[i-1] == '<' && data[i] == '/') { - i++ - } - - if i+2+len(curtag) >= len(data) { - break - } - - j = p.htmlFindEnd(curtag, data[i-1:]) - - if j > 0 { - i += j - 1 - found = true - break - } - } - } - - if !found { - return 0 - } - - // the end of the block has been found - if doRender { - // trim newlines - end := i - for end > 0 && data[end-1] == '\n' { - end-- - } - finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end])) - } - - return i -} - -func finalizeHTMLBlock(block *Node) { - block.Literal = block.content - block.content = nil -} - -// HTML comment, lax form -func (p *Markdown) htmlComment(data []byte, doRender bool) int { - i := p.inlineHTMLComment(data) - // needs to end with a blank line - if j := p.isEmpty(data[i:]); j > 0 { - size := i + j - if doRender { - // trim trailing newlines - end := size - for end > 0 && data[end-1] == '\n' { - end-- - } - block := p.addBlock(HTMLBlock, data[:end]) - finalizeHTMLBlock(block) - } - return size - } - return 0 -} - -// HR, which is the only self-closing block tag considered -func (p *Markdown) htmlHr(data []byte, doRender bool) int { - if len(data) < 4 { - return 0 - } - if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') { - return 0 - } - if data[3] != ' ' && data[3] != '/' && data[3] != '>' { - // not an
    tag after all; at least not a valid one - return 0 - } - i := 3 - for i < len(data) && data[i] != '>' && data[i] != '\n' { - i++ - } - if i < len(data) && data[i] == '>' { - i++ - if j := p.isEmpty(data[i:]); j > 0 { - size := i + j - if doRender { - // trim newlines - end := size - for end > 0 && data[end-1] == '\n' { - end-- - } - finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end])) - } - return size - } - } - return 0 -} - -func (p *Markdown) htmlFindTag(data []byte) (string, bool) { - i := 0 - for i < len(data) && isalnum(data[i]) { - i++ - } - key := string(data[:i]) - if _, ok := blockTags[key]; ok { - return key, true - } - return "", false -} - -func (p *Markdown) htmlFindEnd(tag string, data []byte) int { - // assume data[0] == '<' && data[1] == '/' already tested - if tag == "hr" { - return 2 - } - // check if tag is a match - closetag := []byte("") - if !bytes.HasPrefix(data, closetag) { - return 0 - } - i := len(closetag) - - // check that the rest of the line is blank - skip := 0 - if skip = p.isEmpty(data[i:]); skip == 0 { - return 0 - } - i += skip - skip = 0 - - if i >= len(data) { - return i - } - - if p.extensions&LaxHTMLBlocks != 0 { - return i - } - if skip = p.isEmpty(data[i:]); skip == 0 { - // following line must be blank - return 0 - } - - return i + skip -} - -func (*Markdown) isEmpty(data []byte) int { - // it is okay to call isEmpty on an empty buffer - if len(data) == 0 { - return 0 - } - - var i int - for i = 0; i < len(data) && data[i] != '\n'; i++ { - if data[i] != ' ' && data[i] != '\t' { - return 0 - } - } - if i < len(data) && data[i] == '\n' { - i++ - } - return i -} - -func (*Markdown) isHRule(data []byte) bool { - i := 0 - - // skip up to three spaces - for i < 3 && data[i] == ' ' { - i++ - } - - // look at the hrule char - if data[i] != '*' && data[i] != '-' && data[i] != '_' { - return false - } - c := data[i] - - // the whole line must be the char or whitespace - n := 0 - for i < len(data) && data[i] != '\n' { - switch { - case data[i] == c: - n++ - case data[i] != ' ': - return false - } - i++ - } - - return n >= 3 -} - -// isFenceLine checks if there's a fence line (e.g., ``` or ``` go) at the beginning of data, -// and returns the end index if so, or 0 otherwise. It also returns the marker found. -// If syntax is not nil, it gets set to the syntax specified in the fence line. -func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker string) { - i, size := 0, 0 - - // skip up to three spaces - for i < len(data) && i < 3 && data[i] == ' ' { - i++ - } - - // check for the marker characters: ~ or ` - if i >= len(data) { - return 0, "" - } - if data[i] != '~' && data[i] != '`' { - return 0, "" - } - - c := data[i] - - // the whole line must be the same char or whitespace - for i < len(data) && data[i] == c { - size++ - i++ - } - - // the marker char must occur at least 3 times - if size < 3 { - return 0, "" - } - marker = string(data[i-size : i]) - - // if this is the end marker, it must match the beginning marker - if oldmarker != "" && marker != oldmarker { - return 0, "" - } - - // TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here - // into one, always get the syntax, and discard it if the caller doesn't care. - if syntax != nil { - syn := 0 - i = skipChar(data, i, ' ') - - if i >= len(data) { - if i == len(data) { - return i, marker - } - return 0, "" - } - - syntaxStart := i - - if data[i] == '{' { - i++ - syntaxStart++ - - for i < len(data) && data[i] != '}' && data[i] != '\n' { - syn++ - i++ - } - - if i >= len(data) || data[i] != '}' { - return 0, "" - } - - // strip all whitespace at the beginning and the end - // of the {} block - for syn > 0 && isspace(data[syntaxStart]) { - syntaxStart++ - syn-- - } - - for syn > 0 && isspace(data[syntaxStart+syn-1]) { - syn-- - } - - i++ - } else { - for i < len(data) && !isspace(data[i]) { - syn++ - i++ - } - } - - *syntax = string(data[syntaxStart : syntaxStart+syn]) - } - - i = skipChar(data, i, ' ') - if i >= len(data) || data[i] != '\n' { - if i == len(data) { - return i, marker - } - return 0, "" - } - return i + 1, marker // Take newline into account. -} - -// fencedCodeBlock returns the end index if data contains a fenced code block at the beginning, -// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects. -// If doRender is true, a final newline is mandatory to recognize the fenced code block. -func (p *Markdown) fencedCodeBlock(data []byte, doRender bool) int { - var syntax string - beg, marker := isFenceLine(data, &syntax, "") - if beg == 0 || beg >= len(data) { - return 0 - } - - var work bytes.Buffer - work.Write([]byte(syntax)) - work.WriteByte('\n') - - for { - // safe to assume beg < len(data) - - // check for the end of the code block - fenceEnd, _ := isFenceLine(data[beg:], nil, marker) - if fenceEnd != 0 { - beg += fenceEnd - break - } - - // copy the current line - end := skipUntilChar(data, beg, '\n') + 1 - - // did we reach the end of the buffer without a closing marker? - if end >= len(data) { - return 0 - } - - // verbatim copy to the working buffer - if doRender { - work.Write(data[beg:end]) - } - beg = end - } - - if doRender { - block := p.addBlock(CodeBlock, work.Bytes()) // TODO: get rid of temp buffer - block.IsFenced = true - finalizeCodeBlock(block) - } - - return beg -} - -func unescapeChar(str []byte) []byte { - if str[0] == '\\' { - return []byte{str[1]} - } - return []byte(html.UnescapeString(string(str))) -} - -func unescapeString(str []byte) []byte { - if reBackslashOrAmp.Match(str) { - return reEntityOrEscapedChar.ReplaceAllFunc(str, unescapeChar) - } - return str -} - -func finalizeCodeBlock(block *Node) { - if block.IsFenced { - newlinePos := bytes.IndexByte(block.content, '\n') - firstLine := block.content[:newlinePos] - rest := block.content[newlinePos+1:] - block.Info = unescapeString(bytes.Trim(firstLine, "\n")) - block.Literal = rest - } else { - block.Literal = block.content - } - block.content = nil -} - -func (p *Markdown) table(data []byte) int { - table := p.addBlock(Table, nil) - i, columns := p.tableHeader(data) - if i == 0 { - p.tip = table.Parent - table.Unlink() - return 0 - } - - p.addBlock(TableBody, nil) - - for i < len(data) { - pipes, rowStart := 0, i - for ; i < len(data) && data[i] != '\n'; i++ { - if data[i] == '|' { - pipes++ - } - } - - if pipes == 0 { - i = rowStart - break - } - - // include the newline in data sent to tableRow - if i < len(data) && data[i] == '\n' { - i++ - } - p.tableRow(data[rowStart:i], columns, false) - } - - return i -} - -// check if the specified position is preceded by an odd number of backslashes -func isBackslashEscaped(data []byte, i int) bool { - backslashes := 0 - for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' { - backslashes++ - } - return backslashes&1 == 1 -} - -func (p *Markdown) tableHeader(data []byte) (size int, columns []CellAlignFlags) { - i := 0 - colCount := 1 - for i = 0; i < len(data) && data[i] != '\n'; i++ { - if data[i] == '|' && !isBackslashEscaped(data, i) { - colCount++ - } - } - - // doesn't look like a table header - if colCount == 1 { - return - } - - // include the newline in the data sent to tableRow - j := i - if j < len(data) && data[j] == '\n' { - j++ - } - header := data[:j] - - // column count ignores pipes at beginning or end of line - if data[0] == '|' { - colCount-- - } - if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) { - colCount-- - } - - columns = make([]CellAlignFlags, colCount) - - // move on to the header underline - i++ - if i >= len(data) { - return - } - - if data[i] == '|' && !isBackslashEscaped(data, i) { - i++ - } - i = skipChar(data, i, ' ') - - // each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3 - // and trailing | optional on last column - col := 0 - for i < len(data) && data[i] != '\n' { - dashes := 0 - - if data[i] == ':' { - i++ - columns[col] |= TableAlignmentLeft - dashes++ - } - for i < len(data) && data[i] == '-' { - i++ - dashes++ - } - if i < len(data) && data[i] == ':' { - i++ - columns[col] |= TableAlignmentRight - dashes++ - } - for i < len(data) && data[i] == ' ' { - i++ - } - if i == len(data) { - return - } - // end of column test is messy - switch { - case dashes < 3: - // not a valid column - return - - case data[i] == '|' && !isBackslashEscaped(data, i): - // marker found, now skip past trailing whitespace - col++ - i++ - for i < len(data) && data[i] == ' ' { - i++ - } - - // trailing junk found after last column - if col >= colCount && i < len(data) && data[i] != '\n' { - return - } - - case (data[i] != '|' || isBackslashEscaped(data, i)) && col+1 < colCount: - // something else found where marker was required - return - - case data[i] == '\n': - // marker is optional for the last column - col++ - - default: - // trailing junk found after last column - return - } - } - if col != colCount { - return - } - - p.addBlock(TableHead, nil) - p.tableRow(header, columns, true) - size = i - if size < len(data) && data[size] == '\n' { - size++ - } - return -} - -func (p *Markdown) tableRow(data []byte, columns []CellAlignFlags, header bool) { - p.addBlock(TableRow, nil) - i, col := 0, 0 - - if data[i] == '|' && !isBackslashEscaped(data, i) { - i++ - } - - for col = 0; col < len(columns) && i < len(data); col++ { - for i < len(data) && data[i] == ' ' { - i++ - } - - cellStart := i - - for i < len(data) && (data[i] != '|' || isBackslashEscaped(data, i)) && data[i] != '\n' { - i++ - } - - cellEnd := i - - // skip the end-of-cell marker, possibly taking us past end of buffer - i++ - - for cellEnd > cellStart && cellEnd-1 < len(data) && data[cellEnd-1] == ' ' { - cellEnd-- - } - - cell := p.addBlock(TableCell, data[cellStart:cellEnd]) - cell.IsHeader = header - cell.Align = columns[col] - } - - // pad it out with empty columns to get the right number - for ; col < len(columns); col++ { - cell := p.addBlock(TableCell, nil) - cell.IsHeader = header - cell.Align = columns[col] - } - - // silently ignore rows with too many cells -} - -// returns blockquote prefix length -func (p *Markdown) quotePrefix(data []byte) int { - i := 0 - for i < 3 && i < len(data) && data[i] == ' ' { - i++ - } - if i < len(data) && data[i] == '>' { - if i+1 < len(data) && data[i+1] == ' ' { - return i + 2 - } - return i + 1 - } - return 0 -} - -// blockquote ends with at least one blank line -// followed by something without a blockquote prefix -func (p *Markdown) terminateBlockquote(data []byte, beg, end int) bool { - if p.isEmpty(data[beg:]) <= 0 { - return false - } - if end >= len(data) { - return true - } - return p.quotePrefix(data[end:]) == 0 && p.isEmpty(data[end:]) == 0 -} - -// parse a blockquote fragment -func (p *Markdown) quote(data []byte) int { - block := p.addBlock(BlockQuote, nil) - var raw bytes.Buffer - beg, end := 0, 0 - for beg < len(data) { - end = beg - // Step over whole lines, collecting them. While doing that, check for - // fenced code and if one's found, incorporate it altogether, - // irregardless of any contents inside it - for end < len(data) && data[end] != '\n' { - if p.extensions&FencedCode != 0 { - if i := p.fencedCodeBlock(data[end:], false); i > 0 { - // -1 to compensate for the extra end++ after the loop: - end += i - 1 - break - } - } - end++ - } - if end < len(data) && data[end] == '\n' { - end++ - } - if pre := p.quotePrefix(data[beg:]); pre > 0 { - // skip the prefix - beg += pre - } else if p.terminateBlockquote(data, beg, end) { - break - } - // this line is part of the blockquote - raw.Write(data[beg:end]) - beg = end - } - p.block(raw.Bytes()) - p.finalize(block) - return end -} - -// returns prefix length for block code -func (p *Markdown) codePrefix(data []byte) int { - if len(data) >= 1 && data[0] == '\t' { - return 1 - } - if len(data) >= 4 && data[0] == ' ' && data[1] == ' ' && data[2] == ' ' && data[3] == ' ' { - return 4 - } - return 0 -} - -func (p *Markdown) code(data []byte) int { - var work bytes.Buffer - - i := 0 - for i < len(data) { - beg := i - for i < len(data) && data[i] != '\n' { - i++ - } - if i < len(data) && data[i] == '\n' { - i++ - } - - blankline := p.isEmpty(data[beg:i]) > 0 - if pre := p.codePrefix(data[beg:i]); pre > 0 { - beg += pre - } else if !blankline { - // non-empty, non-prefixed line breaks the pre - i = beg - break - } - - // verbatim copy to the working buffer - if blankline { - work.WriteByte('\n') - } else { - work.Write(data[beg:i]) - } - } - - // trim all the \n off the end of work - workbytes := work.Bytes() - eol := len(workbytes) - for eol > 0 && workbytes[eol-1] == '\n' { - eol-- - } - if eol != len(workbytes) { - work.Truncate(eol) - } - - work.WriteByte('\n') - - block := p.addBlock(CodeBlock, work.Bytes()) // TODO: get rid of temp buffer - block.IsFenced = false - finalizeCodeBlock(block) - - return i -} - -// returns unordered list item prefix -func (p *Markdown) uliPrefix(data []byte) int { - i := 0 - // start with up to 3 spaces - for i < len(data) && i < 3 && data[i] == ' ' { - i++ - } - if i >= len(data)-1 { - return 0 - } - // need one of {'*', '+', '-'} followed by a space or a tab - if (data[i] != '*' && data[i] != '+' && data[i] != '-') || - (data[i+1] != ' ' && data[i+1] != '\t') { - return 0 - } - return i + 2 -} - -// returns ordered list item prefix -func (p *Markdown) oliPrefix(data []byte) int { - i := 0 - - // start with up to 3 spaces - for i < 3 && i < len(data) && data[i] == ' ' { - i++ - } - - // count the digits - start := i - for i < len(data) && data[i] >= '0' && data[i] <= '9' { - i++ - } - if start == i || i >= len(data)-1 { - return 0 - } - - // we need >= 1 digits followed by a dot and a space or a tab - if data[i] != '.' || !(data[i+1] == ' ' || data[i+1] == '\t') { - return 0 - } - return i + 2 -} - -// returns definition list item prefix -func (p *Markdown) dliPrefix(data []byte) int { - if len(data) < 2 { - return 0 - } - i := 0 - // need a ':' followed by a space or a tab - if data[i] != ':' || !(data[i+1] == ' ' || data[i+1] == '\t') { - return 0 - } - for i < len(data) && data[i] == ' ' { - i++ - } - return i + 2 -} - -// parse ordered or unordered list block -func (p *Markdown) list(data []byte, flags ListType) int { - i := 0 - flags |= ListItemBeginningOfList - block := p.addBlock(List, nil) - block.ListFlags = flags - block.Tight = true - - for i < len(data) { - skip := p.listItem(data[i:], &flags) - if flags&ListItemContainsBlock != 0 { - block.ListData.Tight = false - } - i += skip - if skip == 0 || flags&ListItemEndOfList != 0 { - break - } - flags &= ^ListItemBeginningOfList - } - - above := block.Parent - finalizeList(block) - p.tip = above - return i -} - -// Returns true if block ends with a blank line, descending if needed -// into lists and sublists. -func endsWithBlankLine(block *Node) bool { - // TODO: figure this out. Always false now. - for block != nil { - //if block.lastLineBlank { - //return true - //} - t := block.Type - if t == List || t == Item { - block = block.LastChild - } else { - break - } - } - return false -} - -func finalizeList(block *Node) { - block.open = false - item := block.FirstChild - for item != nil { - // check for non-final list item ending with blank line: - if endsWithBlankLine(item) && item.Next != nil { - block.ListData.Tight = false - break - } - // recurse into children of list item, to see if there are spaces - // between any of them: - subItem := item.FirstChild - for subItem != nil { - if endsWithBlankLine(subItem) && (item.Next != nil || subItem.Next != nil) { - block.ListData.Tight = false - break - } - subItem = subItem.Next - } - item = item.Next - } -} - -// Parse a single list item. -// Assumes initial prefix is already removed if this is a sublist. -func (p *Markdown) listItem(data []byte, flags *ListType) int { - // keep track of the indentation of the first line - itemIndent := 0 - if data[0] == '\t' { - itemIndent += 4 - } else { - for itemIndent < 3 && data[itemIndent] == ' ' { - itemIndent++ - } - } - - var bulletChar byte = '*' - i := p.uliPrefix(data) - if i == 0 { - i = p.oliPrefix(data) - } else { - bulletChar = data[i-2] - } - if i == 0 { - i = p.dliPrefix(data) - // reset definition term flag - if i > 0 { - *flags &= ^ListTypeTerm - } - } - if i == 0 { - // if in definition list, set term flag and continue - if *flags&ListTypeDefinition != 0 { - *flags |= ListTypeTerm - } else { - return 0 - } - } - - // skip leading whitespace on first line - for i < len(data) && data[i] == ' ' { - i++ - } - - // find the end of the line - line := i - for i > 0 && i < len(data) && data[i-1] != '\n' { - i++ - } - - // get working buffer - var raw bytes.Buffer - - // put the first line into the working buffer - raw.Write(data[line:i]) - line = i - - // process the following lines - containsBlankLine := false - sublist := 0 - -gatherlines: - for line < len(data) { - i++ - - // find the end of this line - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // if it is an empty line, guess that it is part of this item - // and move on to the next line - if p.isEmpty(data[line:i]) > 0 { - containsBlankLine = true - line = i - continue - } - - // calculate the indentation - indent := 0 - indentIndex := 0 - if data[line] == '\t' { - indentIndex++ - indent += 4 - } else { - for indent < 4 && line+indent < i && data[line+indent] == ' ' { - indent++ - indentIndex++ - } - } - - chunk := data[line+indentIndex : i] - - // evaluate how this line fits in - switch { - // is this a nested list item? - case (p.uliPrefix(chunk) > 0 && !p.isHRule(chunk)) || - p.oliPrefix(chunk) > 0 || - p.dliPrefix(chunk) > 0: - - if containsBlankLine { - *flags |= ListItemContainsBlock - } - - // to be a nested list, it must be indented more - // if not, it is the next item in the same list - if indent <= itemIndent { - break gatherlines - } - - // is this the first item in the nested list? - if sublist == 0 { - sublist = raw.Len() - } - - // is this a nested prefix heading? - case p.isPrefixHeading(chunk): - // if the heading is not indented, it is not nested in the list - // and thus ends the list - if containsBlankLine && indent < 4 { - *flags |= ListItemEndOfList - break gatherlines - } - *flags |= ListItemContainsBlock - - // anything following an empty line is only part - // of this item if it is indented 4 spaces - // (regardless of the indentation of the beginning of the item) - case containsBlankLine && indent < 4: - if *flags&ListTypeDefinition != 0 && i < len(data)-1 { - // is the next item still a part of this list? - next := i - for next < len(data) && data[next] != '\n' { - next++ - } - for next < len(data)-1 && data[next] == '\n' { - next++ - } - if i < len(data)-1 && data[i] != ':' && data[next] != ':' { - *flags |= ListItemEndOfList - } - } else { - *flags |= ListItemEndOfList - } - break gatherlines - - // a blank line means this should be parsed as a block - case containsBlankLine: - raw.WriteByte('\n') - *flags |= ListItemContainsBlock - } - - // if this line was preceded by one or more blanks, - // re-introduce the blank into the buffer - if containsBlankLine { - containsBlankLine = false - raw.WriteByte('\n') - } - - // add the line into the working buffer without prefix - raw.Write(data[line+indentIndex : i]) - - line = i - } - - rawBytes := raw.Bytes() - - block := p.addBlock(Item, nil) - block.ListFlags = *flags - block.Tight = false - block.BulletChar = bulletChar - block.Delimiter = '.' // Only '.' is possible in Markdown, but ')' will also be possible in CommonMark - - // render the contents of the list item - if *flags&ListItemContainsBlock != 0 && *flags&ListTypeTerm == 0 { - // intermediate render of block item, except for definition term - if sublist > 0 { - p.block(rawBytes[:sublist]) - p.block(rawBytes[sublist:]) - } else { - p.block(rawBytes) - } - } else { - // intermediate render of inline item - if sublist > 0 { - child := p.addChild(Paragraph, 0) - child.content = rawBytes[:sublist] - p.block(rawBytes[sublist:]) - } else { - child := p.addChild(Paragraph, 0) - child.content = rawBytes - } - } - return line -} - -// render a single paragraph that has already been parsed out -func (p *Markdown) renderParagraph(data []byte) { - if len(data) == 0 { - return - } - - // trim leading spaces - beg := 0 - for data[beg] == ' ' { - beg++ - } - - end := len(data) - // trim trailing newline - if data[len(data)-1] == '\n' { - end-- - } - - // trim trailing spaces - for end > beg && data[end-1] == ' ' { - end-- - } - - p.addBlock(Paragraph, data[beg:end]) -} - -func (p *Markdown) paragraph(data []byte) int { - // prev: index of 1st char of previous line - // line: index of 1st char of current line - // i: index of cursor/end of current line - var prev, line, i int - tabSize := TabSizeDefault - if p.extensions&TabSizeEight != 0 { - tabSize = TabSizeDouble - } - // keep going until we find something to mark the end of the paragraph - for i < len(data) { - // mark the beginning of the current line - prev = line - current := data[i:] - line = i - - // did we find a reference or a footnote? If so, end a paragraph - // preceding it and report that we have consumed up to the end of that - // reference: - if refEnd := isReference(p, current, tabSize); refEnd > 0 { - p.renderParagraph(data[:i]) - return i + refEnd - } - - // did we find a blank line marking the end of the paragraph? - if n := p.isEmpty(current); n > 0 { - // did this blank line followed by a definition list item? - if p.extensions&DefinitionLists != 0 { - if i < len(data)-1 && data[i+1] == ':' { - return p.list(data[prev:], ListTypeDefinition) - } - } - - p.renderParagraph(data[:i]) - return i + n - } - - // an underline under some text marks a heading, so our paragraph ended on prev line - if i > 0 { - if level := p.isUnderlinedHeading(current); level > 0 { - // render the paragraph - p.renderParagraph(data[:prev]) - - // ignore leading and trailing whitespace - eol := i - 1 - for prev < eol && data[prev] == ' ' { - prev++ - } - for eol > prev && data[eol-1] == ' ' { - eol-- - } - - id := "" - if p.extensions&AutoHeadingIDs != 0 { - id = sanitized_anchor_name.Create(string(data[prev:eol])) - } - - block := p.addBlock(Heading, data[prev:eol]) - block.Level = level - block.HeadingID = id - - // find the end of the underline - for i < len(data) && data[i] != '\n' { - i++ - } - return i - } - } - - // if the next line starts a block of HTML, then the paragraph ends here - if p.extensions&LaxHTMLBlocks != 0 { - if data[i] == '<' && p.html(current, false) > 0 { - // rewind to before the HTML block - p.renderParagraph(data[:i]) - return i - } - } - - // if there's a prefixed heading or a horizontal rule after this, paragraph is over - if p.isPrefixHeading(current) || p.isHRule(current) { - p.renderParagraph(data[:i]) - return i - } - - // if there's a fenced code block, paragraph is over - if p.extensions&FencedCode != 0 { - if p.fencedCodeBlock(current, false) > 0 { - p.renderParagraph(data[:i]) - return i - } - } - - // if there's a definition list item, prev line is a definition term - if p.extensions&DefinitionLists != 0 { - if p.dliPrefix(current) != 0 { - ret := p.list(data[prev:], ListTypeDefinition) - return ret - } - } - - // if there's a list after this, paragraph is over - if p.extensions&NoEmptyLineBeforeBlock != 0 { - if p.uliPrefix(current) != 0 || - p.oliPrefix(current) != 0 || - p.quotePrefix(current) != 0 || - p.codePrefix(current) != 0 { - p.renderParagraph(data[:i]) - return i - } - } - - // otherwise, scan to the beginning of the next line - nl := bytes.IndexByte(data[i:], '\n') - if nl >= 0 { - i += nl + 1 - } else { - i += len(data[i:]) - } - } - - p.renderParagraph(data[:i]) - return i -} - -func skipChar(data []byte, start int, char byte) int { - i := start - for i < len(data) && data[i] == char { - i++ - } - return i -} - -func skipUntilChar(text []byte, start int, char byte) int { - i := start - for i < len(text) && text[i] != char { - i++ - } - return i -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go deleted file mode 100644 index 5b3fa987..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Package blackfriday is a markdown processor. -// -// It translates plain text with simple formatting rules into an AST, which can -// then be further processed to HTML (provided by Blackfriday itself) or other -// formats (provided by the community). -// -// The simplest way to invoke Blackfriday is to call the Run function. It will -// take a text input and produce a text output in HTML (or other format). -// -// A slightly more sophisticated way to use Blackfriday is to create a Markdown -// processor and to call Parse, which returns a syntax tree for the input -// document. You can leverage Blackfriday's parsing for content extraction from -// markdown documents. You can assign a custom renderer and set various options -// to the Markdown processor. -// -// If you're interested in calling Blackfriday from command line, see -// https://github.com/russross/blackfriday-tool. -package blackfriday diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go deleted file mode 100644 index 6385f27c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/esc.go +++ /dev/null @@ -1,34 +0,0 @@ -package blackfriday - -import ( - "html" - "io" -) - -var htmlEscaper = [256][]byte{ - '&': []byte("&"), - '<': []byte("<"), - '>': []byte(">"), - '"': []byte("""), -} - -func escapeHTML(w io.Writer, s []byte) { - var start, end int - for end < len(s) { - escSeq := htmlEscaper[s[end]] - if escSeq != nil { - w.Write(s[start:end]) - w.Write(escSeq) - start = end + 1 - } - end++ - } - if start < len(s) && end <= len(s) { - w.Write(s[start:end]) - } -} - -func escLink(w io.Writer, text []byte) { - unesc := html.UnescapeString(string(text)) - escapeHTML(w, []byte(unesc)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go deleted file mode 100644 index 25fb185e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/html.go +++ /dev/null @@ -1,940 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// -// HTML rendering backend -// -// - -package blackfriday - -import ( - "bytes" - "fmt" - "io" - "regexp" - "strings" -) - -// HTMLFlags control optional behavior of HTML renderer. -type HTMLFlags int - -// HTML renderer configuration options. -const ( - HTMLFlagsNone HTMLFlags = 0 - SkipHTML HTMLFlags = 1 << iota // Skip preformatted HTML blocks - SkipImages // Skip embedded images - SkipLinks // Skip all links - Safelink // Only link to trusted protocols - NofollowLinks // Only link with rel="nofollow" - NoreferrerLinks // Only link with rel="noreferrer" - HrefTargetBlank // Add a blank target - CompletePage // Generate a complete HTML page - UseXHTML // Generate XHTML output instead of HTML - FootnoteReturnLinks // Generate a link at the end of a footnote to return to the source - Smartypants // Enable smart punctuation substitutions - SmartypantsFractions // Enable smart fractions (with Smartypants) - SmartypantsDashes // Enable smart dashes (with Smartypants) - SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants) - SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering - SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants) - TOC // Generate a table of contents -) - -var ( - htmlTagRe = regexp.MustCompile("(?i)^" + htmlTag) -) - -const ( - htmlTag = "(?:" + openTag + "|" + closeTag + "|" + htmlComment + "|" + - processingInstruction + "|" + declaration + "|" + cdata + ")" - closeTag = "]" - openTag = "<" + tagName + attribute + "*" + "\\s*/?>" - attribute = "(?:" + "\\s+" + attributeName + attributeValueSpec + "?)" - attributeValue = "(?:" + unquotedValue + "|" + singleQuotedValue + "|" + doubleQuotedValue + ")" - attributeValueSpec = "(?:" + "\\s*=" + "\\s*" + attributeValue + ")" - attributeName = "[a-zA-Z_:][a-zA-Z0-9:._-]*" - cdata = "" - declaration = "]*>" - doubleQuotedValue = "\"[^\"]*\"" - htmlComment = "|" - processingInstruction = "[<][?].*?[?][>]" - singleQuotedValue = "'[^']*'" - tagName = "[A-Za-z][A-Za-z0-9-]*" - unquotedValue = "[^\"'=<>`\\x00-\\x20]+" -) - -// HTMLRendererParameters is a collection of supplementary parameters tweaking -// the behavior of various parts of HTML renderer. -type HTMLRendererParameters struct { - // Prepend this text to each relative URL. - AbsolutePrefix string - // Add this text to each footnote anchor, to ensure uniqueness. - FootnoteAnchorPrefix string - // Show this text inside the tag for a footnote return link, if the - // HTML_FOOTNOTE_RETURN_LINKS flag is enabled. If blank, the string - // [return] is used. - FootnoteReturnLinkContents string - // If set, add this text to the front of each Heading ID, to ensure - // uniqueness. - HeadingIDPrefix string - // If set, add this text to the back of each Heading ID, to ensure uniqueness. - HeadingIDSuffix string - - Title string // Document title (used if CompletePage is set) - CSS string // Optional CSS file URL (used if CompletePage is set) - Icon string // Optional icon file URL (used if CompletePage is set) - - Flags HTMLFlags // Flags allow customizing this renderer's behavior -} - -// HTMLRenderer is a type that implements the Renderer interface for HTML output. -// -// Do not create this directly, instead use the NewHTMLRenderer function. -type HTMLRenderer struct { - HTMLRendererParameters - - closeTag string // how to end singleton tags: either " />" or ">" - - // Track heading IDs to prevent ID collision in a single generation. - headingIDs map[string]int - - lastOutputLen int - disableTags int - - sr *SPRenderer -} - -const ( - xhtmlClose = " />" - htmlClose = ">" -) - -// NewHTMLRenderer creates and configures an HTMLRenderer object, which -// satisfies the Renderer interface. -func NewHTMLRenderer(params HTMLRendererParameters) *HTMLRenderer { - // configure the rendering engine - closeTag := htmlClose - if params.Flags&UseXHTML != 0 { - closeTag = xhtmlClose - } - - if params.FootnoteReturnLinkContents == "" { - params.FootnoteReturnLinkContents = `[return]` - } - - return &HTMLRenderer{ - HTMLRendererParameters: params, - - closeTag: closeTag, - headingIDs: make(map[string]int), - - sr: NewSmartypantsRenderer(params.Flags), - } -} - -func isHTMLTag(tag []byte, tagname string) bool { - found, _ := findHTMLTagPos(tag, tagname) - return found -} - -// Look for a character, but ignore it when it's in any kind of quotes, it -// might be JavaScript -func skipUntilCharIgnoreQuotes(html []byte, start int, char byte) int { - inSingleQuote := false - inDoubleQuote := false - inGraveQuote := false - i := start - for i < len(html) { - switch { - case html[i] == char && !inSingleQuote && !inDoubleQuote && !inGraveQuote: - return i - case html[i] == '\'': - inSingleQuote = !inSingleQuote - case html[i] == '"': - inDoubleQuote = !inDoubleQuote - case html[i] == '`': - inGraveQuote = !inGraveQuote - } - i++ - } - return start -} - -func findHTMLTagPos(tag []byte, tagname string) (bool, int) { - i := 0 - if i < len(tag) && tag[0] != '<' { - return false, -1 - } - i++ - i = skipSpace(tag, i) - - if i < len(tag) && tag[i] == '/' { - i++ - } - - i = skipSpace(tag, i) - j := 0 - for ; i < len(tag); i, j = i+1, j+1 { - if j >= len(tagname) { - break - } - - if strings.ToLower(string(tag[i]))[0] != tagname[j] { - return false, -1 - } - } - - if i == len(tag) { - return false, -1 - } - - rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>') - if rightAngle >= i { - return true, rightAngle - } - - return false, -1 -} - -func skipSpace(tag []byte, i int) int { - for i < len(tag) && isspace(tag[i]) { - i++ - } - return i -} - -func isRelativeLink(link []byte) (yes bool) { - // a tag begin with '#' - if link[0] == '#' { - return true - } - - // link begin with '/' but not '//', the second maybe a protocol relative link - if len(link) >= 2 && link[0] == '/' && link[1] != '/' { - return true - } - - // only the root '/' - if len(link) == 1 && link[0] == '/' { - return true - } - - // current directory : begin with "./" - if bytes.HasPrefix(link, []byte("./")) { - return true - } - - // parent directory : begin with "../" - if bytes.HasPrefix(link, []byte("../")) { - return true - } - - return false -} - -func (r *HTMLRenderer) ensureUniqueHeadingID(id string) string { - for count, found := r.headingIDs[id]; found; count, found = r.headingIDs[id] { - tmp := fmt.Sprintf("%s-%d", id, count+1) - - if _, tmpFound := r.headingIDs[tmp]; !tmpFound { - r.headingIDs[id] = count + 1 - id = tmp - } else { - id = id + "-1" - } - } - - if _, found := r.headingIDs[id]; !found { - r.headingIDs[id] = 0 - } - - return id -} - -func (r *HTMLRenderer) addAbsPrefix(link []byte) []byte { - if r.AbsolutePrefix != "" && isRelativeLink(link) && link[0] != '.' { - newDest := r.AbsolutePrefix - if link[0] != '/' { - newDest += "/" - } - newDest += string(link) - return []byte(newDest) - } - return link -} - -func appendLinkAttrs(attrs []string, flags HTMLFlags, link []byte) []string { - if isRelativeLink(link) { - return attrs - } - val := []string{} - if flags&NofollowLinks != 0 { - val = append(val, "nofollow") - } - if flags&NoreferrerLinks != 0 { - val = append(val, "noreferrer") - } - if flags&HrefTargetBlank != 0 { - attrs = append(attrs, "target=\"_blank\"") - } - if len(val) == 0 { - return attrs - } - attr := fmt.Sprintf("rel=%q", strings.Join(val, " ")) - return append(attrs, attr) -} - -func isMailto(link []byte) bool { - return bytes.HasPrefix(link, []byte("mailto:")) -} - -func needSkipLink(flags HTMLFlags, dest []byte) bool { - if flags&SkipLinks != 0 { - return true - } - return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) -} - -func isSmartypantable(node *Node) bool { - pt := node.Parent.Type - return pt != Link && pt != CodeBlock && pt != Code -} - -func appendLanguageAttr(attrs []string, info []byte) []string { - if len(info) == 0 { - return attrs - } - endOfLang := bytes.IndexAny(info, "\t ") - if endOfLang < 0 { - endOfLang = len(info) - } - return append(attrs, fmt.Sprintf("class=\"language-%s\"", info[:endOfLang])) -} - -func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) { - w.Write(name) - if len(attrs) > 0 { - w.Write(spaceBytes) - w.Write([]byte(strings.Join(attrs, " "))) - } - w.Write(gtBytes) - r.lastOutputLen = 1 -} - -func footnoteRef(prefix string, node *Node) []byte { - urlFrag := prefix + string(slugify(node.Destination)) - anchor := fmt.Sprintf(`%d`, urlFrag, node.NoteID) - return []byte(fmt.Sprintf(`%s`, urlFrag, anchor)) -} - -func footnoteItem(prefix string, slug []byte) []byte { - return []byte(fmt.Sprintf(`
  • `, prefix, slug)) -} - -func footnoteReturnLink(prefix, returnLink string, slug []byte) []byte { - const format = ` %s` - return []byte(fmt.Sprintf(format, prefix, slug, returnLink)) -} - -func itemOpenCR(node *Node) bool { - if node.Prev == nil { - return false - } - ld := node.Parent.ListData - return !ld.Tight && ld.ListFlags&ListTypeDefinition == 0 -} - -func skipParagraphTags(node *Node) bool { - grandparent := node.Parent.Parent - if grandparent == nil || grandparent.Type != List { - return false - } - tightOrTerm := grandparent.Tight || node.Parent.ListFlags&ListTypeTerm != 0 - return grandparent.Type == List && tightOrTerm -} - -func cellAlignment(align CellAlignFlags) string { - switch align { - case TableAlignmentLeft: - return "left" - case TableAlignmentRight: - return "right" - case TableAlignmentCenter: - return "center" - default: - return "" - } -} - -func (r *HTMLRenderer) out(w io.Writer, text []byte) { - if r.disableTags > 0 { - w.Write(htmlTagRe.ReplaceAll(text, []byte{})) - } else { - w.Write(text) - } - r.lastOutputLen = len(text) -} - -func (r *HTMLRenderer) cr(w io.Writer) { - if r.lastOutputLen > 0 { - r.out(w, nlBytes) - } -} - -var ( - nlBytes = []byte{'\n'} - gtBytes = []byte{'>'} - spaceBytes = []byte{' '} -) - -var ( - brTag = []byte("
    ") - brXHTMLTag = []byte("
    ") - emTag = []byte("") - emCloseTag = []byte("") - strongTag = []byte("") - strongCloseTag = []byte("") - delTag = []byte("") - delCloseTag = []byte("") - ttTag = []byte("") - ttCloseTag = []byte("") - aTag = []byte("") - preTag = []byte("
    ")
    -	preCloseTag        = []byte("
    ") - codeTag = []byte("") - codeCloseTag = []byte("") - pTag = []byte("

    ") - pCloseTag = []byte("

    ") - blockquoteTag = []byte("
    ") - blockquoteCloseTag = []byte("
    ") - hrTag = []byte("
    ") - hrXHTMLTag = []byte("
    ") - ulTag = []byte("
      ") - ulCloseTag = []byte("
    ") - olTag = []byte("
      ") - olCloseTag = []byte("
    ") - dlTag = []byte("
    ") - dlCloseTag = []byte("
    ") - liTag = []byte("
  • ") - liCloseTag = []byte("
  • ") - ddTag = []byte("
    ") - ddCloseTag = []byte("
    ") - dtTag = []byte("
    ") - dtCloseTag = []byte("
    ") - tableTag = []byte("") - tableCloseTag = []byte("
    ") - tdTag = []byte("") - thTag = []byte("") - theadTag = []byte("") - theadCloseTag = []byte("") - tbodyTag = []byte("") - tbodyCloseTag = []byte("") - trTag = []byte("") - trCloseTag = []byte("") - h1Tag = []byte("") - h2Tag = []byte("") - h3Tag = []byte("") - h4Tag = []byte("") - h5Tag = []byte("") - h6Tag = []byte("") - - footnotesDivBytes = []byte("\n
    \n\n") - footnotesCloseDivBytes = []byte("\n
    \n") -) - -func headingTagsFromLevel(level int) ([]byte, []byte) { - switch level { - case 1: - return h1Tag, h1CloseTag - case 2: - return h2Tag, h2CloseTag - case 3: - return h3Tag, h3CloseTag - case 4: - return h4Tag, h4CloseTag - case 5: - return h5Tag, h5CloseTag - default: - return h6Tag, h6CloseTag - } -} - -func (r *HTMLRenderer) outHRTag(w io.Writer) { - if r.Flags&UseXHTML == 0 { - r.out(w, hrTag) - } else { - r.out(w, hrXHTMLTag) - } -} - -// RenderNode is a default renderer of a single node of a syntax tree. For -// block nodes it will be called twice: first time with entering=true, second -// time with entering=false, so that it could know when it's working on an open -// tag and when on close. It writes the result to w. -// -// The return value is a way to tell the calling walker to adjust its walk -// pattern: e.g. it can terminate the traversal by returning Terminate. Or it -// can ask the walker to skip a subtree of this node by returning SkipChildren. -// The typical behavior is to return GoToNext, which asks for the usual -// traversal to the next node. -func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkStatus { - attrs := []string{} - switch node.Type { - case Text: - if r.Flags&Smartypants != 0 { - var tmp bytes.Buffer - escapeHTML(&tmp, node.Literal) - r.sr.Process(w, tmp.Bytes()) - } else { - if node.Parent.Type == Link { - escLink(w, node.Literal) - } else { - escapeHTML(w, node.Literal) - } - } - case Softbreak: - r.cr(w) - // TODO: make it configurable via out(renderer.softbreak) - case Hardbreak: - if r.Flags&UseXHTML == 0 { - r.out(w, brTag) - } else { - r.out(w, brXHTMLTag) - } - r.cr(w) - case Emph: - if entering { - r.out(w, emTag) - } else { - r.out(w, emCloseTag) - } - case Strong: - if entering { - r.out(w, strongTag) - } else { - r.out(w, strongCloseTag) - } - case Del: - if entering { - r.out(w, delTag) - } else { - r.out(w, delCloseTag) - } - case HTMLSpan: - if r.Flags&SkipHTML != 0 { - break - } - r.out(w, node.Literal) - case Link: - // mark it but don't link it if it is not a safe link: no smartypants - dest := node.LinkData.Destination - if needSkipLink(r.Flags, dest) { - if entering { - r.out(w, ttTag) - } else { - r.out(w, ttCloseTag) - } - } else { - if entering { - dest = r.addAbsPrefix(dest) - var hrefBuf bytes.Buffer - hrefBuf.WriteString("href=\"") - escLink(&hrefBuf, dest) - hrefBuf.WriteByte('"') - attrs = append(attrs, hrefBuf.String()) - if node.NoteID != 0 { - r.out(w, footnoteRef(r.FootnoteAnchorPrefix, node)) - break - } - attrs = appendLinkAttrs(attrs, r.Flags, dest) - if len(node.LinkData.Title) > 0 { - var titleBuff bytes.Buffer - titleBuff.WriteString("title=\"") - escapeHTML(&titleBuff, node.LinkData.Title) - titleBuff.WriteByte('"') - attrs = append(attrs, titleBuff.String()) - } - r.tag(w, aTag, attrs) - } else { - if node.NoteID != 0 { - break - } - r.out(w, aCloseTag) - } - } - case Image: - if r.Flags&SkipImages != 0 { - return SkipChildren - } - if entering { - dest := node.LinkData.Destination - dest = r.addAbsPrefix(dest) - if r.disableTags == 0 { - //if options.safe && potentiallyUnsafe(dest) { - //out(w, ``)
-				//} else {
-				r.out(w, []byte(`<img src=`)) - } - } - case Code: - r.out(w, codeTag) - escapeHTML(w, node.Literal) - r.out(w, codeCloseTag) - case Document: - break - case Paragraph: - if skipParagraphTags(node) { - break - } - if entering { - // TODO: untangle this clusterfuck about when the newlines need - // to be added and when not. - if node.Prev != nil { - switch node.Prev.Type { - case HTMLBlock, List, Paragraph, Heading, CodeBlock, BlockQuote, HorizontalRule: - r.cr(w) - } - } - if node.Parent.Type == BlockQuote && node.Prev == nil { - r.cr(w) - } - r.out(w, pTag) - } else { - r.out(w, pCloseTag) - if !(node.Parent.Type == Item && node.Next == nil) { - r.cr(w) - } - } - case BlockQuote: - if entering { - r.cr(w) - r.out(w, blockquoteTag) - } else { - r.out(w, blockquoteCloseTag) - r.cr(w) - } - case HTMLBlock: - if r.Flags&SkipHTML != 0 { - break - } - r.cr(w) - r.out(w, node.Literal) - r.cr(w) - case Heading: - openTag, closeTag := headingTagsFromLevel(node.Level) - if entering { - if node.IsTitleblock { - attrs = append(attrs, `class="title"`) - } - if node.HeadingID != "" { - id := r.ensureUniqueHeadingID(node.HeadingID) - if r.HeadingIDPrefix != "" { - id = r.HeadingIDPrefix + id - } - if r.HeadingIDSuffix != "" { - id = id + r.HeadingIDSuffix - } - attrs = append(attrs, fmt.Sprintf(`id="%s"`, id)) - } - r.cr(w) - r.tag(w, openTag, attrs) - } else { - r.out(w, closeTag) - if !(node.Parent.Type == Item && node.Next == nil) { - r.cr(w) - } - } - case HorizontalRule: - r.cr(w) - r.outHRTag(w) - r.cr(w) - case List: - openTag := ulTag - closeTag := ulCloseTag - if node.ListFlags&ListTypeOrdered != 0 { - openTag = olTag - closeTag = olCloseTag - } - if node.ListFlags&ListTypeDefinition != 0 { - openTag = dlTag - closeTag = dlCloseTag - } - if entering { - if node.IsFootnotesList { - r.out(w, footnotesDivBytes) - r.outHRTag(w) - r.cr(w) - } - r.cr(w) - if node.Parent.Type == Item && node.Parent.Parent.Tight { - r.cr(w) - } - r.tag(w, openTag[:len(openTag)-1], attrs) - r.cr(w) - } else { - r.out(w, closeTag) - //cr(w) - //if node.parent.Type != Item { - // cr(w) - //} - if node.Parent.Type == Item && node.Next != nil { - r.cr(w) - } - if node.Parent.Type == Document || node.Parent.Type == BlockQuote { - r.cr(w) - } - if node.IsFootnotesList { - r.out(w, footnotesCloseDivBytes) - } - } - case Item: - openTag := liTag - closeTag := liCloseTag - if node.ListFlags&ListTypeDefinition != 0 { - openTag = ddTag - closeTag = ddCloseTag - } - if node.ListFlags&ListTypeTerm != 0 { - openTag = dtTag - closeTag = dtCloseTag - } - if entering { - if itemOpenCR(node) { - r.cr(w) - } - if node.ListData.RefLink != nil { - slug := slugify(node.ListData.RefLink) - r.out(w, footnoteItem(r.FootnoteAnchorPrefix, slug)) - break - } - r.out(w, openTag) - } else { - if node.ListData.RefLink != nil { - slug := slugify(node.ListData.RefLink) - if r.Flags&FootnoteReturnLinks != 0 { - r.out(w, footnoteReturnLink(r.FootnoteAnchorPrefix, r.FootnoteReturnLinkContents, slug)) - } - } - r.out(w, closeTag) - r.cr(w) - } - case CodeBlock: - attrs = appendLanguageAttr(attrs, node.Info) - r.cr(w) - r.out(w, preTag) - r.tag(w, codeTag[:len(codeTag)-1], attrs) - escapeHTML(w, node.Literal) - r.out(w, codeCloseTag) - r.out(w, preCloseTag) - if node.Parent.Type != Item { - r.cr(w) - } - case Table: - if entering { - r.cr(w) - r.out(w, tableTag) - } else { - r.out(w, tableCloseTag) - r.cr(w) - } - case TableCell: - openTag := tdTag - closeTag := tdCloseTag - if node.IsHeader { - openTag = thTag - closeTag = thCloseTag - } - if entering { - align := cellAlignment(node.Align) - if align != "" { - attrs = append(attrs, fmt.Sprintf(`align="%s"`, align)) - } - if node.Prev == nil { - r.cr(w) - } - r.tag(w, openTag, attrs) - } else { - r.out(w, closeTag) - r.cr(w) - } - case TableHead: - if entering { - r.cr(w) - r.out(w, theadTag) - } else { - r.out(w, theadCloseTag) - r.cr(w) - } - case TableBody: - if entering { - r.cr(w) - r.out(w, tbodyTag) - // XXX: this is to adhere to a rather silly test. Should fix test. - if node.FirstChild == nil { - r.cr(w) - } - } else { - r.out(w, tbodyCloseTag) - r.cr(w) - } - case TableRow: - if entering { - r.cr(w) - r.out(w, trTag) - } else { - r.out(w, trCloseTag) - r.cr(w) - } - default: - panic("Unknown node type " + node.Type.String()) - } - return GoToNext -} - -// RenderHeader writes HTML document preamble and TOC if requested. -func (r *HTMLRenderer) RenderHeader(w io.Writer, ast *Node) { - r.writeDocumentHeader(w) - if r.Flags&TOC != 0 { - r.writeTOC(w, ast) - } -} - -// RenderFooter writes HTML document footer. -func (r *HTMLRenderer) RenderFooter(w io.Writer, ast *Node) { - if r.Flags&CompletePage == 0 { - return - } - io.WriteString(w, "\n\n\n") -} - -func (r *HTMLRenderer) writeDocumentHeader(w io.Writer) { - if r.Flags&CompletePage == 0 { - return - } - ending := "" - if r.Flags&UseXHTML != 0 { - io.WriteString(w, "\n") - io.WriteString(w, "\n") - ending = " /" - } else { - io.WriteString(w, "\n") - io.WriteString(w, "\n") - } - io.WriteString(w, "\n") - io.WriteString(w, " ") - if r.Flags&Smartypants != 0 { - r.sr.Process(w, []byte(r.Title)) - } else { - escapeHTML(w, []byte(r.Title)) - } - io.WriteString(w, "\n") - io.WriteString(w, " \n") - io.WriteString(w, " \n") - if r.CSS != "" { - io.WriteString(w, " \n") - } - if r.Icon != "" { - io.WriteString(w, " \n") - } - io.WriteString(w, "\n") - io.WriteString(w, "\n\n") -} - -func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) { - buf := bytes.Buffer{} - - inHeading := false - tocLevel := 0 - headingCount := 0 - - ast.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Heading && !node.HeadingData.IsTitleblock { - inHeading = entering - if entering { - node.HeadingID = fmt.Sprintf("toc_%d", headingCount) - if node.Level == tocLevel { - buf.WriteString("\n\n
  • ") - } else if node.Level < tocLevel { - for node.Level < tocLevel { - tocLevel-- - buf.WriteString("
  • \n") - } - buf.WriteString("\n\n
  • ") - } else { - for node.Level > tocLevel { - tocLevel++ - buf.WriteString("\n") - } - - if buf.Len() > 0 { - io.WriteString(w, "\n") - } - r.lastOutputLen = buf.Len() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go deleted file mode 100644 index 3d633106..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/inline.go +++ /dev/null @@ -1,1214 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// Functions to parse inline elements. -// - -package blackfriday - -import ( - "bytes" - "regexp" - "strconv" -) - -var ( - urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+` - anchorRe = regexp.MustCompile(`^(]+")?\s?>` + urlRe + `<\/a>)`) - - // TODO: improve this regexp to catch all possible entities: - htmlEntityRe = regexp.MustCompile(`&[a-z]{2,5};`) -) - -// Functions to parse text within a block -// Each function returns the number of chars taken care of -// data is the complete block being rendered -// offset is the number of valid chars before the current cursor - -func (p *Markdown) inline(currBlock *Node, data []byte) { - // handlers might call us recursively: enforce a maximum depth - if p.nesting >= p.maxNesting || len(data) == 0 { - return - } - p.nesting++ - beg, end := 0, 0 - for end < len(data) { - handler := p.inlineCallback[data[end]] - if handler != nil { - if consumed, node := handler(p, data, end); consumed == 0 { - // No action from the callback. - end++ - } else { - // Copy inactive chars into the output. - currBlock.AppendChild(text(data[beg:end])) - if node != nil { - currBlock.AppendChild(node) - } - // Skip past whatever the callback used. - beg = end + consumed - end = beg - } - } else { - end++ - } - } - if beg < len(data) { - if data[end-1] == '\n' { - end-- - } - currBlock.AppendChild(text(data[beg:end])) - } - p.nesting-- -} - -// single and double emphasis parsing -func emphasis(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - c := data[0] - - if len(data) > 2 && data[1] != c { - // whitespace cannot follow an opening emphasis; - // strikethrough only takes two characters '~~' - if c == '~' || isspace(data[1]) { - return 0, nil - } - ret, node := helperEmphasis(p, data[1:], c) - if ret == 0 { - return 0, nil - } - - return ret + 1, node - } - - if len(data) > 3 && data[1] == c && data[2] != c { - if isspace(data[2]) { - return 0, nil - } - ret, node := helperDoubleEmphasis(p, data[2:], c) - if ret == 0 { - return 0, nil - } - - return ret + 2, node - } - - if len(data) > 4 && data[1] == c && data[2] == c && data[3] != c { - if c == '~' || isspace(data[3]) { - return 0, nil - } - ret, node := helperTripleEmphasis(p, data, 3, c) - if ret == 0 { - return 0, nil - } - - return ret + 3, node - } - - return 0, nil -} - -func codeSpan(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - nb := 0 - - // count the number of backticks in the delimiter - for nb < len(data) && data[nb] == '`' { - nb++ - } - - // find the next delimiter - i, end := 0, 0 - for end = nb; end < len(data) && i < nb; end++ { - if data[end] == '`' { - i++ - } else { - i = 0 - } - } - - // no matching delimiter? - if i < nb && end >= len(data) { - return 0, nil - } - - // trim outside whitespace - fBegin := nb - for fBegin < end && data[fBegin] == ' ' { - fBegin++ - } - - fEnd := end - nb - for fEnd > fBegin && data[fEnd-1] == ' ' { - fEnd-- - } - - // render the code span - if fBegin != fEnd { - code := NewNode(Code) - code.Literal = data[fBegin:fEnd] - return end, code - } - - return end, nil -} - -// newline preceded by two spaces becomes
    -func maybeLineBreak(p *Markdown, data []byte, offset int) (int, *Node) { - origOffset := offset - for offset < len(data) && data[offset] == ' ' { - offset++ - } - - if offset < len(data) && data[offset] == '\n' { - if offset-origOffset >= 2 { - return offset - origOffset + 1, NewNode(Hardbreak) - } - return offset - origOffset, nil - } - return 0, nil -} - -// newline without two spaces works when HardLineBreak is enabled -func lineBreak(p *Markdown, data []byte, offset int) (int, *Node) { - if p.extensions&HardLineBreak != 0 { - return 1, NewNode(Hardbreak) - } - return 0, nil -} - -type linkType int - -const ( - linkNormal linkType = iota - linkImg - linkDeferredFootnote - linkInlineFootnote -) - -func isReferenceStyleLink(data []byte, pos int, t linkType) bool { - if t == linkDeferredFootnote { - return false - } - return pos < len(data)-1 && data[pos] == '[' && data[pos+1] != '^' -} - -func maybeImage(p *Markdown, data []byte, offset int) (int, *Node) { - if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, data, offset) - } - return 0, nil -} - -func maybeInlineFootnote(p *Markdown, data []byte, offset int) (int, *Node) { - if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, data, offset) - } - return 0, nil -} - -// '[': parse a link or an image or a footnote -func link(p *Markdown, data []byte, offset int) (int, *Node) { - // no links allowed inside regular links, footnote, and deferred footnotes - if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') { - return 0, nil - } - - var t linkType - switch { - // special case: ![^text] == deferred footnote (that follows something with - // an exclamation point) - case p.extensions&Footnotes != 0 && len(data)-1 > offset && data[offset+1] == '^': - t = linkDeferredFootnote - // ![alt] == image - case offset >= 0 && data[offset] == '!': - t = linkImg - offset++ - // ^[text] == inline footnote - // [^refId] == deferred footnote - case p.extensions&Footnotes != 0: - if offset >= 0 && data[offset] == '^' { - t = linkInlineFootnote - offset++ - } else if len(data)-1 > offset && data[offset+1] == '^' { - t = linkDeferredFootnote - } - // [text] == regular link - default: - t = linkNormal - } - - data = data[offset:] - - var ( - i = 1 - noteID int - title, link, altContent []byte - textHasNl = false - ) - - if t == linkDeferredFootnote { - i++ - } - - // look for the matching closing bracket - for level := 1; level > 0 && i < len(data); i++ { - switch { - case data[i] == '\n': - textHasNl = true - - case data[i-1] == '\\': - continue - - case data[i] == '[': - level++ - - case data[i] == ']': - level-- - if level <= 0 { - i-- // compensate for extra i++ in for loop - } - } - } - - if i >= len(data) { - return 0, nil - } - - txtE := i - i++ - var footnoteNode *Node - - // skip any amount of whitespace or newline - // (this is much more lax than original markdown syntax) - for i < len(data) && isspace(data[i]) { - i++ - } - - // inline style link - switch { - case i < len(data) && data[i] == '(': - // skip initial whitespace - i++ - - for i < len(data) && isspace(data[i]) { - i++ - } - - linkB := i - - // look for link end: ' " ) - findlinkend: - for i < len(data) { - switch { - case data[i] == '\\': - i += 2 - - case data[i] == ')' || data[i] == '\'' || data[i] == '"': - break findlinkend - - default: - i++ - } - } - - if i >= len(data) { - return 0, nil - } - linkE := i - - // look for title end if present - titleB, titleE := 0, 0 - if data[i] == '\'' || data[i] == '"' { - i++ - titleB = i - - findtitleend: - for i < len(data) { - switch { - case data[i] == '\\': - i += 2 - - case data[i] == ')': - break findtitleend - - default: - i++ - } - } - - if i >= len(data) { - return 0, nil - } - - // skip whitespace after title - titleE = i - 1 - for titleE > titleB && isspace(data[titleE]) { - titleE-- - } - - // check for closing quote presence - if data[titleE] != '\'' && data[titleE] != '"' { - titleB, titleE = 0, 0 - linkE = i - } - } - - // remove whitespace at the end of the link - for linkE > linkB && isspace(data[linkE-1]) { - linkE-- - } - - // remove optional angle brackets around the link - if data[linkB] == '<' { - linkB++ - } - if data[linkE-1] == '>' { - linkE-- - } - - // build escaped link and title - if linkE > linkB { - link = data[linkB:linkE] - } - - if titleE > titleB { - title = data[titleB:titleE] - } - - i++ - - // reference style link - case isReferenceStyleLink(data, i, t): - var id []byte - altContentConsidered := false - - // look for the id - i++ - linkB := i - for i < len(data) && data[i] != ']' { - i++ - } - if i >= len(data) { - return 0, nil - } - linkE := i - - // find the reference - if linkB == linkE { - if textHasNl { - var b bytes.Buffer - - for j := 1; j < txtE; j++ { - switch { - case data[j] != '\n': - b.WriteByte(data[j]) - case data[j-1] != ' ': - b.WriteByte(' ') - } - } - - id = b.Bytes() - } else { - id = data[1:txtE] - altContentConsidered = true - } - } else { - id = data[linkB:linkE] - } - - // find the reference with matching id - lr, ok := p.getRef(string(id)) - if !ok { - return 0, nil - } - - // keep link and title from reference - link = lr.link - title = lr.title - if altContentConsidered { - altContent = lr.text - } - i++ - - // shortcut reference style link or reference or inline footnote - default: - var id []byte - - // craft the id - if textHasNl { - var b bytes.Buffer - - for j := 1; j < txtE; j++ { - switch { - case data[j] != '\n': - b.WriteByte(data[j]) - case data[j-1] != ' ': - b.WriteByte(' ') - } - } - - id = b.Bytes() - } else { - if t == linkDeferredFootnote { - id = data[2:txtE] // get rid of the ^ - } else { - id = data[1:txtE] - } - } - - footnoteNode = NewNode(Item) - if t == linkInlineFootnote { - // create a new reference - noteID = len(p.notes) + 1 - - var fragment []byte - if len(id) > 0 { - if len(id) < 16 { - fragment = make([]byte, len(id)) - } else { - fragment = make([]byte, 16) - } - copy(fragment, slugify(id)) - } else { - fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteID))...) - } - - ref := &reference{ - noteID: noteID, - hasBlock: false, - link: fragment, - title: id, - footnote: footnoteNode, - } - - p.notes = append(p.notes, ref) - - link = ref.link - title = ref.title - } else { - // find the reference with matching id - lr, ok := p.getRef(string(id)) - if !ok { - return 0, nil - } - - if t == linkDeferredFootnote { - lr.noteID = len(p.notes) + 1 - lr.footnote = footnoteNode - p.notes = append(p.notes, lr) - } - - // keep link and title from reference - link = lr.link - // if inline footnote, title == footnote contents - title = lr.title - noteID = lr.noteID - } - - // rewind the whitespace - i = txtE + 1 - } - - var uLink []byte - if t == linkNormal || t == linkImg { - if len(link) > 0 { - var uLinkBuf bytes.Buffer - unescapeText(&uLinkBuf, link) - uLink = uLinkBuf.Bytes() - } - - // links need something to click on and somewhere to go - if len(uLink) == 0 || (t == linkNormal && txtE <= 1) { - return 0, nil - } - } - - // call the relevant rendering function - var linkNode *Node - switch t { - case linkNormal: - linkNode = NewNode(Link) - linkNode.Destination = normalizeURI(uLink) - linkNode.Title = title - if len(altContent) > 0 { - linkNode.AppendChild(text(altContent)) - } else { - // links cannot contain other links, so turn off link parsing - // temporarily and recurse - insideLink := p.insideLink - p.insideLink = true - p.inline(linkNode, data[1:txtE]) - p.insideLink = insideLink - } - - case linkImg: - linkNode = NewNode(Image) - linkNode.Destination = uLink - linkNode.Title = title - linkNode.AppendChild(text(data[1:txtE])) - i++ - - case linkInlineFootnote, linkDeferredFootnote: - linkNode = NewNode(Link) - linkNode.Destination = link - linkNode.Title = title - linkNode.NoteID = noteID - linkNode.Footnote = footnoteNode - if t == linkInlineFootnote { - i++ - } - - default: - return 0, nil - } - - return i, linkNode -} - -func (p *Markdown) inlineHTMLComment(data []byte) int { - if len(data) < 5 { - return 0 - } - if data[0] != '<' || data[1] != '!' || data[2] != '-' || data[3] != '-' { - return 0 - } - i := 5 - // scan for an end-of-comment marker, across lines if necessary - for i < len(data) && !(data[i-2] == '-' && data[i-1] == '-' && data[i] == '>') { - i++ - } - // no end-of-comment marker - if i >= len(data) { - return 0 - } - return i + 1 -} - -func stripMailto(link []byte) []byte { - if bytes.HasPrefix(link, []byte("mailto://")) { - return link[9:] - } else if bytes.HasPrefix(link, []byte("mailto:")) { - return link[7:] - } else { - return link - } -} - -// autolinkType specifies a kind of autolink that gets detected. -type autolinkType int - -// These are the possible flag values for the autolink renderer. -const ( - notAutolink autolinkType = iota - normalAutolink - emailAutolink -) - -// '<' when tags or autolinks are allowed -func leftAngle(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - altype, end := tagLength(data) - if size := p.inlineHTMLComment(data); size > 0 { - end = size - } - if end > 2 { - if altype != notAutolink { - var uLink bytes.Buffer - unescapeText(&uLink, data[1:end+1-2]) - if uLink.Len() > 0 { - link := uLink.Bytes() - node := NewNode(Link) - node.Destination = link - if altype == emailAutolink { - node.Destination = append([]byte("mailto:"), link...) - } - node.AppendChild(text(stripMailto(link))) - return end, node - } - } else { - htmlTag := NewNode(HTMLSpan) - htmlTag.Literal = data[:end] - return end, htmlTag - } - } - - return end, nil -} - -// '\\' backslash escape -var escapeChars = []byte("\\`*_{}[]()#+-.!:|&<>~") - -func escape(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - if len(data) > 1 { - if p.extensions&BackslashLineBreak != 0 && data[1] == '\n' { - return 2, NewNode(Hardbreak) - } - if bytes.IndexByte(escapeChars, data[1]) < 0 { - return 0, nil - } - - return 2, text(data[1:2]) - } - - return 2, nil -} - -func unescapeText(ob *bytes.Buffer, src []byte) { - i := 0 - for i < len(src) { - org := i - for i < len(src) && src[i] != '\\' { - i++ - } - - if i > org { - ob.Write(src[org:i]) - } - - if i+1 >= len(src) { - break - } - - ob.WriteByte(src[i+1]) - i += 2 - } -} - -// '&' escaped when it doesn't belong to an entity -// valid entities are assumed to be anything matching &#?[A-Za-z0-9]+; -func entity(p *Markdown, data []byte, offset int) (int, *Node) { - data = data[offset:] - - end := 1 - - if end < len(data) && data[end] == '#' { - end++ - } - - for end < len(data) && isalnum(data[end]) { - end++ - } - - if end < len(data) && data[end] == ';' { - end++ // real entity - } else { - return 0, nil // lone '&' - } - - ent := data[:end] - // undo & escaping or it will be converted to &amp; by another - // escaper in the renderer - if bytes.Equal(ent, []byte("&")) { - ent = []byte{'&'} - } - - return end, text(ent) -} - -func linkEndsWithEntity(data []byte, linkEnd int) bool { - entityRanges := htmlEntityRe.FindAllIndex(data[:linkEnd], -1) - return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd -} - -// hasPrefixCaseInsensitive is a custom implementation of -// strings.HasPrefix(strings.ToLower(s), prefix) -// we rolled our own because ToLower pulls in a huge machinery of lowercasing -// anything from Unicode and that's very slow. Since this func will only be -// used on ASCII protocol prefixes, we can take shortcuts. -func hasPrefixCaseInsensitive(s, prefix []byte) bool { - if len(s) < len(prefix) { - return false - } - delta := byte('a' - 'A') - for i, b := range prefix { - if b != s[i] && b != s[i]+delta { - return false - } - } - return true -} - -var protocolPrefixes = [][]byte{ - []byte("http://"), - []byte("https://"), - []byte("ftp://"), - []byte("file://"), - []byte("mailto:"), -} - -const shortestPrefix = 6 // len("ftp://"), the shortest of the above - -func maybeAutoLink(p *Markdown, data []byte, offset int) (int, *Node) { - // quick check to rule out most false hits - if p.insideLink || len(data) < offset+shortestPrefix { - return 0, nil - } - for _, prefix := range protocolPrefixes { - endOfHead := offset + 8 // 8 is the len() of the longest prefix - if endOfHead > len(data) { - endOfHead = len(data) - } - if hasPrefixCaseInsensitive(data[offset:endOfHead], prefix) { - return autoLink(p, data, offset) - } - } - return 0, nil -} - -func autoLink(p *Markdown, data []byte, offset int) (int, *Node) { - // Now a more expensive check to see if we're not inside an anchor element - anchorStart := offset - offsetFromAnchor := 0 - for anchorStart > 0 && data[anchorStart] != '<' { - anchorStart-- - offsetFromAnchor++ - } - - anchorStr := anchorRe.Find(data[anchorStart:]) - if anchorStr != nil { - anchorClose := NewNode(HTMLSpan) - anchorClose.Literal = anchorStr[offsetFromAnchor:] - return len(anchorStr) - offsetFromAnchor, anchorClose - } - - // scan backward for a word boundary - rewind := 0 - for offset-rewind > 0 && rewind <= 7 && isletter(data[offset-rewind-1]) { - rewind++ - } - if rewind > 6 { // longest supported protocol is "mailto" which has 6 letters - return 0, nil - } - - origData := data - data = data[offset-rewind:] - - if !isSafeLink(data) { - return 0, nil - } - - linkEnd := 0 - for linkEnd < len(data) && !isEndOfLink(data[linkEnd]) { - linkEnd++ - } - - // Skip punctuation at the end of the link - if (data[linkEnd-1] == '.' || data[linkEnd-1] == ',') && data[linkEnd-2] != '\\' { - linkEnd-- - } - - // But don't skip semicolon if it's a part of escaped entity: - if data[linkEnd-1] == ';' && data[linkEnd-2] != '\\' && !linkEndsWithEntity(data, linkEnd) { - linkEnd-- - } - - // See if the link finishes with a punctuation sign that can be closed. - var copen byte - switch data[linkEnd-1] { - case '"': - copen = '"' - case '\'': - copen = '\'' - case ')': - copen = '(' - case ']': - copen = '[' - case '}': - copen = '{' - default: - copen = 0 - } - - if copen != 0 { - bufEnd := offset - rewind + linkEnd - 2 - - openDelim := 1 - - /* Try to close the final punctuation sign in this same line; - * if we managed to close it outside of the URL, that means that it's - * not part of the URL. If it closes inside the URL, that means it - * is part of the URL. - * - * Examples: - * - * foo http://www.pokemon.com/Pikachu_(Electric) bar - * => http://www.pokemon.com/Pikachu_(Electric) - * - * foo (http://www.pokemon.com/Pikachu_(Electric)) bar - * => http://www.pokemon.com/Pikachu_(Electric) - * - * foo http://www.pokemon.com/Pikachu_(Electric)) bar - * => http://www.pokemon.com/Pikachu_(Electric)) - * - * (foo http://www.pokemon.com/Pikachu_(Electric)) bar - * => foo http://www.pokemon.com/Pikachu_(Electric) - */ - - for bufEnd >= 0 && origData[bufEnd] != '\n' && openDelim != 0 { - if origData[bufEnd] == data[linkEnd-1] { - openDelim++ - } - - if origData[bufEnd] == copen { - openDelim-- - } - - bufEnd-- - } - - if openDelim == 0 { - linkEnd-- - } - } - - var uLink bytes.Buffer - unescapeText(&uLink, data[:linkEnd]) - - if uLink.Len() > 0 { - node := NewNode(Link) - node.Destination = uLink.Bytes() - node.AppendChild(text(uLink.Bytes())) - return linkEnd, node - } - - return linkEnd, nil -} - -func isEndOfLink(char byte) bool { - return isspace(char) || char == '<' -} - -var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")} -var validPaths = [][]byte{[]byte("/"), []byte("./"), []byte("../")} - -func isSafeLink(link []byte) bool { - for _, path := range validPaths { - if len(link) >= len(path) && bytes.Equal(link[:len(path)], path) { - if len(link) == len(path) { - return true - } else if isalnum(link[len(path)]) { - return true - } - } - } - - for _, prefix := range validUris { - // TODO: handle unicode here - // case-insensitive prefix test - if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isalnum(link[len(prefix)]) { - return true - } - } - - return false -} - -// return the length of the given tag, or 0 is it's not valid -func tagLength(data []byte) (autolink autolinkType, end int) { - var i, j int - - // a valid tag can't be shorter than 3 chars - if len(data) < 3 { - return notAutolink, 0 - } - - // begins with a '<' optionally followed by '/', followed by letter or number - if data[0] != '<' { - return notAutolink, 0 - } - if data[1] == '/' { - i = 2 - } else { - i = 1 - } - - if !isalnum(data[i]) { - return notAutolink, 0 - } - - // scheme test - autolink = notAutolink - - // try to find the beginning of an URI - for i < len(data) && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-') { - i++ - } - - if i > 1 && i < len(data) && data[i] == '@' { - if j = isMailtoAutoLink(data[i:]); j != 0 { - return emailAutolink, i + j - } - } - - if i > 2 && i < len(data) && data[i] == ':' { - autolink = normalAutolink - i++ - } - - // complete autolink test: no whitespace or ' or " - switch { - case i >= len(data): - autolink = notAutolink - case autolink != notAutolink: - j = i - - for i < len(data) { - if data[i] == '\\' { - i += 2 - } else if data[i] == '>' || data[i] == '\'' || data[i] == '"' || isspace(data[i]) { - break - } else { - i++ - } - - } - - if i >= len(data) { - return autolink, 0 - } - if i > j && data[i] == '>' { - return autolink, i + 1 - } - - // one of the forbidden chars has been found - autolink = notAutolink - } - i += bytes.IndexByte(data[i:], '>') - if i < 0 { - return autolink, 0 - } - return autolink, i + 1 -} - -// look for the address part of a mail autolink and '>' -// this is less strict than the original markdown e-mail address matching -func isMailtoAutoLink(data []byte) int { - nb := 0 - - // address is assumed to be: [-@._a-zA-Z0-9]+ with exactly one '@' - for i := 0; i < len(data); i++ { - if isalnum(data[i]) { - continue - } - - switch data[i] { - case '@': - nb++ - - case '-', '.', '_': - break - - case '>': - if nb == 1 { - return i + 1 - } - return 0 - default: - return 0 - } - } - - return 0 -} - -// look for the next emph char, skipping other constructs -func helperFindEmphChar(data []byte, c byte) int { - i := 0 - - for i < len(data) { - for i < len(data) && data[i] != c && data[i] != '`' && data[i] != '[' { - i++ - } - if i >= len(data) { - return 0 - } - // do not count escaped chars - if i != 0 && data[i-1] == '\\' { - i++ - continue - } - if data[i] == c { - return i - } - - if data[i] == '`' { - // skip a code span - tmpI := 0 - i++ - for i < len(data) && data[i] != '`' { - if tmpI == 0 && data[i] == c { - tmpI = i - } - i++ - } - if i >= len(data) { - return tmpI - } - i++ - } else if data[i] == '[' { - // skip a link - tmpI := 0 - i++ - for i < len(data) && data[i] != ']' { - if tmpI == 0 && data[i] == c { - tmpI = i - } - i++ - } - i++ - for i < len(data) && (data[i] == ' ' || data[i] == '\n') { - i++ - } - if i >= len(data) { - return tmpI - } - if data[i] != '[' && data[i] != '(' { // not a link - if tmpI > 0 { - return tmpI - } - continue - } - cc := data[i] - i++ - for i < len(data) && data[i] != cc { - if tmpI == 0 && data[i] == c { - return i - } - i++ - } - if i >= len(data) { - return tmpI - } - i++ - } - } - return 0 -} - -func helperEmphasis(p *Markdown, data []byte, c byte) (int, *Node) { - i := 0 - - // skip one symbol if coming from emph3 - if len(data) > 1 && data[0] == c && data[1] == c { - i = 1 - } - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - if i >= len(data) { - return 0, nil - } - - if i+1 < len(data) && data[i+1] == c { - i++ - continue - } - - if data[i] == c && !isspace(data[i-1]) { - - if p.extensions&NoIntraEmphasis != 0 { - if !(i+1 == len(data) || isspace(data[i+1]) || ispunct(data[i+1])) { - continue - } - } - - emph := NewNode(Emph) - p.inline(emph, data[:i]) - return i + 1, emph - } - } - - return 0, nil -} - -func helperDoubleEmphasis(p *Markdown, data []byte, c byte) (int, *Node) { - i := 0 - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - - if i+1 < len(data) && data[i] == c && data[i+1] == c && i > 0 && !isspace(data[i-1]) { - nodeType := Strong - if c == '~' { - nodeType = Del - } - node := NewNode(nodeType) - p.inline(node, data[:i]) - return i + 2, node - } - i++ - } - return 0, nil -} - -func helperTripleEmphasis(p *Markdown, data []byte, offset int, c byte) (int, *Node) { - i := 0 - origData := data - data = data[offset:] - - for i < len(data) { - length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } - i += length - - // skip whitespace preceded symbols - if data[i] != c || isspace(data[i-1]) { - continue - } - - switch { - case i+2 < len(data) && data[i+1] == c && data[i+2] == c: - // triple symbol found - strong := NewNode(Strong) - em := NewNode(Emph) - strong.AppendChild(em) - p.inline(em, data[:i]) - return i + 3, strong - case (i+1 < len(data) && data[i+1] == c): - // double symbol found, hand over to emph1 - length, node := helperEmphasis(p, origData[offset-2:], c) - if length == 0 { - return 0, nil - } - return length - 2, node - default: - // single symbol found, hand over to emph2 - length, node := helperDoubleEmphasis(p, origData[offset-1:], c) - if length == 0 { - return 0, nil - } - return length - 1, node - } - } - return 0, nil -} - -func text(s []byte) *Node { - node := NewNode(Text) - node.Literal = s - return node -} - -func normalizeURI(s []byte) []byte { - return s // TODO: implement -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go deleted file mode 100644 index ff61cb05..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/markdown.go +++ /dev/null @@ -1,940 +0,0 @@ -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. - -package blackfriday - -import ( - "bytes" - "fmt" - "io" - "strings" - "unicode/utf8" -) - -// -// Markdown parsing and processing -// - -// Version string of the package. Appears in the rendered document when -// CompletePage flag is on. -const Version = "2.0" - -// Extensions is a bitwise or'ed collection of enabled Blackfriday's -// extensions. -type Extensions int - -// These are the supported markdown parsing extensions. -// OR these values together to select multiple extensions. -const ( - NoExtensions Extensions = 0 - NoIntraEmphasis Extensions = 1 << iota // Ignore emphasis markers inside words - Tables // Render tables - FencedCode // Render fenced code blocks - Autolink // Detect embedded URLs that are not explicitly marked - Strikethrough // Strikethrough text using ~~test~~ - LaxHTMLBlocks // Loosen up HTML block parsing rules - SpaceHeadings // Be strict about prefix heading rules - HardLineBreak // Translate newlines into line breaks - TabSizeEight // Expand tabs to eight spaces instead of four - Footnotes // Pandoc-style footnotes - NoEmptyLineBeforeBlock // No need to insert an empty line to start a (code, quote, ordered list, unordered list) block - HeadingIDs // specify heading IDs with {#id} - Titleblock // Titleblock ala pandoc - AutoHeadingIDs // Create the heading ID from the text - BackslashLineBreak // Translate trailing backslashes into line breaks - DefinitionLists // Render definition lists - - CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | - SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes - - CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | - Autolink | Strikethrough | SpaceHeadings | HeadingIDs | - BackslashLineBreak | DefinitionLists -) - -// ListType contains bitwise or'ed flags for list and list item objects. -type ListType int - -// These are the possible flag values for the ListItem renderer. -// Multiple flag values may be ORed together. -// These are mostly of interest if you are writing a new output format. -const ( - ListTypeOrdered ListType = 1 << iota - ListTypeDefinition - ListTypeTerm - - ListItemContainsBlock - ListItemBeginningOfList // TODO: figure out if this is of any use now - ListItemEndOfList -) - -// CellAlignFlags holds a type of alignment in a table cell. -type CellAlignFlags int - -// These are the possible flag values for the table cell renderer. -// Only a single one of these values will be used; they are not ORed together. -// These are mostly of interest if you are writing a new output format. -const ( - TableAlignmentLeft CellAlignFlags = 1 << iota - TableAlignmentRight - TableAlignmentCenter = (TableAlignmentLeft | TableAlignmentRight) -) - -// The size of a tab stop. -const ( - TabSizeDefault = 4 - TabSizeDouble = 8 -) - -// blockTags is a set of tags that are recognized as HTML block tags. -// Any of these can be included in markdown text without special escaping. -var blockTags = map[string]struct{}{ - "blockquote": struct{}{}, - "del": struct{}{}, - "div": struct{}{}, - "dl": struct{}{}, - "fieldset": struct{}{}, - "form": struct{}{}, - "h1": struct{}{}, - "h2": struct{}{}, - "h3": struct{}{}, - "h4": struct{}{}, - "h5": struct{}{}, - "h6": struct{}{}, - "iframe": struct{}{}, - "ins": struct{}{}, - "math": struct{}{}, - "noscript": struct{}{}, - "ol": struct{}{}, - "pre": struct{}{}, - "p": struct{}{}, - "script": struct{}{}, - "style": struct{}{}, - "table": struct{}{}, - "ul": struct{}{}, - - // HTML5 - "address": struct{}{}, - "article": struct{}{}, - "aside": struct{}{}, - "canvas": struct{}{}, - "figcaption": struct{}{}, - "figure": struct{}{}, - "footer": struct{}{}, - "header": struct{}{}, - "hgroup": struct{}{}, - "main": struct{}{}, - "nav": struct{}{}, - "output": struct{}{}, - "progress": struct{}{}, - "section": struct{}{}, - "video": struct{}{}, -} - -// Renderer is the rendering interface. This is mostly of interest if you are -// implementing a new rendering format. -// -// Only an HTML implementation is provided in this repository, see the README -// for external implementations. -type Renderer interface { - // RenderNode is the main rendering method. It will be called once for - // every leaf node and twice for every non-leaf node (first with - // entering=true, then with entering=false). The method should write its - // rendition of the node to the supplied writer w. - RenderNode(w io.Writer, node *Node, entering bool) WalkStatus - - // RenderHeader is a method that allows the renderer to produce some - // content preceding the main body of the output document. The header is - // understood in the broad sense here. For example, the default HTML - // renderer will write not only the HTML document preamble, but also the - // table of contents if it was requested. - // - // The method will be passed an entire document tree, in case a particular - // implementation needs to inspect it to produce output. - // - // The output should be written to the supplied writer w. If your - // implementation has no header to write, supply an empty implementation. - RenderHeader(w io.Writer, ast *Node) - - // RenderFooter is a symmetric counterpart of RenderHeader. - RenderFooter(w io.Writer, ast *Node) -} - -// Callback functions for inline parsing. One such function is defined -// for each character that triggers a response when parsing inline data. -type inlineParser func(p *Markdown, data []byte, offset int) (int, *Node) - -// Markdown is a type that holds extensions and the runtime state used by -// Parse, and the renderer. You can not use it directly, construct it with New. -type Markdown struct { - renderer Renderer - referenceOverride ReferenceOverrideFunc - refs map[string]*reference - inlineCallback [256]inlineParser - extensions Extensions - nesting int - maxNesting int - insideLink bool - - // Footnotes need to be ordered as well as available to quickly check for - // presence. If a ref is also a footnote, it's stored both in refs and here - // in notes. Slice is nil if footnotes not enabled. - notes []*reference - - doc *Node - tip *Node // = doc - oldTip *Node - lastMatchedContainer *Node // = doc - allClosed bool -} - -func (p *Markdown) getRef(refid string) (ref *reference, found bool) { - if p.referenceOverride != nil { - r, overridden := p.referenceOverride(refid) - if overridden { - if r == nil { - return nil, false - } - return &reference{ - link: []byte(r.Link), - title: []byte(r.Title), - noteID: 0, - hasBlock: false, - text: []byte(r.Text)}, true - } - } - // refs are case insensitive - ref, found = p.refs[strings.ToLower(refid)] - return ref, found -} - -func (p *Markdown) finalize(block *Node) { - above := block.Parent - block.open = false - p.tip = above -} - -func (p *Markdown) addChild(node NodeType, offset uint32) *Node { - return p.addExistingChild(NewNode(node), offset) -} - -func (p *Markdown) addExistingChild(node *Node, offset uint32) *Node { - for !p.tip.canContain(node.Type) { - p.finalize(p.tip) - } - p.tip.AppendChild(node) - p.tip = node - return node -} - -func (p *Markdown) closeUnmatchedBlocks() { - if !p.allClosed { - for p.oldTip != p.lastMatchedContainer { - parent := p.oldTip.Parent - p.finalize(p.oldTip) - p.oldTip = parent - } - p.allClosed = true - } -} - -// -// -// Public interface -// -// - -// Reference represents the details of a link. -// See the documentation in Options for more details on use-case. -type Reference struct { - // Link is usually the URL the reference points to. - Link string - // Title is the alternate text describing the link in more detail. - Title string - // Text is the optional text to override the ref with if the syntax used was - // [refid][] - Text string -} - -// ReferenceOverrideFunc is expected to be called with a reference string and -// return either a valid Reference type that the reference string maps to or -// nil. If overridden is false, the default reference logic will be executed. -// See the documentation in Options for more details on use-case. -type ReferenceOverrideFunc func(reference string) (ref *Reference, overridden bool) - -// New constructs a Markdown processor. You can use the same With* functions as -// for Run() to customize parser's behavior and the renderer. -func New(opts ...Option) *Markdown { - var p Markdown - for _, opt := range opts { - opt(&p) - } - p.refs = make(map[string]*reference) - p.maxNesting = 16 - p.insideLink = false - docNode := NewNode(Document) - p.doc = docNode - p.tip = docNode - p.oldTip = docNode - p.lastMatchedContainer = docNode - p.allClosed = true - // register inline parsers - p.inlineCallback[' '] = maybeLineBreak - p.inlineCallback['*'] = emphasis - p.inlineCallback['_'] = emphasis - if p.extensions&Strikethrough != 0 { - p.inlineCallback['~'] = emphasis - } - p.inlineCallback['`'] = codeSpan - p.inlineCallback['\n'] = lineBreak - p.inlineCallback['['] = link - p.inlineCallback['<'] = leftAngle - p.inlineCallback['\\'] = escape - p.inlineCallback['&'] = entity - p.inlineCallback['!'] = maybeImage - p.inlineCallback['^'] = maybeInlineFootnote - if p.extensions&Autolink != 0 { - p.inlineCallback['h'] = maybeAutoLink - p.inlineCallback['m'] = maybeAutoLink - p.inlineCallback['f'] = maybeAutoLink - p.inlineCallback['H'] = maybeAutoLink - p.inlineCallback['M'] = maybeAutoLink - p.inlineCallback['F'] = maybeAutoLink - } - if p.extensions&Footnotes != 0 { - p.notes = make([]*reference, 0) - } - return &p -} - -// Option customizes the Markdown processor's default behavior. -type Option func(*Markdown) - -// WithRenderer allows you to override the default renderer. -func WithRenderer(r Renderer) Option { - return func(p *Markdown) { - p.renderer = r - } -} - -// WithExtensions allows you to pick some of the many extensions provided by -// Blackfriday. You can bitwise OR them. -func WithExtensions(e Extensions) Option { - return func(p *Markdown) { - p.extensions = e - } -} - -// WithNoExtensions turns off all extensions and custom behavior. -func WithNoExtensions() Option { - return func(p *Markdown) { - p.extensions = NoExtensions - p.renderer = NewHTMLRenderer(HTMLRendererParameters{ - Flags: HTMLFlagsNone, - }) - } -} - -// WithRefOverride sets an optional function callback that is called every -// time a reference is resolved. -// -// In Markdown, the link reference syntax can be made to resolve a link to -// a reference instead of an inline URL, in one of the following ways: -// -// * [link text][refid] -// * [refid][] -// -// Usually, the refid is defined at the bottom of the Markdown document. If -// this override function is provided, the refid is passed to the override -// function first, before consulting the defined refids at the bottom. If -// the override function indicates an override did not occur, the refids at -// the bottom will be used to fill in the link details. -func WithRefOverride(o ReferenceOverrideFunc) Option { - return func(p *Markdown) { - p.referenceOverride = o - } -} - -// Run is the main entry point to Blackfriday. It parses and renders a -// block of markdown-encoded text. -// -// The simplest invocation of Run takes one argument, input: -// output := Run(input) -// This will parse the input with CommonExtensions enabled and render it with -// the default HTMLRenderer (with CommonHTMLFlags). -// -// Variadic arguments opts can customize the default behavior. Since Markdown -// type does not contain exported fields, you can not use it directly. Instead, -// use the With* functions. For example, this will call the most basic -// functionality, with no extensions: -// output := Run(input, WithNoExtensions()) -// -// You can use any number of With* arguments, even contradicting ones. They -// will be applied in order of appearance and the latter will override the -// former: -// output := Run(input, WithNoExtensions(), WithExtensions(exts), -// WithRenderer(yourRenderer)) -func Run(input []byte, opts ...Option) []byte { - r := NewHTMLRenderer(HTMLRendererParameters{ - Flags: CommonHTMLFlags, - }) - optList := []Option{WithRenderer(r), WithExtensions(CommonExtensions)} - optList = append(optList, opts...) - parser := New(optList...) - ast := parser.Parse(input) - var buf bytes.Buffer - parser.renderer.RenderHeader(&buf, ast) - ast.Walk(func(node *Node, entering bool) WalkStatus { - return parser.renderer.RenderNode(&buf, node, entering) - }) - parser.renderer.RenderFooter(&buf, ast) - return buf.Bytes() -} - -// Parse is an entry point to the parsing part of Blackfriday. It takes an -// input markdown document and produces a syntax tree for its contents. This -// tree can then be rendered with a default or custom renderer, or -// analyzed/transformed by the caller to whatever non-standard needs they have. -// The return value is the root node of the syntax tree. -func (p *Markdown) Parse(input []byte) *Node { - p.block(input) - // Walk the tree and finish up some of unfinished blocks - for p.tip != nil { - p.finalize(p.tip) - } - // Walk the tree again and process inline markdown in each block - p.doc.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Paragraph || node.Type == Heading || node.Type == TableCell { - p.inline(node, node.content) - node.content = nil - } - return GoToNext - }) - p.parseRefsToAST() - return p.doc -} - -func (p *Markdown) parseRefsToAST() { - if p.extensions&Footnotes == 0 || len(p.notes) == 0 { - return - } - p.tip = p.doc - block := p.addBlock(List, nil) - block.IsFootnotesList = true - block.ListFlags = ListTypeOrdered - flags := ListItemBeginningOfList - // Note: this loop is intentionally explicit, not range-form. This is - // because the body of the loop will append nested footnotes to p.notes and - // we need to process those late additions. Range form would only walk over - // the fixed initial set. - for i := 0; i < len(p.notes); i++ { - ref := p.notes[i] - p.addExistingChild(ref.footnote, 0) - block := ref.footnote - block.ListFlags = flags | ListTypeOrdered - block.RefLink = ref.link - if ref.hasBlock { - flags |= ListItemContainsBlock - p.block(ref.title) - } else { - p.inline(block, ref.title) - } - flags &^= ListItemBeginningOfList | ListItemContainsBlock - } - above := block.Parent - finalizeList(block) - p.tip = above - block.Walk(func(node *Node, entering bool) WalkStatus { - if node.Type == Paragraph || node.Type == Heading { - p.inline(node, node.content) - node.content = nil - } - return GoToNext - }) -} - -// -// Link references -// -// This section implements support for references that (usually) appear -// as footnotes in a document, and can be referenced anywhere in the document. -// The basic format is: -// -// [1]: http://www.google.com/ "Google" -// [2]: http://www.github.com/ "Github" -// -// Anywhere in the document, the reference can be linked by referring to its -// label, i.e., 1 and 2 in this example, as in: -// -// This library is hosted on [Github][2], a git hosting site. -// -// Actual footnotes as specified in Pandoc and supported by some other Markdown -// libraries such as php-markdown are also taken care of. They look like this: -// -// This sentence needs a bit of further explanation.[^note] -// -// [^note]: This is the explanation. -// -// Footnotes should be placed at the end of the document in an ordered list. -// Inline footnotes such as: -// -// Inline footnotes^[Not supported.] also exist. -// -// are not yet supported. - -// reference holds all information necessary for a reference-style links or -// footnotes. -// -// Consider this markdown with reference-style links: -// -// [link][ref] -// -// [ref]: /url/ "tooltip title" -// -// It will be ultimately converted to this HTML: -// -//

    link

    -// -// And a reference structure will be populated as follows: -// -// p.refs["ref"] = &reference{ -// link: "/url/", -// title: "tooltip title", -// } -// -// Alternatively, reference can contain information about a footnote. Consider -// this markdown: -// -// Text needing a footnote.[^a] -// -// [^a]: This is the note -// -// A reference structure will be populated as follows: -// -// p.refs["a"] = &reference{ -// link: "a", -// title: "This is the note", -// noteID: , -// } -// -// TODO: As you can see, it begs for splitting into two dedicated structures -// for refs and for footnotes. -type reference struct { - link []byte - title []byte - noteID int // 0 if not a footnote ref - hasBlock bool - footnote *Node // a link to the Item node within a list of footnotes - - text []byte // only gets populated by refOverride feature with Reference.Text -} - -func (r *reference) String() string { - return fmt.Sprintf("{link: %q, title: %q, text: %q, noteID: %d, hasBlock: %v}", - r.link, r.title, r.text, r.noteID, r.hasBlock) -} - -// Check whether or not data starts with a reference link. -// If so, it is parsed and stored in the list of references -// (in the render struct). -// Returns the number of bytes to skip to move past it, -// or zero if the first line is not a reference. -func isReference(p *Markdown, data []byte, tabSize int) int { - // up to 3 optional leading spaces - if len(data) < 4 { - return 0 - } - i := 0 - for i < 3 && data[i] == ' ' { - i++ - } - - noteID := 0 - - // id part: anything but a newline between brackets - if data[i] != '[' { - return 0 - } - i++ - if p.extensions&Footnotes != 0 { - if i < len(data) && data[i] == '^' { - // we can set it to anything here because the proper noteIds will - // be assigned later during the second pass. It just has to be != 0 - noteID = 1 - i++ - } - } - idOffset := i - for i < len(data) && data[i] != '\n' && data[i] != '\r' && data[i] != ']' { - i++ - } - if i >= len(data) || data[i] != ']' { - return 0 - } - idEnd := i - // footnotes can have empty ID, like this: [^], but a reference can not be - // empty like this: []. Break early if it's not a footnote and there's no ID - if noteID == 0 && idOffset == idEnd { - return 0 - } - // spacer: colon (space | tab)* newline? (space | tab)* - i++ - if i >= len(data) || data[i] != ':' { - return 0 - } - i++ - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i < len(data) && (data[i] == '\n' || data[i] == '\r') { - i++ - if i < len(data) && data[i] == '\n' && data[i-1] == '\r' { - i++ - } - } - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i >= len(data) { - return 0 - } - - var ( - linkOffset, linkEnd int - titleOffset, titleEnd int - lineEnd int - raw []byte - hasBlock bool - ) - - if p.extensions&Footnotes != 0 && noteID != 0 { - linkOffset, linkEnd, raw, hasBlock = scanFootnote(p, data, i, tabSize) - lineEnd = linkEnd - } else { - linkOffset, linkEnd, titleOffset, titleEnd, lineEnd = scanLinkRef(p, data, i) - } - if lineEnd == 0 { - return 0 - } - - // a valid ref has been found - - ref := &reference{ - noteID: noteID, - hasBlock: hasBlock, - } - - if noteID > 0 { - // reusing the link field for the id since footnotes don't have links - ref.link = data[idOffset:idEnd] - // if footnote, it's not really a title, it's the contained text - ref.title = raw - } else { - ref.link = data[linkOffset:linkEnd] - ref.title = data[titleOffset:titleEnd] - } - - // id matches are case-insensitive - id := string(bytes.ToLower(data[idOffset:idEnd])) - - p.refs[id] = ref - - return lineEnd -} - -func scanLinkRef(p *Markdown, data []byte, i int) (linkOffset, linkEnd, titleOffset, titleEnd, lineEnd int) { - // link: whitespace-free sequence, optionally between angle brackets - if data[i] == '<' { - i++ - } - linkOffset = i - for i < len(data) && data[i] != ' ' && data[i] != '\t' && data[i] != '\n' && data[i] != '\r' { - i++ - } - linkEnd = i - if data[linkOffset] == '<' && data[linkEnd-1] == '>' { - linkOffset++ - linkEnd-- - } - - // optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - if i < len(data) && data[i] != '\n' && data[i] != '\r' && data[i] != '\'' && data[i] != '"' && data[i] != '(' { - return - } - - // compute end-of-line - if i >= len(data) || data[i] == '\r' || data[i] == '\n' { - lineEnd = i - } - if i+1 < len(data) && data[i] == '\r' && data[i+1] == '\n' { - lineEnd++ - } - - // optional (space|tab)* spacer after a newline - if lineEnd > 0 { - i = lineEnd + 1 - for i < len(data) && (data[i] == ' ' || data[i] == '\t') { - i++ - } - } - - // optional title: any non-newline sequence enclosed in '"() alone on its line - if i+1 < len(data) && (data[i] == '\'' || data[i] == '"' || data[i] == '(') { - i++ - titleOffset = i - - // look for EOL - for i < len(data) && data[i] != '\n' && data[i] != '\r' { - i++ - } - if i+1 < len(data) && data[i] == '\n' && data[i+1] == '\r' { - titleEnd = i + 1 - } else { - titleEnd = i - } - - // step back - i-- - for i > titleOffset && (data[i] == ' ' || data[i] == '\t') { - i-- - } - if i > titleOffset && (data[i] == '\'' || data[i] == '"' || data[i] == ')') { - lineEnd = titleEnd - titleEnd = i - } - } - - return -} - -// The first bit of this logic is the same as Parser.listItem, but the rest -// is much simpler. This function simply finds the entire block and shifts it -// over by one tab if it is indeed a block (just returns the line if it's not). -// blockEnd is the end of the section in the input buffer, and contents is the -// extracted text that was shifted over one tab. It will need to be rendered at -// the end of the document. -func scanFootnote(p *Markdown, data []byte, i, indentSize int) (blockStart, blockEnd int, contents []byte, hasBlock bool) { - if i == 0 || len(data) == 0 { - return - } - - // skip leading whitespace on first line - for i < len(data) && data[i] == ' ' { - i++ - } - - blockStart = i - - // find the end of the line - blockEnd = i - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // get working buffer - var raw bytes.Buffer - - // put the first line into the working buffer - raw.Write(data[blockEnd:i]) - blockEnd = i - - // process the following lines - containsBlankLine := false - -gatherLines: - for blockEnd < len(data) { - i++ - - // find the end of this line - for i < len(data) && data[i-1] != '\n' { - i++ - } - - // if it is an empty line, guess that it is part of this item - // and move on to the next line - if p.isEmpty(data[blockEnd:i]) > 0 { - containsBlankLine = true - blockEnd = i - continue - } - - n := 0 - if n = isIndented(data[blockEnd:i], indentSize); n == 0 { - // this is the end of the block. - // we don't want to include this last line in the index. - break gatherLines - } - - // if there were blank lines before this one, insert a new one now - if containsBlankLine { - raw.WriteByte('\n') - containsBlankLine = false - } - - // get rid of that first tab, write to buffer - raw.Write(data[blockEnd+n : i]) - hasBlock = true - - blockEnd = i - } - - if data[blockEnd-1] != '\n' { - raw.WriteByte('\n') - } - - contents = raw.Bytes() - - return -} - -// -// -// Miscellaneous helper functions -// -// - -// Test if a character is a punctuation symbol. -// Taken from a private function in regexp in the stdlib. -func ispunct(c byte) bool { - for _, r := range []byte("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") { - if c == r { - return true - } - } - return false -} - -// Test if a character is a whitespace character. -func isspace(c byte) bool { - return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' -} - -// Test if a character is letter. -func isletter(c byte) bool { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') -} - -// Test if a character is a letter or a digit. -// TODO: check when this is looking for ASCII alnum and when it should use unicode -func isalnum(c byte) bool { - return (c >= '0' && c <= '9') || isletter(c) -} - -// Replace tab characters with spaces, aligning to the next TAB_SIZE column. -// always ends output with a newline -func expandTabs(out *bytes.Buffer, line []byte, tabSize int) { - // first, check for common cases: no tabs, or only tabs at beginning of line - i, prefix := 0, 0 - slowcase := false - for i = 0; i < len(line); i++ { - if line[i] == '\t' { - if prefix == i { - prefix++ - } else { - slowcase = true - break - } - } - } - - // no need to decode runes if all tabs are at the beginning of the line - if !slowcase { - for i = 0; i < prefix*tabSize; i++ { - out.WriteByte(' ') - } - out.Write(line[prefix:]) - return - } - - // the slow case: we need to count runes to figure out how - // many spaces to insert for each tab - column := 0 - i = 0 - for i < len(line) { - start := i - for i < len(line) && line[i] != '\t' { - _, size := utf8.DecodeRune(line[i:]) - i += size - column++ - } - - if i > start { - out.Write(line[start:i]) - } - - if i >= len(line) { - break - } - - for { - out.WriteByte(' ') - column++ - if column%tabSize == 0 { - break - } - } - - i++ - } -} - -// Find if a line counts as indented or not. -// Returns number of characters the indent is (0 = not indented). -func isIndented(data []byte, indentSize int) int { - if len(data) == 0 { - return 0 - } - if data[0] == '\t' { - return 1 - } - if len(data) < indentSize { - return 0 - } - for i := 0; i < indentSize; i++ { - if data[i] != ' ' { - return 0 - } - } - return indentSize -} - -// Create a url-safe slug for fragments -func slugify(in []byte) []byte { - if len(in) == 0 { - return in - } - out := make([]byte, 0, len(in)) - sym := false - - for _, ch := range in { - if isalnum(ch) { - sym = false - out = append(out, ch) - } else if sym { - continue - } else { - out = append(out, '-') - sym = true - } - } - var a, b int - var ch byte - for a, ch = range out { - if ch != '-' { - break - } - } - for b = len(out) - 1; b > 0; b-- { - if out[b] != '-' { - break - } - } - return out[a : b+1] -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go deleted file mode 100644 index 51b9e8c1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/node.go +++ /dev/null @@ -1,354 +0,0 @@ -package blackfriday - -import ( - "bytes" - "fmt" -) - -// NodeType specifies a type of a single node of a syntax tree. Usually one -// node (and its type) corresponds to a single markdown feature, e.g. emphasis -// or code block. -type NodeType int - -// Constants for identifying different types of nodes. See NodeType. -const ( - Document NodeType = iota - BlockQuote - List - Item - Paragraph - Heading - HorizontalRule - Emph - Strong - Del - Link - Image - Text - HTMLBlock - CodeBlock - Softbreak - Hardbreak - Code - HTMLSpan - Table - TableCell - TableHead - TableBody - TableRow -) - -var nodeTypeNames = []string{ - Document: "Document", - BlockQuote: "BlockQuote", - List: "List", - Item: "Item", - Paragraph: "Paragraph", - Heading: "Heading", - HorizontalRule: "HorizontalRule", - Emph: "Emph", - Strong: "Strong", - Del: "Del", - Link: "Link", - Image: "Image", - Text: "Text", - HTMLBlock: "HTMLBlock", - CodeBlock: "CodeBlock", - Softbreak: "Softbreak", - Hardbreak: "Hardbreak", - Code: "Code", - HTMLSpan: "HTMLSpan", - Table: "Table", - TableCell: "TableCell", - TableHead: "TableHead", - TableBody: "TableBody", - TableRow: "TableRow", -} - -func (t NodeType) String() string { - return nodeTypeNames[t] -} - -// ListData contains fields relevant to a List and Item node type. -type ListData struct { - ListFlags ListType - Tight bool // Skip

    s around list item data if true - BulletChar byte // '*', '+' or '-' in bullet lists - Delimiter byte // '.' or ')' after the number in ordered lists - RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering - IsFootnotesList bool // This is a list of footnotes -} - -// LinkData contains fields relevant to a Link node type. -type LinkData struct { - Destination []byte // Destination is what goes into a href - Title []byte // Title is the tooltip thing that goes in a title attribute - NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote - Footnote *Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. -} - -// CodeBlockData contains fields relevant to a CodeBlock node type. -type CodeBlockData struct { - IsFenced bool // Specifies whether it's a fenced code block or an indented one - Info []byte // This holds the info string - FenceChar byte - FenceLength int - FenceOffset int -} - -// TableCellData contains fields relevant to a TableCell node type. -type TableCellData struct { - IsHeader bool // This tells if it's under the header row - Align CellAlignFlags // This holds the value for align attribute -} - -// HeadingData contains fields relevant to a Heading node type. -type HeadingData struct { - Level int // This holds the heading level number - HeadingID string // This might hold heading ID, if present - IsTitleblock bool // Specifies whether it's a title block -} - -// Node is a single element in the abstract syntax tree of the parsed document. -// It holds connections to the structurally neighboring nodes and, for certain -// types of nodes, additional information that might be needed when rendering. -type Node struct { - Type NodeType // Determines the type of the node - Parent *Node // Points to the parent - FirstChild *Node // Points to the first child, if any - LastChild *Node // Points to the last child, if any - Prev *Node // Previous sibling; nil if it's the first child - Next *Node // Next sibling; nil if it's the last child - - Literal []byte // Text contents of the leaf nodes - - HeadingData // Populated if Type is Heading - ListData // Populated if Type is List - CodeBlockData // Populated if Type is CodeBlock - LinkData // Populated if Type is Link - TableCellData // Populated if Type is TableCell - - content []byte // Markdown content of the block nodes - open bool // Specifies an open block node that has not been finished to process yet -} - -// NewNode allocates a node of a specified type. -func NewNode(typ NodeType) *Node { - return &Node{ - Type: typ, - open: true, - } -} - -func (n *Node) String() string { - ellipsis := "" - snippet := n.Literal - if len(snippet) > 16 { - snippet = snippet[:16] - ellipsis = "..." - } - return fmt.Sprintf("%s: '%s%s'", n.Type, snippet, ellipsis) -} - -// Unlink removes node 'n' from the tree. -// It panics if the node is nil. -func (n *Node) Unlink() { - if n.Prev != nil { - n.Prev.Next = n.Next - } else if n.Parent != nil { - n.Parent.FirstChild = n.Next - } - if n.Next != nil { - n.Next.Prev = n.Prev - } else if n.Parent != nil { - n.Parent.LastChild = n.Prev - } - n.Parent = nil - n.Next = nil - n.Prev = nil -} - -// AppendChild adds a node 'child' as a child of 'n'. -// It panics if either node is nil. -func (n *Node) AppendChild(child *Node) { - child.Unlink() - child.Parent = n - if n.LastChild != nil { - n.LastChild.Next = child - child.Prev = n.LastChild - n.LastChild = child - } else { - n.FirstChild = child - n.LastChild = child - } -} - -// InsertBefore inserts 'sibling' immediately before 'n'. -// It panics if either node is nil. -func (n *Node) InsertBefore(sibling *Node) { - sibling.Unlink() - sibling.Prev = n.Prev - if sibling.Prev != nil { - sibling.Prev.Next = sibling - } - sibling.Next = n - n.Prev = sibling - sibling.Parent = n.Parent - if sibling.Prev == nil { - sibling.Parent.FirstChild = sibling - } -} - -func (n *Node) isContainer() bool { - switch n.Type { - case Document: - fallthrough - case BlockQuote: - fallthrough - case List: - fallthrough - case Item: - fallthrough - case Paragraph: - fallthrough - case Heading: - fallthrough - case Emph: - fallthrough - case Strong: - fallthrough - case Del: - fallthrough - case Link: - fallthrough - case Image: - fallthrough - case Table: - fallthrough - case TableHead: - fallthrough - case TableBody: - fallthrough - case TableRow: - fallthrough - case TableCell: - return true - default: - return false - } -} - -func (n *Node) canContain(t NodeType) bool { - if n.Type == List { - return t == Item - } - if n.Type == Document || n.Type == BlockQuote || n.Type == Item { - return t != Item - } - if n.Type == Table { - return t == TableHead || t == TableBody - } - if n.Type == TableHead || n.Type == TableBody { - return t == TableRow - } - if n.Type == TableRow { - return t == TableCell - } - return false -} - -// WalkStatus allows NodeVisitor to have some control over the tree traversal. -// It is returned from NodeVisitor and different values allow Node.Walk to -// decide which node to go to next. -type WalkStatus int - -const ( - // GoToNext is the default traversal of every node. - GoToNext WalkStatus = iota - // SkipChildren tells walker to skip all children of current node. - SkipChildren - // Terminate tells walker to terminate the traversal. - Terminate -) - -// NodeVisitor is a callback to be called when traversing the syntax tree. -// Called twice for every node: once with entering=true when the branch is -// first visited, then with entering=false after all the children are done. -type NodeVisitor func(node *Node, entering bool) WalkStatus - -// Walk is a convenience method that instantiates a walker and starts a -// traversal of subtree rooted at n. -func (n *Node) Walk(visitor NodeVisitor) { - w := newNodeWalker(n) - for w.current != nil { - status := visitor(w.current, w.entering) - switch status { - case GoToNext: - w.next() - case SkipChildren: - w.entering = false - w.next() - case Terminate: - return - } - } -} - -type nodeWalker struct { - current *Node - root *Node - entering bool -} - -func newNodeWalker(root *Node) *nodeWalker { - return &nodeWalker{ - current: root, - root: root, - entering: true, - } -} - -func (nw *nodeWalker) next() { - if (!nw.current.isContainer() || !nw.entering) && nw.current == nw.root { - nw.current = nil - return - } - if nw.entering && nw.current.isContainer() { - if nw.current.FirstChild != nil { - nw.current = nw.current.FirstChild - nw.entering = true - } else { - nw.entering = false - } - } else if nw.current.Next == nil { - nw.current = nw.current.Parent - nw.entering = false - } else { - nw.current = nw.current.Next - nw.entering = true - } -} - -func dump(ast *Node) { - fmt.Println(dumpString(ast)) -} - -func dumpR(ast *Node, depth int) string { - if ast == nil { - return "" - } - indent := bytes.Repeat([]byte("\t"), depth) - content := ast.Literal - if content == nil { - content = ast.content - } - result := fmt.Sprintf("%s%s(%q)\n", indent, ast.Type, content) - for n := ast.FirstChild; n != nil; n = n.Next { - result += dumpR(n, depth+1) - } - return result -} - -func dumpString(ast *Node) string { - return dumpR(ast, 0) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go deleted file mode 100644 index 3a220e94..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/russross/blackfriday/smartypants.go +++ /dev/null @@ -1,457 +0,0 @@ -// -// Blackfriday Markdown Processor -// Available at http://github.com/russross/blackfriday -// -// Copyright © 2011 Russ Ross . -// Distributed under the Simplified BSD License. -// See README.md for details. -// - -// -// -// SmartyPants rendering -// -// - -package blackfriday - -import ( - "bytes" - "io" -) - -// SPRenderer is a struct containing state of a Smartypants renderer. -type SPRenderer struct { - inSingleQuote bool - inDoubleQuote bool - callbacks [256]smartCallback -} - -func wordBoundary(c byte) bool { - return c == 0 || isspace(c) || ispunct(c) -} - -func tolower(c byte) byte { - if c >= 'A' && c <= 'Z' { - return c - 'A' + 'a' - } - return c -} - -func isdigit(c byte) bool { - return c >= '0' && c <= '9' -} - -func smartQuoteHelper(out *bytes.Buffer, previousChar byte, nextChar byte, quote byte, isOpen *bool, addNBSP bool) bool { - // edge of the buffer is likely to be a tag that we don't get to see, - // so we treat it like text sometimes - - // enumerate all sixteen possibilities for (previousChar, nextChar) - // each can be one of {0, space, punct, other} - switch { - case previousChar == 0 && nextChar == 0: - // context is not any help here, so toggle - *isOpen = !*isOpen - case isspace(previousChar) && nextChar == 0: - // [ "] might be [ "foo...] - *isOpen = true - case ispunct(previousChar) && nextChar == 0: - // [!"] hmm... could be [Run!"] or [("...] - *isOpen = false - case /* isnormal(previousChar) && */ nextChar == 0: - // [a"] is probably a close - *isOpen = false - case previousChar == 0 && isspace(nextChar): - // [" ] might be [...foo" ] - *isOpen = false - case isspace(previousChar) && isspace(nextChar): - // [ " ] context is not any help here, so toggle - *isOpen = !*isOpen - case ispunct(previousChar) && isspace(nextChar): - // [!" ] is probably a close - *isOpen = false - case /* isnormal(previousChar) && */ isspace(nextChar): - // [a" ] this is one of the easy cases - *isOpen = false - case previousChar == 0 && ispunct(nextChar): - // ["!] hmm... could be ["$1.95] or ["!...] - *isOpen = false - case isspace(previousChar) && ispunct(nextChar): - // [ "!] looks more like [ "$1.95] - *isOpen = true - case ispunct(previousChar) && ispunct(nextChar): - // [!"!] context is not any help here, so toggle - *isOpen = !*isOpen - case /* isnormal(previousChar) && */ ispunct(nextChar): - // [a"!] is probably a close - *isOpen = false - case previousChar == 0 /* && isnormal(nextChar) */ : - // ["a] is probably an open - *isOpen = true - case isspace(previousChar) /* && isnormal(nextChar) */ : - // [ "a] this is one of the easy cases - *isOpen = true - case ispunct(previousChar) /* && isnormal(nextChar) */ : - // [!"a] is probably an open - *isOpen = true - default: - // [a'b] maybe a contraction? - *isOpen = false - } - - // Note that with the limited lookahead, this non-breaking - // space will also be appended to single double quotes. - if addNBSP && !*isOpen { - out.WriteString(" ") - } - - out.WriteByte('&') - if *isOpen { - out.WriteByte('l') - } else { - out.WriteByte('r') - } - out.WriteByte(quote) - out.WriteString("quo;") - - if addNBSP && *isOpen { - out.WriteString(" ") - } - - return true -} - -func (r *SPRenderer) smartSingleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 { - t1 := tolower(text[1]) - - if t1 == '\'' { - nextChar := byte(0) - if len(text) >= 3 { - nextChar = text[2] - } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote, false) { - return 1 - } - } - - if (t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd') && (len(text) < 3 || wordBoundary(text[2])) { - out.WriteString("’") - return 0 - } - - if len(text) >= 3 { - t2 := tolower(text[2]) - - if ((t1 == 'r' && t2 == 'e') || (t1 == 'l' && t2 == 'l') || (t1 == 'v' && t2 == 'e')) && - (len(text) < 4 || wordBoundary(text[3])) { - out.WriteString("’") - return 0 - } - } - } - - nextChar := byte(0) - if len(text) > 1 { - nextChar = text[1] - } - if smartQuoteHelper(out, previousChar, nextChar, 's', &r.inSingleQuote, false) { - return 0 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartParens(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 { - t1 := tolower(text[1]) - t2 := tolower(text[2]) - - if t1 == 'c' && t2 == ')' { - out.WriteString("©") - return 2 - } - - if t1 == 'r' && t2 == ')' { - out.WriteString("®") - return 2 - } - - if len(text) >= 4 && t1 == 't' && t2 == 'm' && text[3] == ')' { - out.WriteString("™") - return 3 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDash(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 { - if text[1] == '-' { - out.WriteString("—") - return 1 - } - - if wordBoundary(previousChar) && wordBoundary(text[1]) { - out.WriteString("–") - return 0 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDashLatex(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 && text[1] == '-' && text[2] == '-' { - out.WriteString("—") - return 2 - } - if len(text) >= 2 && text[1] == '-' { - out.WriteString("–") - return 1 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartAmpVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte, addNBSP bool) int { - if bytes.HasPrefix(text, []byte(""")) { - nextChar := byte(0) - if len(text) >= 7 { - nextChar = text[6] - } - if smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote, addNBSP) { - return 5 - } - } - - if bytes.HasPrefix(text, []byte("�")) { - return 3 - } - - out.WriteByte('&') - return 0 -} - -func (r *SPRenderer) smartAmp(angledQuotes, addNBSP bool) func(*bytes.Buffer, byte, []byte) int { - var quote byte = 'd' - if angledQuotes { - quote = 'a' - } - - return func(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartAmpVariant(out, previousChar, text, quote, addNBSP) - } -} - -func (r *SPRenderer) smartPeriod(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 3 && text[1] == '.' && text[2] == '.' { - out.WriteString("…") - return 2 - } - - if len(text) >= 5 && text[1] == ' ' && text[2] == '.' && text[3] == ' ' && text[4] == '.' { - out.WriteString("…") - return 4 - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartBacktick(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 && text[1] == '`' { - nextChar := byte(0) - if len(text) >= 3 { - nextChar = text[2] - } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote, false) { - return 1 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartNumberGeneric(out *bytes.Buffer, previousChar byte, text []byte) int { - if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { - // is it of the form digits/digits(word boundary)?, i.e., \d+/\d+\b - // note: check for regular slash (/) or fraction slash (â„, 0x2044, or 0xe2 81 84 in utf-8) - // and avoid changing dates like 1/23/2005 into fractions. - numEnd := 0 - for len(text) > numEnd && isdigit(text[numEnd]) { - numEnd++ - } - if numEnd == 0 { - out.WriteByte(text[0]) - return 0 - } - denStart := numEnd + 1 - if len(text) > numEnd+3 && text[numEnd] == 0xe2 && text[numEnd+1] == 0x81 && text[numEnd+2] == 0x84 { - denStart = numEnd + 3 - } else if len(text) < numEnd+2 || text[numEnd] != '/' { - out.WriteByte(text[0]) - return 0 - } - denEnd := denStart - for len(text) > denEnd && isdigit(text[denEnd]) { - denEnd++ - } - if denEnd == denStart { - out.WriteByte(text[0]) - return 0 - } - if len(text) == denEnd || wordBoundary(text[denEnd]) && text[denEnd] != '/' { - out.WriteString("") - out.Write(text[:numEnd]) - out.WriteString("") - out.Write(text[denStart:denEnd]) - out.WriteString("") - return denEnd - 1 - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartNumber(out *bytes.Buffer, previousChar byte, text []byte) int { - if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { - if text[0] == '1' && text[1] == '/' && text[2] == '2' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' { - out.WriteString("½") - return 2 - } - } - - if text[0] == '1' && text[1] == '/' && text[2] == '4' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' || (len(text) >= 5 && tolower(text[3]) == 't' && tolower(text[4]) == 'h') { - out.WriteString("¼") - return 2 - } - } - - if text[0] == '3' && text[1] == '/' && text[2] == '4' { - if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' || (len(text) >= 6 && tolower(text[3]) == 't' && tolower(text[4]) == 'h' && tolower(text[5]) == 's') { - out.WriteString("¾") - return 2 - } - } - } - - out.WriteByte(text[0]) - return 0 -} - -func (r *SPRenderer) smartDoubleQuoteVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { - nextChar := byte(0) - if len(text) > 1 { - nextChar = text[1] - } - if !smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote, false) { - out.WriteString(""") - } - - return 0 -} - -func (r *SPRenderer) smartDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartDoubleQuoteVariant(out, previousChar, text, 'd') -} - -func (r *SPRenderer) smartAngledDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return r.smartDoubleQuoteVariant(out, previousChar, text, 'a') -} - -func (r *SPRenderer) smartLeftAngle(out *bytes.Buffer, previousChar byte, text []byte) int { - i := 0 - - for i < len(text) && text[i] != '>' { - i++ - } - - out.Write(text[:i+1]) - return i -} - -type smartCallback func(out *bytes.Buffer, previousChar byte, text []byte) int - -// NewSmartypantsRenderer constructs a Smartypants renderer object. -func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer { - var ( - r SPRenderer - - smartAmpAngled = r.smartAmp(true, false) - smartAmpAngledNBSP = r.smartAmp(true, true) - smartAmpRegular = r.smartAmp(false, false) - smartAmpRegularNBSP = r.smartAmp(false, true) - - addNBSP = flags&SmartypantsQuotesNBSP != 0 - ) - - if flags&SmartypantsAngledQuotes == 0 { - r.callbacks['"'] = r.smartDoubleQuote - if !addNBSP { - r.callbacks['&'] = smartAmpRegular - } else { - r.callbacks['&'] = smartAmpRegularNBSP - } - } else { - r.callbacks['"'] = r.smartAngledDoubleQuote - if !addNBSP { - r.callbacks['&'] = smartAmpAngled - } else { - r.callbacks['&'] = smartAmpAngledNBSP - } - } - r.callbacks['\''] = r.smartSingleQuote - r.callbacks['('] = r.smartParens - if flags&SmartypantsDashes != 0 { - if flags&SmartypantsLatexDashes == 0 { - r.callbacks['-'] = r.smartDash - } else { - r.callbacks['-'] = r.smartDashLatex - } - } - r.callbacks['.'] = r.smartPeriod - if flags&SmartypantsFractions == 0 { - r.callbacks['1'] = r.smartNumber - r.callbacks['3'] = r.smartNumber - } else { - for ch := '1'; ch <= '9'; ch++ { - r.callbacks[ch] = r.smartNumberGeneric - } - } - r.callbacks['<'] = r.smartLeftAngle - r.callbacks['`'] = r.smartBacktick - return &r -} - -// Process is the entry point of the Smartypants renderer. -func (r *SPRenderer) Process(w io.Writer, text []byte) { - mark := 0 - for i := 0; i < len(text); i++ { - if action := r.callbacks[text[i]]; action != nil { - if i > mark { - w.Write(text[mark:i]) - } - previousChar := byte(0) - if i > 0 { - previousChar = text[i-1] - } - var tmp bytes.Buffer - i += action(&tmp, previousChar, text[i:]) - w.Write(tmp.Bytes()) - mark = i + 1 - } - } - if mark < len(text) { - w.Write(text[mark:]) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE deleted file mode 100644 index c35c17af..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2015 Dmitri Shuralyov - -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/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md deleted file mode 100644 index 670bf0fe..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/README.md +++ /dev/null @@ -1,36 +0,0 @@ -sanitized_anchor_name -===================== - -[![Build Status](https://travis-ci.org/shurcooL/sanitized_anchor_name.svg?branch=master)](https://travis-ci.org/shurcooL/sanitized_anchor_name) [![GoDoc](https://godoc.org/github.com/shurcooL/sanitized_anchor_name?status.svg)](https://godoc.org/github.com/shurcooL/sanitized_anchor_name) - -Package sanitized_anchor_name provides a func to create sanitized anchor names. - -Its logic can be reused by multiple packages to create interoperable anchor names -and links to those anchors. - -At this time, it does not try to ensure that generated anchor names -are unique, that responsibility falls on the caller. - -Installation ------------- - -```bash -go get -u github.com/shurcooL/sanitized_anchor_name -``` - -Example -------- - -```Go -anchorName := sanitized_anchor_name.Create("This is a header") - -fmt.Println(anchorName) - -// Output: -// this-is-a-header -``` - -License -------- - -- [MIT License](LICENSE) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go deleted file mode 100644 index 6a77d124..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/cpuguy83/go-md2man/vendor/github.com/shurcooL/sanitized_anchor_name/main.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package sanitized_anchor_name provides a func to create sanitized anchor names. -// -// Its logic can be reused by multiple packages to create interoperable anchor names -// and links to those anchors. -// -// At this time, it does not try to ensure that generated anchor names -// are unique, that responsibility falls on the caller. -package sanitized_anchor_name // import "github.com/shurcooL/sanitized_anchor_name" - -import "unicode" - -// Create returns a sanitized anchor name for the given text. -func Create(text string) string { - var anchorName []rune - var futureDash = false - for _, r := range text { - switch { - case unicode.IsLetter(r) || unicode.IsNumber(r): - if futureDash && len(anchorName) > 0 { - anchorName = append(anchorName, '-') - } - futureDash = false - anchorName = append(anchorName, unicode.ToLower(r)) - default: - futureDash = true - } - } - return string(anchorName) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE new file mode 100644 index 00000000..bc52e96f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2012-2016 Dave Collins + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go new file mode 100644 index 00000000..79299478 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypass.go @@ -0,0 +1,145 @@ +// Copyright (c) 2015-2016 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is not running on Google App Engine, compiled by GopherJS, and +// "-tags safe" is not added to the go build command line. The "disableunsafe" +// tag is deprecated and thus should not be used. +// Go versions prior to 1.4 are disabled because they use a different layout +// for interfaces which make the implementation of unsafeReflectValue more complex. +// +build !js,!appengine,!safe,!disableunsafe,go1.4 + +package spew + +import ( + "reflect" + "unsafe" +) + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = false + + // ptrSize is the size of a pointer on the current arch. + ptrSize = unsafe.Sizeof((*byte)(nil)) +) + +type flag uintptr + +var ( + // flagRO indicates whether the value field of a reflect.Value + // is read-only. + flagRO flag + + // flagAddr indicates whether the address of the reflect.Value's + // value may be taken. + flagAddr flag +) + +// flagKindMask holds the bits that make up the kind +// part of the flags field. In all the supported versions, +// it is in the lower 5 bits. +const flagKindMask = flag(0x1f) + +// Different versions of Go have used different +// bit layouts for the flags type. This table +// records the known combinations. +var okFlags = []struct { + ro, addr flag +}{{ + // From Go 1.4 to 1.5 + ro: 1 << 5, + addr: 1 << 7, +}, { + // Up to Go tip. + ro: 1<<5 | 1<<6, + addr: 1 << 8, +}} + +var flagValOffset = func() uintptr { + field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") + if !ok { + panic("reflect.Value has no flag field") + } + return field.Offset +}() + +// flagField returns a pointer to the flag field of a reflect.Value. +func flagField(v *reflect.Value) *flag { + return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) +} + +// unsafeReflectValue converts the passed reflect.Value into a one that bypasses +// the typical safety restrictions preventing access to unaddressable and +// unexported data. It works by digging the raw pointer to the underlying +// value out of the protected value and generating a new unprotected (unsafe) +// reflect.Value to it. +// +// This allows us to check for implementations of the Stringer and error +// interfaces to be used for pretty printing ordinarily unaddressable and +// inaccessible values such as unexported struct fields. +func unsafeReflectValue(v reflect.Value) reflect.Value { + if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { + return v + } + flagFieldPtr := flagField(&v) + *flagFieldPtr &^= flagRO + *flagFieldPtr |= flagAddr + return v +} + +// Sanity checks against future reflect package changes +// to the type or semantics of the Value.flag field. +func init() { + field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") + if !ok { + panic("reflect.Value has no flag field") + } + if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { + panic("reflect.Value flag field has changed kind") + } + type t0 int + var t struct { + A t0 + // t0 will have flagEmbedRO set. + t0 + // a will have flagStickyRO set + a t0 + } + vA := reflect.ValueOf(t).FieldByName("A") + va := reflect.ValueOf(t).FieldByName("a") + vt0 := reflect.ValueOf(t).FieldByName("t0") + + // Infer flagRO from the difference between the flags + // for the (otherwise identical) fields in t. + flagPublic := *flagField(&vA) + flagWithRO := *flagField(&va) | *flagField(&vt0) + flagRO = flagPublic ^ flagWithRO + + // Infer flagAddr from the difference between a value + // taken from a pointer and not. + vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") + flagNoPtr := *flagField(&vA) + flagPtr := *flagField(&vPtrA) + flagAddr = flagNoPtr ^ flagPtr + + // Check that the inferred flags tally with one of the known versions. + for _, f := range okFlags { + if flagRO == f.ro && flagAddr == f.addr { + return + } + } + panic("reflect.Value read-only flag has changed semantics") +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go new file mode 100644 index 00000000..205c28d6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go @@ -0,0 +1,38 @@ +// Copyright (c) 2015-2016 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is running on Google App Engine, compiled by GopherJS, or +// "-tags safe" is added to the go build command line. The "disableunsafe" +// tag is deprecated and thus should not be used. +// +build js appengine safe disableunsafe !go1.4 + +package spew + +import "reflect" + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = true +) + +// unsafeReflectValue typically converts the passed reflect.Value into a one +// that bypasses the typical safety restrictions preventing access to +// unaddressable and unexported data. However, doing this relies on access to +// the unsafe package. This is a stub version which simply returns the passed +// reflect.Value when the unsafe package is not available. +func unsafeReflectValue(v reflect.Value) reflect.Value { + return v +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go new file mode 100644 index 00000000..1be8ce94 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/common.go @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "io" + "reflect" + "sort" + "strconv" +) + +// Some constants in the form of bytes to avoid string overhead. This mirrors +// the technique used in the fmt package. +var ( + panicBytes = []byte("(PANIC=") + plusBytes = []byte("+") + iBytes = []byte("i") + trueBytes = []byte("true") + falseBytes = []byte("false") + interfaceBytes = []byte("(interface {})") + commaNewlineBytes = []byte(",\n") + newlineBytes = []byte("\n") + openBraceBytes = []byte("{") + openBraceNewlineBytes = []byte("{\n") + closeBraceBytes = []byte("}") + asteriskBytes = []byte("*") + colonBytes = []byte(":") + colonSpaceBytes = []byte(": ") + openParenBytes = []byte("(") + closeParenBytes = []byte(")") + spaceBytes = []byte(" ") + pointerChainBytes = []byte("->") + nilAngleBytes = []byte("") + maxNewlineBytes = []byte("\n") + maxShortBytes = []byte("") + circularBytes = []byte("") + circularShortBytes = []byte("") + invalidAngleBytes = []byte("") + openBracketBytes = []byte("[") + closeBracketBytes = []byte("]") + percentBytes = []byte("%") + precisionBytes = []byte(".") + openAngleBytes = []byte("<") + closeAngleBytes = []byte(">") + openMapBytes = []byte("map[") + closeMapBytes = []byte("]") + lenEqualsBytes = []byte("len=") + capEqualsBytes = []byte("cap=") +) + +// hexDigits is used to map a decimal value to a hex digit. +var hexDigits = "0123456789abcdef" + +// catchPanic handles any panics that might occur during the handleMethods +// calls. +func catchPanic(w io.Writer, v reflect.Value) { + if err := recover(); err != nil { + w.Write(panicBytes) + fmt.Fprintf(w, "%v", err) + w.Write(closeParenBytes) + } +} + +// handleMethods attempts to call the Error and String methods on the underlying +// type the passed reflect.Value represents and outputes the result to Writer w. +// +// It handles panics in any called methods by catching and displaying the error +// as the formatted value. +func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { + // We need an interface to check if the type implements the error or + // Stringer interface. However, the reflect package won't give us an + // interface on certain things like unexported struct fields in order + // to enforce visibility rules. We use unsafe, when it's available, + // to bypass these restrictions since this package does not mutate the + // values. + if !v.CanInterface() { + if UnsafeDisabled { + return false + } + + v = unsafeReflectValue(v) + } + + // Choose whether or not to do error and Stringer interface lookups against + // the base type or a pointer to the base type depending on settings. + // Technically calling one of these methods with a pointer receiver can + // mutate the value, however, types which choose to satisify an error or + // Stringer interface with a pointer receiver should not be mutating their + // state inside these interface methods. + if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { + v = unsafeReflectValue(v) + } + if v.CanAddr() { + v = v.Addr() + } + + // Is it an error or Stringer? + switch iface := v.Interface().(type) { + case error: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.Error())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + + w.Write([]byte(iface.Error())) + return true + + case fmt.Stringer: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.String())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + w.Write([]byte(iface.String())) + return true + } + return false +} + +// printBool outputs a boolean value as true or false to Writer w. +func printBool(w io.Writer, val bool) { + if val { + w.Write(trueBytes) + } else { + w.Write(falseBytes) + } +} + +// printInt outputs a signed integer value to Writer w. +func printInt(w io.Writer, val int64, base int) { + w.Write([]byte(strconv.FormatInt(val, base))) +} + +// printUint outputs an unsigned integer value to Writer w. +func printUint(w io.Writer, val uint64, base int) { + w.Write([]byte(strconv.FormatUint(val, base))) +} + +// printFloat outputs a floating point value using the specified precision, +// which is expected to be 32 or 64bit, to Writer w. +func printFloat(w io.Writer, val float64, precision int) { + w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) +} + +// printComplex outputs a complex value using the specified float precision +// for the real and imaginary parts to Writer w. +func printComplex(w io.Writer, c complex128, floatPrecision int) { + r := real(c) + w.Write(openParenBytes) + w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) + i := imag(c) + if i >= 0 { + w.Write(plusBytes) + } + w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) + w.Write(iBytes) + w.Write(closeParenBytes) +} + +// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' +// prefix to Writer w. +func printHexPtr(w io.Writer, p uintptr) { + // Null pointer. + num := uint64(p) + if num == 0 { + w.Write(nilAngleBytes) + return + } + + // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix + buf := make([]byte, 18) + + // It's simpler to construct the hex string right to left. + base := uint64(16) + i := len(buf) - 1 + for num >= base { + buf[i] = hexDigits[num%base] + num /= base + i-- + } + buf[i] = hexDigits[num] + + // Add '0x' prefix. + i-- + buf[i] = 'x' + i-- + buf[i] = '0' + + // Strip unused leading bytes. + buf = buf[i:] + w.Write(buf) +} + +// valuesSorter implements sort.Interface to allow a slice of reflect.Value +// elements to be sorted. +type valuesSorter struct { + values []reflect.Value + strings []string // either nil or same len and values + cs *ConfigState +} + +// newValuesSorter initializes a valuesSorter instance, which holds a set of +// surrogate keys on which the data should be sorted. It uses flags in +// ConfigState to decide if and how to populate those surrogate keys. +func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { + vs := &valuesSorter{values: values, cs: cs} + if canSortSimply(vs.values[0].Kind()) { + return vs + } + if !cs.DisableMethods { + vs.strings = make([]string, len(values)) + for i := range vs.values { + b := bytes.Buffer{} + if !handleMethods(cs, &b, vs.values[i]) { + vs.strings = nil + break + } + vs.strings[i] = b.String() + } + } + if vs.strings == nil && cs.SpewKeys { + vs.strings = make([]string, len(values)) + for i := range vs.values { + vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) + } + } + return vs +} + +// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted +// directly, or whether it should be considered for sorting by surrogate keys +// (if the ConfigState allows it). +func canSortSimply(kind reflect.Kind) bool { + // This switch parallels valueSortLess, except for the default case. + switch kind { + case reflect.Bool: + return true + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + return true + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return true + case reflect.Float32, reflect.Float64: + return true + case reflect.String: + return true + case reflect.Uintptr: + return true + case reflect.Array: + return true + } + return false +} + +// Len returns the number of values in the slice. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Len() int { + return len(s.values) +} + +// Swap swaps the values at the passed indices. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Swap(i, j int) { + s.values[i], s.values[j] = s.values[j], s.values[i] + if s.strings != nil { + s.strings[i], s.strings[j] = s.strings[j], s.strings[i] + } +} + +// valueSortLess returns whether the first value should sort before the second +// value. It is used by valueSorter.Less as part of the sort.Interface +// implementation. +func valueSortLess(a, b reflect.Value) bool { + switch a.Kind() { + case reflect.Bool: + return !a.Bool() && b.Bool() + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + return a.Int() < b.Int() + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return a.Uint() < b.Uint() + case reflect.Float32, reflect.Float64: + return a.Float() < b.Float() + case reflect.String: + return a.String() < b.String() + case reflect.Uintptr: + return a.Uint() < b.Uint() + case reflect.Array: + // Compare the contents of both arrays. + l := a.Len() + for i := 0; i < l; i++ { + av := a.Index(i) + bv := b.Index(i) + if av.Interface() == bv.Interface() { + continue + } + return valueSortLess(av, bv) + } + } + return a.String() < b.String() +} + +// Less returns whether the value at index i should sort before the +// value at index j. It is part of the sort.Interface implementation. +func (s *valuesSorter) Less(i, j int) bool { + if s.strings == nil { + return valueSortLess(s.values[i], s.values[j]) + } + return s.strings[i] < s.strings[j] +} + +// sortValues is a sort function that handles both native types and any type that +// can be converted to error or Stringer. Other inputs are sorted according to +// their Value.String() value to ensure display stability. +func sortValues(values []reflect.Value, cs *ConfigState) { + if len(values) == 0 { + return + } + sort.Sort(newValuesSorter(values, cs)) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/config.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/config.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/config.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/config.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/doc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go new file mode 100644 index 00000000..f78d89fc --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/dump.go @@ -0,0 +1,509 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "encoding/hex" + "fmt" + "io" + "os" + "reflect" + "regexp" + "strconv" + "strings" +) + +var ( + // uint8Type is a reflect.Type representing a uint8. It is used to + // convert cgo types to uint8 slices for hexdumping. + uint8Type = reflect.TypeOf(uint8(0)) + + // cCharRE is a regular expression that matches a cgo char. + // It is used to detect character arrays to hexdump them. + cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`) + + // cUnsignedCharRE is a regular expression that matches a cgo unsigned + // char. It is used to detect unsigned character arrays to hexdump + // them. + cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`) + + // cUint8tCharRE is a regular expression that matches a cgo uint8_t. + // It is used to detect uint8_t arrays to hexdump them. + cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`) +) + +// dumpState contains information about the state of a dump operation. +type dumpState struct { + w io.Writer + depth int + pointers map[uintptr]int + ignoreNextType bool + ignoreNextIndent bool + cs *ConfigState +} + +// indent performs indentation according to the depth level and cs.Indent +// option. +func (d *dumpState) indent() { + if d.ignoreNextIndent { + d.ignoreNextIndent = false + return + } + d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) +} + +// unpackValue returns values inside of non-nil interfaces when possible. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface && !v.IsNil() { + v = v.Elem() + } + return v +} + +// dumpPtr handles formatting of pointers by indirecting them as necessary. +func (d *dumpState) dumpPtr(v reflect.Value) { + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range d.pointers { + if depth >= d.depth { + delete(d.pointers, k) + } + } + + // Keep list of all dereferenced pointers to show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by dereferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := d.pointers[addr]; ok && pd < d.depth { + cycleFound = true + indirects-- + break + } + d.pointers[addr] = d.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type information. + d.w.Write(openParenBytes) + d.w.Write(bytes.Repeat(asteriskBytes, indirects)) + d.w.Write([]byte(ve.Type().String())) + d.w.Write(closeParenBytes) + + // Display pointer information. + if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { + d.w.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + d.w.Write(pointerChainBytes) + } + printHexPtr(d.w, addr) + } + d.w.Write(closeParenBytes) + } + + // Display dereferenced value. + d.w.Write(openParenBytes) + switch { + case nilFound: + d.w.Write(nilAngleBytes) + + case cycleFound: + d.w.Write(circularBytes) + + default: + d.ignoreNextType = true + d.dump(ve) + } + d.w.Write(closeParenBytes) +} + +// dumpSlice handles formatting of arrays and slices. Byte (uint8 under +// reflection) arrays and slices are dumped in hexdump -C fashion. +func (d *dumpState) dumpSlice(v reflect.Value) { + // Determine whether this type should be hex dumped or not. Also, + // for types which should be hexdumped, try to use the underlying data + // first, then fall back to trying to convert them to a uint8 slice. + var buf []uint8 + doConvert := false + doHexDump := false + numEntries := v.Len() + if numEntries > 0 { + vt := v.Index(0).Type() + vts := vt.String() + switch { + // C types that need to be converted. + case cCharRE.MatchString(vts): + fallthrough + case cUnsignedCharRE.MatchString(vts): + fallthrough + case cUint8tCharRE.MatchString(vts): + doConvert = true + + // Try to use existing uint8 slices and fall back to converting + // and copying if that fails. + case vt.Kind() == reflect.Uint8: + // We need an addressable interface to convert the type + // to a byte slice. However, the reflect package won't + // give us an interface on certain things like + // unexported struct fields in order to enforce + // visibility rules. We use unsafe, when available, to + // bypass these restrictions since this package does not + // mutate the values. + vs := v + if !vs.CanInterface() || !vs.CanAddr() { + vs = unsafeReflectValue(vs) + } + if !UnsafeDisabled { + vs = vs.Slice(0, numEntries) + + // Use the existing uint8 slice if it can be + // type asserted. + iface := vs.Interface() + if slice, ok := iface.([]uint8); ok { + buf = slice + doHexDump = true + break + } + } + + // The underlying data needs to be converted if it can't + // be type asserted to a uint8 slice. + doConvert = true + } + + // Copy and convert the underlying type if needed. + if doConvert && vt.ConvertibleTo(uint8Type) { + // Convert and copy each element into a uint8 byte + // slice. + buf = make([]uint8, numEntries) + for i := 0; i < numEntries; i++ { + vv := v.Index(i) + buf[i] = uint8(vv.Convert(uint8Type).Uint()) + } + doHexDump = true + } + } + + // Hexdump the entire slice as needed. + if doHexDump { + indent := strings.Repeat(d.cs.Indent, d.depth) + str := indent + hex.Dump(buf) + str = strings.Replace(str, "\n", "\n"+indent, -1) + str = strings.TrimRight(str, d.cs.Indent) + d.w.Write([]byte(str)) + return + } + + // Recursively call dump for each item. + for i := 0; i < numEntries; i++ { + d.dump(d.unpackValue(v.Index(i))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } +} + +// dump is the main workhorse for dumping a value. It uses the passed reflect +// value to figure out what kind of object we are dealing with and formats it +// appropriately. It is a recursive function, however circular data structures +// are detected and handled properly. +func (d *dumpState) dump(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + d.w.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + d.indent() + d.dumpPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !d.ignoreNextType { + d.indent() + d.w.Write(openParenBytes) + d.w.Write([]byte(v.Type().String())) + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + d.ignoreNextType = false + + // Display length and capacity if the built-in len and cap functions + // work with the value's kind and the len/cap itself is non-zero. + valueLen, valueCap := 0, 0 + switch v.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + valueLen, valueCap = v.Len(), v.Cap() + case reflect.Map, reflect.String: + valueLen = v.Len() + } + if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 { + d.w.Write(openParenBytes) + if valueLen != 0 { + d.w.Write(lenEqualsBytes) + printInt(d.w, int64(valueLen), 10) + } + if !d.cs.DisableCapacities && valueCap != 0 { + if valueLen != 0 { + d.w.Write(spaceBytes) + } + d.w.Write(capEqualsBytes) + printInt(d.w, int64(valueCap), 10) + } + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + + // Call Stringer/error interfaces if they exist and the handle methods flag + // is enabled + if !d.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(d.cs, d.w, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(d.w, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(d.w, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(d.w, v.Uint(), 10) + + case reflect.Float32: + printFloat(d.w, v.Float(), 32) + + case reflect.Float64: + printFloat(d.w, v.Float(), 64) + + case reflect.Complex64: + printComplex(d.w, v.Complex(), 32) + + case reflect.Complex128: + printComplex(d.w, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + d.dumpSlice(v) + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.String: + d.w.Write([]byte(strconv.Quote(v.String()))) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + d.w.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + numEntries := v.Len() + keys := v.MapKeys() + if d.cs.SortKeys { + sortValues(keys, d.cs) + } + for i, key := range keys { + d.dump(d.unpackValue(key)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.MapIndex(key))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Struct: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + vt := v.Type() + numFields := v.NumField() + for i := 0; i < numFields; i++ { + d.indent() + vtf := vt.Field(i) + d.w.Write([]byte(vtf.Name)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.Field(i))) + if i < (numFields - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(d.w, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(d.w, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it in case any new + // types are added. + default: + if v.CanInterface() { + fmt.Fprintf(d.w, "%v", v.Interface()) + } else { + fmt.Fprintf(d.w, "%v", v.String()) + } + } +} + +// fdump is a helper function to consolidate the logic from the various public +// methods which take varying writers and config states. +func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { + for _, arg := range a { + if arg == nil { + w.Write(interfaceBytes) + w.Write(spaceBytes) + w.Write(nilAngleBytes) + w.Write(newlineBytes) + continue + } + + d := dumpState{w: w, cs: cs} + d.pointers = make(map[uintptr]int) + d.dump(reflect.ValueOf(arg)) + d.w.Write(newlineBytes) + } +} + +// Fdump formats and displays the passed arguments to io.Writer w. It formats +// exactly the same as Dump. +func Fdump(w io.Writer, a ...interface{}) { + fdump(&Config, w, a...) +} + +// Sdump returns a string with the passed arguments formatted exactly the same +// as Dump. +func Sdump(a ...interface{}) string { + var buf bytes.Buffer + fdump(&Config, &buf, a...) + return buf.String() +} + +/* +Dump displays the passed parameters to standard out with newlines, customizable +indentation, and additional debug information such as complete types and all +pointer addresses used to indirect to the final value. It provides the +following features over the built-in printing facilities provided by the fmt +package: + + * Pointers are dereferenced and followed + * Circular data structures are detected and handled properly + * Custom Stringer/error interfaces are optionally invoked, including + on unexported types + * Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + * Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output + +The configuration options are controlled by an exported package global, +spew.Config. See ConfigState for options documentation. + +See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to +get the formatted result as a string. +*/ +func Dump(a ...interface{}) { + fdump(&Config, os.Stdout, a...) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go new file mode 100644 index 00000000..b04edb7d --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/format.go @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "reflect" + "strconv" + "strings" +) + +// supportedFlags is a list of all the character flags supported by fmt package. +const supportedFlags = "0-+# " + +// formatState implements the fmt.Formatter interface and contains information +// about the state of a formatting operation. The NewFormatter function can +// be used to get a new Formatter which can be used directly as arguments +// in standard fmt package printing calls. +type formatState struct { + value interface{} + fs fmt.State + depth int + pointers map[uintptr]int + ignoreNextType bool + cs *ConfigState +} + +// buildDefaultFormat recreates the original format string without precision +// and width information to pass in to fmt.Sprintf in the case of an +// unrecognized type. Unless new types are added to the language, this +// function won't ever be called. +func (f *formatState) buildDefaultFormat() (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + buf.WriteRune('v') + + format = buf.String() + return format +} + +// constructOrigFormat recreates the original format string including precision +// and width information to pass along to the standard fmt package. This allows +// automatic deferral of all format strings this package doesn't support. +func (f *formatState) constructOrigFormat(verb rune) (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + if width, ok := f.fs.Width(); ok { + buf.WriteString(strconv.Itoa(width)) + } + + if precision, ok := f.fs.Precision(); ok { + buf.Write(precisionBytes) + buf.WriteString(strconv.Itoa(precision)) + } + + buf.WriteRune(verb) + + format = buf.String() + return format +} + +// unpackValue returns values inside of non-nil interfaces when possible and +// ensures that types for values which have been unpacked from an interface +// are displayed when the show types flag is also set. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (f *formatState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface { + f.ignoreNextType = false + if !v.IsNil() { + v = v.Elem() + } + } + return v +} + +// formatPtr handles formatting of pointers by indirecting them as necessary. +func (f *formatState) formatPtr(v reflect.Value) { + // Display nil if top level pointer is nil. + showTypes := f.fs.Flag('#') + if v.IsNil() && (!showTypes || f.ignoreNextType) { + f.fs.Write(nilAngleBytes) + return + } + + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range f.pointers { + if depth >= f.depth { + delete(f.pointers, k) + } + } + + // Keep list of all dereferenced pointers to possibly show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by derferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := f.pointers[addr]; ok && pd < f.depth { + cycleFound = true + indirects-- + break + } + f.pointers[addr] = f.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type or indirection level depending on flags. + if showTypes && !f.ignoreNextType { + f.fs.Write(openParenBytes) + f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) + f.fs.Write([]byte(ve.Type().String())) + f.fs.Write(closeParenBytes) + } else { + if nilFound || cycleFound { + indirects += strings.Count(ve.Type().String(), "*") + } + f.fs.Write(openAngleBytes) + f.fs.Write([]byte(strings.Repeat("*", indirects))) + f.fs.Write(closeAngleBytes) + } + + // Display pointer information depending on flags. + if f.fs.Flag('+') && (len(pointerChain) > 0) { + f.fs.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + f.fs.Write(pointerChainBytes) + } + printHexPtr(f.fs, addr) + } + f.fs.Write(closeParenBytes) + } + + // Display dereferenced value. + switch { + case nilFound: + f.fs.Write(nilAngleBytes) + + case cycleFound: + f.fs.Write(circularShortBytes) + + default: + f.ignoreNextType = true + f.format(ve) + } +} + +// format is the main workhorse for providing the Formatter interface. It +// uses the passed reflect value to figure out what kind of object we are +// dealing with and formats it appropriately. It is a recursive function, +// however circular data structures are detected and handled properly. +func (f *formatState) format(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + f.fs.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + f.formatPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !f.ignoreNextType && f.fs.Flag('#') { + f.fs.Write(openParenBytes) + f.fs.Write([]byte(v.Type().String())) + f.fs.Write(closeParenBytes) + } + f.ignoreNextType = false + + // Call Stringer/error interfaces if they exist and the handle methods + // flag is enabled. + if !f.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(f.cs, f.fs, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(f.fs, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(f.fs, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(f.fs, v.Uint(), 10) + + case reflect.Float32: + printFloat(f.fs, v.Float(), 32) + + case reflect.Float64: + printFloat(f.fs, v.Float(), 64) + + case reflect.Complex64: + printComplex(f.fs, v.Complex(), 32) + + case reflect.Complex128: + printComplex(f.fs, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + f.fs.Write(openBracketBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + numEntries := v.Len() + for i := 0; i < numEntries; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(v.Index(i))) + } + } + f.depth-- + f.fs.Write(closeBracketBytes) + + case reflect.String: + f.fs.Write([]byte(v.String())) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + f.fs.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + + f.fs.Write(openMapBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + keys := v.MapKeys() + if f.cs.SortKeys { + sortValues(keys, f.cs) + } + for i, key := range keys { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(key)) + f.fs.Write(colonBytes) + f.ignoreNextType = true + f.format(f.unpackValue(v.MapIndex(key))) + } + } + f.depth-- + f.fs.Write(closeMapBytes) + + case reflect.Struct: + numFields := v.NumField() + f.fs.Write(openBraceBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + vt := v.Type() + for i := 0; i < numFields; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + vtf := vt.Field(i) + if f.fs.Flag('+') || f.fs.Flag('#') { + f.fs.Write([]byte(vtf.Name)) + f.fs.Write(colonBytes) + } + f.format(f.unpackValue(v.Field(i))) + } + } + f.depth-- + f.fs.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(f.fs, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(f.fs, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it if any get added. + default: + format := f.buildDefaultFormat() + if v.CanInterface() { + fmt.Fprintf(f.fs, format, v.Interface()) + } else { + fmt.Fprintf(f.fs, format, v.String()) + } + } +} + +// Format satisfies the fmt.Formatter interface. See NewFormatter for usage +// details. +func (f *formatState) Format(fs fmt.State, verb rune) { + f.fs = fs + + // Use standard formatting for verbs that are not v. + if verb != 'v' { + format := f.constructOrigFormat(verb) + fmt.Fprintf(fs, format, f.value) + return + } + + if f.value == nil { + if fs.Flag('#') { + fs.Write(interfaceBytes) + } + fs.Write(nilAngleBytes) + return + } + + f.format(reflect.ValueOf(f.value)) +} + +// newFormatter is a helper function to consolidate the logic from the various +// public methods which take varying config states. +func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { + fs := &formatState{value: v, cs: cs} + fs.pointers = make(map[uintptr]int) + return fs +} + +/* +NewFormatter returns a custom formatter that satisfies the fmt.Formatter +interface. As a result, it integrates cleanly with standard fmt package +printing functions. The formatter is useful for inline printing of smaller data +types similar to the standard %v format specifier. + +The custom formatter only responds to the %v (most compact), %+v (adds pointer +addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb +combinations. Any other verbs such as %x and %q will be sent to the the +standard fmt package for formatting. In addition, the custom formatter ignores +the width and precision arguments (however they will still work on the format +specifiers not handled by the custom formatter). + +Typically this function shouldn't be called directly. It is much easier to make +use of the custom formatter by calling one of the convenience functions such as +Printf, Println, or Fprintf. +*/ +func NewFormatter(v interface{}) fmt.Formatter { + return newFormatter(&Config, v) +} diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/spew.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/spew.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew/spew.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/davecgh/go-spew/spew/spew.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore new file mode 100644 index 00000000..e256a31e --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.gitignore @@ -0,0 +1,20 @@ +# OSX leaves these everywhere on SMB shares +._* + +# Eclipse files +.classpath +.project +.settings/** + +# Emacs save files +*~ + +# Vim-related files +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist + +# Go test binaries +*.test diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml new file mode 100644 index 00000000..0e9d6edc --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/.travis.yml @@ -0,0 +1,7 @@ +language: go +go: + - 1.3 + - 1.4 +script: + - go test + - go build diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go index 6e7f14fc..4fb4054a 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io" "reflect" "strconv" @@ -27,19 +26,15 @@ func Marshal(o interface{}) ([]byte, error) { return y, nil } -// JSONOpt is a decoding option for decoding from JSON format. -type JSONOpt func(*json.Decoder) *json.Decoder - -// Unmarshal converts YAML to JSON then uses JSON to unmarshal into an object, -// optionally configuring the behavior of the JSON unmarshal. -func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error { +// Converts YAML to JSON then uses JSON to unmarshal into an object. +func Unmarshal(y []byte, o interface{}) error { vo := reflect.ValueOf(o) - j, err := yamlToJSON(y, &vo, yaml.Unmarshal) + j, err := yamlToJSON(y, &vo) if err != nil { return fmt.Errorf("error converting YAML to JSON: %v", err) } - err = jsonUnmarshal(bytes.NewReader(j), o, opts...) + err = json.Unmarshal(j, o) if err != nil { return fmt.Errorf("error unmarshaling JSON: %v", err) } @@ -47,21 +42,6 @@ func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error { return nil } -// jsonUnmarshal unmarshals the JSON byte stream from the given reader into the -// object, optionally applying decoder options prior to decoding. We are not -// using json.Unmarshal directly as we want the chance to pass in non-default -// options. -func jsonUnmarshal(r io.Reader, o interface{}, opts ...JSONOpt) error { - d := json.NewDecoder(r) - for _, opt := range opts { - d = opt(d) - } - if err := d.Decode(&o); err != nil { - return fmt.Errorf("while decoding JSON: %v", err) - } - return nil -} - // Convert JSON to YAML. func JSONToYAML(j []byte) ([]byte, error) { // Convert the JSON to an object. @@ -80,8 +60,8 @@ func JSONToYAML(j []byte) ([]byte, error) { return yaml.Marshal(jsonObj) } -// YAMLToJSON converts YAML to JSON. Since JSON is a subset of YAML, -// passing JSON through this method should be a no-op. +// Convert YAML to JSON. Since JSON is a subset of YAML, passing JSON through +// this method should be a no-op. // // Things YAML can do that are not supported by JSON: // * In YAML you can have binary and null keys in your maps. These are invalid @@ -90,22 +70,14 @@ func JSONToYAML(j []byte) ([]byte, error) { // use binary data with this library, encode the data as base64 as usual but do // not use the !!binary tag in your YAML. This will ensure the original base64 // encoded data makes it all the way through to the JSON. -// -// For strict decoding of YAML, use YAMLToJSONStrict. func YAMLToJSON(y []byte) ([]byte, error) { - return yamlToJSON(y, nil, yaml.Unmarshal) -} - -// YAMLToJSONStrict is like YAMLToJSON but enables strict YAML decoding, -// returning an error on any duplicate field names. -func YAMLToJSONStrict(y []byte) ([]byte, error) { - return yamlToJSON(y, nil, yaml.UnmarshalStrict) + return yamlToJSON(y, nil) } -func yamlToJSON(y []byte, jsonTarget *reflect.Value, yamlUnmarshal func([]byte, interface{}) error) ([]byte, error) { +func yamlToJSON(y []byte, jsonTarget *reflect.Value) ([]byte, error) { // Convert the YAML to an object. var yamlObj interface{} - err := yamlUnmarshal(y, &yamlObj) + err := yaml.Unmarshal(y, &yamlObj) if err != nil { return nil, err } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go deleted file mode 100644 index ab3e06a2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/ghodss/yaml/yaml_go110.go +++ /dev/null @@ -1,14 +0,0 @@ -// This file contains changes that are only compatible with go 1.10 and onwards. - -// +build go1.10 - -package yaml - -import "encoding/json" - -// DisallowUnknownFields configures the JSON decoder to error out if unknown -// fields come along, instead of dropping them by default. -func DisallowUnknownFields(d *json.Decoder) *json.Decoder { - d.DisallowUnknownFields() - return d -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md deleted file mode 100644 index c0751f85..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/CONTRIBUTING.md +++ /dev/null @@ -1,18 +0,0 @@ -# Contributing - -First, thank you for contributing! We love and encourage pull requests from everyone. - -Before submitting major changes, here are a few guidelines to follow: - -1. Check the [open issues][issues] and [pull requests][prs] for existing discussions. -1. Open an [issue][issues] first, to discuss a new feature or enhancement. -1. Write tests, and make sure the test suite passes locally and on CI. -1. Open a pull request, and reference the relevant issue(s). -1. After receiving feedback, [squash your commits][squash] and add a [great commit message][message]. -1. Have fun! - -[issues]: https://github.com/go-kit/kit/issues -[prs]: https://github.com/go-kit/kit/pulls -[squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html -[message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE deleted file mode 100644 index 9d83342a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Peter Bourgon - -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/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md deleted file mode 100644 index a3682408..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/README.md +++ /dev/null @@ -1,120 +0,0 @@ -# Go kit [![Circle CI](https://circleci.com/gh/go-kit/kit.svg?style=shield)](https://circleci.com/gh/go-kit/kit) [![Travis CI](https://travis-ci.org/go-kit/kit.svg?branch=master)](https://travis-ci.org/go-kit/kit) [![GoDoc](https://godoc.org/github.com/go-kit/kit?status.svg)](https://godoc.org/github.com/go-kit/kit) [![Coverage Status](https://coveralls.io/repos/go-kit/kit/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-kit/kit?branch=master) [![Go Report Card](https://goreportcard.com/badge/go-kit/kit)](https://goreportcard.com/report/go-kit/kit) [![Sourcegraph](https://sourcegraph.com/github.com/go-kit/kit/-/badge.svg)](https://sourcegraph.com/github.com/go-kit/kit?badge) - -**Go kit** is a **programming toolkit** for building microservices -(or elegant monoliths) in Go. We solve common problems in distributed -systems and application architecture so you can focus on delivering -business value. - -- Website: [gokit.io](https://gokit.io) -- Mailing list: [go-kit](https://groups.google.com/forum/#!forum/go-kit) -- Slack: [gophers.slack.com](https://gophers.slack.com) **#go-kit** ([invite](https://gophersinvite.herokuapp.com/)) - -## Motivation - -Go has emerged as the language of the server, but it remains underrepresented -in so-called "modern enterprise" companies like Facebook, Twitter, Netflix, and -SoundCloud. Many of these organizations have turned to JVM-based stacks for -their business logic, owing in large part to libraries and ecosystems that -directly support their microservice architectures. - -To reach its next level of success, Go needs more than simple primitives and -idioms. It needs a comprehensive toolkit, for coherent distributed programming -in the large. Go kit is a set of packages and best practices, which provide a -comprehensive, robust, and trustable way of building microservices for -organizations of any size. - -For more details, see - [the website](https://gokit.io), - [the motivating blog post](http://peter.bourgon.org/go-kit/) and - [the video of the talk](https://www.youtube.com/watch?v=iFR_7AKkJFU). -See also the - [Go kit talk at GopherCon 2015](https://www.youtube.com/watch?v=1AjaZi4QuGo). - -## Goals - -- Operate in a heterogeneous SOA — expect to interact with mostly non-Go-kit services -- RPC as the primary messaging pattern -- Pluggable serialization and transport — not just JSON over HTTP -- Operate within existing infrastructures — no mandates for specific tools or technologies - -## Non-goals - -- Supporting messaging patterns other than RPC (for now) — e.g. MPI, pub/sub, CQRS, etc. -- Re-implementing functionality that can be provided by adapting existing software -- Having opinions on operational concerns: deployment, configuration, process supervision, orchestration, etc. - -## Contributing - -Please see [CONTRIBUTING.md](/CONTRIBUTING.md). -Thank you, [contributors](https://github.com/go-kit/kit/graphs/contributors)! - -## Dependency management - -Go kit is a library, designed to be imported into a binary package. Vendoring -is currently the best way for binary package authors to ensure reliable, -reproducible builds. Therefore, we strongly recommend our users use vendoring -for all of their dependencies, including Go kit. To avoid compatibility and -availability issues, Go kit doesn't vendor its own dependencies, and -doesn't recommend use of third-party import proxies. - -There are several tools which make vendoring easier, including - [dep](https://github.com/golang/dep), - [gb](http://getgb.io), - [glide](https://github.com/Masterminds/glide), - [gvt](https://github.com/FiloSottile/gvt), and - [govendor](https://github.com/kardianos/govendor). -In addition, Go kit uses a variety of continuous integration providers - to find and fix compatibility problems as soon as they occur. - -## Related projects - -Projects with a ★ have had particular influence on Go kit's design (or vice-versa). - -### Service frameworks - -- [gizmo](https://github.com/nytimes/gizmo), a microservice toolkit from The New York Times ★ -- [go-micro](https://github.com/myodc/go-micro), a microservices client/server library ★ -- [gotalk](https://github.com/rsms/gotalk), async peer communication protocol & library -- [Kite](https://github.com/koding/kite), a micro-service framework -- [gocircuit](https://github.com/gocircuit/circuit), dynamic cloud orchestration - -### Individual components - -- [afex/hystrix-go](https://github.com/afex/hystrix-go), client-side latency and fault tolerance library -- [armon/go-metrics](https://github.com/armon/go-metrics), library for exporting performance and runtime metrics to external metrics systems -- [codahale/lunk](https://github.com/codahale/lunk), structured logging in the style of Google's Dapper or Twitter's Zipkin -- [eapache/go-resiliency](https://github.com/eapache/go-resiliency), resiliency patterns -- [sasbury/logging](https://github.com/sasbury/logging), a tagged style of logging -- [grpc/grpc-go](https://github.com/grpc/grpc-go), HTTP/2 based RPC -- [inconshreveable/log15](https://github.com/inconshreveable/log15), simple, powerful logging for Go ★ -- [mailgun/vulcand](https://github.com/vulcand/vulcand), programmatic load balancer backed by etcd -- [mattheath/phosphor](https://github.com/mondough/phosphor), distributed system tracing -- [pivotal-golang/lager](https://github.com/pivotal-golang/lager), an opinionated logging library -- [rubyist/circuitbreaker](https://github.com/rubyist/circuitbreaker), circuit breaker library -- [sirupsen/logrus](https://github.com/sirupsen/logrus), structured, pluggable logging for Go ★ -- [sourcegraph/appdash](https://github.com/sourcegraph/appdash), application tracing system based on Google's Dapper -- [spacemonkeygo/monitor](https://github.com/spacemonkeygo/monitor), data collection, monitoring, instrumentation, and Zipkin client library -- [streadway/handy](https://github.com/streadway/handy), net/http handler filters -- [vitess/rpcplus](https://godoc.org/github.com/youtube/vitess/go/rpcplus), package rpc + context.Context -- [gdamore/mangos](https://github.com/gdamore/mangos), nanomsg implementation in pure Go - -### Web frameworks - -- [Gorilla](http://www.gorillatoolkit.org) -- [Gin](https://gin-gonic.github.io/gin/) -- [Negroni](https://github.com/codegangsta/negroni) -- [Goji](https://github.com/zenazn/goji) -- [Martini](https://github.com/go-martini/martini) -- [Beego](http://beego.me/) -- [Revel](https://revel.github.io/) (considered [harmful](https://github.com/go-kit/kit/issues/350)) -- [GoBuffalo](https://gobuffalo.io/) - -## Additional reading - -- [Architecting for the Cloud](https://slideshare.net/stonse/architecting-for-the-cloud-using-netflixoss-codemash-workshop-29852233) — Netflix -- [Dapper, a Large-Scale Distributed Systems Tracing Infrastructure](http://research.google.com/pubs/pub36356.html) — Google -- [Your Server as a Function](http://monkey.org/~marius/funsrv.pdf) (PDF) — Twitter - ---- - -Development supported by [DigitalOcean](https://digitalocean.com). diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md deleted file mode 100644 index 26d6c4b3..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/README.md +++ /dev/null @@ -1,20 +0,0 @@ -This package provides a Basic Authentication middleware. - -It'll try to compare credentials from Authentication request header to a username/password pair in middleware constructor. - -More details about this type of authentication can be found in [Mozilla article](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). - -## Usage - -```go -import httptransport "github.com/go-kit/kit/transport/http" - -httptransport.NewServer( - AuthMiddleware(cfg.auth.user, cfg.auth.password, "Example Realm")(makeUppercaseEndpoint()), - decodeMappingsRequest, - httptransport.EncodeJSONResponse, - httptransport.ServerBefore(httptransport.PopulateRequestContext), - ) -``` - -For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like ```httptransport.ServerBefore(httptransport.PopulateRequestContext)```. \ No newline at end of file diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go deleted file mode 100644 index ad7e4085..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/basic/middleware.go +++ /dev/null @@ -1,94 +0,0 @@ -package basic - -import ( - "bytes" - "context" - "crypto/sha256" - "crypto/subtle" - "encoding/base64" - "fmt" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// AuthError represents an authorization error. -type AuthError struct { - Realm string -} - -// StatusCode is an implementation of the StatusCoder interface in go-kit/http. -func (AuthError) StatusCode() int { - return http.StatusUnauthorized -} - -// Error is an implementation of the Error interface. -func (AuthError) Error() string { - return http.StatusText(http.StatusUnauthorized) -} - -// Headers is an implementation of the Headerer interface in go-kit/http. -func (e AuthError) Headers() http.Header { - return http.Header{ - "Content-Type": []string{"text/plain; charset=utf-8"}, - "X-Content-Type-Options": []string{"nosniff"}, - "WWW-Authenticate": []string{fmt.Sprintf(`Basic realm=%q`, e.Realm)}, - } -} - -// parseBasicAuth parses an HTTP Basic Authentication string. -// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ([]byte("Aladdin"), []byte("open sesame"), true). -func parseBasicAuth(auth string) (username, password []byte, ok bool) { - const prefix = "Basic " - if !strings.HasPrefix(auth, prefix) { - return - } - c, err := base64.StdEncoding.DecodeString(auth[len(prefix):]) - if err != nil { - return - } - - s := bytes.IndexByte(c, ':') - if s < 0 { - return - } - return c[:s], c[s+1:], true -} - -// Returns a hash of a given slice. -func toHashSlice(s []byte) []byte { - hash := sha256.Sum256(s) - return hash[:] -} - -// AuthMiddleware returns a Basic Authentication middleware for a particular user and password. -func AuthMiddleware(requiredUser, requiredPassword, realm string) endpoint.Middleware { - requiredUserBytes := toHashSlice([]byte(requiredUser)) - requiredPasswordBytes := toHashSlice([]byte(requiredPassword)) - - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - auth, ok := ctx.Value(httptransport.ContextKeyRequestAuthorization).(string) - if !ok { - return nil, AuthError{realm} - } - - givenUser, givenPassword, ok := parseBasicAuth(auth) - if !ok { - return nil, AuthError{realm} - } - - givenUserBytes := toHashSlice(givenUser) - givenPasswordBytes := toHashSlice(givenPassword) - - if subtle.ConstantTimeCompare(givenUserBytes, requiredUserBytes) == 0 || - subtle.ConstantTimeCompare(givenPasswordBytes, requiredPasswordBytes) == 0 { - return nil, AuthError{realm} - } - - return next(ctx, request) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md deleted file mode 100644 index 1ed825a9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# package auth/jwt - -`package auth/jwt` provides a set of interfaces for service authorization -through [JSON Web Tokens](https://jwt.io/). - -## Usage - -NewParser takes a key function and an expected signing method and returns an -`endpoint.Middleware`. The middleware will parse a token passed into the -context via the `jwt.JWTTokenContextKey`. If the token is valid, any claims -will be added to the context via the `jwt.JWTClaimsContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - kf := func(token *stdjwt.Token) (interface{}, error) { return []byte("SigningString"), nil } - exampleEndpoint = MakeExampleEndpoint(service) - exampleEndpoint = jwt.NewParser(kf, stdjwt.SigningMethodHS256, jwt.StandardClaimsFactory)(exampleEndpoint) - } -} -``` - -NewSigner takes a JWT key ID header, the signing key, signing method, and a -claims object. It returns an `endpoint.Middleware`. The middleware will build -the token string and add it to the context via the `jwt.JWTTokenContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(...).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -In order for the parser and the signer to work, the authorization headers need -to be passed between the request and the context. `HTTPToContext()`, -`ContextToHTTP()`, `GRPCToContext()`, and `ContextToGRPC()` are given as -helpers to do this. These functions implement the correlating transport's -RequestFunc interface and can be passed as ClientBefore or ServerBefore -options. - -Example of use in a client: - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - grpctransport "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - - options := []httptransport.ClientOption{} - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(..., grpctransport.ClientBefore(jwt.ContextToGRPC())).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -Example of use in a server: - -```go -import ( - "context" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/log" - grpctransport "github.com/go-kit/kit/transport/grpc" -) - -func MakeGRPCServer(ctx context.Context, endpoints Endpoints, logger log.Logger) pb.ExampleServer { - options := []grpctransport.ServerOption{grpctransport.ServerErrorLogger(logger)} - - return &grpcServer{ - createUser: grpctransport.NewServer( - ctx, - endpoints.CreateUserEndpoint, - DecodeGRPCCreateUserRequest, - EncodeGRPCCreateUserResponse, - append(options, grpctransport.ServerBefore(jwt.GRPCToContext()))..., - ), - getUser: grpctransport.NewServer( - ctx, - endpoints.GetUserEndpoint, - DecodeGRPCGetUserRequest, - EncodeGRPCGetUserResponse, - options..., - ), - } -} -``` diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go deleted file mode 100644 index 0e29e6d6..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/middleware.go +++ /dev/null @@ -1,143 +0,0 @@ -package jwt - -import ( - "context" - "errors" - - jwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/endpoint" -) - -type contextKey string - -const ( - // JWTTokenContextKey holds the key used to store a JWT Token in the - // context. - JWTTokenContextKey contextKey = "JWTToken" - - // JWTClaimsContextKey holds the key used to store the JWT Claims in the - // context. - JWTClaimsContextKey contextKey = "JWTClaims" -) - -var ( - // ErrTokenContextMissing denotes a token was not passed into the parsing - // middleware's context. - ErrTokenContextMissing = errors.New("token up for parsing was not passed through the context") - - // ErrTokenInvalid denotes a token was not able to be validated. - ErrTokenInvalid = errors.New("JWT Token was invalid") - - // ErrTokenExpired denotes a token's expire header (exp) has since passed. - ErrTokenExpired = errors.New("JWT Token is expired") - - // ErrTokenMalformed denotes a token was not formatted as a JWT token. - ErrTokenMalformed = errors.New("JWT Token is malformed") - - // ErrTokenNotActive denotes a token's not before header (nbf) is in the - // future. - ErrTokenNotActive = errors.New("token is not valid yet") - - // ErrUnexpectedSigningMethod denotes a token was signed with an unexpected - // signing method. - ErrUnexpectedSigningMethod = errors.New("unexpected signing method") -) - -// NewSigner creates a new JWT token generating middleware, specifying key ID, -// signing string, signing method and the claims you would like it to contain. -// Tokens are signed with a Key ID header (kid) which is useful for determining -// the key to use for parsing. Particularly useful for clients. -func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Claims) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - token := jwt.NewWithClaims(method, claims) - token.Header["kid"] = kid - - // Sign and get the complete encoded token as a string using the secret - tokenString, err := token.SignedString(key) - if err != nil { - return nil, err - } - ctx = context.WithValue(ctx, JWTTokenContextKey, tokenString) - - return next(ctx, request) - } - } -} - -// ClaimsFactory is a factory for jwt.Claims. -// Useful in NewParser middleware. -type ClaimsFactory func() jwt.Claims - -// MapClaimsFactory is a ClaimsFactory that returns -// an empty jwt.MapClaims. -func MapClaimsFactory() jwt.Claims { - return jwt.MapClaims{} -} - -// StandardClaimsFactory is a ClaimsFactory that returns -// an empty jwt.StandardClaims. -func StandardClaimsFactory() jwt.Claims { - return &jwt.StandardClaims{} -} - -// NewParser creates a new JWT token parsing middleware, specifying a -// jwt.Keyfunc interface, the signing method and the claims type to be used. NewParser -// adds the resulting claims to endpoint context or returns error on invalid token. -// Particularly useful for servers. -func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod, newClaims ClaimsFactory) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - // tokenString is stored in the context from the transport handlers. - tokenString, ok := ctx.Value(JWTTokenContextKey).(string) - if !ok { - return nil, ErrTokenContextMissing - } - - // Parse takes the token string and a function for looking up the - // key. The latter is especially useful if you use multiple keys - // for your application. The standard is to use 'kid' in the head - // of the token to identify which key to use, but the parsed token - // (head and claims) is provided to the callback, providing - // flexibility. - token, err := jwt.ParseWithClaims(tokenString, newClaims(), func(token *jwt.Token) (interface{}, error) { - // Don't forget to validate the alg is what you expect: - if token.Method != method { - return nil, ErrUnexpectedSigningMethod - } - - return keyFunc(token) - }) - if err != nil { - if e, ok := err.(*jwt.ValidationError); ok { - switch { - case e.Errors&jwt.ValidationErrorMalformed != 0: - // Token is malformed - return nil, ErrTokenMalformed - case e.Errors&jwt.ValidationErrorExpired != 0: - // Token is expired - return nil, ErrTokenExpired - case e.Errors&jwt.ValidationErrorNotValidYet != 0: - // Token is not active yet - return nil, ErrTokenNotActive - case e.Inner != nil: - // report e.Inner - return nil, e.Inner - } - // We have a ValidationError but have no specific Go kit error for it. - // Fall through to return original error. - } - return nil, err - } - - if !token.Valid { - return nil, ErrTokenInvalid - } - - ctx = context.WithValue(ctx, JWTClaimsContextKey, token.Claims) - - return next(ctx, request) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go deleted file mode 100644 index 57b3aaee..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/auth/jwt/transport.go +++ /dev/null @@ -1,89 +0,0 @@ -package jwt - -import ( - "context" - "fmt" - stdhttp "net/http" - "strings" - - "google.golang.org/grpc/metadata" - - "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/transport/http" -) - -const ( - bearer string = "bearer" - bearerFormat string = "Bearer %s" -) - -// HTTPToContext moves a JWT from request header to context. Particularly -// useful for servers. -func HTTPToContext() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := extractTokenFromAuthHeader(r.Header.Get("Authorization")) - if !ok { - return ctx - } - - return context.WithValue(ctx, JWTTokenContextKey, token) - } -} - -// ContextToHTTP moves a JWT from context to request header. Particularly -// useful for clients. -func ContextToHTTP() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - r.Header.Add("Authorization", generateAuthHeaderFromToken(token)) - } - return ctx - } -} - -// GRPCToContext moves a JWT from grpc metadata to context. Particularly -// userful for servers. -func GRPCToContext() grpc.ServerRequestFunc { - return func(ctx context.Context, md metadata.MD) context.Context { - // capital "Key" is illegal in HTTP/2. - authHeader, ok := md["authorization"] - if !ok { - return ctx - } - - token, ok := extractTokenFromAuthHeader(authHeader[0]) - if ok { - ctx = context.WithValue(ctx, JWTTokenContextKey, token) - } - - return ctx - } -} - -// ContextToGRPC moves a JWT from context to grpc metadata. Particularly -// useful for clients. -func ContextToGRPC() grpc.ClientRequestFunc { - return func(ctx context.Context, md *metadata.MD) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - // capital "Key" is illegal in HTTP/2. - (*md)["authorization"] = []string{generateAuthHeaderFromToken(token)} - } - - return ctx - } -} - -func extractTokenFromAuthHeader(val string) (token string, ok bool) { - authHeaderParts := strings.Split(val, " ") - if len(authHeaderParts) != 2 || strings.ToLower(authHeaderParts[0]) != bearer { - return "", false - } - - return authHeaderParts[1], true -} - -func generateAuthHeaderFromToken(token string) string { - return fmt.Sprintf(bearerFormat, token) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml deleted file mode 100644 index 453528c4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circle.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 - -jobs: - build: - machine: true - working_directory: /home/circleci/.go_workspace/src/github.com/go-kit/kit - environment: - ETCD_ADDR: http://localhost:2379 - CONSUL_ADDR: localhost:8500 - ZK_ADDR: localhost:2181 - EUREKA_ADDR: http://localhost:8761/eureka - steps: - - checkout - - run: docker-compose -f docker-compose-integration.yml up -d --force-recreate - - run: go get -t github.com/go-kit/kit/... - - run: go test -v -race -tags integration github.com/go-kit/kit/... diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go deleted file mode 100644 index fe749575..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// Package circuitbreaker implements the circuit breaker pattern. -// -// Circuit breakers prevent thundering herds, and improve resiliency against -// intermittent errors. Every client-side endpoint should be wrapped in a -// circuit breaker. -// -// We provide several implementations in this package, but if you're looking -// for guidance, Gobreaker is probably the best place to start. It has a -// simple and intuitive API, and is well-tested. -package circuitbreaker diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go deleted file mode 100644 index cf06304f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go +++ /dev/null @@ -1,22 +0,0 @@ -package circuitbreaker - -import ( - "context" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/endpoint" -) - -// Gobreaker returns an endpoint.Middleware that implements the circuit -// breaker pattern using the sony/gobreaker package. Only errors returned by -// the wrapped endpoint count against the circuit breaker's error count. -// -// See http://godoc.org/github.com/sony/gobreaker for more information. -func Gobreaker(cb *gobreaker.CircuitBreaker) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - return cb.Execute(func() (interface{}, error) { return next(ctx, request) }) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go deleted file mode 100644 index a5b60be2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go +++ /dev/null @@ -1,38 +0,0 @@ -package circuitbreaker - -import ( - "context" - "time" - - "github.com/streadway/handy/breaker" - - "github.com/go-kit/kit/endpoint" -) - -// HandyBreaker returns an endpoint.Middleware that implements the circuit -// breaker pattern using the streadway/handy/breaker package. Only errors -// returned by the wrapped endpoint count against the circuit breaker's error -// count. -// -// See http://godoc.org/github.com/streadway/handy/breaker for more -// information. -func HandyBreaker(cb breaker.Breaker) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - if !cb.Allow() { - return nil, breaker.ErrCircuitOpen - } - - defer func(begin time.Time) { - if err == nil { - cb.Success(time.Since(begin)) - } else { - cb.Failure(time.Since(begin)) - } - }(time.Now()) - - response, err = next(ctx, request) - return - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go deleted file mode 100644 index 3c59ec41..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go +++ /dev/null @@ -1,31 +0,0 @@ -package circuitbreaker - -import ( - "context" - - "github.com/afex/hystrix-go/hystrix" - - "github.com/go-kit/kit/endpoint" -) - -// Hystrix returns an endpoint.Middleware that implements the circuit -// breaker pattern using the afex/hystrix-go package. -// -// When using this circuit breaker, please configure your commands separately. -// -// See https://godoc.org/github.com/afex/hystrix-go/hystrix for more -// information. -func Hystrix(commandName string) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - var resp interface{} - if err := hystrix.Do(commandName, func() (err error) { - resp, err = next(ctx, request) - return err - }, nil); err != nil { - return nil, err - } - return resp, nil - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore deleted file mode 100644 index 747f955c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/.ignore +++ /dev/null @@ -1 +0,0 @@ -testdata/*/*/ diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md deleted file mode 100644 index 12cd03e1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# kitgen -kitgen is an experimental code generation utility that helps with some of the -boilerplate code required to implement the "onion" pattern `go-kit` utilizes. - -## Usage -Before using this tool please explore the [testdata]() directory for examples -of the inputs it requires and the outputs that will be produced. _You may not -need this tool._ If you are new to and just learning `go-kit` or if your use -case involves introducing `go-kit` to an existing codebase you are better -suited by slowly building out the "onion" by hand. - -Before starting you need to *install* `kitgen` utility — see instructions below. -1. **Define** your service. Create a `.go` file with the definition of your -Service interface and any of the custom types it refers to: -```go -// service.go -package profilesvc // don't forget to name your package - -type Service interface { - PostProfile(ctx context.Context, p Profile) error - // ... -} -type Profile struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - // ... -} -``` -2. **Generate** your code. Run the following command: -```sh -kitgen ./service.go -# kitgen has a couple of flags that you may find useful - -# keep all code in the root directory -kitgen -repo-layout flat ./service.go - -# put generated code elsewhere -kitgen -target-dir ~/Projects/gohome/src/home.com/kitchenservice/brewcoffee -``` - -## Installation -1. **Fetch** the `inlinefiles` utility. Go generate will use it to create your -code: -``` -go get github.com/nyarly/inlinefiles -``` -2. **Install** the binary for easy access to `kitgen`. Run the following commands: -```sh -cd $GOPATH/src/github.com/go-kit/kit/cmd/kitgen -go install - -# Check installation by running: -kitgen -h -``` diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go deleted file mode 100644 index bcf4e0a5..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/arg.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import "go/ast" - -type arg struct { - name, asField *ast.Ident - typ ast.Expr -} - -func (a arg) chooseName(scope *ast.Scope) *ast.Ident { - if a.name == nil || scope.Lookup(a.name.Name) != nil { - return inventName(a.typ, scope) - } - return a.name -} - -func (a arg) field(scope *ast.Scope) *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{a.chooseName(scope)}, - Type: a.typ, - } -} - -func (a arg) result() *ast.Field { - return &ast.Field{ - Names: nil, - Type: a.typ, - } -} - -func (a arg) exported() *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{id(export(a.asField.Name))}, - Type: a.typ, - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go deleted file mode 100644 index ab7c277d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_helpers.go +++ /dev/null @@ -1,208 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/parser" - "go/token" - "strings" - "unicode" -) - -func export(s string) string { - return strings.Title(s) -} - -func unexport(s string) string { - first := true - return strings.Map(func(r rune) rune { - if first { - first = false - return unicode.ToLower(r) - } - return r - }, s) -} - -func inventName(t ast.Expr, scope *ast.Scope) *ast.Ident { - n := baseName(t) - for try := 0; ; try++ { - nstr := pickName(n, try) - obj := ast.NewObj(ast.Var, nstr) - if alt := scope.Insert(obj); alt == nil { - return ast.NewIdent(nstr) - } - } -} - -func baseName(t ast.Expr) string { - switch tt := t.(type) { - default: - panic(fmt.Sprintf("don't know how to choose a base name for %T (%[1]v)", tt)) - case *ast.ArrayType: - return "slice" - case *ast.Ident: - return tt.Name - case *ast.SelectorExpr: - return tt.Sel.Name - } -} - -func pickName(base string, idx int) string { - if idx == 0 { - switch base { - default: - return strings.Split(base, "")[0] - case "Context": - return "ctx" - case "error": - return "err" - } - } - return fmt.Sprintf("%s%d", base, idx) -} - -func scopeWith(names ...string) *ast.Scope { - scope := ast.NewScope(nil) - for _, name := range names { - scope.Insert(ast.NewObj(ast.Var, name)) - } - return scope -} - -type visitFn func(ast.Node, func(ast.Node)) - -func (fn visitFn) Visit(node ast.Node, r func(ast.Node)) Visitor { - fn(node, r) - return fn -} - -func replaceIdent(src ast.Node, named string, with ast.Node) ast.Node { - r := visitFn(func(node ast.Node, replaceWith func(ast.Node)) { - switch id := node.(type) { - case *ast.Ident: - if id.Name == named { - replaceWith(with) - } - } - }) - return WalkReplace(r, src) -} - -func replaceLit(src ast.Node, from, to string) ast.Node { - r := visitFn(func(node ast.Node, replaceWith func(ast.Node)) { - switch lit := node.(type) { - case *ast.BasicLit: - if lit.Value == from { - replaceWith(&ast.BasicLit{Value: to}) - } - } - }) - return WalkReplace(r, src) -} - -func fullAST() *ast.File { - full, err := ASTTemplates.Open("full.go") - if err != nil { - panic(err) - } - f, err := parser.ParseFile(token.NewFileSet(), "templates/full.go", full, parser.DeclarationErrors) - if err != nil { - panic(err) - } - return f -} - -func fetchImports() []*ast.ImportSpec { - return fullAST().Imports -} - -func fetchFuncDecl(name string) *ast.FuncDecl { - f := fullAST() - for _, decl := range f.Decls { - if f, ok := decl.(*ast.FuncDecl); ok && f.Name.Name == name { - return f - } - } - panic(fmt.Errorf("No function called %q in 'templates/full.go'", name)) -} - -func id(name string) *ast.Ident { - return ast.NewIdent(name) -} - -func sel(ids ...*ast.Ident) ast.Expr { - switch len(ids) { - default: - return &ast.SelectorExpr{ - X: sel(ids[:len(ids)-1]...), - Sel: ids[len(ids)-1], - } - case 1: - return ids[0] - case 0: - panic("zero ids to sel()") - } -} - -func typeField(t ast.Expr) *ast.Field { - return &ast.Field{Type: t} -} - -func field(n *ast.Ident, t ast.Expr) *ast.Field { - return &ast.Field{ - Names: []*ast.Ident{n}, - Type: t, - } -} - -func fieldList(list ...*ast.Field) *ast.FieldList { - return &ast.FieldList{List: list} -} - -func mappedFieldList(fn func(arg) *ast.Field, args ...arg) *ast.FieldList { - fl := &ast.FieldList{List: []*ast.Field{}} - for _, a := range args { - fl.List = append(fl.List, fn(a)) - } - return fl -} - -func blockStmt(stmts ...ast.Stmt) *ast.BlockStmt { - return &ast.BlockStmt{ - List: stmts, - } -} - -func structDecl(name *ast.Ident, fields *ast.FieldList) ast.Decl { - return typeDecl(&ast.TypeSpec{ - Name: name, - Type: &ast.StructType{ - Fields: fields, - }, - }) -} - -func typeDecl(ts *ast.TypeSpec) ast.Decl { - return &ast.GenDecl{ - Tok: token.TYPE, - Specs: []ast.Spec{ts}, - } -} - -func pasteStmts(body *ast.BlockStmt, idx int, stmts []ast.Stmt) { - list := body.List - prefix := list[:idx] - suffix := make([]ast.Stmt, len(list)-idx-1) - copy(suffix, list[idx+1:]) - - body.List = append(append(prefix, stmts...), suffix...) -} - -func importFor(is *ast.ImportSpec) *ast.GenDecl { - return &ast.GenDecl{Tok: token.IMPORT, Specs: []ast.Spec{is}} -} - -func importSpec(path string) *ast.ImportSpec { - return &ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"` + path + `"`}} -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go deleted file mode 100644 index 13aa87c2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/ast_templates.go +++ /dev/null @@ -1,11 +0,0 @@ -// This file was automatically generated based on the contents of *.tmpl -// If you need to update this file, change the contents of those files -// (or add new ones) and run 'go generate' - -package main - -import "golang.org/x/tools/godoc/vfs/mapfs" - -var ASTTemplates = mapfs.New(map[string]string{ - `full.go`: "package foo\n\nimport (\n \"context\"\n \"encoding/json\"\n \"errors\"\n \"net/http\"\n\n \"github.com/go-kit/kit/endpoint\"\n httptransport \"github.com/go-kit/kit/transport/http\"\n)\n\ntype ExampleService struct {\n}\n\ntype ExampleRequest struct {\n I int\n S string\n}\ntype ExampleResponse struct {\n S string\n Err error\n}\n\ntype Endpoints struct {\n ExampleEndpoint endpoint.Endpoint\n}\n\nfunc (f ExampleService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) {\n panic(errors.New(\"not implemented\"))\n}\n\nfunc makeExampleEndpoint(f ExampleService) endpoint.Endpoint {\n return func(ctx context.Context, request interface{}) (interface{}, error) {\n req := request.(ExampleRequest)\n s, err := f.ExampleEndpoint(ctx, req.I, req.S)\n return ExampleResponse{S: s, Err: err}, nil\n }\n}\n\nfunc inlineHandlerBuilder(m *http.ServeMux, endpoints Endpoints) {\n m.Handle(\"/bar\", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse))\n}\n\nfunc NewHTTPHandler(endpoints Endpoints) http.Handler {\n m := http.NewServeMux()\n inlineHandlerBuilder(m, endpoints)\n return m\n}\n\nfunc DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) {\n var req ExampleRequest\n err := json.NewDecoder(r.Body).Decode(&req)\n return req, err\n}\n\nfunc EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {\n w.Header().Set(\"Content-Type\", \"application/json; charset=utf-8\")\n return json.NewEncoder(w).Encode(response)\n}\n", -}) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go deleted file mode 100644 index 27e2fec3..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/deflayout.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import "path/filepath" - -type deflayout struct { - targetDir string -} - -func (l deflayout) packagePath(sub string) string { - return filepath.Join(l.targetDir, sub) -} - -func (l deflayout) transformAST(ctx *sourceContext) (files, error) { - out := make(outputTree) - - endpoints := out.addFile("endpoints/endpoints.go", "endpoints") - http := out.addFile("http/http.go", "http") - service := out.addFile("service/service.go", "service") - - addImports(endpoints, ctx) - addImports(http, ctx) - addImports(service, ctx) - - for _, typ := range ctx.types { - addType(service, typ) - } - - for _, iface := range ctx.interfaces { //only one... - addStubStruct(service, iface) - - for _, meth := range iface.methods { - addMethod(service, iface, meth) - addRequestStruct(endpoints, meth) - addResponseStruct(endpoints, meth) - addEndpointMaker(endpoints, iface, meth) - } - - addEndpointsStruct(endpoints, iface) - addHTTPHandler(http, iface) - - for _, meth := range iface.methods { - addDecoder(http, meth) - addEncoder(http, meth) - } - - for name := range out { - out[name] = selectify(out[name], "service", iface.stubName().Name, l.packagePath("service")) - for _, meth := range iface.methods { - out[name] = selectify(out[name], "endpoints", meth.requestStructName().Name, l.packagePath("endpoints")) - } - } - } - - for name := range out { - out[name] = selectify(out[name], "endpoints", "Endpoints", l.packagePath("endpoints")) - - for _, typ := range ctx.types { - out[name] = selectify(out[name], "service", typ.Name.Name, l.packagePath("service")) - } - } - - return formatNodes(out) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go deleted file mode 100644 index fedffa4b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/flatlayout.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import "go/ast" - -type flat struct{} - -func (f flat) transformAST(ctx *sourceContext) (files, error) { - root := &ast.File{ - Name: ctx.pkg, - Decls: []ast.Decl{}, - } - - addImports(root, ctx) - - for _, typ := range ctx.types { - addType(root, typ) - } - - for _, iface := range ctx.interfaces { //only one... - addStubStruct(root, iface) - - for _, meth := range iface.methods { - addMethod(root, iface, meth) - addRequestStruct(root, meth) - addResponseStruct(root, meth) - addEndpointMaker(root, iface, meth) - } - - addEndpointsStruct(root, iface) - addHTTPHandler(root, iface) - - for _, meth := range iface.methods { - addDecoder(root, meth) - addEncoder(root, meth) - } - } - - return formatNodes(outputTree{"gokit.go": root}) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go deleted file mode 100644 index 0c984dfc..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/interface.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import "go/ast" - -// because "interface" is a keyword... -type iface struct { - name, stubname, rcvrName *ast.Ident - methods []method -} - -func (i iface) stubName() *ast.Ident { - return i.stubname -} - -func (i iface) stubStructDecl() ast.Decl { - return structDecl(i.stubName(), &ast.FieldList{}) -} - -func (i iface) endpointsStruct() ast.Decl { - fl := &ast.FieldList{} - for _, m := range i.methods { - fl.List = append(fl.List, &ast.Field{Names: []*ast.Ident{m.name}, Type: sel(id("endpoint"), id("Endpoint"))}) - } - return structDecl(id("Endpoints"), fl) -} - -func (i iface) httpHandler() ast.Decl { - handlerFn := fetchFuncDecl("NewHTTPHandler") - - // does this "inlining" process merit a helper akin to replaceIdent? - handleCalls := []ast.Stmt{} - for _, m := range i.methods { - handleCall := fetchFuncDecl("inlineHandlerBuilder").Body.List[0].(*ast.ExprStmt).X.(*ast.CallExpr) - - handleCall = replaceLit(handleCall, `"/bar"`, `"`+m.pathName()+`"`).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "ExampleEndpoint", m.name).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "DecodeExampleRequest", m.decodeFuncName()).(*ast.CallExpr) - handleCall = replaceIdent(handleCall, "EncodeExampleResponse", m.encodeFuncName()).(*ast.CallExpr) - - handleCalls = append(handleCalls, &ast.ExprStmt{X: handleCall}) - } - - pasteStmts(handlerFn.Body, 1, handleCalls) - - return handlerFn -} - -func (i iface) reciever() *ast.Field { - return field(i.receiverName(), i.stubName()) -} - -func (i iface) receiverName() *ast.Ident { - if i.rcvrName != nil { - return i.rcvrName - } - scope := ast.NewScope(nil) - for _, meth := range i.methods { - for _, arg := range meth.params { - if arg.name != nil { - scope.Insert(ast.NewObj(ast.Var, arg.name.Name)) - } - } - for _, arg := range meth.results { - if arg.name != nil { - scope.Insert(ast.NewObj(ast.Var, arg.name.Name)) - } - } - } - return id(unexport(inventName(i.name, scope).Name)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go deleted file mode 100644 index fdfd1fb9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/main.go +++ /dev/null @@ -1,156 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "go/ast" - "go/parser" - "go/token" - "io" - "log" - "os" - "path" - - "github.com/pkg/errors" -) - -// go get github.com/nyarly/inlinefiles -//go:generate inlinefiles --package=main --vfs=ASTTemplates ./templates ast_templates.go - -func usage() string { - return fmt.Sprintf("Usage: %s (try -h)", os.Args[0]) -} - -var ( - help = flag.Bool("h", false, "print this help") - layoutkind = flag.String("repo-layout", "default", "default, flat...") - outdirrel = flag.String("target-dir", ".", "base directory to emit into") - //contextOmittable = flag.Bool("allow-no-context", false, "allow service methods to omit context parameter") -) - -func helpText() { - fmt.Println("USAGE") - fmt.Println(" kitgen [flags] path/to/service.go") - fmt.Println("") - fmt.Println("FLAGS") - flag.PrintDefaults() -} - -func main() { - flag.Parse() - - if *help { - helpText() - os.Exit(0) - } - - outdir := *outdirrel - if !path.IsAbs(*outdirrel) { - wd, err := os.Getwd() - if err != nil { - log.Fatalf("error getting current working directory: %v", err) - } - outdir = path.Join(wd, *outdirrel) - } - - var layout layout - switch *layoutkind { - default: - log.Fatalf("Unrecognized layout kind: %q - try 'default' or 'flat'", *layoutkind) - case "default": - gopath := getGopath() - importBase, err := importPath(outdir, gopath) - if err != nil { - log.Fatal(err) - } - layout = deflayout{targetDir: importBase} - case "flat": - layout = flat{} - } - - if len(os.Args) < 2 { - log.Fatal(usage()) - } - filename := flag.Arg(0) - file, err := os.Open(filename) - if err != nil { - log.Fatalf("error while opening %q: %v", filename, err) - } - - tree, err := process(filename, file, layout) - if err != nil { - log.Fatal(err) - } - - err = splat(outdir, tree) - if err != nil { - log.Fatal(err) - } -} - -func process(filename string, source io.Reader, layout layout) (files, error) { - f, err := parseFile(filename, source) - if err != nil { - return nil, errors.Wrapf(err, "parsing input %q", filename) - } - - context, err := extractContext(f) - if err != nil { - return nil, errors.Wrapf(err, "examining input file %q", filename) - } - - tree, err := layout.transformAST(context) - if err != nil { - return nil, errors.Wrapf(err, "generating AST") - } - return tree, nil -} - -/* - buf, err := formatNode(dest) - if err != nil { - return nil, errors.Wrapf(err, "formatting") - } - return buf, nil -} -*/ - -func parseFile(fname string, source io.Reader) (ast.Node, error) { - f, err := parser.ParseFile(token.NewFileSet(), fname, source, parser.DeclarationErrors) - if err != nil { - return nil, err - } - return f, nil -} - -func extractContext(f ast.Node) (*sourceContext, error) { - context := &sourceContext{} - visitor := &parseVisitor{src: context} - - ast.Walk(visitor, f) - - return context, context.validate() -} - -func splat(dir string, tree files) error { - for fn, buf := range tree { - if err := splatFile(path.Join(dir, fn), buf); err != nil { - return err - } - } - return nil -} - -func splatFile(target string, buf io.Reader) error { - err := os.MkdirAll(path.Dir(target), os.ModePerm) - if err != nil { - return errors.Wrapf(err, "Couldn't create directory for %q", target) - } - f, err := os.Create(target) - if err != nil { - return errors.Wrapf(err, "Couldn't create file %q", target) - } - defer f.Close() - _, err = io.Copy(f, buf) - return errors.Wrapf(err, "Error writing data to file %q", target) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go deleted file mode 100644 index f7a6da1b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/method.go +++ /dev/null @@ -1,220 +0,0 @@ -package main - -import ( - "go/ast" - "go/token" - "strings" -) - -type method struct { - name *ast.Ident - params []arg - results []arg - structsResolved bool -} - -func (m method) definition(ifc iface) ast.Decl { - notImpl := fetchFuncDecl("ExampleEndpoint") - - notImpl.Name = m.name - notImpl.Recv = fieldList(ifc.reciever()) - scope := scopeWith(notImpl.Recv.List[0].Names[0].Name) - notImpl.Type.Params = m.funcParams(scope) - notImpl.Type.Results = m.funcResults() - - return notImpl -} - -func (m method) endpointMaker(ifc iface) ast.Decl { - endpointFn := fetchFuncDecl("makeExampleEndpoint") - scope := scopeWith("ctx", "req", ifc.receiverName().Name) - - anonFunc := endpointFn.Body.List[0].(*ast.ReturnStmt).Results[0].(*ast.FuncLit) - if !m.hasContext() { - // strip context param from endpoint function - anonFunc.Type.Params.List = anonFunc.Type.Params.List[1:] - } - - anonFunc = replaceIdent(anonFunc, "ExampleRequest", m.requestStructName()).(*ast.FuncLit) - callMethod := m.called(ifc, scope, "ctx", "req") - anonFunc.Body.List[1] = callMethod - anonFunc.Body.List[2].(*ast.ReturnStmt).Results[0] = m.wrapResult(callMethod.Lhs) - - endpointFn.Body.List[0].(*ast.ReturnStmt).Results[0] = anonFunc - endpointFn.Name = m.endpointMakerName() - endpointFn.Type.Params = fieldList(ifc.reciever()) - endpointFn.Type.Results = fieldList(typeField(sel(id("endpoint"), id("Endpoint")))) - return endpointFn -} - -func (m method) pathName() string { - return "/" + strings.ToLower(m.name.Name) -} - -func (m method) encodeFuncName() *ast.Ident { - return id("Encode" + m.name.Name + "Response") -} - -func (m method) decodeFuncName() *ast.Ident { - return id("Decode" + m.name.Name + "Request") -} - -func (m method) resultNames(scope *ast.Scope) []*ast.Ident { - ids := []*ast.Ident{} - for _, rz := range m.results { - ids = append(ids, rz.chooseName(scope)) - } - return ids -} - -func (m method) called(ifc iface, scope *ast.Scope, ctxName, spreadStruct string) *ast.AssignStmt { - m.resolveStructNames() - - resNamesExpr := []ast.Expr{} - for _, r := range m.resultNames(scope) { - resNamesExpr = append(resNamesExpr, ast.Expr(r)) - } - - arglist := []ast.Expr{} - if m.hasContext() { - arglist = append(arglist, id(ctxName)) - } - ssid := id(spreadStruct) - for _, f := range m.requestStructFields().List { - arglist = append(arglist, sel(ssid, f.Names[0])) - } - - return &ast.AssignStmt{ - Lhs: resNamesExpr, - Tok: token.DEFINE, - Rhs: []ast.Expr{ - &ast.CallExpr{ - Fun: sel(ifc.receiverName(), m.name), - Args: arglist, - }, - }, - } -} - -func (m method) wrapResult(results []ast.Expr) ast.Expr { - kvs := []ast.Expr{} - m.resolveStructNames() - - for i, a := range m.results { - kvs = append(kvs, &ast.KeyValueExpr{ - Key: ast.NewIdent(export(a.asField.Name)), - Value: results[i], - }) - } - return &ast.CompositeLit{ - Type: m.responseStructName(), - Elts: kvs, - } -} - -func (m method) resolveStructNames() { - if m.structsResolved { - return - } - m.structsResolved = true - scope := ast.NewScope(nil) - for i, p := range m.params { - p.asField = p.chooseName(scope) - m.params[i] = p - } - scope = ast.NewScope(nil) - for i, r := range m.results { - r.asField = r.chooseName(scope) - m.results[i] = r - } -} - -func (m method) decoderFunc() ast.Decl { - fn := fetchFuncDecl("DecodeExampleRequest") - fn.Name = m.decodeFuncName() - fn = replaceIdent(fn, "ExampleRequest", m.requestStructName()).(*ast.FuncDecl) - return fn -} - -func (m method) encoderFunc() ast.Decl { - fn := fetchFuncDecl("EncodeExampleResponse") - fn.Name = m.encodeFuncName() - return fn -} - -func (m method) endpointMakerName() *ast.Ident { - return id("Make" + m.name.Name + "Endpoint") -} - -func (m method) requestStruct() ast.Decl { - m.resolveStructNames() - return structDecl(m.requestStructName(), m.requestStructFields()) -} - -func (m method) responseStruct() ast.Decl { - m.resolveStructNames() - return structDecl(m.responseStructName(), m.responseStructFields()) -} - -func (m method) hasContext() bool { - if len(m.params) < 1 { - return false - } - carg := m.params[0].typ - // ugh. this is maybe okay for the one-off, but a general case for matching - // types would be helpful - if sel, is := carg.(*ast.SelectorExpr); is && sel.Sel.Name == "Context" { - if id, is := sel.X.(*ast.Ident); is && id.Name == "context" { - return true - } - } - return false -} - -func (m method) nonContextParams() []arg { - if m.hasContext() { - return m.params[1:] - } - return m.params -} - -func (m method) funcParams(scope *ast.Scope) *ast.FieldList { - parms := &ast.FieldList{} - if m.hasContext() { - parms.List = []*ast.Field{{ - Names: []*ast.Ident{ast.NewIdent("ctx")}, - Type: sel(id("context"), id("Context")), - }} - scope.Insert(ast.NewObj(ast.Var, "ctx")) - } - parms.List = append(parms.List, mappedFieldList(func(a arg) *ast.Field { - return a.field(scope) - }, m.nonContextParams()...).List...) - return parms -} - -func (m method) funcResults() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.result() - }, m.results...) -} - -func (m method) requestStructName() *ast.Ident { - return id(export(m.name.Name) + "Request") -} - -func (m method) requestStructFields() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.exported() - }, m.nonContextParams()...) -} - -func (m method) responseStructName() *ast.Ident { - return id(export(m.name.Name) + "Response") -} - -func (m method) responseStructFields() *ast.FieldList { - return mappedFieldList(func(a arg) *ast.Field { - return a.exported() - }, m.results...) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go deleted file mode 100644 index aa513134..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/parsevisitor.go +++ /dev/null @@ -1,178 +0,0 @@ -package main - -import ( - "go/ast" -) - -type ( - parseVisitor struct { - src *sourceContext - } - - typeSpecVisitor struct { - src *sourceContext - node *ast.TypeSpec - iface *iface - name *ast.Ident - } - - interfaceTypeVisitor struct { - node *ast.TypeSpec - ts *typeSpecVisitor - methods []method - } - - methodVisitor struct { - depth int - node *ast.TypeSpec - list *[]method - name *ast.Ident - params, results *[]arg - isMethod bool - } - - argListVisitor struct { - list *[]arg - } - - argVisitor struct { - node *ast.TypeSpec - parts []ast.Expr - list *[]arg - } -) - -func (v *parseVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - return v - case *ast.File: - v.src.pkg = rn.Name - return v - case *ast.ImportSpec: - v.src.imports = append(v.src.imports, rn) - return nil - - case *ast.TypeSpec: - switch rn.Type.(type) { - default: - v.src.types = append(v.src.types, rn) - case *ast.InterfaceType: - // can't output interfaces - // because they'd conflict with our implementations - } - return &typeSpecVisitor{src: v.src, node: rn} - } -} - -/* -package foo - -type FooService interface { - Bar(ctx context.Context, i int, s string) (string, error) -} -*/ - -func (v *typeSpecVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - return v - case *ast.Ident: - if v.name == nil { - v.name = rn - } - return v - case *ast.InterfaceType: - return &interfaceTypeVisitor{ts: v, methods: []method{}} - case nil: - if v.iface != nil { - v.iface.name = v.name - sn := *v.name - v.iface.stubname = &sn - v.iface.stubname.Name = v.name.String() - v.src.interfaces = append(v.src.interfaces, *v.iface) - } - return nil - } -} - -func (v *interfaceTypeVisitor) Visit(n ast.Node) ast.Visitor { - switch n.(type) { - default: - return v - case *ast.Field: - return &methodVisitor{list: &v.methods} - case nil: - v.ts.iface = &iface{methods: v.methods} - return nil - } -} - -func (v *methodVisitor) Visit(n ast.Node) ast.Visitor { - switch rn := n.(type) { - default: - v.depth++ - return v - case *ast.Ident: - if rn.IsExported() { - v.name = rn - } - v.depth++ - return v - case *ast.FuncType: - v.depth++ - v.isMethod = true - return v - case *ast.FieldList: - if v.params == nil { - v.params = &[]arg{} - return &argListVisitor{list: v.params} - } - if v.results == nil { - v.results = &[]arg{} - } - return &argListVisitor{list: v.results} - case nil: - v.depth-- - if v.depth == 0 && v.isMethod && v.name != nil { - *v.list = append(*v.list, method{name: v.name, params: *v.params, results: *v.results}) - } - return nil - } -} - -func (v *argListVisitor) Visit(n ast.Node) ast.Visitor { - switch n.(type) { - default: - return nil - case *ast.Field: - return &argVisitor{list: v.list} - } -} - -func (v *argVisitor) Visit(n ast.Node) ast.Visitor { - switch t := n.(type) { - case *ast.CommentGroup, *ast.BasicLit: - return nil - case *ast.Ident: //Expr -> everything, but clarity - if t.Name != "_" { - v.parts = append(v.parts, t) - } - case ast.Expr: - v.parts = append(v.parts, t) - case nil: - names := v.parts[:len(v.parts)-1] - tp := v.parts[len(v.parts)-1] - if len(names) == 0 { - *v.list = append(*v.list, arg{typ: tp}) - return nil - } - for _, n := range names { - *v.list = append(*v.list, arg{ - name: n.(*ast.Ident), - typ: tp, - }) - } - } - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go deleted file mode 100644 index f6b70dcd..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/replacewalk.go +++ /dev/null @@ -1,759 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" -) - -// A Visitor's Visit method is invoked for each node encountered by walkToReplace. -// If the result visitor w is not nil, walkToReplace visits each of the children -// of node with the visitor w, followed by a call of w.Visit(nil). -type Visitor interface { - Visit(node ast.Node, replace func(ast.Node)) (w Visitor) -} - -// Helper functions for common node lists. They may be empty. - -func walkIdentList(v Visitor, list []*ast.Ident) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(*ast.Ident) - }) - } -} - -func walkExprList(v Visitor, list []ast.Expr) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Expr) - }) - } -} - -func walkStmtList(v Visitor, list []ast.Stmt) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Stmt) - }) - } -} - -func walkDeclList(v Visitor, list []ast.Decl) { - for i, x := range list { - walkToReplace(v, x, func(r ast.Node) { - list[i] = r.(ast.Decl) - }) - } -} - -// WalkToReplace traverses an AST in depth-first order: It starts by calling -// v.Visit(node); node must not be nil. If the visitor w returned by -// v.Visit(node) is not nil, walkToReplace is invoked recursively with visitor -// w for each of the non-nil children of node, followed by a call of -// w.Visit(nil). -func WalkReplace(v Visitor, node ast.Node) (replacement ast.Node) { - walkToReplace(v, node, func(r ast.Node) { - replacement = r - }) - return -} - -func walkToReplace(v Visitor, node ast.Node, replace func(ast.Node)) { - if v == nil { - return - } - var replacement ast.Node - repl := func(r ast.Node) { - replacement = r - replace(r) - } - - v = v.Visit(node, repl) - - if replacement != nil { - return - } - - // walk children - // (the order of the cases matches the order - // of the corresponding node types in ast.go) - switch n := node.(type) { - - // These are all leaves, so there's no sub-walk to do. - // We just need to replace them on their parent with a copy. - case *ast.Comment: - cpy := *n - replace(&cpy) - case *ast.BadExpr: - cpy := *n - replace(&cpy) - case *ast.Ident: - cpy := *n - replace(&cpy) - case *ast.BasicLit: - cpy := *n - replace(&cpy) - case *ast.BadDecl: - cpy := *n - replace(&cpy) - case *ast.EmptyStmt: - cpy := *n - replace(&cpy) - case *ast.BadStmt: - cpy := *n - replace(&cpy) - - case *ast.CommentGroup: - cpy := *n - - if n.List != nil { - cpy.List = make([]*ast.Comment, len(n.List)) - copy(cpy.List, n.List) - } - - for i, c := range cpy.List { - walkToReplace(v, c, func(r ast.Node) { - cpy.List[i] = r.(*ast.Comment) - }) - } - replace(&cpy) - - case *ast.Field: - cpy := *n - if n.Names != nil { - cpy.Names = make([]*ast.Ident, len(n.Names)) - copy(cpy.Names, n.Names) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkIdentList(v, cpy.Names) - - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - if cpy.Tag != nil { - walkToReplace(v, cpy.Tag, func(r ast.Node) { - cpy.Tag = r.(*ast.BasicLit) - }) - } - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - replace(&cpy) - - case *ast.FieldList: - cpy := *n - if n.List != nil { - cpy.List = make([]*ast.Field, len(n.List)) - copy(cpy.List, n.List) - } - - for i, f := range cpy.List { - walkToReplace(v, f, func(r ast.Node) { - cpy.List[i] = r.(*ast.Field) - }) - } - - replace(&cpy) - - case *ast.Ellipsis: - cpy := *n - - if cpy.Elt != nil { - walkToReplace(v, cpy.Elt, func(r ast.Node) { - cpy.Elt = r.(ast.Expr) - }) - } - - replace(&cpy) - - case *ast.FuncLit: - cpy := *n - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(*ast.FuncType) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.CompositeLit: - cpy := *n - if n.Elts != nil { - cpy.Elts = make([]ast.Expr, len(n.Elts)) - copy(cpy.Elts, n.Elts) - } - - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - walkExprList(v, cpy.Elts) - - replace(&cpy) - case *ast.ParenExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SelectorExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Sel, func(r ast.Node) { - cpy.Sel = r.(*ast.Ident) - }) - - replace(&cpy) - case *ast.IndexExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Index, func(r ast.Node) { - cpy.Index = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SliceExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - if cpy.Low != nil { - walkToReplace(v, cpy.Low, func(r ast.Node) { - cpy.Low = r.(ast.Expr) - }) - } - if cpy.High != nil { - walkToReplace(v, cpy.High, func(r ast.Node) { - cpy.High = r.(ast.Expr) - }) - } - if cpy.Max != nil { - walkToReplace(v, cpy.Max, func(r ast.Node) { - cpy.Max = r.(ast.Expr) - }) - } - - replace(&cpy) - case *ast.TypeAssertExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - replace(&cpy) - case *ast.CallExpr: - cpy := *n - if n.Args != nil { - cpy.Args = make([]ast.Expr, len(n.Args)) - copy(cpy.Args, n.Args) - } - - walkToReplace(v, cpy.Fun, func(r ast.Node) { - cpy.Fun = r.(ast.Expr) - }) - walkExprList(v, cpy.Args) - - replace(&cpy) - case *ast.StarExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.UnaryExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.BinaryExpr: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Y, func(r ast.Node) { - cpy.Y = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.KeyValueExpr: - cpy := *n - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - - // Types - case *ast.ArrayType: - cpy := *n - if cpy.Len != nil { - walkToReplace(v, cpy.Len, func(r ast.Node) { - cpy.Len = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.Elt, func(r ast.Node) { - cpy.Elt = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.StructType: - cpy := *n - walkToReplace(v, cpy.Fields, func(r ast.Node) { - cpy.Fields = r.(*ast.FieldList) - }) - - replace(&cpy) - case *ast.FuncType: - cpy := *n - if cpy.Params != nil { - walkToReplace(v, cpy.Params, func(r ast.Node) { - cpy.Params = r.(*ast.FieldList) - }) - } - if cpy.Results != nil { - walkToReplace(v, cpy.Results, func(r ast.Node) { - cpy.Results = r.(*ast.FieldList) - }) - } - - replace(&cpy) - case *ast.InterfaceType: - cpy := *n - walkToReplace(v, cpy.Methods, func(r ast.Node) { - cpy.Methods = r.(*ast.FieldList) - }) - - replace(&cpy) - case *ast.MapType: - cpy := *n - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.ChanType: - cpy := *n - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.DeclStmt: - cpy := *n - walkToReplace(v, cpy.Decl, func(r ast.Node) { - cpy.Decl = r.(ast.Decl) - }) - - replace(&cpy) - case *ast.LabeledStmt: - cpy := *n - walkToReplace(v, cpy.Label, func(r ast.Node) { - cpy.Label = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Stmt, func(r ast.Node) { - cpy.Stmt = r.(ast.Stmt) - }) - - replace(&cpy) - case *ast.ExprStmt: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.SendStmt: - cpy := *n - walkToReplace(v, cpy.Chan, func(r ast.Node) { - cpy.Chan = r.(ast.Expr) - }) - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.IncDecStmt: - cpy := *n - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - - replace(&cpy) - case *ast.AssignStmt: - cpy := *n - if n.Lhs != nil { - cpy.Lhs = make([]ast.Expr, len(n.Lhs)) - copy(cpy.Lhs, n.Lhs) - } - if n.Rhs != nil { - cpy.Rhs = make([]ast.Expr, len(n.Rhs)) - copy(cpy.Rhs, n.Rhs) - } - - walkExprList(v, cpy.Lhs) - walkExprList(v, cpy.Rhs) - - replace(&cpy) - case *ast.GoStmt: - cpy := *n - walkToReplace(v, cpy.Call, func(r ast.Node) { - cpy.Call = r.(*ast.CallExpr) - }) - - replace(&cpy) - case *ast.DeferStmt: - cpy := *n - walkToReplace(v, cpy.Call, func(r ast.Node) { - cpy.Call = r.(*ast.CallExpr) - }) - - replace(&cpy) - case *ast.ReturnStmt: - cpy := *n - if n.Results != nil { - cpy.Results = make([]ast.Expr, len(n.Results)) - copy(cpy.Results, n.Results) - } - - walkExprList(v, cpy.Results) - - replace(&cpy) - case *ast.BranchStmt: - cpy := *n - if cpy.Label != nil { - walkToReplace(v, cpy.Label, func(r ast.Node) { - cpy.Label = r.(*ast.Ident) - }) - } - - replace(&cpy) - case *ast.BlockStmt: - cpy := *n - if n.List != nil { - cpy.List = make([]ast.Stmt, len(n.List)) - copy(cpy.List, n.List) - } - - walkStmtList(v, cpy.List) - - replace(&cpy) - case *ast.IfStmt: - cpy := *n - - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Cond, func(r ast.Node) { - cpy.Cond = r.(ast.Expr) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - if cpy.Else != nil { - walkToReplace(v, cpy.Else, func(r ast.Node) { - cpy.Else = r.(ast.Stmt) - }) - } - - replace(&cpy) - case *ast.CaseClause: - cpy := *n - if n.List != nil { - cpy.List = make([]ast.Expr, len(n.List)) - copy(cpy.List, n.List) - } - if n.Body != nil { - cpy.Body = make([]ast.Stmt, len(n.Body)) - copy(cpy.Body, n.Body) - } - - walkExprList(v, cpy.List) - walkStmtList(v, cpy.Body) - - replace(&cpy) - case *ast.SwitchStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - if cpy.Tag != nil { - walkToReplace(v, cpy.Tag, func(r ast.Node) { - cpy.Tag = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.TypeSwitchStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Assign, func(r ast.Node) { - cpy.Assign = r.(ast.Stmt) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.CommClause: - cpy := *n - if n.Body != nil { - cpy.Body = make([]ast.Stmt, len(n.Body)) - copy(cpy.Body, n.Body) - } - - if cpy.Comm != nil { - walkToReplace(v, cpy.Comm, func(r ast.Node) { - cpy.Comm = r.(ast.Stmt) - }) - } - walkStmtList(v, cpy.Body) - - replace(&cpy) - case *ast.SelectStmt: - cpy := *n - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.ForStmt: - cpy := *n - if cpy.Init != nil { - walkToReplace(v, cpy.Init, func(r ast.Node) { - cpy.Init = r.(ast.Stmt) - }) - } - if cpy.Cond != nil { - walkToReplace(v, cpy.Cond, func(r ast.Node) { - cpy.Cond = r.(ast.Expr) - }) - } - if cpy.Post != nil { - walkToReplace(v, cpy.Post, func(r ast.Node) { - cpy.Post = r.(ast.Stmt) - }) - } - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - replace(&cpy) - case *ast.RangeStmt: - cpy := *n - if cpy.Key != nil { - walkToReplace(v, cpy.Key, func(r ast.Node) { - cpy.Key = r.(ast.Expr) - }) - } - if cpy.Value != nil { - walkToReplace(v, cpy.Value, func(r ast.Node) { - cpy.Value = r.(ast.Expr) - }) - } - walkToReplace(v, cpy.X, func(r ast.Node) { - cpy.X = r.(ast.Expr) - }) - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - - // Declarations - replace(&cpy) - case *ast.ImportSpec: - cpy := *n - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - if cpy.Name != nil { - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - } - walkToReplace(v, cpy.Path, func(r ast.Node) { - cpy.Path = r.(*ast.BasicLit) - }) - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - case *ast.ValueSpec: - cpy := *n - if n.Names != nil { - cpy.Names = make([]*ast.Ident, len(n.Names)) - copy(cpy.Names, n.Names) - } - if n.Values != nil { - cpy.Values = make([]ast.Expr, len(n.Values)) - copy(cpy.Values, n.Values) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - - walkIdentList(v, cpy.Names) - - if cpy.Type != nil { - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - } - - walkExprList(v, cpy.Values) - - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - - case *ast.TypeSpec: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(ast.Expr) - }) - if cpy.Comment != nil { - walkToReplace(v, cpy.Comment, func(r ast.Node) { - cpy.Comment = r.(*ast.CommentGroup) - }) - } - - replace(&cpy) - case *ast.GenDecl: - cpy := *n - if n.Specs != nil { - cpy.Specs = make([]ast.Spec, len(n.Specs)) - copy(cpy.Specs, n.Specs) - } - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - for i, s := range cpy.Specs { - walkToReplace(v, s, func(r ast.Node) { - cpy.Specs[i] = r.(ast.Spec) - }) - } - - replace(&cpy) - case *ast.FuncDecl: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - if cpy.Recv != nil { - walkToReplace(v, cpy.Recv, func(r ast.Node) { - cpy.Recv = r.(*ast.FieldList) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkToReplace(v, cpy.Type, func(r ast.Node) { - cpy.Type = r.(*ast.FuncType) - }) - if cpy.Body != nil { - walkToReplace(v, cpy.Body, func(r ast.Node) { - cpy.Body = r.(*ast.BlockStmt) - }) - } - - // Files and packages - replace(&cpy) - case *ast.File: - cpy := *n - - if cpy.Doc != nil { - walkToReplace(v, cpy.Doc, func(r ast.Node) { - cpy.Doc = r.(*ast.CommentGroup) - }) - } - walkToReplace(v, cpy.Name, func(r ast.Node) { - cpy.Name = r.(*ast.Ident) - }) - walkDeclList(v, cpy.Decls) - // don't walk cpy.Comments - they have been - // visited already through the individual - // nodes - - replace(&cpy) - case *ast.Package: - cpy := *n - cpy.Files = map[string]*ast.File{} - - for i, f := range n.Files { - cpy.Files[i] = f - walkToReplace(v, f, func(r ast.Node) { - cpy.Files[i] = r.(*ast.File) - }) - } - replace(&cpy) - - default: - panic(fmt.Sprintf("walkToReplace: unexpected node type %T", n)) - } - - if v != nil { - v.Visit(nil, func(ast.Node) { panic("can't replace the go-up nil") }) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go deleted file mode 100644 index 35933a20..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/sourcecontext.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/token" -) - -type sourceContext struct { - pkg *ast.Ident - imports []*ast.ImportSpec - interfaces []iface - types []*ast.TypeSpec -} - -func (sc *sourceContext) validate() error { - if len(sc.interfaces) != 1 { - return fmt.Errorf("found %d interfaces, expecting exactly 1", len(sc.interfaces)) - } - for _, i := range sc.interfaces { - for _, m := range i.methods { - if len(m.results) < 1 { - return fmt.Errorf("method %q of interface %q has no result types", m.name, i.name) - } - } - } - return nil -} - -func (sc *sourceContext) importDecls() (decls []ast.Decl) { - have := map[string]struct{}{} - notHave := func(is *ast.ImportSpec) bool { - if _, has := have[is.Path.Value]; has { - return false - } - have[is.Path.Value] = struct{}{} - return true - } - - for _, is := range sc.imports { - if notHave(is) { - decls = append(decls, importFor(is)) - } - } - - for _, is := range fetchImports() { - if notHave(is) { - decls = append(decls, &ast.GenDecl{Tok: token.IMPORT, Specs: []ast.Spec{is}}) - } - } - - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go deleted file mode 100644 index c3516856..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/templates/full.go +++ /dev/null @@ -1,60 +0,0 @@ -package foo - -import ( - "context" - "encoding/json" - "errors" - "net/http" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -type ExampleService struct { -} - -type ExampleRequest struct { - I int - S string -} -type ExampleResponse struct { - S string - Err error -} - -type Endpoints struct { - ExampleEndpoint endpoint.Endpoint -} - -func (f ExampleService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) { - panic(errors.New("not implemented")) -} - -func makeExampleEndpoint(f ExampleService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(ExampleRequest) - s, err := f.ExampleEndpoint(ctx, req.I, req.S) - return ExampleResponse{S: s, Err: err}, nil - } -} - -func inlineHandlerBuilder(m *http.ServeMux, endpoints Endpoints) { - m.Handle("/bar", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse)) -} - -func NewHTTPHandler(endpoints Endpoints) http.Handler { - m := http.NewServeMux() - inlineHandlerBuilder(m, endpoints) - return m -} - -func DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req ExampleRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -func EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go deleted file mode 100644 index 362398c9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/cmd/kitgen/transform.go +++ /dev/null @@ -1,230 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "go/ast" - "go/format" - "go/token" - "io" - "os" - "path/filepath" - "sort" - "strings" - - "github.com/davecgh/go-spew/spew" - "github.com/pkg/errors" - - "golang.org/x/tools/imports" -) - -type ( - files map[string]io.Reader - layout interface { - transformAST(ctx *sourceContext) (files, error) - } - outputTree map[string]*ast.File -) - -func (ot outputTree) addFile(path, pkgname string) *ast.File { - file := &ast.File{ - Name: id(pkgname), - Decls: []ast.Decl{}, - } - ot[path] = file - return file -} - -func getGopath() string { - gopath, set := os.LookupEnv("GOPATH") - if !set { - return filepath.Join(os.Getenv("HOME"), "go") - } - return gopath -} - -func importPath(targetDir, gopath string) (string, error) { - if !filepath.IsAbs(targetDir) { - return "", fmt.Errorf("%q is not an absolute path", targetDir) - } - - for _, dir := range filepath.SplitList(gopath) { - abspath, err := filepath.Abs(dir) - if err != nil { - continue - } - srcPath := filepath.Join(abspath, "src") - - res, err := filepath.Rel(srcPath, targetDir) - if err != nil { - continue - } - if strings.Index(res, "..") == -1 { - return res, nil - } - } - return "", fmt.Errorf("%q is not in GOPATH (%s)", targetDir, gopath) - -} - -func selectify(file *ast.File, pkgName, identName, importPath string) *ast.File { - if file.Name.Name == pkgName { - return file - } - - selector := sel(id(pkgName), id(identName)) - var did bool - if file, did = selectifyIdent(identName, file, selector); did { - addImport(file, importPath) - } - return file -} - -type selIdentFn func(ast.Node, func(ast.Node)) Visitor - -func (f selIdentFn) Visit(node ast.Node, r func(ast.Node)) Visitor { - return f(node, r) -} - -func selectifyIdent(identName string, file *ast.File, selector ast.Expr) (*ast.File, bool) { - var replaced bool - var r selIdentFn - r = selIdentFn(func(node ast.Node, replaceWith func(ast.Node)) Visitor { - switch id := node.(type) { - case *ast.SelectorExpr: - return nil - case *ast.Ident: - if id.Name == identName { - replaced = true - replaceWith(selector) - } - } - return r - }) - return WalkReplace(r, file).(*ast.File), replaced -} - -func formatNode(fname string, node ast.Node) (*bytes.Buffer, error) { - if file, is := node.(*ast.File); is { - sort.Stable(sortableDecls(file.Decls)) - } - outfset := token.NewFileSet() - buf := &bytes.Buffer{} - err := format.Node(buf, outfset, node) - if err != nil { - return nil, err - } - imps, err := imports.Process(fname, buf.Bytes(), nil) - if err != nil { - return nil, err - } - return bytes.NewBuffer(imps), nil -} - -type sortableDecls []ast.Decl - -func (sd sortableDecls) Len() int { - return len(sd) -} - -func (sd sortableDecls) Less(i int, j int) bool { - switch left := sd[i].(type) { - case *ast.GenDecl: - switch right := sd[j].(type) { - default: - return left.Tok == token.IMPORT - case *ast.GenDecl: - return left.Tok == token.IMPORT && right.Tok != token.IMPORT - } - } - return false -} - -func (sd sortableDecls) Swap(i int, j int) { - sd[i], sd[j] = sd[j], sd[i] -} - -func formatNodes(nodes outputTree) (files, error) { - res := files{} - var err error - for fn, node := range nodes { - res[fn], err = formatNode(fn, node) - if err != nil { - return nil, errors.Wrapf(err, "formatNodes") - } - } - return res, nil -} - -// XXX debug -func spewDecls(f *ast.File) { - for _, d := range f.Decls { - switch dcl := d.(type) { - default: - spew.Dump(dcl) - case *ast.GenDecl: - spew.Dump(dcl.Tok) - case *ast.FuncDecl: - spew.Dump(dcl.Name.Name) - } - } -} - -func addImports(root *ast.File, ctx *sourceContext) { - root.Decls = append(root.Decls, ctx.importDecls()...) -} - -func addImport(root *ast.File, path string) { - for _, d := range root.Decls { - if imp, is := d.(*ast.GenDecl); is && imp.Tok == token.IMPORT { - for _, s := range imp.Specs { - if s.(*ast.ImportSpec).Path.Value == `"`+path+`"` { - return // already have one - // xxx aliased imports? - } - } - } - } - root.Decls = append(root.Decls, importFor(importSpec(path))) -} - -func addStubStruct(root *ast.File, iface iface) { - root.Decls = append(root.Decls, iface.stubStructDecl()) -} - -func addType(root *ast.File, typ *ast.TypeSpec) { - root.Decls = append(root.Decls, typeDecl(typ)) -} - -func addMethod(root *ast.File, iface iface, meth method) { - def := meth.definition(iface) - root.Decls = append(root.Decls, def) -} - -func addRequestStruct(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.requestStruct()) -} - -func addResponseStruct(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.responseStruct()) -} - -func addEndpointMaker(root *ast.File, ifc iface, meth method) { - root.Decls = append(root.Decls, meth.endpointMaker(ifc)) -} - -func addEndpointsStruct(root *ast.File, ifc iface) { - root.Decls = append(root.Decls, ifc.endpointsStruct()) -} - -func addHTTPHandler(root *ast.File, ifc iface) { - root.Decls = append(root.Decls, ifc.httpHandler()) -} - -func addDecoder(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.decoderFunc()) -} - -func addEncoder(root *ast.File, meth method) { - root.Decls = append(root.Decls, meth.encoderFunc()) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash deleted file mode 100755 index cf8fee93..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/coveralls.bash +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -if ! type -P gover -then - echo gover missing: go get github.com/modocache/gover - exit 1 -fi - -if ! type -P goveralls -then - echo goveralls missing: go get github.com/mattn/goveralls - exit 1 -fi - -if [[ "$COVERALLS_TOKEN" == "" ]] -then - echo COVERALLS_TOKEN not set - exit 1 -fi - -go list ./... | grep -v '/examples/' | cut -d'/' -f 4- | while read d -do - cd $d - go test -covermode count -coverprofile coverage.coverprofile - cd - -done - -gover -goveralls -coverprofile gover.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN -find . -name '*.coverprofile' -delete - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml deleted file mode 100644 index 287d97db..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/docker-compose-integration.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '2' -services: - etcd: - image: quay.io/coreos/etcd - ports: - - "2379:2379" - command: /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001" - consul: - image: progrium/consul - ports: - - "8500:8500" - command: -server -bootstrap - zk: - image: zookeeper - ports: - - "2181:2181" - eureka: - image: springcloud/eureka - environment: - eureka.server.responseCacheUpdateIntervalMs: 1000 - ports: - - "8761:8761" diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go deleted file mode 100644 index 84e27b95..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Package endpoint defines an abstraction for RPCs. -// -// Endpoints are a fundamental building block for many Go kit components. -// Endpoints are implemented by servers, and called by clients. -package endpoint diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go deleted file mode 100644 index 6e9da367..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/endpoint/endpoint.go +++ /dev/null @@ -1,40 +0,0 @@ -package endpoint - -import ( - "context" -) - -// Endpoint is the fundamental building block of servers and clients. -// It represents a single RPC method. -type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error) - -// Nop is an endpoint that does nothing and returns a nil error. -// Useful for tests. -func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil } - -// Middleware is a chainable behavior modifier for endpoints. -type Middleware func(Endpoint) Endpoint - -// Chain is a helper function for composing middlewares. Requests will -// traverse them in the order they're declared. That is, the first middleware -// is treated as the outermost middleware. -func Chain(outer Middleware, others ...Middleware) Middleware { - return func(next Endpoint) Endpoint { - for i := len(others) - 1; i >= 0; i-- { // reverse - next = others[i](next) - } - return outer(next) - } -} - -// Failer may be implemented by Go kit response types that contain business -// logic error details. If Failed returns a non-nil error, the Go kit transport -// layer may interpret this as a business logic error, and may encode it -// differently than a regular, successful response. -// -// It's not necessary for your response types to implement Failer, but it may -// help for more sophisticated use cases. The addsvc example shows how Failer -// should be used by a complete application. -type Failer interface { - Failed() error -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md deleted file mode 100644 index 2891d788..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Examples - -For more information about these examples, - including a walkthrough of the stringsvc example, - see [gokit.io/examples](https://gokit.io/examples). diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md deleted file mode 100644 index 08080060..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# addsvc - -addsvc is an example microservice which takes full advantage of most of Go -kit's features, including both service- and transport-level middlewares, -speaking multiple transports simultaneously, distributed tracing, and rich -error definitions. The server binary is available in cmd/addsvc. The client -binary is available in cmd/addcli. - -Finally, the addtransport package provides both server and clients for each -supported transport. The client structs bake-in certain middlewares, in order to -demonstrate the _client library pattern_. But beware: client libraries are -generally a bad idea, because they easily lead to the - [distributed monolith antipattern](https://www.microservices.com/talks/dont-build-a-distributed-monolith/). -If you don't _know_ you need to use one in your organization, it's probably best -avoided: prefer moving that logic to consumers, and relying on - [contract testing](https://docs.pact.io/best_practices/contract_tests_not_functional_tests.html) -to detect incompatibilities. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go deleted file mode 100644 index 099eb590..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addcli/addcli.go +++ /dev/null @@ -1,226 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "os" - "strconv" - "text/tabwriter" - "time" - - "google.golang.org/grpc" - - "github.com/apache/thrift/lib/go/thrift" - lightstep "github.com/lightstep/lightstep-tracer-go" - stdopentracing "github.com/opentracing/opentracing-go" - zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" - zipkin "github.com/openzipkin/zipkin-go" - zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" - "sourcegraph.com/sourcegraph/appdash" - appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -func main() { - // The addcli presumes no service discovery system, and expects users to - // provide the direct address of an addsvc. This presumption is reflected in - // the addcli binary and the client packages: the -transport.addr flags - // and various client constructors both expect host:port strings. For an - // example service with a client built on top of a service discovery system, - // see profilesvc. - fs := flag.NewFlagSet("addcli", flag.ExitOnError) - var ( - httpAddr = fs.String("http-addr", "", "HTTP address of addsvc") - grpcAddr = fs.String("grpc-addr", "", "gRPC address of addsvc") - thriftAddr = fs.String("thrift-addr", "", "Thrift address of addsvc") - jsonRPCAddr = fs.String("jsonrpc-addr", "", "JSON RPC address of addsvc") - thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") - thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") - thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") - zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) via HTTP Reporter URL e.g. http://localhost:9411/api/v2/spans") - zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) via a collector URL e.g. http://localhost:9411/api/v1/spans") - lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") - appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") - method = fs.String("method", "sum", "sum, concat") - ) - fs.Usage = usageFor(fs, os.Args[0]+" [flags] ") - fs.Parse(os.Args[1:]) - if len(fs.Args()) != 2 { - fs.Usage() - os.Exit(1) - } - - // This is a demonstration client, which supports multiple tracers. - // Your clients will probably just use one tracer. - var otTracer stdopentracing.Tracer - { - if *zipkinV1URL != "" && *zipkinV2URL == "" { - collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - defer collector.Close() - var ( - debug = false - hostPort = "localhost:0" - serviceName = "addsvc-cli" - ) - recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) - otTracer, err = zipkinot.NewTracer(recorder) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - } else if *lightstepToken != "" { - otTracer = lightstep.NewTracer(lightstep.Options{ - AccessToken: *lightstepToken, - }) - defer lightstep.FlushLightStepTracer(otTracer) - } else if *appdashAddr != "" { - otTracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) - } else { - otTracer = stdopentracing.GlobalTracer() // no-op - } - } - - // This is a demonstration of the native Zipkin tracing client. If using - // Zipkin this is the more idiomatic client over OpenTracing. - var zipkinTracer *zipkin.Tracer - { - var ( - err error - hostPort = "" // if host:port is unknown we can keep this empty - serviceName = "addsvc-cli" - useNoopTracer = (*zipkinV2URL == "") - reporter = zipkinhttp.NewReporter(*zipkinV2URL) - ) - defer reporter.Close() - zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) - zipkinTracer, err = zipkin.NewTracer( - reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), - ) - if err != nil { - fmt.Fprintf(os.Stderr, "unable to create zipkin tracer: %s\n", err.Error()) - os.Exit(1) - } - } - - // This is a demonstration client, which supports multiple transports. - // Your clients will probably just define and stick with 1 transport. - var ( - svc addservice.Service - err error - ) - if *httpAddr != "" { - svc, err = addtransport.NewHTTPClient(*httpAddr, otTracer, zipkinTracer, log.NewNopLogger()) - } else if *grpcAddr != "" { - conn, err := grpc.Dial(*grpcAddr, grpc.WithInsecure(), grpc.WithTimeout(time.Second)) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v", err) - os.Exit(1) - } - defer conn.Close() - svc = addtransport.NewGRPCClient(conn, otTracer, zipkinTracer, log.NewNopLogger()) - } else if *jsonRPCAddr != "" { - svc, err = addtransport.NewJSONRPCClient(*jsonRPCAddr, otTracer, log.NewNopLogger()) - } else if *thriftAddr != "" { - // It's necessary to do all of this construction in the func main, - // because (among other reasons) we need to control the lifecycle of the - // Thrift transport, i.e. close it eventually. - var protocolFactory thrift.TProtocolFactory - switch *thriftProtocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - default: - fmt.Fprintf(os.Stderr, "error: invalid protocol %q\n", *thriftProtocol) - os.Exit(1) - } - var transportFactory thrift.TTransportFactory - if *thriftBuffer > 0 { - transportFactory = thrift.NewTBufferedTransportFactory(*thriftBuffer) - } else { - transportFactory = thrift.NewTTransportFactory() - } - if *thriftFramed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) - } - transportSocket, err := thrift.NewTSocket(*thriftAddr) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - transport, err := transportFactory.GetTransport(transportSocket) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - if err := transport.Open(); err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - defer transport.Close() - client := addthrift.NewAddServiceClientFactory(transport, protocolFactory) - svc = addtransport.NewThriftClient(client) - } else { - fmt.Fprintf(os.Stderr, "error: no remote address specified\n") - os.Exit(1) - } - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - - switch *method { - case "sum": - a, _ := strconv.ParseInt(fs.Args()[0], 10, 64) - b, _ := strconv.ParseInt(fs.Args()[1], 10, 64) - v, err := svc.Sum(context.Background(), int(a), int(b)) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - fmt.Fprintf(os.Stdout, "%d + %d = %d\n", a, b, v) - - case "concat": - a := fs.Args()[0] - b := fs.Args()[1] - v, err := svc.Concat(context.Background(), a, b) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) - } - fmt.Fprintf(os.Stdout, "%q + %q = %q\n", a, b, v) - - default: - fmt.Fprintf(os.Stderr, "error: invalid method %q\n", *method) - os.Exit(1) - } -} - -func usageFor(fs *flag.FlagSet, short string) func() { - return func() { - fmt.Fprintf(os.Stderr, "USAGE\n") - fmt.Fprintf(os.Stderr, " %s\n", short) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "FLAGS\n") - w := tabwriter.NewWriter(os.Stderr, 0, 2, 2, ' ', 0) - fs.VisitAll(func(f *flag.Flag) { - fmt.Fprintf(w, "\t-%s %s\t%s\n", f.Name, f.DefValue, f.Usage) - }) - w.Flush() - fmt.Fprintf(os.Stderr, "\n") - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go deleted file mode 100644 index dac7c560..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/addsvc.go +++ /dev/null @@ -1,322 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "net" - "net/http" - "os" - "os/signal" - "syscall" - "text/tabwriter" - - "github.com/apache/thrift/lib/go/thrift" - lightstep "github.com/lightstep/lightstep-tracer-go" - "github.com/oklog/oklog/pkg/group" - stdopentracing "github.com/opentracing/opentracing-go" - zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" - zipkin "github.com/openzipkin/zipkin-go" - zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - "google.golang.org/grpc" - "sourcegraph.com/sourcegraph/appdash" - appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" - "github.com/go-kit/kit/metrics/prometheus" - kitgrpc "github.com/go-kit/kit/transport/grpc" - - addpb "github.com/go-kit/kit/examples/addsvc/pb" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -func main() { - // Define our flags. Your service probably won't need to bind listeners for - // *all* supported transports, or support both Zipkin and LightStep, and so - // on, but we do it here for demonstration purposes. - fs := flag.NewFlagSet("addsvc", flag.ExitOnError) - var ( - debugAddr = fs.String("debug.addr", ":8080", "Debug and metrics listen address") - httpAddr = fs.String("http-addr", ":8081", "HTTP listen address") - grpcAddr = fs.String("grpc-addr", ":8082", "gRPC listen address") - thriftAddr = fs.String("thrift-addr", ":8083", "Thrift listen address") - jsonRPCAddr = fs.String("jsonrpc-addr", ":8084", "JSON RPC listen address") - thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") - thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") - thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") - zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) using a Reporter URL e.g. http://localhost:9411/api/v2/spans") - zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) using a collector URL e.g. http://localhost:9411/api/v1/spans") - lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") - appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") - ) - fs.Usage = usageFor(fs, os.Args[0]+" [flags]") - fs.Parse(os.Args[1:]) - - // Create a single logger, which we'll use and give to other components. - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - // Determine which OpenTracing tracer to use. We'll pass the tracer to all the - // components that use it, as a dependency. - var tracer stdopentracing.Tracer - { - if *zipkinV1URL != "" && *zipkinV2URL == "" { - logger.Log("tracer", "Zipkin", "type", "OpenTracing", "URL", *zipkinV1URL) - collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - defer collector.Close() - var ( - debug = false - hostPort = "localhost:80" - serviceName = "addsvc" - ) - recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) - tracer, err = zipkinot.NewTracer(recorder) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - } else if *lightstepToken != "" { - logger.Log("tracer", "LightStep") // probably don't want to print out the token :) - tracer = lightstep.NewTracer(lightstep.Options{ - AccessToken: *lightstepToken, - }) - defer lightstep.FlushLightStepTracer(tracer) - } else if *appdashAddr != "" { - logger.Log("tracer", "Appdash", "addr", *appdashAddr) - tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) - } else { - tracer = stdopentracing.GlobalTracer() // no-op - } - } - - var zipkinTracer *zipkin.Tracer - { - var ( - err error - hostPort = "localhost:80" - serviceName = "addsvc" - useNoopTracer = (*zipkinV2URL == "") - reporter = zipkinhttp.NewReporter(*zipkinV2URL) - ) - defer reporter.Close() - zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) - zipkinTracer, err = zipkin.NewTracer( - reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - if !useNoopTracer { - logger.Log("tracer", "Zipkin", "type", "Native", "URL", *zipkinV2URL) - } - } - - // Create the (sparse) metrics we'll use in the service. They, too, are - // dependencies that we pass to components that use them. - var ints, chars metrics.Counter - { - // Business-level metrics. - ints = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "integers_summed", - Help: "Total count of integers summed via the Sum method.", - }, []string{}) - chars = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "characters_concatenated", - Help: "Total count of characters concatenated via the Concat method.", - }, []string{}) - } - var duration metrics.Histogram - { - // Endpoint-level metrics. - duration = prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "example", - Subsystem: "addsvc", - Name: "request_duration_seconds", - Help: "Request duration in seconds.", - }, []string{"method", "success"}) - } - http.DefaultServeMux.Handle("/metrics", promhttp.Handler()) - - // Build the layers of the service "onion" from the inside out. First, the - // business logic service; then, the set of endpoints that wrap the service; - // and finally, a series of concrete transport adapters. The adapters, like - // the HTTP handler or the gRPC server, are the bridge between Go kit and - // the interfaces that the transports expect. Note that we're not binding - // them to ports or anything yet; we'll do that next. - var ( - service = addservice.New(logger, ints, chars) - endpoints = addendpoint.New(service, logger, duration, tracer, zipkinTracer) - httpHandler = addtransport.NewHTTPHandler(endpoints, tracer, zipkinTracer, logger) - grpcServer = addtransport.NewGRPCServer(endpoints, tracer, zipkinTracer, logger) - thriftServer = addtransport.NewThriftServer(endpoints) - jsonrpcHandler = addtransport.NewJSONRPCHandler(endpoints, logger) - ) - - // Now we're to the part of the func main where we want to start actually - // running things, like servers bound to listeners to receive connections. - // - // The method is the same for each component: add a new actor to the group - // struct, which is a combination of 2 anonymous functions: the first - // function actually runs the component, and the second function should - // interrupt the first function and cause it to return. It's in these - // functions that we actually bind the Go kit server/handler structs to the - // concrete transports and run them. - // - // Putting each component into its own block is mostly for aesthetics: it - // clearly demarcates the scope in which each listener/socket may be used. - var g group.Group - { - // The debug listener mounts the http.DefaultServeMux, and serves up - // stuff like the Prometheus metrics route, the Go debug and profiling - // routes, and so on. - debugListener, err := net.Listen("tcp", *debugAddr) - if err != nil { - logger.Log("transport", "debug/HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "debug/HTTP", "addr", *debugAddr) - return http.Serve(debugListener, http.DefaultServeMux) - }, func(error) { - debugListener.Close() - }) - } - { - // The HTTP listener mounts the Go kit HTTP handler we created. - httpListener, err := net.Listen("tcp", *httpAddr) - if err != nil { - logger.Log("transport", "HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "HTTP", "addr", *httpAddr) - return http.Serve(httpListener, httpHandler) - }, func(error) { - httpListener.Close() - }) - } - { - // The gRPC listener mounts the Go kit gRPC server we created. - grpcListener, err := net.Listen("tcp", *grpcAddr) - if err != nil { - logger.Log("transport", "gRPC", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "gRPC", "addr", *grpcAddr) - // we add the Go Kit gRPC Interceptor to our gRPC service as it is used by - // the here demonstrated zipkin tracing middleware. - baseServer := grpc.NewServer(grpc.UnaryInterceptor(kitgrpc.Interceptor)) - addpb.RegisterAddServer(baseServer, grpcServer) - return baseServer.Serve(grpcListener) - }, func(error) { - grpcListener.Close() - }) - } - { - // The Thrift socket mounts the Go kit Thrift server we created earlier. - // There's a lot of boilerplate involved here, related to configuring - // the protocol and transport; blame Thrift. - thriftSocket, err := thrift.NewTServerSocket(*thriftAddr) - if err != nil { - logger.Log("transport", "Thrift", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "Thrift", "addr", *thriftAddr) - var protocolFactory thrift.TProtocolFactory - switch *thriftProtocol { - case "binary": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - default: - return fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol) - } - var transportFactory thrift.TTransportFactory - if *thriftBuffer > 0 { - transportFactory = thrift.NewTBufferedTransportFactory(*thriftBuffer) - } else { - transportFactory = thrift.NewTTransportFactory() - } - if *thriftFramed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) - } - return thrift.NewTSimpleServer4( - addthrift.NewAddServiceProcessor(thriftServer), - thriftSocket, - transportFactory, - protocolFactory, - ).Serve() - }, func(error) { - thriftSocket.Close() - }) - } - { - httpListener, err := net.Listen("tcp", *jsonRPCAddr) - if err != nil { - logger.Log("transport", "JSONRPC over HTTP", "during", "Listen", "err", err) - os.Exit(1) - } - g.Add(func() error { - logger.Log("transport", "JSONRPC over HTTP", "addr", *jsonRPCAddr) - return http.Serve(httpListener, jsonrpcHandler) - }, func(error) { - httpListener.Close() - }) - } - { - // This function just sits and waits for ctrl-C. - cancelInterrupt := make(chan struct{}) - g.Add(func() error { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - select { - case sig := <-c: - return fmt.Errorf("received signal %s", sig) - case <-cancelInterrupt: - return nil - } - }, func(error) { - close(cancelInterrupt) - }) - } - logger.Log("exit", g.Run()) -} - -func usageFor(fs *flag.FlagSet, short string) func() { - return func() { - fmt.Fprintf(os.Stderr, "USAGE\n") - fmt.Fprintf(os.Stderr, " %s\n", short) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "FLAGS\n") - w := tabwriter.NewWriter(os.Stderr, 0, 2, 2, ' ', 0) - fs.VisitAll(func(f *flag.Flag) { - fmt.Fprintf(w, "\t-%s %s\t%s\n", f.Name, f.DefValue, f.Usage) - }) - w.Flush() - fmt.Fprintf(os.Stderr, "\n") - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go deleted file mode 100644 index 781b50b7..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.pb.go +++ /dev/null @@ -1,270 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: addsvc.proto - -/* -Package pb is a generated protocol buffer package. - -It is generated from these files: - addsvc.proto - -It has these top-level messages: - SumRequest - SumReply - ConcatRequest - ConcatReply -*/ -package pb - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// 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.ProtoPackageIsVersion2 // please upgrade the proto package - -// The sum request contains two parameters. -type SumRequest struct { - A int64 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"` - B int64 `protobuf:"varint,2,opt,name=b" json:"b,omitempty"` -} - -func (m *SumRequest) Reset() { *m = SumRequest{} } -func (m *SumRequest) String() string { return proto.CompactTextString(m) } -func (*SumRequest) ProtoMessage() {} -func (*SumRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -func (m *SumRequest) GetA() int64 { - if m != nil { - return m.A - } - return 0 -} - -func (m *SumRequest) GetB() int64 { - if m != nil { - return m.B - } - return 0 -} - -// The sum response contains the result of the calculation. -type SumReply struct { - V int64 `protobuf:"varint,1,opt,name=v" json:"v,omitempty"` - Err string `protobuf:"bytes,2,opt,name=err" json:"err,omitempty"` -} - -func (m *SumReply) Reset() { *m = SumReply{} } -func (m *SumReply) String() string { return proto.CompactTextString(m) } -func (*SumReply) ProtoMessage() {} -func (*SumReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -func (m *SumReply) GetV() int64 { - if m != nil { - return m.V - } - return 0 -} - -func (m *SumReply) GetErr() string { - if m != nil { - return m.Err - } - return "" -} - -// The Concat request contains two parameters. -type ConcatRequest struct { - A string `protobuf:"bytes,1,opt,name=a" json:"a,omitempty"` - B string `protobuf:"bytes,2,opt,name=b" json:"b,omitempty"` -} - -func (m *ConcatRequest) Reset() { *m = ConcatRequest{} } -func (m *ConcatRequest) String() string { return proto.CompactTextString(m) } -func (*ConcatRequest) ProtoMessage() {} -func (*ConcatRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - -func (m *ConcatRequest) GetA() string { - if m != nil { - return m.A - } - return "" -} - -func (m *ConcatRequest) GetB() string { - if m != nil { - return m.B - } - return "" -} - -// The Concat response contains the result of the concatenation. -type ConcatReply struct { - V string `protobuf:"bytes,1,opt,name=v" json:"v,omitempty"` - Err string `protobuf:"bytes,2,opt,name=err" json:"err,omitempty"` -} - -func (m *ConcatReply) Reset() { *m = ConcatReply{} } -func (m *ConcatReply) String() string { return proto.CompactTextString(m) } -func (*ConcatReply) ProtoMessage() {} -func (*ConcatReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - -func (m *ConcatReply) GetV() string { - if m != nil { - return m.V - } - return "" -} - -func (m *ConcatReply) GetErr() string { - if m != nil { - return m.Err - } - return "" -} - -func init() { - proto.RegisterType((*SumRequest)(nil), "pb.SumRequest") - proto.RegisterType((*SumReply)(nil), "pb.SumReply") - proto.RegisterType((*ConcatRequest)(nil), "pb.ConcatRequest") - proto.RegisterType((*ConcatReply)(nil), "pb.ConcatReply") -} - -// 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 - -// Client API for Add service - -type AddClient interface { - // Sums two integers. - Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumReply, error) - // Concatenates two strings - Concat(ctx context.Context, in *ConcatRequest, opts ...grpc.CallOption) (*ConcatReply, error) -} - -type addClient struct { - cc *grpc.ClientConn -} - -func NewAddClient(cc *grpc.ClientConn) AddClient { - return &addClient{cc} -} - -func (c *addClient) Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumReply, error) { - out := new(SumReply) - err := grpc.Invoke(ctx, "/pb.Add/Sum", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *addClient) Concat(ctx context.Context, in *ConcatRequest, opts ...grpc.CallOption) (*ConcatReply, error) { - out := new(ConcatReply) - err := grpc.Invoke(ctx, "/pb.Add/Concat", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Add service - -type AddServer interface { - // Sums two integers. - Sum(context.Context, *SumRequest) (*SumReply, error) - // Concatenates two strings - Concat(context.Context, *ConcatRequest) (*ConcatReply, error) -} - -func RegisterAddServer(s *grpc.Server, srv AddServer) { - s.RegisterService(&_Add_serviceDesc, srv) -} - -func _Add_Sum_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SumRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AddServer).Sum(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.Add/Sum", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AddServer).Sum(ctx, req.(*SumRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Add_Concat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ConcatRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AddServer).Concat(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.Add/Concat", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AddServer).Concat(ctx, req.(*ConcatRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Add_serviceDesc = grpc.ServiceDesc{ - ServiceName: "pb.Add", - HandlerType: (*AddServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Sum", - Handler: _Add_Sum_Handler, - }, - { - MethodName: "Concat", - Handler: _Add_Concat_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "addsvc.proto", -} - -func init() { proto.RegisterFile("addsvc.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 189 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x4c, 0x49, 0x29, - 0x2e, 0x4b, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52, 0xd2, 0xe0, 0xe2, - 0x0a, 0x2e, 0xcd, 0x0d, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0xe2, 0xe1, 0x62, 0x4c, 0x94, - 0x60, 0x54, 0x60, 0xd4, 0x60, 0x0e, 0x62, 0x4c, 0x04, 0xf1, 0x92, 0x24, 0x98, 0x20, 0xbc, 0x24, - 0x25, 0x2d, 0x2e, 0x0e, 0xb0, 0xca, 0x82, 0x9c, 0x4a, 0x90, 0x4c, 0x19, 0x4c, 0x5d, 0x99, 0x90, - 0x00, 0x17, 0x73, 0x6a, 0x51, 0x11, 0x58, 0x25, 0x67, 0x10, 0x88, 0xa9, 0xa4, 0xcd, 0xc5, 0xeb, - 0x9c, 0x9f, 0x97, 0x9c, 0x58, 0x82, 0x61, 0x30, 0x27, 0x8a, 0xc1, 0x9c, 0x20, 0x83, 0x75, 0xb9, - 0xb8, 0x61, 0x8a, 0x51, 0xcc, 0xe6, 0xc4, 0x6a, 0xb6, 0x51, 0x0c, 0x17, 0xb3, 0x63, 0x4a, 0x8a, - 0x90, 0x2a, 0x17, 0x73, 0x70, 0x69, 0xae, 0x10, 0x9f, 0x5e, 0x41, 0x92, 0x1e, 0xc2, 0x07, 0x52, - 0x3c, 0x70, 0x7e, 0x41, 0x4e, 0xa5, 0x12, 0x83, 0x90, 0x1e, 0x17, 0x1b, 0xc4, 0x70, 0x21, 0x41, - 0x90, 0x0c, 0x8a, 0xab, 0xa4, 0xf8, 0x91, 0x85, 0xc0, 0xea, 0x93, 0xd8, 0xc0, 0x41, 0x63, 0x0c, - 0x08, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x37, 0x81, 0x99, 0x2a, 0x01, 0x00, 0x00, -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto deleted file mode 100644 index cf61532f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto +++ /dev/null @@ -1,36 +0,0 @@ -syntax = "proto3"; - -package pb; - -// The Add service definition. -service Add { - // Sums two integers. - rpc Sum (SumRequest) returns (SumReply) {} - - // Concatenates two strings - rpc Concat (ConcatRequest) returns (ConcatReply) {} -} - -// The sum request contains two parameters. -message SumRequest { - int64 a = 1; - int64 b = 2; -} - -// The sum response contains the result of the calculation. -message SumReply { - int64 v = 1; - string err = 2; -} - -// The Concat request contains two parameters. -message ConcatRequest { - string a = 1; - string b = 2; -} - -// The Concat response contains the result of the concatenation. -message ConcatReply { - string v = 1; - string err = 2; -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go deleted file mode 100644 index c83047b7..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go +++ /dev/null @@ -1,43 +0,0 @@ -package addendpoint - -import ( - "context" - "fmt" - "time" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// InstrumentingMiddleware returns an endpoint middleware that records -// the duration of each invocation to the passed histogram. The middleware adds -// a single field: "success", which is "true" if no error is returned, and -// "false" otherwise. -func InstrumentingMiddleware(duration metrics.Histogram) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - - defer func(begin time.Time) { - duration.With("success", fmt.Sprint(err == nil)).Observe(time.Since(begin).Seconds()) - }(time.Now()) - return next(ctx, request) - - } - } -} - -// LoggingMiddleware returns an endpoint middleware that logs the -// duration of each invocation, and the resulting error, if any. -func LoggingMiddleware(logger log.Logger) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - - defer func(begin time.Time) { - logger.Log("transport_error", err, "took", time.Since(begin)) - }(time.Now()) - return next(ctx, request) - - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go deleted file mode 100644 index 03411a9e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/set.go +++ /dev/null @@ -1,133 +0,0 @@ -package addendpoint - -import ( - "context" - "time" - - "golang.org/x/time/rate" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -// Set collects all of the endpoints that compose an add service. It's meant to -// be used as a helper struct, to collect all of the endpoints into a single -// parameter. -type Set struct { - SumEndpoint endpoint.Endpoint - ConcatEndpoint endpoint.Endpoint -} - -// New returns a Set that wraps the provided server, and wires in all of the -// expected endpoint middlewares via the various parameters. -func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer) Set { - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = MakeSumEndpoint(svc) - sumEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 1))(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(sumEndpoint) - sumEndpoint = opentracing.TraceServer(otTracer, "Sum")(sumEndpoint) - sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) - sumEndpoint = LoggingMiddleware(log.With(logger, "method", "Sum"))(sumEndpoint) - sumEndpoint = InstrumentingMiddleware(duration.With("method", "Sum"))(sumEndpoint) - } - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = MakeConcatEndpoint(svc) - concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100))(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(concatEndpoint) - concatEndpoint = opentracing.TraceServer(otTracer, "Concat")(concatEndpoint) - concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) - concatEndpoint = LoggingMiddleware(log.With(logger, "method", "Concat"))(concatEndpoint) - concatEndpoint = InstrumentingMiddleware(duration.With("method", "Concat"))(concatEndpoint) - } - return Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// Sum implements the service interface, so Set may be used as a service. -// This is primarily useful in the context of a client library. -func (s Set) Sum(ctx context.Context, a, b int) (int, error) { - resp, err := s.SumEndpoint(ctx, SumRequest{A: a, B: b}) - if err != nil { - return 0, err - } - response := resp.(SumResponse) - return response.V, response.Err -} - -// Concat implements the service interface, so Set may be used as a -// service. This is primarily useful in the context of a client library. -func (s Set) Concat(ctx context.Context, a, b string) (string, error) { - resp, err := s.ConcatEndpoint(ctx, ConcatRequest{A: a, B: b}) - if err != nil { - return "", err - } - response := resp.(ConcatResponse) - return response.V, response.Err -} - -// MakeSumEndpoint constructs a Sum endpoint wrapping the service. -func MakeSumEndpoint(s addservice.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(SumRequest) - v, err := s.Sum(ctx, req.A, req.B) - return SumResponse{V: v, Err: err}, nil - } -} - -// MakeConcatEndpoint constructs a Concat endpoint wrapping the service. -func MakeConcatEndpoint(s addservice.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(ConcatRequest) - v, err := s.Concat(ctx, req.A, req.B) - return ConcatResponse{V: v, Err: err}, nil - } -} - -// compile time assertions for our response types implementing endpoint.Failer. -var ( - _ endpoint.Failer = SumResponse{} - _ endpoint.Failer = ConcatResponse{} -) - -// SumRequest collects the request parameters for the Sum method. -type SumRequest struct { - A, B int -} - -// SumResponse collects the response values for the Sum method. -type SumResponse struct { - V int `json:"v"` - Err error `json:"-"` // should be intercepted by Failed/errorEncoder -} - -// Failed implements endpoint.Failer. -func (r SumResponse) Failed() error { return r.Err } - -// ConcatRequest collects the request parameters for the Concat method. -type ConcatRequest struct { - A, B string -} - -// ConcatResponse collects the response values for the Concat method. -type ConcatResponse struct { - V string `json:"v"` - Err error `json:"-"` -} - -// Failed implements endpoint.Failer. -func (r ConcatResponse) Failed() error { return r.Err } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go deleted file mode 100644 index 5a1d6ee5..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go +++ /dev/null @@ -1,69 +0,0 @@ -package addservice - -import ( - "context" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// Middleware describes a service (as opposed to endpoint) middleware. -type Middleware func(Service) Service - -// LoggingMiddleware takes a logger as a dependency -// and returns a ServiceMiddleware. -func LoggingMiddleware(logger log.Logger) Middleware { - return func(next Service) Service { - return loggingMiddleware{logger, next} - } -} - -type loggingMiddleware struct { - logger log.Logger - next Service -} - -func (mw loggingMiddleware) Sum(ctx context.Context, a, b int) (v int, err error) { - defer func() { - mw.logger.Log("method", "Sum", "a", a, "b", b, "v", v, "err", err) - }() - return mw.next.Sum(ctx, a, b) -} - -func (mw loggingMiddleware) Concat(ctx context.Context, a, b string) (v string, err error) { - defer func() { - mw.logger.Log("method", "Concat", "a", a, "b", b, "v", v, "err", err) - }() - return mw.next.Concat(ctx, a, b) -} - -// InstrumentingMiddleware returns a service middleware that instruments -// the number of integers summed and characters concatenated over the lifetime of -// the service. -func InstrumentingMiddleware(ints, chars metrics.Counter) Middleware { - return func(next Service) Service { - return instrumentingMiddleware{ - ints: ints, - chars: chars, - next: next, - } - } -} - -type instrumentingMiddleware struct { - ints metrics.Counter - chars metrics.Counter - next Service -} - -func (mw instrumentingMiddleware) Sum(ctx context.Context, a, b int) (int, error) { - v, err := mw.next.Sum(ctx, a, b) - mw.ints.Add(float64(v)) - return v, err -} - -func (mw instrumentingMiddleware) Concat(ctx context.Context, a, b string) (string, error) { - v, err := mw.next.Concat(ctx, a, b) - mw.chars.Add(float64(len(v))) - return v, err -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go deleted file mode 100644 index d884373b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/service.go +++ /dev/null @@ -1,71 +0,0 @@ -package addservice - -import ( - "context" - "errors" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/metrics" -) - -// Service describes a service that adds things together. -type Service interface { - Sum(ctx context.Context, a, b int) (int, error) - Concat(ctx context.Context, a, b string) (string, error) -} - -// New returns a basic Service with all of the expected middlewares wired in. -func New(logger log.Logger, ints, chars metrics.Counter) Service { - var svc Service - { - svc = NewBasicService() - svc = LoggingMiddleware(logger)(svc) - svc = InstrumentingMiddleware(ints, chars)(svc) - } - return svc -} - -var ( - // ErrTwoZeroes is an arbitrary business rule for the Add method. - ErrTwoZeroes = errors.New("can't sum two zeroes") - - // ErrIntOverflow protects the Add method. We've decided that this error - // indicates a misbehaving service and should count against e.g. circuit - // breakers. So, we return it directly in endpoints, to illustrate the - // difference. In a real service, this probably wouldn't be the case. - ErrIntOverflow = errors.New("integer overflow") - - // ErrMaxSizeExceeded protects the Concat method. - ErrMaxSizeExceeded = errors.New("result exceeds maximum size") -) - -// NewBasicService returns a naïve, stateless implementation of Service. -func NewBasicService() Service { - return basicService{} -} - -type basicService struct{} - -const ( - intMax = 1<<31 - 1 - intMin = -(intMax + 1) - maxLen = 10 -) - -func (s basicService) Sum(_ context.Context, a, b int) (int, error) { - if a == 0 && b == 0 { - return 0, ErrTwoZeroes - } - if (b > 0 && a > (intMax-b)) || (b < 0 && a < (intMin-b)) { - return 0, ErrIntOverflow - } - return a + b, nil -} - -// Concat implements Service. -func (s basicService) Concat(_ context.Context, a, b string) (string, error) { - if len(a)+len(b) > maxLen { - return "", ErrMaxSizeExceeded - } - return a + b, nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go deleted file mode 100644 index ca14cce7..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/grpc.go +++ /dev/null @@ -1,239 +0,0 @@ -package addtransport - -import ( - "context" - "errors" - "time" - - "google.golang.org/grpc" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - oldcontext "golang.org/x/net/context" - "golang.org/x/time/rate" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - grpctransport "github.com/go-kit/kit/transport/grpc" - - "github.com/go-kit/kit/examples/addsvc/pb" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -type grpcServer struct { - sum grpctransport.Handler - concat grpctransport.Handler -} - -// NewGRPCServer makes a set of endpoints available as a gRPC AddServer. -func NewGRPCServer(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) pb.AddServer { - // Zipkin GRPC Server Trace can either be instantiated per gRPC method with a - // provided operation name or a global tracing service can be instantiated - // without an operation name and fed to each Go kit gRPC server as a - // ServerOption. - // In the latter case, the operation name will be the endpoint's grpc method - // path if used in combination with the Go kit gRPC Interceptor. - // - // In this example, we demonstrate a global Zipkin tracing service with - // Go kit gRPC Interceptor. - zipkinServer := zipkin.GRPCServerTrace(zipkinTracer) - - options := []grpctransport.ServerOption{ - grpctransport.ServerErrorLogger(logger), - zipkinServer, - } - - return &grpcServer{ - sum: grpctransport.NewServer( - endpoints.SumEndpoint, - decodeGRPCSumRequest, - encodeGRPCSumResponse, - append(options, grpctransport.ServerBefore(opentracing.GRPCToContext(otTracer, "Sum", logger)))..., - ), - concat: grpctransport.NewServer( - endpoints.ConcatEndpoint, - decodeGRPCConcatRequest, - encodeGRPCConcatResponse, - append(options, grpctransport.ServerBefore(opentracing.GRPCToContext(otTracer, "Concat", logger)))..., - ), - } -} - -func (s *grpcServer) Sum(ctx oldcontext.Context, req *pb.SumRequest) (*pb.SumReply, error) { - _, rep, err := s.sum.ServeGRPC(ctx, req) - if err != nil { - return nil, err - } - return rep.(*pb.SumReply), nil -} - -func (s *grpcServer) Concat(ctx oldcontext.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) { - _, rep, err := s.concat.ServeGRPC(ctx, req) - if err != nil { - return nil, err - } - return rep.(*pb.ConcatReply), nil -} - -// NewGRPCClient returns an AddService backed by a gRPC server at the other end -// of the conn. The caller is responsible for constructing the conn, and -// eventually closing the underlying transport. We bake-in certain middlewares, -// implementing the client library pattern. -func NewGRPCClient(conn *grpc.ClientConn, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) addservice.Service { - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Zipkin GRPC Client Trace can either be instantiated per gRPC method with a - // provided operation name or a global tracing client can be instantiated - // without an operation name and fed to each Go kit client as ClientOption. - // In the latter case, the operation name will be the endpoint's grpc method - // path. - // - // In this example, we demonstrace a global tracing client. - zipkinClient := zipkin.GRPCClientTrace(zipkinTracer) - - // global client middlewares - options := []grpctransport.ClientOption{ - zipkinClient, - } - - // Each individual endpoint is an grpc/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // made your own client library, you'd do this work there, so your server - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = grpctransport.NewClient( - conn, - "pb.Add", - "Sum", - encodeGRPCSumRequest, - decodeGRPCSumResponse, - pb.SumReply{}, - append(options, grpctransport.ClientBefore(opentracing.ContextToGRPC(otTracer, logger)))..., - ).Endpoint() - sumEndpoint = opentracing.TraceClient(otTracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = grpctransport.NewClient( - conn, - "pb.Add", - "Concat", - encodeGRPCConcatRequest, - decodeGRPCConcatResponse, - pb.ConcatReply{}, - append(options, grpctransport.ClientBefore(opentracing.ContextToGRPC(otTracer, logger)))..., - ).Endpoint() - concatEndpoint = opentracing.TraceClient(otTracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// decodeGRPCSumRequest is a transport/grpc.DecodeRequestFunc that converts a -// gRPC sum request to a user-domain sum request. Primarily useful in a server. -func decodeGRPCSumRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { - req := grpcReq.(*pb.SumRequest) - return addendpoint.SumRequest{A: int(req.A), B: int(req.B)}, nil -} - -// decodeGRPCConcatRequest is a transport/grpc.DecodeRequestFunc that converts a -// gRPC concat request to a user-domain concat request. Primarily useful in a -// server. -func decodeGRPCConcatRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { - req := grpcReq.(*pb.ConcatRequest) - return addendpoint.ConcatRequest{A: req.A, B: req.B}, nil -} - -// decodeGRPCSumResponse is a transport/grpc.DecodeResponseFunc that converts a -// gRPC sum reply to a user-domain sum response. Primarily useful in a client. -func decodeGRPCSumResponse(_ context.Context, grpcReply interface{}) (interface{}, error) { - reply := grpcReply.(*pb.SumReply) - return addendpoint.SumResponse{V: int(reply.V), Err: str2err(reply.Err)}, nil -} - -// decodeGRPCConcatResponse is a transport/grpc.DecodeResponseFunc that converts -// a gRPC concat reply to a user-domain concat response. Primarily useful in a -// client. -func decodeGRPCConcatResponse(_ context.Context, grpcReply interface{}) (interface{}, error) { - reply := grpcReply.(*pb.ConcatReply) - return addendpoint.ConcatResponse{V: reply.V, Err: str2err(reply.Err)}, nil -} - -// encodeGRPCSumResponse is a transport/grpc.EncodeResponseFunc that converts a -// user-domain sum response to a gRPC sum reply. Primarily useful in a server. -func encodeGRPCSumResponse(_ context.Context, response interface{}) (interface{}, error) { - resp := response.(addendpoint.SumResponse) - return &pb.SumReply{V: int64(resp.V), Err: err2str(resp.Err)}, nil -} - -// encodeGRPCConcatResponse is a transport/grpc.EncodeResponseFunc that converts -// a user-domain concat response to a gRPC concat reply. Primarily useful in a -// server. -func encodeGRPCConcatResponse(_ context.Context, response interface{}) (interface{}, error) { - resp := response.(addendpoint.ConcatResponse) - return &pb.ConcatReply{V: resp.V, Err: err2str(resp.Err)}, nil -} - -// encodeGRPCSumRequest is a transport/grpc.EncodeRequestFunc that converts a -// user-domain sum request to a gRPC sum request. Primarily useful in a client. -func encodeGRPCSumRequest(_ context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.SumRequest) - return &pb.SumRequest{A: int64(req.A), B: int64(req.B)}, nil -} - -// encodeGRPCConcatRequest is a transport/grpc.EncodeRequestFunc that converts a -// user-domain concat request to a gRPC concat request. Primarily useful in a -// client. -func encodeGRPCConcatRequest(_ context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.ConcatRequest) - return &pb.ConcatRequest{A: req.A, B: req.B}, nil -} - -// These annoying helper functions are required to translate Go error types to -// and from strings, which is the type we use in our IDLs to represent errors. -// There is special casing to treat empty strings as nil errors. - -func str2err(s string) error { - if s == "" { - return nil - } - return errors.New(s) -} - -func err2str(err error) string { - if err == nil { - return "" - } - return err.Error() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go deleted file mode 100644 index c1e2b296..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/http.go +++ /dev/null @@ -1,244 +0,0 @@ -package addtransport - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/tracing/zipkin" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" -) - -// NewHTTPHandler returns an HTTP handler that makes a set of endpoints -// available on predefined paths. -func NewHTTPHandler(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) http.Handler { - // Zipkin HTTP Server Trace can either be instantiated per endpoint with a - // provided operation name or a global tracing service can be instantiated - // without an operation name and fed to each Go kit endpoint as ServerOption. - // In the latter case, the operation name will be the endpoint's http method. - // We demonstrate a global tracing service here. - zipkinServer := zipkin.HTTPServerTrace(zipkinTracer) - - options := []httptransport.ServerOption{ - httptransport.ServerErrorEncoder(errorEncoder), - httptransport.ServerErrorLogger(logger), - zipkinServer, - } - - m := http.NewServeMux() - m.Handle("/sum", httptransport.NewServer( - endpoints.SumEndpoint, - decodeHTTPSumRequest, - encodeHTTPGenericResponse, - append(options, httptransport.ServerBefore(opentracing.HTTPToContext(otTracer, "Sum", logger)))..., - )) - m.Handle("/concat", httptransport.NewServer( - endpoints.ConcatEndpoint, - decodeHTTPConcatRequest, - encodeHTTPGenericResponse, - append(options, httptransport.ServerBefore(opentracing.HTTPToContext(otTracer, "Concat", logger)))..., - )) - return m -} - -// NewHTTPClient returns an AddService backed by an HTTP server living at the -// remote instance. We expect instance to come from a service discovery system, -// so likely of the form "host:port". We bake-in certain middlewares, -// implementing the client library pattern. -func NewHTTPClient(instance string, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) (addservice.Service, error) { - // Quickly sanitize the instance string. - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - return nil, err - } - - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Zipkin HTTP Client Trace can either be instantiated per endpoint with a - // provided operation name or a global tracing client can be instantiated - // without an operation name and fed to each Go kit endpoint as ClientOption. - // In the latter case, the operation name will be the endpoint's http method. - zipkinClient := zipkin.HTTPClientTrace(zipkinTracer) - - // global client middlewares - options := []httptransport.ClientOption{ - zipkinClient, - } - - // Each individual endpoint is an http/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // made your own client library, you'd do this work there, so your server - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = httptransport.NewClient( - "POST", - copyURL(u, "/sum"), - encodeHTTPGenericRequest, - decodeHTTPSumResponse, - append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., - ).Endpoint() - sumEndpoint = opentracing.TraceClient(otTracer, "Sum")(sumEndpoint) - sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = httptransport.NewClient( - "POST", - copyURL(u, "/concat"), - encodeHTTPGenericRequest, - decodeHTTPConcatResponse, - append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., - ).Endpoint() - concatEndpoint = opentracing.TraceClient(otTracer, "Concat")(concatEndpoint) - concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - }, nil -} - -func copyURL(base *url.URL, path string) *url.URL { - next := *base - next.Path = path - return &next -} - -func errorEncoder(_ context.Context, err error, w http.ResponseWriter) { - w.WriteHeader(err2code(err)) - json.NewEncoder(w).Encode(errorWrapper{Error: err.Error()}) -} - -func err2code(err error) int { - switch err { - case addservice.ErrTwoZeroes, addservice.ErrMaxSizeExceeded, addservice.ErrIntOverflow: - return http.StatusBadRequest - } - return http.StatusInternalServerError -} - -func errorDecoder(r *http.Response) error { - var w errorWrapper - if err := json.NewDecoder(r.Body).Decode(&w); err != nil { - return err - } - return errors.New(w.Error) -} - -type errorWrapper struct { - Error string `json:"error"` -} - -// decodeHTTPSumRequest is a transport/http.DecodeRequestFunc that decodes a -// JSON-encoded sum request from the HTTP request body. Primarily useful in a -// server. -func decodeHTTPSumRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req addendpoint.SumRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -// decodeHTTPConcatRequest is a transport/http.DecodeRequestFunc that decodes a -// JSON-encoded concat request from the HTTP request body. Primarily useful in a -// server. -func decodeHTTPConcatRequest(_ context.Context, r *http.Request) (interface{}, error) { - var req addendpoint.ConcatRequest - err := json.NewDecoder(r.Body).Decode(&req) - return req, err -} - -// decodeHTTPSumResponse is a transport/http.DecodeResponseFunc that decodes a -// JSON-encoded sum response from the HTTP response body. If the response has a -// non-200 status code, we will interpret that as an error and attempt to decode -// the specific error message from the response body. Primarily useful in a -// client. -func decodeHTTPSumResponse(_ context.Context, r *http.Response) (interface{}, error) { - if r.StatusCode != http.StatusOK { - return nil, errors.New(r.Status) - } - var resp addendpoint.SumResponse - err := json.NewDecoder(r.Body).Decode(&resp) - return resp, err -} - -// decodeHTTPConcatResponse is a transport/http.DecodeResponseFunc that decodes -// a JSON-encoded concat response from the HTTP response body. If the response -// has a non-200 status code, we will interpret that as an error and attempt to -// decode the specific error message from the response body. Primarily useful in -// a client. -func decodeHTTPConcatResponse(_ context.Context, r *http.Response) (interface{}, error) { - if r.StatusCode != http.StatusOK { - return nil, errors.New(r.Status) - } - var resp addendpoint.ConcatResponse - err := json.NewDecoder(r.Body).Decode(&resp) - return resp, err -} - -// encodeHTTPGenericRequest is a transport/http.EncodeRequestFunc that -// JSON-encodes any request to the request body. Primarily useful in a client. -func encodeHTTPGenericRequest(_ context.Context, r *http.Request, request interface{}) error { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - r.Body = ioutil.NopCloser(&buf) - return nil -} - -// encodeHTTPGenericResponse is a transport/http.EncodeResponseFunc that encodes -// the response as JSON to the response writer. Primarily useful in a server. -func encodeHTTPGenericResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if f, ok := response.(endpoint.Failer); ok && f.Failed() != nil { - errorEncoder(ctx, f.Failed(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go deleted file mode 100644 index a8975ef4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/jsonrpc.go +++ /dev/null @@ -1,213 +0,0 @@ -package addtransport - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/transport/http/jsonrpc" - stdopentracing "github.com/opentracing/opentracing-go" - "github.com/sony/gobreaker" -) - -// NewJSONRPCHandler returns a JSON RPC Server/Handler that can be passed to http.Handle() -func NewJSONRPCHandler(endpoints addendpoint.Set, logger log.Logger) *jsonrpc.Server { - handler := jsonrpc.NewServer( - makeEndpointCodecMap(endpoints), - jsonrpc.ServerErrorLogger(logger), - ) - return handler -} - -// NewJSONRPCClient returns an addservice backed by a JSON RPC over HTTP server -// living at the remote instance. We expect instance to come from a service -// discovery system, so likely of the form "host:port". We bake-in certain -// middlewares, implementing the client library pattern. -func NewJSONRPCClient(instance string, tracer stdopentracing.Tracer, logger log.Logger) (addservice.Service, error) { - // Quickly sanitize the instance string. - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - return nil, err - } - - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = jsonrpc.NewClient( - u, - "sum", - jsonrpc.ClientRequestEncoder(encodeSumRequest), - jsonrpc.ClientResponseDecoder(decodeSumResponse), - ).Endpoint() - sumEndpoint = opentracing.TraceClient(tracer, "Sum")(sumEndpoint) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = jsonrpc.NewClient( - u, - "concat", - jsonrpc.ClientRequestEncoder(encodeConcatRequest), - jsonrpc.ClientResponseDecoder(decodeConcatResponse), - ).Endpoint() - concatEndpoint = opentracing.TraceClient(tracer, "Concat")(concatEndpoint) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 30 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - }, nil - -} - -// makeEndpointCodecMap returns a codec map configured for the addsvc. -func makeEndpointCodecMap(endpoints addendpoint.Set) jsonrpc.EndpointCodecMap { - return jsonrpc.EndpointCodecMap{ - "sum": jsonrpc.EndpointCodec{ - Endpoint: endpoints.SumEndpoint, - Decode: decodeSumRequest, - Encode: encodeSumResponse, - }, - "concat": jsonrpc.EndpointCodec{ - Endpoint: endpoints.ConcatEndpoint, - Decode: decodeConcatRequest, - Encode: encodeConcatResponse, - }, - } -} - -func decodeSumRequest(_ context.Context, msg json.RawMessage) (interface{}, error) { - var req addendpoint.SumRequest - err := json.Unmarshal(msg, &req) - if err != nil { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("couldn't unmarshal body to sum request: %s", err), - } - } - return req, nil -} - -func encodeSumResponse(_ context.Context, obj interface{}) (json.RawMessage, error) { - res, ok := obj.(addendpoint.SumResponse) - if !ok { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("Asserting result to *SumResponse failed. Got %T, %+v", obj, obj), - } - } - b, err := json.Marshal(res) - if err != nil { - return nil, fmt.Errorf("couldn't marshal response: %s", err) - } - return b, nil -} - -func decodeSumResponse(_ context.Context, res jsonrpc.Response) (interface{}, error) { - if res.Error != nil { - return nil, *res.Error - } - var sumres addendpoint.SumResponse - err := json.Unmarshal(res.Result, &sumres) - if err != nil { - return nil, fmt.Errorf("couldn't unmarshal body to SumResponse: %s", err) - } - return sumres, nil -} - -func encodeSumRequest(_ context.Context, obj interface{}) (json.RawMessage, error) { - req, ok := obj.(addendpoint.SumRequest) - if !ok { - return nil, fmt.Errorf("couldn't assert request as SumRequest, got %T", obj) - } - b, err := json.Marshal(req) - if err != nil { - return nil, fmt.Errorf("couldn't marshal request: %s", err) - } - return b, nil -} - -func decodeConcatRequest(_ context.Context, msg json.RawMessage) (interface{}, error) { - var req addendpoint.ConcatRequest - err := json.Unmarshal(msg, &req) - if err != nil { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("couldn't unmarshal body to concat request: %s", err), - } - } - return req, nil -} - -func encodeConcatResponse(_ context.Context, obj interface{}) (json.RawMessage, error) { - res, ok := obj.(addendpoint.ConcatResponse) - if !ok { - return nil, &jsonrpc.Error{ - Code: -32000, - Message: fmt.Sprintf("Asserting result to *ConcatResponse failed. Got %T, %+v", obj, obj), - } - } - b, err := json.Marshal(res) - if err != nil { - return nil, fmt.Errorf("couldn't marshal response: %s", err) - } - return b, nil -} - -func decodeConcatResponse(_ context.Context, res jsonrpc.Response) (interface{}, error) { - if res.Error != nil { - return nil, *res.Error - } - var concatres addendpoint.ConcatResponse - err := json.Unmarshal(res.Result, &concatres) - if err != nil { - return nil, fmt.Errorf("couldn't unmarshal body to ConcatResponse: %s", err) - } - return concatres, nil -} - -func encodeConcatRequest(_ context.Context, obj interface{}) (json.RawMessage, error) { - req, ok := obj.(addendpoint.ConcatRequest) - if !ok { - return nil, fmt.Errorf("couldn't assert request as ConcatRequest, got %T", obj) - } - b, err := json.Marshal(req) - if err != nil { - return nil, fmt.Errorf("couldn't marshal request: %s", err) - } - return b, nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go deleted file mode 100644 index 485840fe..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/pkg/addtransport/thrift.go +++ /dev/null @@ -1,120 +0,0 @@ -package addtransport - -import ( - "context" - "time" - - "golang.org/x/time/rate" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/ratelimit" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - addthrift "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - -type thriftServer struct { - ctx context.Context - endpoints addendpoint.Set -} - -// NewThriftServer makes a set of endpoints available as a Thrift service. -func NewThriftServer(endpoints addendpoint.Set) addthrift.AddService { - return &thriftServer{ - endpoints: endpoints, - } -} - -func (s *thriftServer) Sum(ctx context.Context, a int64, b int64) (*addthrift.SumReply, error) { - request := addendpoint.SumRequest{A: int(a), B: int(b)} - response, err := s.endpoints.SumEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(addendpoint.SumResponse) - return &addthrift.SumReply{Value: int64(resp.V), Err: err2str(resp.Err)}, nil -} - -func (s *thriftServer) Concat(ctx context.Context, a string, b string) (*addthrift.ConcatReply, error) { - request := addendpoint.ConcatRequest{A: a, B: b} - response, err := s.endpoints.ConcatEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(addendpoint.ConcatResponse) - return &addthrift.ConcatReply{Value: resp.V, Err: err2str(resp.Err)}, nil -} - -// NewThriftClient returns an AddService backed by a Thrift server described by -// the provided client. The caller is responsible for constructing the client, -// and eventually closing the underlying transport. We bake-in certain middlewares, -// implementing the client library pattern. -func NewThriftClient(client *addthrift.AddServiceClient) addservice.Service { - // We construct a single ratelimiter middleware, to limit the total outgoing - // QPS from this client to all methods on the remote instance. We also - // construct per-endpoint circuitbreaker middlewares to demonstrate how - // that's done, although they could easily be combined into a single breaker - // for the entire remote instance, too. - limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) - - // Each individual endpoint is an http/transport.Client (which implements - // endpoint.Endpoint) that gets wrapped with various middlewares. If you - // could rely on a consistent set of client behavior. - var sumEndpoint endpoint.Endpoint - { - sumEndpoint = MakeThriftSumEndpoint(client) - sumEndpoint = limiter(sumEndpoint) - sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Sum", - Timeout: 30 * time.Second, - }))(sumEndpoint) - } - - // The Concat endpoint is the same thing, with slightly different - // middlewares to demonstrate how to specialize per-endpoint. - var concatEndpoint endpoint.Endpoint - { - concatEndpoint = MakeThriftConcatEndpoint(client) - concatEndpoint = limiter(concatEndpoint) - concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ - Name: "Concat", - Timeout: 10 * time.Second, - }))(concatEndpoint) - } - - // Returning the endpoint.Set as a service.Service relies on the - // endpoint.Set implementing the Service methods. That's just a simple bit - // of glue code. - return addendpoint.Set{ - SumEndpoint: sumEndpoint, - ConcatEndpoint: concatEndpoint, - } -} - -// MakeThriftSumEndpoint returns an endpoint that invokes the passed Thrift client. -// Useful only in clients, and only until a proper transport/thrift.Client exists. -func MakeThriftSumEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.SumRequest) - reply, err := client.Sum(ctx, int64(req.A), int64(req.B)) - if err == addservice.ErrIntOverflow { - return nil, err // special case; see comment on ErrIntOverflow - } - return addendpoint.SumResponse{V: int(reply.Value), Err: err}, nil - } -} - -// MakeThriftConcatEndpoint returns an endpoint that invokes the passed Thrift -// client. Useful only in clients, and only until a proper -// transport/thrift.Client exists. -func MakeThriftConcatEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(addendpoint.ConcatRequest) - reply, err := client.Concat(ctx, req.A, req.B) - return addendpoint.ConcatResponse{V: reply.Value, Err: err}, nil - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift deleted file mode 100644 index e67ce1b2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift +++ /dev/null @@ -1,14 +0,0 @@ -struct SumReply { - 1: i64 value - 2: string err -} - -struct ConcatReply { - 1: string value - 2: string err -} - -service AddService { - SumReply Sum(1: i64 a, 2: i64 b) - ConcatReply Concat(1: string a, 2: string b) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go deleted file mode 100644 index 88387e14..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go +++ /dev/null @@ -1,7 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -var GoUnusedProtection__ int; - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go deleted file mode 100755 index 9e6800e7..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go +++ /dev/null @@ -1,186 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package main - -import ( - "context" - "flag" - "fmt" - "math" - "net" - "net/url" - "os" - "strconv" - "strings" - "github.com/apache/thrift/lib/go/thrift" - "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc" -) - - -func Usage() { - fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") - flag.PrintDefaults() - fmt.Fprintln(os.Stderr, "\nFunctions:") - fmt.Fprintln(os.Stderr, " SumReply Sum(i64 a, i64 b)") - fmt.Fprintln(os.Stderr, " ConcatReply Concat(string a, string b)") - fmt.Fprintln(os.Stderr) - os.Exit(0) -} - -type httpHeaders map[string]string - -func (h httpHeaders) String() string { - var m map[string]string = h - return fmt.Sprintf("%s", m) -} - -func (h httpHeaders) Set(value string) error { - parts := strings.Split(value, ": ") - if len(parts) != 2 { - return fmt.Errorf("header should be of format 'Key: Value'") - } - h[parts[0]] = parts[1] - return nil -} - -func main() { - flag.Usage = Usage - var host string - var port int - var protocol string - var urlString string - var framed bool - var useHttp bool - headers := make(httpHeaders) - var parsedUrl *url.URL - var trans thrift.TTransport - _ = strconv.Atoi - _ = math.Abs - flag.Usage = Usage - flag.StringVar(&host, "h", "localhost", "Specify host and port") - flag.IntVar(&port, "p", 9090, "Specify port") - flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") - flag.StringVar(&urlString, "u", "", "Specify the url") - flag.BoolVar(&framed, "framed", false, "Use framed transport") - flag.BoolVar(&useHttp, "http", false, "Use http") - flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")") - flag.Parse() - - if len(urlString) > 0 { - var err error - parsedUrl, err = url.Parse(urlString) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - host = parsedUrl.Host - useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https" - } else if useHttp { - _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - } - - cmd := flag.Arg(0) - var err error - if useHttp { - trans, err = thrift.NewTHttpClient(parsedUrl.String()) - if len(headers) > 0 { - httptrans := trans.(*thrift.THttpClient) - for key, value := range headers { - httptrans.SetHeader(key, value) - } - } - } else { - portStr := fmt.Sprint(port) - if strings.Contains(host, ":") { - host, portStr, err = net.SplitHostPort(host) - if err != nil { - fmt.Fprintln(os.Stderr, "error with host:", err) - os.Exit(1) - } - } - trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) - if err != nil { - fmt.Fprintln(os.Stderr, "error resolving address:", err) - os.Exit(1) - } - if framed { - trans = thrift.NewTFramedTransport(trans) - } - } - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating transport", err) - os.Exit(1) - } - defer trans.Close() - var protocolFactory thrift.TProtocolFactory - switch protocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - break - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - break - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - break - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - break - default: - fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) - Usage() - os.Exit(1) - } - iprot := protocolFactory.GetProtocol(trans) - oprot := protocolFactory.GetProtocol(trans) - client := addsvc.NewAddServiceClient(thrift.NewTStandardClient(iprot, oprot)) - if err := trans.Open(); err != nil { - fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) - os.Exit(1) - } - - switch cmd { - case "Sum": - if flag.NArg() - 1 != 2 { - fmt.Fprintln(os.Stderr, "Sum requires 2 args") - flag.Usage() - } - argvalue0, err6 := (strconv.ParseInt(flag.Arg(1), 10, 64)) - if err6 != nil { - Usage() - return - } - value0 := argvalue0 - argvalue1, err7 := (strconv.ParseInt(flag.Arg(2), 10, 64)) - if err7 != nil { - Usage() - return - } - value1 := argvalue1 - fmt.Print(client.Sum(context.Background(), value0, value1)) - fmt.Print("\n") - break - case "Concat": - if flag.NArg() - 1 != 2 { - fmt.Fprintln(os.Stderr, "Concat requires 2 args") - flag.Usage() - } - argvalue0 := flag.Arg(1) - value0 := argvalue0 - argvalue1 := flag.Arg(2) - value1 := argvalue1 - fmt.Print(client.Concat(context.Background(), value0, value1)) - fmt.Print("\n") - break - case "": - Usage() - break - default: - fmt.Fprintln(os.Stderr, "Invalid function ", cmd) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go deleted file mode 100644 index eea54fe1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -import ( - "bytes" - "context" - "reflect" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = context.Background -var _ = reflect.DeepEqual -var _ = bytes.Equal - - -func init() { -} - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go deleted file mode 100644 index 14a87e6d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc.go +++ /dev/null @@ -1,935 +0,0 @@ -// Autogenerated by Thrift Compiler (1.0.0-dev) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package addsvc - -import ( - "bytes" - "context" - "reflect" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = context.Background -var _ = reflect.DeepEqual -var _ = bytes.Equal - -// Attributes: -// - Value -// - Err -type SumReply struct { - Value int64 `thrift:"value,1" db:"value" json:"value"` - Err string `thrift:"err,2" db:"err" json:"err"` -} - -func NewSumReply() *SumReply { - return &SumReply{} -} - - -func (p *SumReply) GetValue() int64 { - return p.Value -} - -func (p *SumReply) GetErr() string { - return p.Err -} -func (p *SumReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.I64 { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *SumReply) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.Value = v -} - return nil -} - -func (p *SumReply) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.Err = v -} - return nil -} - -func (p *SumReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("SumReply"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *SumReply) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) } - if err := oprot.WriteI64(int64(p.Value)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) } - return err -} - -func (p *SumReply) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("err", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:err: ", p), err) } - if err := oprot.WriteString(string(p.Err)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.err (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:err: ", p), err) } - return err -} - -func (p *SumReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("SumReply(%+v)", *p) -} - -// Attributes: -// - Value -// - Err -type ConcatReply struct { - Value string `thrift:"value,1" db:"value" json:"value"` - Err string `thrift:"err,2" db:"err" json:"err"` -} - -func NewConcatReply() *ConcatReply { - return &ConcatReply{} -} - - -func (p *ConcatReply) GetValue() string { - return p.Value -} - -func (p *ConcatReply) GetErr() string { - return p.Err -} -func (p *ConcatReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *ConcatReply) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.Value = v -} - return nil -} - -func (p *ConcatReply) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.Err = v -} - return nil -} - -func (p *ConcatReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("ConcatReply"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *ConcatReply) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("value", thrift.STRING, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: ", p), err) } - if err := oprot.WriteString(string(p.Value)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.value (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:value: ", p), err) } - return err -} - -func (p *ConcatReply) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("err", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:err: ", p), err) } - if err := oprot.WriteString(string(p.Err)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.err (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:err: ", p), err) } - return err -} - -func (p *ConcatReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("ConcatReply(%+v)", *p) -} - -type AddService interface { - // Parameters: - // - A - // - B - Sum(ctx context.Context, a int64, b int64) (r *SumReply, err error) - // Parameters: - // - A - // - B - Concat(ctx context.Context, a string, b string) (r *ConcatReply, err error) -} - -type AddServiceClient struct { - c thrift.TClient -} - -func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { - return &AddServiceClient{ - c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), - } -} - -func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { - return &AddServiceClient{ - c: thrift.NewTStandardClient(iprot, oprot), - } -} - -func NewAddServiceClient(c thrift.TClient) *AddServiceClient { - return &AddServiceClient{ - c: c, - } -} - -func (p *AddServiceClient) Client_() thrift.TClient { - return p.c -} -// Parameters: -// - A -// - B -func (p *AddServiceClient) Sum(ctx context.Context, a int64, b int64) (r *SumReply, err error) { - var _args0 AddServiceSumArgs - _args0.A = a - _args0.B = b - var _result1 AddServiceSumResult - if err = p.Client_().Call(ctx, "Sum", &_args0, &_result1); err != nil { - return - } - return _result1.GetSuccess(), nil -} - -// Parameters: -// - A -// - B -func (p *AddServiceClient) Concat(ctx context.Context, a string, b string) (r *ConcatReply, err error) { - var _args2 AddServiceConcatArgs - _args2.A = a - _args2.B = b - var _result3 AddServiceConcatResult - if err = p.Client_().Call(ctx, "Concat", &_args2, &_result3); err != nil { - return - } - return _result3.GetSuccess(), nil -} - -type AddServiceProcessor struct { - processorMap map[string]thrift.TProcessorFunction - handler AddService -} - -func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { - p.processorMap[key] = processor -} - -func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { - processor, ok = p.processorMap[key] - return processor, ok -} - -func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { - return p.processorMap -} - -func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { - - self4 := &AddServiceProcessor{handler:handler, processorMap:make(map[string]thrift.TProcessorFunction)} - self4.processorMap["Sum"] = &addServiceProcessorSum{handler:handler} - self4.processorMap["Concat"] = &addServiceProcessorConcat{handler:handler} -return self4 -} - -func (p *AddServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - name, _, seqId, err := iprot.ReadMessageBegin() - if err != nil { return false, err } - if processor, ok := p.GetProcessorFunction(name); ok { - return processor.Process(ctx, seqId, iprot, oprot) - } - iprot.Skip(thrift.STRUCT) - iprot.ReadMessageEnd() - x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function " + name) - oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) - x5.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, x5 - -} - -type addServiceProcessorSum struct { - handler AddService -} - -func (p *addServiceProcessorSum) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := AddServiceSumArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - result := AddServiceSumResult{} -var retval *SumReply - var err2 error - if retval, err2 = p.handler.Sum(ctx, args.A, args.B); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Sum: " + err2.Error()) - oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval -} - if err2 = oprot.WriteMessageBegin("Sum", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type addServiceProcessorConcat struct { - handler AddService -} - -func (p *addServiceProcessorConcat) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := AddServiceConcatArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - result := AddServiceConcatResult{} -var retval *ConcatReply - var err2 error - if retval, err2 = p.handler.Concat(ctx, args.A, args.B); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Concat: " + err2.Error()) - oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval -} - if err2 = oprot.WriteMessageBegin("Concat", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - - -// HELPER FUNCTIONS AND STRUCTURES - -// Attributes: -// - A -// - B -type AddServiceSumArgs struct { - A int64 `thrift:"a,1" db:"a" json:"a"` - B int64 `thrift:"b,2" db:"b" json:"b"` -} - -func NewAddServiceSumArgs() *AddServiceSumArgs { - return &AddServiceSumArgs{} -} - - -func (p *AddServiceSumArgs) GetA() int64 { - return p.A -} - -func (p *AddServiceSumArgs) GetB() int64 { - return p.B -} -func (p *AddServiceSumArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.I64 { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.I64 { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceSumArgs) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.A = v -} - return nil -} - -func (p *AddServiceSumArgs) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.B = v -} - return nil -} - -func (p *AddServiceSumArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Sum_args"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceSumArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) } - if err := oprot.WriteI64(int64(p.A)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) } - return err -} - -func (p *AddServiceSumArgs) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) } - if err := oprot.WriteI64(int64(p.B)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) } - return err -} - -func (p *AddServiceSumArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceSumArgs(%+v)", *p) -} - -// Attributes: -// - Success -type AddServiceSumResult struct { - Success *SumReply `thrift:"success,0" db:"success" json:"success,omitempty"` -} - -func NewAddServiceSumResult() *AddServiceSumResult { - return &AddServiceSumResult{} -} - -var AddServiceSumResult_Success_DEFAULT *SumReply -func (p *AddServiceSumResult) GetSuccess() *SumReply { - if !p.IsSetSuccess() { - return AddServiceSumResult_Success_DEFAULT - } -return p.Success -} -func (p *AddServiceSumResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *AddServiceSumResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err := p.ReadField0(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceSumResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &SumReply{} - if err := p.Success.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) - } - return nil -} - -func (p *AddServiceSumResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Sum_result"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField0(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceSumResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } - if err := p.Success.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } - } - return err -} - -func (p *AddServiceSumResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceSumResult(%+v)", *p) -} - -// Attributes: -// - A -// - B -type AddServiceConcatArgs struct { - A string `thrift:"a,1" db:"a" json:"a"` - B string `thrift:"b,2" db:"b" json:"b"` -} - -func NewAddServiceConcatArgs() *AddServiceConcatArgs { - return &AddServiceConcatArgs{} -} - - -func (p *AddServiceConcatArgs) GetA() string { - return p.A -} - -func (p *AddServiceConcatArgs) GetB() string { - return p.B -} -func (p *AddServiceConcatArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err := p.ReadField1(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err := p.ReadField2(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceConcatArgs) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 1: ", err) -} else { - p.A = v -} - return nil -} - -func (p *AddServiceConcatArgs) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return thrift.PrependError("error reading field 2: ", err) -} else { - p.B = v -} - return nil -} - -func (p *AddServiceConcatArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Concat_args"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField1(oprot); err != nil { return err } - if err := p.writeField2(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceConcatArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("a", thrift.STRING, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:a: ", p), err) } - if err := oprot.WriteString(string(p.A)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.a (1) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:a: ", p), err) } - return err -} - -func (p *AddServiceConcatArgs) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("b", thrift.STRING, 2); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err) } - if err := oprot.WriteString(string(p.B)); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err) } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err) } - return err -} - -func (p *AddServiceConcatArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceConcatArgs(%+v)", *p) -} - -// Attributes: -// - Success -type AddServiceConcatResult struct { - Success *ConcatReply `thrift:"success,0" db:"success" json:"success,omitempty"` -} - -func NewAddServiceConcatResult() *AddServiceConcatResult { - return &AddServiceConcatResult{} -} - -var AddServiceConcatResult_Success_DEFAULT *ConcatReply -func (p *AddServiceConcatResult) GetSuccess() *ConcatReply { - if !p.IsSetSuccess() { - return AddServiceConcatResult_Success_DEFAULT - } -return p.Success -} -func (p *AddServiceConcatResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *AddServiceConcatResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { break; } - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err := p.ReadField0(iprot); err != nil { - return err - } - } else { - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *AddServiceConcatResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &ConcatReply{} - if err := p.Success.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) - } - return nil -} - -func (p *AddServiceConcatResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Concat_result"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } - if p != nil { - if err := p.writeField0(oprot); err != nil { return err } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) } - return nil -} - -func (p *AddServiceConcatResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } - if err := p.Success.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } - } - return err -} - -func (p *AddServiceConcatResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddServiceConcatResult(%+v)", *p) -} - - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go deleted file mode 100644 index 5891241d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/apigateway/main.go +++ /dev/null @@ -1,287 +0,0 @@ -package main - -import ( - "bytes" - "context" - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/url" - "os" - "os/signal" - "strings" - "syscall" - "time" - - consulsd "github.com/go-kit/kit/sd/consul" - "github.com/gorilla/mux" - "github.com/hashicorp/consul/api" - stdopentracing "github.com/opentracing/opentracing-go" - stdzipkin "github.com/openzipkin/zipkin-go" - "google.golang.org/grpc" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/lb" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" - "github.com/go-kit/kit/examples/addsvc/pkg/addservice" - "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" -) - -func main() { - var ( - httpAddr = flag.String("http.addr", ":8000", "Address for HTTP (JSON) server") - consulAddr = flag.String("consul.addr", "", "Consul agent address") - retryMax = flag.Int("retry.max", 3, "per-request retries to different instances") - retryTimeout = flag.Duration("retry.timeout", 500*time.Millisecond, "per-request timeout, including retries") - ) - flag.Parse() - - // Logging domain. - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - // Service discovery domain. In this example we use Consul. - var client consulsd.Client - { - consulConfig := api.DefaultConfig() - if len(*consulAddr) > 0 { - consulConfig.Address = *consulAddr - } - consulClient, err := api.NewClient(consulConfig) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - client = consulsd.NewClient(consulClient) - } - - // Transport domain. - tracer := stdopentracing.GlobalTracer() // no-op - zipkinTracer, _ := stdzipkin.NewTracer(nil, stdzipkin.WithNoopTracer(true)) - ctx := context.Background() - r := mux.NewRouter() - - // Now we begin installing the routes. Each route corresponds to a single - // method: sum, concat, uppercase, and count. - - // addsvc routes. - { - // Each method gets constructed with a factory. Factories take an - // instance string, and return a specific endpoint. In the factory we - // dial the instance string we get from Consul, and then leverage an - // addsvc client package to construct a complete service. We can then - // leverage the addsvc.Make{Sum,Concat}Endpoint constructors to convert - // the complete service to specific endpoint. - var ( - tags = []string{} - passingOnly = true - endpoints = addendpoint.Set{} - instancer = consulsd.NewInstancer(client, logger, "addsvc", tags, passingOnly) - ) - { - factory := addsvcFactory(addendpoint.MakeSumEndpoint, tracer, zipkinTracer, logger) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - endpoints.SumEndpoint = retry - } - { - factory := addsvcFactory(addendpoint.MakeConcatEndpoint, tracer, zipkinTracer, logger) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - endpoints.ConcatEndpoint = retry - } - - // Here we leverage the fact that addsvc comes with a constructor for an - // HTTP handler, and just install it under a particular path prefix in - // our router. - - r.PathPrefix("/addsvc").Handler(http.StripPrefix("/addsvc", addtransport.NewHTTPHandler(endpoints, tracer, zipkinTracer, logger))) - } - - // stringsvc routes. - { - // addsvc had lots of nice importable Go packages we could leverage. - // With stringsvc we are not so fortunate, it just has some endpoints - // that we assume will exist. So we have to write that logic here. This - // is by design, so you can see two totally different methods of - // proxying to a remote service. - - var ( - tags = []string{} - passingOnly = true - uppercase endpoint.Endpoint - count endpoint.Endpoint - instancer = consulsd.NewInstancer(client, logger, "stringsvc", tags, passingOnly) - ) - { - factory := stringsvcFactory(ctx, "GET", "/uppercase") - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - uppercase = retry - } - { - factory := stringsvcFactory(ctx, "GET", "/count") - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(*retryMax, *retryTimeout, balancer) - count = retry - } - - // We can use the transport/http.Server to act as our handler, all we - // have to do provide it with the encode and decode functions for our - // stringsvc methods. - - r.Handle("/stringsvc/uppercase", httptransport.NewServer(uppercase, decodeUppercaseRequest, encodeJSONResponse)) - r.Handle("/stringsvc/count", httptransport.NewServer(count, decodeCountRequest, encodeJSONResponse)) - } - - // Interrupt handler. - errc := make(chan error) - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - errc <- fmt.Errorf("%s", <-c) - }() - - // HTTP transport. - go func() { - logger.Log("transport", "HTTP", "addr", *httpAddr) - errc <- http.ListenAndServe(*httpAddr, r) - }() - - // Run! - logger.Log("exit", <-errc) -} - -func addsvcFactory(makeEndpoint func(addservice.Service) endpoint.Endpoint, tracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - // We could just as easily use the HTTP or Thrift client package to make - // the connection to addsvc. We've chosen gRPC arbitrarily. Note that - // the transport is an implementation detail: it doesn't leak out of - // this function. Nice! - - conn, err := grpc.Dial(instance, grpc.WithInsecure()) - if err != nil { - return nil, nil, err - } - service := addtransport.NewGRPCClient(conn, tracer, zipkinTracer, logger) - endpoint := makeEndpoint(service) - - // Notice that the addsvc gRPC client converts the connection to a - // complete addsvc, and we just throw away everything except the method - // we're interested in. A smarter factory would mux multiple methods - // over the same connection. But that would require more work to manage - // the returned io.Closer, e.g. reference counting. Since this is for - // the purposes of demonstration, we'll just keep it simple. - - return endpoint, conn, nil - } -} - -func stringsvcFactory(ctx context.Context, method, path string) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - tgt, err := url.Parse(instance) - if err != nil { - return nil, nil, err - } - tgt.Path = path - - // Since stringsvc doesn't have any kind of package we can import, or - // any formal spec, we are forced to just assert where the endpoints - // live, and write our own code to encode and decode requests and - // responses. Ideally, if you write the service, you will want to - // provide stronger guarantees to your clients. - - var ( - enc httptransport.EncodeRequestFunc - dec httptransport.DecodeResponseFunc - ) - switch path { - case "/uppercase": - enc, dec = encodeJSONRequest, decodeUppercaseResponse - case "/count": - enc, dec = encodeJSONRequest, decodeCountResponse - default: - return nil, nil, fmt.Errorf("unknown stringsvc path %q", path) - } - - return httptransport.NewClient(method, tgt, enc, dec).Endpoint(), nil, nil - } -} - -func encodeJSONRequest(_ context.Context, req *http.Request, request interface{}) error { - // Both uppercase and count requests are encoded in the same way: - // simple JSON serialization to the request body. - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - req.Body = ioutil.NopCloser(&buf) - return nil -} - -func encodeJSONResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -// I've just copied these functions from stringsvc3/transport.go, inlining the -// struct definitions. - -func decodeUppercaseResponse(ctx context.Context, resp *http.Response) (interface{}, error) { - var response struct { - V string `json:"v"` - Err string `json:"err,omitempty"` - } - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func decodeCountResponse(ctx context.Context, resp *http.Response) (interface{}, error) { - var response struct { - V int `json:"v"` - } - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func decodeUppercaseRequest(ctx context.Context, req *http.Request) (interface{}, error) { - var request struct { - S string `json:"s"` - } - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(ctx context.Context, req *http.Request) (interface{}, error) { - var request struct { - S string `json:"s"` - } - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md deleted file mode 100644 index 34a06e71..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# profilesvc - -This example demonstrates how to use Go kit to implement a REST-y HTTP service. -It leverages the excellent [gorilla mux package](https://github.com/gorilla/mux) for routing. - -Run the example with the optional port address for the service: - -```bash -$ go run ./cmd/profilesvc/main.go -http.addr :8080 -ts=2018-05-01T16:13:12.849086255Z caller=main.go:47 transport=HTTP addr=:8080 -``` - -Create a Profile: - -```bash -$ curl -d '{"id":"1234","Name":"Go Kit"}' -H "Content-Type: application/json" -X POST http://localhost:8080/profiles/ -{} -``` - -Get the profile you just created - -```bash -$ curl localhost:8080/profiles/1234 -{"profile":{"id":"1234","name":"Go Kit"}} -``` diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go deleted file mode 100644 index 03c1dc7a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/client/client.go +++ /dev/null @@ -1,121 +0,0 @@ -// Package client provides a profilesvc client based on a predefined Consul -// service name and relevant tags. Users must only provide the address of a -// Consul server. -package client - -import ( - "io" - "time" - - consulapi "github.com/hashicorp/consul/api" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/examples/profilesvc" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/consul" - "github.com/go-kit/kit/sd/lb" -) - -// New returns a service that's load-balanced over instances of profilesvc found -// in the provided Consul server. The mechanism of looking up profilesvc -// instances in Consul is hard-coded into the client. -func New(consulAddr string, logger log.Logger) (profilesvc.Service, error) { - apiclient, err := consulapi.NewClient(&consulapi.Config{ - Address: consulAddr, - }) - if err != nil { - return nil, err - } - - // As the implementer of profilesvc, we declare and enforce these - // parameters for all of the profilesvc consumers. - var ( - consulService = "profilesvc" - consulTags = []string{"prod"} - passingOnly = true - retryMax = 3 - retryTimeout = 500 * time.Millisecond - ) - - var ( - sdclient = consul.NewClient(apiclient) - instancer = consul.NewInstancer(sdclient, logger, consulService, consulTags, passingOnly) - endpoints profilesvc.Endpoints - ) - { - factory := factoryFor(profilesvc.MakePostProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PostProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePutProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PutProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePatchProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PatchProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeDeleteProfileEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.DeleteProfileEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetAddressesEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetAddressesEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeGetAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.GetAddressEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakePostAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.PostAddressEndpoint = retry - } - { - factory := factoryFor(profilesvc.MakeDeleteAddressEndpoint) - endpointer := sd.NewEndpointer(instancer, factory, logger) - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(retryMax, retryTimeout, balancer) - endpoints.DeleteAddressEndpoint = retry - } - - return endpoints, nil -} - -func factoryFor(makeEndpoint func(profilesvc.Service) endpoint.Endpoint) sd.Factory { - return func(instance string) (endpoint.Endpoint, io.Closer, error) { - service, err := profilesvc.MakeClientEndpoints(instance) - if err != nil { - return nil, nil, err - } - return makeEndpoint(service), nil, nil - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go deleted file mode 100644 index fda75295..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "net/http" - "os" - "os/signal" - "syscall" - - "github.com/go-kit/kit/examples/profilesvc" - "github.com/go-kit/kit/log" -) - -func main() { - var ( - httpAddr = flag.String("http.addr", ":8080", "HTTP listen address") - ) - flag.Parse() - - var logger log.Logger - { - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - logger = log.With(logger, "caller", log.DefaultCaller) - } - - var s profilesvc.Service - { - s = profilesvc.NewInmemService() - s = profilesvc.LoggingMiddleware(logger)(s) - } - - var h http.Handler - { - h = profilesvc.MakeHTTPHandler(s, log.With(logger, "component", "HTTP")) - } - - errs := make(chan error) - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - errs <- fmt.Errorf("%s", <-c) - }() - - go func() { - logger.Log("transport", "HTTP", "addr", *httpAddr) - errs <- http.ListenAndServe(*httpAddr, h) - }() - - logger.Log("exit", <-errs) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go deleted file mode 100644 index 794d0f17..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/endpoints.go +++ /dev/null @@ -1,387 +0,0 @@ -package profilesvc - -import ( - "context" - "net/url" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// Endpoints collects all of the endpoints that compose a profile service. It's -// meant to be used as a helper struct, to collect all of the endpoints into a -// single parameter. -// -// In a server, it's useful for functions that need to operate on a per-endpoint -// basis. For example, you might pass an Endpoints to a function that produces -// an http.Handler, with each method (endpoint) wired up to a specific path. (It -// is probably a mistake in design to invoke the Service methods on the -// Endpoints struct in a server.) -// -// In a client, it's useful to collect individually constructed endpoints into a -// single type that implements the Service interface. For example, you might -// construct individual endpoints using transport/http.NewClient, combine them -// into an Endpoints, and return it to the caller as a Service. -type Endpoints struct { - PostProfileEndpoint endpoint.Endpoint - GetProfileEndpoint endpoint.Endpoint - PutProfileEndpoint endpoint.Endpoint - PatchProfileEndpoint endpoint.Endpoint - DeleteProfileEndpoint endpoint.Endpoint - GetAddressesEndpoint endpoint.Endpoint - GetAddressEndpoint endpoint.Endpoint - PostAddressEndpoint endpoint.Endpoint - DeleteAddressEndpoint endpoint.Endpoint -} - -// MakeServerEndpoints returns an Endpoints struct where each endpoint invokes -// the corresponding method on the provided service. Useful in a profilesvc -// server. -func MakeServerEndpoints(s Service) Endpoints { - return Endpoints{ - PostProfileEndpoint: MakePostProfileEndpoint(s), - GetProfileEndpoint: MakeGetProfileEndpoint(s), - PutProfileEndpoint: MakePutProfileEndpoint(s), - PatchProfileEndpoint: MakePatchProfileEndpoint(s), - DeleteProfileEndpoint: MakeDeleteProfileEndpoint(s), - GetAddressesEndpoint: MakeGetAddressesEndpoint(s), - GetAddressEndpoint: MakeGetAddressEndpoint(s), - PostAddressEndpoint: MakePostAddressEndpoint(s), - DeleteAddressEndpoint: MakeDeleteAddressEndpoint(s), - } -} - -// MakeClientEndpoints returns an Endpoints struct where each endpoint invokes -// the corresponding method on the remote instance, via a transport/http.Client. -// Useful in a profilesvc client. -func MakeClientEndpoints(instance string) (Endpoints, error) { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - tgt, err := url.Parse(instance) - if err != nil { - return Endpoints{}, err - } - tgt.Path = "" - - options := []httptransport.ClientOption{} - - // Note that the request encoders need to modify the request URL, changing - // the path. That's fine: we simply need to provide specific encoders for - // each endpoint. - - return Endpoints{ - PostProfileEndpoint: httptransport.NewClient("POST", tgt, encodePostProfileRequest, decodePostProfileResponse, options...).Endpoint(), - GetProfileEndpoint: httptransport.NewClient("GET", tgt, encodeGetProfileRequest, decodeGetProfileResponse, options...).Endpoint(), - PutProfileEndpoint: httptransport.NewClient("PUT", tgt, encodePutProfileRequest, decodePutProfileResponse, options...).Endpoint(), - PatchProfileEndpoint: httptransport.NewClient("PATCH", tgt, encodePatchProfileRequest, decodePatchProfileResponse, options...).Endpoint(), - DeleteProfileEndpoint: httptransport.NewClient("DELETE", tgt, encodeDeleteProfileRequest, decodeDeleteProfileResponse, options...).Endpoint(), - GetAddressesEndpoint: httptransport.NewClient("GET", tgt, encodeGetAddressesRequest, decodeGetAddressesResponse, options...).Endpoint(), - GetAddressEndpoint: httptransport.NewClient("GET", tgt, encodeGetAddressRequest, decodeGetAddressResponse, options...).Endpoint(), - PostAddressEndpoint: httptransport.NewClient("POST", tgt, encodePostAddressRequest, decodePostAddressResponse, options...).Endpoint(), - DeleteAddressEndpoint: httptransport.NewClient("DELETE", tgt, encodeDeleteAddressRequest, decodeDeleteAddressResponse, options...).Endpoint(), - }, nil -} - -// PostProfile implements Service. Primarily useful in a client. -func (e Endpoints) PostProfile(ctx context.Context, p Profile) error { - request := postProfileRequest{Profile: p} - response, err := e.PostProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(postProfileResponse) - return resp.Err -} - -// GetProfile implements Service. Primarily useful in a client. -func (e Endpoints) GetProfile(ctx context.Context, id string) (Profile, error) { - request := getProfileRequest{ID: id} - response, err := e.GetProfileEndpoint(ctx, request) - if err != nil { - return Profile{}, err - } - resp := response.(getProfileResponse) - return resp.Profile, resp.Err -} - -// PutProfile implements Service. Primarily useful in a client. -func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error { - request := putProfileRequest{ID: id, Profile: p} - response, err := e.PutProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(putProfileResponse) - return resp.Err -} - -// PatchProfile implements Service. Primarily useful in a client. -func (e Endpoints) PatchProfile(ctx context.Context, id string, p Profile) error { - request := patchProfileRequest{ID: id, Profile: p} - response, err := e.PatchProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(patchProfileResponse) - return resp.Err -} - -// DeleteProfile implements Service. Primarily useful in a client. -func (e Endpoints) DeleteProfile(ctx context.Context, id string) error { - request := deleteProfileRequest{ID: id} - response, err := e.DeleteProfileEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(deleteProfileResponse) - return resp.Err -} - -// GetAddresses implements Service. Primarily useful in a client. -func (e Endpoints) GetAddresses(ctx context.Context, profileID string) ([]Address, error) { - request := getAddressesRequest{ProfileID: profileID} - response, err := e.GetAddressesEndpoint(ctx, request) - if err != nil { - return nil, err - } - resp := response.(getAddressesResponse) - return resp.Addresses, resp.Err -} - -// GetAddress implements Service. Primarily useful in a client. -func (e Endpoints) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) { - request := getAddressRequest{ProfileID: profileID, AddressID: addressID} - response, err := e.GetAddressEndpoint(ctx, request) - if err != nil { - return Address{}, err - } - resp := response.(getAddressResponse) - return resp.Address, resp.Err -} - -// PostAddress implements Service. Primarily useful in a client. -func (e Endpoints) PostAddress(ctx context.Context, profileID string, a Address) error { - request := postAddressRequest{ProfileID: profileID, Address: a} - response, err := e.PostAddressEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(postAddressResponse) - return resp.Err -} - -// DeleteAddress implements Service. Primarily useful in a client. -func (e Endpoints) DeleteAddress(ctx context.Context, profileID string, addressID string) error { - request := deleteAddressRequest{ProfileID: profileID, AddressID: addressID} - response, err := e.DeleteAddressEndpoint(ctx, request) - if err != nil { - return err - } - resp := response.(deleteAddressResponse) - return resp.Err -} - -// MakePostProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePostProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(postProfileRequest) - e := s.PostProfile(ctx, req.Profile) - return postProfileResponse{Err: e}, nil - } -} - -// MakeGetProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getProfileRequest) - p, e := s.GetProfile(ctx, req.ID) - return getProfileResponse{Profile: p, Err: e}, nil - } -} - -// MakePutProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePutProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(putProfileRequest) - e := s.PutProfile(ctx, req.ID, req.Profile) - return putProfileResponse{Err: e}, nil - } -} - -// MakePatchProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePatchProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(patchProfileRequest) - e := s.PatchProfile(ctx, req.ID, req.Profile) - return patchProfileResponse{Err: e}, nil - } -} - -// MakeDeleteProfileEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeDeleteProfileEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(deleteProfileRequest) - e := s.DeleteProfile(ctx, req.ID) - return deleteProfileResponse{Err: e}, nil - } -} - -// MakeGetAddressesEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetAddressesEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getAddressesRequest) - a, e := s.GetAddresses(ctx, req.ProfileID) - return getAddressesResponse{Addresses: a, Err: e}, nil - } -} - -// MakeGetAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeGetAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(getAddressRequest) - a, e := s.GetAddress(ctx, req.ProfileID, req.AddressID) - return getAddressResponse{Address: a, Err: e}, nil - } -} - -// MakePostAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakePostAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(postAddressRequest) - e := s.PostAddress(ctx, req.ProfileID, req.Address) - return postAddressResponse{Err: e}, nil - } -} - -// MakeDeleteAddressEndpoint returns an endpoint via the passed service. -// Primarily useful in a server. -func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(deleteAddressRequest) - e := s.DeleteAddress(ctx, req.ProfileID, req.AddressID) - return deleteAddressResponse{Err: e}, nil - } -} - -// We have two options to return errors from the business logic. -// -// We could return the error via the endpoint itself. That makes certain things -// a little bit easier, like providing non-200 HTTP responses to the client. But -// Go kit assumes that endpoint errors are (or may be treated as) -// transport-domain errors. For example, an endpoint error will count against a -// circuit breaker error count. -// -// Therefore, it's often better to return service (business logic) errors in the -// response object. This means we have to do a bit more work in the HTTP -// response encoder to detect e.g. a not-found error and provide a proper HTTP -// status code. That work is done with the errorer interface, in transport.go. -// Response types that may contain business-logic errors implement that -// interface. - -type postProfileRequest struct { - Profile Profile -} - -type postProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r postProfileResponse) error() error { return r.Err } - -type getProfileRequest struct { - ID string -} - -type getProfileResponse struct { - Profile Profile `json:"profile,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getProfileResponse) error() error { return r.Err } - -type putProfileRequest struct { - ID string - Profile Profile -} - -type putProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r putProfileResponse) error() error { return nil } - -type patchProfileRequest struct { - ID string - Profile Profile -} - -type patchProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r patchProfileResponse) error() error { return r.Err } - -type deleteProfileRequest struct { - ID string -} - -type deleteProfileResponse struct { - Err error `json:"err,omitempty"` -} - -func (r deleteProfileResponse) error() error { return r.Err } - -type getAddressesRequest struct { - ProfileID string -} - -type getAddressesResponse struct { - Addresses []Address `json:"addresses,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getAddressesResponse) error() error { return r.Err } - -type getAddressRequest struct { - ProfileID string - AddressID string -} - -type getAddressResponse struct { - Address Address `json:"address,omitempty"` - Err error `json:"err,omitempty"` -} - -func (r getAddressResponse) error() error { return r.Err } - -type postAddressRequest struct { - ProfileID string - Address Address -} - -type postAddressResponse struct { - Err error `json:"err,omitempty"` -} - -func (r postAddressResponse) error() error { return r.Err } - -type deleteAddressRequest struct { - ProfileID string - AddressID string -} - -type deleteAddressResponse struct { - Err error `json:"err,omitempty"` -} - -func (r deleteAddressResponse) error() error { return r.Err } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go deleted file mode 100644 index 1b738f5b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/middlewares.go +++ /dev/null @@ -1,88 +0,0 @@ -package profilesvc - -import ( - "context" - "time" - - "github.com/go-kit/kit/log" -) - -// Middleware describes a service (as opposed to endpoint) middleware. -type Middleware func(Service) Service - -func LoggingMiddleware(logger log.Logger) Middleware { - return func(next Service) Service { - return &loggingMiddleware{ - next: next, - logger: logger, - } - } -} - -type loggingMiddleware struct { - next Service - logger log.Logger -} - -func (mw loggingMiddleware) PostProfile(ctx context.Context, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PostProfile", "id", p.ID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PostProfile(ctx, p) -} - -func (mw loggingMiddleware) GetProfile(ctx context.Context, id string) (p Profile, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetProfile(ctx, id) -} - -func (mw loggingMiddleware) PutProfile(ctx context.Context, id string, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PutProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PutProfile(ctx, id, p) -} - -func (mw loggingMiddleware) PatchProfile(ctx context.Context, id string, p Profile) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PatchProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PatchProfile(ctx, id, p) -} - -func (mw loggingMiddleware) DeleteProfile(ctx context.Context, id string) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "DeleteProfile", "id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.DeleteProfile(ctx, id) -} - -func (mw loggingMiddleware) GetAddresses(ctx context.Context, profileID string) (addresses []Address, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetAddresses", "profileID", profileID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetAddresses(ctx, profileID) -} - -func (mw loggingMiddleware) GetAddress(ctx context.Context, profileID string, addressID string) (a Address, err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "GetAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.GetAddress(ctx, profileID, addressID) -} - -func (mw loggingMiddleware) PostAddress(ctx context.Context, profileID string, a Address) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "PostAddress", "profileID", profileID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.PostAddress(ctx, profileID, a) -} - -func (mw loggingMiddleware) DeleteAddress(ctx context.Context, profileID string, addressID string) (err error) { - defer func(begin time.Time) { - mw.logger.Log("method", "DeleteAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err) - }(time.Now()) - return mw.next.DeleteAddress(ctx, profileID, addressID) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go deleted file mode 100644 index cd34ecd9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/service.go +++ /dev/null @@ -1,185 +0,0 @@ -package profilesvc - -import ( - "context" - "errors" - "sync" -) - -// Service is a simple CRUD interface for user profiles. -type Service interface { - PostProfile(ctx context.Context, p Profile) error - GetProfile(ctx context.Context, id string) (Profile, error) - PutProfile(ctx context.Context, id string, p Profile) error - PatchProfile(ctx context.Context, id string, p Profile) error - DeleteProfile(ctx context.Context, id string) error - GetAddresses(ctx context.Context, profileID string) ([]Address, error) - GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) - PostAddress(ctx context.Context, profileID string, a Address) error - DeleteAddress(ctx context.Context, profileID string, addressID string) error -} - -// Profile represents a single user profile. -// ID should be globally unique. -type Profile struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - Addresses []Address `json:"addresses,omitempty"` -} - -// Address is a field of a user profile. -// ID should be unique within the profile (at a minimum). -type Address struct { - ID string `json:"id"` - Location string `json:"location,omitempty"` -} - -var ( - ErrInconsistentIDs = errors.New("inconsistent IDs") - ErrAlreadyExists = errors.New("already exists") - ErrNotFound = errors.New("not found") -) - -type inmemService struct { - mtx sync.RWMutex - m map[string]Profile -} - -func NewInmemService() Service { - return &inmemService{ - m: map[string]Profile{}, - } -} - -func (s *inmemService) PostProfile(ctx context.Context, p Profile) error { - s.mtx.Lock() - defer s.mtx.Unlock() - if _, ok := s.m[p.ID]; ok { - return ErrAlreadyExists // POST = create, don't overwrite - } - s.m[p.ID] = p - return nil -} - -func (s *inmemService) GetProfile(ctx context.Context, id string) (Profile, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[id] - if !ok { - return Profile{}, ErrNotFound - } - return p, nil -} - -func (s *inmemService) PutProfile(ctx context.Context, id string, p Profile) error { - if id != p.ID { - return ErrInconsistentIDs - } - s.mtx.Lock() - defer s.mtx.Unlock() - s.m[id] = p // PUT = create or update - return nil -} - -func (s *inmemService) PatchProfile(ctx context.Context, id string, p Profile) error { - if p.ID != "" && id != p.ID { - return ErrInconsistentIDs - } - - s.mtx.Lock() - defer s.mtx.Unlock() - - existing, ok := s.m[id] - if !ok { - return ErrNotFound // PATCH = update existing, don't create - } - - // We assume that it's not possible to PATCH the ID, and that it's not - // possible to PATCH any field to its zero value. That is, the zero value - // means not specified. The way around this is to use e.g. Name *string in - // the Profile definition. But since this is just a demonstrative example, - // I'm leaving that out. - - if p.Name != "" { - existing.Name = p.Name - } - if len(p.Addresses) > 0 { - existing.Addresses = p.Addresses - } - s.m[id] = existing - return nil -} - -func (s *inmemService) DeleteProfile(ctx context.Context, id string) error { - s.mtx.Lock() - defer s.mtx.Unlock() - if _, ok := s.m[id]; !ok { - return ErrNotFound - } - delete(s.m, id) - return nil -} - -func (s *inmemService) GetAddresses(ctx context.Context, profileID string) ([]Address, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[profileID] - if !ok { - return []Address{}, ErrNotFound - } - return p.Addresses, nil -} - -func (s *inmemService) GetAddress(ctx context.Context, profileID string, addressID string) (Address, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - p, ok := s.m[profileID] - if !ok { - return Address{}, ErrNotFound - } - for _, address := range p.Addresses { - if address.ID == addressID { - return address, nil - } - } - return Address{}, ErrNotFound -} - -func (s *inmemService) PostAddress(ctx context.Context, profileID string, a Address) error { - s.mtx.Lock() - defer s.mtx.Unlock() - p, ok := s.m[profileID] - if !ok { - return ErrNotFound - } - for _, address := range p.Addresses { - if address.ID == a.ID { - return ErrAlreadyExists - } - } - p.Addresses = append(p.Addresses, a) - s.m[profileID] = p - return nil -} - -func (s *inmemService) DeleteAddress(ctx context.Context, profileID string, addressID string) error { - s.mtx.Lock() - defer s.mtx.Unlock() - p, ok := s.m[profileID] - if !ok { - return ErrNotFound - } - newAddresses := make([]Address, 0, len(p.Addresses)) - for _, address := range p.Addresses { - if address.ID == addressID { - continue // delete - } - newAddresses = append(newAddresses, address) - } - if len(newAddresses) == len(p.Addresses) { - return ErrNotFound - } - p.Addresses = newAddresses - s.m[profileID] = p - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go deleted file mode 100644 index 6d34126d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/profilesvc/transport.go +++ /dev/null @@ -1,400 +0,0 @@ -package profilesvc - -// The profilesvc is just over HTTP, so we just have a single transport.go. - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "net/url" - - "github.com/gorilla/mux" - - "github.com/go-kit/kit/log" - httptransport "github.com/go-kit/kit/transport/http" -) - -var ( - // ErrBadRouting is returned when an expected path variable is missing. - // It always indicates programmer error. - ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)") -) - -// MakeHTTPHandler mounts all of the service endpoints into an http.Handler. -// Useful in a profilesvc server. -func MakeHTTPHandler(s Service, logger log.Logger) http.Handler { - r := mux.NewRouter() - e := MakeServerEndpoints(s) - options := []httptransport.ServerOption{ - httptransport.ServerErrorLogger(logger), - httptransport.ServerErrorEncoder(encodeError), - } - - // POST /profiles/ adds another profile - // GET /profiles/:id retrieves the given profile by id - // PUT /profiles/:id post updated profile information about the profile - // PATCH /profiles/:id partial updated profile information - // DELETE /profiles/:id remove the given profile - // GET /profiles/:id/addresses/ retrieve addresses associated with the profile - // GET /profiles/:id/addresses/:addressID retrieve a particular profile address - // POST /profiles/:id/addresses/ add a new address - // DELETE /profiles/:id/addresses/:addressID remove an address - - r.Methods("POST").Path("/profiles/").Handler(httptransport.NewServer( - e.PostProfileEndpoint, - decodePostProfileRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.GetProfileEndpoint, - decodeGetProfileRequest, - encodeResponse, - options..., - )) - r.Methods("PUT").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.PutProfileEndpoint, - decodePutProfileRequest, - encodeResponse, - options..., - )) - r.Methods("PATCH").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.PatchProfileEndpoint, - decodePatchProfileRequest, - encodeResponse, - options..., - )) - r.Methods("DELETE").Path("/profiles/{id}").Handler(httptransport.NewServer( - e.DeleteProfileEndpoint, - decodeDeleteProfileRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}/addresses/").Handler(httptransport.NewServer( - e.GetAddressesEndpoint, - decodeGetAddressesRequest, - encodeResponse, - options..., - )) - r.Methods("GET").Path("/profiles/{id}/addresses/{addressID}").Handler(httptransport.NewServer( - e.GetAddressEndpoint, - decodeGetAddressRequest, - encodeResponse, - options..., - )) - r.Methods("POST").Path("/profiles/{id}/addresses/").Handler(httptransport.NewServer( - e.PostAddressEndpoint, - decodePostAddressRequest, - encodeResponse, - options..., - )) - r.Methods("DELETE").Path("/profiles/{id}/addresses/{addressID}").Handler(httptransport.NewServer( - e.DeleteAddressEndpoint, - decodeDeleteAddressRequest, - encodeResponse, - options..., - )) - return r -} - -func decodePostProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - var req postProfileRequest - if e := json.NewDecoder(r.Body).Decode(&req.Profile); e != nil { - return nil, e - } - return req, nil -} - -func decodeGetProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return getProfileRequest{ID: id}, nil -} - -func decodePutProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var profile Profile - if err := json.NewDecoder(r.Body).Decode(&profile); err != nil { - return nil, err - } - return putProfileRequest{ - ID: id, - Profile: profile, - }, nil -} - -func decodePatchProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var profile Profile - if err := json.NewDecoder(r.Body).Decode(&profile); err != nil { - return nil, err - } - return patchProfileRequest{ - ID: id, - Profile: profile, - }, nil -} - -func decodeDeleteProfileRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return deleteProfileRequest{ID: id}, nil -} - -func decodeGetAddressesRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - return getAddressesRequest{ProfileID: id}, nil -} - -func decodeGetAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - addressID, ok := vars["addressID"] - if !ok { - return nil, ErrBadRouting - } - return getAddressRequest{ - ProfileID: id, - AddressID: addressID, - }, nil -} - -func decodePostAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - var address Address - if err := json.NewDecoder(r.Body).Decode(&address); err != nil { - return nil, err - } - return postAddressRequest{ - ProfileID: id, - Address: address, - }, nil -} - -func decodeDeleteAddressRequest(_ context.Context, r *http.Request) (request interface{}, err error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, ErrBadRouting - } - addressID, ok := vars["addressID"] - if !ok { - return nil, ErrBadRouting - } - return deleteAddressRequest{ - ProfileID: id, - AddressID: addressID, - }, nil -} - -func encodePostProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("POST").Path("/profiles/") - req.URL.Path = "/profiles/" - return encodeRequest(ctx, req, request) -} - -func encodeGetProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}") - r := request.(getProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodePutProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("PUT").Path("/profiles/{id}") - r := request.(putProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodePatchProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("PATCH").Path("/profiles/{id}") - r := request.(patchProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodeDeleteProfileRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("DELETE").Path("/profiles/{id}") - r := request.(deleteProfileRequest) - profileID := url.QueryEscape(r.ID) - req.URL.Path = "/profiles/" + profileID - return encodeRequest(ctx, req, request) -} - -func encodeGetAddressesRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}/addresses/") - r := request.(getAddressesRequest) - profileID := url.QueryEscape(r.ProfileID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" - return encodeRequest(ctx, req, request) -} - -func encodeGetAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("GET").Path("/profiles/{id}/addresses/{addressID}") - r := request.(getAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - addressID := url.QueryEscape(r.AddressID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" + addressID - return encodeRequest(ctx, req, request) -} - -func encodePostAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("POST").Path("/profiles/{id}/addresses/") - r := request.(postAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" - return encodeRequest(ctx, req, request) -} - -func encodeDeleteAddressRequest(ctx context.Context, req *http.Request, request interface{}) error { - // r.Methods("DELETE").Path("/profiles/{id}/addresses/{addressID}") - r := request.(deleteAddressRequest) - profileID := url.QueryEscape(r.ProfileID) - addressID := url.QueryEscape(r.AddressID) - req.URL.Path = "/profiles/" + profileID + "/addresses/" + addressID - return encodeRequest(ctx, req, request) -} - -func decodePostProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response postProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePutProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response putProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePatchProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response patchProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeDeleteProfileResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response deleteProfileResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetAddressesResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getAddressesResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeGetAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response getAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodePostAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response postAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -func decodeDeleteAddressResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response deleteAddressResponse - err := json.NewDecoder(resp.Body).Decode(&response) - return response, err -} - -// errorer is implemented by all concrete response types that may contain -// errors. It allows us to change the HTTP response code without needing to -// trigger an endpoint (transport-level) error. For more information, read the -// big comment in endpoints.go. -type errorer interface { - error() error -} - -// encodeResponse is the common method to encode all response types to the -// client. I chose to do it this way because, since we're using JSON, there's no -// reason to provide anything more specific. It's certainly possible to -// specialize on a per-response (per-method) basis. -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - // Not a Go kit transport error, but a business-logic error. - // Provide those as HTTP errors. - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -// encodeRequest likewise JSON-encodes the request to the HTTP request body. -// Don't use it directly as a transport/http.Client EncodeRequestFunc: -// profilesvc endpoints require mutating the HTTP method and request path. -func encodeRequest(_ context.Context, req *http.Request, request interface{}) error { - var buf bytes.Buffer - err := json.NewEncoder(&buf).Encode(request) - if err != nil { - return err - } - req.Body = ioutil.NopCloser(&buf) - return nil -} - -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - if err == nil { - panic("encodeError with nil error") - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - w.WriteHeader(codeFrom(err)) - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} - -func codeFrom(err error) int { - switch err { - case ErrNotFound: - return http.StatusNotFound - case ErrAlreadyExists, ErrInconsistentIDs: - return http.StatusBadRequest - default: - return http.StatusInternalServerError - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md deleted file mode 100644 index 1a9a14ee..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# shipping - -This example demonstrates a more real-world application consisting of multiple services. - -## Description - -The implementation is based on the container shipping domain from the [Domain Driven Design](http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215) book by Eric Evans, which was [originally](http://dddsample.sourceforge.net/) implemented in Java but has since been ported to Go. This example is a somewhat stripped down version to demonstrate the use of Go kit. The [original Go application](https://github.com/marcusolsson/goddd) is maintained separately and accompanied by an [AngularJS application](https://github.com/marcusolsson/dddelivery-angularjs) as well as a mock [routing service](https://github.com/marcusolsson/pathfinder). - -### Organization - -The application consists of three application services, `booking`, `handling` and `tracking`. Each of these is an individual Go kit service as seen in previous examples. - -- __booking__ - used by the shipping company to book and route cargos. -- __handling__ - used by our staff around the world to register whenever the cargo has been received, loaded etc. -- __tracking__ - used by the customer to track the cargo along the route - -There are also a few pure domain packages that contain some intricate business-logic. They provide domain objects and services that are used by each application service to provide interesting use-cases for the user. - -`inmem` contains in-memory implementations for the repositories found in the domain packages. - -The `routing` package provides a _domain service_ that is used to query an external application for possible routes. - -## Contributing - -As with all Go kit examples you are more than welcome to contribute. If you do however, please consider contributing back to the original project as well. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go deleted file mode 100644 index abe83f75..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/endpoint.go +++ /dev/null @@ -1,139 +0,0 @@ -package booking - -import ( - "context" - "time" - - "github.com/go-kit/kit/endpoint" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type bookCargoRequest struct { - Origin location.UNLocode - Destination location.UNLocode - ArrivalDeadline time.Time -} - -type bookCargoResponse struct { - ID cargo.TrackingID `json:"tracking_id,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r bookCargoResponse) error() error { return r.Err } - -func makeBookCargoEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(bookCargoRequest) - id, err := s.BookNewCargo(req.Origin, req.Destination, req.ArrivalDeadline) - return bookCargoResponse{ID: id, Err: err}, nil - } -} - -type loadCargoRequest struct { - ID cargo.TrackingID -} - -type loadCargoResponse struct { - Cargo *Cargo `json:"cargo,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r loadCargoResponse) error() error { return r.Err } - -func makeLoadCargoEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(loadCargoRequest) - c, err := s.LoadCargo(req.ID) - return loadCargoResponse{Cargo: &c, Err: err}, nil - } -} - -type requestRoutesRequest struct { - ID cargo.TrackingID -} - -type requestRoutesResponse struct { - Routes []cargo.Itinerary `json:"routes,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r requestRoutesResponse) error() error { return r.Err } - -func makeRequestRoutesEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(requestRoutesRequest) - itin := s.RequestPossibleRoutesForCargo(req.ID) - return requestRoutesResponse{Routes: itin, Err: nil}, nil - } -} - -type assignToRouteRequest struct { - ID cargo.TrackingID - Itinerary cargo.Itinerary -} - -type assignToRouteResponse struct { - Err error `json:"error,omitempty"` -} - -func (r assignToRouteResponse) error() error { return r.Err } - -func makeAssignToRouteEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(assignToRouteRequest) - err := s.AssignCargoToRoute(req.ID, req.Itinerary) - return assignToRouteResponse{Err: err}, nil - } -} - -type changeDestinationRequest struct { - ID cargo.TrackingID - Destination location.UNLocode -} - -type changeDestinationResponse struct { - Err error `json:"error,omitempty"` -} - -func (r changeDestinationResponse) error() error { return r.Err } - -func makeChangeDestinationEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(changeDestinationRequest) - err := s.ChangeDestination(req.ID, req.Destination) - return changeDestinationResponse{Err: err}, nil - } -} - -type listCargosRequest struct{} - -type listCargosResponse struct { - Cargos []Cargo `json:"cargos,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r listCargosResponse) error() error { return r.Err } - -func makeListCargosEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - _ = request.(listCargosRequest) - return listCargosResponse{Cargos: s.Cargos(), Err: nil}, nil - } -} - -type listLocationsRequest struct { -} - -type listLocationsResponse struct { - Locations []Location `json:"locations,omitempty"` - Err error `json:"error,omitempty"` -} - -func makeListLocationsEndpoint(s Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - _ = request.(listLocationsRequest) - return listLocationsResponse{Locations: s.Locations(), Err: nil}, nil - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go deleted file mode 100644 index b9b03b91..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/instrumenting.go +++ /dev/null @@ -1,88 +0,0 @@ -package booking - -import ( - "time" - - "github.com/go-kit/kit/metrics" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) BookNewCargo(origin, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) { - defer func(begin time.Time) { - s.requestCount.With("method", "book").Add(1) - s.requestLatency.With("method", "book").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.BookNewCargo(origin, destination, deadline) -} - -func (s *instrumentingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "load").Add(1) - s.requestLatency.With("method", "load").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.LoadCargo(id) -} - -func (s *instrumentingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - defer func(begin time.Time) { - s.requestCount.With("method", "request_routes").Add(1) - s.requestLatency.With("method", "request_routes").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.RequestPossibleRoutesForCargo(id) -} - -func (s *instrumentingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "assign_to_route").Add(1) - s.requestLatency.With("method", "assign_to_route").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.AssignCargoToRoute(id, itinerary) -} - -func (s *instrumentingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) { - defer func(begin time.Time) { - s.requestCount.With("method", "change_destination").Add(1) - s.requestLatency.With("method", "change_destination").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.ChangeDestination(id, l) -} - -func (s *instrumentingService) Cargos() []Cargo { - defer func(begin time.Time) { - s.requestCount.With("method", "list_cargos").Add(1) - s.requestLatency.With("method", "list_cargos").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Cargos() -} - -func (s *instrumentingService) Locations() []Location { - defer func(begin time.Time) { - s.requestCount.With("method", "list_locations").Add(1) - s.requestLatency.With("method", "list_locations").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Locations() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go deleted file mode 100644 index 931d4307..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/logging.go +++ /dev/null @@ -1,102 +0,0 @@ -package booking - -import ( - "time" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) BookNewCargo(origin location.UNLocode, destination location.UNLocode, deadline time.Time) (id cargo.TrackingID, err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "book", - "origin", origin, - "destination", destination, - "arrival_deadline", deadline, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.BookNewCargo(origin, destination, deadline) -} - -func (s *loggingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "load", - "tracking_id", id, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.LoadCargo(id) -} - -func (s *loggingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - defer func(begin time.Time) { - s.logger.Log( - "method", "request_routes", - "tracking_id", id, - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.RequestPossibleRoutesForCargo(id) -} - -func (s *loggingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "assign_to_route", - "tracking_id", id, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.AssignCargoToRoute(id, itinerary) -} - -func (s *loggingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "change_destination", - "tracking_id", id, - "destination", l, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.ChangeDestination(id, l) -} - -func (s *loggingService) Cargos() []Cargo { - defer func(begin time.Time) { - s.logger.Log( - "method", "list_cargos", - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.Cargos() -} - -func (s *loggingService) Locations() []Location { - defer func(begin time.Time) { - s.logger.Log( - "method", "list_locations", - "took", time.Since(begin), - ) - }(time.Now()) - return s.Service.Locations() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go deleted file mode 100644 index 8689a5a5..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/service.go +++ /dev/null @@ -1,197 +0,0 @@ -// Package booking provides the use-case of booking a cargo. Used by views -// facing an administrator. -package booking - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/routing" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// Service is the interface that provides booking methods. -type Service interface { - // BookNewCargo registers a new cargo in the tracking system, not yet - // routed. - BookNewCargo(origin location.UNLocode, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) - - // LoadCargo returns a read model of a cargo. - LoadCargo(id cargo.TrackingID) (Cargo, error) - - // RequestPossibleRoutesForCargo requests a list of itineraries describing - // possible routes for this cargo. - RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary - - // AssignCargoToRoute assigns a cargo to the route specified by the - // itinerary. - AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) error - - // ChangeDestination changes the destination of a cargo. - ChangeDestination(id cargo.TrackingID, destination location.UNLocode) error - - // Cargos returns a list of all cargos that have been booked. - Cargos() []Cargo - - // Locations returns a list of registered locations. - Locations() []Location -} - -type service struct { - cargos cargo.Repository - locations location.Repository - handlingEvents cargo.HandlingEventRepository - routingService routing.Service -} - -func (s *service) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) error { - if id == "" || len(itinerary.Legs) == 0 { - return ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return err - } - - c.AssignToRoute(itinerary) - - return s.cargos.Store(c) -} - -func (s *service) BookNewCargo(origin, destination location.UNLocode, deadline time.Time) (cargo.TrackingID, error) { - if origin == "" || destination == "" || deadline.IsZero() { - return "", ErrInvalidArgument - } - - id := cargo.NextTrackingID() - rs := cargo.RouteSpecification{ - Origin: origin, - Destination: destination, - ArrivalDeadline: deadline, - } - - c := cargo.New(id, rs) - - if err := s.cargos.Store(c); err != nil { - return "", err - } - - return c.TrackingID, nil -} - -func (s *service) LoadCargo(id cargo.TrackingID) (Cargo, error) { - if id == "" { - return Cargo{}, ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return Cargo{}, err - } - - return assemble(c, s.handlingEvents), nil -} - -func (s *service) ChangeDestination(id cargo.TrackingID, destination location.UNLocode) error { - if id == "" || destination == "" { - return ErrInvalidArgument - } - - c, err := s.cargos.Find(id) - if err != nil { - return err - } - - l, err := s.locations.Find(destination) - if err != nil { - return err - } - - c.SpecifyNewRoute(cargo.RouteSpecification{ - Origin: c.Origin, - Destination: l.UNLocode, - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - }) - - if err := s.cargos.Store(c); err != nil { - return err - } - - return nil -} - -func (s *service) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { - if id == "" { - return nil - } - - c, err := s.cargos.Find(id) - if err != nil { - return []cargo.Itinerary{} - } - - return s.routingService.FetchRoutesForSpecification(c.RouteSpecification) -} - -func (s *service) Cargos() []Cargo { - var result []Cargo - for _, c := range s.cargos.FindAll() { - result = append(result, assemble(c, s.handlingEvents)) - } - return result -} - -func (s *service) Locations() []Location { - var result []Location - for _, v := range s.locations.FindAll() { - result = append(result, Location{ - UNLocode: string(v.UNLocode), - Name: v.Name, - }) - } - return result -} - -// NewService creates a booking service with necessary dependencies. -func NewService(cargos cargo.Repository, locations location.Repository, events cargo.HandlingEventRepository, rs routing.Service) Service { - return &service{ - cargos: cargos, - locations: locations, - handlingEvents: events, - routingService: rs, - } -} - -// Location is a read model for booking views. -type Location struct { - UNLocode string `json:"locode"` - Name string `json:"name"` -} - -// Cargo is a read model for booking views. -type Cargo struct { - ArrivalDeadline time.Time `json:"arrival_deadline"` - Destination string `json:"destination"` - Legs []cargo.Leg `json:"legs,omitempty"` - Misrouted bool `json:"misrouted"` - Origin string `json:"origin"` - Routed bool `json:"routed"` - TrackingID string `json:"tracking_id"` -} - -func assemble(c *cargo.Cargo, events cargo.HandlingEventRepository) Cargo { - return Cargo{ - TrackingID: string(c.TrackingID), - Origin: string(c.Origin), - Destination: string(c.RouteSpecification.Destination), - Misrouted: c.Delivery.RoutingStatus == cargo.Misrouted, - Routed: !c.Itinerary.IsEmpty(), - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - Legs: c.Itinerary.Legs, - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go deleted file mode 100644 index 8cf11a26..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/booking/transport.go +++ /dev/null @@ -1,194 +0,0 @@ -package booking - -import ( - "context" - "encoding/json" - "errors" - "net/http" - "time" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" -) - -// MakeHandler returns a handler for the booking service. -func MakeHandler(bs Service, logger kitlog.Logger) http.Handler { - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - bookCargoHandler := kithttp.NewServer( - makeBookCargoEndpoint(bs), - decodeBookCargoRequest, - encodeResponse, - opts..., - ) - loadCargoHandler := kithttp.NewServer( - makeLoadCargoEndpoint(bs), - decodeLoadCargoRequest, - encodeResponse, - opts..., - ) - requestRoutesHandler := kithttp.NewServer( - makeRequestRoutesEndpoint(bs), - decodeRequestRoutesRequest, - encodeResponse, - opts..., - ) - assignToRouteHandler := kithttp.NewServer( - makeAssignToRouteEndpoint(bs), - decodeAssignToRouteRequest, - encodeResponse, - opts..., - ) - changeDestinationHandler := kithttp.NewServer( - makeChangeDestinationEndpoint(bs), - decodeChangeDestinationRequest, - encodeResponse, - opts..., - ) - listCargosHandler := kithttp.NewServer( - makeListCargosEndpoint(bs), - decodeListCargosRequest, - encodeResponse, - opts..., - ) - listLocationsHandler := kithttp.NewServer( - makeListLocationsEndpoint(bs), - decodeListLocationsRequest, - encodeResponse, - opts..., - ) - - r := mux.NewRouter() - - r.Handle("/booking/v1/cargos", bookCargoHandler).Methods("POST") - r.Handle("/booking/v1/cargos", listCargosHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}", loadCargoHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}/request_routes", requestRoutesHandler).Methods("GET") - r.Handle("/booking/v1/cargos/{id}/assign_to_route", assignToRouteHandler).Methods("POST") - r.Handle("/booking/v1/cargos/{id}/change_destination", changeDestinationHandler).Methods("POST") - r.Handle("/booking/v1/locations", listLocationsHandler).Methods("GET") - - return r -} - -var errBadRoute = errors.New("bad route") - -func decodeBookCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - var body struct { - Origin string `json:"origin"` - Destination string `json:"destination"` - ArrivalDeadline time.Time `json:"arrival_deadline"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return bookCargoRequest{ - Origin: location.UNLocode(body.Origin), - Destination: location.UNLocode(body.Destination), - ArrivalDeadline: body.ArrivalDeadline, - }, nil -} - -func decodeLoadCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - return loadCargoRequest{ID: cargo.TrackingID(id)}, nil -} - -func decodeRequestRoutesRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - return requestRoutesRequest{ID: cargo.TrackingID(id)}, nil -} - -func decodeAssignToRouteRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - - var itinerary cargo.Itinerary - if err := json.NewDecoder(r.Body).Decode(&itinerary); err != nil { - return nil, err - } - - return assignToRouteRequest{ - ID: cargo.TrackingID(id), - Itinerary: itinerary, - }, nil -} - -func decodeChangeDestinationRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errBadRoute - } - - var body struct { - Destination string `json:"destination"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return changeDestinationRequest{ - ID: cargo.TrackingID(id), - Destination: location.UNLocode(body.Destination), - }, nil -} - -func decodeListCargosRequest(_ context.Context, r *http.Request) (interface{}, error) { - return listCargosRequest{}, nil -} - -func decodeListLocationsRequest(_ context.Context, r *http.Request) (interface{}, error) { - return listLocationsRequest{}, nil -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go deleted file mode 100644 index a9440f51..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/cargo.go +++ /dev/null @@ -1,137 +0,0 @@ -// Package cargo contains the heart of the domain model. -package cargo - -import ( - "errors" - "strings" - "time" - - "github.com/pborman/uuid" - - "github.com/go-kit/kit/examples/shipping/location" -) - -// TrackingID uniquely identifies a particular cargo. -type TrackingID string - -// Cargo is the central class in the domain model. -type Cargo struct { - TrackingID TrackingID - Origin location.UNLocode - RouteSpecification RouteSpecification - Itinerary Itinerary - Delivery Delivery -} - -// SpecifyNewRoute specifies a new route for this cargo. -func (c *Cargo) SpecifyNewRoute(rs RouteSpecification) { - c.RouteSpecification = rs - c.Delivery = c.Delivery.UpdateOnRouting(c.RouteSpecification, c.Itinerary) -} - -// AssignToRoute attaches a new itinerary to this cargo. -func (c *Cargo) AssignToRoute(itinerary Itinerary) { - c.Itinerary = itinerary - c.Delivery = c.Delivery.UpdateOnRouting(c.RouteSpecification, c.Itinerary) -} - -// DeriveDeliveryProgress updates all aspects of the cargo aggregate status -// based on the current route specification, itinerary and handling of the cargo. -func (c *Cargo) DeriveDeliveryProgress(history HandlingHistory) { - c.Delivery = DeriveDeliveryFrom(c.RouteSpecification, c.Itinerary, history) -} - -// New creates a new, unrouted cargo. -func New(id TrackingID, rs RouteSpecification) *Cargo { - itinerary := Itinerary{} - history := HandlingHistory{make([]HandlingEvent, 0)} - - return &Cargo{ - TrackingID: id, - Origin: rs.Origin, - RouteSpecification: rs, - Delivery: DeriveDeliveryFrom(rs, itinerary, history), - } -} - -// Repository provides access a cargo store. -type Repository interface { - Store(cargo *Cargo) error - Find(id TrackingID) (*Cargo, error) - FindAll() []*Cargo -} - -// ErrUnknown is used when a cargo could not be found. -var ErrUnknown = errors.New("unknown cargo") - -// NextTrackingID generates a new tracking ID. -// TODO: Move to infrastructure(?) -func NextTrackingID() TrackingID { - return TrackingID(strings.Split(strings.ToUpper(uuid.New()), "-")[0]) -} - -// RouteSpecification Contains information about a route: its origin, -// destination and arrival deadline. -type RouteSpecification struct { - Origin location.UNLocode - Destination location.UNLocode - ArrivalDeadline time.Time -} - -// IsSatisfiedBy checks whether provided itinerary satisfies this -// specification. -func (s RouteSpecification) IsSatisfiedBy(itinerary Itinerary) bool { - return itinerary.Legs != nil && - s.Origin == itinerary.InitialDepartureLocation() && - s.Destination == itinerary.FinalArrivalLocation() -} - -// RoutingStatus describes status of cargo routing. -type RoutingStatus int - -// Valid routing statuses. -const ( - NotRouted RoutingStatus = iota - Misrouted - Routed -) - -func (s RoutingStatus) String() string { - switch s { - case NotRouted: - return "Not routed" - case Misrouted: - return "Misrouted" - case Routed: - return "Routed" - } - return "" -} - -// TransportStatus describes status of cargo transportation. -type TransportStatus int - -// Valid transport statuses. -const ( - NotReceived TransportStatus = iota - InPort - OnboardCarrier - Claimed - Unknown -) - -func (s TransportStatus) String() string { - switch s { - case NotReceived: - return "Not received" - case InPort: - return "In port" - case OnboardCarrier: - return "Onboard carrier" - case Claimed: - return "Claimed" - case Unknown: - return "Unknown" - } - return "" -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go deleted file mode 100644 index 34f079dc..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/delivery.go +++ /dev/null @@ -1,174 +0,0 @@ -package cargo - -import ( - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// Delivery is the actual transportation of the cargo, as opposed to the -// customer requirement (RouteSpecification) and the plan (Itinerary). -type Delivery struct { - Itinerary Itinerary - RouteSpecification RouteSpecification - RoutingStatus RoutingStatus - TransportStatus TransportStatus - NextExpectedActivity HandlingActivity - LastEvent HandlingEvent - LastKnownLocation location.UNLocode - CurrentVoyage voyage.Number - ETA time.Time - IsMisdirected bool - IsUnloadedAtDestination bool -} - -// UpdateOnRouting creates a new delivery snapshot to reflect changes in -// routing, i.e. when the route specification or the itinerary has changed but -// no additional handling of the cargo has been performed. -func (d Delivery) UpdateOnRouting(rs RouteSpecification, itinerary Itinerary) Delivery { - return newDelivery(d.LastEvent, itinerary, rs) -} - -// IsOnTrack checks if the delivery is on track. -func (d Delivery) IsOnTrack() bool { - return d.RoutingStatus == Routed && !d.IsMisdirected -} - -// DeriveDeliveryFrom creates a new delivery snapshot based on the complete -// handling history of a cargo, as well as its route specification and -// itinerary. -func DeriveDeliveryFrom(rs RouteSpecification, itinerary Itinerary, history HandlingHistory) Delivery { - lastEvent, _ := history.MostRecentlyCompletedEvent() - return newDelivery(lastEvent, itinerary, rs) -} - -// newDelivery creates a up-to-date delivery based on an handling event, -// itinerary and a route specification. -func newDelivery(lastEvent HandlingEvent, itinerary Itinerary, rs RouteSpecification) Delivery { - var ( - routingStatus = calculateRoutingStatus(itinerary, rs) - transportStatus = calculateTransportStatus(lastEvent) - lastKnownLocation = calculateLastKnownLocation(lastEvent) - isMisdirected = calculateMisdirectedStatus(lastEvent, itinerary) - isUnloadedAtDestination = calculateUnloadedAtDestination(lastEvent, rs) - currentVoyage = calculateCurrentVoyage(transportStatus, lastEvent) - ) - - d := Delivery{ - LastEvent: lastEvent, - Itinerary: itinerary, - RouteSpecification: rs, - RoutingStatus: routingStatus, - TransportStatus: transportStatus, - LastKnownLocation: lastKnownLocation, - IsMisdirected: isMisdirected, - IsUnloadedAtDestination: isUnloadedAtDestination, - CurrentVoyage: currentVoyage, - } - - d.NextExpectedActivity = calculateNextExpectedActivity(d) - d.ETA = calculateETA(d) - - return d -} - -// Below are internal functions used when creating a new delivery. - -func calculateRoutingStatus(itinerary Itinerary, rs RouteSpecification) RoutingStatus { - if itinerary.Legs == nil { - return NotRouted - } - - if rs.IsSatisfiedBy(itinerary) { - return Routed - } - - return Misrouted -} - -func calculateMisdirectedStatus(event HandlingEvent, itinerary Itinerary) bool { - if event.Activity.Type == NotHandled { - return false - } - - return !itinerary.IsExpected(event) -} - -func calculateUnloadedAtDestination(event HandlingEvent, rs RouteSpecification) bool { - if event.Activity.Type == NotHandled { - return false - } - - return event.Activity.Type == Unload && rs.Destination == event.Activity.Location -} - -func calculateTransportStatus(event HandlingEvent) TransportStatus { - switch event.Activity.Type { - case NotHandled: - return NotReceived - case Load: - return OnboardCarrier - case Unload: - return InPort - case Receive: - return InPort - case Customs: - return InPort - case Claim: - return Claimed - } - return Unknown -} - -func calculateLastKnownLocation(event HandlingEvent) location.UNLocode { - return event.Activity.Location -} - -func calculateNextExpectedActivity(d Delivery) HandlingActivity { - if !d.IsOnTrack() { - return HandlingActivity{} - } - - switch d.LastEvent.Activity.Type { - case NotHandled: - return HandlingActivity{Type: Receive, Location: d.RouteSpecification.Origin} - case Receive: - l := d.Itinerary.Legs[0] - return HandlingActivity{Type: Load, Location: l.LoadLocation, VoyageNumber: l.VoyageNumber} - case Load: - for _, l := range d.Itinerary.Legs { - if l.LoadLocation == d.LastEvent.Activity.Location { - return HandlingActivity{Type: Unload, Location: l.UnloadLocation, VoyageNumber: l.VoyageNumber} - } - } - case Unload: - for i, l := range d.Itinerary.Legs { - if l.UnloadLocation == d.LastEvent.Activity.Location { - if i < len(d.Itinerary.Legs)-1 { - return HandlingActivity{Type: Load, Location: d.Itinerary.Legs[i+1].LoadLocation, VoyageNumber: d.Itinerary.Legs[i+1].VoyageNumber} - } - - return HandlingActivity{Type: Claim, Location: l.UnloadLocation} - } - } - } - - return HandlingActivity{} -} - -func calculateCurrentVoyage(transportStatus TransportStatus, event HandlingEvent) voyage.Number { - if transportStatus == OnboardCarrier && event.Activity.Type != NotHandled { - return event.Activity.VoyageNumber - } - - return voyage.Number("") -} - -func calculateETA(d Delivery) time.Time { - if !d.IsOnTrack() { - return time.Time{} - } - - return d.Itinerary.FinalArrivalTime() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go deleted file mode 100644 index bec8509f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/handling.go +++ /dev/null @@ -1,121 +0,0 @@ -package cargo - -// TODO: It would make sense to have this in its own package. Unfortunately, -// then there would be a circular dependency between the cargo and handling -// packages since cargo.Delivery would use handling.HandlingEvent and -// handling.HandlingEvent would use cargo.TrackingID. Also, -// HandlingEventFactory depends on the cargo repository. -// -// It would make sense not having the cargo package depend on handling. - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// HandlingActivity represents how and where a cargo can be handled, and can -// be used to express predictions about what is expected to happen to a cargo -// in the future. -type HandlingActivity struct { - Type HandlingEventType - Location location.UNLocode - VoyageNumber voyage.Number -} - -// HandlingEvent is used to register the event when, for instance, a cargo is -// unloaded from a carrier at a some location at a given time. -type HandlingEvent struct { - TrackingID TrackingID - Activity HandlingActivity -} - -// HandlingEventType describes type of a handling event. -type HandlingEventType int - -// Valid handling event types. -const ( - NotHandled HandlingEventType = iota - Load - Unload - Receive - Claim - Customs -) - -func (t HandlingEventType) String() string { - switch t { - case NotHandled: - return "Not Handled" - case Load: - return "Load" - case Unload: - return "Unload" - case Receive: - return "Receive" - case Claim: - return "Claim" - case Customs: - return "Customs" - } - - return "" -} - -// HandlingHistory is the handling history of a cargo. -type HandlingHistory struct { - HandlingEvents []HandlingEvent -} - -// MostRecentlyCompletedEvent returns most recently completed handling event. -func (h HandlingHistory) MostRecentlyCompletedEvent() (HandlingEvent, error) { - if len(h.HandlingEvents) == 0 { - return HandlingEvent{}, errors.New("delivery history is empty") - } - - return h.HandlingEvents[len(h.HandlingEvents)-1], nil -} - -// HandlingEventRepository provides access a handling event store. -type HandlingEventRepository interface { - Store(e HandlingEvent) - QueryHandlingHistory(TrackingID) HandlingHistory -} - -// HandlingEventFactory creates handling events. -type HandlingEventFactory struct { - CargoRepository Repository - VoyageRepository voyage.Repository - LocationRepository location.Repository -} - -// CreateHandlingEvent creates a validated handling event. -func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID, - voyageNumber voyage.Number, unLocode location.UNLocode, eventType HandlingEventType) (HandlingEvent, error) { - - if _, err := f.CargoRepository.Find(id); err != nil { - return HandlingEvent{}, err - } - - if _, err := f.VoyageRepository.Find(voyageNumber); err != nil { - // TODO: This is pretty ugly, but when creating a Receive event, the voyage number is not known. - if len(voyageNumber) > 0 { - return HandlingEvent{}, err - } - } - - if _, err := f.LocationRepository.Find(unLocode); err != nil { - return HandlingEvent{}, err - } - - return HandlingEvent{ - TrackingID: id, - Activity: HandlingActivity{ - Type: eventType, - Location: unLocode, - VoyageNumber: voyageNumber, - }, - }, nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go deleted file mode 100644 index 6b5088ea..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/cargo/itinerary.go +++ /dev/null @@ -1,91 +0,0 @@ -package cargo - -import ( - "time" - - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// Leg describes the transportation between two locations on a voyage. -type Leg struct { - VoyageNumber voyage.Number `json:"voyage_number"` - LoadLocation location.UNLocode `json:"from"` - UnloadLocation location.UNLocode `json:"to"` - LoadTime time.Time `json:"load_time"` - UnloadTime time.Time `json:"unload_time"` -} - -// NewLeg creates a new itinerary leg. -func NewLeg(voyageNumber voyage.Number, loadLocation, unloadLocation location.UNLocode, loadTime, unloadTime time.Time) Leg { - return Leg{ - VoyageNumber: voyageNumber, - LoadLocation: loadLocation, - UnloadLocation: unloadLocation, - LoadTime: loadTime, - UnloadTime: unloadTime, - } -} - -// Itinerary specifies steps required to transport a cargo from its origin to -// destination. -type Itinerary struct { - Legs []Leg `json:"legs"` -} - -// InitialDepartureLocation returns the start of the itinerary. -func (i Itinerary) InitialDepartureLocation() location.UNLocode { - if i.IsEmpty() { - return location.UNLocode("") - } - return i.Legs[0].LoadLocation -} - -// FinalArrivalLocation returns the end of the itinerary. -func (i Itinerary) FinalArrivalLocation() location.UNLocode { - if i.IsEmpty() { - return location.UNLocode("") - } - return i.Legs[len(i.Legs)-1].UnloadLocation -} - -// FinalArrivalTime returns the expected arrival time at final destination. -func (i Itinerary) FinalArrivalTime() time.Time { - return i.Legs[len(i.Legs)-1].UnloadTime -} - -// IsEmpty checks if the itinerary contains at least one leg. -func (i Itinerary) IsEmpty() bool { - return i.Legs == nil || len(i.Legs) == 0 -} - -// IsExpected checks if the given handling event is expected when executing -// this itinerary. -func (i Itinerary) IsExpected(event HandlingEvent) bool { - if i.IsEmpty() { - return true - } - - switch event.Activity.Type { - case Receive: - return i.InitialDepartureLocation() == event.Activity.Location - case Load: - for _, l := range i.Legs { - if l.LoadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber { - return true - } - } - return false - case Unload: - for _, l := range i.Legs { - if l.UnloadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber { - return true - } - } - return false - case Claim: - return i.FinalArrivalLocation() == event.Activity.Location - } - - return true -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go deleted file mode 100644 index 555d0873..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go +++ /dev/null @@ -1,34 +0,0 @@ -package handling - -import ( - "context" - "time" - - "github.com/go-kit/kit/endpoint" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type registerIncidentRequest struct { - ID cargo.TrackingID - Location location.UNLocode - Voyage voyage.Number - EventType cargo.HandlingEventType - CompletionTime time.Time -} - -type registerIncidentResponse struct { - Err error `json:"error,omitempty"` -} - -func (r registerIncidentResponse) error() error { return r.Err } - -func makeRegisterIncidentEndpoint(hs Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(registerIncidentRequest) - err := hs.RegisterHandlingEvent(req.CompletionTime, req.ID, req.Voyage, req.Location, req.EventType) - return registerIncidentResponse{Err: err}, nil - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go deleted file mode 100644 index fecce04e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go +++ /dev/null @@ -1,37 +0,0 @@ -package handling - -import ( - "time" - - "github.com/go-kit/kit/metrics" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - loc location.UNLocode, eventType cargo.HandlingEventType) error { - - defer func(begin time.Time) { - s.requestCount.With("method", "register_incident").Add(1) - s.requestLatency.With("method", "register_incident").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, loc, eventType) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go deleted file mode 100644 index 84722fb4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go +++ /dev/null @@ -1,38 +0,0 @@ -package handling - -import ( - "time" - - "github.com/go-kit/kit/log" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - unLocode location.UNLocode, eventType cargo.HandlingEventType) (err error) { - defer func(begin time.Time) { - s.logger.Log( - "method", "register_incident", - "tracking_id", id, - "location", unLocode, - "voyage", voyageNumber, - "event_type", eventType, - "completion_time", completed, - "took", time.Since(begin), - "err", err, - ) - }(time.Now()) - return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, unLocode, eventType) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go deleted file mode 100644 index 83d503a2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/service.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package handling provides the use-case for registering incidents. Used by -// views facing the people handling the cargo along its route. -package handling - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/inspection" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// EventHandler provides a means of subscribing to registered handling events. -type EventHandler interface { - CargoWasHandled(cargo.HandlingEvent) -} - -// Service provides handling operations. -type Service interface { - // RegisterHandlingEvent registers a handling event in the system, and - // notifies interested parties that a cargo has been handled. - RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - unLocode location.UNLocode, eventType cargo.HandlingEventType) error -} - -type service struct { - handlingEventRepository cargo.HandlingEventRepository - handlingEventFactory cargo.HandlingEventFactory - handlingEventHandler EventHandler -} - -func (s *service) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, - loc location.UNLocode, eventType cargo.HandlingEventType) error { - if completed.IsZero() || id == "" || loc == "" || eventType == cargo.NotHandled { - return ErrInvalidArgument - } - - e, err := s.handlingEventFactory.CreateHandlingEvent(time.Now(), completed, id, voyageNumber, loc, eventType) - if err != nil { - return err - } - - s.handlingEventRepository.Store(e) - s.handlingEventHandler.CargoWasHandled(e) - - return nil -} - -// NewService creates a handling event service with necessary dependencies. -func NewService(r cargo.HandlingEventRepository, f cargo.HandlingEventFactory, h EventHandler) Service { - return &service{ - handlingEventRepository: r, - handlingEventFactory: f, - handlingEventHandler: h, - } -} - -type handlingEventHandler struct { - InspectionService inspection.Service -} - -func (h *handlingEventHandler) CargoWasHandled(event cargo.HandlingEvent) { - h.InspectionService.InspectCargo(event.TrackingID) -} - -// NewEventHandler returns a new instance of a EventHandler. -func NewEventHandler(s inspection.Service) EventHandler { - return &handlingEventHandler{ - InspectionService: s, - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go deleted file mode 100644 index 0e21365b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/handling/transport.go +++ /dev/null @@ -1,100 +0,0 @@ -package handling - -import ( - "context" - "encoding/json" - "net/http" - "time" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -// MakeHandler returns a handler for the handling service. -func MakeHandler(hs Service, logger kitlog.Logger) http.Handler { - r := mux.NewRouter() - - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - registerIncidentHandler := kithttp.NewServer( - makeRegisterIncidentEndpoint(hs), - decodeRegisterIncidentRequest, - encodeResponse, - opts..., - ) - - r.Handle("/handling/v1/incidents", registerIncidentHandler).Methods("POST") - - return r -} - -func decodeRegisterIncidentRequest(_ context.Context, r *http.Request) (interface{}, error) { - var body struct { - CompletionTime time.Time `json:"completion_time"` - TrackingID string `json:"tracking_id"` - VoyageNumber string `json:"voyage"` - Location string `json:"location"` - EventType string `json:"event_type"` - } - - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { - return nil, err - } - - return registerIncidentRequest{ - CompletionTime: body.CompletionTime, - ID: cargo.TrackingID(body.TrackingID), - Voyage: voyage.Number(body.VoyageNumber), - Location: location.UNLocode(body.Location), - EventType: stringToEventType(body.EventType), - }, nil -} - -func stringToEventType(s string) cargo.HandlingEventType { - types := map[string]cargo.HandlingEventType{ - cargo.Receive.String(): cargo.Receive, - cargo.Load.String(): cargo.Load, - cargo.Unload.String(): cargo.Unload, - cargo.Customs.String(): cargo.Customs, - cargo.Claim.String(): cargo.Claim, - } - return types[s] -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go deleted file mode 100644 index f941b7eb..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inmem/inmem.go +++ /dev/null @@ -1,142 +0,0 @@ -// Package inmem provides in-memory implementations of all the domain repositories. -package inmem - -import ( - "sync" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type cargoRepository struct { - mtx sync.RWMutex - cargos map[cargo.TrackingID]*cargo.Cargo -} - -func (r *cargoRepository) Store(c *cargo.Cargo) error { - r.mtx.Lock() - defer r.mtx.Unlock() - r.cargos[c.TrackingID] = c - return nil -} - -func (r *cargoRepository) Find(id cargo.TrackingID) (*cargo.Cargo, error) { - r.mtx.RLock() - defer r.mtx.RUnlock() - if val, ok := r.cargos[id]; ok { - return val, nil - } - return nil, cargo.ErrUnknown -} - -func (r *cargoRepository) FindAll() []*cargo.Cargo { - r.mtx.RLock() - defer r.mtx.RUnlock() - c := make([]*cargo.Cargo, 0, len(r.cargos)) - for _, val := range r.cargos { - c = append(c, val) - } - return c -} - -// NewCargoRepository returns a new instance of a in-memory cargo repository. -func NewCargoRepository() cargo.Repository { - return &cargoRepository{ - cargos: make(map[cargo.TrackingID]*cargo.Cargo), - } -} - -type locationRepository struct { - locations map[location.UNLocode]*location.Location -} - -func (r *locationRepository) Find(locode location.UNLocode) (*location.Location, error) { - if l, ok := r.locations[locode]; ok { - return l, nil - } - return nil, location.ErrUnknown -} - -func (r *locationRepository) FindAll() []*location.Location { - l := make([]*location.Location, 0, len(r.locations)) - for _, val := range r.locations { - l = append(l, val) - } - return l -} - -// NewLocationRepository returns a new instance of a in-memory location repository. -func NewLocationRepository() location.Repository { - r := &locationRepository{ - locations: make(map[location.UNLocode]*location.Location), - } - - r.locations[location.SESTO] = location.Stockholm - r.locations[location.AUMEL] = location.Melbourne - r.locations[location.CNHKG] = location.Hongkong - r.locations[location.JNTKO] = location.Tokyo - r.locations[location.NLRTM] = location.Rotterdam - r.locations[location.DEHAM] = location.Hamburg - - return r -} - -type voyageRepository struct { - voyages map[voyage.Number]*voyage.Voyage -} - -func (r *voyageRepository) Find(voyageNumber voyage.Number) (*voyage.Voyage, error) { - if v, ok := r.voyages[voyageNumber]; ok { - return v, nil - } - - return nil, voyage.ErrUnknown -} - -// NewVoyageRepository returns a new instance of a in-memory voyage repository. -func NewVoyageRepository() voyage.Repository { - r := &voyageRepository{ - voyages: make(map[voyage.Number]*voyage.Voyage), - } - - r.voyages[voyage.V100.Number] = voyage.V100 - r.voyages[voyage.V300.Number] = voyage.V300 - r.voyages[voyage.V400.Number] = voyage.V400 - - r.voyages[voyage.V0100S.Number] = voyage.V0100S - r.voyages[voyage.V0200T.Number] = voyage.V0200T - r.voyages[voyage.V0300A.Number] = voyage.V0300A - r.voyages[voyage.V0301S.Number] = voyage.V0301S - r.voyages[voyage.V0400S.Number] = voyage.V0400S - - return r -} - -type handlingEventRepository struct { - mtx sync.RWMutex - events map[cargo.TrackingID][]cargo.HandlingEvent -} - -func (r *handlingEventRepository) Store(e cargo.HandlingEvent) { - r.mtx.Lock() - defer r.mtx.Unlock() - // Make array if it's the first event with this tracking ID. - if _, ok := r.events[e.TrackingID]; !ok { - r.events[e.TrackingID] = make([]cargo.HandlingEvent, 0) - } - r.events[e.TrackingID] = append(r.events[e.TrackingID], e) -} - -func (r *handlingEventRepository) QueryHandlingHistory(id cargo.TrackingID) cargo.HandlingHistory { - r.mtx.RLock() - defer r.mtx.RUnlock() - return cargo.HandlingHistory{HandlingEvents: r.events[id]} -} - -// NewHandlingEventRepository returns a new instance of a in-memory handling event repository. -func NewHandlingEventRepository() cargo.HandlingEventRepository { - return &handlingEventRepository{ - events: make(map[cargo.TrackingID][]cargo.HandlingEvent), - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go deleted file mode 100644 index 2ebf73d4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/inspection/inspection.go +++ /dev/null @@ -1,53 +0,0 @@ -// Package inspection provides means to inspect cargos. -package inspection - -import ( - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// EventHandler provides means of subscribing to inspection events. -type EventHandler interface { - CargoWasMisdirected(*cargo.Cargo) - CargoHasArrived(*cargo.Cargo) -} - -// Service provides cargo inspection operations. -type Service interface { - // InspectCargo inspects cargo and send relevant notifications to - // interested parties, for example if a cargo has been misdirected, or - // unloaded at the final destination. - InspectCargo(id cargo.TrackingID) -} - -type service struct { - cargos cargo.Repository - events cargo.HandlingEventRepository - handler EventHandler -} - -// TODO: Should be transactional -func (s *service) InspectCargo(id cargo.TrackingID) { - c, err := s.cargos.Find(id) - if err != nil { - return - } - - h := s.events.QueryHandlingHistory(id) - - c.DeriveDeliveryProgress(h) - - if c.Delivery.IsMisdirected { - s.handler.CargoWasMisdirected(c) - } - - if c.Delivery.IsUnloadedAtDestination { - s.handler.CargoHasArrived(c) - } - - s.cargos.Store(c) -} - -// NewService creates a inspection service with necessary dependencies. -func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository, handler EventHandler) Service { - return &service{cargos, events, handler} -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go deleted file mode 100644 index ee2e5d45..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/location.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package location provides the Location aggregate. -package location - -import ( - "errors" -) - -// UNLocode is the United Nations location code that uniquely identifies a -// particular location. -// -// http://www.unece.org/cefact/locode/ -// http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE -type UNLocode string - -// Location is a location is our model is stops on a journey, such as cargo -// origin or destination, or carrier movement endpoints. -type Location struct { - UNLocode UNLocode - Name string -} - -// ErrUnknown is used when a location could not be found. -var ErrUnknown = errors.New("unknown location") - -// Repository provides access a location store. -type Repository interface { - Find(locode UNLocode) (*Location, error) - FindAll() []*Location -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go deleted file mode 100644 index 7fd34efa..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go +++ /dev/null @@ -1,27 +0,0 @@ -package location - -// Sample UN locodes. -var ( - SESTO UNLocode = "SESTO" - AUMEL UNLocode = "AUMEL" - CNHKG UNLocode = "CNHKG" - USNYC UNLocode = "USNYC" - USCHI UNLocode = "USCHI" - JNTKO UNLocode = "JNTKO" - DEHAM UNLocode = "DEHAM" - NLRTM UNLocode = "NLRTM" - FIHEL UNLocode = "FIHEL" -) - -// Sample locations. -var ( - Stockholm = &Location{SESTO, "Stockholm"} - Melbourne = &Location{AUMEL, "Melbourne"} - Hongkong = &Location{CNHKG, "Hongkong"} - NewYork = &Location{USNYC, "New York"} - Chicago = &Location{USCHI, "Chicago"} - Tokyo = &Location{JNTKO, "Tokyo"} - Hamburg = &Location{DEHAM, "Hamburg"} - Rotterdam = &Location{NLRTM, "Rotterdam"} - Helsinki = &Location{FIHEL, "Helsinki"} -) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go deleted file mode 100644 index 8337d61d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/main.go +++ /dev/null @@ -1,200 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "net/http" - "os" - "os/signal" - "syscall" - "time" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - - "github.com/go-kit/kit/examples/shipping/booking" - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/handling" - "github.com/go-kit/kit/examples/shipping/inmem" - "github.com/go-kit/kit/examples/shipping/inspection" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/routing" - "github.com/go-kit/kit/examples/shipping/tracking" -) - -const ( - defaultPort = "8080" - defaultRoutingServiceURL = "http://localhost:7878" -) - -func main() { - var ( - addr = envString("PORT", defaultPort) - rsurl = envString("ROUTINGSERVICE_URL", defaultRoutingServiceURL) - - httpAddr = flag.String("http.addr", ":"+addr, "HTTP listen address") - routingServiceURL = flag.String("service.routing", rsurl, "routing service URL") - - ctx = context.Background() - ) - - flag.Parse() - - var logger log.Logger - logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - - var ( - cargos = inmem.NewCargoRepository() - locations = inmem.NewLocationRepository() - voyages = inmem.NewVoyageRepository() - handlingEvents = inmem.NewHandlingEventRepository() - ) - - // Configure some questionable dependencies. - var ( - handlingEventFactory = cargo.HandlingEventFactory{ - CargoRepository: cargos, - VoyageRepository: voyages, - LocationRepository: locations, - } - handlingEventHandler = handling.NewEventHandler( - inspection.NewService(cargos, handlingEvents, nil), - ) - ) - - // Facilitate testing by adding some cargos. - storeTestData(cargos) - - fieldKeys := []string{"method"} - - var rs routing.Service - rs = routing.NewProxyingMiddleware(ctx, *routingServiceURL)(rs) - - var bs booking.Service - bs = booking.NewService(cargos, locations, handlingEvents, rs) - bs = booking.NewLoggingService(log.With(logger, "component", "booking"), bs) - bs = booking.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "booking_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "booking_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - bs, - ) - - var ts tracking.Service - ts = tracking.NewService(cargos, handlingEvents) - ts = tracking.NewLoggingService(log.With(logger, "component", "tracking"), ts) - ts = tracking.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "tracking_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "tracking_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - ts, - ) - - var hs handling.Service - hs = handling.NewService(handlingEvents, handlingEventFactory, handlingEventHandler) - hs = handling.NewLoggingService(log.With(logger, "component", "handling"), hs) - hs = handling.NewInstrumentingService( - kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "api", - Subsystem: "handling_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys), - kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "api", - Subsystem: "handling_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys), - hs, - ) - - httpLogger := log.With(logger, "component", "http") - - mux := http.NewServeMux() - - mux.Handle("/booking/v1/", booking.MakeHandler(bs, httpLogger)) - mux.Handle("/tracking/v1/", tracking.MakeHandler(ts, httpLogger)) - mux.Handle("/handling/v1/", handling.MakeHandler(hs, httpLogger)) - - http.Handle("/", accessControl(mux)) - http.Handle("/metrics", promhttp.Handler()) - - errs := make(chan error, 2) - go func() { - logger.Log("transport", "http", "address", *httpAddr, "msg", "listening") - errs <- http.ListenAndServe(*httpAddr, nil) - }() - go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT) - errs <- fmt.Errorf("%s", <-c) - }() - - logger.Log("terminated", <-errs) -} - -func accessControl(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") - w.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type") - - if r.Method == "OPTIONS" { - return - } - - h.ServeHTTP(w, r) - }) -} - -func envString(env, fallback string) string { - e := os.Getenv(env) - if e == "" { - return fallback - } - return e -} - -func storeTestData(r cargo.Repository) { - test1 := cargo.New("FTL456", cargo.RouteSpecification{ - Origin: location.AUMEL, - Destination: location.SESTO, - ArrivalDeadline: time.Now().AddDate(0, 0, 7), - }) - if err := r.Store(test1); err != nil { - panic(err) - } - - test2 := cargo.New("ABC123", cargo.RouteSpecification{ - Origin: location.SESTO, - Destination: location.CNHKG, - ArrivalDeadline: time.Now().AddDate(0, 0, 14), - }) - if err := r.Store(test2); err != nil { - panic(err) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go deleted file mode 100644 index 0c9150b1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/proxying.go +++ /dev/null @@ -1,117 +0,0 @@ -package routing - -import ( - "context" - "encoding/json" - "net/http" - "net/url" - "time" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" - "github.com/go-kit/kit/examples/shipping/location" - "github.com/go-kit/kit/examples/shipping/voyage" -) - -type proxyService struct { - context.Context - FetchRoutesEndpoint endpoint.Endpoint - Service -} - -func (s proxyService) FetchRoutesForSpecification(rs cargo.RouteSpecification) []cargo.Itinerary { - response, err := s.FetchRoutesEndpoint(s.Context, fetchRoutesRequest{ - From: string(rs.Origin), - To: string(rs.Destination), - }) - if err != nil { - return []cargo.Itinerary{} - } - - resp := response.(fetchRoutesResponse) - - var itineraries []cargo.Itinerary - for _, r := range resp.Paths { - var legs []cargo.Leg - for _, e := range r.Edges { - legs = append(legs, cargo.Leg{ - VoyageNumber: voyage.Number(e.Voyage), - LoadLocation: location.UNLocode(e.Origin), - UnloadLocation: location.UNLocode(e.Destination), - LoadTime: e.Departure, - UnloadTime: e.Arrival, - }) - } - - itineraries = append(itineraries, cargo.Itinerary{Legs: legs}) - } - - return itineraries -} - -// ServiceMiddleware defines a middleware for a routing service. -type ServiceMiddleware func(Service) Service - -// NewProxyingMiddleware returns a new instance of a proxying middleware. -func NewProxyingMiddleware(ctx context.Context, proxyURL string) ServiceMiddleware { - return func(next Service) Service { - var e endpoint.Endpoint - e = makeFetchRoutesEndpoint(ctx, proxyURL) - e = circuitbreaker.Hystrix("fetch-routes")(e) - return proxyService{ctx, e, next} - } -} - -type fetchRoutesRequest struct { - From string - To string -} - -type fetchRoutesResponse struct { - Paths []struct { - Edges []struct { - Origin string `json:"origin"` - Destination string `json:"destination"` - Voyage string `json:"voyage"` - Departure time.Time `json:"departure"` - Arrival time.Time `json:"arrival"` - } `json:"edges"` - } `json:"paths"` -} - -func makeFetchRoutesEndpoint(ctx context.Context, instance string) endpoint.Endpoint { - u, err := url.Parse(instance) - if err != nil { - panic(err) - } - if u.Path == "" { - u.Path = "/paths" - } - return kithttp.NewClient( - "GET", u, - encodeFetchRoutesRequest, - decodeFetchRoutesResponse, - ).Endpoint() -} - -func decodeFetchRoutesResponse(_ context.Context, resp *http.Response) (interface{}, error) { - var response fetchRoutesResponse - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func encodeFetchRoutesRequest(_ context.Context, r *http.Request, request interface{}) error { - req := request.(fetchRoutesRequest) - - vals := r.URL.Query() - vals.Add("from", req.From) - vals.Add("to", req.To) - r.URL.RawQuery = vals.Encode() - - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go deleted file mode 100644 index 50496f2b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go +++ /dev/null @@ -1,15 +0,0 @@ -// Package routing provides the routing domain service. It does not actually -// implement the routing service but merely acts as a proxy for a separate -// bounded context. -package routing - -import ( - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// Service provides access to an external routing service. -type Service interface { - // FetchRoutesForSpecification finds all possible routes that satisfy a - // given specification. - FetchRoutesForSpecification(rs cargo.RouteSpecification) []cargo.Itinerary -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go deleted file mode 100644 index ddb13172..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go +++ /dev/null @@ -1,26 +0,0 @@ -package tracking - -import ( - "context" - - "github.com/go-kit/kit/endpoint" -) - -type trackCargoRequest struct { - ID string -} - -type trackCargoResponse struct { - Cargo *Cargo `json:"cargo,omitempty"` - Err error `json:"error,omitempty"` -} - -func (r trackCargoResponse) error() error { return r.Err } - -func makeTrackCargoEndpoint(ts Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(trackCargoRequest) - c, err := ts.Track(req.ID) - return trackCargoResponse{Cargo: &c, Err: err}, nil - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go deleted file mode 100644 index f5dc018b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go +++ /dev/null @@ -1,31 +0,0 @@ -package tracking - -import ( - "time" - - "github.com/go-kit/kit/metrics" -) - -type instrumentingService struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - Service -} - -// NewInstrumentingService returns an instance of an instrumenting Service. -func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { - return &instrumentingService{ - requestCount: counter, - requestLatency: latency, - Service: s, - } -} - -func (s *instrumentingService) Track(id string) (Cargo, error) { - defer func(begin time.Time) { - s.requestCount.With("method", "track").Add(1) - s.requestLatency.With("method", "track").Observe(time.Since(begin).Seconds()) - }(time.Now()) - - return s.Service.Track(id) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go deleted file mode 100644 index 584aeaa4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go +++ /dev/null @@ -1,24 +0,0 @@ -package tracking - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -type loggingService struct { - logger log.Logger - Service -} - -// NewLoggingService returns a new instance of a logging Service. -func NewLoggingService(logger log.Logger, s Service) Service { - return &loggingService{logger, s} -} - -func (s *loggingService) Track(id string) (c Cargo, err error) { - defer func(begin time.Time) { - s.logger.Log("method", "track", "tracking_id", id, "took", time.Since(begin), "err", err) - }(time.Now()) - return s.Service.Track(id) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go deleted file mode 100644 index b0e360b2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/service.go +++ /dev/null @@ -1,163 +0,0 @@ -// Package tracking provides the use-case of tracking a cargo. Used by views -// facing the end-user. -package tracking - -import ( - "errors" - "fmt" - "strings" - "time" - - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// ErrInvalidArgument is returned when one or more arguments are invalid. -var ErrInvalidArgument = errors.New("invalid argument") - -// Service is the interface that provides the basic Track method. -type Service interface { - // Track returns a cargo matching a tracking ID. - Track(id string) (Cargo, error) -} - -type service struct { - cargos cargo.Repository - handlingEvents cargo.HandlingEventRepository -} - -func (s *service) Track(id string) (Cargo, error) { - if id == "" { - return Cargo{}, ErrInvalidArgument - } - c, err := s.cargos.Find(cargo.TrackingID(id)) - if err != nil { - return Cargo{}, err - } - return assemble(c, s.handlingEvents), nil -} - -// NewService returns a new instance of the default Service. -func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository) Service { - return &service{ - cargos: cargos, - handlingEvents: events, - } -} - -// Cargo is a read model for tracking views. -type Cargo struct { - TrackingID string `json:"tracking_id"` - StatusText string `json:"status_text"` - Origin string `json:"origin"` - Destination string `json:"destination"` - ETA time.Time `json:"eta"` - NextExpectedActivity string `json:"next_expected_activity"` - ArrivalDeadline time.Time `json:"arrival_deadline"` - Events []Event `json:"events"` -} - -// Leg is a read model for booking views. -type Leg struct { - VoyageNumber string `json:"voyage_number"` - From string `json:"from"` - To string `json:"to"` - LoadTime time.Time `json:"load_time"` - UnloadTime time.Time `json:"unload_time"` -} - -// Event is a read model for tracking views. -type Event struct { - Description string `json:"description"` - Expected bool `json:"expected"` -} - -func assemble(c *cargo.Cargo, events cargo.HandlingEventRepository) Cargo { - return Cargo{ - TrackingID: string(c.TrackingID), - Origin: string(c.Origin), - Destination: string(c.RouteSpecification.Destination), - ETA: c.Delivery.ETA, - NextExpectedActivity: nextExpectedActivity(c), - ArrivalDeadline: c.RouteSpecification.ArrivalDeadline, - StatusText: assembleStatusText(c), - Events: assembleEvents(c, events), - } -} - -func assembleLegs(c cargo.Cargo) []Leg { - var legs []Leg - for _, l := range c.Itinerary.Legs { - legs = append(legs, Leg{ - VoyageNumber: string(l.VoyageNumber), - From: string(l.LoadLocation), - To: string(l.UnloadLocation), - LoadTime: l.LoadTime, - UnloadTime: l.UnloadTime, - }) - } - return legs -} - -func nextExpectedActivity(c *cargo.Cargo) string { - a := c.Delivery.NextExpectedActivity - prefix := "Next expected activity is to" - - switch a.Type { - case cargo.Load: - return fmt.Sprintf("%s %s cargo onto voyage %s in %s.", prefix, strings.ToLower(a.Type.String()), a.VoyageNumber, a.Location) - case cargo.Unload: - return fmt.Sprintf("%s %s cargo off of voyage %s in %s.", prefix, strings.ToLower(a.Type.String()), a.VoyageNumber, a.Location) - case cargo.NotHandled: - return "There are currently no expected activities for this cargo." - } - - return fmt.Sprintf("%s %s cargo in %s.", prefix, strings.ToLower(a.Type.String()), a.Location) -} - -func assembleStatusText(c *cargo.Cargo) string { - switch c.Delivery.TransportStatus { - case cargo.NotReceived: - return "Not received" - case cargo.InPort: - return fmt.Sprintf("In port %s", c.Delivery.LastKnownLocation) - case cargo.OnboardCarrier: - return fmt.Sprintf("Onboard voyage %s", c.Delivery.CurrentVoyage) - case cargo.Claimed: - return "Claimed" - default: - return "Unknown" - } -} - -func assembleEvents(c *cargo.Cargo, handlingEvents cargo.HandlingEventRepository) []Event { - h := handlingEvents.QueryHandlingHistory(c.TrackingID) - - var events []Event - for _, e := range h.HandlingEvents { - var description string - - switch e.Activity.Type { - case cargo.NotHandled: - description = "Cargo has not yet been received." - case cargo.Receive: - description = fmt.Sprintf("Received in %s, at %s", e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Load: - description = fmt.Sprintf("Loaded onto voyage %s in %s, at %s.", e.Activity.VoyageNumber, e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Unload: - description = fmt.Sprintf("Unloaded off voyage %s in %s, at %s.", e.Activity.VoyageNumber, e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Claim: - description = fmt.Sprintf("Claimed in %s, at %s.", e.Activity.Location, time.Now().Format(time.RFC3339)) - case cargo.Customs: - description = fmt.Sprintf("Cleared customs in %s, at %s.", e.Activity.Location, time.Now().Format(time.RFC3339)) - default: - description = "[Unknown status]" - } - - events = append(events, Event{ - Description: description, - Expected: c.Itinerary.IsExpected(e), - }) - } - - return events -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go deleted file mode 100644 index 32db9716..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/tracking/transport.go +++ /dev/null @@ -1,74 +0,0 @@ -package tracking - -import ( - "context" - "encoding/json" - "errors" - "net/http" - - "github.com/gorilla/mux" - - kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - - "github.com/go-kit/kit/examples/shipping/cargo" -) - -// MakeHandler returns a handler for the tracking service. -func MakeHandler(ts Service, logger kitlog.Logger) http.Handler { - r := mux.NewRouter() - - opts := []kithttp.ServerOption{ - kithttp.ServerErrorLogger(logger), - kithttp.ServerErrorEncoder(encodeError), - } - - trackCargoHandler := kithttp.NewServer( - makeTrackCargoEndpoint(ts), - decodeTrackCargoRequest, - encodeResponse, - opts..., - ) - - r.Handle("/tracking/v1/cargos/{id}", trackCargoHandler).Methods("GET") - - return r -} - -func decodeTrackCargoRequest(_ context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - id, ok := vars["id"] - if !ok { - return nil, errors.New("bad route") - } - return trackCargoRequest{ID: id}, nil -} - -func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { - if e, ok := response.(errorer); ok && e.error() != nil { - encodeError(ctx, e.error(), w) - return nil - } - w.Header().Set("Content-Type", "application/json; charset=utf-8") - return json.NewEncoder(w).Encode(response) -} - -type errorer interface { - error() error -} - -// encode errors from business-logic -func encodeError(_ context.Context, err error, w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - switch err { - case cargo.ErrUnknown: - w.WriteHeader(http.StatusNotFound) - case ErrInvalidArgument: - w.WriteHeader(http.StatusBadRequest) - default: - w.WriteHeader(http.StatusInternalServerError) - } - json.NewEncoder(w).Encode(map[string]interface{}{ - "error": err.Error(), - }) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go deleted file mode 100644 index 751f5885..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go +++ /dev/null @@ -1,40 +0,0 @@ -package voyage - -import "github.com/go-kit/kit/examples/shipping/location" - -// A set of sample voyages. -var ( - V100 = New("V100", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.CNHKG, ArrivalLocation: location.JNTKO}, - {DepartureLocation: location.JNTKO, ArrivalLocation: location.USNYC}, - }, - }) - - V300 = New("V300", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.JNTKO, ArrivalLocation: location.NLRTM}, - {DepartureLocation: location.NLRTM, ArrivalLocation: location.DEHAM}, - {DepartureLocation: location.DEHAM, ArrivalLocation: location.AUMEL}, - {DepartureLocation: location.AUMEL, ArrivalLocation: location.JNTKO}, - }, - }) - - V400 = New("V400", Schedule{ - []CarrierMovement{ - {DepartureLocation: location.DEHAM, ArrivalLocation: location.SESTO}, - {DepartureLocation: location.SESTO, ArrivalLocation: location.FIHEL}, - {DepartureLocation: location.FIHEL, ArrivalLocation: location.DEHAM}, - }, - }) -) - -// These voyages are hard-coded into the current pathfinder. Make sure -// they exist. -var ( - V0100S = New("0100S", Schedule{[]CarrierMovement{}}) - V0200T = New("0200T", Schedule{[]CarrierMovement{}}) - V0300A = New("0300A", Schedule{[]CarrierMovement{}}) - V0301S = New("0301S", Schedule{[]CarrierMovement{}}) - V0400S = New("0400S", Schedule{[]CarrierMovement{}}) -) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go deleted file mode 100644 index 37366af4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go +++ /dev/null @@ -1,44 +0,0 @@ -// Package voyage provides the Voyage aggregate. -package voyage - -import ( - "errors" - "time" - - "github.com/go-kit/kit/examples/shipping/location" -) - -// Number uniquely identifies a particular Voyage. -type Number string - -// Voyage is a uniquely identifiable series of carrier movements. -type Voyage struct { - Number Number - Schedule Schedule -} - -// New creates a voyage with a voyage number and a provided schedule. -func New(n Number, s Schedule) *Voyage { - return &Voyage{Number: n, Schedule: s} -} - -// Schedule describes a voyage schedule. -type Schedule struct { - CarrierMovements []CarrierMovement -} - -// CarrierMovement is a vessel voyage from one location to another. -type CarrierMovement struct { - DepartureLocation location.UNLocode - ArrivalLocation location.UNLocode - DepartureTime time.Time - ArrivalTime time.Time -} - -// ErrUnknown is used when a voyage could not be found. -var ErrUnknown = errors.New("unknown voyage") - -// Repository provides access a voyage store. -type Repository interface { - Find(Number) (*Voyage, error) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go deleted file mode 100644 index 8cbca37d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc1/main.go +++ /dev/null @@ -1,115 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "log" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - httptransport "github.com/go-kit/kit/transport/http" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -// stringService is a concrete implementation of StringService -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// For each method, we define request and response structs -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} - -// Endpoints are a primary abstraction in go-kit. An endpoint represents a single RPC (method in our service interface) -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -// Transports expose the service to the network. In this first example we utilize JSON over HTTP. -func main() { - svc := stringService{} - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go deleted file mode 100644 index 675617d9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/go-kit/kit/metrics" -) - -type instrumentingMiddleware struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - countResult metrics.Histogram - next StringService -} - -func (mw instrumentingMiddleware) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - }(time.Now()) - - output, err = mw.next.Uppercase(s) - return -} - -func (mw instrumentingMiddleware) Count(s string) (n int) { - defer func(begin time.Time) { - lvs := []string{"method", "count", "error", "false"} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - mw.countResult.Observe(float64(n)) - }(time.Now()) - - n = mw.next.Count(s) - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go deleted file mode 100644 index b958f3b6..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -type loggingMiddleware struct { - logger log.Logger - next StringService -} - -func (mw loggingMiddleware) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "uppercase", - "input", s, - "output", output, - "err", err, - "took", time.Since(begin), - ) - }(time.Now()) - - output, err = mw.next.Uppercase(s) - return -} - -func (mw loggingMiddleware) Count(s string) (n int) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "count", - "input", s, - "n", n, - "took", time.Since(begin), - ) - }(time.Now()) - - n = mw.next.Count(s) - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go deleted file mode 100644 index 60544f27..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "net/http" - "os" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - httptransport "github.com/go-kit/kit/transport/http" -) - -func main() { - logger := log.NewLogfmtLogger(os.Stderr) - - fieldKeys := []string{"method", "error"} - requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys) - requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys) - countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "count_result", - Help: "The result of each count method.", - }, []string{}) // no fields here - - var svc StringService - svc = stringService{} - svc = loggingMiddleware{logger, svc} - svc = instrumentingMiddleware{requestCount, requestLatency, countResult, svc} - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - http.Handle("/metrics", promhttp.Handler()) - logger.Log("msg", "HTTP", "addr", ":8080") - logger.Log("err", http.ListenAndServe(":8080", nil)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go deleted file mode 100644 index 1da2f3eb..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "errors" - "strings" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go deleted file mode 100644 index 3e892a9c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/go-kit/kit/endpoint" -) - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(_ context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go deleted file mode 100644 index b21c016c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/go-kit/kit/metrics" -) - -func instrumentingMiddleware( - requestCount metrics.Counter, - requestLatency metrics.Histogram, - countResult metrics.Histogram, -) ServiceMiddleware { - return func(next StringService) StringService { - return instrmw{requestCount, requestLatency, countResult, next} - } -} - -type instrmw struct { - requestCount metrics.Counter - requestLatency metrics.Histogram - countResult metrics.Histogram - StringService -} - -func (mw instrmw) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - }(time.Now()) - - output, err = mw.StringService.Uppercase(s) - return -} - -func (mw instrmw) Count(s string) (n int) { - defer func(begin time.Time) { - lvs := []string{"method", "count", "error", "false"} - mw.requestCount.With(lvs...).Add(1) - mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) - mw.countResult.Observe(float64(n)) - }(time.Now()) - - n = mw.StringService.Count(s) - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go deleted file mode 100644 index 72a2709d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "time" - - "github.com/go-kit/kit/log" -) - -func loggingMiddleware(logger log.Logger) ServiceMiddleware { - return func(next StringService) StringService { - return logmw{logger, next} - } -} - -type logmw struct { - logger log.Logger - StringService -} - -func (mw logmw) Uppercase(s string) (output string, err error) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "uppercase", - "input", s, - "output", output, - "err", err, - "took", time.Since(begin), - ) - }(time.Now()) - - output, err = mw.StringService.Uppercase(s) - return -} - -func (mw logmw) Count(s string) (n int) { - defer func(begin time.Time) { - _ = mw.logger.Log( - "method", "count", - "input", s, - "n", n, - "took", time.Since(begin), - ) - }(time.Now()) - - n = mw.StringService.Count(s) - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go deleted file mode 100644 index 5cdb43b1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "context" - "flag" - "net/http" - "os" - - stdprometheus "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/go-kit/kit/log" - kitprometheus "github.com/go-kit/kit/metrics/prometheus" - httptransport "github.com/go-kit/kit/transport/http" -) - -func main() { - var ( - listen = flag.String("listen", ":8080", "HTTP listen address") - proxy = flag.String("proxy", "", "Optional comma-separated list of URLs to proxy uppercase requests") - ) - flag.Parse() - - var logger log.Logger - logger = log.NewLogfmtLogger(os.Stderr) - logger = log.With(logger, "listen", *listen, "caller", log.DefaultCaller) - - fieldKeys := []string{"method", "error"} - requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_count", - Help: "Number of requests received.", - }, fieldKeys) - requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "request_latency_microseconds", - Help: "Total duration of requests in microseconds.", - }, fieldKeys) - countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ - Namespace: "my_group", - Subsystem: "string_service", - Name: "count_result", - Help: "The result of each count method.", - }, []string{}) - - var svc StringService - svc = stringService{} - svc = proxyingMiddleware(context.Background(), *proxy, logger)(svc) - svc = loggingMiddleware(logger)(svc) - svc = instrumentingMiddleware(requestCount, requestLatency, countResult)(svc) - - uppercaseHandler := httptransport.NewServer( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - encodeResponse, - ) - countHandler := httptransport.NewServer( - makeCountEndpoint(svc), - decodeCountRequest, - encodeResponse, - ) - - http.Handle("/uppercase", uppercaseHandler) - http.Handle("/count", countHandler) - http.Handle("/metrics", promhttp.Handler()) - logger.Log("msg", "HTTP", "addr", *listen) - logger.Log("err", http.ListenAndServe(*listen, nil)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go deleted file mode 100644 index 0f678077..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/proxying.go +++ /dev/null @@ -1,117 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "net/url" - "strings" - "time" - - "golang.org/x/time/rate" - - "github.com/sony/gobreaker" - - "github.com/go-kit/kit/circuitbreaker" - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/ratelimit" - "github.com/go-kit/kit/sd" - "github.com/go-kit/kit/sd/lb" - httptransport "github.com/go-kit/kit/transport/http" -) - -func proxyingMiddleware(ctx context.Context, instances string, logger log.Logger) ServiceMiddleware { - // If instances is empty, don't proxy. - if instances == "" { - logger.Log("proxy_to", "none") - return func(next StringService) StringService { return next } - } - - // Set some parameters for our client. - var ( - qps = 100 // beyond which we will return an error - maxAttempts = 3 // per request, before giving up - maxTime = 250 * time.Millisecond // wallclock time, before giving up - ) - - // Otherwise, construct an endpoint for each instance in the list, and add - // it to a fixed set of endpoints. In a real service, rather than doing this - // by hand, you'd probably use package sd's support for your service - // discovery system. - var ( - instanceList = split(instances) - endpointer sd.FixedEndpointer - ) - logger.Log("proxy_to", fmt.Sprint(instanceList)) - for _, instance := range instanceList { - var e endpoint.Endpoint - e = makeUppercaseProxy(ctx, instance) - e = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(e) - e = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), qps))(e) - endpointer = append(endpointer, e) - } - - // Now, build a single, retrying, load-balancing endpoint out of all of - // those individual endpoints. - balancer := lb.NewRoundRobin(endpointer) - retry := lb.Retry(maxAttempts, maxTime, balancer) - - // And finally, return the ServiceMiddleware, implemented by proxymw. - return func(next StringService) StringService { - return proxymw{ctx, next, retry} - } -} - -// proxymw implements StringService, forwarding Uppercase requests to the -// provided endpoint, and serving all other (i.e. Count) requests via the -// next StringService. -type proxymw struct { - ctx context.Context - next StringService // Serve most requests via this service... - uppercase endpoint.Endpoint // ...except Uppercase, which gets served by this endpoint -} - -func (mw proxymw) Count(s string) int { - return mw.next.Count(s) -} - -func (mw proxymw) Uppercase(s string) (string, error) { - response, err := mw.uppercase(mw.ctx, uppercaseRequest{S: s}) - if err != nil { - return "", err - } - - resp := response.(uppercaseResponse) - if resp.Err != "" { - return resp.V, errors.New(resp.Err) - } - return resp.V, nil -} - -func makeUppercaseProxy(ctx context.Context, instance string) endpoint.Endpoint { - if !strings.HasPrefix(instance, "http") { - instance = "http://" + instance - } - u, err := url.Parse(instance) - if err != nil { - panic(err) - } - if u.Path == "" { - u.Path = "/uppercase" - } - return httptransport.NewClient( - "GET", - u, - encodeRequest, - decodeUppercaseResponse, - ).Endpoint() -} - -func split(s string) []string { - a := strings.Split(s, ",") - for i := range a { - a[i] = strings.TrimSpace(a[i]) - } - return a -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go deleted file mode 100644 index 7e1773a9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/service.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "errors" - "strings" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(string) (string, error) - Count(string) int -} - -type stringService struct{} - -func (stringService) Uppercase(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// ServiceMiddleware is a chainable behavior modifier for StringService. -type ServiceMiddleware func(StringService) StringService diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go deleted file mode 100644 index c17a055c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc3/transport.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "bytes" - "context" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/go-kit/kit/endpoint" -) - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(req.S) - return countResponse{v}, nil - } -} - -func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeUppercaseResponse(_ context.Context, r *http.Response) (interface{}, error) { - var response uppercaseResponse - if err := json.NewDecoder(r.Body).Decode(&response); err != nil { - return nil, err - } - return response, nil -} - -func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -func encodeRequest(_ context.Context, r *http.Request, request interface{}) error { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(request); err != nil { - return err - } - r.Body = ioutil.NopCloser(&buf) - return nil -} - -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go deleted file mode 100644 index c6447079..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/examples/stringsvc4/main.go +++ /dev/null @@ -1,206 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "log" - "strings" - "flag" - "net/http" - - "github.com/go-kit/kit/endpoint" - natstransport "github.com/go-kit/kit/transport/nats" - httptransport "github.com/go-kit/kit/transport/http" - - "github.com/nats-io/go-nats" -) - -// StringService provides operations on strings. -type StringService interface { - Uppercase(context.Context, string) (string, error) - Count(context.Context, string) int -} - -// stringService is a concrete implementation of StringService -type stringService struct{} - -func (stringService) Uppercase(_ context.Context, s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -func (stringService) Count(_ context.Context, s string) int { - return len(s) -} - -// ErrEmpty is returned when an input string is empty. -var ErrEmpty = errors.New("empty string") - -// For each method, we define request and response structs -type uppercaseRequest struct { - S string `json:"s"` -} - -type uppercaseResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -type countRequest struct { - S string `json:"s"` -} - -type countResponse struct { - V int `json:"v"` -} - -// Endpoints are a primary abstraction in go-kit. An endpoint represents a single RPC (method in our service interface) -func makeUppercaseHTTPEndpoint(nc *nats.Conn) endpoint.Endpoint { - return natstransport.NewPublisher( - nc, - "stringsvc.uppercase", - natstransport.EncodeJSONRequest, - decodeUppercaseResponse, - ).Endpoint() -} - -func makeCountHTTPEndpoint(nc *nats.Conn) endpoint.Endpoint { - return natstransport.NewPublisher( - nc, - "stringsvc.count", - natstransport.EncodeJSONRequest, - decodeCountResponse, - ).Endpoint() -} - -func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(uppercaseRequest) - v, err := svc.Uppercase(ctx, req.S) - if err != nil { - return uppercaseResponse{v, err.Error()}, nil - } - return uppercaseResponse{v, ""}, nil - } -} - -func makeCountEndpoint(svc StringService) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(countRequest) - v := svc.Count(ctx, req.S) - return countResponse{v}, nil - } -} - -// Transports expose the service to the network. In this fourth example we utilize JSON over NATS and HTTP. -func main() { - svc := stringService{} - - natsURL := flag.String("nats-url", nats.DefaultURL, "URL for connection to NATS") - flag.Parse() - - nc, err := nats.Connect(*natsURL) - if err != nil { - log.Fatal(err) - } - defer nc.Close() - - uppercaseHTTPHandler := httptransport.NewServer( - makeUppercaseHTTPEndpoint(nc), - decodeUppercaseHTTPRequest, - httptransport.EncodeJSONResponse, - ) - - countHTTPHandler := httptransport.NewServer( - makeCountHTTPEndpoint(nc), - decodeCountHTTPRequest, - httptransport.EncodeJSONResponse, - ) - - uppercaseHandler := natstransport.NewSubscriber( - makeUppercaseEndpoint(svc), - decodeUppercaseRequest, - natstransport.EncodeJSONResponse, - ) - - countHandler := natstransport.NewSubscriber( - makeCountEndpoint(svc), - decodeCountRequest, - natstransport.EncodeJSONResponse, - ) - - uSub, err := nc.QueueSubscribe("stringsvc.uppercase", "stringsvc", uppercaseHandler.ServeMsg(nc)) - if err != nil { - log.Fatal(err) - } - defer uSub.Unsubscribe() - - cSub, err := nc.QueueSubscribe("stringsvc.count", "stringsvc", countHandler.ServeMsg(nc)) - if err != nil { - log.Fatal(err) - } - defer cSub.Unsubscribe() - - http.Handle("/uppercase", uppercaseHTTPHandler) - http.Handle("/count", countHTTPHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) - -} - -func decodeUppercaseHTTPRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request uppercaseRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountHTTPRequest(_ context.Context, r *http.Request) (interface{}, error) { - var request countRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -func decodeUppercaseResponse(_ context.Context, msg *nats.Msg) (interface{}, error) { - var response uppercaseResponse - - if err := json.Unmarshal(msg.Data, &response); err != nil { - return nil, err - } - - return response, nil -} - -func decodeCountResponse(_ context.Context, msg *nats.Msg) (interface{}, error) { - var response countResponse - - if err := json.Unmarshal(msg.Data, &response); err != nil { - return nil, err - } - - return response, nil -} - -func decodeUppercaseRequest(_ context.Context, msg *nats.Msg) (interface{}, error) { - var request uppercaseRequest - - if err := json.Unmarshal(msg.Data, &request); err != nil { - return nil, err - } - return request, nil -} - -func decodeCountRequest(_ context.Context, msg *nats.Msg) (interface{}, error) { - var request countRequest - - if err := json.Unmarshal(msg.Data, &request); err != nil { - return nil, err - } - return request, nil -} - diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint deleted file mode 100755 index 12e30727..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/lint +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -if [ ! $(command -v gometalinter) ] -then - go get github.com/alecthomas/gometalinter - gometalinter --update --install -fi - -time gometalinter \ - --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ - --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ - --exclude='/thrift/' \ - --exclude='/pb/' \ - --exclude='no args in Log call \(vet\)' \ - --disable=dupl \ - --disable=aligncheck \ - --disable=gotype \ - --cyclo-over=20 \ - --tests \ - --concurrency=2 \ - --deadline=300s \ - ./... diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md deleted file mode 100644 index 7222f800..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/README.md +++ /dev/null @@ -1,147 +0,0 @@ -# package log - -`package log` provides a minimal interface for structured logging in services. -It may be wrapped to encode conventions, enforce type-safety, provide leveled -logging, and so on. It can be used for both typical application log events, -and log-structured data streams. - -## Structured logging - -Structured logging is, basically, conceding to the reality that logs are -_data_, and warrant some level of schematic rigor. Using a stricter, -key/value-oriented message format for our logs, containing contextual and -semantic information, makes it much easier to get insight into the -operational activity of the systems we build. Consequently, `package log` is -of the strong belief that "[the benefits of structured logging outweigh the -minimal effort involved](https://www.thoughtworks.com/radar/techniques/structured-logging)". - -Migrating from unstructured to structured logging is probably a lot easier -than you'd expect. - -```go -// Unstructured -log.Printf("HTTP server listening on %s", addr) - -// Structured -logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") -``` - -## Usage - -### Typical application logging - -```go -w := log.NewSyncWriter(os.Stderr) -logger := log.NewLogfmtLogger(w) -logger.Log("question", "what is the meaning of life?", "answer", 42) - -// Output: -// question="what is the meaning of life?" answer=42 -``` - -### Contextual Loggers - -```go -func main() { - var logger log.Logger - logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - logger = log.With(logger, "instance_id", 123) - - logger.Log("msg", "starting") - NewWorker(log.With(logger, "component", "worker")).Run() - NewSlacker(log.With(logger, "component", "slacker")).Run() -} - -// Output: -// instance_id=123 msg=starting -// instance_id=123 component=worker msg=running -// instance_id=123 component=slacker msg=running -``` - -### Interact with stdlib logger - -Redirect stdlib logger to Go kit logger. - -```go -import ( - "os" - stdlog "log" - kitlog "github.com/go-kit/kit/log" -) - -func main() { - logger := kitlog.NewJSONLogger(kitlog.NewSyncWriter(os.Stdout)) - stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) - stdlog.Print("I sure like pie") -} - -// Output: -// {"msg":"I sure like pie","ts":"2016/01/01 12:34:56"} -``` - -Or, if, for legacy reasons, you need to pipe all of your logging through the -stdlib log package, you can redirect Go kit logger to the stdlib logger. - -```go -logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{}) -logger.Log("legacy", true, "msg", "at least it's something") - -// Output: -// 2016/01/01 12:34:56 legacy=true msg="at least it's something" -``` - -### Timestamps and callers - -```go -var logger log.Logger -logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) -logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) - -logger.Log("msg", "hello") - -// Output: -// ts=2016-01-01T12:34:56Z caller=main.go:15 msg=hello -``` - -## Supported output formats - -- [Logfmt](https://brandur.org/logfmt) ([see also](https://blog.codeship.com/logfmt-a-log-format-thats-easy-to-read-and-write)) -- JSON - -## Enhancements - -`package log` is centered on the one-method Logger interface. - -```go -type Logger interface { - Log(keyvals ...interface{}) error -} -``` - -This interface, and its supporting code like is the product of much iteration -and evaluation. For more details on the evolution of the Logger interface, -see [The Hunt for a Logger Interface](http://go-talks.appspot.com/github.com/ChrisHines/talks/structured-logging/structured-logging.slide#1), -a talk by [Chris Hines](https://github.com/ChrisHines). -Also, please see -[#63](https://github.com/go-kit/kit/issues/63), -[#76](https://github.com/go-kit/kit/pull/76), -[#131](https://github.com/go-kit/kit/issues/131), -[#157](https://github.com/go-kit/kit/pull/157), -[#164](https://github.com/go-kit/kit/issues/164), and -[#252](https://github.com/go-kit/kit/pull/252) -to review historical conversations about package log and the Logger interface. - -Value-add packages and suggestions, -like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/kit/log/level), -are of course welcome. Good proposals should - -- Be composable with [contextual loggers](https://godoc.org/github.com/go-kit/kit/log#With), -- Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/kit/log#Caller) in any wrapped contextual loggers, and -- Be friendly to packages that accept only an unadorned log.Logger. - -## Benchmarks & comparisons - -There are a few Go logging benchmarks and comparisons that include Go kit's package log. - -- [imkira/go-loggers-bench](https://github.com/imkira/go-loggers-bench) includes kit/log -- [uber-common/zap](https://github.com/uber-common/zap), a zero-alloc logging library, includes a comparison with kit/log diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go deleted file mode 100644 index a0342127..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/deprecated_levels/levels.go +++ /dev/null @@ -1,127 +0,0 @@ -package levels - -import "github.com/go-kit/kit/log" - -// Levels provides a leveled logging wrapper around a logger. It has five -// levels: debug, info, warning (warn), error, and critical (crit). If you -// want a different set of levels, you can create your own levels type very -// easily, and you can elide the configuration. -type Levels struct { - logger log.Logger - levelKey string - - // We have a choice between storing level values in string fields or - // making a separate context for each level. When using string fields the - // Log method must combine the base context, the level data, and the - // logged keyvals; but the With method only requires updating one context. - // If we instead keep a separate context for each level the Log method - // must only append the new keyvals; but the With method would have to - // update all five contexts. - - // Roughly speaking, storing multiple contexts breaks even if the ratio of - // Log/With calls is more than the number of levels. We have chosen to - // make the With method cheap and the Log method a bit more costly because - // we do not expect most applications to Log more than five times for each - // call to With. - - debugValue string - infoValue string - warnValue string - errorValue string - critValue string -} - -// New creates a new leveled logger, wrapping the passed logger. -func New(logger log.Logger, options ...Option) Levels { - l := Levels{ - logger: logger, - levelKey: "level", - - debugValue: "debug", - infoValue: "info", - warnValue: "warn", - errorValue: "error", - critValue: "crit", - } - for _, option := range options { - option(&l) - } - return l -} - -// With returns a new leveled logger that includes keyvals in all log events. -func (l Levels) With(keyvals ...interface{}) Levels { - return Levels{ - logger: log.With(l.logger, keyvals...), - levelKey: l.levelKey, - debugValue: l.debugValue, - infoValue: l.infoValue, - warnValue: l.warnValue, - errorValue: l.errorValue, - critValue: l.critValue, - } -} - -// Debug returns a debug level logger. -func (l Levels) Debug() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.debugValue) -} - -// Info returns an info level logger. -func (l Levels) Info() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.infoValue) -} - -// Warn returns a warning level logger. -func (l Levels) Warn() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.warnValue) -} - -// Error returns an error level logger. -func (l Levels) Error() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.errorValue) -} - -// Crit returns a critical level logger. -func (l Levels) Crit() log.Logger { - return log.WithPrefix(l.logger, l.levelKey, l.critValue) -} - -// Option sets a parameter for leveled loggers. -type Option func(*Levels) - -// Key sets the key for the field used to indicate log level. By default, -// the key is "level". -func Key(key string) Option { - return func(l *Levels) { l.levelKey = key } -} - -// DebugValue sets the value for the field used to indicate the debug log -// level. By default, the value is "debug". -func DebugValue(value string) Option { - return func(l *Levels) { l.debugValue = value } -} - -// InfoValue sets the value for the field used to indicate the info log level. -// By default, the value is "info". -func InfoValue(value string) Option { - return func(l *Levels) { l.infoValue = value } -} - -// WarnValue sets the value for the field used to indicate the warning log -// level. By default, the value is "warn". -func WarnValue(value string) Option { - return func(l *Levels) { l.warnValue = value } -} - -// ErrorValue sets the value for the field used to indicate the error log -// level. By default, the value is "error". -func ErrorValue(value string) Option { - return func(l *Levels) { l.errorValue = value } -} - -// CritValue sets the value for the field used to indicate the critical log -// level. By default, the value is "crit". -func CritValue(value string) Option { - return func(l *Levels) { l.critValue = value } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go deleted file mode 100644 index 918c0af4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/doc.go +++ /dev/null @@ -1,116 +0,0 @@ -// Package log provides a structured logger. -// -// Structured logging produces logs easily consumed later by humans or -// machines. Humans might be interested in debugging errors, or tracing -// specific requests. Machines might be interested in counting interesting -// events, or aggregating information for off-line processing. In both cases, -// it is important that the log messages are structured and actionable. -// Package log is designed to encourage both of these best practices. -// -// Basic Usage -// -// The fundamental interface is Logger. Loggers create log events from -// key/value data. The Logger interface has a single method, Log, which -// accepts a sequence of alternating key/value pairs, which this package names -// keyvals. -// -// type Logger interface { -// Log(keyvals ...interface{}) error -// } -// -// Here is an example of a function using a Logger to create log events. -// -// func RunTask(task Task, logger log.Logger) string { -// logger.Log("taskID", task.ID, "event", "starting task") -// ... -// logger.Log("taskID", task.ID, "event", "task complete") -// } -// -// The keys in the above example are "taskID" and "event". The values are -// task.ID, "starting task", and "task complete". Every key is followed -// immediately by its value. -// -// Keys are usually plain strings. Values may be any type that has a sensible -// encoding in the chosen log format. With structured logging it is a good -// idea to log simple values without formatting them. This practice allows -// the chosen logger to encode values in the most appropriate way. -// -// Contextual Loggers -// -// A contextual logger stores keyvals that it includes in all log events. -// Building appropriate contextual loggers reduces repetition and aids -// consistency in the resulting log output. With and WithPrefix add context to -// a logger. We can use With to improve the RunTask example. -// -// func RunTask(task Task, logger log.Logger) string { -// logger = log.With(logger, "taskID", task.ID) -// logger.Log("event", "starting task") -// ... -// taskHelper(task.Cmd, logger) -// ... -// logger.Log("event", "task complete") -// } -// -// The improved version emits the same log events as the original for the -// first and last calls to Log. Passing the contextual logger to taskHelper -// enables each log event created by taskHelper to include the task.ID even -// though taskHelper does not have access to that value. Using contextual -// loggers this way simplifies producing log output that enables tracing the -// life cycle of individual tasks. (See the Contextual example for the full -// code of the above snippet.) -// -// Dynamic Contextual Values -// -// A Valuer function stored in a contextual logger generates a new value each -// time an event is logged. The Valuer example demonstrates how this feature -// works. -// -// Valuers provide the basis for consistently logging timestamps and source -// code location. The log package defines several valuers for that purpose. -// See Timestamp, DefaultTimestamp, DefaultTimestampUTC, Caller, and -// DefaultCaller. A common logger initialization sequence that ensures all log -// entries contain a timestamp and source location looks like this: -// -// logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) -// logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) -// -// Concurrent Safety -// -// Applications with multiple goroutines want each log event written to the -// same logger to remain separate from other log events. Package log provides -// two simple solutions for concurrent safe logging. -// -// NewSyncWriter wraps an io.Writer and serializes each call to its Write -// method. Using a SyncWriter has the benefit that the smallest practical -// portion of the logging logic is performed within a mutex, but it requires -// the formatting Logger to make only one call to Write per log event. -// -// NewSyncLogger wraps any Logger and serializes each call to its Log method. -// Using a SyncLogger has the benefit that it guarantees each log event is -// handled atomically within the wrapped logger, but it typically serializes -// both the formatting and output logic. Use a SyncLogger if the formatting -// logger may perform multiple writes per log event. -// -// Error Handling -// -// This package relies on the practice of wrapping or decorating loggers with -// other loggers to provide composable pieces of functionality. It also means -// that Logger.Log must return an error because some -// implementations—especially those that output log data to an io.Writer—may -// encounter errors that cannot be handled locally. This in turn means that -// Loggers that wrap other loggers should return errors from the wrapped -// logger up the stack. -// -// Fortunately, the decorator pattern also provides a way to avoid the -// necessity to check for errors every time an application calls Logger.Log. -// An application required to panic whenever its Logger encounters -// an error could initialize its logger as follows. -// -// fmtlogger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) -// logger := log.LoggerFunc(func(keyvals ...interface{}) error { -// if err := fmtlogger.Log(keyvals...); err != nil { -// panic(err) -// } -// return nil -// }) -package log diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go deleted file mode 100644 index 66094b4d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/json_logger.go +++ /dev/null @@ -1,89 +0,0 @@ -package log - -import ( - "encoding" - "encoding/json" - "fmt" - "io" - "reflect" -) - -type jsonLogger struct { - io.Writer -} - -// NewJSONLogger returns a Logger that encodes keyvals to the Writer as a -// single JSON object. Each log event produces no more than one call to -// w.Write. The passed Writer must be safe for concurrent use by multiple -// goroutines if the returned Logger will be used concurrently. -func NewJSONLogger(w io.Writer) Logger { - return &jsonLogger{w} -} - -func (l *jsonLogger) Log(keyvals ...interface{}) error { - n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd - m := make(map[string]interface{}, n) - for i := 0; i < len(keyvals); i += 2 { - k := keyvals[i] - var v interface{} = ErrMissingValue - if i+1 < len(keyvals) { - v = keyvals[i+1] - } - merge(m, k, v) - } - return json.NewEncoder(l.Writer).Encode(m) -} - -func merge(dst map[string]interface{}, k, v interface{}) { - var key string - switch x := k.(type) { - case string: - key = x - case fmt.Stringer: - key = safeString(x) - default: - key = fmt.Sprint(x) - } - - // We want json.Marshaler and encoding.TextMarshaller to take priority over - // err.Error() and v.String(). But json.Marshall (called later) does that by - // default so we force a no-op if it's one of those 2 case. - switch x := v.(type) { - case json.Marshaler: - case encoding.TextMarshaler: - case error: - v = safeError(x) - case fmt.Stringer: - v = safeString(x) - } - - dst[key] = v -} - -func safeString(str fmt.Stringer) (s string) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { - s = "NULL" - } else { - panic(panicVal) - } - } - }() - s = str.String() - return -} - -func safeError(err error) (s interface{}) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { - s = nil - } else { - panic(panicVal) - } - } - }() - s = err.Error() - return -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go deleted file mode 100644 index 505d307b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/doc.go +++ /dev/null @@ -1,22 +0,0 @@ -// Package level implements leveled logging on top of Go kit's log package. To -// use the level package, create a logger as per normal in your func main, and -// wrap it with level.NewFilter. -// -// var logger log.Logger -// logger = log.NewLogfmtLogger(os.Stderr) -// logger = level.NewFilter(logger, level.AllowInfo()) // <-- -// logger = log.With(logger, "ts", log.DefaultTimestampUTC) -// -// Then, at the callsites, use one of the level.Debug, Info, Warn, or Error -// helper methods to emit leveled log events. -// -// logger.Log("foo", "bar") // as normal, no level -// level.Debug(logger).Log("request_id", reqID, "trace_data", trace.Get()) -// if value > 100 { -// level.Error(logger).Log("value", value) -// } -// -// NewFilter allows precise control over what happens when a log event is -// emitted without a level key, or if a squelched level is used. Check the -// Option functions for details. -package level diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go deleted file mode 100644 index fceafc45..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/level/level.go +++ /dev/null @@ -1,205 +0,0 @@ -package level - -import "github.com/go-kit/kit/log" - -// Error returns a logger that includes a Key/ErrorValue pair. -func Error(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), ErrorValue()) -} - -// Warn returns a logger that includes a Key/WarnValue pair. -func Warn(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), WarnValue()) -} - -// Info returns a logger that includes a Key/InfoValue pair. -func Info(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), InfoValue()) -} - -// Debug returns a logger that includes a Key/DebugValue pair. -func Debug(logger log.Logger) log.Logger { - return log.WithPrefix(logger, Key(), DebugValue()) -} - -// NewFilter wraps next and implements level filtering. See the commentary on -// the Option functions for a detailed description of how to configure levels. -// If no options are provided, all leveled log events created with Debug, -// Info, Warn or Error helper methods are squelched and non-leveled log -// events are passed to next unmodified. -func NewFilter(next log.Logger, options ...Option) log.Logger { - l := &logger{ - next: next, - } - for _, option := range options { - option(l) - } - return l -} - -type logger struct { - next log.Logger - allowed level - squelchNoLevel bool - errNotAllowed error - errNoLevel error -} - -func (l *logger) Log(keyvals ...interface{}) error { - var hasLevel, levelAllowed bool - for i := 1; i < len(keyvals); i += 2 { - if v, ok := keyvals[i].(*levelValue); ok { - hasLevel = true - levelAllowed = l.allowed&v.level != 0 - break - } - } - if !hasLevel && l.squelchNoLevel { - return l.errNoLevel - } - if hasLevel && !levelAllowed { - return l.errNotAllowed - } - return l.next.Log(keyvals...) -} - -// Option sets a parameter for the leveled logger. -type Option func(*logger) - -// AllowAll is an alias for AllowDebug. -func AllowAll() Option { - return AllowDebug() -} - -// AllowDebug allows error, warn, info and debug level log events to pass. -func AllowDebug() Option { - return allowed(levelError | levelWarn | levelInfo | levelDebug) -} - -// AllowInfo allows error, warn and info level log events to pass. -func AllowInfo() Option { - return allowed(levelError | levelWarn | levelInfo) -} - -// AllowWarn allows error and warn level log events to pass. -func AllowWarn() Option { - return allowed(levelError | levelWarn) -} - -// AllowError allows only error level log events to pass. -func AllowError() Option { - return allowed(levelError) -} - -// AllowNone allows no leveled log events to pass. -func AllowNone() Option { - return allowed(0) -} - -func allowed(allowed level) Option { - return func(l *logger) { l.allowed = allowed } -} - -// ErrNotAllowed sets the error to return from Log when it squelches a log -// event disallowed by the configured Allow[Level] option. By default, -// ErrNotAllowed is nil; in this case the log event is squelched with no -// error. -func ErrNotAllowed(err error) Option { - return func(l *logger) { l.errNotAllowed = err } -} - -// SquelchNoLevel instructs Log to squelch log events with no level, so that -// they don't proceed through to the wrapped logger. If SquelchNoLevel is set -// to true and a log event is squelched in this way, the error value -// configured with ErrNoLevel is returned to the caller. -func SquelchNoLevel(squelch bool) Option { - return func(l *logger) { l.squelchNoLevel = squelch } -} - -// ErrNoLevel sets the error to return from Log when it squelches a log event -// with no level. By default, ErrNoLevel is nil; in this case the log event is -// squelched with no error. -func ErrNoLevel(err error) Option { - return func(l *logger) { l.errNoLevel = err } -} - -// NewInjector wraps next and returns a logger that adds a Key/level pair to -// the beginning of log events that don't already contain a level. In effect, -// this gives a default level to logs without a level. -func NewInjector(next log.Logger, level Value) log.Logger { - return &injector{ - next: next, - level: level, - } -} - -type injector struct { - next log.Logger - level interface{} -} - -func (l *injector) Log(keyvals ...interface{}) error { - for i := 1; i < len(keyvals); i += 2 { - if _, ok := keyvals[i].(*levelValue); ok { - return l.next.Log(keyvals...) - } - } - kvs := make([]interface{}, len(keyvals)+2) - kvs[0], kvs[1] = key, l.level - copy(kvs[2:], keyvals) - return l.next.Log(kvs...) -} - -// Value is the interface that each of the canonical level values implement. -// It contains unexported methods that prevent types from other packages from -// implementing it and guaranteeing that NewFilter can distinguish the levels -// defined in this package from all other values. -type Value interface { - String() string - levelVal() -} - -// Key returns the unique key added to log events by the loggers in this -// package. -func Key() interface{} { return key } - -// ErrorValue returns the unique value added to log events by Error. -func ErrorValue() Value { return errorValue } - -// WarnValue returns the unique value added to log events by Warn. -func WarnValue() Value { return warnValue } - -// InfoValue returns the unique value added to log events by Info. -func InfoValue() Value { return infoValue } - -// DebugValue returns the unique value added to log events by Warn. -func DebugValue() Value { return debugValue } - -var ( - // key is of type interface{} so that it allocates once during package - // initialization and avoids allocating every time the value is added to a - // []interface{} later. - key interface{} = "level" - - errorValue = &levelValue{level: levelError, name: "error"} - warnValue = &levelValue{level: levelWarn, name: "warn"} - infoValue = &levelValue{level: levelInfo, name: "info"} - debugValue = &levelValue{level: levelDebug, name: "debug"} -) - -type level byte - -const ( - levelDebug level = 1 << iota - levelInfo - levelWarn - levelError -) - -type levelValue struct { - name string - level -} - -func (v *levelValue) String() string { return v.name } -func (v *levelValue) levelVal() {} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go deleted file mode 100644 index 66a9e2fd..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/log.go +++ /dev/null @@ -1,135 +0,0 @@ -package log - -import "errors" - -// Logger is the fundamental interface for all log operations. Log creates a -// log event from keyvals, a variadic sequence of alternating keys and values. -// Implementations must be safe for concurrent use by multiple goroutines. In -// particular, any implementation of Logger that appends to keyvals or -// modifies or retains any of its elements must make a copy first. -type Logger interface { - Log(keyvals ...interface{}) error -} - -// ErrMissingValue is appended to keyvals slices with odd length to substitute -// the missing value. -var ErrMissingValue = errors.New("(MISSING)") - -// With returns a new contextual logger with keyvals prepended to those passed -// to calls to Log. If logger is also a contextual logger created by With or -// WithPrefix, keyvals is appended to the existing context. -// -// The returned Logger replaces all value elements (odd indexes) containing a -// Valuer with their generated value for each call to its Log method. -func With(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - return &context{ - logger: l.logger, - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - keyvals: kvs[:len(kvs):len(kvs)], - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// WithPrefix returns a new contextual logger with keyvals prepended to those -// passed to calls to Log. If logger is also a contextual logger created by -// With or WithPrefix, keyvals is prepended to the existing context. -// -// The returned Logger replaces all value elements (odd indexes) containing a -// Valuer with their generated value for each call to its Log method. -func WithPrefix(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - n := len(l.keyvals) + len(keyvals) - if len(keyvals)%2 != 0 { - n++ - } - kvs := make([]interface{}, 0, n) - kvs = append(kvs, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - kvs = append(kvs, l.keyvals...) - return &context{ - logger: l.logger, - keyvals: kvs, - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// context is the Logger implementation returned by With and WithPrefix. It -// wraps a Logger and holds keyvals that it includes in all log events. Its -// Log method calls bindValues to generate values for each Valuer in the -// context keyvals. -// -// A context must always have the same number of stack frames between calls to -// its Log method and the eventual binding of Valuers to their value. This -// requirement comes from the functional requirement to allow a context to -// resolve application call site information for a Caller stored in the -// context. To do this we must be able to predict the number of logging -// functions on the stack when bindValues is called. -// -// Two implementation details provide the needed stack depth consistency. -// -// 1. newContext avoids introducing an additional layer when asked to -// wrap another context. -// 2. With and WithPrefix avoid introducing an additional layer by -// returning a newly constructed context with a merged keyvals rather -// than simply wrapping the existing context. -type context struct { - logger Logger - keyvals []interface{} - hasValuer bool -} - -func newContext(logger Logger) *context { - if c, ok := logger.(*context); ok { - return c - } - return &context{logger: logger} -} - -// Log replaces all value elements (odd indexes) containing a Valuer in the -// stored context with their generated value, appends keyvals, and passes the -// result to the wrapped Logger. -func (l *context) Log(keyvals ...interface{}) error { - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - if l.hasValuer { - // If no keyvals were appended above then we must copy l.keyvals so - // that future log events will reevaluate the stored Valuers. - if len(keyvals) == 0 { - kvs = append([]interface{}{}, l.keyvals...) - } - bindValues(kvs[:len(l.keyvals)]) - } - return l.logger.Log(kvs...) -} - -// LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If -// f is a function with the appropriate signature, LoggerFunc(f) is a Logger -// object that calls f. -type LoggerFunc func(...interface{}) error - -// Log implements Logger by calling f(keyvals...). -func (f LoggerFunc) Log(keyvals ...interface{}) error { - return f(keyvals...) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go deleted file mode 100644 index a0030529..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logfmt_logger.go +++ /dev/null @@ -1,62 +0,0 @@ -package log - -import ( - "bytes" - "io" - "sync" - - "github.com/go-logfmt/logfmt" -) - -type logfmtEncoder struct { - *logfmt.Encoder - buf bytes.Buffer -} - -func (l *logfmtEncoder) Reset() { - l.Encoder.Reset() - l.buf.Reset() -} - -var logfmtEncoderPool = sync.Pool{ - New: func() interface{} { - var enc logfmtEncoder - enc.Encoder = logfmt.NewEncoder(&enc.buf) - return &enc - }, -} - -type logfmtLogger struct { - w io.Writer -} - -// NewLogfmtLogger returns a logger that encodes keyvals to the Writer in -// logfmt format. Each log event produces no more than one call to w.Write. -// The passed Writer must be safe for concurrent use by multiple goroutines if -// the returned Logger will be used concurrently. -func NewLogfmtLogger(w io.Writer) Logger { - return &logfmtLogger{w} -} - -func (l logfmtLogger) Log(keyvals ...interface{}) error { - enc := logfmtEncoderPool.Get().(*logfmtEncoder) - enc.Reset() - defer logfmtEncoderPool.Put(enc) - - if err := enc.EncodeKeyvals(keyvals...); err != nil { - return err - } - - // Add newline to the end of the buffer - if err := enc.EndRecord(); err != nil { - return err - } - - // The Logger interface requires implementations to be safe for concurrent - // use by multiple goroutines. For this implementation that means making - // only one call to l.w.Write() for each call to Log. - if _, err := l.w.Write(enc.buf.Bytes()); err != nil { - return err - } - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go deleted file mode 100644 index e7e370c9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/logrus/logrus_logger.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package logrus provides an adapter to the -// go-kit log.Logger interface. -package logrus - -import ( - "errors" - "fmt" - - "github.com/go-kit/kit/log" - "github.com/sirupsen/logrus" -) - -type logrusLogger struct { - *logrus.Logger -} - -var errMissingValue = errors.New("(MISSING)") - -// NewLogrusLogger returns a go-kit log.Logger that sends log events to a Logrus logger. -func NewLogrusLogger(logger *logrus.Logger) log.Logger { - return &logrusLogger{logger} -} - -func (l logrusLogger) Log(keyvals ...interface{}) error { - fields := logrus.Fields{} - for i := 0; i < len(keyvals); i += 2 { - if i+1 < len(keyvals) { - fields[fmt.Sprint(keyvals[i])] = keyvals[i+1] - } else { - fields[fmt.Sprint(keyvals[i])] = errMissingValue - } - } - l.WithFields(fields).Info() - return nil -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go deleted file mode 100644 index 1047d626..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/nop_logger.go +++ /dev/null @@ -1,8 +0,0 @@ -package log - -type nopLogger struct{} - -// NewNopLogger returns a logger that doesn't do anything. -func NewNopLogger() Logger { return nopLogger{} } - -func (nopLogger) Log(...interface{}) error { return nil } diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go deleted file mode 100644 index ff96b5de..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/go-kit/kit/log/stdlib.go +++ /dev/null @@ -1,116 +0,0 @@ -package log - -import ( - "io" - "log" - "regexp" - "strings" -) - -// StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's -// designed to be passed to a Go kit logger as the writer, for cases where -// it's necessary to redirect all Go kit log output to the stdlib logger. -// -// If you have any choice in the matter, you shouldn't use this. Prefer to -// redirect the stdlib log to the Go kit logger via NewStdlibAdapter. -type StdlibWriter struct{} - -// Write implements io.Writer. -func (w StdlibWriter) Write(p []byte) (int, error) { - log.Print(strings.TrimSpace(string(p))) - return len(p), nil -} - -// StdlibAdapter wraps a Logger and allows it to be passed to the stdlib -// logger's SetOutput. It will extract date/timestamps, filenames, and -// messages, and place them under relevant keys. -type StdlibAdapter struct { - Logger - timestampKey string - fileKey string - messageKey string -} - -// StdlibAdapterOption sets a parameter for the StdlibAdapter. -type StdlibAdapterOption func(*StdlibAdapter) - -// TimestampKey sets the key for the timestamp field. By default, it's "ts". -func TimestampKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.timestampKey = key } -} - -// FileKey sets the key for the file and line field. By default, it's "caller". -func FileKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.fileKey = key } -} - -// MessageKey sets the key for the actual log message. By default, it's "msg". -func MessageKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.messageKey = key } -} - -// NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed -// logger. It's designed to be passed to log.SetOutput. -func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { - a := StdlibAdapter{ - Logger: logger, - timestampKey: "ts", - fileKey: "caller", - messageKey: "msg", - } - for _, option := range options { - option(&a) - } - return a -} - -func (a StdlibAdapter) Write(p []byte) (int, error) { - result := subexps(p) - keyvals := []interface{}{} - var timestamp string - if date, ok := result["date"]; ok && date != "" { - timestamp = date - } - if time, ok := result["time"]; ok && time != "" { - if timestamp != "" { - timestamp += " " - } - timestamp += time - } - if timestamp != "" { - keyvals = append(keyvals, a.timestampKey, timestamp) - } - if file, ok := result["file"]; ok && file != "" { - keyvals = append(keyvals, a.fileKey, file) - } - if msg, ok := result["msg"]; ok { - keyvals = append(keyvals, a.messageKey, msg) - } - if err := a.Logger.Log(keyvals...); err != nil { - return 0, err - } - return len(p), nil -} - -const ( - logRegexpDate = `(?P[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` - logRegexpTime = `(?P

    + if data[0] == '<' { + if i := p.html(out, data, true); i > 0 { + data = data[i:] + continue + } + } + + // title block + // + // % stuff + // % more stuff + // % even more stuff + if p.flags&EXTENSION_TITLEBLOCK != 0 { + if data[0] == '%' { + if i := p.titleBlock(out, data, true); i > 0 { + data = data[i:] + continue + } + } + } + + // blank lines. note: returns the # of bytes to skip + if i := p.isEmpty(data); i > 0 { + data = data[i:] + continue + } + + // indented code block: + // + // func max(a, b int) int { + // if a > b { + // return a + // } + // return b + // } + if p.codePrefix(data) > 0 { + data = data[p.code(out, data):] + continue + } + + // fenced code block: + // + // ``` go info string here + // func fact(n int) int { + // if n <= 1 { + // return n + // } + // return n * fact(n-1) + // } + // ``` + if p.flags&EXTENSION_FENCED_CODE != 0 { + if i := p.fencedCodeBlock(out, data, true); i > 0 { + data = data[i:] + continue + } + } + + // horizontal rule: + // + // ------ + // or + // ****** + // or + // ______ + if p.isHRule(data) { + p.r.HRule(out) + var i int + for i = 0; data[i] != '\n'; i++ { + } + data = data[i:] + continue + } + + // block quote: + // + // > A big quote I found somewhere + // > on the web + if p.quotePrefix(data) > 0 { + data = data[p.quote(out, data):] + continue + } + + // table: + // + // Name | Age | Phone + // ------|-----|--------- + // Bob | 31 | 555-1234 + // Alice | 27 | 555-4321 + if p.flags&EXTENSION_TABLES != 0 { + if i := p.table(out, data); i > 0 { + data = data[i:] + continue + } + } + + // an itemized/unordered list: + // + // * Item 1 + // * Item 2 + // + // also works with + or - + if p.uliPrefix(data) > 0 { + data = data[p.list(out, data, 0):] + continue + } + + // a numbered/ordered list: + // + // 1. Item 1 + // 2. Item 2 + if p.oliPrefix(data) > 0 { + data = data[p.list(out, data, LIST_TYPE_ORDERED):] + continue + } + + // definition lists: + // + // Term 1 + // : Definition a + // : Definition b + // + // Term 2 + // : Definition c + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.dliPrefix(data) > 0 { + data = data[p.list(out, data, LIST_TYPE_DEFINITION):] + continue + } + } + + // anything else must look like a normal paragraph + // note: this finds underlined headers, too + data = data[p.paragraph(out, data):] + } + + p.nesting-- +} + +func (p *parser) isPrefixHeader(data []byte) bool { + if data[0] != '#' { + return false + } + + if p.flags&EXTENSION_SPACE_HEADERS != 0 { + level := 0 + for level < 6 && data[level] == '#' { + level++ + } + if data[level] != ' ' { + return false + } + } + return true +} + +func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int { + level := 0 + for level < 6 && data[level] == '#' { + level++ + } + i := skipChar(data, level, ' ') + end := skipUntilChar(data, i, '\n') + skip := end + id := "" + if p.flags&EXTENSION_HEADER_IDS != 0 { + j, k := 0, 0 + // find start/end of header id + for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ { + } + for k = j + 1; k < end && data[k] != '}'; k++ { + } + // extract header id iff found + if j < end && k < end { + id = string(data[j+2 : k]) + end = j + skip = k + 1 + for end > 0 && data[end-1] == ' ' { + end-- + } + } + } + for end > 0 && data[end-1] == '#' { + if isBackslashEscaped(data, end-1) { + break + } + end-- + } + for end > 0 && data[end-1] == ' ' { + end-- + } + if end > i { + if id == "" && p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + id = SanitizedAnchorName(string(data[i:end])) + } + work := func() bool { + p.inline(out, data[i:end]) + return true + } + p.r.Header(out, work, level, id) + } + return skip +} + +func (p *parser) isUnderlinedHeader(data []byte) int { + // test of level 1 header + if data[0] == '=' { + i := skipChar(data, 1, '=') + i = skipChar(data, i, ' ') + if data[i] == '\n' { + return 1 + } else { + return 0 + } + } + + // test of level 2 header + if data[0] == '-' { + i := skipChar(data, 1, '-') + i = skipChar(data, i, ' ') + if data[i] == '\n' { + return 2 + } else { + return 0 + } + } + + return 0 +} + +func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int { + if data[0] != '%' { + return 0 + } + splitData := bytes.Split(data, []byte("\n")) + var i int + for idx, b := range splitData { + if !bytes.HasPrefix(b, []byte("%")) { + i = idx // - 1 + break + } + } + + data = bytes.Join(splitData[0:i], []byte("\n")) + p.r.TitleBlock(out, data) + + return len(data) +} + +func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int { + var i, j int + + // identify the opening tag + if data[0] != '<' { + return 0 + } + curtag, tagfound := p.htmlFindTag(data[1:]) + + // handle special cases + if !tagfound { + // check for an HTML comment + if size := p.htmlComment(out, data, doRender); size > 0 { + return size + } + + // check for an
    tag + if size := p.htmlHr(out, data, doRender); size > 0 { + return size + } + + // check for HTML CDATA + if size := p.htmlCDATA(out, data, doRender); size > 0 { + return size + } + + // no special case recognized + return 0 + } + + // look for an unindented matching closing tag + // followed by a blank line + found := false + /* + closetag := []byte("\n") + j = len(curtag) + 1 + for !found { + // scan for a closing tag at the beginning of a line + if skip := bytes.Index(data[j:], closetag); skip >= 0 { + j += skip + len(closetag) + } else { + break + } + + // see if it is the only thing on the line + if skip := p.isEmpty(data[j:]); skip > 0 { + // see if it is followed by a blank line/eof + j += skip + if j >= len(data) { + found = true + i = j + } else { + if skip := p.isEmpty(data[j:]); skip > 0 { + j += skip + found = true + i = j + } + } + } + } + */ + + // if not found, try a second pass looking for indented match + // but not if tag is "ins" or "del" (following original Markdown.pl) + if !found && curtag != "ins" && curtag != "del" { + i = 1 + for i < len(data) { + i++ + for i < len(data) && !(data[i-1] == '<' && data[i] == '/') { + i++ + } + + if i+2+len(curtag) >= len(data) { + break + } + + j = p.htmlFindEnd(curtag, data[i-1:]) + + if j > 0 { + i += j - 1 + found = true + break + } + } + } + + if !found { + return 0 + } + + // the end of the block has been found + if doRender { + // trim newlines + end := i + for end > 0 && data[end-1] == '\n' { + end-- + } + p.r.BlockHtml(out, data[:end]) + } + + return i +} + +func (p *parser) renderHTMLBlock(out *bytes.Buffer, data []byte, start int, doRender bool) int { + // html block needs to end with a blank line + if i := p.isEmpty(data[start:]); i > 0 { + size := start + i + if doRender { + // trim trailing newlines + end := size + for end > 0 && data[end-1] == '\n' { + end-- + } + p.r.BlockHtml(out, data[:end]) + } + return size + } + return 0 +} + +// HTML comment, lax form +func (p *parser) htmlComment(out *bytes.Buffer, data []byte, doRender bool) int { + i := p.inlineHTMLComment(out, data) + return p.renderHTMLBlock(out, data, i, doRender) +} + +// HTML CDATA section +func (p *parser) htmlCDATA(out *bytes.Buffer, data []byte, doRender bool) int { + const cdataTag = "') { + i++ + } + i++ + // no end-of-comment marker + if i >= len(data) { + return 0 + } + return p.renderHTMLBlock(out, data, i, doRender) +} + +// HR, which is the only self-closing block tag considered +func (p *parser) htmlHr(out *bytes.Buffer, data []byte, doRender bool) int { + if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') { + return 0 + } + if data[3] != ' ' && data[3] != '/' && data[3] != '>' { + // not an
    tag after all; at least not a valid one + return 0 + } + + i := 3 + for data[i] != '>' && data[i] != '\n' { + i++ + } + + if data[i] == '>' { + return p.renderHTMLBlock(out, data, i+1, doRender) + } + + return 0 +} + +func (p *parser) htmlFindTag(data []byte) (string, bool) { + i := 0 + for isalnum(data[i]) { + i++ + } + key := string(data[:i]) + if _, ok := blockTags[key]; ok { + return key, true + } + return "", false +} + +func (p *parser) htmlFindEnd(tag string, data []byte) int { + // assume data[0] == '<' && data[1] == '/' already tested + + // check if tag is a match + closetag := []byte("") + if !bytes.HasPrefix(data, closetag) { + return 0 + } + i := len(closetag) + + // check that the rest of the line is blank + skip := 0 + if skip = p.isEmpty(data[i:]); skip == 0 { + return 0 + } + i += skip + skip = 0 + + if i >= len(data) { + return i + } + + if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + return i + } + if skip = p.isEmpty(data[i:]); skip == 0 { + // following line must be blank + return 0 + } + + return i + skip +} + +func (*parser) isEmpty(data []byte) int { + // it is okay to call isEmpty on an empty buffer + if len(data) == 0 { + return 0 + } + + var i int + for i = 0; i < len(data) && data[i] != '\n'; i++ { + if data[i] != ' ' && data[i] != '\t' { + return 0 + } + } + return i + 1 +} + +func (*parser) isHRule(data []byte) bool { + i := 0 + + // skip up to three spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // look at the hrule char + if data[i] != '*' && data[i] != '-' && data[i] != '_' { + return false + } + c := data[i] + + // the whole line must be the char or whitespace + n := 0 + for data[i] != '\n' { + switch { + case data[i] == c: + n++ + case data[i] != ' ': + return false + } + i++ + } + + return n >= 3 +} + +// isFenceLine checks if there's a fence line (e.g., ``` or ``` go) at the beginning of data, +// and returns the end index if so, or 0 otherwise. It also returns the marker found. +// If syntax is not nil, it gets set to the syntax specified in the fence line. +// A final newline is mandatory to recognize the fence line, unless newlineOptional is true. +func isFenceLine(data []byte, info *string, oldmarker string, newlineOptional bool) (end int, marker string) { + i, size := 0, 0 + + // skip up to three spaces + for i < len(data) && i < 3 && data[i] == ' ' { + i++ + } + + // check for the marker characters: ~ or ` + if i >= len(data) { + return 0, "" + } + if data[i] != '~' && data[i] != '`' { + return 0, "" + } + + c := data[i] + + // the whole line must be the same char or whitespace + for i < len(data) && data[i] == c { + size++ + i++ + } + + // the marker char must occur at least 3 times + if size < 3 { + return 0, "" + } + marker = string(data[i-size : i]) + + // if this is the end marker, it must match the beginning marker + if oldmarker != "" && marker != oldmarker { + return 0, "" + } + + // TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here + // into one, always get the info string, and discard it if the caller doesn't care. + if info != nil { + infoLength := 0 + i = skipChar(data, i, ' ') + + if i >= len(data) { + if newlineOptional && i == len(data) { + return i, marker + } + return 0, "" + } + + infoStart := i + + if data[i] == '{' { + i++ + infoStart++ + + for i < len(data) && data[i] != '}' && data[i] != '\n' { + infoLength++ + i++ + } + + if i >= len(data) || data[i] != '}' { + return 0, "" + } + + // strip all whitespace at the beginning and the end + // of the {} block + for infoLength > 0 && isspace(data[infoStart]) { + infoStart++ + infoLength-- + } + + for infoLength > 0 && isspace(data[infoStart+infoLength-1]) { + infoLength-- + } + + i++ + } else { + for i < len(data) && !isverticalspace(data[i]) { + infoLength++ + i++ + } + } + + *info = strings.TrimSpace(string(data[infoStart : infoStart+infoLength])) + } + + i = skipChar(data, i, ' ') + if i >= len(data) || data[i] != '\n' { + if newlineOptional && i == len(data) { + return i, marker + } + return 0, "" + } + + return i + 1, marker // Take newline into account. +} + +// fencedCodeBlock returns the end index if data contains a fenced code block at the beginning, +// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects. +// If doRender is true, a final newline is mandatory to recognize the fenced code block. +func (p *parser) fencedCodeBlock(out *bytes.Buffer, data []byte, doRender bool) int { + var infoString string + beg, marker := isFenceLine(data, &infoString, "", false) + if beg == 0 || beg >= len(data) { + return 0 + } + + var work bytes.Buffer + + for { + // safe to assume beg < len(data) + + // check for the end of the code block + newlineOptional := !doRender + fenceEnd, _ := isFenceLine(data[beg:], nil, marker, newlineOptional) + if fenceEnd != 0 { + beg += fenceEnd + break + } + + // copy the current line + end := skipUntilChar(data, beg, '\n') + 1 + + // did we reach the end of the buffer without a closing marker? + if end >= len(data) { + return 0 + } + + // verbatim copy to the working buffer + if doRender { + work.Write(data[beg:end]) + } + beg = end + } + + if doRender { + p.r.BlockCode(out, work.Bytes(), infoString) + } + + return beg +} + +func (p *parser) table(out *bytes.Buffer, data []byte) int { + var header bytes.Buffer + i, columns := p.tableHeader(&header, data) + if i == 0 { + return 0 + } + + var body bytes.Buffer + + for i < len(data) { + pipes, rowStart := 0, i + for ; data[i] != '\n'; i++ { + if data[i] == '|' { + pipes++ + } + } + + if pipes == 0 { + i = rowStart + break + } + + // include the newline in data sent to tableRow + i++ + p.tableRow(&body, data[rowStart:i], columns, false) + } + + p.r.Table(out, header.Bytes(), body.Bytes(), columns) + + return i +} + +// check if the specified position is preceded by an odd number of backslashes +func isBackslashEscaped(data []byte, i int) bool { + backslashes := 0 + for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' { + backslashes++ + } + return backslashes&1 == 1 +} + +func (p *parser) tableHeader(out *bytes.Buffer, data []byte) (size int, columns []int) { + i := 0 + colCount := 1 + for i = 0; data[i] != '\n'; i++ { + if data[i] == '|' && !isBackslashEscaped(data, i) { + colCount++ + } + } + + // doesn't look like a table header + if colCount == 1 { + return + } + + // include the newline in the data sent to tableRow + header := data[:i+1] + + // column count ignores pipes at beginning or end of line + if data[0] == '|' { + colCount-- + } + if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) { + colCount-- + } + + columns = make([]int, colCount) + + // move on to the header underline + i++ + if i >= len(data) { + return + } + + if data[i] == '|' && !isBackslashEscaped(data, i) { + i++ + } + i = skipChar(data, i, ' ') + + // each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3 + // and trailing | optional on last column + col := 0 + for data[i] != '\n' { + dashes := 0 + + if data[i] == ':' { + i++ + columns[col] |= TABLE_ALIGNMENT_LEFT + dashes++ + } + for data[i] == '-' { + i++ + dashes++ + } + if data[i] == ':' { + i++ + columns[col] |= TABLE_ALIGNMENT_RIGHT + dashes++ + } + for data[i] == ' ' { + i++ + } + + // end of column test is messy + switch { + case dashes < 3: + // not a valid column + return + + case data[i] == '|' && !isBackslashEscaped(data, i): + // marker found, now skip past trailing whitespace + col++ + i++ + for data[i] == ' ' { + i++ + } + + // trailing junk found after last column + if col >= colCount && data[i] != '\n' { + return + } + + case (data[i] != '|' || isBackslashEscaped(data, i)) && col+1 < colCount: + // something else found where marker was required + return + + case data[i] == '\n': + // marker is optional for the last column + col++ + + default: + // trailing junk found after last column + return + } + } + if col != colCount { + return + } + + p.tableRow(out, header, columns, true) + size = i + 1 + return +} + +func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int, header bool) { + i, col := 0, 0 + var rowWork bytes.Buffer + + if data[i] == '|' && !isBackslashEscaped(data, i) { + i++ + } + + for col = 0; col < len(columns) && i < len(data); col++ { + for data[i] == ' ' { + i++ + } + + cellStart := i + + for (data[i] != '|' || isBackslashEscaped(data, i)) && data[i] != '\n' { + i++ + } + + cellEnd := i + + // skip the end-of-cell marker, possibly taking us past end of buffer + i++ + + for cellEnd > cellStart && data[cellEnd-1] == ' ' { + cellEnd-- + } + + var cellWork bytes.Buffer + p.inline(&cellWork, data[cellStart:cellEnd]) + + if header { + p.r.TableHeaderCell(&rowWork, cellWork.Bytes(), columns[col]) + } else { + p.r.TableCell(&rowWork, cellWork.Bytes(), columns[col]) + } + } + + // pad it out with empty columns to get the right number + for ; col < len(columns); col++ { + if header { + p.r.TableHeaderCell(&rowWork, nil, columns[col]) + } else { + p.r.TableCell(&rowWork, nil, columns[col]) + } + } + + // silently ignore rows with too many cells + + p.r.TableRow(out, rowWork.Bytes()) +} + +// returns blockquote prefix length +func (p *parser) quotePrefix(data []byte) int { + i := 0 + for i < 3 && data[i] == ' ' { + i++ + } + if data[i] == '>' { + if data[i+1] == ' ' { + return i + 2 + } + return i + 1 + } + return 0 +} + +// blockquote ends with at least one blank line +// followed by something without a blockquote prefix +func (p *parser) terminateBlockquote(data []byte, beg, end int) bool { + if p.isEmpty(data[beg:]) <= 0 { + return false + } + if end >= len(data) { + return true + } + return p.quotePrefix(data[end:]) == 0 && p.isEmpty(data[end:]) == 0 +} + +// parse a blockquote fragment +func (p *parser) quote(out *bytes.Buffer, data []byte) int { + var raw bytes.Buffer + beg, end := 0, 0 + for beg < len(data) { + end = beg + // Step over whole lines, collecting them. While doing that, check for + // fenced code and if one's found, incorporate it altogether, + // irregardless of any contents inside it + for data[end] != '\n' { + if p.flags&EXTENSION_FENCED_CODE != 0 { + if i := p.fencedCodeBlock(out, data[end:], false); i > 0 { + // -1 to compensate for the extra end++ after the loop: + end += i - 1 + break + } + } + end++ + } + end++ + + if pre := p.quotePrefix(data[beg:]); pre > 0 { + // skip the prefix + beg += pre + } else if p.terminateBlockquote(data, beg, end) { + break + } + + // this line is part of the blockquote + raw.Write(data[beg:end]) + beg = end + } + + var cooked bytes.Buffer + p.block(&cooked, raw.Bytes()) + p.r.BlockQuote(out, cooked.Bytes()) + return end +} + +// returns prefix length for block code +func (p *parser) codePrefix(data []byte) int { + if data[0] == ' ' && data[1] == ' ' && data[2] == ' ' && data[3] == ' ' { + return 4 + } + return 0 +} + +func (p *parser) code(out *bytes.Buffer, data []byte) int { + var work bytes.Buffer + + i := 0 + for i < len(data) { + beg := i + for data[i] != '\n' { + i++ + } + i++ + + blankline := p.isEmpty(data[beg:i]) > 0 + if pre := p.codePrefix(data[beg:i]); pre > 0 { + beg += pre + } else if !blankline { + // non-empty, non-prefixed line breaks the pre + i = beg + break + } + + // verbatim copy to the working buffeu + if blankline { + work.WriteByte('\n') + } else { + work.Write(data[beg:i]) + } + } + + // trim all the \n off the end of work + workbytes := work.Bytes() + eol := len(workbytes) + for eol > 0 && workbytes[eol-1] == '\n' { + eol-- + } + if eol != len(workbytes) { + work.Truncate(eol) + } + + work.WriteByte('\n') + + p.r.BlockCode(out, work.Bytes(), "") + + return i +} + +// returns unordered list item prefix +func (p *parser) uliPrefix(data []byte) int { + i := 0 + + // start with up to 3 spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // need a *, +, or - followed by a space + if (data[i] != '*' && data[i] != '+' && data[i] != '-') || + data[i+1] != ' ' { + return 0 + } + return i + 2 +} + +// returns ordered list item prefix +func (p *parser) oliPrefix(data []byte) int { + i := 0 + + // start with up to 3 spaces + for i < 3 && data[i] == ' ' { + i++ + } + + // count the digits + start := i + for data[i] >= '0' && data[i] <= '9' { + i++ + } + + // we need >= 1 digits followed by a dot and a space + if start == i || data[i] != '.' || data[i+1] != ' ' { + return 0 + } + return i + 2 +} + +// returns definition list item prefix +func (p *parser) dliPrefix(data []byte) int { + i := 0 + + // need a : followed by a spaces + if data[i] != ':' || data[i+1] != ' ' { + return 0 + } + for data[i] == ' ' { + i++ + } + return i + 2 +} + +// parse ordered or unordered list block +func (p *parser) list(out *bytes.Buffer, data []byte, flags int) int { + i := 0 + flags |= LIST_ITEM_BEGINNING_OF_LIST + work := func() bool { + for i < len(data) { + skip := p.listItem(out, data[i:], &flags) + i += skip + + if skip == 0 || flags&LIST_ITEM_END_OF_LIST != 0 { + break + } + flags &= ^LIST_ITEM_BEGINNING_OF_LIST + } + return true + } + + p.r.List(out, work, flags) + return i +} + +// Parse a single list item. +// Assumes initial prefix is already removed if this is a sublist. +func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *int) int { + // keep track of the indentation of the first line + itemIndent := 0 + for itemIndent < 3 && data[itemIndent] == ' ' { + itemIndent++ + } + + i := p.uliPrefix(data) + if i == 0 { + i = p.oliPrefix(data) + } + if i == 0 { + i = p.dliPrefix(data) + // reset definition term flag + if i > 0 { + *flags &= ^LIST_TYPE_TERM + } + } + if i == 0 { + // if in defnition list, set term flag and continue + if *flags&LIST_TYPE_DEFINITION != 0 { + *flags |= LIST_TYPE_TERM + } else { + return 0 + } + } + + // skip leading whitespace on first line + for data[i] == ' ' { + i++ + } + + // find the end of the line + line := i + for i > 0 && data[i-1] != '\n' { + i++ + } + + // get working buffer + var raw bytes.Buffer + + // put the first line into the working buffer + raw.Write(data[line:i]) + line = i + + // process the following lines + containsBlankLine := false + sublist := 0 + codeBlockMarker := "" + +gatherlines: + for line < len(data) { + i++ + + // find the end of this line + for data[i-1] != '\n' { + i++ + } + + // if it is an empty line, guess that it is part of this item + // and move on to the next line + if p.isEmpty(data[line:i]) > 0 { + containsBlankLine = true + raw.Write(data[line:i]) + line = i + continue + } + + // calculate the indentation + indent := 0 + for indent < 4 && line+indent < i && data[line+indent] == ' ' { + indent++ + } + + chunk := data[line+indent : i] + + if p.flags&EXTENSION_FENCED_CODE != 0 { + // determine if in or out of codeblock + // if in codeblock, ignore normal list processing + _, marker := isFenceLine(chunk, nil, codeBlockMarker, false) + if marker != "" { + if codeBlockMarker == "" { + // start of codeblock + codeBlockMarker = marker + } else { + // end of codeblock. + *flags |= LIST_ITEM_CONTAINS_BLOCK + codeBlockMarker = "" + } + } + // we are in a codeblock, write line, and continue + if codeBlockMarker != "" || marker != "" { + raw.Write(data[line+indent : i]) + line = i + continue gatherlines + } + } + + // evaluate how this line fits in + switch { + // is this a nested list item? + case (p.uliPrefix(chunk) > 0 && !p.isHRule(chunk)) || + p.oliPrefix(chunk) > 0 || + p.dliPrefix(chunk) > 0: + + if containsBlankLine { + // end the list if the type changed after a blank line + if indent <= itemIndent && + ((*flags&LIST_TYPE_ORDERED != 0 && p.uliPrefix(chunk) > 0) || + (*flags&LIST_TYPE_ORDERED == 0 && p.oliPrefix(chunk) > 0)) { + + *flags |= LIST_ITEM_END_OF_LIST + break gatherlines + } + *flags |= LIST_ITEM_CONTAINS_BLOCK + } + + // to be a nested list, it must be indented more + // if not, it is the next item in the same list + if indent <= itemIndent { + break gatherlines + } + + // is this the first item in the nested list? + if sublist == 0 { + sublist = raw.Len() + } + + // is this a nested prefix header? + case p.isPrefixHeader(chunk): + // if the header is not indented, it is not nested in the list + // and thus ends the list + if containsBlankLine && indent < 4 { + *flags |= LIST_ITEM_END_OF_LIST + break gatherlines + } + *flags |= LIST_ITEM_CONTAINS_BLOCK + + // anything following an empty line is only part + // of this item if it is indented 4 spaces + // (regardless of the indentation of the beginning of the item) + case containsBlankLine && indent < 4: + if *flags&LIST_TYPE_DEFINITION != 0 && i < len(data)-1 { + // is the next item still a part of this list? + next := i + for data[next] != '\n' { + next++ + } + for next < len(data)-1 && data[next] == '\n' { + next++ + } + if i < len(data)-1 && data[i] != ':' && data[next] != ':' { + *flags |= LIST_ITEM_END_OF_LIST + } + } else { + *flags |= LIST_ITEM_END_OF_LIST + } + break gatherlines + + // a blank line means this should be parsed as a block + case containsBlankLine: + *flags |= LIST_ITEM_CONTAINS_BLOCK + } + + containsBlankLine = false + + // add the line into the working buffer without prefix + raw.Write(data[line+indent : i]) + + line = i + } + + // If reached end of data, the Renderer.ListItem call we're going to make below + // is definitely the last in the list. + if line >= len(data) { + *flags |= LIST_ITEM_END_OF_LIST + } + + rawBytes := raw.Bytes() + + // render the contents of the list item + var cooked bytes.Buffer + if *flags&LIST_ITEM_CONTAINS_BLOCK != 0 && *flags&LIST_TYPE_TERM == 0 { + // intermediate render of block item, except for definition term + if sublist > 0 { + p.block(&cooked, rawBytes[:sublist]) + p.block(&cooked, rawBytes[sublist:]) + } else { + p.block(&cooked, rawBytes) + } + } else { + // intermediate render of inline item + if sublist > 0 { + p.inline(&cooked, rawBytes[:sublist]) + p.block(&cooked, rawBytes[sublist:]) + } else { + p.inline(&cooked, rawBytes) + } + } + + // render the actual list item + cookedBytes := cooked.Bytes() + parsedEnd := len(cookedBytes) + + // strip trailing newlines + for parsedEnd > 0 && cookedBytes[parsedEnd-1] == '\n' { + parsedEnd-- + } + p.r.ListItem(out, cookedBytes[:parsedEnd], *flags) + + return line +} + +// render a single paragraph that has already been parsed out +func (p *parser) renderParagraph(out *bytes.Buffer, data []byte) { + if len(data) == 0 { + return + } + + // trim leading spaces + beg := 0 + for data[beg] == ' ' { + beg++ + } + + // trim trailing newline + end := len(data) - 1 + + // trim trailing spaces + for end > beg && data[end-1] == ' ' { + end-- + } + + work := func() bool { + p.inline(out, data[beg:end]) + return true + } + p.r.Paragraph(out, work) +} + +func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { + // prev: index of 1st char of previous line + // line: index of 1st char of current line + // i: index of cursor/end of current line + var prev, line, i int + + // keep going until we find something to mark the end of the paragraph + for i < len(data) { + // mark the beginning of the current line + prev = line + current := data[i:] + line = i + + // did we find a blank line marking the end of the paragraph? + if n := p.isEmpty(current); n > 0 { + // did this blank line followed by a definition list item? + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if i < len(data)-1 && data[i+1] == ':' { + return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + } + } + + p.renderParagraph(out, data[:i]) + return i + n + } + + // an underline under some text marks a header, so our paragraph ended on prev line + if i > 0 { + if level := p.isUnderlinedHeader(current); level > 0 { + // render the paragraph + p.renderParagraph(out, data[:prev]) + + // ignore leading and trailing whitespace + eol := i - 1 + for prev < eol && data[prev] == ' ' { + prev++ + } + for eol > prev && data[eol-1] == ' ' { + eol-- + } + + // render the header + // this ugly double closure avoids forcing variables onto the heap + work := func(o *bytes.Buffer, pp *parser, d []byte) func() bool { + return func() bool { + pp.inline(o, d) + return true + } + }(out, p, data[prev:eol]) + + id := "" + if p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + id = SanitizedAnchorName(string(data[prev:eol])) + } + + p.r.Header(out, work, level, id) + + // find the end of the underline + for data[i] != '\n' { + i++ + } + return i + } + } + + // if the next line starts a block of HTML, then the paragraph ends here + if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + if data[i] == '<' && p.html(out, current, false) > 0 { + // rewind to before the HTML block + p.renderParagraph(out, data[:i]) + return i + } + } + + // if there's a prefixed header or a horizontal rule after this, paragraph is over + if p.isPrefixHeader(current) || p.isHRule(current) { + p.renderParagraph(out, data[:i]) + return i + } + + // if there's a fenced code block, paragraph is over + if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.fencedCodeBlock(out, current, false) > 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + + // if there's a definition list item, prev line is a definition term + if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.dliPrefix(current) != 0 { + return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + } + } + + // if there's a list after this, paragraph is over + if p.flags&EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK != 0 { + if p.uliPrefix(current) != 0 || + p.oliPrefix(current) != 0 || + p.quotePrefix(current) != 0 || + p.codePrefix(current) != 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + + // otherwise, scan to the beginning of the next line + for data[i] != '\n' { + i++ + } + i++ + } + + p.renderParagraph(out, data[:i]) + return i +} + +// SanitizedAnchorName returns a sanitized anchor name for the given text. +// +// It implements the algorithm specified in the package comment. +func SanitizedAnchorName(text string) string { + var anchorName []rune + futureDash := false + for _, r := range text { + switch { + case unicode.IsLetter(r) || unicode.IsNumber(r): + if futureDash && len(anchorName) > 0 { + anchorName = append(anchorName, '-') + } + futureDash = false + anchorName = append(anchorName, unicode.ToLower(r)) + default: + futureDash = true + } + } + return string(anchorName) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go new file mode 100644 index 00000000..9656c42a --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/doc.go @@ -0,0 +1,32 @@ +// Package blackfriday is a Markdown processor. +// +// It translates plain text with simple formatting rules into HTML or LaTeX. +// +// Sanitized Anchor Names +// +// Blackfriday includes an algorithm for creating sanitized anchor names +// corresponding to a given input text. This algorithm is used to create +// anchors for headings when EXTENSION_AUTO_HEADER_IDS is enabled. The +// algorithm is specified below, so that other packages can create +// compatible anchor names and links to those anchors. +// +// The algorithm iterates over the input text, interpreted as UTF-8, +// one Unicode code point (rune) at a time. All runes that are letters (category L) +// or numbers (category N) are considered valid characters. They are mapped to +// lower case, and included in the output. All other runes are considered +// invalid characters. Invalid characters that preceed the first valid character, +// as well as invalid character that follow the last valid character +// are dropped completely. All other sequences of invalid characters +// between two valid characters are replaced with a single dash character '-'. +// +// SanitizedAnchorName exposes this functionality, and can be used to +// create compatible links to the anchor names generated by blackfriday. +// This algorithm is also implemented in a small standalone package at +// github.com/shurcooL/sanitized_anchor_name. It can be useful for clients +// that want a small package and don't need full functionality of blackfriday. +package blackfriday + +// NOTE: Keep Sanitized Anchor Name algorithm in sync with package +// github.com/shurcooL/sanitized_anchor_name. +// Otherwise, users of sanitized_anchor_name will get anchor names +// that are incompatible with those generated by blackfriday. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod new file mode 100644 index 00000000..b05561a0 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/go.mod @@ -0,0 +1 @@ +module github.com/russross/blackfriday diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go new file mode 100644 index 00000000..e0a6c69c --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/russross/blackfriday/html.go @@ -0,0 +1,938 @@ +// +// Blackfriday Markdown Processor +// Available at http://github.com/russross/blackfriday +// +// Copyright © 2011 Russ Ross . +// Distributed under the Simplified BSD License. +// See README.md for details. +// + +// +// +// HTML rendering backend +// +// + +package blackfriday + +import ( + "bytes" + "fmt" + "regexp" + "strconv" + "strings" +) + +// Html renderer configuration options. +const ( + HTML_SKIP_HTML = 1 << iota // skip preformatted HTML blocks + HTML_SKIP_STYLE // skip embedded ", basePathEscaped) - fmt.Fprintf(w, "

    %s

    ", basePathEscaped) - fmt.Fprintf(w, "
      ") - - if len(basePathEscaped) > 1 { - var parentURI URI - base.CopyTo(&parentURI) - parentURI.Update(string(base.Path()) + "/..") - parentPathEscaped := html.EscapeString(string(parentURI.Path())) - fmt.Fprintf(w, `
    • ..
    • `, parentPathEscaped) - } - - f, err := os.Open(dirPath) - if err != nil { - return nil, err - } - - fileinfos, err := f.Readdir(0) - f.Close() - if err != nil { - return nil, err - } - - fm := make(map[string]os.FileInfo, len(fileinfos)) - var filenames []string - for _, fi := range fileinfos { - name := fi.Name() - if strings.HasSuffix(name, h.compressedFileSuffix) { - // Do not show compressed files on index page. - continue - } - fm[name] = fi - filenames = append(filenames, name) - } - - var u URI - base.CopyTo(&u) - u.Update(string(u.Path()) + "/") - - sort.Sort(sort.StringSlice(filenames)) - for _, name := range filenames { - u.Update(name) - pathEscaped := html.EscapeString(string(u.Path())) - fi := fm[name] - auxStr := "dir" - className := "dir" - if !fi.IsDir() { - auxStr = fmt.Sprintf("file, %d bytes", fi.Size()) - className = "file" - } - fmt.Fprintf(w, `
    • %s, %s, last modified %s
    • `, - pathEscaped, className, html.EscapeString(name), auxStr, fsModTime(fi.ModTime())) - } - - fmt.Fprintf(w, "
    ") - - if mustCompress { - var zbuf ByteBuffer - zbuf.B = AppendGzipBytesLevel(zbuf.B, w.B, CompressDefaultCompression) - w = &zbuf - } - - dirIndex := w.B - lastModified := time.Now() - ff := &fsFile{ - h: h, - dirIndex: dirIndex, - contentType: "text/html; charset=utf-8", - contentLength: len(dirIndex), - compressed: mustCompress, - lastModified: lastModified, - lastModifiedStr: AppendHTTPDate(nil, lastModified), - - t: lastModified, - } - return ff, nil -} - -const ( - fsMinCompressRatio = 0.8 - fsMaxCompressibleFileSize = 8 * 1024 * 1024 -) - -func (h *fsHandler) compressAndOpenFSFile(filePath string) (*fsFile, error) { - f, err := os.Open(filePath) - if err != nil { - return nil, err - } - - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for file %q: %s", filePath, err) - } - - if fileInfo.IsDir() { - f.Close() - return nil, errDirIndexRequired - } - - if strings.HasSuffix(filePath, h.compressedFileSuffix) || - fileInfo.Size() > fsMaxCompressibleFileSize || - !isFileCompressible(f, fsMinCompressRatio) { - return h.newFSFile(f, fileInfo, false) - } - - compressedFilePath := filePath + h.compressedFileSuffix - absPath, err := filepath.Abs(compressedFilePath) - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot determine absolute path for %q: %s", compressedFilePath, err) - } - - flock := getFileLock(absPath) - flock.Lock() - ff, err := h.compressFileNolock(f, fileInfo, filePath, compressedFilePath) - flock.Unlock() - - return ff, err -} - -func (h *fsHandler) compressFileNolock(f *os.File, fileInfo os.FileInfo, filePath, compressedFilePath string) (*fsFile, error) { - // Attempt to open compressed file created by another concurrent - // goroutine. - // It is safe opening such a file, since the file creation - // is guarded by file mutex - see getFileLock call. - if _, err := os.Stat(compressedFilePath); err == nil { - f.Close() - return h.newCompressedFSFile(compressedFilePath) - } - - // Create temporary file, so concurrent goroutines don't use - // it until it is created. - tmpFilePath := compressedFilePath + ".tmp" - zf, err := os.Create(tmpFilePath) - if err != nil { - f.Close() - if !os.IsPermission(err) { - return nil, fmt.Errorf("cannot create temporary file %q: %s", tmpFilePath, err) - } - return nil, errNoCreatePermission - } - - zw := acquireStacklessGzipWriter(zf, CompressDefaultCompression) - _, err = copyZeroAlloc(zw, f) - if err1 := zw.Flush(); err == nil { - err = err1 - } - releaseStacklessGzipWriter(zw, CompressDefaultCompression) - zf.Close() - f.Close() - if err != nil { - return nil, fmt.Errorf("error when compressing file %q to %q: %s", filePath, tmpFilePath, err) - } - if err = os.Chtimes(tmpFilePath, time.Now(), fileInfo.ModTime()); err != nil { - return nil, fmt.Errorf("cannot change modification time to %s for tmp file %q: %s", - fileInfo.ModTime(), tmpFilePath, err) - } - if err = os.Rename(tmpFilePath, compressedFilePath); err != nil { - return nil, fmt.Errorf("cannot move compressed file from %q to %q: %s", tmpFilePath, compressedFilePath, err) - } - return h.newCompressedFSFile(compressedFilePath) -} - -func (h *fsHandler) newCompressedFSFile(filePath string) (*fsFile, error) { - f, err := os.Open(filePath) - if err != nil { - return nil, fmt.Errorf("cannot open compressed file %q: %s", filePath, err) - } - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for compressed file %q: %s", filePath, err) - } - return h.newFSFile(f, fileInfo, true) -} - -func (h *fsHandler) openFSFile(filePath string, mustCompress bool) (*fsFile, error) { - filePathOriginal := filePath - if mustCompress { - filePath += h.compressedFileSuffix - } - - f, err := os.Open(filePath) - if err != nil { - if mustCompress && os.IsNotExist(err) { - return h.compressAndOpenFSFile(filePathOriginal) - } - return nil, err - } - - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for file %q: %s", filePath, err) - } - - if fileInfo.IsDir() { - f.Close() - if mustCompress { - return nil, fmt.Errorf("directory with unexpected suffix found: %q. Suffix: %q", - filePath, h.compressedFileSuffix) - } - return nil, errDirIndexRequired - } - - if mustCompress { - fileInfoOriginal, err := os.Stat(filePathOriginal) - if err != nil { - f.Close() - return nil, fmt.Errorf("cannot obtain info for original file %q: %s", filePathOriginal, err) - } - - if fileInfoOriginal.ModTime() != fileInfo.ModTime() { - // The compressed file became stale. Re-create it. - f.Close() - os.Remove(filePath) - return h.compressAndOpenFSFile(filePathOriginal) - } - } - - return h.newFSFile(f, fileInfo, mustCompress) -} - -func (h *fsHandler) newFSFile(f *os.File, fileInfo os.FileInfo, compressed bool) (*fsFile, error) { - n := fileInfo.Size() - contentLength := int(n) - if n != int64(contentLength) { - f.Close() - return nil, fmt.Errorf("too big file: %d bytes", n) - } - - // detect content-type - ext := fileExtension(fileInfo.Name(), compressed, h.compressedFileSuffix) - contentType := mime.TypeByExtension(ext) - if len(contentType) == 0 { - data, err := readFileHeader(f, compressed) - if err != nil { - return nil, fmt.Errorf("cannot read header of the file %q: %s", f.Name(), err) - } - contentType = http.DetectContentType(data) - } - - lastModified := fileInfo.ModTime() - ff := &fsFile{ - h: h, - f: f, - contentType: contentType, - contentLength: contentLength, - compressed: compressed, - lastModified: lastModified, - lastModifiedStr: AppendHTTPDate(nil, lastModified), - - t: time.Now(), - } - return ff, nil -} - -func readFileHeader(f *os.File, compressed bool) ([]byte, error) { - r := io.Reader(f) - var zr *gzip.Reader - if compressed { - var err error - if zr, err = acquireGzipReader(f); err != nil { - return nil, err - } - r = zr - } - - lr := &io.LimitedReader{ - R: r, - N: 512, - } - data, err := ioutil.ReadAll(lr) - f.Seek(0, 0) - - if zr != nil { - releaseGzipReader(zr) - } - - return data, err -} - -func stripLeadingSlashes(path []byte, stripSlashes int) []byte { - for stripSlashes > 0 && len(path) > 0 { - if path[0] != '/' { - panic("BUG: path must start with slash") - } - n := bytes.IndexByte(path[1:], '/') - if n < 0 { - path = path[:0] - break - } - path = path[n+1:] - stripSlashes-- - } - return path -} - -func stripTrailingSlashes(path []byte) []byte { - for len(path) > 0 && path[len(path)-1] == '/' { - path = path[:len(path)-1] - } - return path -} - -func fileExtension(path string, compressed bool, compressedFileSuffix string) string { - if compressed && strings.HasSuffix(path, compressedFileSuffix) { - path = path[:len(path)-len(compressedFileSuffix)] - } - n := strings.LastIndexByte(path, '.') - if n < 0 { - return "" - } - return path[n:] -} - -// FileLastModified returns last modified time for the file. -func FileLastModified(path string) (time.Time, error) { - f, err := os.Open(path) - if err != nil { - return zeroTime, err - } - fileInfo, err := f.Stat() - f.Close() - if err != nil { - return zeroTime, err - } - return fsModTime(fileInfo.ModTime()), nil -} - -func fsModTime(t time.Time) time.Time { - return t.In(time.UTC).Truncate(time.Second) -} - -var ( - filesLockMap = make(map[string]*sync.Mutex) - filesLockMapLock sync.Mutex -) - -func getFileLock(absPath string) *sync.Mutex { - filesLockMapLock.Lock() - flock := filesLockMap[absPath] - if flock == nil { - flock = &sync.Mutex{} - filesLockMap[absPath] = flock - } - filesLockMapLock.Unlock() - return flock -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go deleted file mode 100644 index 4283433e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/header.go +++ /dev/null @@ -1,2111 +0,0 @@ -package fasthttp - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - "sync/atomic" - "time" -) - -// ResponseHeader represents HTTP response header. -// -// It is forbidden copying ResponseHeader instances. -// Create new instances instead and use CopyTo. -// -// ResponseHeader instance MUST NOT be used from concurrently running -// goroutines. -type ResponseHeader struct { - noCopy noCopy - - disableNormalizing bool - noHTTP11 bool - connectionClose bool - - statusCode int - contentLength int - contentLengthBytes []byte - - contentType []byte - server []byte - - h []argsKV - bufKV argsKV - - cookies []argsKV -} - -// RequestHeader represents HTTP request header. -// -// It is forbidden copying RequestHeader instances. -// Create new instances instead and use CopyTo. -// -// RequestHeader instance MUST NOT be used from concurrently running -// goroutines. -type RequestHeader struct { - noCopy noCopy - - disableNormalizing bool - noHTTP11 bool - connectionClose bool - isGet bool - - // These two fields have been moved close to other bool fields - // for reducing RequestHeader object size. - cookiesCollected bool - rawHeadersParsed bool - - contentLength int - contentLengthBytes []byte - - method []byte - requestURI []byte - host []byte - contentType []byte - userAgent []byte - - h []argsKV - bufKV argsKV - - cookies []argsKV - - rawHeaders []byte -} - -// SetContentRange sets 'Content-Range: bytes startPos-endPos/contentLength' -// header. -func (h *ResponseHeader) SetContentRange(startPos, endPos, contentLength int) { - b := h.bufKV.value[:0] - b = append(b, strBytes...) - b = append(b, ' ') - b = AppendUint(b, startPos) - b = append(b, '-') - b = AppendUint(b, endPos) - b = append(b, '/') - b = AppendUint(b, contentLength) - h.bufKV.value = b - - h.SetCanonical(strContentRange, h.bufKV.value) -} - -// SetByteRange sets 'Range: bytes=startPos-endPos' header. -// -// * If startPos is negative, then 'bytes=-startPos' value is set. -// * If endPos is negative, then 'bytes=startPos-' value is set. -func (h *RequestHeader) SetByteRange(startPos, endPos int) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strBytes...) - b = append(b, '=') - if startPos >= 0 { - b = AppendUint(b, startPos) - } else { - endPos = -startPos - } - b = append(b, '-') - if endPos >= 0 { - b = AppendUint(b, endPos) - } - h.bufKV.value = b - - h.SetCanonical(strRange, h.bufKV.value) -} - -// StatusCode returns response status code. -func (h *ResponseHeader) StatusCode() int { - if h.statusCode == 0 { - return StatusOK - } - return h.statusCode -} - -// SetStatusCode sets response status code. -func (h *ResponseHeader) SetStatusCode(statusCode int) { - h.statusCode = statusCode -} - -// SetLastModified sets 'Last-Modified' header to the given value. -func (h *ResponseHeader) SetLastModified(t time.Time) { - h.bufKV.value = AppendHTTPDate(h.bufKV.value[:0], t) - h.SetCanonical(strLastModified, h.bufKV.value) -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (h *ResponseHeader) ConnectionClose() bool { - return h.connectionClose -} - -// SetConnectionClose sets 'Connection: close' header. -func (h *ResponseHeader) SetConnectionClose() { - h.connectionClose = true -} - -// ResetConnectionClose clears 'Connection: close' header if it exists. -func (h *ResponseHeader) ResetConnectionClose() { - if h.connectionClose { - h.connectionClose = false - h.h = delAllArgsBytes(h.h, strConnection) - } -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (h *RequestHeader) ConnectionClose() bool { - h.parseRawHeaders() - return h.connectionClose -} - -func (h *RequestHeader) connectionCloseFast() bool { - // h.parseRawHeaders() isn't called for performance reasons. - // Use ConnectionClose for triggering raw headers parsing. - return h.connectionClose -} - -// SetConnectionClose sets 'Connection: close' header. -func (h *RequestHeader) SetConnectionClose() { - // h.parseRawHeaders() isn't called for performance reasons. - h.connectionClose = true -} - -// ResetConnectionClose clears 'Connection: close' header if it exists. -func (h *RequestHeader) ResetConnectionClose() { - h.parseRawHeaders() - if h.connectionClose { - h.connectionClose = false - h.h = delAllArgsBytes(h.h, strConnection) - } -} - -// ConnectionUpgrade returns true if 'Connection: Upgrade' header is set. -func (h *ResponseHeader) ConnectionUpgrade() bool { - return hasHeaderValue(h.Peek("Connection"), strUpgrade) -} - -// ConnectionUpgrade returns true if 'Connection: Upgrade' header is set. -func (h *RequestHeader) ConnectionUpgrade() bool { - h.parseRawHeaders() - return hasHeaderValue(h.Peek("Connection"), strUpgrade) -} - -// ContentLength returns Content-Length header value. -// -// It may be negative: -// -1 means Transfer-Encoding: chunked. -// -2 means Transfer-Encoding: identity. -func (h *ResponseHeader) ContentLength() int { - return h.contentLength -} - -// SetContentLength sets Content-Length header value. -// -// Content-Length may be negative: -// -1 means Transfer-Encoding: chunked. -// -2 means Transfer-Encoding: identity. -func (h *ResponseHeader) SetContentLength(contentLength int) { - if h.mustSkipContentLength() { - return - } - h.contentLength = contentLength - if contentLength >= 0 { - h.contentLengthBytes = AppendUint(h.contentLengthBytes[:0], contentLength) - h.h = delAllArgsBytes(h.h, strTransferEncoding) - } else { - h.contentLengthBytes = h.contentLengthBytes[:0] - value := strChunked - if contentLength == -2 { - h.SetConnectionClose() - value = strIdentity - } - h.h = setArgBytes(h.h, strTransferEncoding, value) - } -} - -func (h *ResponseHeader) mustSkipContentLength() bool { - // From http/1.1 specs: - // All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body - statusCode := h.StatusCode() - - // Fast path. - if statusCode < 100 || statusCode == StatusOK { - return false - } - - // Slow path. - return statusCode == StatusNotModified || statusCode == StatusNoContent || statusCode < 200 -} - -// ContentLength returns Content-Length header value. -// -// It may be negative: -// -1 means Transfer-Encoding: chunked. -func (h *RequestHeader) ContentLength() int { - if h.noBody() { - return 0 - } - h.parseRawHeaders() - return h.contentLength -} - -// SetContentLength sets Content-Length header value. -// -// Negative content-length sets 'Transfer-Encoding: chunked' header. -func (h *RequestHeader) SetContentLength(contentLength int) { - h.parseRawHeaders() - h.contentLength = contentLength - if contentLength >= 0 { - h.contentLengthBytes = AppendUint(h.contentLengthBytes[:0], contentLength) - h.h = delAllArgsBytes(h.h, strTransferEncoding) - } else { - h.contentLengthBytes = h.contentLengthBytes[:0] - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } -} - -func (h *ResponseHeader) isCompressibleContentType() bool { - contentType := h.ContentType() - return bytes.HasPrefix(contentType, strTextSlash) || - bytes.HasPrefix(contentType, strApplicationSlash) -} - -// ContentType returns Content-Type header value. -func (h *ResponseHeader) ContentType() []byte { - contentType := h.contentType - if len(h.contentType) == 0 { - contentType = defaultContentType - } - return contentType -} - -// SetContentType sets Content-Type header value. -func (h *ResponseHeader) SetContentType(contentType string) { - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetContentTypeBytes sets Content-Type header value. -func (h *ResponseHeader) SetContentTypeBytes(contentType []byte) { - h.contentType = append(h.contentType[:0], contentType...) -} - -// Server returns Server header value. -func (h *ResponseHeader) Server() []byte { - return h.server -} - -// SetServer sets Server header value. -func (h *ResponseHeader) SetServer(server string) { - h.server = append(h.server[:0], server...) -} - -// SetServerBytes sets Server header value. -func (h *ResponseHeader) SetServerBytes(server []byte) { - h.server = append(h.server[:0], server...) -} - -// ContentType returns Content-Type header value. -func (h *RequestHeader) ContentType() []byte { - h.parseRawHeaders() - return h.contentType -} - -// SetContentType sets Content-Type header value. -func (h *RequestHeader) SetContentType(contentType string) { - h.parseRawHeaders() - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetContentTypeBytes sets Content-Type header value. -func (h *RequestHeader) SetContentTypeBytes(contentType []byte) { - h.parseRawHeaders() - h.contentType = append(h.contentType[:0], contentType...) -} - -// SetMultipartFormBoundary sets the following Content-Type: -// 'multipart/form-data; boundary=...' -// where ... is substituted by the given boundary. -func (h *RequestHeader) SetMultipartFormBoundary(boundary string) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strMultipartFormData...) - b = append(b, ';', ' ') - b = append(b, strBoundary...) - b = append(b, '=') - b = append(b, boundary...) - h.bufKV.value = b - - h.SetContentTypeBytes(h.bufKV.value) -} - -// SetMultipartFormBoundaryBytes sets the following Content-Type: -// 'multipart/form-data; boundary=...' -// where ... is substituted by the given boundary. -func (h *RequestHeader) SetMultipartFormBoundaryBytes(boundary []byte) { - h.parseRawHeaders() - - b := h.bufKV.value[:0] - b = append(b, strMultipartFormData...) - b = append(b, ';', ' ') - b = append(b, strBoundary...) - b = append(b, '=') - b = append(b, boundary...) - h.bufKV.value = b - - h.SetContentTypeBytes(h.bufKV.value) -} - -// MultipartFormBoundary returns boundary part -// from 'multipart/form-data; boundary=...' Content-Type. -func (h *RequestHeader) MultipartFormBoundary() []byte { - b := h.ContentType() - if !bytes.HasPrefix(b, strMultipartFormData) { - return nil - } - b = b[len(strMultipartFormData):] - if len(b) == 0 || b[0] != ';' { - return nil - } - - var n int - for len(b) > 0 { - n++ - for len(b) > n && b[n] == ' ' { - n++ - } - b = b[n:] - if !bytes.HasPrefix(b, strBoundary) { - if n = bytes.IndexByte(b, ';'); n < 0 { - return nil - } - continue - } - - b = b[len(strBoundary):] - if len(b) == 0 || b[0] != '=' { - return nil - } - b = b[1:] - if n = bytes.IndexByte(b, ';'); n >= 0 { - b = b[:n] - } - if len(b) > 1 && b[0] == '"' && b[len(b)-1] == '"' { - b = b[1 : len(b)-1] - } - return b - } - return nil -} - -// Host returns Host header value. -func (h *RequestHeader) Host() []byte { - if len(h.host) > 0 { - return h.host - } - if !h.rawHeadersParsed { - // fast path without employing full headers parsing. - host := peekRawHeader(h.rawHeaders, strHost) - if len(host) > 0 { - h.host = append(h.host[:0], host...) - return h.host - } - } - - // slow path. - h.parseRawHeaders() - return h.host -} - -// SetHost sets Host header value. -func (h *RequestHeader) SetHost(host string) { - h.parseRawHeaders() - h.host = append(h.host[:0], host...) -} - -// SetHostBytes sets Host header value. -func (h *RequestHeader) SetHostBytes(host []byte) { - h.parseRawHeaders() - h.host = append(h.host[:0], host...) -} - -// UserAgent returns User-Agent header value. -func (h *RequestHeader) UserAgent() []byte { - h.parseRawHeaders() - return h.userAgent -} - -// SetUserAgent sets User-Agent header value. -func (h *RequestHeader) SetUserAgent(userAgent string) { - h.parseRawHeaders() - h.userAgent = append(h.userAgent[:0], userAgent...) -} - -// SetUserAgentBytes sets User-Agent header value. -func (h *RequestHeader) SetUserAgentBytes(userAgent []byte) { - h.parseRawHeaders() - h.userAgent = append(h.userAgent[:0], userAgent...) -} - -// Referer returns Referer header value. -func (h *RequestHeader) Referer() []byte { - return h.PeekBytes(strReferer) -} - -// SetReferer sets Referer header value. -func (h *RequestHeader) SetReferer(referer string) { - h.SetBytesK(strReferer, referer) -} - -// SetRefererBytes sets Referer header value. -func (h *RequestHeader) SetRefererBytes(referer []byte) { - h.SetCanonical(strReferer, referer) -} - -// Method returns HTTP request method. -func (h *RequestHeader) Method() []byte { - if len(h.method) == 0 { - return strGet - } - return h.method -} - -// SetMethod sets HTTP request method. -func (h *RequestHeader) SetMethod(method string) { - h.method = append(h.method[:0], method...) -} - -// SetMethodBytes sets HTTP request method. -func (h *RequestHeader) SetMethodBytes(method []byte) { - h.method = append(h.method[:0], method...) -} - -// RequestURI returns RequestURI from the first HTTP request line. -func (h *RequestHeader) RequestURI() []byte { - requestURI := h.requestURI - if len(requestURI) == 0 { - requestURI = strSlash - } - return requestURI -} - -// SetRequestURI sets RequestURI for the first HTTP request line. -// RequestURI must be properly encoded. -// Use URI.RequestURI for constructing proper RequestURI if unsure. -func (h *RequestHeader) SetRequestURI(requestURI string) { - h.requestURI = append(h.requestURI[:0], requestURI...) -} - -// SetRequestURIBytes sets RequestURI for the first HTTP request line. -// RequestURI must be properly encoded. -// Use URI.RequestURI for constructing proper RequestURI if unsure. -func (h *RequestHeader) SetRequestURIBytes(requestURI []byte) { - h.requestURI = append(h.requestURI[:0], requestURI...) -} - -// IsGet returns true if request method is GET. -func (h *RequestHeader) IsGet() bool { - // Optimize fast path for GET requests. - if !h.isGet { - h.isGet = bytes.Equal(h.Method(), strGet) - } - return h.isGet -} - -// IsPost returns true if request method is POST. -func (h *RequestHeader) IsPost() bool { - return bytes.Equal(h.Method(), strPost) -} - -// IsPut returns true if request method is PUT. -func (h *RequestHeader) IsPut() bool { - return bytes.Equal(h.Method(), strPut) -} - -// IsHead returns true if request method is HEAD. -func (h *RequestHeader) IsHead() bool { - // Fast path - if h.isGet { - return false - } - return bytes.Equal(h.Method(), strHead) -} - -// IsDelete returns true if request method is DELETE. -func (h *RequestHeader) IsDelete() bool { - return bytes.Equal(h.Method(), strDelete) -} - -// IsConnect returns true if request method is CONNECT. -func (h *RequestHeader) IsConnect() bool { - return bytes.Equal(h.Method(), strConnect) -} - -// IsOptions returns true if request method is OPTIONS. -func (h *RequestHeader) IsOptions() bool { - return bytes.Equal(h.Method(), strOptions) -} - -// IsTrace returns true if request method is TRACE. -func (h *RequestHeader) IsTrace() bool { - return bytes.Equal(h.Method(), strTrace) -} - -// IsPatch returns true if request method is PATCH. -func (h *RequestHeader) IsPatch() bool { - return bytes.Equal(h.Method(), strPatch) -} - -// IsHTTP11 returns true if the request is HTTP/1.1. -func (h *RequestHeader) IsHTTP11() bool { - return !h.noHTTP11 -} - -// IsHTTP11 returns true if the response is HTTP/1.1. -func (h *ResponseHeader) IsHTTP11() bool { - return !h.noHTTP11 -} - -// HasAcceptEncoding returns true if the header contains -// the given Accept-Encoding value. -func (h *RequestHeader) HasAcceptEncoding(acceptEncoding string) bool { - h.bufKV.value = append(h.bufKV.value[:0], acceptEncoding...) - return h.HasAcceptEncodingBytes(h.bufKV.value) -} - -// HasAcceptEncodingBytes returns true if the header contains -// the given Accept-Encoding value. -func (h *RequestHeader) HasAcceptEncodingBytes(acceptEncoding []byte) bool { - ae := h.peek(strAcceptEncoding) - n := bytes.Index(ae, acceptEncoding) - if n < 0 { - return false - } - b := ae[n+len(acceptEncoding):] - if len(b) > 0 && b[0] != ',' { - return false - } - if n == 0 { - return true - } - return ae[n-1] == ' ' -} - -// Len returns the number of headers set, -// i.e. the number of times f is called in VisitAll. -func (h *ResponseHeader) Len() int { - n := 0 - h.VisitAll(func(k, v []byte) { n++ }) - return n -} - -// Len returns the number of headers set, -// i.e. the number of times f is called in VisitAll. -func (h *RequestHeader) Len() int { - n := 0 - h.VisitAll(func(k, v []byte) { n++ }) - return n -} - -// DisableNormalizing disables header names' normalization. -// -// By default all the header names are normalized by uppercasing -// the first letter and all the first letters following dashes, -// while lowercasing all the other letters. -// Examples: -// -// * CONNECTION -> Connection -// * conteNT-tYPE -> Content-Type -// * foo-bar-baz -> Foo-Bar-Baz -// -// Disable header names' normalization only if know what are you doing. -func (h *RequestHeader) DisableNormalizing() { - h.disableNormalizing = true -} - -// DisableNormalizing disables header names' normalization. -// -// By default all the header names are normalized by uppercasing -// the first letter and all the first letters following dashes, -// while lowercasing all the other letters. -// Examples: -// -// * CONNECTION -> Connection -// * conteNT-tYPE -> Content-Type -// * foo-bar-baz -> Foo-Bar-Baz -// -// Disable header names' normalization only if know what are you doing. -func (h *ResponseHeader) DisableNormalizing() { - h.disableNormalizing = true -} - -// Reset clears response header. -func (h *ResponseHeader) Reset() { - h.disableNormalizing = false - h.resetSkipNormalize() -} - -func (h *ResponseHeader) resetSkipNormalize() { - h.noHTTP11 = false - h.connectionClose = false - - h.statusCode = 0 - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - - h.contentType = h.contentType[:0] - h.server = h.server[:0] - - h.h = h.h[:0] - h.cookies = h.cookies[:0] -} - -// Reset clears request header. -func (h *RequestHeader) Reset() { - h.disableNormalizing = false - h.resetSkipNormalize() -} - -func (h *RequestHeader) resetSkipNormalize() { - h.noHTTP11 = false - h.connectionClose = false - h.isGet = false - - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - - h.method = h.method[:0] - h.requestURI = h.requestURI[:0] - h.host = h.host[:0] - h.contentType = h.contentType[:0] - h.userAgent = h.userAgent[:0] - - h.h = h.h[:0] - h.cookies = h.cookies[:0] - h.cookiesCollected = false - - h.rawHeaders = h.rawHeaders[:0] - h.rawHeadersParsed = false -} - -// CopyTo copies all the headers to dst. -func (h *ResponseHeader) CopyTo(dst *ResponseHeader) { - dst.Reset() - - dst.disableNormalizing = h.disableNormalizing - dst.noHTTP11 = h.noHTTP11 - dst.connectionClose = h.connectionClose - - dst.statusCode = h.statusCode - dst.contentLength = h.contentLength - dst.contentLengthBytes = append(dst.contentLengthBytes[:0], h.contentLengthBytes...) - dst.contentType = append(dst.contentType[:0], h.contentType...) - dst.server = append(dst.server[:0], h.server...) - dst.h = copyArgs(dst.h, h.h) - dst.cookies = copyArgs(dst.cookies, h.cookies) -} - -// CopyTo copies all the headers to dst. -func (h *RequestHeader) CopyTo(dst *RequestHeader) { - dst.Reset() - - dst.disableNormalizing = h.disableNormalizing - dst.noHTTP11 = h.noHTTP11 - dst.connectionClose = h.connectionClose - dst.isGet = h.isGet - - dst.contentLength = h.contentLength - dst.contentLengthBytes = append(dst.contentLengthBytes[:0], h.contentLengthBytes...) - dst.method = append(dst.method[:0], h.method...) - dst.requestURI = append(dst.requestURI[:0], h.requestURI...) - dst.host = append(dst.host[:0], h.host...) - dst.contentType = append(dst.contentType[:0], h.contentType...) - dst.userAgent = append(dst.userAgent[:0], h.userAgent...) - dst.h = copyArgs(dst.h, h.h) - dst.cookies = copyArgs(dst.cookies, h.cookies) - dst.cookiesCollected = h.cookiesCollected - dst.rawHeaders = append(dst.rawHeaders[:0], h.rawHeaders...) - dst.rawHeadersParsed = h.rawHeadersParsed -} - -// VisitAll calls f for each header. -// -// f must not retain references to key and/or value after returning. -// Copy key and/or value contents before returning if you need retaining them. -func (h *ResponseHeader) VisitAll(f func(key, value []byte)) { - if len(h.contentLengthBytes) > 0 { - f(strContentLength, h.contentLengthBytes) - } - contentType := h.ContentType() - if len(contentType) > 0 { - f(strContentType, contentType) - } - server := h.Server() - if len(server) > 0 { - f(strServer, server) - } - if len(h.cookies) > 0 { - visitArgs(h.cookies, func(k, v []byte) { - f(strSetCookie, v) - }) - } - visitArgs(h.h, f) - if h.ConnectionClose() { - f(strConnection, strClose) - } -} - -// VisitAllCookie calls f for each response cookie. -// -// Cookie name is passed in key and the whole Set-Cookie header value -// is passed in value on each f invocation. Value may be parsed -// with Cookie.ParseBytes(). -// -// f must not retain references to key and/or value after returning. -func (h *ResponseHeader) VisitAllCookie(f func(key, value []byte)) { - visitArgs(h.cookies, f) -} - -// VisitAllCookie calls f for each request cookie. -// -// f must not retain references to key and/or value after returning. -func (h *RequestHeader) VisitAllCookie(f func(key, value []byte)) { - h.parseRawHeaders() - h.collectCookies() - visitArgs(h.cookies, f) -} - -// VisitAll calls f for each header. -// -// f must not retain references to key and/or value after returning. -// Copy key and/or value contents before returning if you need retaining them. -func (h *RequestHeader) VisitAll(f func(key, value []byte)) { - h.parseRawHeaders() - host := h.Host() - if len(host) > 0 { - f(strHost, host) - } - if len(h.contentLengthBytes) > 0 { - f(strContentLength, h.contentLengthBytes) - } - contentType := h.ContentType() - if len(contentType) > 0 { - f(strContentType, contentType) - } - userAgent := h.UserAgent() - if len(userAgent) > 0 { - f(strUserAgent, userAgent) - } - - h.collectCookies() - if len(h.cookies) > 0 { - h.bufKV.value = appendRequestCookieBytes(h.bufKV.value[:0], h.cookies) - f(strCookie, h.bufKV.value) - } - visitArgs(h.h, f) - if h.ConnectionClose() { - f(strConnection, strClose) - } -} - -// Del deletes header with the given key. -func (h *ResponseHeader) Del(key string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.del(k) -} - -// DelBytes deletes header with the given key. -func (h *ResponseHeader) DelBytes(key []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.del(h.bufKV.key) -} - -func (h *ResponseHeader) del(key []byte) { - switch string(key) { - case "Content-Type": - h.contentType = h.contentType[:0] - case "Server": - h.server = h.server[:0] - case "Set-Cookie": - h.cookies = h.cookies[:0] - case "Content-Length": - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - case "Connection": - h.connectionClose = false - } - h.h = delAllArgsBytes(h.h, key) -} - -// Del deletes header with the given key. -func (h *RequestHeader) Del(key string) { - h.parseRawHeaders() - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.del(k) -} - -// DelBytes deletes header with the given key. -func (h *RequestHeader) DelBytes(key []byte) { - h.parseRawHeaders() - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.del(h.bufKV.key) -} - -func (h *RequestHeader) del(key []byte) { - switch string(key) { - case "Host": - h.host = h.host[:0] - case "Content-Type": - h.contentType = h.contentType[:0] - case "User-Agent": - h.userAgent = h.userAgent[:0] - case "Cookie": - h.cookies = h.cookies[:0] - case "Content-Length": - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - case "Connection": - h.connectionClose = false - } - h.h = delAllArgsBytes(h.h, key) -} - -// Add adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use Set for setting a single header for the given key. -func (h *ResponseHeader) Add(key, value string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.h = appendArg(h.h, b2s(k), value) -} - -// AddBytesK adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesK for setting a single header for the given key. -func (h *ResponseHeader) AddBytesK(key []byte, value string) { - h.Add(b2s(key), value) -} - -// AddBytesV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesV for setting a single header for the given key. -func (h *ResponseHeader) AddBytesV(key string, value []byte) { - h.Add(key, b2s(value)) -} - -// AddBytesKV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesKV for setting a single header for the given key. -func (h *ResponseHeader) AddBytesKV(key, value []byte) { - h.Add(b2s(key), b2s(value)) -} - -// Set sets the given 'key: value' header. -// -// Use Add for setting multiple header values under the same key. -func (h *ResponseHeader) Set(key, value string) { - initHeaderKV(&h.bufKV, key, value, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, h.bufKV.value) -} - -// SetBytesK sets the given 'key: value' header. -// -// Use AddBytesK for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesK(key []byte, value string) { - h.bufKV.value = append(h.bufKV.value[:0], value...) - h.SetBytesKV(key, h.bufKV.value) -} - -// SetBytesV sets the given 'key: value' header. -// -// Use AddBytesV for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesV(key string, value []byte) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.SetCanonical(k, value) -} - -// SetBytesKV sets the given 'key: value' header. -// -// Use AddBytesKV for setting multiple header values under the same key. -func (h *ResponseHeader) SetBytesKV(key, value []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, value) -} - -// SetCanonical sets the given 'key: value' header assuming that -// key is in canonical form. -func (h *ResponseHeader) SetCanonical(key, value []byte) { - switch string(key) { - case "Content-Type": - h.SetContentTypeBytes(value) - case "Server": - h.SetServerBytes(value) - case "Set-Cookie": - var kv *argsKV - h.cookies, kv = allocArg(h.cookies) - kv.key = getCookieKey(kv.key, value) - kv.value = append(kv.value[:0], value...) - case "Content-Length": - if contentLength, err := parseContentLength(value); err == nil { - h.contentLength = contentLength - h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) - } - case "Connection": - if bytes.Equal(strClose, value) { - h.SetConnectionClose() - } else { - h.ResetConnectionClose() - h.h = setArgBytes(h.h, key, value) - } - case "Transfer-Encoding": - // Transfer-Encoding is managed automatically. - case "Date": - // Date is managed automatically. - default: - h.h = setArgBytes(h.h, key, value) - } -} - -// SetCookie sets the given response cookie. -// -// It is save re-using the cookie after the function returns. -func (h *ResponseHeader) SetCookie(cookie *Cookie) { - h.cookies = setArgBytes(h.cookies, cookie.Key(), cookie.Cookie()) -} - -// SetCookie sets 'key: value' cookies. -func (h *RequestHeader) SetCookie(key, value string) { - h.parseRawHeaders() - h.collectCookies() - h.cookies = setArg(h.cookies, key, value) -} - -// SetCookieBytesK sets 'key: value' cookies. -func (h *RequestHeader) SetCookieBytesK(key []byte, value string) { - h.SetCookie(b2s(key), value) -} - -// SetCookieBytesKV sets 'key: value' cookies. -func (h *RequestHeader) SetCookieBytesKV(key, value []byte) { - h.SetCookie(b2s(key), b2s(value)) -} - -// DelClientCookie instructs the client to remove the given cookie. -// -// Use DelCookie if you want just removing the cookie from response header. -func (h *ResponseHeader) DelClientCookie(key string) { - h.DelCookie(key) - - c := AcquireCookie() - c.SetKey(key) - c.SetExpire(CookieExpireDelete) - h.SetCookie(c) - ReleaseCookie(c) -} - -// DelClientCookieBytes instructs the client to remove the given cookie. -// -// Use DelCookieBytes if you want just removing the cookie from response header. -func (h *ResponseHeader) DelClientCookieBytes(key []byte) { - h.DelClientCookie(b2s(key)) -} - -// DelCookie removes cookie under the given key from response header. -// -// Note that DelCookie doesn't remove the cookie from the client. -// Use DelClientCookie instead. -func (h *ResponseHeader) DelCookie(key string) { - h.cookies = delAllArgs(h.cookies, key) -} - -// DelCookieBytes removes cookie under the given key from response header. -// -// Note that DelCookieBytes doesn't remove the cookie from the client. -// Use DelClientCookieBytes instead. -func (h *ResponseHeader) DelCookieBytes(key []byte) { - h.DelCookie(b2s(key)) -} - -// DelCookie removes cookie under the given key. -func (h *RequestHeader) DelCookie(key string) { - h.parseRawHeaders() - h.collectCookies() - h.cookies = delAllArgs(h.cookies, key) -} - -// DelCookieBytes removes cookie under the given key. -func (h *RequestHeader) DelCookieBytes(key []byte) { - h.DelCookie(b2s(key)) -} - -// DelAllCookies removes all the cookies from response headers. -func (h *ResponseHeader) DelAllCookies() { - h.cookies = h.cookies[:0] -} - -// DelAllCookies removes all the cookies from request headers. -func (h *RequestHeader) DelAllCookies() { - h.parseRawHeaders() - h.collectCookies() - h.cookies = h.cookies[:0] -} - -// Add adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use Set for setting a single header for the given key. -func (h *RequestHeader) Add(key, value string) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.h = appendArg(h.h, b2s(k), value) -} - -// AddBytesK adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesK for setting a single header for the given key. -func (h *RequestHeader) AddBytesK(key []byte, value string) { - h.Add(b2s(key), value) -} - -// AddBytesV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesV for setting a single header for the given key. -func (h *RequestHeader) AddBytesV(key string, value []byte) { - h.Add(key, b2s(value)) -} - -// AddBytesKV adds the given 'key: value' header. -// -// Multiple headers with the same key may be added with this function. -// Use SetBytesKV for setting a single header for the given key. -func (h *RequestHeader) AddBytesKV(key, value []byte) { - h.Add(b2s(key), b2s(value)) -} - -// Set sets the given 'key: value' header. -// -// Use Add for setting multiple header values under the same key. -func (h *RequestHeader) Set(key, value string) { - initHeaderKV(&h.bufKV, key, value, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, h.bufKV.value) -} - -// SetBytesK sets the given 'key: value' header. -// -// Use AddBytesK for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesK(key []byte, value string) { - h.bufKV.value = append(h.bufKV.value[:0], value...) - h.SetBytesKV(key, h.bufKV.value) -} - -// SetBytesV sets the given 'key: value' header. -// -// Use AddBytesV for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesV(key string, value []byte) { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - h.SetCanonical(k, value) -} - -// SetBytesKV sets the given 'key: value' header. -// -// Use AddBytesKV for setting multiple header values under the same key. -func (h *RequestHeader) SetBytesKV(key, value []byte) { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - h.SetCanonical(h.bufKV.key, value) -} - -// SetCanonical sets the given 'key: value' header assuming that -// key is in canonical form. -func (h *RequestHeader) SetCanonical(key, value []byte) { - h.parseRawHeaders() - switch string(key) { - case "Host": - h.SetHostBytes(value) - case "Content-Type": - h.SetContentTypeBytes(value) - case "User-Agent": - h.SetUserAgentBytes(value) - case "Cookie": - h.collectCookies() - h.cookies = parseRequestCookies(h.cookies, value) - case "Content-Length": - if contentLength, err := parseContentLength(value); err == nil { - h.contentLength = contentLength - h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) - } - case "Connection": - if bytes.Equal(strClose, value) { - h.SetConnectionClose() - } else { - h.ResetConnectionClose() - h.h = setArgBytes(h.h, key, value) - } - case "Transfer-Encoding": - // Transfer-Encoding is managed automatically. - default: - h.h = setArgBytes(h.h, key, value) - } -} - -// Peek returns header value for the given key. -// -// Returned value is valid until the next call to ResponseHeader. -// Do not store references to returned value. Make copies instead. -func (h *ResponseHeader) Peek(key string) []byte { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - return h.peek(k) -} - -// PeekBytes returns header value for the given key. -// -// Returned value is valid until the next call to ResponseHeader. -// Do not store references to returned value. Make copies instead. -func (h *ResponseHeader) PeekBytes(key []byte) []byte { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - return h.peek(h.bufKV.key) -} - -// Peek returns header value for the given key. -// -// Returned value is valid until the next call to RequestHeader. -// Do not store references to returned value. Make copies instead. -func (h *RequestHeader) Peek(key string) []byte { - k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) - return h.peek(k) -} - -// PeekBytes returns header value for the given key. -// -// Returned value is valid until the next call to RequestHeader. -// Do not store references to returned value. Make copies instead. -func (h *RequestHeader) PeekBytes(key []byte) []byte { - h.bufKV.key = append(h.bufKV.key[:0], key...) - normalizeHeaderKey(h.bufKV.key, h.disableNormalizing) - return h.peek(h.bufKV.key) -} - -func (h *ResponseHeader) peek(key []byte) []byte { - switch string(key) { - case "Content-Type": - return h.ContentType() - case "Server": - return h.Server() - case "Connection": - if h.ConnectionClose() { - return strClose - } - return peekArgBytes(h.h, key) - case "Content-Length": - return h.contentLengthBytes - default: - return peekArgBytes(h.h, key) - } -} - -func (h *RequestHeader) peek(key []byte) []byte { - h.parseRawHeaders() - switch string(key) { - case "Host": - return h.Host() - case "Content-Type": - return h.ContentType() - case "User-Agent": - return h.UserAgent() - case "Connection": - if h.ConnectionClose() { - return strClose - } - return peekArgBytes(h.h, key) - case "Content-Length": - return h.contentLengthBytes - default: - return peekArgBytes(h.h, key) - } -} - -// Cookie returns cookie for the given key. -func (h *RequestHeader) Cookie(key string) []byte { - h.parseRawHeaders() - h.collectCookies() - return peekArgStr(h.cookies, key) -} - -// CookieBytes returns cookie for the given key. -func (h *RequestHeader) CookieBytes(key []byte) []byte { - h.parseRawHeaders() - h.collectCookies() - return peekArgBytes(h.cookies, key) -} - -// Cookie fills cookie for the given cookie.Key. -// -// Returns false if cookie with the given cookie.Key is missing. -func (h *ResponseHeader) Cookie(cookie *Cookie) bool { - v := peekArgBytes(h.cookies, cookie.Key()) - if v == nil { - return false - } - cookie.ParseBytes(v) - return true -} - -// Read reads response header from r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (h *ResponseHeader) Read(r *bufio.Reader) error { - n := 1 - for { - err := h.tryRead(r, n) - if err == nil { - return nil - } - if err != errNeedMore { - h.resetSkipNormalize() - return err - } - n = r.Buffered() + 1 - } -} - -func (h *ResponseHeader) tryRead(r *bufio.Reader, n int) error { - h.resetSkipNormalize() - b, err := r.Peek(n) - if len(b) == 0 { - // treat all errors on the first byte read as EOF - if n == 1 || err == io.EOF { - return io.EOF - } - - // This is for go 1.6 bug. See https://github.com/golang/go/issues/14121 . - if err == bufio.ErrBufferFull { - return &ErrSmallBuffer{ - error: fmt.Errorf("error when reading response headers: %s", errSmallBuffer), - } - } - - return fmt.Errorf("error when reading response headers: %s", err) - } - b = mustPeekBuffered(r) - headersLen, errParse := h.parse(b) - if errParse != nil { - return headerError("response", err, errParse, b) - } - mustDiscard(r, headersLen) - return nil -} - -func headerError(typ string, err, errParse error, b []byte) error { - if errParse != errNeedMore { - return headerErrorMsg(typ, errParse, b) - } - if err == nil { - return errNeedMore - } - - // Buggy servers may leave trailing CRLFs after http body. - // Treat this case as EOF. - if isOnlyCRLF(b) { - return io.EOF - } - - if err != bufio.ErrBufferFull { - return headerErrorMsg(typ, err, b) - } - return &ErrSmallBuffer{ - error: headerErrorMsg(typ, errSmallBuffer, b), - } -} - -func headerErrorMsg(typ string, err error, b []byte) error { - return fmt.Errorf("error when reading %s headers: %s. Buffer size=%d, contents: %s", typ, err, len(b), bufferSnippet(b)) -} - -// Read reads request header from r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (h *RequestHeader) Read(r *bufio.Reader) error { - n := 1 - for { - err := h.tryRead(r, n) - if err == nil { - return nil - } - if err != errNeedMore { - h.resetSkipNormalize() - return err - } - n = r.Buffered() + 1 - } -} - -func (h *RequestHeader) tryRead(r *bufio.Reader, n int) error { - h.resetSkipNormalize() - b, err := r.Peek(n) - if len(b) == 0 { - // treat all errors on the first byte read as EOF - if n == 1 || err == io.EOF { - return io.EOF - } - - // This is for go 1.6 bug. See https://github.com/golang/go/issues/14121 . - if err == bufio.ErrBufferFull { - return &ErrSmallBuffer{ - error: fmt.Errorf("error when reading request headers: %s", errSmallBuffer), - } - } - - return fmt.Errorf("error when reading request headers: %s", err) - } - b = mustPeekBuffered(r) - headersLen, errParse := h.parse(b) - if errParse != nil { - return headerError("request", err, errParse, b) - } - mustDiscard(r, headersLen) - return nil -} - -func bufferSnippet(b []byte) string { - n := len(b) - start := 200 - end := n - start - if start >= end { - start = n - end = n - } - bStart, bEnd := b[:start], b[end:] - if len(bEnd) == 0 { - return fmt.Sprintf("%q", b) - } - return fmt.Sprintf("%q...%q", bStart, bEnd) -} - -func isOnlyCRLF(b []byte) bool { - for _, ch := range b { - if ch != '\r' && ch != '\n' { - return false - } - } - return true -} - -func init() { - refreshServerDate() - go func() { - for { - time.Sleep(time.Second) - refreshServerDate() - } - }() -} - -var serverDate atomic.Value - -func refreshServerDate() { - b := AppendHTTPDate(nil, time.Now()) - serverDate.Store(b) -} - -// Write writes response header to w. -func (h *ResponseHeader) Write(w *bufio.Writer) error { - _, err := w.Write(h.Header()) - return err -} - -// WriteTo writes response header to w. -// -// WriteTo implements io.WriterTo interface. -func (h *ResponseHeader) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(h.Header()) - return int64(n), err -} - -// Header returns response header representation. -// -// The returned value is valid until the next call to ResponseHeader methods. -func (h *ResponseHeader) Header() []byte { - h.bufKV.value = h.AppendBytes(h.bufKV.value[:0]) - return h.bufKV.value -} - -// String returns response header representation. -func (h *ResponseHeader) String() string { - return string(h.Header()) -} - -// AppendBytes appends response header representation to dst and returns -// the extended dst. -func (h *ResponseHeader) AppendBytes(dst []byte) []byte { - statusCode := h.StatusCode() - if statusCode < 0 { - statusCode = StatusOK - } - dst = append(dst, statusLine(statusCode)...) - - server := h.Server() - if len(server) == 0 { - server = defaultServerName - } - dst = appendHeaderLine(dst, strServer, server) - dst = appendHeaderLine(dst, strDate, serverDate.Load().([]byte)) - - // Append Content-Type only for non-zero responses - // or if it is explicitly set. - // See https://github.com/valyala/fasthttp/issues/28 . - if h.ContentLength() != 0 || len(h.contentType) > 0 { - dst = appendHeaderLine(dst, strContentType, h.ContentType()) - } - - if len(h.contentLengthBytes) > 0 { - dst = appendHeaderLine(dst, strContentLength, h.contentLengthBytes) - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - if !bytes.Equal(kv.key, strDate) { - dst = appendHeaderLine(dst, kv.key, kv.value) - } - } - - n := len(h.cookies) - if n > 0 { - for i := 0; i < n; i++ { - kv := &h.cookies[i] - dst = appendHeaderLine(dst, strSetCookie, kv.value) - } - } - - if h.ConnectionClose() { - dst = appendHeaderLine(dst, strConnection, strClose) - } - - return append(dst, strCRLF...) -} - -// Write writes request header to w. -func (h *RequestHeader) Write(w *bufio.Writer) error { - _, err := w.Write(h.Header()) - return err -} - -// WriteTo writes request header to w. -// -// WriteTo implements io.WriterTo interface. -func (h *RequestHeader) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(h.Header()) - return int64(n), err -} - -// Header returns request header representation. -// -// The returned representation is valid until the next call to RequestHeader methods. -func (h *RequestHeader) Header() []byte { - h.bufKV.value = h.AppendBytes(h.bufKV.value[:0]) - return h.bufKV.value -} - -// String returns request header representation. -func (h *RequestHeader) String() string { - return string(h.Header()) -} - -// AppendBytes appends request header representation to dst and returns -// the extended dst. -func (h *RequestHeader) AppendBytes(dst []byte) []byte { - // there is no need in h.parseRawHeaders() here - raw headers are specially handled below. - dst = append(dst, h.Method()...) - dst = append(dst, ' ') - dst = append(dst, h.RequestURI()...) - dst = append(dst, ' ') - dst = append(dst, strHTTP11...) - dst = append(dst, strCRLF...) - - if !h.rawHeadersParsed && len(h.rawHeaders) > 0 { - return append(dst, h.rawHeaders...) - } - - userAgent := h.UserAgent() - if len(userAgent) == 0 { - userAgent = defaultUserAgent - } - dst = appendHeaderLine(dst, strUserAgent, userAgent) - - host := h.Host() - if len(host) > 0 { - dst = appendHeaderLine(dst, strHost, host) - } - - contentType := h.ContentType() - if !h.noBody() { - if len(contentType) == 0 { - contentType = strPostArgsContentType - } - dst = appendHeaderLine(dst, strContentType, contentType) - - if len(h.contentLengthBytes) > 0 { - dst = appendHeaderLine(dst, strContentLength, h.contentLengthBytes) - } - } else if len(contentType) > 0 { - dst = appendHeaderLine(dst, strContentType, contentType) - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - dst = appendHeaderLine(dst, kv.key, kv.value) - } - - // there is no need in h.collectCookies() here, since if cookies aren't collected yet, - // they all are located in h.h. - n := len(h.cookies) - if n > 0 { - dst = append(dst, strCookie...) - dst = append(dst, strColonSpace...) - dst = appendRequestCookieBytes(dst, h.cookies) - dst = append(dst, strCRLF...) - } - - if h.ConnectionClose() { - dst = appendHeaderLine(dst, strConnection, strClose) - } - - return append(dst, strCRLF...) -} - -func appendHeaderLine(dst, key, value []byte) []byte { - dst = append(dst, key...) - dst = append(dst, strColonSpace...) - dst = append(dst, value...) - return append(dst, strCRLF...) -} - -func (h *ResponseHeader) parse(buf []byte) (int, error) { - m, err := h.parseFirstLine(buf) - if err != nil { - return 0, err - } - n, err := h.parseHeaders(buf[m:]) - if err != nil { - return 0, err - } - return m + n, nil -} - -func (h *RequestHeader) noBody() bool { - return h.IsGet() || h.IsHead() -} - -func (h *RequestHeader) parse(buf []byte) (int, error) { - m, err := h.parseFirstLine(buf) - if err != nil { - return 0, err - } - - var n int - if !h.noBody() || h.noHTTP11 { - n, err = h.parseHeaders(buf[m:]) - if err != nil { - return 0, err - } - h.rawHeadersParsed = true - } else { - var rawHeaders []byte - rawHeaders, n, err = readRawHeaders(h.rawHeaders[:0], buf[m:]) - if err != nil { - return 0, err - } - h.rawHeaders = rawHeaders - } - return m + n, nil -} - -func (h *ResponseHeader) parseFirstLine(buf []byte) (int, error) { - bNext := buf - var b []byte - var err error - for len(b) == 0 { - if b, bNext, err = nextLine(bNext); err != nil { - return 0, err - } - } - - // parse protocol - n := bytes.IndexByte(b, ' ') - if n < 0 { - return 0, fmt.Errorf("cannot find whitespace in the first line of response %q", buf) - } - h.noHTTP11 = !bytes.Equal(b[:n], strHTTP11) - b = b[n+1:] - - // parse status code - h.statusCode, n, err = parseUintBuf(b) - if err != nil { - return 0, fmt.Errorf("cannot parse response status code: %s. Response %q", err, buf) - } - if len(b) > n && b[n] != ' ' { - return 0, fmt.Errorf("unexpected char at the end of status code. Response %q", buf) - } - - return len(buf) - len(bNext), nil -} - -func (h *RequestHeader) parseFirstLine(buf []byte) (int, error) { - bNext := buf - var b []byte - var err error - for len(b) == 0 { - if b, bNext, err = nextLine(bNext); err != nil { - return 0, err - } - } - - // parse method - n := bytes.IndexByte(b, ' ') - if n <= 0 { - return 0, fmt.Errorf("cannot find http request method in %q", buf) - } - h.method = append(h.method[:0], b[:n]...) - b = b[n+1:] - - // parse requestURI - n = bytes.LastIndexByte(b, ' ') - if n < 0 { - h.noHTTP11 = true - n = len(b) - } else if n == 0 { - return 0, fmt.Errorf("requestURI cannot be empty in %q", buf) - } else if !bytes.Equal(b[n+1:], strHTTP11) { - h.noHTTP11 = true - } - h.requestURI = append(h.requestURI[:0], b[:n]...) - - return len(buf) - len(bNext), nil -} - -func peekRawHeader(buf, key []byte) []byte { - n := bytes.Index(buf, key) - if n < 0 { - return nil - } - if n > 0 && buf[n-1] != '\n' { - return nil - } - n += len(key) - if n >= len(buf) { - return nil - } - if buf[n] != ':' { - return nil - } - n++ - if buf[n] != ' ' { - return nil - } - n++ - buf = buf[n:] - n = bytes.IndexByte(buf, '\n') - if n < 0 { - return nil - } - if n > 0 && buf[n-1] == '\r' { - n-- - } - return buf[:n] -} - -func readRawHeaders(dst, buf []byte) ([]byte, int, error) { - n := bytes.IndexByte(buf, '\n') - if n < 0 { - return nil, 0, errNeedMore - } - if (n == 1 && buf[0] == '\r') || n == 0 { - // empty headers - return dst, n + 1, nil - } - - n++ - b := buf - m := n - for { - b = b[m:] - m = bytes.IndexByte(b, '\n') - if m < 0 { - return nil, 0, errNeedMore - } - m++ - n += m - if (m == 2 && b[0] == '\r') || m == 1 { - dst = append(dst, buf[:n]...) - return dst, n, nil - } - } -} - -func (h *ResponseHeader) parseHeaders(buf []byte) (int, error) { - // 'identity' content-length by default - h.contentLength = -2 - - var s headerScanner - s.b = buf - s.disableNormalizing = h.disableNormalizing - var err error - var kv *argsKV - for s.next() { - switch string(s.key) { - case "Content-Type": - h.contentType = append(h.contentType[:0], s.value...) - case "Server": - h.server = append(h.server[:0], s.value...) - case "Content-Length": - if h.contentLength != -1 { - if h.contentLength, err = parseContentLength(s.value); err != nil { - h.contentLength = -2 - } else { - h.contentLengthBytes = append(h.contentLengthBytes[:0], s.value...) - } - } - case "Transfer-Encoding": - if !bytes.Equal(s.value, strIdentity) { - h.contentLength = -1 - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } - case "Set-Cookie": - h.cookies, kv = allocArg(h.cookies) - kv.key = getCookieKey(kv.key, s.value) - kv.value = append(kv.value[:0], s.value...) - case "Connection": - if bytes.Equal(s.value, strClose) { - h.connectionClose = true - } else { - h.connectionClose = false - h.h = appendArgBytes(h.h, s.key, s.value) - } - default: - h.h = appendArgBytes(h.h, s.key, s.value) - } - } - if s.err != nil { - h.connectionClose = true - return 0, s.err - } - - if h.contentLength < 0 { - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.contentLength == -2 && !h.ConnectionUpgrade() && !h.mustSkipContentLength() { - h.h = setArgBytes(h.h, strTransferEncoding, strIdentity) - h.connectionClose = true - } - if h.noHTTP11 && !h.connectionClose { - // close connection for non-http/1.1 response unless 'Connection: keep-alive' is set. - v := peekArgBytes(h.h, strConnection) - h.connectionClose = !hasHeaderValue(v, strKeepAlive) && !hasHeaderValue(v, strKeepAliveCamelCase) - } - - return len(buf) - len(s.b), nil -} - -func (h *RequestHeader) parseHeaders(buf []byte) (int, error) { - h.contentLength = -2 - - var s headerScanner - s.b = buf - s.disableNormalizing = h.disableNormalizing - var err error - for s.next() { - switch string(s.key) { - case "Host": - h.host = append(h.host[:0], s.value...) - case "User-Agent": - h.userAgent = append(h.userAgent[:0], s.value...) - case "Content-Type": - h.contentType = append(h.contentType[:0], s.value...) - case "Content-Length": - if h.contentLength != -1 { - if h.contentLength, err = parseContentLength(s.value); err != nil { - h.contentLength = -2 - } else { - h.contentLengthBytes = append(h.contentLengthBytes[:0], s.value...) - } - } - case "Transfer-Encoding": - if !bytes.Equal(s.value, strIdentity) { - h.contentLength = -1 - h.h = setArgBytes(h.h, strTransferEncoding, strChunked) - } - case "Connection": - if bytes.Equal(s.value, strClose) { - h.connectionClose = true - } else { - h.connectionClose = false - h.h = appendArgBytes(h.h, s.key, s.value) - } - default: - h.h = appendArgBytes(h.h, s.key, s.value) - } - } - if s.err != nil { - h.connectionClose = true - return 0, s.err - } - - if h.contentLength < 0 { - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.noBody() { - h.contentLength = 0 - h.contentLengthBytes = h.contentLengthBytes[:0] - } - if h.noHTTP11 && !h.connectionClose { - // close connection for non-http/1.1 request unless 'Connection: keep-alive' is set. - v := peekArgBytes(h.h, strConnection) - h.connectionClose = !hasHeaderValue(v, strKeepAlive) && !hasHeaderValue(v, strKeepAliveCamelCase) - } - - return len(buf) - len(s.b), nil -} - -func (h *RequestHeader) parseRawHeaders() { - if h.rawHeadersParsed { - return - } - h.rawHeadersParsed = true - if len(h.rawHeaders) == 0 { - return - } - h.parseHeaders(h.rawHeaders) -} - -func (h *RequestHeader) collectCookies() { - if h.cookiesCollected { - return - } - - for i, n := 0, len(h.h); i < n; i++ { - kv := &h.h[i] - if bytes.Equal(kv.key, strCookie) { - h.cookies = parseRequestCookies(h.cookies, kv.value) - tmp := *kv - copy(h.h[i:], h.h[i+1:]) - n-- - i-- - h.h[n] = tmp - h.h = h.h[:n] - } - } - h.cookiesCollected = true -} - -func parseContentLength(b []byte) (int, error) { - v, n, err := parseUintBuf(b) - if err != nil { - return -1, err - } - if n != len(b) { - return -1, fmt.Errorf("non-numeric chars at the end of Content-Length") - } - return v, nil -} - -type headerScanner struct { - b []byte - key []byte - value []byte - err error - - disableNormalizing bool -} - -func (s *headerScanner) next() bool { - bLen := len(s.b) - if bLen >= 2 && s.b[0] == '\r' && s.b[1] == '\n' { - s.b = s.b[2:] - return false - } - if bLen >= 1 && s.b[0] == '\n' { - s.b = s.b[1:] - return false - } - n := bytes.IndexByte(s.b, ':') - if n < 0 { - s.err = errNeedMore - return false - } - s.key = s.b[:n] - normalizeHeaderKey(s.key, s.disableNormalizing) - n++ - for len(s.b) > n && s.b[n] == ' ' { - n++ - } - s.b = s.b[n:] - n = bytes.IndexByte(s.b, '\n') - if n < 0 { - s.err = errNeedMore - return false - } - s.value = s.b[:n] - s.b = s.b[n+1:] - - if n > 0 && s.value[n-1] == '\r' { - n-- - } - for n > 0 && s.value[n-1] == ' ' { - n-- - } - s.value = s.value[:n] - return true -} - -type headerValueScanner struct { - b []byte - value []byte -} - -func (s *headerValueScanner) next() bool { - b := s.b - if len(b) == 0 { - return false - } - n := bytes.IndexByte(b, ',') - if n < 0 { - s.value = stripSpace(b) - s.b = b[len(b):] - return true - } - s.value = stripSpace(b[:n]) - s.b = b[n+1:] - return true -} - -func stripSpace(b []byte) []byte { - for len(b) > 0 && b[0] == ' ' { - b = b[1:] - } - for len(b) > 0 && b[len(b)-1] == ' ' { - b = b[:len(b)-1] - } - return b -} - -func hasHeaderValue(s, value []byte) bool { - var vs headerValueScanner - vs.b = s - for vs.next() { - if bytes.Equal(vs.value, value) { - return true - } - } - return false -} - -func nextLine(b []byte) ([]byte, []byte, error) { - nNext := bytes.IndexByte(b, '\n') - if nNext < 0 { - return nil, nil, errNeedMore - } - n := nNext - if n > 0 && b[n-1] == '\r' { - n-- - } - return b[:n], b[nNext+1:], nil -} - -func initHeaderKV(kv *argsKV, key, value string, disableNormalizing bool) { - kv.key = getHeaderKeyBytes(kv, key, disableNormalizing) - kv.value = append(kv.value[:0], value...) -} - -func getHeaderKeyBytes(kv *argsKV, key string, disableNormalizing bool) []byte { - kv.key = append(kv.key[:0], key...) - normalizeHeaderKey(kv.key, disableNormalizing) - return kv.key -} - -func normalizeHeaderKey(b []byte, disableNormalizing bool) { - if disableNormalizing { - return - } - - n := len(b) - if n == 0 { - return - } - - b[0] = toUpperTable[b[0]] - for i := 1; i < n; i++ { - p := &b[i] - if *p == '-' { - i++ - if i < n { - b[i] = toUpperTable[b[i]] - } - continue - } - *p = toLowerTable[*p] - } -} - -// AppendNormalizedHeaderKey appends normalized header key (name) to dst -// and returns the resulting dst. -// -// Normalized header key starts with uppercase letter. The first letters -// after dashes are also uppercased. All the other letters are lowercased. -// Examples: -// -// * coNTENT-TYPe -> Content-Type -// * HOST -> Host -// * foo-bar-baz -> Foo-Bar-Baz -func AppendNormalizedHeaderKey(dst []byte, key string) []byte { - dst = append(dst, key...) - normalizeHeaderKey(dst[len(dst)-len(key):], false) - return dst -} - -// AppendNormalizedHeaderKeyBytes appends normalized header key (name) to dst -// and returns the resulting dst. -// -// Normalized header key starts with uppercase letter. The first letters -// after dashes are also uppercased. All the other letters are lowercased. -// Examples: -// -// * coNTENT-TYPe -> Content-Type -// * HOST -> Host -// * foo-bar-baz -> Foo-Bar-Baz -func AppendNormalizedHeaderKeyBytes(dst, key []byte) []byte { - return AppendNormalizedHeaderKey(dst, b2s(key)) -} - -var ( - errNeedMore = errors.New("need more data: cannot find trailing lf") - errSmallBuffer = errors.New("small read buffer. Increase ReadBufferSize") -) - -// ErrSmallBuffer is returned when the provided buffer size is too small -// for reading request and/or response headers. -// -// ReadBufferSize value from Server or clients should reduce the number -// of such errors. -type ErrSmallBuffer struct { - error -} - -func mustPeekBuffered(r *bufio.Reader) []byte { - buf, err := r.Peek(r.Buffered()) - if len(buf) == 0 || err != nil { - panic(fmt.Sprintf("bufio.Reader.Peek() returned unexpected data (%q, %v)", buf, err)) - } - return buf -} - -func mustDiscard(r *bufio.Reader, n int) { - if _, err := r.Discard(n); err != nil { - panic(fmt.Sprintf("bufio.Reader.Discard(%d) failed: %s", n, err)) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go deleted file mode 100644 index 95ade063..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/http.go +++ /dev/null @@ -1,1714 +0,0 @@ -package fasthttp - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - "mime/multipart" - "os" - "sync" - - "github.com/valyala/bytebufferpool" -) - -// Request represents HTTP request. -// -// It is forbidden copying Request instances. Create new instances -// and use CopyTo instead. -// -// Request instance MUST NOT be used from concurrently running goroutines. -type Request struct { - noCopy noCopy - - // Request header - // - // Copying Header by value is forbidden. Use pointer to Header instead. - Header RequestHeader - - uri URI - postArgs Args - - bodyStream io.Reader - w requestBodyWriter - body *bytebufferpool.ByteBuffer - - multipartForm *multipart.Form - multipartFormBoundary string - - // Group bool members in order to reduce Request object size. - parsedURI bool - parsedPostArgs bool - - keepBodyBuffer bool - - isTLS bool -} - -// Response represents HTTP response. -// -// It is forbidden copying Response instances. Create new instances -// and use CopyTo instead. -// -// Response instance MUST NOT be used from concurrently running goroutines. -type Response struct { - noCopy noCopy - - // Response header - // - // Copying Header by value is forbidden. Use pointer to Header instead. - Header ResponseHeader - - bodyStream io.Reader - w responseBodyWriter - body *bytebufferpool.ByteBuffer - - // Response.Read() skips reading body if set to true. - // Use it for reading HEAD responses. - // - // Response.Write() skips writing body if set to true. - // Use it for writing HEAD responses. - SkipBody bool - - keepBodyBuffer bool -} - -// SetHost sets host for the request. -func (req *Request) SetHost(host string) { - req.URI().SetHost(host) -} - -// SetHostBytes sets host for the request. -func (req *Request) SetHostBytes(host []byte) { - req.URI().SetHostBytes(host) -} - -// Host returns the host for the given request. -func (req *Request) Host() []byte { - return req.URI().Host() -} - -// SetRequestURI sets RequestURI. -func (req *Request) SetRequestURI(requestURI string) { - req.Header.SetRequestURI(requestURI) - req.parsedURI = false -} - -// SetRequestURIBytes sets RequestURI. -func (req *Request) SetRequestURIBytes(requestURI []byte) { - req.Header.SetRequestURIBytes(requestURI) - req.parsedURI = false -} - -// RequestURI returns request's URI. -func (req *Request) RequestURI() []byte { - if req.parsedURI { - requestURI := req.uri.RequestURI() - req.SetRequestURIBytes(requestURI) - } - return req.Header.RequestURI() -} - -// StatusCode returns response status code. -func (resp *Response) StatusCode() int { - return resp.Header.StatusCode() -} - -// SetStatusCode sets response status code. -func (resp *Response) SetStatusCode(statusCode int) { - resp.Header.SetStatusCode(statusCode) -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (resp *Response) ConnectionClose() bool { - return resp.Header.ConnectionClose() -} - -// SetConnectionClose sets 'Connection: close' header. -func (resp *Response) SetConnectionClose() { - resp.Header.SetConnectionClose() -} - -// ConnectionClose returns true if 'Connection: close' header is set. -func (req *Request) ConnectionClose() bool { - return req.Header.ConnectionClose() -} - -// SetConnectionClose sets 'Connection: close' header. -func (req *Request) SetConnectionClose() { - req.Header.SetConnectionClose() -} - -// SendFile registers file on the given path to be used as response body -// when Write is called. -// -// Note that SendFile doesn't set Content-Type, so set it yourself -// with Header.SetContentType. -func (resp *Response) SendFile(path string) error { - f, err := os.Open(path) - if err != nil { - return err - } - fileInfo, err := f.Stat() - if err != nil { - f.Close() - return err - } - size64 := fileInfo.Size() - size := int(size64) - if int64(size) != size64 { - size = -1 - } - - resp.Header.SetLastModified(fileInfo.ModTime()) - resp.SetBodyStream(f, size) - return nil -} - -// SetBodyStream sets request body stream and, optionally body size. -// -// If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// Note that GET and HEAD requests cannot have body. -// -// See also SetBodyStreamWriter. -func (req *Request) SetBodyStream(bodyStream io.Reader, bodySize int) { - req.ResetBody() - req.bodyStream = bodyStream - req.Header.SetContentLength(bodySize) -} - -// SetBodyStream sets response body stream and, optionally body size. -// -// If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// See also SetBodyStreamWriter. -func (resp *Response) SetBodyStream(bodyStream io.Reader, bodySize int) { - resp.ResetBody() - resp.bodyStream = bodyStream - resp.Header.SetContentLength(bodySize) -} - -// IsBodyStream returns true if body is set via SetBodyStream* -func (req *Request) IsBodyStream() bool { - return req.bodyStream != nil -} - -// IsBodyStream returns true if body is set via SetBodyStream* -func (resp *Response) IsBodyStream() bool { - return resp.bodyStream != nil -} - -// SetBodyStreamWriter registers the given sw for populating request body. -// -// This function may be used in the following cases: -// -// * if request body is too big (more than 10MB). -// * if request body is streamed from slow external sources. -// * if request body must be streamed to the server in chunks -// (aka `http client push` or `chunked transfer-encoding`). -// -// Note that GET and HEAD requests cannot have body. -// -/// See also SetBodyStream. -func (req *Request) SetBodyStreamWriter(sw StreamWriter) { - sr := NewStreamReader(sw) - req.SetBodyStream(sr, -1) -} - -// SetBodyStreamWriter registers the given sw for populating response body. -// -// This function may be used in the following cases: -// -// * if response body is too big (more than 10MB). -// * if response body is streamed from slow external sources. -// * if response body must be streamed to the client in chunks -// (aka `http server push` or `chunked transfer-encoding`). -// -// See also SetBodyStream. -func (resp *Response) SetBodyStreamWriter(sw StreamWriter) { - sr := NewStreamReader(sw) - resp.SetBodyStream(sr, -1) -} - -// BodyWriter returns writer for populating response body. -// -// If used inside RequestHandler, the returned writer must not be used -// after returning from RequestHandler. Use RequestCtx.Write -// or SetBodyStreamWriter in this case. -func (resp *Response) BodyWriter() io.Writer { - resp.w.r = resp - return &resp.w -} - -// BodyWriter returns writer for populating request body. -func (req *Request) BodyWriter() io.Writer { - req.w.r = req - return &req.w -} - -type responseBodyWriter struct { - r *Response -} - -func (w *responseBodyWriter) Write(p []byte) (int, error) { - w.r.AppendBody(p) - return len(p), nil -} - -type requestBodyWriter struct { - r *Request -} - -func (w *requestBodyWriter) Write(p []byte) (int, error) { - w.r.AppendBody(p) - return len(p), nil -} - -// Body returns response body. -// -// The returned body is valid until the response modification. -func (resp *Response) Body() []byte { - if resp.bodyStream != nil { - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - _, err := copyZeroAlloc(bodyBuf, resp.bodyStream) - resp.closeBodyStream() - if err != nil { - bodyBuf.SetString(err.Error()) - } - } - return resp.bodyBytes() -} - -func (resp *Response) bodyBytes() []byte { - if resp.body == nil { - return nil - } - return resp.body.B -} - -func (req *Request) bodyBytes() []byte { - if req.body == nil { - return nil - } - return req.body.B -} - -func (resp *Response) bodyBuffer() *bytebufferpool.ByteBuffer { - if resp.body == nil { - resp.body = responseBodyPool.Get() - } - return resp.body -} - -func (req *Request) bodyBuffer() *bytebufferpool.ByteBuffer { - if req.body == nil { - req.body = requestBodyPool.Get() - } - return req.body -} - -var ( - responseBodyPool bytebufferpool.Pool - requestBodyPool bytebufferpool.Pool -) - -// BodyGunzip returns un-gzipped body data. -// -// This method may be used if the request header contains -// 'Content-Encoding: gzip' for reading un-gzipped body. -// Use Body for reading gzipped request body. -func (req *Request) BodyGunzip() ([]byte, error) { - return gunzipData(req.Body()) -} - -// BodyGunzip returns un-gzipped body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: gzip' for reading un-gzipped body. -// Use Body for reading gzipped response body. -func (resp *Response) BodyGunzip() ([]byte, error) { - return gunzipData(resp.Body()) -} - -func gunzipData(p []byte) ([]byte, error) { - var bb ByteBuffer - _, err := WriteGunzip(&bb, p) - if err != nil { - return nil, err - } - return bb.B, nil -} - -// BodyInflate returns inflated body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: deflate' for reading inflated request body. -// Use Body for reading deflated request body. -func (req *Request) BodyInflate() ([]byte, error) { - return inflateData(req.Body()) -} - -// BodyInflate returns inflated body data. -// -// This method may be used if the response header contains -// 'Content-Encoding: deflate' for reading inflated response body. -// Use Body for reading deflated response body. -func (resp *Response) BodyInflate() ([]byte, error) { - return inflateData(resp.Body()) -} - -func inflateData(p []byte) ([]byte, error) { - var bb ByteBuffer - _, err := WriteInflate(&bb, p) - if err != nil { - return nil, err - } - return bb.B, nil -} - -// BodyWriteTo writes request body to w. -func (req *Request) BodyWriteTo(w io.Writer) error { - if req.bodyStream != nil { - _, err := copyZeroAlloc(w, req.bodyStream) - req.closeBodyStream() - return err - } - if req.onlyMultipartForm() { - return WriteMultipartForm(w, req.multipartForm, req.multipartFormBoundary) - } - _, err := w.Write(req.bodyBytes()) - return err -} - -// BodyWriteTo writes response body to w. -func (resp *Response) BodyWriteTo(w io.Writer) error { - if resp.bodyStream != nil { - _, err := copyZeroAlloc(w, resp.bodyStream) - resp.closeBodyStream() - return err - } - _, err := w.Write(resp.bodyBytes()) - return err -} - -// AppendBody appends p to response body. -// -// It is safe re-using p after the function returns. -func (resp *Response) AppendBody(p []byte) { - resp.AppendBodyString(b2s(p)) -} - -// AppendBodyString appends s to response body. -func (resp *Response) AppendBodyString(s string) { - resp.closeBodyStream() - resp.bodyBuffer().WriteString(s) -} - -// SetBody sets response body. -// -// It is safe re-using body argument after the function returns. -func (resp *Response) SetBody(body []byte) { - resp.SetBodyString(b2s(body)) -} - -// SetBodyString sets response body. -func (resp *Response) SetBodyString(body string) { - resp.closeBodyStream() - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - bodyBuf.WriteString(body) -} - -// ResetBody resets response body. -func (resp *Response) ResetBody() { - resp.closeBodyStream() - if resp.body != nil { - if resp.keepBodyBuffer { - resp.body.Reset() - } else { - responseBodyPool.Put(resp.body) - resp.body = nil - } - } -} - -// ReleaseBody retires the response body if it is greater than "size" bytes. -// -// This permits GC to reclaim the large buffer. If used, must be before -// ReleaseResponse. -// -// Use this method only if you really understand how it works. -// The majority of workloads don't need this method. -func (resp *Response) ReleaseBody(size int) { - if cap(resp.body.B) > size { - resp.closeBodyStream() - resp.body = nil - } -} - -// ReleaseBody retires the request body if it is greater than "size" bytes. -// -// This permits GC to reclaim the large buffer. If used, must be before -// ReleaseRequest. -// -// Use this method only if you really understand how it works. -// The majority of workloads don't need this method. -func (req *Request) ReleaseBody(size int) { - if cap(req.body.B) > size { - req.closeBodyStream() - req.body = nil - } -} - -// SwapBody swaps response body with the given body and returns -// the previous response body. -// -// It is forbidden to use the body passed to SwapBody after -// the function returns. -func (resp *Response) SwapBody(body []byte) []byte { - bb := resp.bodyBuffer() - - if resp.bodyStream != nil { - bb.Reset() - _, err := copyZeroAlloc(bb, resp.bodyStream) - resp.closeBodyStream() - if err != nil { - bb.Reset() - bb.SetString(err.Error()) - } - } - - oldBody := bb.B - bb.B = body - return oldBody -} - -// SwapBody swaps request body with the given body and returns -// the previous request body. -// -// It is forbidden to use the body passed to SwapBody after -// the function returns. -func (req *Request) SwapBody(body []byte) []byte { - bb := req.bodyBuffer() - - if req.bodyStream != nil { - bb.Reset() - _, err := copyZeroAlloc(bb, req.bodyStream) - req.closeBodyStream() - if err != nil { - bb.Reset() - bb.SetString(err.Error()) - } - } - - oldBody := bb.B - bb.B = body - return oldBody -} - -// Body returns request body. -// -// The returned body is valid until the request modification. -func (req *Request) Body() []byte { - if req.bodyStream != nil { - bodyBuf := req.bodyBuffer() - bodyBuf.Reset() - _, err := copyZeroAlloc(bodyBuf, req.bodyStream) - req.closeBodyStream() - if err != nil { - bodyBuf.SetString(err.Error()) - } - } else if req.onlyMultipartForm() { - body, err := marshalMultipartForm(req.multipartForm, req.multipartFormBoundary) - if err != nil { - return []byte(err.Error()) - } - return body - } - return req.bodyBytes() -} - -// AppendBody appends p to request body. -// -// It is safe re-using p after the function returns. -func (req *Request) AppendBody(p []byte) { - req.AppendBodyString(b2s(p)) -} - -// AppendBodyString appends s to request body. -func (req *Request) AppendBodyString(s string) { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - req.bodyBuffer().WriteString(s) -} - -// SetBody sets request body. -// -// It is safe re-using body argument after the function returns. -func (req *Request) SetBody(body []byte) { - req.SetBodyString(b2s(body)) -} - -// SetBodyString sets request body. -func (req *Request) SetBodyString(body string) { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - req.bodyBuffer().SetString(body) -} - -// ResetBody resets request body. -func (req *Request) ResetBody() { - req.RemoveMultipartFormFiles() - req.closeBodyStream() - if req.body != nil { - if req.keepBodyBuffer { - req.body.Reset() - } else { - requestBodyPool.Put(req.body) - req.body = nil - } - } -} - -// CopyTo copies req contents to dst except of body stream. -func (req *Request) CopyTo(dst *Request) { - req.copyToSkipBody(dst) - if req.body != nil { - dst.bodyBuffer().Set(req.body.B) - } else if dst.body != nil { - dst.body.Reset() - } -} - -func (req *Request) copyToSkipBody(dst *Request) { - dst.Reset() - req.Header.CopyTo(&dst.Header) - - req.uri.CopyTo(&dst.uri) - dst.parsedURI = req.parsedURI - - req.postArgs.CopyTo(&dst.postArgs) - dst.parsedPostArgs = req.parsedPostArgs - dst.isTLS = req.isTLS - - // do not copy multipartForm - it will be automatically - // re-created on the first call to MultipartForm. -} - -// CopyTo copies resp contents to dst except of body stream. -func (resp *Response) CopyTo(dst *Response) { - resp.copyToSkipBody(dst) - if resp.body != nil { - dst.bodyBuffer().Set(resp.body.B) - } else if dst.body != nil { - dst.body.Reset() - } -} - -func (resp *Response) copyToSkipBody(dst *Response) { - dst.Reset() - resp.Header.CopyTo(&dst.Header) - dst.SkipBody = resp.SkipBody -} - -func swapRequestBody(a, b *Request) { - a.body, b.body = b.body, a.body - a.bodyStream, b.bodyStream = b.bodyStream, a.bodyStream -} - -func swapResponseBody(a, b *Response) { - a.body, b.body = b.body, a.body - a.bodyStream, b.bodyStream = b.bodyStream, a.bodyStream -} - -// URI returns request URI -func (req *Request) URI() *URI { - req.parseURI() - return &req.uri -} - -func (req *Request) parseURI() { - if req.parsedURI { - return - } - req.parsedURI = true - - req.uri.parseQuick(req.Header.RequestURI(), &req.Header, req.isTLS) -} - -// PostArgs returns POST arguments. -func (req *Request) PostArgs() *Args { - req.parsePostArgs() - return &req.postArgs -} - -func (req *Request) parsePostArgs() { - if req.parsedPostArgs { - return - } - req.parsedPostArgs = true - - if !bytes.HasPrefix(req.Header.ContentType(), strPostArgsContentType) { - return - } - req.postArgs.ParseBytes(req.bodyBytes()) -} - -// ErrNoMultipartForm means that the request's Content-Type -// isn't 'multipart/form-data'. -var ErrNoMultipartForm = errors.New("request has no multipart/form-data Content-Type") - -// MultipartForm returns requests's multipart form. -// -// Returns ErrNoMultipartForm if request's Content-Type -// isn't 'multipart/form-data'. -// -// RemoveMultipartFormFiles must be called after returned multipart form -// is processed. -func (req *Request) MultipartForm() (*multipart.Form, error) { - if req.multipartForm != nil { - return req.multipartForm, nil - } - - req.multipartFormBoundary = string(req.Header.MultipartFormBoundary()) - if len(req.multipartFormBoundary) == 0 { - return nil, ErrNoMultipartForm - } - - ce := req.Header.peek(strContentEncoding) - body := req.bodyBytes() - if bytes.Equal(ce, strGzip) { - // Do not care about memory usage here. - var err error - if body, err = AppendGunzipBytes(nil, body); err != nil { - return nil, fmt.Errorf("cannot gunzip request body: %s", err) - } - } else if len(ce) > 0 { - return nil, fmt.Errorf("unsupported Content-Encoding: %q", ce) - } - - f, err := readMultipartForm(bytes.NewReader(body), req.multipartFormBoundary, len(body), len(body)) - if err != nil { - return nil, err - } - req.multipartForm = f - return f, nil -} - -func marshalMultipartForm(f *multipart.Form, boundary string) ([]byte, error) { - var buf ByteBuffer - if err := WriteMultipartForm(&buf, f, boundary); err != nil { - return nil, err - } - return buf.B, nil -} - -// WriteMultipartForm writes the given multipart form f with the given -// boundary to w. -func WriteMultipartForm(w io.Writer, f *multipart.Form, boundary string) error { - // Do not care about memory allocations here, since multipart - // form processing is slow. - if len(boundary) == 0 { - panic("BUG: form boundary cannot be empty") - } - - mw := multipart.NewWriter(w) - if err := mw.SetBoundary(boundary); err != nil { - return fmt.Errorf("cannot use form boundary %q: %s", boundary, err) - } - - // marshal values - for k, vv := range f.Value { - for _, v := range vv { - if err := mw.WriteField(k, v); err != nil { - return fmt.Errorf("cannot write form field %q value %q: %s", k, v, err) - } - } - } - - // marshal files - for k, fvv := range f.File { - for _, fv := range fvv { - vw, err := mw.CreateFormFile(k, fv.Filename) - if err != nil { - return fmt.Errorf("cannot create form file %q (%q): %s", k, fv.Filename, err) - } - fh, err := fv.Open() - if err != nil { - return fmt.Errorf("cannot open form file %q (%q): %s", k, fv.Filename, err) - } - if _, err = copyZeroAlloc(vw, fh); err != nil { - return fmt.Errorf("error when copying form file %q (%q): %s", k, fv.Filename, err) - } - if err = fh.Close(); err != nil { - return fmt.Errorf("cannot close form file %q (%q): %s", k, fv.Filename, err) - } - } - } - - if err := mw.Close(); err != nil { - return fmt.Errorf("error when closing multipart form writer: %s", err) - } - - return nil -} - -func readMultipartForm(r io.Reader, boundary string, size, maxInMemoryFileSize int) (*multipart.Form, error) { - // Do not care about memory allocations here, since they are tiny - // compared to multipart data (aka multi-MB files) usually sent - // in multipart/form-data requests. - - if size <= 0 { - panic(fmt.Sprintf("BUG: form size must be greater than 0. Given %d", size)) - } - lr := io.LimitReader(r, int64(size)) - mr := multipart.NewReader(lr, boundary) - f, err := mr.ReadForm(int64(maxInMemoryFileSize)) - if err != nil { - return nil, fmt.Errorf("cannot read multipart/form-data body: %s", err) - } - return f, nil -} - -// Reset clears request contents. -func (req *Request) Reset() { - req.Header.Reset() - req.resetSkipHeader() -} - -func (req *Request) resetSkipHeader() { - req.ResetBody() - req.uri.Reset() - req.parsedURI = false - req.postArgs.Reset() - req.parsedPostArgs = false - req.isTLS = false -} - -// RemoveMultipartFormFiles removes multipart/form-data temporary files -// associated with the request. -func (req *Request) RemoveMultipartFormFiles() { - if req.multipartForm != nil { - // Do not check for error, since these files may be deleted or moved - // to new places by user code. - req.multipartForm.RemoveAll() - req.multipartForm = nil - } - req.multipartFormBoundary = "" -} - -// Reset clears response contents. -func (resp *Response) Reset() { - resp.Header.Reset() - resp.resetSkipHeader() - resp.SkipBody = false -} - -func (resp *Response) resetSkipHeader() { - resp.ResetBody() -} - -// Read reads request (including body) from the given r. -// -// RemoveMultipartFormFiles or Reset must be called after -// reading multipart/form-data request in order to delete temporarily -// uploaded files. -// -// If MayContinue returns true, the caller must: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (req *Request) Read(r *bufio.Reader) error { - return req.ReadLimitBody(r, 0) -} - -const defaultMaxInMemoryFileSize = 16 * 1024 * 1024 - -var errGetOnly = errors.New("non-GET request received") - -// ReadLimitBody reads request from the given r, limiting the body size. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -// -// RemoveMultipartFormFiles or Reset must be called after -// reading multipart/form-data request in order to delete temporarily -// uploaded files. -// -// If MayContinue returns true, the caller must: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (req *Request) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { - req.resetSkipHeader() - return req.readLimitBody(r, maxBodySize, false) -} - -func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool) error { - // Do not reset the request here - the caller must reset it before - // calling this method. - - err := req.Header.Read(r) - if err != nil { - return err - } - if getOnly && !req.Header.IsGet() { - return errGetOnly - } - - if req.Header.noBody() { - return nil - } - - if req.MayContinue() { - // 'Expect: 100-continue' header found. Let the caller deciding - // whether to read request body or - // to return StatusExpectationFailed. - return nil - } - - return req.ContinueReadBody(r, maxBodySize) -} - -// MayContinue returns true if the request contains -// 'Expect: 100-continue' header. -// -// The caller must do one of the following actions if MayContinue returns true: -// -// - Either send StatusExpectationFailed response if request headers don't -// satisfy the caller. -// - Or send StatusContinue response before reading request body -// with ContinueReadBody. -// - Or close the connection. -func (req *Request) MayContinue() bool { - return bytes.Equal(req.Header.peek(strExpect), str100Continue) -} - -// ContinueReadBody reads request body if request header contains -// 'Expect: 100-continue'. -// -// The caller must send StatusContinue response before calling this method. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -func (req *Request) ContinueReadBody(r *bufio.Reader, maxBodySize int) error { - var err error - contentLength := req.Header.ContentLength() - if contentLength > 0 { - if maxBodySize > 0 && contentLength > maxBodySize { - return ErrBodyTooLarge - } - - // Pre-read multipart form data of known length. - // This way we limit memory usage for large file uploads, since their contents - // is streamed into temporary files if file size exceeds defaultMaxInMemoryFileSize. - req.multipartFormBoundary = string(req.Header.MultipartFormBoundary()) - if len(req.multipartFormBoundary) > 0 && len(req.Header.peek(strContentEncoding)) == 0 { - req.multipartForm, err = readMultipartForm(r, req.multipartFormBoundary, contentLength, defaultMaxInMemoryFileSize) - if err != nil { - req.Reset() - } - return err - } - } - - if contentLength == -2 { - // identity body has no sense for http requests, since - // the end of body is determined by connection close. - // So just ignore request body for requests without - // 'Content-Length' and 'Transfer-Encoding' headers. - req.Header.SetContentLength(0) - return nil - } - - bodyBuf := req.bodyBuffer() - bodyBuf.Reset() - bodyBuf.B, err = readBody(r, contentLength, maxBodySize, bodyBuf.B) - if err != nil { - req.Reset() - return err - } - req.Header.SetContentLength(len(bodyBuf.B)) - return nil -} - -// Read reads response (including body) from the given r. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (resp *Response) Read(r *bufio.Reader) error { - return resp.ReadLimitBody(r, 0) -} - -// ReadLimitBody reads response from the given r, limiting the body size. -// -// If maxBodySize > 0 and the body size exceeds maxBodySize, -// then ErrBodyTooLarge is returned. -// -// io.EOF is returned if r is closed before reading the first header byte. -func (resp *Response) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { - resp.resetSkipHeader() - err := resp.Header.Read(r) - if err != nil { - return err - } - if resp.Header.StatusCode() == StatusContinue { - // Read the next response according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html . - if err = resp.Header.Read(r); err != nil { - return err - } - } - - if !resp.mustSkipBody() { - bodyBuf := resp.bodyBuffer() - bodyBuf.Reset() - bodyBuf.B, err = readBody(r, resp.Header.ContentLength(), maxBodySize, bodyBuf.B) - if err != nil { - resp.Reset() - return err - } - resp.Header.SetContentLength(len(bodyBuf.B)) - } - return nil -} - -func (resp *Response) mustSkipBody() bool { - return resp.SkipBody || resp.Header.mustSkipContentLength() -} - -var errRequestHostRequired = errors.New("missing required Host header in request") - -// WriteTo writes request to w. It implements io.WriterTo. -func (req *Request) WriteTo(w io.Writer) (int64, error) { - return writeBufio(req, w) -} - -// WriteTo writes response to w. It implements io.WriterTo. -func (resp *Response) WriteTo(w io.Writer) (int64, error) { - return writeBufio(resp, w) -} - -func writeBufio(hw httpWriter, w io.Writer) (int64, error) { - sw := acquireStatsWriter(w) - bw := acquireBufioWriter(sw) - err1 := hw.Write(bw) - err2 := bw.Flush() - releaseBufioWriter(bw) - n := sw.bytesWritten - releaseStatsWriter(sw) - - err := err1 - if err == nil { - err = err2 - } - return n, err -} - -type statsWriter struct { - w io.Writer - bytesWritten int64 -} - -func (w *statsWriter) Write(p []byte) (int, error) { - n, err := w.w.Write(p) - w.bytesWritten += int64(n) - return n, err -} - -func acquireStatsWriter(w io.Writer) *statsWriter { - v := statsWriterPool.Get() - if v == nil { - return &statsWriter{ - w: w, - } - } - sw := v.(*statsWriter) - sw.w = w - return sw -} - -func releaseStatsWriter(sw *statsWriter) { - sw.w = nil - sw.bytesWritten = 0 - statsWriterPool.Put(sw) -} - -var statsWriterPool sync.Pool - -func acquireBufioWriter(w io.Writer) *bufio.Writer { - v := bufioWriterPool.Get() - if v == nil { - return bufio.NewWriter(w) - } - bw := v.(*bufio.Writer) - bw.Reset(w) - return bw -} - -func releaseBufioWriter(bw *bufio.Writer) { - bufioWriterPool.Put(bw) -} - -var bufioWriterPool sync.Pool - -func (req *Request) onlyMultipartForm() bool { - return req.multipartForm != nil && (req.body == nil || len(req.body.B) == 0) -} - -// Write writes request to w. -// -// Write doesn't flush request to w for performance reasons. -// -// See also WriteTo. -func (req *Request) Write(w *bufio.Writer) error { - if len(req.Header.Host()) == 0 || req.parsedURI { - uri := req.URI() - host := uri.Host() - if len(host) == 0 { - return errRequestHostRequired - } - req.Header.SetHostBytes(host) - req.Header.SetRequestURIBytes(uri.RequestURI()) - } - - if req.bodyStream != nil { - return req.writeBodyStream(w) - } - - body := req.bodyBytes() - var err error - if req.onlyMultipartForm() { - body, err = marshalMultipartForm(req.multipartForm, req.multipartFormBoundary) - if err != nil { - return fmt.Errorf("error when marshaling multipart form: %s", err) - } - req.Header.SetMultipartFormBoundary(req.multipartFormBoundary) - } - - hasBody := !req.Header.noBody() - if hasBody { - req.Header.SetContentLength(len(body)) - } - if err = req.Header.Write(w); err != nil { - return err - } - if hasBody { - _, err = w.Write(body) - } else if len(body) > 0 { - return fmt.Errorf("non-zero body for non-POST request. body=%q", body) - } - return err -} - -// WriteGzip writes response with gzipped body to w. -// -// The method gzips response body and sets 'Content-Encoding: gzip' -// header before writing response to w. -// -// WriteGzip doesn't flush response to w for performance reasons. -func (resp *Response) WriteGzip(w *bufio.Writer) error { - return resp.WriteGzipLevel(w, CompressDefaultCompression) -} - -// WriteGzipLevel writes response with gzipped body to w. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -// -// The method gzips response body and sets 'Content-Encoding: gzip' -// header before writing response to w. -// -// WriteGzipLevel doesn't flush response to w for performance reasons. -func (resp *Response) WriteGzipLevel(w *bufio.Writer, level int) error { - if err := resp.gzipBody(level); err != nil { - return err - } - return resp.Write(w) -} - -// WriteDeflate writes response with deflated body to w. -// -// The method deflates response body and sets 'Content-Encoding: deflate' -// header before writing response to w. -// -// WriteDeflate doesn't flush response to w for performance reasons. -func (resp *Response) WriteDeflate(w *bufio.Writer) error { - return resp.WriteDeflateLevel(w, CompressDefaultCompression) -} - -// WriteDeflateLevel writes response with deflated body to w. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -// -// The method deflates response body and sets 'Content-Encoding: deflate' -// header before writing response to w. -// -// WriteDeflateLevel doesn't flush response to w for performance reasons. -func (resp *Response) WriteDeflateLevel(w *bufio.Writer, level int) error { - if err := resp.deflateBody(level); err != nil { - return err - } - return resp.Write(w) -} - -func (resp *Response) gzipBody(level int) error { - if len(resp.Header.peek(strContentEncoding)) > 0 { - // It looks like the body is already compressed. - // Do not compress it again. - return nil - } - - if !resp.Header.isCompressibleContentType() { - // The content-type cannot be compressed. - return nil - } - - if resp.bodyStream != nil { - // Reset Content-Length to -1, since it is impossible - // to determine body size beforehand of streamed compression. - // For https://github.com/valyala/fasthttp/issues/176 . - resp.Header.SetContentLength(-1) - - // Do not care about memory allocations here, since gzip is slow - // and allocates a lot of memory by itself. - bs := resp.bodyStream - resp.bodyStream = NewStreamReader(func(sw *bufio.Writer) { - zw := acquireStacklessGzipWriter(sw, level) - fw := &flushWriter{ - wf: zw, - bw: sw, - } - copyZeroAlloc(fw, bs) - releaseStacklessGzipWriter(zw, level) - if bsc, ok := bs.(io.Closer); ok { - bsc.Close() - } - }) - } else { - bodyBytes := resp.bodyBytes() - if len(bodyBytes) < minCompressLen { - // There is no sense in spending CPU time on small body compression, - // since there is a very high probability that the compressed - // body size will be bigger than the original body size. - return nil - } - w := responseBodyPool.Get() - w.B = AppendGzipBytesLevel(w.B, bodyBytes, level) - - // Hack: swap resp.body with w. - if resp.body != nil { - responseBodyPool.Put(resp.body) - } - resp.body = w - } - resp.Header.SetCanonical(strContentEncoding, strGzip) - return nil -} - -func (resp *Response) deflateBody(level int) error { - if len(resp.Header.peek(strContentEncoding)) > 0 { - // It looks like the body is already compressed. - // Do not compress it again. - return nil - } - - if !resp.Header.isCompressibleContentType() { - // The content-type cannot be compressed. - return nil - } - - if resp.bodyStream != nil { - // Reset Content-Length to -1, since it is impossible - // to determine body size beforehand of streamed compression. - // For https://github.com/valyala/fasthttp/issues/176 . - resp.Header.SetContentLength(-1) - - // Do not care about memory allocations here, since flate is slow - // and allocates a lot of memory by itself. - bs := resp.bodyStream - resp.bodyStream = NewStreamReader(func(sw *bufio.Writer) { - zw := acquireStacklessDeflateWriter(sw, level) - fw := &flushWriter{ - wf: zw, - bw: sw, - } - copyZeroAlloc(fw, bs) - releaseStacklessDeflateWriter(zw, level) - if bsc, ok := bs.(io.Closer); ok { - bsc.Close() - } - }) - } else { - bodyBytes := resp.bodyBytes() - if len(bodyBytes) < minCompressLen { - // There is no sense in spending CPU time on small body compression, - // since there is a very high probability that the compressed - // body size will be bigger than the original body size. - return nil - } - w := responseBodyPool.Get() - w.B = AppendDeflateBytesLevel(w.B, bodyBytes, level) - - // Hack: swap resp.body with w. - if resp.body != nil { - responseBodyPool.Put(resp.body) - } - resp.body = w - } - resp.Header.SetCanonical(strContentEncoding, strDeflate) - return nil -} - -// Bodies with sizes smaller than minCompressLen aren't compressed at all -const minCompressLen = 200 - -type writeFlusher interface { - io.Writer - Flush() error -} - -type flushWriter struct { - wf writeFlusher - bw *bufio.Writer -} - -func (w *flushWriter) Write(p []byte) (int, error) { - n, err := w.wf.Write(p) - if err != nil { - return 0, err - } - if err = w.wf.Flush(); err != nil { - return 0, err - } - if err = w.bw.Flush(); err != nil { - return 0, err - } - return n, nil -} - -// Write writes response to w. -// -// Write doesn't flush response to w for performance reasons. -// -// See also WriteTo. -func (resp *Response) Write(w *bufio.Writer) error { - sendBody := !resp.mustSkipBody() - - if resp.bodyStream != nil { - return resp.writeBodyStream(w, sendBody) - } - - body := resp.bodyBytes() - bodyLen := len(body) - if sendBody || bodyLen > 0 { - resp.Header.SetContentLength(bodyLen) - } - if err := resp.Header.Write(w); err != nil { - return err - } - if sendBody { - if _, err := w.Write(body); err != nil { - return err - } - } - return nil -} - -func (req *Request) writeBodyStream(w *bufio.Writer) error { - var err error - - contentLength := req.Header.ContentLength() - if contentLength < 0 { - lrSize := limitedReaderSize(req.bodyStream) - if lrSize >= 0 { - contentLength = int(lrSize) - if int64(contentLength) != lrSize { - contentLength = -1 - } - if contentLength >= 0 { - req.Header.SetContentLength(contentLength) - } - } - } - if contentLength >= 0 { - if err = req.Header.Write(w); err == nil { - err = writeBodyFixedSize(w, req.bodyStream, int64(contentLength)) - } - } else { - req.Header.SetContentLength(-1) - if err = req.Header.Write(w); err == nil { - err = writeBodyChunked(w, req.bodyStream) - } - } - err1 := req.closeBodyStream() - if err == nil { - err = err1 - } - return err -} - -func (resp *Response) writeBodyStream(w *bufio.Writer, sendBody bool) error { - var err error - - contentLength := resp.Header.ContentLength() - if contentLength < 0 { - lrSize := limitedReaderSize(resp.bodyStream) - if lrSize >= 0 { - contentLength = int(lrSize) - if int64(contentLength) != lrSize { - contentLength = -1 - } - if contentLength >= 0 { - resp.Header.SetContentLength(contentLength) - } - } - } - if contentLength >= 0 { - if err = resp.Header.Write(w); err == nil && sendBody { - err = writeBodyFixedSize(w, resp.bodyStream, int64(contentLength)) - } - } else { - resp.Header.SetContentLength(-1) - if err = resp.Header.Write(w); err == nil && sendBody { - err = writeBodyChunked(w, resp.bodyStream) - } - } - err1 := resp.closeBodyStream() - if err == nil { - err = err1 - } - return err -} - -func (req *Request) closeBodyStream() error { - if req.bodyStream == nil { - return nil - } - var err error - if bsc, ok := req.bodyStream.(io.Closer); ok { - err = bsc.Close() - } - req.bodyStream = nil - return err -} - -func (resp *Response) closeBodyStream() error { - if resp.bodyStream == nil { - return nil - } - var err error - if bsc, ok := resp.bodyStream.(io.Closer); ok { - err = bsc.Close() - } - resp.bodyStream = nil - return err -} - -// String returns request representation. -// -// Returns error message instead of request representation on error. -// -// Use Write instead of String for performance-critical code. -func (req *Request) String() string { - return getHTTPString(req) -} - -// String returns response representation. -// -// Returns error message instead of response representation on error. -// -// Use Write instead of String for performance-critical code. -func (resp *Response) String() string { - return getHTTPString(resp) -} - -func getHTTPString(hw httpWriter) string { - w := AcquireByteBuffer() - bw := bufio.NewWriter(w) - if err := hw.Write(bw); err != nil { - return err.Error() - } - if err := bw.Flush(); err != nil { - return err.Error() - } - s := string(w.B) - ReleaseByteBuffer(w) - return s -} - -type httpWriter interface { - Write(w *bufio.Writer) error -} - -func writeBodyChunked(w *bufio.Writer, r io.Reader) error { - vbuf := copyBufPool.Get() - buf := vbuf.([]byte) - - var err error - var n int - for { - n, err = r.Read(buf) - if n == 0 { - if err == nil { - panic("BUG: io.Reader returned 0, nil") - } - if err == io.EOF { - if err = writeChunk(w, buf[:0]); err != nil { - break - } - err = nil - } - break - } - if err = writeChunk(w, buf[:n]); err != nil { - break - } - } - - copyBufPool.Put(vbuf) - return err -} - -func limitedReaderSize(r io.Reader) int64 { - lr, ok := r.(*io.LimitedReader) - if !ok { - return -1 - } - return lr.N -} - -func writeBodyFixedSize(w *bufio.Writer, r io.Reader, size int64) error { - if size > maxSmallFileSize { - // w buffer must be empty for triggering - // sendfile path in bufio.Writer.ReadFrom. - if err := w.Flush(); err != nil { - return err - } - } - - // Unwrap a single limited reader for triggering sendfile path - // in net.TCPConn.ReadFrom. - lr, ok := r.(*io.LimitedReader) - if ok { - r = lr.R - } - - n, err := copyZeroAlloc(w, r) - - if ok { - lr.N -= n - } - - if n != size && err == nil { - err = fmt.Errorf("copied %d bytes from body stream instead of %d bytes", n, size) - } - return err -} - -func copyZeroAlloc(w io.Writer, r io.Reader) (int64, error) { - vbuf := copyBufPool.Get() - buf := vbuf.([]byte) - n, err := io.CopyBuffer(w, r, buf) - copyBufPool.Put(vbuf) - return n, err -} - -var copyBufPool = sync.Pool{ - New: func() interface{} { - return make([]byte, 4096) - }, -} - -func writeChunk(w *bufio.Writer, b []byte) error { - n := len(b) - writeHexInt(w, n) - w.Write(strCRLF) - w.Write(b) - _, err := w.Write(strCRLF) - err1 := w.Flush() - if err == nil { - err = err1 - } - return err -} - -// ErrBodyTooLarge is returned if either request or response body exceeds -// the given limit. -var ErrBodyTooLarge = errors.New("body size exceeds the given limit") - -func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) { - dst = dst[:0] - if contentLength >= 0 { - if maxBodySize > 0 && contentLength > maxBodySize { - return dst, ErrBodyTooLarge - } - return appendBodyFixedSize(r, dst, contentLength) - } - if contentLength == -1 { - return readBodyChunked(r, maxBodySize, dst) - } - return readBodyIdentity(r, maxBodySize, dst) -} - -func readBodyIdentity(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, error) { - dst = dst[:cap(dst)] - if len(dst) == 0 { - dst = make([]byte, 1024) - } - offset := 0 - for { - nn, err := r.Read(dst[offset:]) - if nn <= 0 { - if err != nil { - if err == io.EOF { - return dst[:offset], nil - } - return dst[:offset], err - } - panic(fmt.Sprintf("BUG: bufio.Read() returned (%d, nil)", nn)) - } - offset += nn - if maxBodySize > 0 && offset > maxBodySize { - return dst[:offset], ErrBodyTooLarge - } - if len(dst) == offset { - n := round2(2 * offset) - if maxBodySize > 0 && n > maxBodySize { - n = maxBodySize + 1 - } - b := make([]byte, n) - copy(b, dst) - dst = b - } - } -} - -func appendBodyFixedSize(r *bufio.Reader, dst []byte, n int) ([]byte, error) { - if n == 0 { - return dst, nil - } - - offset := len(dst) - dstLen := offset + n - if cap(dst) < dstLen { - b := make([]byte, round2(dstLen)) - copy(b, dst) - dst = b - } - dst = dst[:dstLen] - - for { - nn, err := r.Read(dst[offset:]) - if nn <= 0 { - if err != nil { - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - return dst[:offset], err - } - panic(fmt.Sprintf("BUG: bufio.Read() returned (%d, nil)", nn)) - } - offset += nn - if offset == dstLen { - return dst, nil - } - } -} - -func readBodyChunked(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, error) { - if len(dst) > 0 { - panic("BUG: expected zero-length buffer") - } - - strCRLFLen := len(strCRLF) - for { - chunkSize, err := parseChunkSize(r) - if err != nil { - return dst, err - } - if maxBodySize > 0 && len(dst)+chunkSize > maxBodySize { - return dst, ErrBodyTooLarge - } - dst, err = appendBodyFixedSize(r, dst, chunkSize+strCRLFLen) - if err != nil { - return dst, err - } - if !bytes.Equal(dst[len(dst)-strCRLFLen:], strCRLF) { - return dst, fmt.Errorf("cannot find crlf at the end of chunk") - } - dst = dst[:len(dst)-strCRLFLen] - if chunkSize == 0 { - return dst, nil - } - } -} - -func parseChunkSize(r *bufio.Reader) (int, error) { - n, err := readHexInt(r) - if err != nil { - return -1, err - } - c, err := r.ReadByte() - if err != nil { - return -1, fmt.Errorf("cannot read '\r' char at the end of chunk size: %s", err) - } - if c != '\r' { - return -1, fmt.Errorf("unexpected char %q at the end of chunk size. Expected %q", c, '\r') - } - c, err = r.ReadByte() - if err != nil { - return -1, fmt.Errorf("cannot read '\n' char at the end of chunk size: %s", err) - } - if c != '\n' { - return -1, fmt.Errorf("unexpected char %q at the end of chunk size. Expected %q", c, '\n') - } - return n, nil -} - -func round2(n int) int { - if n <= 0 { - return 0 - } - n-- - x := uint(0) - for n > 0 { - n >>= 1 - x++ - } - return 1 << x -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/lbclient.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/lbclient.go deleted file mode 100644 index 12418b6b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/lbclient.go +++ /dev/null @@ -1,183 +0,0 @@ -package fasthttp - -import ( - "sync" - "sync/atomic" - "time" -) - -// BalancingClient is the interface for clients, which may be passed -// to LBClient.Clients. -type BalancingClient interface { - DoDeadline(req *Request, resp *Response, deadline time.Time) error - PendingRequests() int -} - -// LBClient balances requests among available LBClient.Clients. -// -// It has the following features: -// -// - Balances load among available clients using 'least loaded' + 'round robin' -// hybrid technique. -// - Dynamically decreases load on unhealthy clients. -// -// It is forbidden copying LBClient instances. Create new instances instead. -// -// It is safe calling LBClient methods from concurrently running goroutines. -type LBClient struct { - noCopy noCopy - - // Clients must contain non-zero clients list. - // Incoming requests are balanced among these clients. - Clients []BalancingClient - - // HealthCheck is a callback called after each request. - // - // The request, response and the error returned by the client - // is passed to HealthCheck, so the callback may determine whether - // the client is healthy. - // - // Load on the current client is decreased if HealthCheck returns false. - // - // By default HealthCheck returns false if err != nil. - HealthCheck func(req *Request, resp *Response, err error) bool - - // Timeout is the request timeout used when calling LBClient.Do. - // - // DefaultLBClientTimeout is used by default. - Timeout time.Duration - - cs []*lbClient - - // nextIdx is for spreading requests among equally loaded clients - // in a round-robin fashion. - nextIdx uint32 - - once sync.Once -} - -// DefaultLBClientTimeout is the default request timeout used by LBClient -// when calling LBClient.Do. -// -// The timeout may be overridden via LBClient.Timeout. -const DefaultLBClientTimeout = time.Second - -// DoDeadline calls DoDeadline on the least loaded client -func (cc *LBClient) DoDeadline(req *Request, resp *Response, deadline time.Time) error { - return cc.get().DoDeadline(req, resp, deadline) -} - -// DoTimeout calculates deadline and calls DoDeadline on the least loaded client -func (cc *LBClient) DoTimeout(req *Request, resp *Response, timeout time.Duration) error { - deadline := time.Now().Add(timeout) - return cc.get().DoDeadline(req, resp, deadline) -} - -// Do calls calculates deadline using LBClient.Timeout and calls DoDeadline -// on the least loaded client. -func (cc *LBClient) Do(req *Request, resp *Response) error { - timeout := cc.Timeout - if timeout <= 0 { - timeout = DefaultLBClientTimeout - } - return cc.DoTimeout(req, resp, timeout) -} - -func (cc *LBClient) init() { - if len(cc.Clients) == 0 { - panic("BUG: LBClient.Clients cannot be empty") - } - for _, c := range cc.Clients { - cc.cs = append(cc.cs, &lbClient{ - c: c, - healthCheck: cc.HealthCheck, - }) - } - - // Randomize nextIdx in order to prevent initial servers' - // hammering from a cluster of identical LBClients. - cc.nextIdx = uint32(time.Now().UnixNano()) -} - -func (cc *LBClient) get() *lbClient { - cc.once.Do(cc.init) - - cs := cc.cs - idx := atomic.AddUint32(&cc.nextIdx, 1) - idx %= uint32(len(cs)) - - minC := cs[idx] - minN := minC.PendingRequests() - if minN == 0 { - return minC - } - for _, c := range cs[idx+1:] { - n := c.PendingRequests() - if n == 0 { - return c - } - if n < minN { - minC = c - minN = n - } - } - for _, c := range cs[:idx] { - n := c.PendingRequests() - if n == 0 { - return c - } - if n < minN { - minC = c - minN = n - } - } - return minC -} - -type lbClient struct { - c BalancingClient - healthCheck func(req *Request, resp *Response, err error) bool - penalty uint32 -} - -func (c *lbClient) DoDeadline(req *Request, resp *Response, deadline time.Time) error { - err := c.c.DoDeadline(req, resp, deadline) - if !c.isHealthy(req, resp, err) && c.incPenalty() { - // Penalize the client returning error, so the next requests - // are routed to another clients. - time.AfterFunc(penaltyDuration, c.decPenalty) - } - return err -} - -func (c *lbClient) PendingRequests() int { - n := c.c.PendingRequests() - m := atomic.LoadUint32(&c.penalty) - return n + int(m) -} - -func (c *lbClient) isHealthy(req *Request, resp *Response, err error) bool { - if c.healthCheck == nil { - return err == nil - } - return c.healthCheck(req, resp, err) -} - -func (c *lbClient) incPenalty() bool { - m := atomic.AddUint32(&c.penalty, 1) - if m > maxPenalty { - c.decPenalty() - return false - } - return true -} - -func (c *lbClient) decPenalty() { - atomic.AddUint32(&c.penalty, ^uint32(0)) -} - -const ( - maxPenalty = 300 - - penaltyDuration = 3 * time.Second -) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/nocopy.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/nocopy.go deleted file mode 100644 index 32af52e4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/nocopy.go +++ /dev/null @@ -1,9 +0,0 @@ -package fasthttp - -// Embed this type into a struct, which mustn't be copied, -// so `go vet` gives a warning if this struct is copied. -// -// See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. -type noCopy struct{} - -func (*noCopy) Lock() {} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/peripconn.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/peripconn.go deleted file mode 100644 index afd2a927..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/peripconn.go +++ /dev/null @@ -1,100 +0,0 @@ -package fasthttp - -import ( - "fmt" - "net" - "sync" -) - -type perIPConnCounter struct { - pool sync.Pool - lock sync.Mutex - m map[uint32]int -} - -func (cc *perIPConnCounter) Register(ip uint32) int { - cc.lock.Lock() - if cc.m == nil { - cc.m = make(map[uint32]int) - } - n := cc.m[ip] + 1 - cc.m[ip] = n - cc.lock.Unlock() - return n -} - -func (cc *perIPConnCounter) Unregister(ip uint32) { - cc.lock.Lock() - if cc.m == nil { - cc.lock.Unlock() - panic("BUG: perIPConnCounter.Register() wasn't called") - } - n := cc.m[ip] - 1 - if n < 0 { - cc.lock.Unlock() - panic(fmt.Sprintf("BUG: negative per-ip counter=%d for ip=%d", n, ip)) - } - cc.m[ip] = n - cc.lock.Unlock() -} - -type perIPConn struct { - net.Conn - - ip uint32 - perIPConnCounter *perIPConnCounter -} - -func acquirePerIPConn(conn net.Conn, ip uint32, counter *perIPConnCounter) *perIPConn { - v := counter.pool.Get() - if v == nil { - v = &perIPConn{ - perIPConnCounter: counter, - } - } - c := v.(*perIPConn) - c.Conn = conn - c.ip = ip - return c -} - -func releasePerIPConn(c *perIPConn) { - c.Conn = nil - c.perIPConnCounter.pool.Put(c) -} - -func (c *perIPConn) Close() error { - err := c.Conn.Close() - c.perIPConnCounter.Unregister(c.ip) - releasePerIPConn(c) - return err -} - -func getUint32IP(c net.Conn) uint32 { - return ip2uint32(getConnIP4(c)) -} - -func getConnIP4(c net.Conn) net.IP { - addr := c.RemoteAddr() - ipAddr, ok := addr.(*net.TCPAddr) - if !ok { - return net.IPv4zero - } - return ipAddr.IP.To4() -} - -func ip2uint32(ip net.IP) uint32 { - if len(ip) != 4 { - return 0 - } - return uint32(ip[0])<<24 | uint32(ip[1])<<16 | uint32(ip[2])<<8 | uint32(ip[3]) -} - -func uint322ip(ip uint32) net.IP { - b := make([]byte, 4) - b[0] = byte(ip >> 24) - b[1] = byte(ip >> 16) - b[2] = byte(ip >> 8) - b[3] = byte(ip) - return b -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go deleted file mode 100644 index 200ae512..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/pprofhandler/pprof.go +++ /dev/null @@ -1,35 +0,0 @@ -package pprofhandler - -import ( - "net/http/pprof" - "strings" - - "github.com/valyala/fasthttp" - "github.com/valyala/fasthttp/fasthttpadaptor" -) - -var ( - cmdline = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Cmdline) - profile = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Profile) - symbol = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Symbol) - trace = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Trace) - index = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Index) -) - -// PprofHandler serves server runtime profiling data in the format expected by the pprof visualization tool. -// -// See https://golang.org/pkg/net/http/pprof/ for details. -func PprofHandler(ctx *fasthttp.RequestCtx) { - ctx.Response.Header.Set("Content-Type", "text/html") - if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/cmdline") { - cmdline(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/profile") { - profile(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/symbol") { - symbol(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/trace") { - trace(ctx) - } else { - index(ctx) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE deleted file mode 100644 index 5f25159a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Max Riveiro - -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/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go deleted file mode 100644 index 191fe641..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/reuseport/reuseport.go +++ /dev/null @@ -1,57 +0,0 @@ -// +build linux darwin dragonfly freebsd netbsd openbsd rumprun - -// Package reuseport provides TCP net.Listener with SO_REUSEPORT support. -// -// SO_REUSEPORT allows linear scaling server performance on multi-CPU servers. -// See https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ for more details :) -// -// The package is based on https://github.com/kavu/go_reuseport . -package reuseport - -import ( - "fmt" - "net" - "strings" - - "github.com/valyala/tcplisten" -) - -// ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT. -type ErrNoReusePort struct { - err error -} - -// Error implements error interface. -func (e *ErrNoReusePort) Error() string { - return fmt.Sprintf("The OS doesn't support SO_REUSEPORT: %s", e.err) -} - -// Listen returns TCP listener with SO_REUSEPORT option set. -// -// The returned listener tries enabling the following TCP options, which usually -// have positive impact on performance: -// -// - TCP_DEFER_ACCEPT. This option expects that the server reads from accepted -// connections before writing to them. -// -// - TCP_FASTOPEN. See https://lwn.net/Articles/508865/ for details. -// -// Use https://github.com/valyala/tcplisten if you want customizing -// these options. -// -// Only tcp4 and tcp6 networks are supported. -// -// ErrNoReusePort error is returned if the system doesn't support SO_REUSEPORT. -func Listen(network, addr string) (net.Listener, error) { - ln, err := cfg.NewListener(network, addr) - if err != nil && strings.Contains(err.Error(), "SO_REUSEPORT") { - return nil, &ErrNoReusePort{err} - } - return ln, err -} - -var cfg = &tcplisten.Config{ - ReusePort: true, - DeferAccept: true, - FastOpen: true, -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go deleted file mode 100644 index 927a3b20..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/server.go +++ /dev/null @@ -1,2019 +0,0 @@ -package fasthttp - -import ( - "bufio" - "crypto/tls" - "errors" - "fmt" - "io" - "log" - "mime/multipart" - "net" - "os" - "strings" - "sync" - "sync/atomic" - "time" -) - -// ServeConn serves HTTP requests from the given connection -// using the given handler. -// -// ServeConn returns nil if all requests from the c are successfully served. -// It returns non-nil error otherwise. -// -// Connection c must immediately propagate all the data passed to Write() -// to the client. Otherwise requests' processing may hang. -// -// ServeConn closes c before returning. -func ServeConn(c net.Conn, handler RequestHandler) error { - v := serverPool.Get() - if v == nil { - v = &Server{} - } - s := v.(*Server) - s.Handler = handler - err := s.ServeConn(c) - s.Handler = nil - serverPool.Put(v) - return err -} - -var serverPool sync.Pool - -// Serve serves incoming connections from the given listener -// using the given handler. -// -// Serve blocks until the given listener returns permanent error. -func Serve(ln net.Listener, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.Serve(ln) -} - -// ServeTLS serves HTTPS requests from the given net.Listener -// using the given handler. -// -// certFile and keyFile are paths to TLS certificate and key files. -func ServeTLS(ln net.Listener, certFile, keyFile string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ServeTLS(ln, certFile, keyFile) -} - -// ServeTLSEmbed serves HTTPS requests from the given net.Listener -// using the given handler. -// -// certData and keyData must contain valid TLS certificate and key data. -func ServeTLSEmbed(ln net.Listener, certData, keyData []byte, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ServeTLSEmbed(ln, certData, keyData) -} - -// ListenAndServe serves HTTP requests from the given TCP addr -// using the given handler. -func ListenAndServe(addr string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServe(addr) -} - -// ListenAndServeUNIX serves HTTP requests from the given UNIX addr -// using the given handler. -// -// The function deletes existing file at addr before starting serving. -// -// The server sets the given file mode for the UNIX addr. -func ListenAndServeUNIX(addr string, mode os.FileMode, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeUNIX(addr, mode) -} - -// ListenAndServeTLS serves HTTPS requests from the given TCP addr -// using the given handler. -// -// certFile and keyFile are paths to TLS certificate and key files. -func ListenAndServeTLS(addr, certFile, keyFile string, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeTLS(addr, certFile, keyFile) -} - -// ListenAndServeTLSEmbed serves HTTPS requests from the given TCP addr -// using the given handler. -// -// certData and keyData must contain valid TLS certificate and key data. -func ListenAndServeTLSEmbed(addr string, certData, keyData []byte, handler RequestHandler) error { - s := &Server{ - Handler: handler, - } - return s.ListenAndServeTLSEmbed(addr, certData, keyData) -} - -// RequestHandler must process incoming requests. -// -// RequestHandler must call ctx.TimeoutError() before returning -// if it keeps references to ctx and/or its' members after the return. -// Consider wrapping RequestHandler into TimeoutHandler if response time -// must be limited. -type RequestHandler func(ctx *RequestCtx) - -// Server implements HTTP server. -// -// Default Server settings should satisfy the majority of Server users. -// Adjust Server settings only if you really understand the consequences. -// -// It is forbidden copying Server instances. Create new Server instances -// instead. -// -// It is safe to call Server methods from concurrently running goroutines. -type Server struct { - noCopy noCopy - - // Handler for processing incoming requests. - Handler RequestHandler - - // Server name for sending in response headers. - // - // Default server name is used if left blank. - Name string - - // The maximum number of concurrent connections the server may serve. - // - // DefaultConcurrency is used if not set. - Concurrency int - - // Whether to disable keep-alive connections. - // - // The server will close all the incoming connections after sending - // the first response to client if this option is set to true. - // - // By default keep-alive connections are enabled. - DisableKeepalive bool - - // Per-connection buffer size for requests' reading. - // This also limits the maximum header size. - // - // Increase this buffer if your clients send multi-KB RequestURIs - // and/or multi-KB headers (for example, BIG cookies). - // - // Default buffer size is used if not set. - ReadBufferSize int - - // Per-connection buffer size for responses' writing. - // - // Default buffer size is used if not set. - WriteBufferSize int - - // Maximum duration for reading the full request (including body). - // - // This also limits the maximum duration for idle keep-alive - // connections. - // - // By default request read timeout is unlimited. - ReadTimeout time.Duration - - // Maximum duration for writing the full response (including body). - // - // By default response write timeout is unlimited. - WriteTimeout time.Duration - - // Maximum number of concurrent client connections allowed per IP. - // - // By default unlimited number of concurrent connections - // may be established to the server from a single IP address. - MaxConnsPerIP int - - // Maximum number of requests served per connection. - // - // The server closes connection after the last request. - // 'Connection: close' header is added to the last response. - // - // By default unlimited number of requests may be served per connection. - MaxRequestsPerConn int - - // Maximum keep-alive connection lifetime. - // - // The server closes keep-alive connection after its' lifetime - // expiration. - // - // See also ReadTimeout for limiting the duration of idle keep-alive - // connections. - // - // By default keep-alive connection lifetime is unlimited. - MaxKeepaliveDuration time.Duration - - // Maximum request body size. - // - // The server rejects requests with bodies exceeding this limit. - // - // Request body size is limited by DefaultMaxRequestBodySize by default. - MaxRequestBodySize int - - // Aggressively reduces memory usage at the cost of higher CPU usage - // if set to true. - // - // Try enabling this option only if the server consumes too much memory - // serving mostly idle keep-alive connections. This may reduce memory - // usage by more than 50%. - // - // Aggressive memory usage reduction is disabled by default. - ReduceMemoryUsage bool - - // Rejects all non-GET requests if set to true. - // - // This option is useful as anti-DoS protection for servers - // accepting only GET requests. The request size is limited - // by ReadBufferSize if GetOnly is set. - // - // Server accepts all the requests by default. - GetOnly bool - - // Logs all errors, including the most frequent - // 'connection reset by peer', 'broken pipe' and 'connection timeout' - // errors. Such errors are common in production serving real-world - // clients. - // - // By default the most frequent errors such as - // 'connection reset by peer', 'broken pipe' and 'connection timeout' - // are suppressed in order to limit output log traffic. - LogAllErrors bool - - // Header names are passed as-is without normalization - // if this option is set. - // - // Disabled header names' normalization may be useful only for proxying - // incoming requests to other servers expecting case-sensitive - // header names. See https://github.com/valyala/fasthttp/issues/57 - // for details. - // - // By default request and response header names are normalized, i.e. - // The first letter and the first letters following dashes - // are uppercased, while all the other letters are lowercased. - // Examples: - // - // * HOST -> Host - // * content-type -> Content-Type - // * cONTENT-lenGTH -> Content-Length - DisableHeaderNamesNormalizing bool - - // Logger, which is used by RequestCtx.Logger(). - // - // By default standard logger from log package is used. - Logger Logger - - concurrency uint32 - concurrencyCh chan struct{} - perIPConnCounter perIPConnCounter - serverName atomic.Value - - ctxPool sync.Pool - readerPool sync.Pool - writerPool sync.Pool - hijackConnPool sync.Pool - bytePool sync.Pool -} - -// TimeoutHandler creates RequestHandler, which returns StatusRequestTimeout -// error with the given msg to the client if h didn't return during -// the given duration. -// -// The returned handler may return StatusTooManyRequests error with the given -// msg to the client if there are more than Server.Concurrency concurrent -// handlers h are running at the moment. -func TimeoutHandler(h RequestHandler, timeout time.Duration, msg string) RequestHandler { - if timeout <= 0 { - return h - } - - return func(ctx *RequestCtx) { - concurrencyCh := ctx.s.concurrencyCh - select { - case concurrencyCh <- struct{}{}: - default: - ctx.Error(msg, StatusTooManyRequests) - return - } - - ch := ctx.timeoutCh - if ch == nil { - ch = make(chan struct{}, 1) - ctx.timeoutCh = ch - } - go func() { - h(ctx) - ch <- struct{}{} - <-concurrencyCh - }() - ctx.timeoutTimer = initTimer(ctx.timeoutTimer, timeout) - select { - case <-ch: - case <-ctx.timeoutTimer.C: - ctx.TimeoutError(msg) - } - stopTimer(ctx.timeoutTimer) - } -} - -// CompressHandler returns RequestHandler that transparently compresses -// response body generated by h if the request contains 'gzip' or 'deflate' -// 'Accept-Encoding' header. -func CompressHandler(h RequestHandler) RequestHandler { - return CompressHandlerLevel(h, CompressDefaultCompression) -} - -// CompressHandlerLevel returns RequestHandler that transparently compresses -// response body generated by h if the request contains 'gzip' or 'deflate' -// 'Accept-Encoding' header. -// -// Level is the desired compression level: -// -// * CompressNoCompression -// * CompressBestSpeed -// * CompressBestCompression -// * CompressDefaultCompression -// * CompressHuffmanOnly -func CompressHandlerLevel(h RequestHandler, level int) RequestHandler { - return func(ctx *RequestCtx) { - h(ctx) - ce := ctx.Response.Header.PeekBytes(strContentEncoding) - if len(ce) > 0 { - // Do not compress responses with non-empty - // Content-Encoding. - return - } - if ctx.Request.Header.HasAcceptEncodingBytes(strGzip) { - ctx.Response.gzipBody(level) - } else if ctx.Request.Header.HasAcceptEncodingBytes(strDeflate) { - ctx.Response.deflateBody(level) - } - } -} - -// RequestCtx contains incoming request and manages outgoing response. -// -// It is forbidden copying RequestCtx instances. -// -// RequestHandler should avoid holding references to incoming RequestCtx and/or -// its' members after the return. -// If holding RequestCtx references after the return is unavoidable -// (for instance, ctx is passed to a separate goroutine and ctx lifetime cannot -// be controlled), then the RequestHandler MUST call ctx.TimeoutError() -// before return. -// -// It is unsafe modifying/reading RequestCtx instance from concurrently -// running goroutines. The only exception is TimeoutError*, which may be called -// while other goroutines accessing RequestCtx. -type RequestCtx struct { - noCopy noCopy - - // Incoming request. - // - // Copying Request by value is forbidden. Use pointer to Request instead. - Request Request - - // Outgoing response. - // - // Copying Response by value is forbidden. Use pointer to Response instead. - Response Response - - userValues userData - - lastReadDuration time.Duration - - connID uint64 - connRequestNum uint64 - connTime time.Time - - time time.Time - - logger ctxLogger - s *Server - c net.Conn - fbr firstByteReader - - timeoutResponse *Response - timeoutCh chan struct{} - timeoutTimer *time.Timer - - hijackHandler HijackHandler -} - -// HijackHandler must process the hijacked connection c. -// -// The connection c is automatically closed after returning from HijackHandler. -// -// The connection c must not be used after returning from the handler. -type HijackHandler func(c net.Conn) - -// Hijack registers the given handler for connection hijacking. -// -// The handler is called after returning from RequestHandler -// and sending http response. The current connection is passed -// to the handler. The connection is automatically closed after -// returning from the handler. -// -// The server skips calling the handler in the following cases: -// -// * 'Connection: close' header exists in either request or response. -// * Unexpected error during response writing to the connection. -// -// The server stops processing requests from hijacked connections. -// Server limits such as Concurrency, ReadTimeout, WriteTimeout, etc. -// aren't applied to hijacked connections. -// -// The handler must not retain references to ctx members. -// -// Arbitrary 'Connection: Upgrade' protocols may be implemented -// with HijackHandler. For instance, -// -// * WebSocket ( https://en.wikipedia.org/wiki/WebSocket ) -// * HTTP/2.0 ( https://en.wikipedia.org/wiki/HTTP/2 ) -// -func (ctx *RequestCtx) Hijack(handler HijackHandler) { - ctx.hijackHandler = handler -} - -// Hijacked returns true after Hijack is called. -func (ctx *RequestCtx) Hijacked() bool { - return ctx.hijackHandler != nil -} - -// SetUserValue stores the given value (arbitrary object) -// under the given key in ctx. -// -// The value stored in ctx may be obtained by UserValue*. -// -// This functionality may be useful for passing arbitrary values between -// functions involved in request processing. -// -// All the values are removed from ctx after returning from the top -// RequestHandler. Additionally, Close method is called on each value -// implementing io.Closer before removing the value from ctx. -func (ctx *RequestCtx) SetUserValue(key string, value interface{}) { - ctx.userValues.Set(key, value) -} - -// SetUserValueBytes stores the given value (arbitrary object) -// under the given key in ctx. -// -// The value stored in ctx may be obtained by UserValue*. -// -// This functionality may be useful for passing arbitrary values between -// functions involved in request processing. -// -// All the values stored in ctx are deleted after returning from RequestHandler. -func (ctx *RequestCtx) SetUserValueBytes(key []byte, value interface{}) { - ctx.userValues.SetBytes(key, value) -} - -// UserValue returns the value stored via SetUserValue* under the given key. -func (ctx *RequestCtx) UserValue(key string) interface{} { - return ctx.userValues.Get(key) -} - -// UserValueBytes returns the value stored via SetUserValue* -// under the given key. -func (ctx *RequestCtx) UserValueBytes(key []byte) interface{} { - return ctx.userValues.GetBytes(key) -} - -// VisitUserValues calls visitor for each existing userValue. -// -// visitor must not retain references to key and value after returning. -// Make key and/or value copies if you need storing them after returning. -func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, interface{})) { - for i, n := 0, len(ctx.userValues); i < n; i++ { - kv := &ctx.userValues[i] - visitor(kv.key, kv.value) - } -} - -type connTLSer interface { - ConnectionState() tls.ConnectionState -} - -// IsTLS returns true if the underlying connection is tls.Conn. -// -// tls.Conn is an encrypted connection (aka SSL, HTTPS). -func (ctx *RequestCtx) IsTLS() bool { - // cast to (connTLSer) instead of (*tls.Conn), since it catches - // cases with overridden tls.Conn such as: - // - // type customConn struct { - // *tls.Conn - // - // // other custom fields here - // } - _, ok := ctx.c.(connTLSer) - return ok -} - -// TLSConnectionState returns TLS connection state. -// -// The function returns nil if the underlying connection isn't tls.Conn. -// -// The returned state may be used for verifying TLS version, client certificates, -// etc. -func (ctx *RequestCtx) TLSConnectionState() *tls.ConnectionState { - tlsConn, ok := ctx.c.(connTLSer) - if !ok { - return nil - } - state := tlsConn.ConnectionState() - return &state -} - -type firstByteReader struct { - c net.Conn - ch byte - byteRead bool -} - -func (r *firstByteReader) Read(b []byte) (int, error) { - if len(b) == 0 { - return 0, nil - } - nn := 0 - if !r.byteRead { - b[0] = r.ch - b = b[1:] - r.byteRead = true - nn = 1 - } - n, err := r.c.Read(b) - return n + nn, err -} - -// Logger is used for logging formatted messages. -type Logger interface { - // Printf must have the same semantics as log.Printf. - Printf(format string, args ...interface{}) -} - -var ctxLoggerLock sync.Mutex - -type ctxLogger struct { - ctx *RequestCtx - logger Logger -} - -func (cl *ctxLogger) Printf(format string, args ...interface{}) { - ctxLoggerLock.Lock() - msg := fmt.Sprintf(format, args...) - ctx := cl.ctx - cl.logger.Printf("%.3f %s - %s", time.Since(ctx.Time()).Seconds(), ctx.String(), msg) - ctxLoggerLock.Unlock() -} - -var zeroTCPAddr = &net.TCPAddr{ - IP: net.IPv4zero, -} - -// String returns unique string representation of the ctx. -// -// The returned value may be useful for logging. -func (ctx *RequestCtx) String() string { - return fmt.Sprintf("#%016X - %s<->%s - %s %s", ctx.ID(), ctx.LocalAddr(), ctx.RemoteAddr(), ctx.Request.Header.Method(), ctx.URI().FullURI()) -} - -// ID returns unique ID of the request. -func (ctx *RequestCtx) ID() uint64 { - return (ctx.connID << 32) | ctx.connRequestNum -} - -// ConnID returns unique connection ID. -// -// This ID may be used to match distinct requests to the same incoming -// connection. -func (ctx *RequestCtx) ConnID() uint64 { - return ctx.connID -} - -// Time returns RequestHandler call time. -func (ctx *RequestCtx) Time() time.Time { - return ctx.time -} - -// ConnTime returns the time the server started serving the connection -// the current request came from. -func (ctx *RequestCtx) ConnTime() time.Time { - return ctx.connTime -} - -// ConnRequestNum returns request sequence number -// for the current connection. -// -// Sequence starts with 1. -func (ctx *RequestCtx) ConnRequestNum() uint64 { - return ctx.connRequestNum -} - -// SetConnectionClose sets 'Connection: close' response header and closes -// connection after the RequestHandler returns. -func (ctx *RequestCtx) SetConnectionClose() { - ctx.Response.SetConnectionClose() -} - -// SetStatusCode sets response status code. -func (ctx *RequestCtx) SetStatusCode(statusCode int) { - ctx.Response.SetStatusCode(statusCode) -} - -// SetContentType sets response Content-Type. -func (ctx *RequestCtx) SetContentType(contentType string) { - ctx.Response.Header.SetContentType(contentType) -} - -// SetContentTypeBytes sets response Content-Type. -// -// It is safe modifying contentType buffer after function return. -func (ctx *RequestCtx) SetContentTypeBytes(contentType []byte) { - ctx.Response.Header.SetContentTypeBytes(contentType) -} - -// RequestURI returns RequestURI. -// -// This uri is valid until returning from RequestHandler. -func (ctx *RequestCtx) RequestURI() []byte { - return ctx.Request.Header.RequestURI() -} - -// URI returns requested uri. -// -// The uri is valid until returning from RequestHandler. -func (ctx *RequestCtx) URI() *URI { - return ctx.Request.URI() -} - -// Referer returns request referer. -// -// The referer is valid until returning from RequestHandler. -func (ctx *RequestCtx) Referer() []byte { - return ctx.Request.Header.Referer() -} - -// UserAgent returns User-Agent header value from the request. -func (ctx *RequestCtx) UserAgent() []byte { - return ctx.Request.Header.UserAgent() -} - -// Path returns requested path. -// -// The path is valid until returning from RequestHandler. -func (ctx *RequestCtx) Path() []byte { - return ctx.URI().Path() -} - -// Host returns requested host. -// -// The host is valid until returning from RequestHandler. -func (ctx *RequestCtx) Host() []byte { - return ctx.URI().Host() -} - -// QueryArgs returns query arguments from RequestURI. -// -// It doesn't return POST'ed arguments - use PostArgs() for this. -// -// Returned arguments are valid until returning from RequestHandler. -// -// See also PostArgs, FormValue and FormFile. -func (ctx *RequestCtx) QueryArgs() *Args { - return ctx.URI().QueryArgs() -} - -// PostArgs returns POST arguments. -// -// It doesn't return query arguments from RequestURI - use QueryArgs for this. -// -// Returned arguments are valid until returning from RequestHandler. -// -// See also QueryArgs, FormValue and FormFile. -func (ctx *RequestCtx) PostArgs() *Args { - return ctx.Request.PostArgs() -} - -// MultipartForm returns requests's multipart form. -// -// Returns ErrNoMultipartForm if request's content-type -// isn't 'multipart/form-data'. -// -// All uploaded temporary files are automatically deleted after -// returning from RequestHandler. Either move or copy uploaded files -// into new place if you want retaining them. -// -// Use SaveMultipartFile function for permanently saving uploaded file. -// -// The returned form is valid until returning from RequestHandler. -// -// See also FormFile and FormValue. -func (ctx *RequestCtx) MultipartForm() (*multipart.Form, error) { - return ctx.Request.MultipartForm() -} - -// FormFile returns uploaded file associated with the given multipart form key. -// -// The file is automatically deleted after returning from RequestHandler, -// so either move or copy uploaded file into new place if you want retaining it. -// -// Use SaveMultipartFile function for permanently saving uploaded file. -// -// The returned file header is valid until returning from RequestHandler. -func (ctx *RequestCtx) FormFile(key string) (*multipart.FileHeader, error) { - mf, err := ctx.MultipartForm() - if err != nil { - return nil, err - } - if mf.File == nil { - return nil, err - } - fhh := mf.File[key] - if fhh == nil { - return nil, ErrMissingFile - } - return fhh[0], nil -} - -// ErrMissingFile may be returned from FormFile when the is no uploaded file -// associated with the given multipart form key. -var ErrMissingFile = errors.New("there is no uploaded file associated with the given key") - -// SaveMultipartFile saves multipart file fh under the given filename path. -func SaveMultipartFile(fh *multipart.FileHeader, path string) error { - f, err := fh.Open() - if err != nil { - return err - } - defer f.Close() - - if ff, ok := f.(*os.File); ok { - return os.Rename(ff.Name(), path) - } - - ff, err := os.Create(path) - if err != nil { - return err - } - defer ff.Close() - _, err = copyZeroAlloc(ff, f) - return err -} - -// FormValue returns form value associated with the given key. -// -// The value is searched in the following places: -// -// * Query string. -// * POST or PUT body. -// -// There are more fine-grained methods for obtaining form values: -// -// * QueryArgs for obtaining values from query string. -// * PostArgs for obtaining values from POST or PUT body. -// * MultipartForm for obtaining values from multipart form. -// * FormFile for obtaining uploaded files. -// -// The returned value is valid until returning from RequestHandler. -func (ctx *RequestCtx) FormValue(key string) []byte { - v := ctx.QueryArgs().Peek(key) - if len(v) > 0 { - return v - } - v = ctx.PostArgs().Peek(key) - if len(v) > 0 { - return v - } - mf, err := ctx.MultipartForm() - if err == nil && mf.Value != nil { - vv := mf.Value[key] - if len(vv) > 0 { - return []byte(vv[0]) - } - } - return nil -} - -// IsGet returns true if request method is GET. -func (ctx *RequestCtx) IsGet() bool { - return ctx.Request.Header.IsGet() -} - -// IsPost returns true if request method is POST. -func (ctx *RequestCtx) IsPost() bool { - return ctx.Request.Header.IsPost() -} - -// IsPut returns true if request method is PUT. -func (ctx *RequestCtx) IsPut() bool { - return ctx.Request.Header.IsPut() -} - -// IsDelete returns true if request method is DELETE. -func (ctx *RequestCtx) IsDelete() bool { - return ctx.Request.Header.IsDelete() -} - -// IsConnect returns true if request method is CONNECT. -func (ctx *RequestCtx) IsConnect() bool { - return ctx.Request.Header.IsConnect() -} - -// IsOptions returns true if request method is OPTIONS. -func (ctx *RequestCtx) IsOptions() bool { - return ctx.Request.Header.IsOptions() -} - -// IsTrace returns true if request method is TRACE. -func (ctx *RequestCtx) IsTrace() bool { - return ctx.Request.Header.IsTrace() -} - -// IsPatch returns true if request method is PATCH. -func (ctx *RequestCtx) IsPatch() bool { - return ctx.Request.Header.IsPatch() -} - -// Method return request method. -// -// Returned value is valid until returning from RequestHandler. -func (ctx *RequestCtx) Method() []byte { - return ctx.Request.Header.Method() -} - -// IsHead returns true if request method is HEAD. -func (ctx *RequestCtx) IsHead() bool { - return ctx.Request.Header.IsHead() -} - -// RemoteAddr returns client address for the given request. -// -// Always returns non-nil result. -func (ctx *RequestCtx) RemoteAddr() net.Addr { - if ctx.c == nil { - return zeroTCPAddr - } - addr := ctx.c.RemoteAddr() - if addr == nil { - return zeroTCPAddr - } - return addr -} - -// LocalAddr returns server address for the given request. -// -// Always returns non-nil result. -func (ctx *RequestCtx) LocalAddr() net.Addr { - if ctx.c == nil { - return zeroTCPAddr - } - addr := ctx.c.LocalAddr() - if addr == nil { - return zeroTCPAddr - } - return addr -} - -// RemoteIP returns the client ip the request came from. -// -// Always returns non-nil result. -func (ctx *RequestCtx) RemoteIP() net.IP { - return addrToIP(ctx.RemoteAddr()) -} - -// LocalIP returns the server ip the request came to. -// -// Always returns non-nil result. -func (ctx *RequestCtx) LocalIP() net.IP { - return addrToIP(ctx.LocalAddr()) -} - -func addrToIP(addr net.Addr) net.IP { - x, ok := addr.(*net.TCPAddr) - if !ok { - return net.IPv4zero - } - return x.IP -} - -// Error sets response status code to the given value and sets response body -// to the given message. -func (ctx *RequestCtx) Error(msg string, statusCode int) { - ctx.Response.Reset() - ctx.SetStatusCode(statusCode) - ctx.SetContentTypeBytes(defaultContentType) - ctx.SetBodyString(msg) -} - -// Success sets response Content-Type and body to the given values. -func (ctx *RequestCtx) Success(contentType string, body []byte) { - ctx.SetContentType(contentType) - ctx.SetBody(body) -} - -// SuccessString sets response Content-Type and body to the given values. -func (ctx *RequestCtx) SuccessString(contentType, body string) { - ctx.SetContentType(contentType) - ctx.SetBodyString(body) -} - -// Redirect sets 'Location: uri' response header and sets the given statusCode. -// -// statusCode must have one of the following values: -// -// * StatusMovedPermanently (301) -// * StatusFound (302) -// * StatusSeeOther (303) -// * StatusTemporaryRedirect (307) -// -// All other statusCode values are replaced by StatusFound (302). -// -// The redirect uri may be either absolute or relative to the current -// request uri. -func (ctx *RequestCtx) Redirect(uri string, statusCode int) { - u := AcquireURI() - ctx.URI().CopyTo(u) - u.Update(uri) - ctx.redirect(u.FullURI(), statusCode) - ReleaseURI(u) -} - -// RedirectBytes sets 'Location: uri' response header and sets -// the given statusCode. -// -// statusCode must have one of the following values: -// -// * StatusMovedPermanently (301) -// * StatusFound (302) -// * StatusSeeOther (303) -// * StatusTemporaryRedirect (307) -// -// All other statusCode values are replaced by StatusFound (302). -// -// The redirect uri may be either absolute or relative to the current -// request uri. -func (ctx *RequestCtx) RedirectBytes(uri []byte, statusCode int) { - s := b2s(uri) - ctx.Redirect(s, statusCode) -} - -func (ctx *RequestCtx) redirect(uri []byte, statusCode int) { - ctx.Response.Header.SetCanonical(strLocation, uri) - statusCode = getRedirectStatusCode(statusCode) - ctx.Response.SetStatusCode(statusCode) -} - -func getRedirectStatusCode(statusCode int) int { - if statusCode == StatusMovedPermanently || statusCode == StatusFound || - statusCode == StatusSeeOther || statusCode == StatusTemporaryRedirect { - return statusCode - } - return StatusFound -} - -// SetBody sets response body to the given value. -// -// It is safe re-using body argument after the function returns. -func (ctx *RequestCtx) SetBody(body []byte) { - ctx.Response.SetBody(body) -} - -// SetBodyString sets response body to the given value. -func (ctx *RequestCtx) SetBodyString(body string) { - ctx.Response.SetBodyString(body) -} - -// ResetBody resets response body contents. -func (ctx *RequestCtx) ResetBody() { - ctx.Response.ResetBody() -} - -// SendFile sends local file contents from the given path as response body. -// -// This is a shortcut to ServeFile(ctx, path). -// -// SendFile logs all the errors via ctx.Logger. -// -// See also ServeFile, FSHandler and FS. -func (ctx *RequestCtx) SendFile(path string) { - ServeFile(ctx, path) -} - -// SendFileBytes sends local file contents from the given path as response body. -// -// This is a shortcut to ServeFileBytes(ctx, path). -// -// SendFileBytes logs all the errors via ctx.Logger. -// -// See also ServeFileBytes, FSHandler and FS. -func (ctx *RequestCtx) SendFileBytes(path []byte) { - ServeFileBytes(ctx, path) -} - -// IfModifiedSince returns true if lastModified exceeds 'If-Modified-Since' -// value from the request header. -// -// The function returns true also 'If-Modified-Since' request header is missing. -func (ctx *RequestCtx) IfModifiedSince(lastModified time.Time) bool { - ifModStr := ctx.Request.Header.peek(strIfModifiedSince) - if len(ifModStr) == 0 { - return true - } - ifMod, err := ParseHTTPDate(ifModStr) - if err != nil { - return true - } - lastModified = lastModified.Truncate(time.Second) - return ifMod.Before(lastModified) -} - -// NotModified resets response and sets '304 Not Modified' response status code. -func (ctx *RequestCtx) NotModified() { - ctx.Response.Reset() - ctx.SetStatusCode(StatusNotModified) -} - -// NotFound resets response and sets '404 Not Found' response status code. -func (ctx *RequestCtx) NotFound() { - ctx.Response.Reset() - ctx.SetStatusCode(StatusNotFound) - ctx.SetBodyString("404 Page not found") -} - -// Write writes p into response body. -func (ctx *RequestCtx) Write(p []byte) (int, error) { - ctx.Response.AppendBody(p) - return len(p), nil -} - -// WriteString appends s to response body. -func (ctx *RequestCtx) WriteString(s string) (int, error) { - ctx.Response.AppendBodyString(s) - return len(s), nil -} - -// PostBody returns POST request body. -// -// The returned value is valid until RequestHandler return. -func (ctx *RequestCtx) PostBody() []byte { - return ctx.Request.Body() -} - -// SetBodyStream sets response body stream and, optionally body size. -// -// bodyStream.Close() is called after finishing reading all body data -// if it implements io.Closer. -// -// If bodySize is >= 0, then bodySize bytes must be provided by bodyStream -// before returning io.EOF. -// -// If bodySize < 0, then bodyStream is read until io.EOF. -// -// See also SetBodyStreamWriter. -func (ctx *RequestCtx) SetBodyStream(bodyStream io.Reader, bodySize int) { - ctx.Response.SetBodyStream(bodyStream, bodySize) -} - -// SetBodyStreamWriter registers the given stream writer for populating -// response body. -// -// Access to RequestCtx and/or its' members is forbidden from sw. -// -// This function may be used in the following cases: -// -// * if response body is too big (more than 10MB). -// * if response body is streamed from slow external sources. -// * if response body must be streamed to the client in chunks. -// (aka `http server push`). -func (ctx *RequestCtx) SetBodyStreamWriter(sw StreamWriter) { - ctx.Response.SetBodyStreamWriter(sw) -} - -// IsBodyStream returns true if response body is set via SetBodyStream*. -func (ctx *RequestCtx) IsBodyStream() bool { - return ctx.Response.IsBodyStream() -} - -// Logger returns logger, which may be used for logging arbitrary -// request-specific messages inside RequestHandler. -// -// Each message logged via returned logger contains request-specific information -// such as request id, request duration, local address, remote address, -// request method and request url. -// -// It is safe re-using returned logger for logging multiple messages -// for the current request. -// -// The returned logger is valid until returning from RequestHandler. -func (ctx *RequestCtx) Logger() Logger { - if ctx.logger.ctx == nil { - ctx.logger.ctx = ctx - } - if ctx.logger.logger == nil { - ctx.logger.logger = ctx.s.logger() - } - return &ctx.logger -} - -// TimeoutError sets response status code to StatusRequestTimeout and sets -// body to the given msg. -// -// All response modifications after TimeoutError call are ignored. -// -// TimeoutError MUST be called before returning from RequestHandler if there are -// references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutError(msg string) { - ctx.TimeoutErrorWithCode(msg, StatusRequestTimeout) -} - -// TimeoutErrorWithCode sets response body to msg and response status -// code to statusCode. -// -// All response modifications after TimeoutErrorWithCode call are ignored. -// -// TimeoutErrorWithCode MUST be called before returning from RequestHandler -// if there are references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutErrorWithCode(msg string, statusCode int) { - var resp Response - resp.SetStatusCode(statusCode) - resp.SetBodyString(msg) - ctx.TimeoutErrorWithResponse(&resp) -} - -// TimeoutErrorWithResponse marks the ctx as timed out and sends the given -// response to the client. -// -// All ctx modifications after TimeoutErrorWithResponse call are ignored. -// -// TimeoutErrorWithResponse MUST be called before returning from RequestHandler -// if there are references to ctx and/or its members in other goroutines remain. -// -// Usage of this function is discouraged. Prefer eliminating ctx references -// from pending goroutines instead of using this function. -func (ctx *RequestCtx) TimeoutErrorWithResponse(resp *Response) { - respCopy := &Response{} - resp.CopyTo(respCopy) - ctx.timeoutResponse = respCopy -} - -// ListenAndServe serves HTTP requests from the given TCP4 addr. -// -// Pass custom listener to Serve if you need listening on non-TCP4 media -// such as IPv6. -func (s *Server) ListenAndServe(addr string) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.Serve(ln) -} - -// ListenAndServeUNIX serves HTTP requests from the given UNIX addr. -// -// The function deletes existing file at addr before starting serving. -// -// The server sets the given file mode for the UNIX addr. -func (s *Server) ListenAndServeUNIX(addr string, mode os.FileMode) error { - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("unexpected error when trying to remove unix socket file %q: %s", addr, err) - } - ln, err := net.Listen("unix", addr) - if err != nil { - return err - } - if err = os.Chmod(addr, mode); err != nil { - return fmt.Errorf("cannot chmod %#o for %q: %s", mode, addr, err) - } - return s.Serve(ln) -} - -// ListenAndServeTLS serves HTTPS requests from the given TCP4 addr. -// -// certFile and keyFile are paths to TLS certificate and key files. -// -// Pass custom listener to Serve if you need listening on non-TCP4 media -// such as IPv6. -func (s *Server) ListenAndServeTLS(addr, certFile, keyFile string) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.ServeTLS(ln, certFile, keyFile) -} - -// ListenAndServeTLSEmbed serves HTTPS requests from the given TCP4 addr. -// -// certData and keyData must contain valid TLS certificate and key data. -// -// Pass custom listener to Serve if you need listening on arbitrary media -// such as IPv6. -func (s *Server) ListenAndServeTLSEmbed(addr string, certData, keyData []byte) error { - ln, err := net.Listen("tcp4", addr) - if err != nil { - return err - } - return s.ServeTLSEmbed(ln, certData, keyData) -} - -// ServeTLS serves HTTPS requests from the given listener. -// -// certFile and keyFile are paths to TLS certificate and key files. -func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error { - lnTLS, err := newTLSListener(ln, certFile, keyFile) - if err != nil { - return err - } - return s.Serve(lnTLS) -} - -// ServeTLSEmbed serves HTTPS requests from the given listener. -// -// certData and keyData must contain valid TLS certificate and key data. -func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error { - lnTLS, err := newTLSListenerEmbed(ln, certData, keyData) - if err != nil { - return err - } - return s.Serve(lnTLS) -} - -func newTLSListener(ln net.Listener, certFile, keyFile string) (net.Listener, error) { - cert, err := tls.LoadX509KeyPair(certFile, keyFile) - if err != nil { - return nil, fmt.Errorf("cannot load TLS key pair from certFile=%q and keyFile=%q: %s", certFile, keyFile, err) - } - return newCertListener(ln, &cert), nil -} - -func newTLSListenerEmbed(ln net.Listener, certData, keyData []byte) (net.Listener, error) { - cert, err := tls.X509KeyPair(certData, keyData) - if err != nil { - return nil, fmt.Errorf("cannot load TLS key pair from the provided certData(%d) and keyData(%d): %s", - len(certData), len(keyData), err) - } - return newCertListener(ln, &cert), nil -} - -func newCertListener(ln net.Listener, cert *tls.Certificate) net.Listener { - tlsConfig := &tls.Config{ - Certificates: []tls.Certificate{*cert}, - PreferServerCipherSuites: true, - } - return tls.NewListener(ln, tlsConfig) -} - -// DefaultConcurrency is the maximum number of concurrent connections -// the Server may serve by default (i.e. if Server.Concurrency isn't set). -const DefaultConcurrency = 256 * 1024 - -// Serve serves incoming connections from the given listener. -// -// Serve blocks until the given listener returns permanent error. -func (s *Server) Serve(ln net.Listener) error { - var lastOverflowErrorTime time.Time - var lastPerIPErrorTime time.Time - var c net.Conn - var err error - - maxWorkersCount := s.getConcurrency() - s.concurrencyCh = make(chan struct{}, maxWorkersCount) - wp := &workerPool{ - WorkerFunc: s.serveConn, - MaxWorkersCount: maxWorkersCount, - LogAllErrors: s.LogAllErrors, - Logger: s.logger(), - } - wp.Start() - - for { - if c, err = acceptConn(s, ln, &lastPerIPErrorTime); err != nil { - wp.Stop() - if err == io.EOF { - return nil - } - return err - } - if !wp.Serve(c) { - s.writeFastError(c, StatusServiceUnavailable, - "The connection cannot be served because Server.Concurrency limit exceeded") - c.Close() - if time.Since(lastOverflowErrorTime) > time.Minute { - s.logger().Printf("The incoming connection cannot be served, because %d concurrent connections are served. "+ - "Try increasing Server.Concurrency", maxWorkersCount) - lastOverflowErrorTime = time.Now() - } - - // The current server reached concurrency limit, - // so give other concurrently running servers a chance - // accepting incoming connections on the same address. - // - // There is a hope other servers didn't reach their - // concurrency limits yet :) - time.Sleep(100 * time.Millisecond) - } - c = nil - } -} - -func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.Conn, error) { - for { - c, err := ln.Accept() - if err != nil { - if c != nil { - panic("BUG: net.Listener returned non-nil conn and non-nil error") - } - if netErr, ok := err.(net.Error); ok && netErr.Temporary() { - s.logger().Printf("Temporary error when accepting new connections: %s", netErr) - time.Sleep(time.Second) - continue - } - if err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") { - s.logger().Printf("Permanent error when accepting new connections: %s", err) - return nil, err - } - return nil, io.EOF - } - if c == nil { - panic("BUG: net.Listener returned (nil, nil)") - } - if s.MaxConnsPerIP > 0 { - pic := wrapPerIPConn(s, c) - if pic == nil { - if time.Since(*lastPerIPErrorTime) > time.Minute { - s.logger().Printf("The number of connections from %s exceeds MaxConnsPerIP=%d", - getConnIP4(c), s.MaxConnsPerIP) - *lastPerIPErrorTime = time.Now() - } - continue - } - c = pic - } - return c, nil - } -} - -func wrapPerIPConn(s *Server, c net.Conn) net.Conn { - ip := getUint32IP(c) - if ip == 0 { - return c - } - n := s.perIPConnCounter.Register(ip) - if n > s.MaxConnsPerIP { - s.perIPConnCounter.Unregister(ip) - s.writeFastError(c, StatusTooManyRequests, "The number of connections from your ip exceeds MaxConnsPerIP") - c.Close() - return nil - } - return acquirePerIPConn(c, ip, &s.perIPConnCounter) -} - -var defaultLogger = Logger(log.New(os.Stderr, "", log.LstdFlags)) - -func (s *Server) logger() Logger { - if s.Logger != nil { - return s.Logger - } - return defaultLogger -} - -var ( - // ErrPerIPConnLimit may be returned from ServeConn if the number of connections - // per ip exceeds Server.MaxConnsPerIP. - ErrPerIPConnLimit = errors.New("too many connections per ip") - - // ErrConcurrencyLimit may be returned from ServeConn if the number - // of concurrently served connections exceeds Server.Concurrency. - ErrConcurrencyLimit = errors.New("cannot serve the connection because Server.Concurrency concurrent connections are served") - - // ErrKeepaliveTimeout is returned from ServeConn - // if the connection lifetime exceeds MaxKeepaliveDuration. - ErrKeepaliveTimeout = errors.New("exceeded MaxKeepaliveDuration") -) - -// ServeConn serves HTTP requests from the given connection. -// -// ServeConn returns nil if all requests from the c are successfully served. -// It returns non-nil error otherwise. -// -// Connection c must immediately propagate all the data passed to Write() -// to the client. Otherwise requests' processing may hang. -// -// ServeConn closes c before returning. -func (s *Server) ServeConn(c net.Conn) error { - if s.MaxConnsPerIP > 0 { - pic := wrapPerIPConn(s, c) - if pic == nil { - return ErrPerIPConnLimit - } - c = pic - } - - n := atomic.AddUint32(&s.concurrency, 1) - if n > uint32(s.getConcurrency()) { - atomic.AddUint32(&s.concurrency, ^uint32(0)) - s.writeFastError(c, StatusServiceUnavailable, "The connection cannot be served because Server.Concurrency limit exceeded") - c.Close() - return ErrConcurrencyLimit - } - - err := s.serveConn(c) - - atomic.AddUint32(&s.concurrency, ^uint32(0)) - - if err != errHijacked { - err1 := c.Close() - if err == nil { - err = err1 - } - } else { - err = nil - } - return err -} - -var errHijacked = errors.New("connection has been hijacked") - -func (s *Server) getConcurrency() int { - n := s.Concurrency - if n <= 0 { - n = DefaultConcurrency - } - return n -} - -var globalConnID uint64 - -func nextConnID() uint64 { - return atomic.AddUint64(&globalConnID, 1) -} - -// DefaultMaxRequestBodySize is the maximum request body size the server -// reads by default. -// -// See Server.MaxRequestBodySize for details. -const DefaultMaxRequestBodySize = 4 * 1024 * 1024 - -func (s *Server) serveConn(c net.Conn) error { - serverName := s.getServerName() - connRequestNum := uint64(0) - connID := nextConnID() - currentTime := time.Now() - connTime := currentTime - maxRequestBodySize := s.MaxRequestBodySize - if maxRequestBodySize <= 0 { - maxRequestBodySize = DefaultMaxRequestBodySize - } - - ctx := s.acquireCtx(c) - ctx.connTime = connTime - isTLS := ctx.IsTLS() - var ( - br *bufio.Reader - bw *bufio.Writer - - err error - timeoutResponse *Response - hijackHandler HijackHandler - - lastReadDeadlineTime time.Time - lastWriteDeadlineTime time.Time - - connectionClose bool - isHTTP11 bool - ) - for { - connRequestNum++ - ctx.time = currentTime - - if s.ReadTimeout > 0 || s.MaxKeepaliveDuration > 0 { - lastReadDeadlineTime = s.updateReadDeadline(c, ctx, lastReadDeadlineTime) - if lastReadDeadlineTime.IsZero() { - err = ErrKeepaliveTimeout - break - } - } - - if !(s.ReduceMemoryUsage || ctx.lastReadDuration > time.Second) || br != nil { - if br == nil { - br = acquireReader(ctx) - } - } else { - br, err = acquireByteReader(&ctx) - } - ctx.Request.isTLS = isTLS - - if err == nil { - if s.DisableHeaderNamesNormalizing { - ctx.Request.Header.DisableNormalizing() - ctx.Response.Header.DisableNormalizing() - } - err = ctx.Request.readLimitBody(br, maxRequestBodySize, s.GetOnly) - if br.Buffered() == 0 || err != nil { - releaseReader(s, br) - br = nil - } - } - - currentTime = time.Now() - ctx.lastReadDuration = currentTime.Sub(ctx.time) - - if err != nil { - if err == io.EOF { - err = nil - } else { - bw = writeErrorResponse(bw, ctx, err) - } - break - } - - // 'Expect: 100-continue' request handling. - // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html for details. - if !ctx.Request.Header.noBody() && ctx.Request.MayContinue() { - // Send 'HTTP/1.1 100 Continue' response. - if bw == nil { - bw = acquireWriter(ctx) - } - bw.Write(strResponseContinue) - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - - // Read request body. - if br == nil { - br = acquireReader(ctx) - } - err = ctx.Request.ContinueReadBody(br, maxRequestBodySize) - if br.Buffered() == 0 || err != nil { - releaseReader(s, br) - br = nil - } - if err != nil { - bw = writeErrorResponse(bw, ctx, err) - break - } - } - - connectionClose = s.DisableKeepalive || ctx.Request.Header.connectionCloseFast() - isHTTP11 = ctx.Request.Header.IsHTTP11() - - ctx.Response.Header.SetServerBytes(serverName) - ctx.connID = connID - ctx.connRequestNum = connRequestNum - ctx.connTime = connTime - ctx.time = currentTime - s.Handler(ctx) - - timeoutResponse = ctx.timeoutResponse - if timeoutResponse != nil { - ctx = s.acquireCtx(c) - timeoutResponse.CopyTo(&ctx.Response) - if br != nil { - // Close connection, since br may be attached to the old ctx via ctx.fbr. - ctx.SetConnectionClose() - } - } - - if !ctx.IsGet() && ctx.IsHead() { - ctx.Response.SkipBody = true - } - ctx.Request.Reset() - - hijackHandler = ctx.hijackHandler - ctx.hijackHandler = nil - - ctx.userValues.Reset() - - if s.MaxRequestsPerConn > 0 && connRequestNum >= uint64(s.MaxRequestsPerConn) { - ctx.SetConnectionClose() - } - - if s.WriteTimeout > 0 || s.MaxKeepaliveDuration > 0 { - lastWriteDeadlineTime = s.updateWriteDeadline(c, ctx, lastWriteDeadlineTime) - } - - // Verify Request.Header.connectionCloseFast() again, - // since request handler might trigger full headers' parsing. - connectionClose = connectionClose || ctx.Request.Header.connectionCloseFast() || ctx.Response.ConnectionClose() - if connectionClose { - ctx.Response.Header.SetCanonical(strConnection, strClose) - } else if !isHTTP11 { - // Set 'Connection: keep-alive' response header for non-HTTP/1.1 request. - // There is no need in setting this header for http/1.1, since in http/1.1 - // connections are keep-alive by default. - ctx.Response.Header.SetCanonical(strConnection, strKeepAlive) - } - - if len(ctx.Response.Header.Server()) == 0 { - ctx.Response.Header.SetServerBytes(serverName) - } - - if bw == nil { - bw = acquireWriter(ctx) - } - if err = writeResponse(ctx, bw); err != nil { - break - } - - if br == nil || connectionClose { - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - if connectionClose { - break - } - } - - if hijackHandler != nil { - var hjr io.Reader - hjr = c - if br != nil { - hjr = br - br = nil - - // br may point to ctx.fbr, so do not return ctx into pool. - ctx = s.acquireCtx(c) - } - if bw != nil { - err = bw.Flush() - releaseWriter(s, bw) - bw = nil - if err != nil { - break - } - } - c.SetReadDeadline(zeroTime) - c.SetWriteDeadline(zeroTime) - go hijackConnHandler(hjr, c, s, hijackHandler) - hijackHandler = nil - err = errHijacked - break - } - - currentTime = time.Now() - } - - if br != nil { - releaseReader(s, br) - } - if bw != nil { - releaseWriter(s, bw) - } - s.releaseCtx(ctx) - return err -} - -func (s *Server) updateReadDeadline(c net.Conn, ctx *RequestCtx, lastDeadlineTime time.Time) time.Time { - readTimeout := s.ReadTimeout - currentTime := ctx.time - if s.MaxKeepaliveDuration > 0 { - connTimeout := s.MaxKeepaliveDuration - currentTime.Sub(ctx.connTime) - if connTimeout <= 0 { - return zeroTime - } - if connTimeout < readTimeout { - readTimeout = connTimeout - } - } - - // Optimization: update read deadline only if more than 25% - // of the last read deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. - if currentTime.Sub(lastDeadlineTime) > (readTimeout >> 2) { - if err := c.SetReadDeadline(currentTime.Add(readTimeout)); err != nil { - panic(fmt.Sprintf("BUG: error in SetReadDeadline(%s): %s", readTimeout, err)) - } - lastDeadlineTime = currentTime - } - return lastDeadlineTime -} - -func (s *Server) updateWriteDeadline(c net.Conn, ctx *RequestCtx, lastDeadlineTime time.Time) time.Time { - writeTimeout := s.WriteTimeout - if s.MaxKeepaliveDuration > 0 { - connTimeout := s.MaxKeepaliveDuration - time.Since(ctx.connTime) - if connTimeout <= 0 { - // MaxKeepAliveDuration exceeded, but let's try sending response anyway - // in 100ms with 'Connection: close' header. - ctx.SetConnectionClose() - connTimeout = 100 * time.Millisecond - } - if connTimeout < writeTimeout { - writeTimeout = connTimeout - } - } - - // Optimization: update write deadline only if more than 25% - // of the last write deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. - currentTime := time.Now() - if currentTime.Sub(lastDeadlineTime) > (writeTimeout >> 2) { - if err := c.SetWriteDeadline(currentTime.Add(writeTimeout)); err != nil { - panic(fmt.Sprintf("BUG: error in SetWriteDeadline(%s): %s", writeTimeout, err)) - } - lastDeadlineTime = currentTime - } - return lastDeadlineTime -} - -func hijackConnHandler(r io.Reader, c net.Conn, s *Server, h HijackHandler) { - hjc := s.acquireHijackConn(r, c) - h(hjc) - - if br, ok := r.(*bufio.Reader); ok { - releaseReader(s, br) - } - c.Close() - s.releaseHijackConn(hjc) -} - -func (s *Server) acquireHijackConn(r io.Reader, c net.Conn) *hijackConn { - v := s.hijackConnPool.Get() - if v == nil { - hjc := &hijackConn{ - Conn: c, - r: r, - } - return hjc - } - hjc := v.(*hijackConn) - hjc.Conn = c - hjc.r = r - return hjc -} - -func (s *Server) releaseHijackConn(hjc *hijackConn) { - hjc.Conn = nil - hjc.r = nil - s.hijackConnPool.Put(hjc) -} - -type hijackConn struct { - net.Conn - r io.Reader -} - -func (c hijackConn) Read(p []byte) (int, error) { - return c.r.Read(p) -} - -func (c hijackConn) Close() error { - // hijacked conn is closed in hijackConnHandler. - return nil -} - -// LastTimeoutErrorResponse returns the last timeout response set -// via TimeoutError* call. -// -// This function is intended for custom server implementations. -func (ctx *RequestCtx) LastTimeoutErrorResponse() *Response { - return ctx.timeoutResponse -} - -func writeResponse(ctx *RequestCtx, w *bufio.Writer) error { - if ctx.timeoutResponse != nil { - panic("BUG: cannot write timed out response") - } - err := ctx.Response.Write(w) - ctx.Response.Reset() - return err -} - -const ( - defaultReadBufferSize = 4096 - defaultWriteBufferSize = 4096 -) - -func acquireByteReader(ctxP **RequestCtx) (*bufio.Reader, error) { - ctx := *ctxP - s := ctx.s - c := ctx.c - t := ctx.time - s.releaseCtx(ctx) - - // Make GC happy, so it could garbage collect ctx - // while we waiting for the next request. - ctx = nil - *ctxP = nil - - v := s.bytePool.Get() - if v == nil { - v = make([]byte, 1) - } - b := v.([]byte) - n, err := c.Read(b) - ch := b[0] - s.bytePool.Put(v) - ctx = s.acquireCtx(c) - ctx.time = t - *ctxP = ctx - if err != nil { - // Treat all errors as EOF on unsuccessful read - // of the first request byte. - return nil, io.EOF - } - if n != 1 { - panic("BUG: Reader must return at least one byte") - } - - ctx.fbr.c = c - ctx.fbr.ch = ch - ctx.fbr.byteRead = false - r := acquireReader(ctx) - r.Reset(&ctx.fbr) - return r, nil -} - -func acquireReader(ctx *RequestCtx) *bufio.Reader { - v := ctx.s.readerPool.Get() - if v == nil { - n := ctx.s.ReadBufferSize - if n <= 0 { - n = defaultReadBufferSize - } - return bufio.NewReaderSize(ctx.c, n) - } - r := v.(*bufio.Reader) - r.Reset(ctx.c) - return r -} - -func releaseReader(s *Server, r *bufio.Reader) { - s.readerPool.Put(r) -} - -func acquireWriter(ctx *RequestCtx) *bufio.Writer { - v := ctx.s.writerPool.Get() - if v == nil { - n := ctx.s.WriteBufferSize - if n <= 0 { - n = defaultWriteBufferSize - } - return bufio.NewWriterSize(ctx.c, n) - } - w := v.(*bufio.Writer) - w.Reset(ctx.c) - return w -} - -func releaseWriter(s *Server, w *bufio.Writer) { - s.writerPool.Put(w) -} - -func (s *Server) acquireCtx(c net.Conn) *RequestCtx { - v := s.ctxPool.Get() - var ctx *RequestCtx - if v == nil { - ctx = &RequestCtx{ - s: s, - } - keepBodyBuffer := !s.ReduceMemoryUsage - ctx.Request.keepBodyBuffer = keepBodyBuffer - ctx.Response.keepBodyBuffer = keepBodyBuffer - } else { - ctx = v.(*RequestCtx) - } - ctx.c = c - return ctx -} - -// Init2 prepares ctx for passing to RequestHandler. -// -// conn is used only for determining local and remote addresses. -// -// This function is intended for custom Server implementations. -// See https://github.com/valyala/httpteleport for details. -func (ctx *RequestCtx) Init2(conn net.Conn, logger Logger, reduceMemoryUsage bool) { - ctx.c = conn - ctx.logger.logger = logger - ctx.connID = nextConnID() - ctx.s = fakeServer - ctx.connRequestNum = 0 - ctx.connTime = time.Now() - ctx.time = ctx.connTime - - keepBodyBuffer := !reduceMemoryUsage - ctx.Request.keepBodyBuffer = keepBodyBuffer - ctx.Response.keepBodyBuffer = keepBodyBuffer -} - -// Init prepares ctx for passing to RequestHandler. -// -// remoteAddr and logger are optional. They are used by RequestCtx.Logger(). -// -// This function is intended for custom Server implementations. -func (ctx *RequestCtx) Init(req *Request, remoteAddr net.Addr, logger Logger) { - if remoteAddr == nil { - remoteAddr = zeroTCPAddr - } - c := &fakeAddrer{ - laddr: zeroTCPAddr, - raddr: remoteAddr, - } - if logger == nil { - logger = defaultLogger - } - ctx.Init2(c, logger, true) - req.CopyTo(&ctx.Request) -} - -var fakeServer = &Server{ - // Initialize concurrencyCh for TimeoutHandler - concurrencyCh: make(chan struct{}, DefaultConcurrency), -} - -type fakeAddrer struct { - net.Conn - laddr net.Addr - raddr net.Addr -} - -func (fa *fakeAddrer) RemoteAddr() net.Addr { - return fa.raddr -} - -func (fa *fakeAddrer) LocalAddr() net.Addr { - return fa.laddr -} - -func (fa *fakeAddrer) Read(p []byte) (int, error) { - panic("BUG: unexpected Read call") -} - -func (fa *fakeAddrer) Write(p []byte) (int, error) { - panic("BUG: unexpected Write call") -} - -func (fa *fakeAddrer) Close() error { - panic("BUG: unexpected Close call") -} - -func (s *Server) releaseCtx(ctx *RequestCtx) { - if ctx.timeoutResponse != nil { - panic("BUG: cannot release timed out RequestCtx") - } - ctx.c = nil - ctx.fbr.c = nil - s.ctxPool.Put(ctx) -} - -func (s *Server) getServerName() []byte { - v := s.serverName.Load() - var serverName []byte - if v == nil { - serverName = []byte(s.Name) - if len(serverName) == 0 { - serverName = defaultServerName - } - s.serverName.Store(serverName) - } else { - serverName = v.([]byte) - } - return serverName -} - -func (s *Server) writeFastError(w io.Writer, statusCode int, msg string) { - w.Write(statusLine(statusCode)) - fmt.Fprintf(w, "Connection: close\r\n"+ - "Server: %s\r\n"+ - "Date: %s\r\n"+ - "Content-Type: text/plain\r\n"+ - "Content-Length: %d\r\n"+ - "\r\n"+ - "%s", - s.getServerName(), serverDate.Load(), len(msg), msg) -} - -func writeErrorResponse(bw *bufio.Writer, ctx *RequestCtx, err error) *bufio.Writer { - if _, ok := err.(*ErrSmallBuffer); ok { - ctx.Error("Too big request header", StatusRequestHeaderFieldsTooLarge) - } else { - ctx.Error("Error when parsing request", StatusBadRequest) - } - ctx.SetConnectionClose() - if bw == nil { - bw = acquireWriter(ctx) - } - writeResponse(ctx, bw) - bw.Flush() - return bw -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key deleted file mode 100644 index 00a79a3b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD4IQusAs8PJdnG -3mURt/AXtgC+ceqLOatJ49JJE1VPTkMAy+oE1f1XvkMrYsHqmDf6GWVzgVXryL4U -wq2/nJSm56ddhN55nI8oSN3dtywUB8/ShelEN73nlN77PeD9tl6NksPwWaKrqxq0 -FlabRPZSQCfmgZbhDV8Sa8mfCkFU0G0lit6kLGceCKMvmW+9Bz7ebsYmVdmVMxmf -IJStFD44lWFTdUc65WISKEdW2ELcUefb0zOLw+0PCbXFGJH5x5ktksW8+BBk2Hkg -GeQRL/qPCccthbScO0VgNj3zJ3ZZL0ObSDAbvNDG85joeNjDNq5DT/BAZ0bOSbEF -sh+f9BAzAgMBAAECggEBAJWv2cq7Jw6MVwSRxYca38xuD6TUNBopgBvjREixURW2 -sNUaLuMb9Omp7fuOaE2N5rcJ+xnjPGIxh/oeN5MQctz9gwn3zf6vY+15h97pUb4D -uGvYPRDaT8YVGS+X9NMZ4ZCmqW2lpWzKnCFoGHcy8yZLbcaxBsRdvKzwOYGoPiFb -K2QuhXZ/1UPmqK9i2DFKtj40X6vBszTNboFxOVpXrPu0FJwLVSDf2hSZ4fMM0DH3 -YqwKcYf5te+hxGKgrqRA3tn0NCWii0in6QIwXMC+kMw1ebg/tZKqyDLMNptAK8J+ -DVw9m5X1seUHS5ehU/g2jrQrtK5WYn7MrFK4lBzlRwECgYEA/d1TeANYECDWRRDk -B0aaRZs87Rwl/J9PsvbsKvtU/bX+OfSOUjOa9iQBqn0LmU8GqusEET/QVUfocVwV -Bggf/5qDLxz100Rj0ags/yE/kNr0Bb31kkkKHFMnCT06YasR7qKllwrAlPJvQv9x -IzBKq+T/Dx08Wep9bCRSFhzRCnsCgYEA+jdeZXTDr/Vz+D2B3nAw1frqYFfGnEVY -wqmoK3VXMDkGuxsloO2rN+SyiUo3JNiQNPDub/t7175GH5pmKtZOlftePANsUjBj -wZ1D0rI5Bxu/71ibIUYIRVmXsTEQkh/ozoh3jXCZ9+bLgYiYx7789IUZZSokFQ3D -FICUT9KJ36kCgYAGoq9Y1rWJjmIrYfqj2guUQC+CfxbbGIrrwZqAsRsSmpwvhZ3m -tiSZxG0quKQB+NfSxdvQW5ulbwC7Xc3K35F+i9pb8+TVBdeaFkw+yu6vaZmxQLrX -fQM/pEjD7A7HmMIaO7QaU5SfEAsqdCTP56Y8AftMuNXn/8IRfo2KuGwaWwKBgFpU -ILzJoVdlad9E/Rw7LjYhZfkv1uBVXIyxyKcfrkEXZSmozDXDdxsvcZCEfVHM6Ipk -K/+7LuMcqp4AFEAEq8wTOdq6daFaHLkpt/FZK6M4TlruhtpFOPkoNc3e45eM83OT -6mziKINJC1CQ6m65sQHpBtjxlKMRG8rL/D6wx9s5AoGBAMRlqNPMwglT3hvDmsAt -9Lf9pdmhERUlHhD8bj8mDaBj2Aqv7f6VRJaYZqP403pKKQexuqcn80mtjkSAPFkN -Cj7BVt/RXm5uoxDTnfi26RF9F6yNDEJ7UU9+peBr99aazF/fTgW/1GcMkQnum8uV -c257YgaWmjK9uB0Y2r2VxS0G ------END PRIVATE KEY----- diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem deleted file mode 100644 index 93e77cd9..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICujCCAaKgAwIBAgIJAMbXnKZ/cikUMA0GCSqGSIb3DQEBCwUAMBUxEzARBgNV -BAMTCnVidW50dS5uYW4wHhcNMTUwMjA0MDgwMTM5WhcNMjUwMjAxMDgwMTM5WjAV -MRMwEQYDVQQDEwp1YnVudHUubmFuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEA+CELrALPDyXZxt5lEbfwF7YAvnHqizmrSePSSRNVT05DAMvqBNX9V75D -K2LB6pg3+hllc4FV68i+FMKtv5yUpuenXYTeeZyPKEjd3bcsFAfP0oXpRDe955Te -+z3g/bZejZLD8Fmiq6satBZWm0T2UkAn5oGW4Q1fEmvJnwpBVNBtJYrepCxnHgij -L5lvvQc+3m7GJlXZlTMZnyCUrRQ+OJVhU3VHOuViEihHVthC3FHn29Mzi8PtDwm1 -xRiR+ceZLZLFvPgQZNh5IBnkES/6jwnHLYW0nDtFYDY98yd2WS9Dm0gwG7zQxvOY -6HjYwzauQ0/wQGdGzkmxBbIfn/QQMwIDAQABow0wCzAJBgNVHRMEAjAAMA0GCSqG -SIb3DQEBCwUAA4IBAQBQjKm/4KN/iTgXbLTL3i7zaxYXFLXsnT1tF+ay4VA8aj98 -L3JwRTciZ3A5iy/W4VSCt3eASwOaPWHKqDBB5RTtL73LoAqsWmO3APOGQAbixcQ2 -45GXi05OKeyiYRi1Nvq7Unv9jUkRDHUYVPZVSAjCpsXzPhFkmZoTRxmx5l0ZF7Li -K91lI5h+eFq0dwZwrmlPambyh1vQUi70VHv8DNToVU29kel7YLbxGbuqETfhrcy6 -X+Mha6RYITkAn5FqsZcKMsc9eYGEF4l3XV+oS7q6xfTxktYJMFTI18J0lQ2Lv/CI -whdMnYGntDQBE/iFCrJEGNsKGc38796GBOb5j+zd ------END CERTIFICATE----- diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/doc.go deleted file mode 100644 index 8c0cc497..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package stackless provides functionality that may save stack space -// for high number of concurrently running goroutines. -package stackless diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/func.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/func.go deleted file mode 100644 index 9a49bcc2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/func.go +++ /dev/null @@ -1,79 +0,0 @@ -package stackless - -import ( - "runtime" - "sync" -) - -// NewFunc returns stackless wrapper for the function f. -// -// Unlike f, the returned stackless wrapper doesn't use stack space -// on the goroutine that calls it. -// The wrapper may save a lot of stack space if the following conditions -// are met: -// -// - f doesn't contain blocking calls on network, I/O or channels; -// - f uses a lot of stack space; -// - the wrapper is called from high number of concurrent goroutines. -// -// The stackless wrapper returns false if the call cannot be processed -// at the moment due to high load. -func NewFunc(f func(ctx interface{})) func(ctx interface{}) bool { - if f == nil { - panic("BUG: f cannot be nil") - } - - funcWorkCh := make(chan *funcWork, runtime.GOMAXPROCS(-1)*2048) - onceInit := func() { - n := runtime.GOMAXPROCS(-1) - for i := 0; i < n; i++ { - go funcWorker(funcWorkCh, f) - } - } - var once sync.Once - - return func(ctx interface{}) bool { - once.Do(onceInit) - fw := getFuncWork() - fw.ctx = ctx - - select { - case funcWorkCh <- fw: - default: - putFuncWork(fw) - return false - } - <-fw.done - putFuncWork(fw) - return true - } -} - -func funcWorker(funcWorkCh <-chan *funcWork, f func(ctx interface{})) { - for fw := range funcWorkCh { - f(fw.ctx) - fw.done <- struct{}{} - } -} - -func getFuncWork() *funcWork { - v := funcWorkPool.Get() - if v == nil { - v = &funcWork{ - done: make(chan struct{}, 1), - } - } - return v.(*funcWork) -} - -func putFuncWork(fw *funcWork) { - fw.ctx = nil - funcWorkPool.Put(fw) -} - -var funcWorkPool sync.Pool - -type funcWork struct { - ctx interface{} - done chan struct{} -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/writer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/writer.go deleted file mode 100644 index c2053f9a..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/writer.go +++ /dev/null @@ -1,139 +0,0 @@ -package stackless - -import ( - "errors" - "fmt" - "io" - - "github.com/valyala/bytebufferpool" -) - -// Writer is an interface stackless writer must conform to. -// -// The interface contains common subset for Writers from compress/* packages. -type Writer interface { - Write(p []byte) (int, error) - Flush() error - Close() error - Reset(w io.Writer) -} - -// NewWriterFunc must return new writer that will be wrapped into -// stackless writer. -type NewWriterFunc func(w io.Writer) Writer - -// NewWriter creates a stackless writer around a writer returned -// from newWriter. -// -// The returned writer writes data to dstW. -// -// Writers that use a lot of stack space may be wrapped into stackless writer, -// thus saving stack space for high number of concurrently running goroutines. -func NewWriter(dstW io.Writer, newWriter NewWriterFunc) Writer { - w := &writer{ - dstW: dstW, - } - w.zw = newWriter(&w.xw) - return w -} - -type writer struct { - dstW io.Writer - zw Writer - xw xWriter - - err error - n int - - p []byte - op op -} - -type op int - -const ( - opWrite op = iota - opFlush - opClose - opReset -) - -func (w *writer) Write(p []byte) (int, error) { - w.p = p - err := w.do(opWrite) - w.p = nil - return w.n, err -} - -func (w *writer) Flush() error { - return w.do(opFlush) -} - -func (w *writer) Close() error { - return w.do(opClose) -} - -func (w *writer) Reset(dstW io.Writer) { - w.xw.Reset() - w.do(opReset) - w.dstW = dstW -} - -func (w *writer) do(op op) error { - w.op = op - if !stacklessWriterFunc(w) { - return errHighLoad - } - err := w.err - if err != nil { - return err - } - if w.xw.bb != nil && len(w.xw.bb.B) > 0 { - _, err = w.dstW.Write(w.xw.bb.B) - } - w.xw.Reset() - - return err -} - -var errHighLoad = errors.New("cannot compress data due to high load") - -var stacklessWriterFunc = NewFunc(writerFunc) - -func writerFunc(ctx interface{}) { - w := ctx.(*writer) - switch w.op { - case opWrite: - w.n, w.err = w.zw.Write(w.p) - case opFlush: - w.err = w.zw.Flush() - case opClose: - w.err = w.zw.Close() - case opReset: - w.zw.Reset(&w.xw) - w.err = nil - default: - panic(fmt.Sprintf("BUG: unexpected op: %d", w.op)) - } -} - -type xWriter struct { - bb *bytebufferpool.ByteBuffer -} - -func (w *xWriter) Write(p []byte) (int, error) { - if w.bb == nil { - w.bb = bufferPool.Get() - } - w.bb.Write(p) - return len(p), nil -} - -func (w *xWriter) Reset() { - if w.bb != nil { - bufferPool.Put(w.bb) - w.bb = nil - } -} - -var bufferPool bytebufferpool.Pool diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/status.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/status.go deleted file mode 100644 index 6687efb4..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/status.go +++ /dev/null @@ -1,176 +0,0 @@ -package fasthttp - -import ( - "fmt" - "sync/atomic" -) - -// HTTP status codes were stolen from net/http. -const ( - StatusContinue = 100 // RFC 7231, 6.2.1 - StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 - StatusProcessing = 102 // RFC 2518, 10.1 - - StatusOK = 200 // RFC 7231, 6.3.1 - StatusCreated = 201 // RFC 7231, 6.3.2 - StatusAccepted = 202 // RFC 7231, 6.3.3 - StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4 - StatusNoContent = 204 // RFC 7231, 6.3.5 - StatusResetContent = 205 // RFC 7231, 6.3.6 - StatusPartialContent = 206 // RFC 7233, 4.1 - StatusMultiStatus = 207 // RFC 4918, 11.1 - StatusAlreadyReported = 208 // RFC 5842, 7.1 - StatusIMUsed = 226 // RFC 3229, 10.4.1 - - StatusMultipleChoices = 300 // RFC 7231, 6.4.1 - StatusMovedPermanently = 301 // RFC 7231, 6.4.2 - StatusFound = 302 // RFC 7231, 6.4.3 - StatusSeeOther = 303 // RFC 7231, 6.4.4 - StatusNotModified = 304 // RFC 7232, 4.1 - StatusUseProxy = 305 // RFC 7231, 6.4.5 - _ = 306 // RFC 7231, 6.4.6 (Unused) - StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 - StatusPermanentRedirect = 308 // RFC 7538, 3 - - StatusBadRequest = 400 // RFC 7231, 6.5.1 - StatusUnauthorized = 401 // RFC 7235, 3.1 - StatusPaymentRequired = 402 // RFC 7231, 6.5.2 - StatusForbidden = 403 // RFC 7231, 6.5.3 - StatusNotFound = 404 // RFC 7231, 6.5.4 - StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 - StatusNotAcceptable = 406 // RFC 7231, 6.5.6 - StatusProxyAuthRequired = 407 // RFC 7235, 3.2 - StatusRequestTimeout = 408 // RFC 7231, 6.5.7 - StatusConflict = 409 // RFC 7231, 6.5.8 - StatusGone = 410 // RFC 7231, 6.5.9 - StatusLengthRequired = 411 // RFC 7231, 6.5.10 - StatusPreconditionFailed = 412 // RFC 7232, 4.2 - StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 - StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 - StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 - StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 - StatusExpectationFailed = 417 // RFC 7231, 6.5.14 - StatusTeapot = 418 // RFC 7168, 2.3.3 - StatusUnprocessableEntity = 422 // RFC 4918, 11.2 - StatusLocked = 423 // RFC 4918, 11.3 - StatusFailedDependency = 424 // RFC 4918, 11.4 - StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 - StatusPreconditionRequired = 428 // RFC 6585, 3 - StatusTooManyRequests = 429 // RFC 6585, 4 - StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 - StatusUnavailableForLegalReasons = 451 // RFC 7725, 3 - - StatusInternalServerError = 500 // RFC 7231, 6.6.1 - StatusNotImplemented = 501 // RFC 7231, 6.6.2 - StatusBadGateway = 502 // RFC 7231, 6.6.3 - StatusServiceUnavailable = 503 // RFC 7231, 6.6.4 - StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 - StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 - StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 - StatusInsufficientStorage = 507 // RFC 4918, 11.5 - StatusLoopDetected = 508 // RFC 5842, 7.2 - StatusNotExtended = 510 // RFC 2774, 7 - StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 -) - -var ( - statusLines atomic.Value - - statusMessages = map[int]string{ - StatusContinue: "Continue", - StatusSwitchingProtocols: "Switching Protocols", - StatusProcessing: "Processing", - - StatusOK: "OK", - StatusCreated: "Created", - StatusAccepted: "Accepted", - StatusNonAuthoritativeInfo: "Non-Authoritative Information", - StatusNoContent: "No Content", - StatusResetContent: "Reset Content", - StatusPartialContent: "Partial Content", - StatusMultiStatus: "Multi-Status", - StatusAlreadyReported: "Already Reported", - StatusIMUsed: "IM Used", - - StatusMultipleChoices: "Multiple Choices", - StatusMovedPermanently: "Moved Permanently", - StatusFound: "Found", - StatusSeeOther: "See Other", - StatusNotModified: "Not Modified", - StatusUseProxy: "Use Proxy", - StatusTemporaryRedirect: "Temporary Redirect", - StatusPermanentRedirect: "Permanent Redirect", - - StatusBadRequest: "Bad Request", - StatusUnauthorized: "Unauthorized", - StatusPaymentRequired: "Payment Required", - StatusForbidden: "Forbidden", - StatusNotFound: "Not Found", - StatusMethodNotAllowed: "Method Not Allowed", - StatusNotAcceptable: "Not Acceptable", - StatusProxyAuthRequired: "Proxy Authentication Required", - StatusRequestTimeout: "Request Timeout", - StatusConflict: "Conflict", - StatusGone: "Gone", - StatusLengthRequired: "Length Required", - StatusPreconditionFailed: "Precondition Failed", - StatusRequestEntityTooLarge: "Request Entity Too Large", - StatusRequestURITooLong: "Request URI Too Long", - StatusUnsupportedMediaType: "Unsupported Media Type", - StatusRequestedRangeNotSatisfiable: "Requested Range Not Satisfiable", - StatusExpectationFailed: "Expectation Failed", - StatusTeapot: "I'm a teapot", - StatusUnprocessableEntity: "Unprocessable Entity", - StatusLocked: "Locked", - StatusFailedDependency: "Failed Dependency", - StatusUpgradeRequired: "Upgrade Required", - StatusPreconditionRequired: "Precondition Required", - StatusTooManyRequests: "Too Many Requests", - StatusRequestHeaderFieldsTooLarge: "Request Header Fields Too Large", - StatusUnavailableForLegalReasons: "Unavailable For Legal Reasons", - - StatusInternalServerError: "Internal Server Error", - StatusNotImplemented: "Not Implemented", - StatusBadGateway: "Bad Gateway", - StatusServiceUnavailable: "Service Unavailable", - StatusGatewayTimeout: "Gateway Timeout", - StatusHTTPVersionNotSupported: "HTTP Version Not Supported", - StatusVariantAlsoNegotiates: "Variant Also Negotiates", - StatusInsufficientStorage: "Insufficient Storage", - StatusLoopDetected: "Loop Detected", - StatusNotExtended: "Not Extended", - StatusNetworkAuthenticationRequired: "Network Authentication Required", - } -) - -// StatusMessage returns HTTP status message for the given status code. -func StatusMessage(statusCode int) string { - s := statusMessages[statusCode] - if s == "" { - s = "Unknown Status Code" - } - return s -} - -func init() { - statusLines.Store(make(map[int][]byte)) -} - -func statusLine(statusCode int) []byte { - m := statusLines.Load().(map[int][]byte) - h := m[statusCode] - if h != nil { - return h - } - - statusText := StatusMessage(statusCode) - - h = []byte(fmt.Sprintf("HTTP/1.1 %d %s\r\n", statusCode, statusText)) - newM := make(map[int][]byte, len(m)+1) - for k, v := range m { - newM[k] = v - } - newM[statusCode] = h - statusLines.Store(newM) - return h -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stream.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stream.go deleted file mode 100644 index aa23b1af..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stream.go +++ /dev/null @@ -1,54 +0,0 @@ -package fasthttp - -import ( - "bufio" - "io" - "sync" - - "github.com/valyala/fasthttp/fasthttputil" -) - -// StreamWriter must write data to w. -// -// Usually StreamWriter writes data to w in a loop (aka 'data streaming'). -// -// StreamWriter must return immediately if w returns error. -// -// Since the written data is buffered, do not forget calling w.Flush -// when the data must be propagated to reader. -type StreamWriter func(w *bufio.Writer) - -// NewStreamReader returns a reader, which replays all the data generated by sw. -// -// The returned reader may be passed to Response.SetBodyStream. -// -// Close must be called on the returned reader after all the required data -// has been read. Otherwise goroutine leak may occur. -// -// See also Response.SetBodyStreamWriter. -func NewStreamReader(sw StreamWriter) io.ReadCloser { - pc := fasthttputil.NewPipeConns() - pw := pc.Conn1() - pr := pc.Conn2() - - var bw *bufio.Writer - v := streamWriterBufPool.Get() - if v == nil { - bw = bufio.NewWriter(pw) - } else { - bw = v.(*bufio.Writer) - bw.Reset(pw) - } - - go func() { - sw(bw) - bw.Flush() - pw.Close() - - streamWriterBufPool.Put(bw) - }() - - return pr -} - -var streamWriterBufPool sync.Pool diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go deleted file mode 100644 index 7b7e53e3..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/strings.go +++ /dev/null @@ -1,77 +0,0 @@ -package fasthttp - -var ( - defaultServerName = []byte("fasthttp") - defaultUserAgent = []byte("fasthttp") - defaultContentType = []byte("text/plain; charset=utf-8") -) - -var ( - strSlash = []byte("/") - strSlashSlash = []byte("//") - strSlashDotDot = []byte("/..") - strSlashDotSlash = []byte("/./") - strSlashDotDotSlash = []byte("/../") - strCRLF = []byte("\r\n") - strHTTP = []byte("http") - strHTTPS = []byte("https") - strHTTP11 = []byte("HTTP/1.1") - strColonSlashSlash = []byte("://") - strColonSpace = []byte(": ") - strGMT = []byte("GMT") - - strResponseContinue = []byte("HTTP/1.1 100 Continue\r\n\r\n") - - strGet = []byte("GET") - strHead = []byte("HEAD") - strPost = []byte("POST") - strPut = []byte("PUT") - strDelete = []byte("DELETE") - strConnect = []byte("CONNECT") - strOptions = []byte("OPTIONS") - strTrace = []byte("TRACE") - strPatch = []byte("PATCH") - - strExpect = []byte("Expect") - strConnection = []byte("Connection") - strContentLength = []byte("Content-Length") - strContentType = []byte("Content-Type") - strDate = []byte("Date") - strHost = []byte("Host") - strReferer = []byte("Referer") - strServer = []byte("Server") - strTransferEncoding = []byte("Transfer-Encoding") - strContentEncoding = []byte("Content-Encoding") - strAcceptEncoding = []byte("Accept-Encoding") - strUserAgent = []byte("User-Agent") - strCookie = []byte("Cookie") - strSetCookie = []byte("Set-Cookie") - strLocation = []byte("Location") - strIfModifiedSince = []byte("If-Modified-Since") - strLastModified = []byte("Last-Modified") - strAcceptRanges = []byte("Accept-Ranges") - strRange = []byte("Range") - strContentRange = []byte("Content-Range") - - strCookieExpires = []byte("expires") - strCookieDomain = []byte("domain") - strCookiePath = []byte("path") - strCookieHTTPOnly = []byte("HttpOnly") - strCookieSecure = []byte("secure") - - strClose = []byte("close") - strGzip = []byte("gzip") - strDeflate = []byte("deflate") - strKeepAlive = []byte("keep-alive") - strKeepAliveCamelCase = []byte("Keep-Alive") - strUpgrade = []byte("Upgrade") - strChunked = []byte("chunked") - strIdentity = []byte("identity") - str100Continue = []byte("100-continue") - strPostArgsContentType = []byte("application/x-www-form-urlencoded") - strMultipartFormData = []byte("multipart/form-data") - strBoundary = []byte("boundary") - strBytes = []byte("bytes") - strTextSlash = []byte("text/") - strApplicationSlash = []byte("application/") -) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/tcpdialer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/tcpdialer.go deleted file mode 100644 index e31fd758..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/tcpdialer.go +++ /dev/null @@ -1,369 +0,0 @@ -package fasthttp - -import ( - "errors" - "net" - "strconv" - "sync" - "sync/atomic" - "time" -) - -// Dial dials the given TCP addr using tcp4. -// -// This function has the following additional features comparing to net.Dial: -// -// * It reduces load on DNS resolver by caching resolved TCP addressed -// for DefaultDNSCacheDuration. -// * It dials all the resolved TCP addresses in round-robin manner until -// connection is established. This may be useful if certain addresses -// are temporarily unreachable. -// * It returns ErrDialTimeout if connection cannot be established during -// DefaultDialTimeout seconds. Use DialTimeout for customizing dial timeout. -// -// This dialer is intended for custom code wrapping before passing -// to Client.Dial or HostClient.Dial. -// -// For instance, per-host counters and/or limits may be implemented -// by such wrappers. -// -// The addr passed to the function must contain port. Example addr values: -// -// * foobar.baz:443 -// * foo.bar:80 -// * aaa.com:8080 -func Dial(addr string) (net.Conn, error) { - return getDialer(DefaultDialTimeout, false)(addr) -} - -// DialTimeout dials the given TCP addr using tcp4 using the given timeout. -// -// This function has the following additional features comparing to net.Dial: -// -// * It reduces load on DNS resolver by caching resolved TCP addressed -// for DefaultDNSCacheDuration. -// * It dials all the resolved TCP addresses in round-robin manner until -// connection is established. This may be useful if certain addresses -// are temporarily unreachable. -// -// This dialer is intended for custom code wrapping before passing -// to Client.Dial or HostClient.Dial. -// -// For instance, per-host counters and/or limits may be implemented -// by such wrappers. -// -// The addr passed to the function must contain port. Example addr values: -// -// * foobar.baz:443 -// * foo.bar:80 -// * aaa.com:8080 -func DialTimeout(addr string, timeout time.Duration) (net.Conn, error) { - return getDialer(timeout, false)(addr) -} - -// DialDualStack dials the given TCP addr using both tcp4 and tcp6. -// -// This function has the following additional features comparing to net.Dial: -// -// * It reduces load on DNS resolver by caching resolved TCP addressed -// for DefaultDNSCacheDuration. -// * It dials all the resolved TCP addresses in round-robin manner until -// connection is established. This may be useful if certain addresses -// are temporarily unreachable. -// * It returns ErrDialTimeout if connection cannot be established during -// DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial -// timeout. -// -// This dialer is intended for custom code wrapping before passing -// to Client.Dial or HostClient.Dial. -// -// For instance, per-host counters and/or limits may be implemented -// by such wrappers. -// -// The addr passed to the function must contain port. Example addr values: -// -// * foobar.baz:443 -// * foo.bar:80 -// * aaa.com:8080 -func DialDualStack(addr string) (net.Conn, error) { - return getDialer(DefaultDialTimeout, true)(addr) -} - -// DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 -// using the given timeout. -// -// This function has the following additional features comparing to net.Dial: -// -// * It reduces load on DNS resolver by caching resolved TCP addressed -// for DefaultDNSCacheDuration. -// * It dials all the resolved TCP addresses in round-robin manner until -// connection is established. This may be useful if certain addresses -// are temporarily unreachable. -// -// This dialer is intended for custom code wrapping before passing -// to Client.Dial or HostClient.Dial. -// -// For instance, per-host counters and/or limits may be implemented -// by such wrappers. -// -// The addr passed to the function must contain port. Example addr values: -// -// * foobar.baz:443 -// * foo.bar:80 -// * aaa.com:8080 -func DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error) { - return getDialer(timeout, true)(addr) -} - -func getDialer(timeout time.Duration, dualStack bool) DialFunc { - if timeout <= 0 { - timeout = DefaultDialTimeout - } - timeoutRounded := int(timeout.Seconds()*10 + 9) - - m := dialMap - if dualStack { - m = dialDualStackMap - } - - dialMapLock.Lock() - d := m[timeoutRounded] - if d == nil { - dialer := dialerStd - if dualStack { - dialer = dialerDualStack - } - d = dialer.NewDial(timeout) - m[timeoutRounded] = d - } - dialMapLock.Unlock() - return d -} - -var ( - dialerStd = &tcpDialer{} - dialerDualStack = &tcpDialer{DualStack: true} - - dialMap = make(map[int]DialFunc) - dialDualStackMap = make(map[int]DialFunc) - dialMapLock sync.Mutex -) - -type tcpDialer struct { - DualStack bool - - tcpAddrsLock sync.Mutex - tcpAddrsMap map[string]*tcpAddrEntry - - concurrencyCh chan struct{} - - once sync.Once -} - -const maxDialConcurrency = 1000 - -func (d *tcpDialer) NewDial(timeout time.Duration) DialFunc { - d.once.Do(func() { - d.concurrencyCh = make(chan struct{}, maxDialConcurrency) - d.tcpAddrsMap = make(map[string]*tcpAddrEntry) - go d.tcpAddrsClean() - }) - - return func(addr string) (net.Conn, error) { - addrs, idx, err := d.getTCPAddrs(addr) - if err != nil { - return nil, err - } - network := "tcp4" - if d.DualStack { - network = "tcp" - } - - var conn net.Conn - n := uint32(len(addrs)) - deadline := time.Now().Add(timeout) - for n > 0 { - conn, err = tryDial(network, &addrs[idx%n], deadline, d.concurrencyCh) - if err == nil { - return conn, nil - } - if err == ErrDialTimeout { - return nil, err - } - idx++ - n-- - } - return nil, err - } -} - -func tryDial(network string, addr *net.TCPAddr, deadline time.Time, concurrencyCh chan struct{}) (net.Conn, error) { - timeout := -time.Since(deadline) - if timeout <= 0 { - return nil, ErrDialTimeout - } - - select { - case concurrencyCh <- struct{}{}: - default: - tc := acquireTimer(timeout) - isTimeout := false - select { - case concurrencyCh <- struct{}{}: - case <-tc.C: - isTimeout = true - } - releaseTimer(tc) - if isTimeout { - return nil, ErrDialTimeout - } - } - - timeout = -time.Since(deadline) - if timeout <= 0 { - <-concurrencyCh - return nil, ErrDialTimeout - } - - chv := dialResultChanPool.Get() - if chv == nil { - chv = make(chan dialResult, 1) - } - ch := chv.(chan dialResult) - go func() { - var dr dialResult - dr.conn, dr.err = net.DialTCP(network, nil, addr) - ch <- dr - <-concurrencyCh - }() - - var ( - conn net.Conn - err error - ) - - tc := acquireTimer(timeout) - select { - case dr := <-ch: - conn = dr.conn - err = dr.err - dialResultChanPool.Put(ch) - case <-tc.C: - err = ErrDialTimeout - } - releaseTimer(tc) - - return conn, err -} - -var dialResultChanPool sync.Pool - -type dialResult struct { - conn net.Conn - err error -} - -// ErrDialTimeout is returned when TCP dialing is timed out. -var ErrDialTimeout = errors.New("dialing to the given TCP address timed out") - -// DefaultDialTimeout is timeout used by Dial and DialDualStack -// for establishing TCP connections. -const DefaultDialTimeout = 3 * time.Second - -type tcpAddrEntry struct { - addrs []net.TCPAddr - addrsIdx uint32 - - resolveTime time.Time - pending bool -} - -// DefaultDNSCacheDuration is the duration for caching resolved TCP addresses -// by Dial* functions. -const DefaultDNSCacheDuration = time.Minute - -func (d *tcpDialer) tcpAddrsClean() { - expireDuration := 2 * DefaultDNSCacheDuration - for { - time.Sleep(time.Second) - t := time.Now() - - d.tcpAddrsLock.Lock() - for k, e := range d.tcpAddrsMap { - if t.Sub(e.resolveTime) > expireDuration { - delete(d.tcpAddrsMap, k) - } - } - d.tcpAddrsLock.Unlock() - } -} - -func (d *tcpDialer) getTCPAddrs(addr string) ([]net.TCPAddr, uint32, error) { - d.tcpAddrsLock.Lock() - e := d.tcpAddrsMap[addr] - if e != nil && !e.pending && time.Since(e.resolveTime) > DefaultDNSCacheDuration { - e.pending = true - e = nil - } - d.tcpAddrsLock.Unlock() - - if e == nil { - addrs, err := resolveTCPAddrs(addr, d.DualStack) - if err != nil { - d.tcpAddrsLock.Lock() - e = d.tcpAddrsMap[addr] - if e != nil && e.pending { - e.pending = false - } - d.tcpAddrsLock.Unlock() - return nil, 0, err - } - - e = &tcpAddrEntry{ - addrs: addrs, - resolveTime: time.Now(), - } - - d.tcpAddrsLock.Lock() - d.tcpAddrsMap[addr] = e - d.tcpAddrsLock.Unlock() - } - - idx := atomic.AddUint32(&e.addrsIdx, 1) - return e.addrs, idx, nil -} - -func resolveTCPAddrs(addr string, dualStack bool) ([]net.TCPAddr, error) { - host, portS, err := net.SplitHostPort(addr) - if err != nil { - return nil, err - } - port, err := strconv.Atoi(portS) - if err != nil { - return nil, err - } - - ips, err := net.LookupIP(host) - if err != nil { - return nil, err - } - - n := len(ips) - addrs := make([]net.TCPAddr, 0, n) - for i := 0; i < n; i++ { - ip := ips[i] - if !dualStack && ip.To4() == nil { - continue - } - addrs = append(addrs, net.TCPAddr{ - IP: ip, - Port: port, - }) - } - if len(addrs) == 0 { - return nil, errNoDNSEntries - } - return addrs, nil -} - -var errNoDNSEntries = errors.New("couldn't find DNS entries for the given domain. Try using DialDualStack") diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/timer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/timer.go deleted file mode 100644 index bb12acb7..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/timer.go +++ /dev/null @@ -1,44 +0,0 @@ -package fasthttp - -import ( - "sync" - "time" -) - -func initTimer(t *time.Timer, timeout time.Duration) *time.Timer { - if t == nil { - return time.NewTimer(timeout) - } - if t.Reset(timeout) { - panic("BUG: active timer trapped into initTimer()") - } - return t -} - -func stopTimer(t *time.Timer) { - if !t.Stop() { - // Collect possibly added time from the channel - // if timer has been stopped and nobody collected its' value. - select { - case <-t.C: - default: - } - } -} - -func acquireTimer(timeout time.Duration) *time.Timer { - v := timerPool.Get() - if v == nil { - return time.NewTimer(timeout) - } - t := v.(*time.Timer) - initTimer(t, timeout) - return t -} - -func releaseTimer(t *time.Timer) { - stopTimer(t) - timerPool.Put(t) -} - -var timerPool sync.Pool diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri.go deleted file mode 100644 index d536f593..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri.go +++ /dev/null @@ -1,525 +0,0 @@ -package fasthttp - -import ( - "bytes" - "io" - "sync" -) - -// AcquireURI returns an empty URI instance from the pool. -// -// Release the URI with ReleaseURI after the URI is no longer needed. -// This allows reducing GC load. -func AcquireURI() *URI { - return uriPool.Get().(*URI) -} - -// ReleaseURI releases the URI acquired via AcquireURI. -// -// The released URI mustn't be used after releasing it, otherwise data races -// may occur. -func ReleaseURI(u *URI) { - u.Reset() - uriPool.Put(u) -} - -var uriPool = &sync.Pool{ - New: func() interface{} { - return &URI{} - }, -} - -// URI represents URI :) . -// -// It is forbidden copying URI instances. Create new instance and use CopyTo -// instead. -// -// URI instance MUST NOT be used from concurrently running goroutines. -type URI struct { - noCopy noCopy - - pathOriginal []byte - scheme []byte - path []byte - queryString []byte - hash []byte - host []byte - - queryArgs Args - parsedQueryArgs bool - - fullURI []byte - requestURI []byte - - h *RequestHeader -} - -// CopyTo copies uri contents to dst. -func (u *URI) CopyTo(dst *URI) { - dst.Reset() - dst.pathOriginal = append(dst.pathOriginal[:0], u.pathOriginal...) - dst.scheme = append(dst.scheme[:0], u.scheme...) - dst.path = append(dst.path[:0], u.path...) - dst.queryString = append(dst.queryString[:0], u.queryString...) - dst.hash = append(dst.hash[:0], u.hash...) - dst.host = append(dst.host[:0], u.host...) - - u.queryArgs.CopyTo(&dst.queryArgs) - dst.parsedQueryArgs = u.parsedQueryArgs - - // fullURI and requestURI shouldn't be copied, since they are created - // from scratch on each FullURI() and RequestURI() call. - dst.h = u.h -} - -// Hash returns URI hash, i.e. qwe of http://aaa.com/foo/bar?baz=123#qwe . -// -// The returned value is valid until the next URI method call. -func (u *URI) Hash() []byte { - return u.hash -} - -// SetHash sets URI hash. -func (u *URI) SetHash(hash string) { - u.hash = append(u.hash[:0], hash...) -} - -// SetHashBytes sets URI hash. -func (u *URI) SetHashBytes(hash []byte) { - u.hash = append(u.hash[:0], hash...) -} - -// QueryString returns URI query string, -// i.e. baz=123 of http://aaa.com/foo/bar?baz=123#qwe . -// -// The returned value is valid until the next URI method call. -func (u *URI) QueryString() []byte { - return u.queryString -} - -// SetQueryString sets URI query string. -func (u *URI) SetQueryString(queryString string) { - u.queryString = append(u.queryString[:0], queryString...) - u.parsedQueryArgs = false -} - -// SetQueryStringBytes sets URI query string. -func (u *URI) SetQueryStringBytes(queryString []byte) { - u.queryString = append(u.queryString[:0], queryString...) - u.parsedQueryArgs = false -} - -// Path returns URI path, i.e. /foo/bar of http://aaa.com/foo/bar?baz=123#qwe . -// -// The returned path is always urldecoded and normalized, -// i.e. '//f%20obar/baz/../zzz' becomes '/f obar/zzz'. -// -// The returned value is valid until the next URI method call. -func (u *URI) Path() []byte { - path := u.path - if len(path) == 0 { - path = strSlash - } - return path -} - -// SetPath sets URI path. -func (u *URI) SetPath(path string) { - u.pathOriginal = append(u.pathOriginal[:0], path...) - u.path = normalizePath(u.path, u.pathOriginal) -} - -// SetPathBytes sets URI path. -func (u *URI) SetPathBytes(path []byte) { - u.pathOriginal = append(u.pathOriginal[:0], path...) - u.path = normalizePath(u.path, u.pathOriginal) -} - -// PathOriginal returns the original path from requestURI passed to URI.Parse(). -// -// The returned value is valid until the next URI method call. -func (u *URI) PathOriginal() []byte { - return u.pathOriginal -} - -// Scheme returns URI scheme, i.e. http of http://aaa.com/foo/bar?baz=123#qwe . -// -// Returned scheme is always lowercased. -// -// The returned value is valid until the next URI method call. -func (u *URI) Scheme() []byte { - scheme := u.scheme - if len(scheme) == 0 { - scheme = strHTTP - } - return scheme -} - -// SetScheme sets URI scheme, i.e. http, https, ftp, etc. -func (u *URI) SetScheme(scheme string) { - u.scheme = append(u.scheme[:0], scheme...) - lowercaseBytes(u.scheme) -} - -// SetSchemeBytes sets URI scheme, i.e. http, https, ftp, etc. -func (u *URI) SetSchemeBytes(scheme []byte) { - u.scheme = append(u.scheme[:0], scheme...) - lowercaseBytes(u.scheme) -} - -// Reset clears uri. -func (u *URI) Reset() { - u.pathOriginal = u.pathOriginal[:0] - u.scheme = u.scheme[:0] - u.path = u.path[:0] - u.queryString = u.queryString[:0] - u.hash = u.hash[:0] - - u.host = u.host[:0] - u.queryArgs.Reset() - u.parsedQueryArgs = false - - // There is no need in u.fullURI = u.fullURI[:0], since full uri - // is calculated on each call to FullURI(). - - // There is no need in u.requestURI = u.requestURI[:0], since requestURI - // is calculated on each call to RequestURI(). - - u.h = nil -} - -// Host returns host part, i.e. aaa.com of http://aaa.com/foo/bar?baz=123#qwe . -// -// Host is always lowercased. -func (u *URI) Host() []byte { - if len(u.host) == 0 && u.h != nil { - u.host = append(u.host[:0], u.h.Host()...) - lowercaseBytes(u.host) - u.h = nil - } - return u.host -} - -// SetHost sets host for the uri. -func (u *URI) SetHost(host string) { - u.host = append(u.host[:0], host...) - lowercaseBytes(u.host) -} - -// SetHostBytes sets host for the uri. -func (u *URI) SetHostBytes(host []byte) { - u.host = append(u.host[:0], host...) - lowercaseBytes(u.host) -} - -// Parse initializes URI from the given host and uri. -// -// host may be nil. In this case uri must contain fully qualified uri, -// i.e. with scheme and host. http is assumed if scheme is omitted. -// -// uri may contain e.g. RequestURI without scheme and host if host is non-empty. -func (u *URI) Parse(host, uri []byte) { - u.parse(host, uri, nil) -} - -func (u *URI) parseQuick(uri []byte, h *RequestHeader, isTLS bool) { - u.parse(nil, uri, h) - if isTLS { - u.scheme = append(u.scheme[:0], strHTTPS...) - } -} - -func (u *URI) parse(host, uri []byte, h *RequestHeader) { - u.Reset() - u.h = h - - scheme, host, uri := splitHostURI(host, uri) - u.scheme = append(u.scheme, scheme...) - lowercaseBytes(u.scheme) - u.host = append(u.host, host...) - lowercaseBytes(u.host) - - b := uri - queryIndex := bytes.IndexByte(b, '?') - fragmentIndex := bytes.IndexByte(b, '#') - // Ignore query in fragment part - if fragmentIndex >= 0 && queryIndex > fragmentIndex { - queryIndex = -1 - } - - if queryIndex < 0 && fragmentIndex < 0 { - u.pathOriginal = append(u.pathOriginal, b...) - u.path = normalizePath(u.path, u.pathOriginal) - return - } - - if queryIndex >= 0 { - // Path is everything up to the start of the query - u.pathOriginal = append(u.pathOriginal, b[:queryIndex]...) - u.path = normalizePath(u.path, u.pathOriginal) - - if fragmentIndex < 0 { - u.queryString = append(u.queryString, b[queryIndex+1:]...) - } else { - u.queryString = append(u.queryString, b[queryIndex+1:fragmentIndex]...) - u.hash = append(u.hash, b[fragmentIndex+1:]...) - } - return - } - - // fragmentIndex >= 0 && queryIndex < 0 - // Path is up to the start of fragment - u.pathOriginal = append(u.pathOriginal, b[:fragmentIndex]...) - u.path = normalizePath(u.path, u.pathOriginal) - u.hash = append(u.hash, b[fragmentIndex+1:]...) -} - -func normalizePath(dst, src []byte) []byte { - dst = dst[:0] - dst = addLeadingSlash(dst, src) - dst = decodeArgAppendNoPlus(dst, src) - - // remove duplicate slashes - b := dst - bSize := len(b) - for { - n := bytes.Index(b, strSlashSlash) - if n < 0 { - break - } - b = b[n:] - copy(b, b[1:]) - b = b[:len(b)-1] - bSize-- - } - dst = dst[:bSize] - - // remove /./ parts - b = dst - for { - n := bytes.Index(b, strSlashDotSlash) - if n < 0 { - break - } - nn := n + len(strSlashDotSlash) - 1 - copy(b[n:], b[nn:]) - b = b[:len(b)-nn+n] - } - - // remove /foo/../ parts - for { - n := bytes.Index(b, strSlashDotDotSlash) - if n < 0 { - break - } - nn := bytes.LastIndexByte(b[:n], '/') - if nn < 0 { - nn = 0 - } - n += len(strSlashDotDotSlash) - 1 - copy(b[nn:], b[n:]) - b = b[:len(b)-n+nn] - } - - // remove trailing /foo/.. - n := bytes.LastIndex(b, strSlashDotDot) - if n >= 0 && n+len(strSlashDotDot) == len(b) { - nn := bytes.LastIndexByte(b[:n], '/') - if nn < 0 { - return strSlash - } - b = b[:nn+1] - } - - return b -} - -// RequestURI returns RequestURI - i.e. URI without Scheme and Host. -func (u *URI) RequestURI() []byte { - dst := appendQuotedPath(u.requestURI[:0], u.Path()) - if u.queryArgs.Len() > 0 { - dst = append(dst, '?') - dst = u.queryArgs.AppendBytes(dst) - } else if len(u.queryString) > 0 { - dst = append(dst, '?') - dst = append(dst, u.queryString...) - } - if len(u.hash) > 0 { - dst = append(dst, '#') - dst = append(dst, u.hash...) - } - u.requestURI = dst - return u.requestURI -} - -// LastPathSegment returns the last part of uri path after '/'. -// -// Examples: -// -// * For /foo/bar/baz.html path returns baz.html. -// * For /foo/bar/ returns empty byte slice. -// * For /foobar.js returns foobar.js. -func (u *URI) LastPathSegment() []byte { - path := u.Path() - n := bytes.LastIndexByte(path, '/') - if n < 0 { - return path - } - return path[n+1:] -} - -// Update updates uri. -// -// The following newURI types are accepted: -// -// * Absolute, i.e. http://foobar.com/aaa/bb?cc . In this case the original -// uri is replaced by newURI. -// * Absolute without scheme, i.e. //foobar.com/aaa/bb?cc. In this case -// the original scheme is preserved. -// * Missing host, i.e. /aaa/bb?cc . In this case only RequestURI part -// of the original uri is replaced. -// * Relative path, i.e. xx?yy=abc . In this case the original RequestURI -// is updated according to the new relative path. -func (u *URI) Update(newURI string) { - u.UpdateBytes(s2b(newURI)) -} - -// UpdateBytes updates uri. -// -// The following newURI types are accepted: -// -// * Absolute, i.e. http://foobar.com/aaa/bb?cc . In this case the original -// uri is replaced by newURI. -// * Absolute without scheme, i.e. //foobar.com/aaa/bb?cc. In this case -// the original scheme is preserved. -// * Missing host, i.e. /aaa/bb?cc . In this case only RequestURI part -// of the original uri is replaced. -// * Relative path, i.e. xx?yy=abc . In this case the original RequestURI -// is updated according to the new relative path. -func (u *URI) UpdateBytes(newURI []byte) { - u.requestURI = u.updateBytes(newURI, u.requestURI) -} - -func (u *URI) updateBytes(newURI, buf []byte) []byte { - if len(newURI) == 0 { - return buf - } - - n := bytes.Index(newURI, strSlashSlash) - if n >= 0 { - // absolute uri - var b [32]byte - schemeOriginal := b[:0] - if len(u.scheme) > 0 { - schemeOriginal = append([]byte(nil), u.scheme...) - } - u.Parse(nil, newURI) - if len(schemeOriginal) > 0 && len(u.scheme) == 0 { - u.scheme = append(u.scheme[:0], schemeOriginal...) - } - return buf - } - - if newURI[0] == '/' { - // uri without host - buf = u.appendSchemeHost(buf[:0]) - buf = append(buf, newURI...) - u.Parse(nil, buf) - return buf - } - - // relative path - switch newURI[0] { - case '?': - // query string only update - u.SetQueryStringBytes(newURI[1:]) - return append(buf[:0], u.FullURI()...) - case '#': - // update only hash - u.SetHashBytes(newURI[1:]) - return append(buf[:0], u.FullURI()...) - default: - // update the last path part after the slash - path := u.Path() - n = bytes.LastIndexByte(path, '/') - if n < 0 { - panic("BUG: path must contain at least one slash") - } - buf = u.appendSchemeHost(buf[:0]) - buf = appendQuotedPath(buf, path[:n+1]) - buf = append(buf, newURI...) - u.Parse(nil, buf) - return buf - } -} - -// FullURI returns full uri in the form {Scheme}://{Host}{RequestURI}#{Hash}. -func (u *URI) FullURI() []byte { - u.fullURI = u.AppendBytes(u.fullURI[:0]) - return u.fullURI -} - -// AppendBytes appends full uri to dst and returns the extended dst. -func (u *URI) AppendBytes(dst []byte) []byte { - dst = u.appendSchemeHost(dst) - return append(dst, u.RequestURI()...) -} - -func (u *URI) appendSchemeHost(dst []byte) []byte { - dst = append(dst, u.Scheme()...) - dst = append(dst, strColonSlashSlash...) - return append(dst, u.Host()...) -} - -// WriteTo writes full uri to w. -// -// WriteTo implements io.WriterTo interface. -func (u *URI) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(u.FullURI()) - return int64(n), err -} - -// String returns full uri. -func (u *URI) String() string { - return string(u.FullURI()) -} - -func splitHostURI(host, uri []byte) ([]byte, []byte, []byte) { - n := bytes.Index(uri, strSlashSlash) - if n < 0 { - return strHTTP, host, uri - } - scheme := uri[:n] - if bytes.IndexByte(scheme, '/') >= 0 { - return strHTTP, host, uri - } - if len(scheme) > 0 && scheme[len(scheme)-1] == ':' { - scheme = scheme[:len(scheme)-1] - } - n += len(strSlashSlash) - uri = uri[n:] - n = bytes.IndexByte(uri, '/') - if n < 0 { - // A hack for bogus urls like foobar.com?a=b without - // slash after host. - if n = bytes.IndexByte(uri, '?'); n >= 0 { - return scheme, uri[:n], uri[n:] - } - return scheme, uri, strSlash - } - return scheme, uri[:n], uri[n:] -} - -// QueryArgs returns query args. -func (u *URI) QueryArgs() *Args { - u.parseQueryArgs() - return &u.queryArgs -} - -func (u *URI) parseQueryArgs() { - if u.parsedQueryArgs { - return - } - u.queryArgs.ParseBytes(u.queryString) - u.parsedQueryArgs = true -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_unix.go deleted file mode 100644 index 1e307332..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_unix.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !windows - -package fasthttp - -func addLeadingSlash(dst, src []byte) []byte { - // add leading slash for unix paths - if len(src) == 0 || src[0] != '/' { - dst = append(dst, '/') - } - - return dst -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_windows.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_windows.go deleted file mode 100644 index 95917a6b..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_windows.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build windows - -package fasthttp - -func addLeadingSlash(dst, src []byte) []byte { - // zero length and "C:/" case - if len(src) == 0 || (len(src) > 2 && src[1] != ':') { - dst = append(dst, '/') - } - - return dst -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/userdata.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/userdata.go deleted file mode 100644 index bd3e28aa..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/userdata.go +++ /dev/null @@ -1,71 +0,0 @@ -package fasthttp - -import ( - "io" -) - -type userDataKV struct { - key []byte - value interface{} -} - -type userData []userDataKV - -func (d *userData) Set(key string, value interface{}) { - args := *d - n := len(args) - for i := 0; i < n; i++ { - kv := &args[i] - if string(kv.key) == key { - kv.value = value - return - } - } - - c := cap(args) - if c > n { - args = args[:n+1] - kv := &args[n] - kv.key = append(kv.key[:0], key...) - kv.value = value - *d = args - return - } - - kv := userDataKV{} - kv.key = append(kv.key[:0], key...) - kv.value = value - *d = append(args, kv) -} - -func (d *userData) SetBytes(key []byte, value interface{}) { - d.Set(b2s(key), value) -} - -func (d *userData) Get(key string) interface{} { - args := *d - n := len(args) - for i := 0; i < n; i++ { - kv := &args[i] - if string(kv.key) == key { - return kv.value - } - } - return nil -} - -func (d *userData) GetBytes(key []byte) interface{} { - return d.Get(b2s(key)) -} - -func (d *userData) Reset() { - args := *d - n := len(args) - for i := 0; i < n; i++ { - v := args[i].value - if vc, ok := v.(io.Closer); ok { - vc.Close() - } - } - *d = (*d)[:0] -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go deleted file mode 100644 index 081ac65c..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/workerpool.go +++ /dev/null @@ -1,231 +0,0 @@ -package fasthttp - -import ( - "net" - "runtime" - "strings" - "sync" - "time" -) - -// workerPool serves incoming connections via a pool of workers -// in FILO order, i.e. the most recently stopped worker will serve the next -// incoming connection. -// -// Such a scheme keeps CPU caches hot (in theory). -type workerPool struct { - // Function for serving server connections. - // It must leave c unclosed. - WorkerFunc func(c net.Conn) error - - MaxWorkersCount int - - LogAllErrors bool - - MaxIdleWorkerDuration time.Duration - - Logger Logger - - lock sync.Mutex - workersCount int - mustStop bool - - ready []*workerChan - - stopCh chan struct{} - - workerChanPool sync.Pool -} - -type workerChan struct { - lastUseTime time.Time - ch chan net.Conn -} - -func (wp *workerPool) Start() { - if wp.stopCh != nil { - panic("BUG: workerPool already started") - } - wp.stopCh = make(chan struct{}) - stopCh := wp.stopCh - go func() { - var scratch []*workerChan - for { - wp.clean(&scratch) - select { - case <-stopCh: - return - default: - time.Sleep(wp.getMaxIdleWorkerDuration()) - } - } - }() -} - -func (wp *workerPool) Stop() { - if wp.stopCh == nil { - panic("BUG: workerPool wasn't started") - } - close(wp.stopCh) - wp.stopCh = nil - - // Stop all the workers waiting for incoming connections. - // Do not wait for busy workers - they will stop after - // serving the connection and noticing wp.mustStop = true. - wp.lock.Lock() - ready := wp.ready - for i, ch := range ready { - ch.ch <- nil - ready[i] = nil - } - wp.ready = ready[:0] - wp.mustStop = true - wp.lock.Unlock() -} - -func (wp *workerPool) getMaxIdleWorkerDuration() time.Duration { - if wp.MaxIdleWorkerDuration <= 0 { - return 10 * time.Second - } - return wp.MaxIdleWorkerDuration -} - -func (wp *workerPool) clean(scratch *[]*workerChan) { - maxIdleWorkerDuration := wp.getMaxIdleWorkerDuration() - - // Clean least recently used workers if they didn't serve connections - // for more than maxIdleWorkerDuration. - currentTime := time.Now() - - wp.lock.Lock() - ready := wp.ready - n := len(ready) - i := 0 - for i < n && currentTime.Sub(ready[i].lastUseTime) > maxIdleWorkerDuration { - i++ - } - *scratch = append((*scratch)[:0], ready[:i]...) - if i > 0 { - m := copy(ready, ready[i:]) - for i = m; i < n; i++ { - ready[i] = nil - } - wp.ready = ready[:m] - } - wp.lock.Unlock() - - // Notify obsolete workers to stop. - // This notification must be outside the wp.lock, since ch.ch - // may be blocking and may consume a lot of time if many workers - // are located on non-local CPUs. - tmp := *scratch - for i, ch := range tmp { - ch.ch <- nil - tmp[i] = nil - } -} - -func (wp *workerPool) Serve(c net.Conn) bool { - ch := wp.getCh() - if ch == nil { - return false - } - ch.ch <- c - return true -} - -var workerChanCap = func() int { - // Use blocking workerChan if GOMAXPROCS=1. - // This immediately switches Serve to WorkerFunc, which results - // in higher performance (under go1.5 at least). - if runtime.GOMAXPROCS(0) == 1 { - return 0 - } - - // Use non-blocking workerChan if GOMAXPROCS>1, - // since otherwise the Serve caller (Acceptor) may lag accepting - // new connections if WorkerFunc is CPU-bound. - return 1 -}() - -func (wp *workerPool) getCh() *workerChan { - var ch *workerChan - createWorker := false - - wp.lock.Lock() - ready := wp.ready - n := len(ready) - 1 - if n < 0 { - if wp.workersCount < wp.MaxWorkersCount { - createWorker = true - wp.workersCount++ - } - } else { - ch = ready[n] - ready[n] = nil - wp.ready = ready[:n] - } - wp.lock.Unlock() - - if ch == nil { - if !createWorker { - return nil - } - vch := wp.workerChanPool.Get() - if vch == nil { - vch = &workerChan{ - ch: make(chan net.Conn, workerChanCap), - } - } - ch = vch.(*workerChan) - go func() { - wp.workerFunc(ch) - wp.workerChanPool.Put(vch) - }() - } - return ch -} - -func (wp *workerPool) release(ch *workerChan) bool { - ch.lastUseTime = time.Now() - wp.lock.Lock() - if wp.mustStop { - wp.lock.Unlock() - return false - } - wp.ready = append(wp.ready, ch) - wp.lock.Unlock() - return true -} - -func (wp *workerPool) workerFunc(ch *workerChan) { - var c net.Conn - - var err error - for c = range ch.ch { - if c == nil { - break - } - - if err = wp.WorkerFunc(c); err != nil && err != errHijacked { - errStr := err.Error() - if wp.LogAllErrors || !(strings.Contains(errStr, "broken pipe") || - strings.Contains(errStr, "reset by peer") || - strings.Contains(errStr, "i/o timeout")) { - wp.Logger.Printf("error when serving connection %q<->%q: %s", c.LocalAddr(), c.RemoteAddr(), err) - } - } - if err != errHijacked { - c.Close() - } - c = nil - - if !wp.release(ch) { - break - } - } - - wp.lock.Lock() - wp.workersCount-- - wp.lock.Unlock() -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml new file mode 100644 index 00000000..6a6ec2eb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/.travis.yml @@ -0,0 +1,15 @@ +language: go + +go: + - 1.6 + +script: + # build test for supported platforms + - GOOS=linux go build + - GOOS=darwin go build + - GOOS=freebsd go build + - GOOS=windows go build + - GOARCH=386 go build + + # run tests on a standard platform + - go test -v ./... diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/LICENSE similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/README.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/bytebufferpool/README.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/bytebuffer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/bytebuffer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/bytebuffer.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/bytebuffer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/pool.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/pool.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/bytebufferpool/pool.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/bytebufferpool/pool.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore new file mode 100644 index 00000000..7b58ce45 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.gitignore @@ -0,0 +1,3 @@ +tags +*.pprof +*.fasthttp.gz diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml new file mode 100644 index 00000000..fca54a82 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/.travis.yml @@ -0,0 +1,36 @@ +language: go + +go: + - tip + - 1.11 + - 1.10.x + - 1.9.x + +os: + - linux + - osx + +matrix: + allow_failures: + - tip + fast_finish: true + +before_install: + - go get -t -v ./... + # - go get -v golang.org/x/tools/cmd/goimports + +script: + # TODO(@kirilldanshin) + # - test -z "$(goimports -d $(find . -type f -name '*.go' -not -path "./vendor/*"))" + # build test for supported platforms + - GOOS=linux go build + - GOOS=darwin go build + - GOOS=freebsd go build + - GOOS=windows go build + - GOARCH=386 go build + + # run tests on a standard platform + - go test -v ./... + + # run tests with the race detector as well + - go test -race -v ./... diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/LICENSE similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/README.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/README.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/README.md diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/TODO b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/TODO similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/TODO rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/TODO diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/args.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/args.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/args.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/args.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/bytesconv.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/bytesconv_32.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_32.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/bytesconv_32.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_32.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/bytesconv_64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_64.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/bytesconv_64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/bytesconv_64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/client.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/client.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/client.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/client.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/coarseTime.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/coarseTime.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/coarseTime.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/coarseTime.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/compress.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/compress.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/compress.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/compress.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/cookie.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/cookie.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/cookie.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/cookie.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/doc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/ecdsa.pem diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/inmemory_listener.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/pipeconns.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fasthttputil/rsa.pem diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fs.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fs.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/fs.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/fs.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.mod b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.mod similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.mod rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.mod diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.sum b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.sum similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/go.sum rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/go.sum diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/header.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/header.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/header.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/header.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/http.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/http.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/http.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/http.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/lbclient.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/lbclient.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/lbclient.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/lbclient.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/nocopy.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/nocopy.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/nocopy.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/nocopy.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/peripconn.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/peripconn.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/peripconn.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/peripconn.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/server.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/server.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/server.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/server.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.key b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.key rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.key diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.pem b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.pem rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/ssl-cert-snakeoil.pem diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/doc.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/doc.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/func.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/func.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/func.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/func.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/writer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/writer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stackless/writer.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stackless/writer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/status.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/status.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/status.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/status.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stream.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stream.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/stream.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/stream.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/strings.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/strings.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/strings.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/strings.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/tcpdialer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/tcpdialer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/tcpdialer.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/tcpdialer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/timer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/timer.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/timer.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/timer.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_unix.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_unix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_unix.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_windows.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_windows.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/uri_windows.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/uri_windows.go diff --git a/functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/userdata.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/userdata.go similarity index 100% rename from functions/ingest/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/v3io-go-http/vendor/github.com/valyala/fasthttp/userdata.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/userdata.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/workerpool.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/workerpool.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/github.com/valyala/fasthttp/workerpool.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/valyala/fasthttp/workerpool.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore new file mode 100644 index 00000000..26520536 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.gitignore @@ -0,0 +1 @@ +y.output diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml new file mode 100644 index 00000000..43c9bafa --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/.travis.yml @@ -0,0 +1,17 @@ +dist: trusty +sudo: false + +language: go +go: + - 1.6.x + - 1.7.x + - 1.8.x + - 1.9.x + +before_install: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + - go install golang.org/x/tools/cmd/goyacc + +script: + - travis_retry $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go deleted file mode 100644 index 6d8c1ef1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/analyzer_test.go +++ /dev/null @@ -1,511 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestPreview(t *testing.T) { - testcases := []struct { - sql string - want int - }{ - {"select ...", StmtSelect}, - {" select ...", StmtSelect}, - {"(select ...", StmtSelect}, - {"insert ...", StmtInsert}, - {"replace ....", StmtReplace}, - {" update ...", StmtUpdate}, - {"Update", StmtUpdate}, - {"UPDATE ...", StmtUpdate}, - {"\n\t delete ...", StmtDelete}, - {"", StmtUnknown}, - {" ", StmtUnknown}, - {"begin", StmtBegin}, - {" begin", StmtBegin}, - {" begin ", StmtBegin}, - {"\n\t begin ", StmtBegin}, - {"... begin ", StmtUnknown}, - {"begin ...", StmtUnknown}, - {"begin /* ... */", StmtBegin}, - {"begin /* ... *//*test*/", StmtBegin}, - {"start transaction", StmtBegin}, - {"commit", StmtCommit}, - {"commit /*...*/", StmtCommit}, - {"rollback", StmtRollback}, - {"rollback /*...*/", StmtRollback}, - {"create", StmtDDL}, - {"alter", StmtDDL}, - {"rename", StmtDDL}, - {"drop", StmtDDL}, - {"set", StmtSet}, - {"show", StmtShow}, - {"use", StmtUse}, - {"analyze", StmtOther}, - {"describe", StmtOther}, - {"desc", StmtOther}, - {"explain", StmtOther}, - {"repair", StmtOther}, - {"optimize", StmtOther}, - {"truncate", StmtDDL}, - {"unknown", StmtUnknown}, - - {"/* leading comment */ select ...", StmtSelect}, - {"/* leading comment */ (select ...", StmtSelect}, - {"/* leading comment */ /* leading comment 2 */ select ...", StmtSelect}, - {"/*! MySQL-specific comment */", StmtComment}, - {"/*!50708 MySQL-version comment */", StmtComment}, - {"-- leading single line comment \n select ...", StmtSelect}, - {"-- leading single line comment \n -- leading single line comment 2\n select ...", StmtSelect}, - - {"/* leading comment no end select ...", StmtUnknown}, - {"-- leading single line comment no end select ...", StmtUnknown}, - } - for _, tcase := range testcases { - if got := Preview(tcase.sql); got != tcase.want { - t.Errorf("Preview(%s): %v, want %v", tcase.sql, got, tcase.want) - } - } -} - -func TestIsDML(t *testing.T) { - testcases := []struct { - sql string - want bool - }{ - {" update ...", true}, - {"Update", true}, - {"UPDATE ...", true}, - {"\n\t delete ...", true}, - {"insert ...", true}, - {"replace ...", true}, - {"select ...", false}, - {" select ...", false}, - {"", false}, - {" ", false}, - } - for _, tcase := range testcases { - if got := IsDML(tcase.sql); got != tcase.want { - t.Errorf("IsDML(%s): %v, want %v", tcase.sql, got, tcase.want) - } - } -} - -func TestGetTableName(t *testing.T) { - testcases := []struct { - in, out string - }{{ - in: "select * from t", - out: "t", - }, { - in: "select * from t.t", - out: "", - }, { - in: "select * from (select * from t) as tt", - out: "", - }} - - for _, tc := range testcases { - tree, err := Parse(tc.in) - if err != nil { - t.Error(err) - continue - } - out := GetTableName(tree.(*Select).From[0].(*AliasedTableExpr).Expr) - if out.String() != tc.out { - t.Errorf("GetTableName('%s'): %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestIsColName(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: &ColName{}, - out: true, - }, { - in: newHexVal(""), - }} - for _, tc := range testcases { - out := IsColName(tc.in) - if out != tc.out { - t.Errorf("IsColName(%T): %v, want %v", tc.in, out, tc.out) - } - } -} - -func TestIsValue(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: newStrVal("aa"), - out: true, - }, { - in: newHexVal("3131"), - out: true, - }, { - in: newIntVal("1"), - out: true, - }, { - in: newValArg(":a"), - out: true, - }, { - in: &NullVal{}, - out: false, - }} - for _, tc := range testcases { - out := IsValue(tc.in) - if out != tc.out { - t.Errorf("IsValue(%T): %v, want %v", tc.in, out, tc.out) - } - if tc.out { - // NewPlanValue should not fail for valid values. - if _, err := NewPlanValue(tc.in); err != nil { - t.Error(err) - } - } - } -} - -func TestIsNull(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: &NullVal{}, - out: true, - }, { - in: newStrVal(""), - }} - for _, tc := range testcases { - out := IsNull(tc.in) - if out != tc.out { - t.Errorf("IsNull(%T): %v, want %v", tc.in, out, tc.out) - } - } -} - -func TestIsSimpleTuple(t *testing.T) { - testcases := []struct { - in Expr - out bool - }{{ - in: ValTuple{newStrVal("aa")}, - out: true, - }, { - in: ValTuple{&ColName{}}, - }, { - in: ListArg("::a"), - out: true, - }, { - in: &ColName{}, - }} - for _, tc := range testcases { - out := IsSimpleTuple(tc.in) - if out != tc.out { - t.Errorf("IsSimpleTuple(%T): %v, want %v", tc.in, out, tc.out) - } - if tc.out { - // NewPlanValue should not fail for valid tuples. - if _, err := NewPlanValue(tc.in); err != nil { - t.Error(err) - } - } - } -} - -func TestNewPlanValue(t *testing.T) { - tcases := []struct { - in Expr - out sqltypes.PlanValue - err string - }{{ - in: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }, - out: sqltypes.PlanValue{Key: "valarg"}, - }, { - in: &SQLVal{ - Type: IntVal, - Val: []byte("10"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewInt64(10)}, - }, { - in: &SQLVal{ - Type: IntVal, - Val: []byte("1111111111111111111111111111111111111111"), - }, - err: "value out of range", - }, { - in: &SQLVal{ - Type: StrVal, - Val: []byte("strval"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewVarBinary("strval")}, - }, { - in: &SQLVal{ - Type: HexVal, - Val: []byte("3131"), - }, - out: sqltypes.PlanValue{Value: sqltypes.NewVarBinary("11")}, - }, { - in: &SQLVal{ - Type: HexVal, - Val: []byte("313"), - }, - err: "odd length hex string", - }, { - in: ListArg("::list"), - out: sqltypes.PlanValue{ListKey: "list"}, - }, { - in: ValTuple{ - &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }, - &SQLVal{ - Type: StrVal, - Val: []byte("strval"), - }, - }, - out: sqltypes.PlanValue{ - Values: []sqltypes.PlanValue{{ - Key: "valarg", - }, { - Value: sqltypes.NewVarBinary("strval"), - }}, - }, - }, { - in: ValTuple{ - &ParenExpr{Expr: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }}, - }, - err: "expression is too complex", - }, { - in: ValTuple{ - ListArg("::list"), - }, - err: "unsupported: nested lists", - }, { - in: &NullVal{}, - out: sqltypes.PlanValue{}, - }, { - in: &ParenExpr{Expr: &SQLVal{ - Type: ValArg, - Val: []byte(":valarg"), - }}, - err: "expression is too complex", - }} - for _, tc := range tcases { - got, err := NewPlanValue(tc.in) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("NewPlanValue(%s) error: %v, want '%s'", String(tc.in), err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("NewPlanValue(%s) error: nil, want '%s'", String(tc.in), tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("NewPlanValue(%s): %v, want %v", String(tc.in), got, tc.out) - } - } -} - -func TestStringIn(t *testing.T) { - testcases := []struct { - in1 string - in2 []string - out bool - }{{ - in1: "v1", - in2: []string{"v1", "v2"}, - out: true, - }, { - in1: "v0", - in2: []string{"v1", "v2"}, - }} - for _, tc := range testcases { - out := StringIn(tc.in1, tc.in2...) - if out != tc.out { - t.Errorf("StringIn(%v,%v): %#v, want %#v", tc.in1, tc.in2, out, tc.out) - } - } -} - -func TestExtractSetValues(t *testing.T) { - testcases := []struct { - sql string - out map[SetKey]interface{} - scope string - err string - }{{ - sql: "invalid", - err: "syntax error at position 8 near 'invalid'", - }, { - sql: "select * from t", - err: "ast did not yield *sqlparser.Set: *sqlparser.Select", - }, { - sql: "set autocommit=1+1", - err: "invalid syntax: 1 + 1", - }, { - sql: "set transaction_mode='single'", - out: map[SetKey]interface{}{{Key: "transaction_mode", Scope: "session"}: "single"}, - }, { - sql: "set autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set autocommit=true", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set autocommit=false", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(0)}, - }, { - sql: "set autocommit=on", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: "on"}, - }, { - sql: "set autocommit=off", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: "off"}, - }, { - sql: "set @@global.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "global"}: int64(1)}, - }, { - sql: "set @@global.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "global"}: int64(1)}, - }, { - sql: "set @@session.autocommit=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.`autocommit`=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.'autocommit'=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.\"autocommit\"=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.'\"autocommit'=1", - out: map[SetKey]interface{}{{Key: "\"autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "set @@session.`autocommit'`=1", - out: map[SetKey]interface{}{{Key: "autocommit'", Scope: "session"}: int64(1)}, - }, { - sql: "set AUTOCOMMIT=1", - out: map[SetKey]interface{}{{Key: "autocommit", Scope: "session"}: int64(1)}, - }, { - sql: "SET character_set_results = NULL", - out: map[SetKey]interface{}{{Key: "character_set_results", Scope: "session"}: nil}, - }, { - sql: "SET foo = 0x1234", - err: "invalid value type: 0x1234", - }, { - sql: "SET names utf8", - out: map[SetKey]interface{}{{Key: "names", Scope: "session"}: "utf8"}, - }, { - sql: "SET names ascii collate ascii_bin", - out: map[SetKey]interface{}{{Key: "names", Scope: "session"}: "ascii"}, - }, { - sql: "SET charset default", - out: map[SetKey]interface{}{{Key: "charset", Scope: "session"}: "default"}, - }, { - sql: "SET character set ascii", - out: map[SetKey]interface{}{{Key: "charset", Scope: "session"}: "ascii"}, - }, { - sql: "SET SESSION wait_timeout = 3600", - out: map[SetKey]interface{}{{Key: "wait_timeout", Scope: "session"}: int64(3600)}, - scope: "session", - }, { - sql: "SET GLOBAL wait_timeout = 3600", - out: map[SetKey]interface{}{{Key: "wait_timeout", Scope: "session"}: int64(3600)}, - scope: "global", - }, { - sql: "set session transaction isolation level repeatable read", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "repeatable read"}, - scope: "session", - }, { - sql: "set session transaction isolation level read committed", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "read committed"}, - scope: "session", - }, { - sql: "set session transaction isolation level read uncommitted", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "read uncommitted"}, - scope: "session", - }, { - sql: "set session transaction isolation level serializable", - out: map[SetKey]interface{}{{Key: "tx_isolation", Scope: "session"}: "serializable"}, - scope: "session", - }, { - sql: "set session tx_read_only = 0", - out: map[SetKey]interface{}{{Key: "tx_read_only", Scope: "session"}: int64(0)}, - scope: "session", - }, { - sql: "set session tx_read_only = 1", - out: map[SetKey]interface{}{{Key: "tx_read_only", Scope: "session"}: int64(1)}, - scope: "session", - }, { - sql: "set session sql_safe_updates = 0", - out: map[SetKey]interface{}{{Key: "sql_safe_updates", Scope: "session"}: int64(0)}, - scope: "session", - }, { - sql: "set session sql_safe_updates = 1", - out: map[SetKey]interface{}{{Key: "sql_safe_updates", Scope: "session"}: int64(1)}, - scope: "session", - }} - for _, tcase := range testcases { - out, _, err := ExtractSetValues(tcase.sql) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ExtractSetValues(%s): %v, want '%s'", tcase.sql, err, tcase.err) - } - } else if err != nil { - t.Errorf("ExtractSetValues(%s): %v, want no error", tcase.sql, err) - } - if !reflect.DeepEqual(out, tcase.out) { - t.Errorf("ExtractSetValues(%s): %v, want '%v'", tcase.sql, out, tcase.out) - } - } -} - -func newStrVal(in string) *SQLVal { - return NewStrVal([]byte(in)) -} - -func newIntVal(in string) *SQLVal { - return NewIntVal([]byte(in)) -} - -func newHexVal(in string) *SQLVal { - return NewHexVal([]byte(in)) -} - -func newValArg(in string) *SQLVal { - return NewValArg([]byte(in)) -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go deleted file mode 100644 index c02d882e..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/ast_test.go +++ /dev/null @@ -1,636 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "encoding/json" - "reflect" - "strings" - "testing" - "unsafe" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestAppend(t *testing.T) { - query := "select * from t where a = 1" - tree, err := Parse(query) - if err != nil { - t.Error(err) - } - var b bytes.Buffer - Append(&b, tree) - got := b.String() - want := query - if got != want { - t.Errorf("Append: %s, want %s", got, want) - } - Append(&b, tree) - got = b.String() - want = query + query - if got != want { - t.Errorf("Append: %s, want %s", got, want) - } -} - -func TestSelect(t *testing.T) { - tree, err := Parse("select * from t where a = 1") - if err != nil { - t.Error(err) - } - expr := tree.(*Select).Where.Expr - - sel := &Select{} - sel.AddWhere(expr) - buf := NewTrackedBuffer(nil) - sel.Where.Format(buf) - want := " where a = 1" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel.AddWhere(expr) - buf = NewTrackedBuffer(nil) - sel.Where.Format(buf) - want = " where a = 1 and a = 1" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel = &Select{} - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having a = 1" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having a = 1 and a = 1" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } - - // OR clauses must be parenthesized. - tree, err = Parse("select * from t where a = 1 or b = 1") - if err != nil { - t.Error(err) - } - expr = tree.(*Select).Where.Expr - sel = &Select{} - sel.AddWhere(expr) - buf = NewTrackedBuffer(nil) - sel.Where.Format(buf) - want = " where (a = 1 or b = 1)" - if buf.String() != want { - t.Errorf("where: %q, want %s", buf.String(), want) - } - sel = &Select{} - sel.AddHaving(expr) - buf = NewTrackedBuffer(nil) - sel.Having.Format(buf) - want = " having (a = 1 or b = 1)" - if buf.String() != want { - t.Errorf("having: %q, want %s", buf.String(), want) - } -} - -func TestRemoveHints(t *testing.T) { - for _, query := range []string{ - "select * from t use index (i)", - "select * from t force index (i)", - } { - tree, err := Parse(query) - if err != nil { - t.Fatal(err) - } - sel := tree.(*Select) - sel.From = TableExprs{ - sel.From[0].(*AliasedTableExpr).RemoveHints(), - } - buf := NewTrackedBuffer(nil) - sel.Format(buf) - if got, want := buf.String(), "select * from t"; got != want { - t.Errorf("stripped query: %s, want %s", got, want) - } - } -} - -func TestAddOrder(t *testing.T) { - src, err := Parse("select foo, bar from baz order by foo") - if err != nil { - t.Error(err) - } - order := src.(*Select).OrderBy[0] - dst, err := Parse("select * from t") - if err != nil { - t.Error(err) - } - dst.(*Select).AddOrder(order) - buf := NewTrackedBuffer(nil) - dst.Format(buf) - want := "select * from t order by foo asc" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } - dst, err = Parse("select * from t union select * from s") - if err != nil { - t.Error(err) - } - dst.(*Union).AddOrder(order) - buf = NewTrackedBuffer(nil) - dst.Format(buf) - want = "select * from t union select * from s order by foo asc" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } -} - -func TestSetLimit(t *testing.T) { - src, err := Parse("select foo, bar from baz limit 4") - if err != nil { - t.Error(err) - } - limit := src.(*Select).Limit - dst, err := Parse("select * from t") - if err != nil { - t.Error(err) - } - dst.(*Select).SetLimit(limit) - buf := NewTrackedBuffer(nil) - dst.Format(buf) - want := "select * from t limit 4" - if buf.String() != want { - t.Errorf("limit: %q, want %s", buf.String(), want) - } - dst, err = Parse("select * from t union select * from s") - if err != nil { - t.Error(err) - } - dst.(*Union).SetLimit(limit) - buf = NewTrackedBuffer(nil) - dst.Format(buf) - want = "select * from t union select * from s limit 4" - if buf.String() != want { - t.Errorf("order: %q, want %s", buf.String(), want) - } -} - -func TestWhere(t *testing.T) { - var w *Where - buf := NewTrackedBuffer(nil) - w.Format(buf) - if buf.String() != "" { - t.Errorf("w.Format(nil): %q, want \"\"", buf.String()) - } - w = NewWhere(WhereStr, nil) - buf = NewTrackedBuffer(nil) - w.Format(buf) - if buf.String() != "" { - t.Errorf("w.Format(&Where{nil}: %q, want \"\"", buf.String()) - } -} - -func TestIsAggregate(t *testing.T) { - f := FuncExpr{Name: NewColIdent("avg")} - if !f.IsAggregate() { - t.Error("IsAggregate: false, want true") - } - - f = FuncExpr{Name: NewColIdent("Avg")} - if !f.IsAggregate() { - t.Error("IsAggregate: false, want true") - } - - f = FuncExpr{Name: NewColIdent("foo")} - if f.IsAggregate() { - t.Error("IsAggregate: true, want false") - } -} - -func TestReplaceExpr(t *testing.T) { - tcases := []struct { - in, out string - }{{ - in: "select * from t where (select a from b)", - out: ":a", - }, { - in: "select * from t where (select a from b) and b", - out: ":a and b", - }, { - in: "select * from t where a and (select a from b)", - out: "a and :a", - }, { - in: "select * from t where (select a from b) or b", - out: ":a or b", - }, { - in: "select * from t where a or (select a from b)", - out: "a or :a", - }, { - in: "select * from t where not (select a from b)", - out: "not :a", - }, { - in: "select * from t where ((select a from b))", - out: "(:a)", - }, { - in: "select * from t where (select a from b) = 1", - out: ":a = 1", - }, { - in: "select * from t where a = (select a from b)", - out: "a = :a", - }, { - in: "select * from t where a like b escape (select a from b)", - out: "a like b escape :a", - }, { - in: "select * from t where (select a from b) between a and b", - out: ":a between a and b", - }, { - in: "select * from t where a between (select a from b) and b", - out: "a between :a and b", - }, { - in: "select * from t where a between b and (select a from b)", - out: "a between b and :a", - }, { - in: "select * from t where (select a from b) is null", - out: ":a is null", - }, { - // exists should not replace. - in: "select * from t where exists (select a from b)", - out: "exists (select a from b)", - }, { - in: "select * from t where a in ((select a from b), 1)", - out: "a in (:a, 1)", - }, { - in: "select * from t where a in (0, (select a from b), 1)", - out: "a in (0, :a, 1)", - }, { - in: "select * from t where (select a from b) + 1", - out: ":a + 1", - }, { - in: "select * from t where 1+(select a from b)", - out: "1 + :a", - }, { - in: "select * from t where -(select a from b)", - out: "-:a", - }, { - in: "select * from t where interval (select a from b) aa", - out: "interval :a aa", - }, { - in: "select * from t where (select a from b) collate utf8", - out: ":a collate utf8", - }, { - in: "select * from t where func((select a from b), 1)", - out: "func(:a, 1)", - }, { - in: "select * from t where func(1, (select a from b), 1)", - out: "func(1, :a, 1)", - }, { - in: "select * from t where group_concat((select a from b), 1 order by a)", - out: "group_concat(:a, 1 order by a asc)", - }, { - in: "select * from t where group_concat(1 order by (select a from b), a)", - out: "group_concat(1 order by :a asc, a asc)", - }, { - in: "select * from t where group_concat(1 order by a, (select a from b))", - out: "group_concat(1 order by a asc, :a asc)", - }, { - in: "select * from t where substr(a, (select a from b), b)", - out: "substr(a, :a, b)", - }, { - in: "select * from t where substr(a, b, (select a from b))", - out: "substr(a, b, :a)", - }, { - in: "select * from t where convert((select a from b), json)", - out: "convert(:a, json)", - }, { - in: "select * from t where convert((select a from b) using utf8)", - out: "convert(:a using utf8)", - }, { - in: "select * from t where match((select a from b), 1) against (a)", - out: "match(:a, 1) against (a)", - }, { - in: "select * from t where match(1, (select a from b), 1) against (a)", - out: "match(1, :a, 1) against (a)", - }, { - in: "select * from t where match(1, a, 1) against ((select a from b))", - out: "match(1, a, 1) against (:a)", - }, { - in: "select * from t where case (select a from b) when a then b when b then c else d end", - out: "case :a when a then b when b then c else d end", - }, { - in: "select * from t where case a when (select a from b) then b when b then c else d end", - out: "case a when :a then b when b then c else d end", - }, { - in: "select * from t where case a when b then (select a from b) when b then c else d end", - out: "case a when b then :a when b then c else d end", - }, { - in: "select * from t where case a when b then c when (select a from b) then c else d end", - out: "case a when b then c when :a then c else d end", - }, { - in: "select * from t where case a when b then c when d then c else (select a from b) end", - out: "case a when b then c when d then c else :a end", - }} - to := NewValArg([]byte(":a")) - for _, tcase := range tcases { - tree, err := Parse(tcase.in) - if err != nil { - t.Fatal(err) - } - var from *Subquery - _ = Walk(func(node SQLNode) (kontinue bool, err error) { - if sq, ok := node.(*Subquery); ok { - from = sq - return false, nil - } - return true, nil - }, tree) - if from == nil { - t.Fatalf("from is nil for %s", tcase.in) - } - expr := ReplaceExpr(tree.(*Select).Where.Expr, from, to) - got := String(expr) - if tcase.out != got { - t.Errorf("ReplaceExpr(%s): %s, want %s", tcase.in, got, tcase.out) - } - } -} - -func TestExprFromValue(t *testing.T) { - tcases := []struct { - in sqltypes.Value - out SQLNode - err string - }{{ - in: sqltypes.NULL, - out: &NullVal{}, - }, { - in: sqltypes.NewInt64(1), - out: NewIntVal([]byte("1")), - }, { - in: sqltypes.NewFloat64(1.1), - out: NewFloatVal([]byte("1.1")), - }, { - in: sqltypes.MakeTrusted(sqltypes.Decimal, []byte("1.1")), - out: NewFloatVal([]byte("1.1")), - }, { - in: sqltypes.NewVarChar("aa"), - out: NewStrVal([]byte("aa")), - }, { - in: sqltypes.MakeTrusted(sqltypes.Expression, []byte("rand()")), - err: "cannot convert value EXPRESSION(rand()) to AST", - }} - for _, tcase := range tcases { - got, err := ExprFromValue(tcase.in) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ExprFromValue(%v) err: %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Error(err) - } - if got, want := got, tcase.out; !reflect.DeepEqual(got, want) { - t.Errorf("ExprFromValue(%v): %v, want %s", tcase.in, got, want) - } - } -} - -func TestColNameEqual(t *testing.T) { - var c1, c2 *ColName - if c1.Equal(c2) { - t.Error("nil columns equal, want unequal") - } - c1 = &ColName{ - Name: NewColIdent("aa"), - } - c2 = &ColName{ - Name: NewColIdent("bb"), - } - if c1.Equal(c2) { - t.Error("columns equal, want unequal") - } - c2.Name = NewColIdent("aa") - if !c1.Equal(c2) { - t.Error("columns unequal, want equal") - } -} - -func TestColIdent(t *testing.T) { - str := NewColIdent("Ab") - if str.String() != "Ab" { - t.Errorf("String=%s, want Ab", str.String()) - } - if str.String() != "Ab" { - t.Errorf("Val=%s, want Ab", str.String()) - } - if str.Lowered() != "ab" { - t.Errorf("Val=%s, want ab", str.Lowered()) - } - if !str.Equal(NewColIdent("aB")) { - t.Error("str.Equal(NewColIdent(aB))=false, want true") - } - if !str.EqualString("ab") { - t.Error("str.EqualString(ab)=false, want true") - } - str = NewColIdent("") - if str.Lowered() != "" { - t.Errorf("Val=%s, want \"\"", str.Lowered()) - } -} - -func TestColIdentMarshal(t *testing.T) { - str := NewColIdent("Ab") - b, err := json.Marshal(str) - if err != nil { - t.Fatal(err) - } - got := string(b) - want := `"Ab"` - if got != want { - t.Errorf("json.Marshal()= %s, want %s", got, want) - } - var out ColIdent - if err := json.Unmarshal(b, &out); err != nil { - t.Errorf("Unmarshal err: %v, want nil", err) - } - if !reflect.DeepEqual(out, str) { - t.Errorf("Unmarshal: %v, want %v", out, str) - } -} - -func TestColIdentSize(t *testing.T) { - size := unsafe.Sizeof(NewColIdent("")) - want := 2 * unsafe.Sizeof("") - if size != want { - t.Errorf("Size of ColIdent: %d, want 32", want) - } -} - -func TestTableIdentMarshal(t *testing.T) { - str := NewTableIdent("Ab") - b, err := json.Marshal(str) - if err != nil { - t.Fatal(err) - } - got := string(b) - want := `"Ab"` - if got != want { - t.Errorf("json.Marshal()= %s, want %s", got, want) - } - var out TableIdent - if err := json.Unmarshal(b, &out); err != nil { - t.Errorf("Unmarshal err: %v, want nil", err) - } - if !reflect.DeepEqual(out, str) { - t.Errorf("Unmarshal: %v, want %v", out, str) - } -} - -func TestHexDecode(t *testing.T) { - testcase := []struct { - in, out string - }{{ - in: "313233", - out: "123", - }, { - in: "ag", - out: "encoding/hex: invalid byte: U+0067 'g'", - }, { - in: "777", - out: "encoding/hex: odd length hex string", - }} - for _, tc := range testcase { - out, err := newHexVal(tc.in).HexDecode() - if err != nil { - if err.Error() != tc.out { - t.Errorf("Decode(%q): %v, want %s", tc.in, err, tc.out) - } - continue - } - if !bytes.Equal(out, []byte(tc.out)) { - t.Errorf("Decode(%q): %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestCompliantName(t *testing.T) { - testcases := []struct { - in, out string - }{{ - in: "aa", - out: "aa", - }, { - in: "1a", - out: "_a", - }, { - in: "a1", - out: "a1", - }, { - in: "a.b", - out: "a_b", - }, { - in: ".ab", - out: "_ab", - }} - for _, tc := range testcases { - out := NewColIdent(tc.in).CompliantName() - if out != tc.out { - t.Errorf("ColIdent(%s).CompliantNamt: %s, want %s", tc.in, out, tc.out) - } - out = NewTableIdent(tc.in).CompliantName() - if out != tc.out { - t.Errorf("TableIdent(%s).CompliantNamt: %s, want %s", tc.in, out, tc.out) - } - } -} - -func TestColumns_FindColumn(t *testing.T) { - cols := Columns{NewColIdent("a"), NewColIdent("c"), NewColIdent("b"), NewColIdent("0")} - - testcases := []struct { - in string - out int - }{{ - in: "a", - out: 0, - }, { - in: "b", - out: 2, - }, - { - in: "0", - out: 3, - }, - { - in: "f", - out: -1, - }} - - for _, tc := range testcases { - val := cols.FindColumn(NewColIdent(tc.in)) - if val != tc.out { - t.Errorf("FindColumn(%s): %d, want %d", tc.in, val, tc.out) - } - } -} - -func TestSplitStatementToPieces(t *testing.T) { - testcases := []struct { - input string - output string - }{{ - input: "select * from table", - }, { - input: "select * from table1; select * from table2;", - output: "select * from table1; select * from table2", - }, { - input: "select * from /* comment ; */ table;", - output: "select * from /* comment ; */ table", - }, { - input: "select * from table where semi = ';';", - output: "select * from table where semi = ';'", - }, { - input: "select * from table1;--comment;\nselect * from table2;", - output: "select * from table1;--comment;\nselect * from table2", - }, { - input: "CREATE TABLE `total_data` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', " + - "`region` varchar(32) NOT NULL COMMENT 'region name, like zh; th; kepler'," + - "`data_size` bigint NOT NULL DEFAULT '0' COMMENT 'data size;'," + - "`createtime` datetime NOT NULL DEFAULT NOW() COMMENT 'create time;'," + - "`comment` varchar(100) NOT NULL DEFAULT '' COMMENT 'comment'," + - "PRIMARY KEY (`id`))", - }} - - for _, tcase := range testcases { - if tcase.output == "" { - tcase.output = tcase.input - } - - stmtPieces, err := SplitStatementToPieces(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - - out := strings.Join(stmtPieces, ";") - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go deleted file mode 100644 index 430293bf..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/comments_test.go +++ /dev/null @@ -1,375 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "testing" -) - -func TestSplitComments(t *testing.T) { - var testCases = []struct { - input, outSQL, outLeadingComments, outTrailingComments string - }{{ - input: "/", - outSQL: "/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "*/", - outSQL: "*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "/*/", - outSQL: "/*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "a*/", - outSQL: "a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "*a*/", - outSQL: "*a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "**a*/", - outSQL: "**a*/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: "/*b**a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*b**a*/", - }, { - input: "/*a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*a*/", - }, { - input: "/**/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/**/", - }, { - input: "/*b*/ /*a*/", - outSQL: "", - outLeadingComments: "", - outTrailingComments: "/*b*/ /*a*/", - }, { - input: "/* before */ foo /* bar */", - outSQL: "foo", - outLeadingComments: "/* before */ ", - outTrailingComments: " /* bar */", - }, { - input: "/* before1 */ /* before2 */ foo /* after1 */ /* after2 */", - outSQL: "foo", - outLeadingComments: "/* before1 */ /* before2 */ ", - outTrailingComments: " /* after1 */ /* after2 */", - }, { - input: "/** before */ foo /** bar */", - outSQL: "foo", - outLeadingComments: "/** before */ ", - outTrailingComments: " /** bar */", - }, { - input: "/*** before */ foo /*** bar */", - outSQL: "foo", - outLeadingComments: "/*** before */ ", - outTrailingComments: " /*** bar */", - }, { - input: "/** before **/ foo /** bar **/", - outSQL: "foo", - outLeadingComments: "/** before **/ ", - outTrailingComments: " /** bar **/", - }, { - input: "/*** before ***/ foo /*** bar ***/", - outSQL: "foo", - outLeadingComments: "/*** before ***/ ", - outTrailingComments: " /*** bar ***/", - }, { - input: " /*** before ***/ foo /*** bar ***/ ", - outSQL: "foo", - outLeadingComments: "/*** before ***/ ", - outTrailingComments: " /*** bar ***/", - }, { - input: "*** bar ***/", - outSQL: "*** bar ***/", - outLeadingComments: "", - outTrailingComments: "", - }, { - input: " foo ", - outSQL: "foo", - outLeadingComments: "", - outTrailingComments: "", - }} - for _, testCase := range testCases { - gotSQL, gotComments := SplitMarginComments(testCase.input) - gotLeadingComments, gotTrailingComments := gotComments.Leading, gotComments.Trailing - - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - if gotLeadingComments != testCase.outLeadingComments { - t.Errorf("test input: '%s', got LeadingComments\n%+v, want\n%+v", testCase.input, gotLeadingComments, testCase.outLeadingComments) - } - if gotTrailingComments != testCase.outTrailingComments { - t.Errorf("test input: '%s', got TrailingComments\n%+v, want\n%+v", testCase.input, gotTrailingComments, testCase.outTrailingComments) - } - } -} - -func TestStripLeadingComments(t *testing.T) { - var testCases = []struct { - input, outSQL string - }{{ - input: "/", - outSQL: "/", - }, { - input: "*/", - outSQL: "*/", - }, { - input: "/*/", - outSQL: "/*/", - }, { - input: "/*a", - outSQL: "/*a", - }, { - input: "/*a*", - outSQL: "/*a*", - }, { - input: "/*a**", - outSQL: "/*a**", - }, { - input: "/*b**a*/", - outSQL: "", - }, { - input: "/*a*/", - outSQL: "", - }, { - input: "/**/", - outSQL: "", - }, { - input: "/*!*/", - outSQL: "/*!*/", - }, { - input: "/*!a*/", - outSQL: "/*!a*/", - }, { - input: "/*b*/ /*a*/", - outSQL: "", - }, { - input: `/*b*/ --foo -bar`, - outSQL: "bar", - }, { - input: "foo /* bar */", - outSQL: "foo /* bar */", - }, { - input: "/* foo */ bar", - outSQL: "bar", - }, { - input: "-- /* foo */ bar", - outSQL: "-- /* foo */ bar", - }, { - input: "foo -- bar */", - outSQL: "foo -- bar */", - }, { - input: `/* -foo */ bar`, - outSQL: "bar", - }, { - input: `-- foo bar -a`, - outSQL: "a", - }, { - input: `-- foo bar`, - outSQL: "-- foo bar", - }} - for _, testCase := range testCases { - gotSQL := StripLeadingComments(testCase.input) - - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - } -} - -func TestExtractMysqlComment(t *testing.T) { - var testCases = []struct { - input, outSQL, outVersion string - }{{ - input: "/*!50708SET max_execution_time=5000 */", - outSQL: "SET max_execution_time=5000", - outVersion: "50708", - }, { - input: "/*!50708 SET max_execution_time=5000*/", - outSQL: "SET max_execution_time=5000", - outVersion: "50708", - }, { - input: "/*!50708* from*/", - outSQL: "* from", - outVersion: "50708", - }, { - input: "/*! SET max_execution_time=5000*/", - outSQL: "SET max_execution_time=5000", - outVersion: "", - }} - for _, testCase := range testCases { - gotVersion, gotSQL := ExtractMysqlComment(testCase.input) - - if gotVersion != testCase.outVersion { - t.Errorf("test input: '%s', got version\n%+v, want\n%+v", testCase.input, gotVersion, testCase.outVersion) - } - if gotSQL != testCase.outSQL { - t.Errorf("test input: '%s', got SQL\n%+v, want\n%+v", testCase.input, gotSQL, testCase.outSQL) - } - } -} - -func TestExtractCommentDirectives(t *testing.T) { - var testCases = []struct { - input string - vals CommentDirectives - }{{ - input: "", - vals: nil, - }, { - input: "/* not a vt comment */", - vals: nil, - }, { - input: "/*vt+ */", - vals: CommentDirectives{}, - }, { - input: "/*vt+ SINGLE_OPTION */", - vals: CommentDirectives{ - "SINGLE_OPTION": true, - }, - }, { - input: "/*vt+ ONE_OPT TWO_OPT */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": true, - }, - }, { - input: "/*vt+ ONE_OPT */ /* other comment */ /*vt+ TWO_OPT */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": true, - }, - }, { - input: "/*vt+ ONE_OPT=abc TWO_OPT=def */", - vals: CommentDirectives{ - "ONE_OPT": "abc", - "TWO_OPT": "def", - }, - }, { - input: "/*vt+ ONE_OPT=true TWO_OPT=false */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": false, - }, - }, { - input: "/*vt+ ONE_OPT=true TWO_OPT=\"false\" */", - vals: CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": "\"false\"", - }, - }, { - input: "/*vt+ RANGE_OPT=[a:b] ANOTHER ANOTHER_WITH_VALEQ=val= AND_ONE_WITH_EQ== */", - vals: CommentDirectives{ - "RANGE_OPT": "[a:b]", - "ANOTHER": true, - "ANOTHER_WITH_VALEQ": "val=", - "AND_ONE_WITH_EQ": "=", - }, - }} - - for _, testCase := range testCases { - sql := "select " + testCase.input + " 1 from dual" - stmt, _ := Parse(sql) - comments := stmt.(*Select).Comments - vals := ExtractCommentDirectives(comments) - - if !reflect.DeepEqual(vals, testCase.vals) { - t.Errorf("test input: '%v', got vals:\n%+v, want\n%+v", testCase.input, vals, testCase.vals) - } - } - - d := CommentDirectives{ - "ONE_OPT": true, - "TWO_OPT": false, - "three": 1, - "four": 2, - "five": 0, - "six": "true", - } - - if !d.IsSet("ONE_OPT") { - t.Errorf("d.IsSet(ONE_OPT) should be true") - } - - if d.IsSet("TWO_OPT") { - t.Errorf("d.IsSet(TWO_OPT) should be false") - } - - if !d.IsSet("three") { - t.Errorf("d.IsSet(three) should be true") - } - - if d.IsSet("four") { - t.Errorf("d.IsSet(four) should be false") - } - - if d.IsSet("five") { - t.Errorf("d.IsSet(five) should be false") - } - - if d.IsSet("six") { - t.Errorf("d.IsSet(six) should be false") - } -} - -func TestSkipQueryPlanCacheDirective(t *testing.T) { - stmt, _ := Parse("insert /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ into user(id) values (1), (2)") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("insert into user(id) values (1), (2)") - if SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be false") - } - - stmt, _ = Parse("update /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ users set name=1") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("select /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ * from users") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } - - stmt, _ = Parse("delete /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ from users") - if !SkipQueryPlanCacheDirective(stmt) { - t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true") - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go deleted file mode 100644 index 6f3b102f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/bytes2/buffer_test.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package bytes2 - -import "testing" - -func TestBuffer(t *testing.T) { - b := NewBuffer(nil) - b.Write([]byte("ab")) - b.WriteString("cd") - b.WriteByte('e') - want := "abcde" - if got := string(b.Bytes()); got != want { - t.Errorf("b.Bytes(): %s, want %s", got, want) - } - if got := b.String(); got != want { - t.Errorf("b.String(): %s, want %s", got, want) - } - if got := b.Len(); got != 5 { - t.Errorf("b.Len(): %d, want 5", got) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go deleted file mode 100644 index d8208c6f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/hack/hack_test.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package hack - -import "testing" - -func TestStringArena(t *testing.T) { - sarena := NewStringArena(10) - - s0 := sarena.NewString(nil) - checkint(t, len(sarena.buf), 0) - checkint(t, sarena.SpaceLeft(), 10) - checkstring(t, s0, "") - - s1 := sarena.NewString([]byte("01234")) - checkint(t, len(sarena.buf), 5) - checkint(t, sarena.SpaceLeft(), 5) - checkstring(t, s1, "01234") - - s2 := sarena.NewString([]byte("5678")) - checkint(t, len(sarena.buf), 9) - checkint(t, sarena.SpaceLeft(), 1) - checkstring(t, s2, "5678") - - // s3 will be allocated outside of sarena - s3 := sarena.NewString([]byte("ab")) - checkint(t, len(sarena.buf), 9) - checkint(t, sarena.SpaceLeft(), 1) - checkstring(t, s3, "ab") - - // s4 should still fit in sarena - s4 := sarena.NewString([]byte("9")) - checkint(t, len(sarena.buf), 10) - checkint(t, sarena.SpaceLeft(), 0) - checkstring(t, s4, "9") - - sarena.buf[0] = 'A' - checkstring(t, s1, "A1234") - - sarena.buf[5] = 'B' - checkstring(t, s2, "B678") - - sarena.buf[9] = 'C' - // s3 will not change - checkstring(t, s3, "ab") - checkstring(t, s4, "C") - checkstring(t, sarena.str, "A1234B678C") -} - -func checkstring(t *testing.T, actual, expected string) { - if actual != expected { - t.Errorf("received %s, expecting %s", actual, expected) - } -} - -func checkint(t *testing.T, actual, expected int) { - if actual != expected { - t.Errorf("received %d, expecting %d", actual, expected) - } -} - -func TestByteToString(t *testing.T) { - v1 := []byte("1234") - if s := String(v1); s != "1234" { - t.Errorf("String(\"1234\"): %q, want 1234", s) - } - - v1 = []byte("") - if s := String(v1); s != "" { - t.Errorf("String(\"\"): %q, want empty", s) - } - - v1 = nil - if s := String(v1); s != "" { - t.Errorf("String(\"\"): %q, want empty", s) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go deleted file mode 100644 index ca0636c8..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/bind_variables_test.go +++ /dev/null @@ -1,553 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestProtoConversions(t *testing.T) { - v := TestValue(Int64, "1") - got := ValueToProto(v) - want := &querypb.Value{Type: Int64, Value: []byte("1")} - if !reflect.DeepEqual(got, want) { - t.Errorf("ValueToProto: %v, want %v", got, want) - } - gotback := ProtoToValue(got) - if !reflect.DeepEqual(gotback, v) { - t.Errorf("ProtoToValue: %v, want %v", gotback, v) - } -} - -func TestBuildBindVariables(t *testing.T) { - tcases := []struct { - in map[string]interface{} - out map[string]*querypb.BindVariable - err string - }{{ - in: nil, - out: nil, - }, { - in: map[string]interface{}{ - "k": int64(1), - }, - out: map[string]*querypb.BindVariable{ - "k": Int64BindVariable(1), - }, - }, { - in: map[string]interface{}{ - "k": byte(1), - }, - err: "k: type uint8 not supported as bind var: 1", - }} - for _, tcase := range tcases { - bindVars, err := BuildBindVariables(tcase.in) - if err != nil { - if err.Error() != tcase.err { - t.Errorf("MapToBindVars(%v) error: %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if tcase.err != "" { - t.Errorf("MapToBindVars(%v) error: nil, want %s", tcase.in, tcase.err) - continue - } - if !BindVariablesEqual(bindVars, tcase.out) { - t.Errorf("MapToBindVars(%v): %v, want %s", tcase.in, bindVars, tcase.out) - } - } -} - -func TestBuildBindVariable(t *testing.T) { - tcases := []struct { - in interface{} - out *querypb.BindVariable - err string - }{{ - in: "aa", - out: &querypb.BindVariable{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, - }, { - in: []byte("aa"), - out: &querypb.BindVariable{ - Type: querypb.Type_VARBINARY, - Value: []byte("aa"), - }, - }, { - in: int(1), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: int64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: uint64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, - }, { - in: float64(1), - out: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("1"), - }, - }, { - in: nil, - out: NullBindVariable, - }, { - in: MakeTrusted(Int64, []byte("1")), - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - out: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: []interface{}{"aa", int64(1)}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, { - Type: querypb.Type_INT64, - Value: []byte("1"), - }}, - }, - }, { - in: []string{"aa", "bb"}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARCHAR, - Value: []byte("aa"), - }, { - Type: querypb.Type_VARCHAR, - Value: []byte("bb"), - }}, - }, - }, { - in: [][]byte{[]byte("aa"), []byte("bb")}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_VARBINARY, - Value: []byte("aa"), - }, { - Type: querypb.Type_VARBINARY, - Value: []byte("bb"), - }}, - }, - }, { - in: []int{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, { - Type: querypb.Type_INT64, - Value: []byte("2"), - }}, - }, - }, { - in: []int64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, { - Type: querypb.Type_INT64, - Value: []byte("2"), - }}, - }, - }, { - in: []uint64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, { - Type: querypb.Type_UINT64, - Value: []byte("2"), - }}, - }, - }, { - in: []float64{1, 2}, - out: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_FLOAT64, - Value: []byte("1"), - }, { - Type: querypb.Type_FLOAT64, - Value: []byte("2"), - }}, - }, - }, { - in: byte(1), - err: "type uint8 not supported as bind var: 1", - }, { - in: []interface{}{1, byte(1)}, - err: "type uint8 not supported as bind var: 1", - }} - for _, tcase := range tcases { - bv, err := BuildBindVariable(tcase.in) - if err != nil { - if err.Error() != tcase.err { - t.Errorf("ToBindVar(%T(%v)) error: %v, want %s", tcase.in, tcase.in, err, tcase.err) - } - continue - } - if tcase.err != "" { - t.Errorf("ToBindVar(%T(%v)) error: nil, want %s", tcase.in, tcase.in, tcase.err) - continue - } - if !reflect.DeepEqual(bv, tcase.out) { - t.Errorf("ToBindVar(%T(%v)): %v, want %s", tcase.in, tcase.in, bv, tcase.out) - } - } -} - -func TestValidateBindVarables(t *testing.T) { - tcases := []struct { - in map[string]*querypb.BindVariable - err string - }{{ - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, - err: "", - }, { - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_INT64, - Value: []byte("a"), - }, - }, - err: `v: strconv.ParseInt: parsing "a": invalid syntax`, - }, { - in: map[string]*querypb.BindVariable{ - "v": { - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: Int64, - Value: []byte("a"), - }}, - }, - }, - err: `v: strconv.ParseInt: parsing "a": invalid syntax`, - }} - for _, tcase := range tcases { - err := ValidateBindVariables(tcase.in) - if tcase.err != "" { - if err == nil || err.Error() != tcase.err { - t.Errorf("ValidateBindVars(%v): %v, want %s", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Errorf("ValidateBindVars(%v): %v, want nil", tcase.in, err) - } - } -} - -func TestValidateBindVariable(t *testing.T) { - testcases := []struct { - in *querypb.BindVariable - err string - }{{ - in: &querypb.BindVariable{ - Type: querypb.Type_INT8, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT16, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT24, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT32, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT8, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT16, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT24, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT32, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT32, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DECIMAL, - Value: []byte("1.00"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TIMESTAMP, - Value: []byte("2012-02-24 23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DATE, - Value: []byte("2012-02-24"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TIME, - Value: []byte("23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_DATETIME, - Value: []byte("2012-02-24 23:19:43"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_YEAR, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TEXT, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BLOB, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_VARCHAR, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BINARY, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_CHAR, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_BIT, - Value: []byte("1"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_ENUM, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_SET, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_VARBINARY, - Value: []byte("a"), - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte(InvalidNeg), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_INT64, - Value: []byte(InvalidPos), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte("-1"), - }, - err: "invalid syntax", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_UINT64, - Value: []byte(InvalidPos), - }, - err: "out of range", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_FLOAT64, - Value: []byte("a"), - }, - err: "invalid syntax", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_EXPRESSION, - Value: []byte("a"), - }, - err: "invalid type specified for MakeValue: EXPRESSION", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_INT64, - Value: []byte("1"), - }}, - }, - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - }, - err: "empty tuple is not allowed", - }, { - in: &querypb.BindVariable{ - Type: querypb.Type_TUPLE, - Values: []*querypb.Value{{ - Type: querypb.Type_TUPLE, - }}, - }, - err: "tuple not allowed inside another tuple", - }} - for _, tcase := range testcases { - err := ValidateBindVariable(tcase.in) - if tcase.err != "" { - if err == nil || !strings.Contains(err.Error(), tcase.err) { - t.Errorf("ValidateBindVar(%v) error: %v, must contain %v", tcase.in, err, tcase.err) - } - continue - } - if err != nil { - t.Errorf("ValidateBindVar(%v) error: %v", tcase.in, err) - } - } - - // Special case: nil bind var. - err := ValidateBindVariable(nil) - want := "bind variable is nil" - if err == nil || err.Error() != want { - t.Errorf("ValidateBindVar(nil) error: %v, want %s", err, want) - } -} - -func TestBindVariableToValue(t *testing.T) { - v, err := BindVariableToValue(Int64BindVariable(1)) - if err != nil { - t.Error(err) - } - want := MakeTrusted(querypb.Type_INT64, []byte("1")) - if !reflect.DeepEqual(v, want) { - t.Errorf("BindVarToValue(1): %v, want %v", v, want) - } - - v, err = BindVariableToValue(&querypb.BindVariable{Type: querypb.Type_TUPLE}) - wantErr := "cannot convert a TUPLE bind var into a value" - if err == nil || err.Error() != wantErr { - t.Errorf(" BindVarToValue(TUPLE): %v, want %s", err, wantErr) - } -} - -func TestBindVariablesEqual(t *testing.T) { - bv1 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - bv2 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - bv3 := map[string]*querypb.BindVariable{ - "k": { - Type: querypb.Type_INT64, - Value: []byte("1"), - }, - } - if !BindVariablesEqual(bv1, bv2) { - t.Errorf("%v != %v, want equal", bv1, bv2) - } - if !BindVariablesEqual(bv1, bv3) { - t.Errorf("%v = %v, want not equal", bv1, bv3) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go deleted file mode 100644 index ea85c9c6..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/plan_value_test.go +++ /dev/null @@ -1,319 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestPlanValueIsNull(t *testing.T) { - tcases := []struct { - in PlanValue - out bool - }{{ - in: PlanValue{}, - out: true, - }, { - in: PlanValue{Key: "aa"}, - out: false, - }, { - in: PlanValue{Value: NewVarBinary("aa")}, - out: false, - }, { - in: PlanValue{ListKey: "aa"}, - out: false, - }, { - in: PlanValue{Values: []PlanValue{}}, - out: false, - }} - for _, tc := range tcases { - got := tc.in.IsNull() - if got != tc.out { - t.Errorf("IsNull(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestPlanValueIsList(t *testing.T) { - tcases := []struct { - in PlanValue - out bool - }{{ - in: PlanValue{}, - out: false, - }, { - in: PlanValue{Key: "aa"}, - out: false, - }, { - in: PlanValue{Value: NewVarBinary("aa")}, - out: false, - }, { - in: PlanValue{ListKey: "aa"}, - out: true, - }, { - in: PlanValue{Values: []PlanValue{}}, - out: true, - }} - for _, tc := range tcases { - got := tc.in.IsList() - if got != tc.out { - t.Errorf("IsList(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveRows(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - strValue := MakeTrusted(VarChar, []byte("aa")) - tcases := []struct { - in []PlanValue - out [][]Value - err string - }{{ - // Simple cases. - in: []PlanValue{ - {Key: "int"}, - }, - out: [][]Value{ - {intValue}, - }, - }, { - in: []PlanValue{ - {Value: intValue}, - }, - out: [][]Value{ - {intValue}, - }, - }, { - in: []PlanValue{ - {ListKey: "intstr"}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{ - {Values: []PlanValue{{Value: intValue}, {Value: strValue}}}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{ - {Values: []PlanValue{{Key: "int"}, {Value: strValue}}}, - }, - out: [][]Value{ - {intValue}, - {strValue}, - }, - }, { - in: []PlanValue{{}}, - out: [][]Value{ - {NULL}, - }, - }, { - // Cases with varying rowcounts. - // All types of input.. - in: []PlanValue{ - {Key: "int"}, - {Value: strValue}, - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {intValue, strValue, intValue, strValue}, - {intValue, strValue, strValue, intValue}, - }, - }, { - // list, val, list. - in: []PlanValue{ - {Value: strValue}, - {Key: "int"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {strValue, intValue, strValue}, - {strValue, intValue, intValue}, - }, - }, { - // list, list - in: []PlanValue{ - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}, {Value: intValue}}}, - }, - out: [][]Value{ - {intValue, strValue}, - {strValue, intValue}, - }, - }, { - // Error cases - in: []PlanValue{ - {ListKey: "intstr"}, - {Values: []PlanValue{{Value: strValue}}}, - }, - err: "mismatch in number of column values", - }, { - // This is a different code path for a similar validation. - in: []PlanValue{ - {Values: []PlanValue{{Value: strValue}}}, - {ListKey: "intstr"}, - }, - err: "mismatch in number of column values", - }, { - in: []PlanValue{ - {Key: "absent"}, - }, - err: "missing bind var", - }, { - in: []PlanValue{ - {ListKey: "absent"}, - }, - err: "missing bind var", - }, { - in: []PlanValue{ - {Values: []PlanValue{{Key: "absent"}}}, - }, - err: "missing bind var", - }} - - for _, tc := range tcases { - got, err := ResolveRows(tc.in, testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveRows(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveRows(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveRows(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveList(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - strValue := MakeTrusted(VarChar, []byte("aa")) - tcases := []struct { - in PlanValue - out []Value - err string - }{{ - in: PlanValue{ListKey: "intstr"}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{Values: []PlanValue{{Value: intValue}, {Value: strValue}}}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{Values: []PlanValue{{Key: "int"}, {Value: strValue}}}, - out: []Value{intValue, strValue}, - }, { - in: PlanValue{ListKey: "absent"}, - err: "missing bind var", - }, { - in: PlanValue{Values: []PlanValue{{Key: "absent"}, {Value: strValue}}}, - err: "missing bind var", - }, { - in: PlanValue{ListKey: "int"}, - err: "single value was supplied for TUPLE bind var", - }, { - in: PlanValue{Key: "int"}, - err: "a single value was supplied where a list was expected", - }} - - for _, tc := range tcases { - got, err := tc.in.ResolveList(testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveList(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveList(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveList(%v): %v, want %v", tc.in, got, tc.out) - } - } -} - -func TestResolveValue(t *testing.T) { - testBindVars := map[string]*querypb.BindVariable{ - "int": Int64BindVariable(10), - "intstr": TestBindVariable([]interface{}{10, "aa"}), - } - intValue := MakeTrusted(Int64, []byte("10")) - tcases := []struct { - in PlanValue - out Value - err string - }{{ - in: PlanValue{Key: "int"}, - out: intValue, - }, { - in: PlanValue{Value: intValue}, - out: intValue, - }, { - in: PlanValue{}, - out: NULL, - }, { - in: PlanValue{Key: "absent"}, - err: "missing bind var", - }, { - in: PlanValue{Key: "intstr"}, - err: "TUPLE was supplied for single value bind var", - }, { - in: PlanValue{ListKey: "intstr"}, - err: "a list was supplied where a single value was expected", - }} - - for _, tc := range tcases { - got, err := tc.in.ResolveValue(testBindVars) - if err != nil { - if !strings.Contains(err.Error(), tc.err) { - t.Errorf("ResolveValue(%v) error: %v, want '%s'", tc.in, err, tc.err) - } - continue - } - if tc.err != "" { - t.Errorf("ResolveValue(%v) error: nil, want '%s'", tc.in, tc.err) - continue - } - if !reflect.DeepEqual(got, tc.out) { - t.Errorf("ResolveValue(%v): %v, want %v", tc.in, got, tc.out) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go deleted file mode 100644 index 613fcda1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/type_test.go +++ /dev/null @@ -1,414 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestTypeValues(t *testing.T) { - testcases := []struct { - defined querypb.Type - expected int - }{{ - defined: Null, - expected: 0, - }, { - defined: Int8, - expected: 1 | flagIsIntegral, - }, { - defined: Uint8, - expected: 2 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int16, - expected: 3 | flagIsIntegral, - }, { - defined: Uint16, - expected: 4 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int24, - expected: 5 | flagIsIntegral, - }, { - defined: Uint24, - expected: 6 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int32, - expected: 7 | flagIsIntegral, - }, { - defined: Uint32, - expected: 8 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Int64, - expected: 9 | flagIsIntegral, - }, { - defined: Uint64, - expected: 10 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Float32, - expected: 11 | flagIsFloat, - }, { - defined: Float64, - expected: 12 | flagIsFloat, - }, { - defined: Timestamp, - expected: 13 | flagIsQuoted, - }, { - defined: Date, - expected: 14 | flagIsQuoted, - }, { - defined: Time, - expected: 15 | flagIsQuoted, - }, { - defined: Datetime, - expected: 16 | flagIsQuoted, - }, { - defined: Year, - expected: 17 | flagIsIntegral | flagIsUnsigned, - }, { - defined: Decimal, - expected: 18, - }, { - defined: Text, - expected: 19 | flagIsQuoted | flagIsText, - }, { - defined: Blob, - expected: 20 | flagIsQuoted | flagIsBinary, - }, { - defined: VarChar, - expected: 21 | flagIsQuoted | flagIsText, - }, { - defined: VarBinary, - expected: 22 | flagIsQuoted | flagIsBinary, - }, { - defined: Char, - expected: 23 | flagIsQuoted | flagIsText, - }, { - defined: Binary, - expected: 24 | flagIsQuoted | flagIsBinary, - }, { - defined: Bit, - expected: 25 | flagIsQuoted, - }, { - defined: Enum, - expected: 26 | flagIsQuoted, - }, { - defined: Set, - expected: 27 | flagIsQuoted, - }, { - defined: Geometry, - expected: 29 | flagIsQuoted, - }, { - defined: TypeJSON, - expected: 30 | flagIsQuoted, - }, { - defined: Expression, - expected: 31, - }} - for _, tcase := range testcases { - if int(tcase.defined) != tcase.expected { - t.Errorf("Type %s: %d, want: %d", tcase.defined, int(tcase.defined), tcase.expected) - } - } -} - -// TestCategory verifies that the type categorizations -// are non-overlapping and complete. -func TestCategory(t *testing.T) { - alltypes := []querypb.Type{ - Null, - Int8, - Uint8, - Int16, - Uint16, - Int24, - Uint24, - Int32, - Uint32, - Int64, - Uint64, - Float32, - Float64, - Timestamp, - Date, - Time, - Datetime, - Year, - Decimal, - Text, - Blob, - VarChar, - VarBinary, - Char, - Binary, - Bit, - Enum, - Set, - Geometry, - TypeJSON, - Expression, - } - for _, typ := range alltypes { - matched := false - if IsSigned(typ) { - if !IsIntegral(typ) { - t.Errorf("Signed type %v is not an integral", typ) - } - matched = true - } - if IsUnsigned(typ) { - if !IsIntegral(typ) { - t.Errorf("Unsigned type %v is not an integral", typ) - } - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if IsFloat(typ) { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if IsQuoted(typ) { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if typ == Null || typ == Decimal || typ == Expression { - if matched { - t.Errorf("%v matched more than one category", typ) - } - matched = true - } - if !matched { - t.Errorf("%v matched no category", typ) - } - } -} - -func TestIsFunctions(t *testing.T) { - if IsIntegral(Null) { - t.Error("Null: IsIntegral, must be false") - } - if !IsIntegral(Int64) { - t.Error("Int64: !IsIntegral, must be true") - } - if IsSigned(Uint64) { - t.Error("Uint64: IsSigned, must be false") - } - if !IsSigned(Int64) { - t.Error("Int64: !IsSigned, must be true") - } - if IsUnsigned(Int64) { - t.Error("Int64: IsUnsigned, must be false") - } - if !IsUnsigned(Uint64) { - t.Error("Uint64: !IsUnsigned, must be true") - } - if IsFloat(Int64) { - t.Error("Int64: IsFloat, must be false") - } - if !IsFloat(Float64) { - t.Error("Uint64: !IsFloat, must be true") - } - if IsQuoted(Int64) { - t.Error("Int64: IsQuoted, must be false") - } - if !IsQuoted(Binary) { - t.Error("Binary: !IsQuoted, must be true") - } - if IsText(Int64) { - t.Error("Int64: IsText, must be false") - } - if !IsText(Char) { - t.Error("Char: !IsText, must be true") - } - if IsBinary(Int64) { - t.Error("Int64: IsBinary, must be false") - } - if !IsBinary(Binary) { - t.Error("Char: !IsBinary, must be true") - } - if !isNumber(Int64) { - t.Error("Int64: !isNumber, must be true") - } -} - -func TestTypeToMySQL(t *testing.T) { - v, f := TypeToMySQL(Bit) - if v != 16 { - t.Errorf("Bit: %d, want 16", v) - } - if f != mysqlUnsigned { - t.Errorf("Bit flag: %x, want %x", f, mysqlUnsigned) - } - v, f = TypeToMySQL(Date) - if v != 10 { - t.Errorf("Bit: %d, want 10", v) - } - if f != mysqlBinary { - t.Errorf("Bit flag: %x, want %x", f, mysqlBinary) - } -} - -func TestMySQLToType(t *testing.T) { - testcases := []struct { - intype int64 - inflags int64 - outtype querypb.Type - }{{ - intype: 1, - outtype: Int8, - }, { - intype: 1, - inflags: mysqlUnsigned, - outtype: Uint8, - }, { - intype: 2, - outtype: Int16, - }, { - intype: 2, - inflags: mysqlUnsigned, - outtype: Uint16, - }, { - intype: 3, - outtype: Int32, - }, { - intype: 3, - inflags: mysqlUnsigned, - outtype: Uint32, - }, { - intype: 4, - outtype: Float32, - }, { - intype: 5, - outtype: Float64, - }, { - intype: 6, - outtype: Null, - }, { - intype: 7, - outtype: Timestamp, - }, { - intype: 8, - outtype: Int64, - }, { - intype: 8, - inflags: mysqlUnsigned, - outtype: Uint64, - }, { - intype: 9, - outtype: Int24, - }, { - intype: 9, - inflags: mysqlUnsigned, - outtype: Uint24, - }, { - intype: 10, - outtype: Date, - }, { - intype: 11, - outtype: Time, - }, { - intype: 12, - outtype: Datetime, - }, { - intype: 13, - outtype: Year, - }, { - intype: 16, - outtype: Bit, - }, { - intype: 245, - outtype: TypeJSON, - }, { - intype: 246, - outtype: Decimal, - }, { - intype: 249, - outtype: Text, - }, { - intype: 250, - outtype: Text, - }, { - intype: 251, - outtype: Text, - }, { - intype: 252, - outtype: Text, - }, { - intype: 252, - inflags: mysqlBinary, - outtype: Blob, - }, { - intype: 253, - outtype: VarChar, - }, { - intype: 253, - inflags: mysqlBinary, - outtype: VarBinary, - }, { - intype: 254, - outtype: Char, - }, { - intype: 254, - inflags: mysqlBinary, - outtype: Binary, - }, { - intype: 254, - inflags: mysqlEnum, - outtype: Enum, - }, { - intype: 254, - inflags: mysqlSet, - outtype: Set, - }, { - intype: 255, - outtype: Geometry, - }, { - // Binary flag must be ignored. - intype: 8, - inflags: mysqlUnsigned | mysqlBinary, - outtype: Uint64, - }, { - // Unsigned flag must be ignored - intype: 252, - inflags: mysqlUnsigned | mysqlBinary, - outtype: Blob, - }} - for _, tcase := range testcases { - got, err := MySQLToType(tcase.intype, tcase.inflags) - if err != nil { - t.Error(err) - } - if got != tcase.outtype { - t.Errorf("MySQLToType(%d, %x): %v, want %v", tcase.intype, tcase.inflags, got, tcase.outtype) - } - } -} - -func TestTypeError(t *testing.T) { - _, err := MySQLToType(15, 0) - want := "unsupported type: 15" - if err == nil || err.Error() != want { - t.Errorf("MySQLToType: %v, want %s", err, want) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go deleted file mode 100644 index 96b137d1..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/dependency/sqltypes/value_test.go +++ /dev/null @@ -1,408 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqltypes - -import ( - "bytes" - "reflect" - "strings" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -const ( - InvalidNeg = "-9223372036854775809" - MinNeg = "-9223372036854775808" - MinPos = "18446744073709551615" - InvalidPos = "18446744073709551616" -) - -func TestNewValue(t *testing.T) { - testcases := []struct { - inType querypb.Type - inVal string - outVal Value - outErr string - }{{ - inType: Null, - inVal: "", - outVal: NULL, - }, { - inType: Int8, - inVal: "1", - outVal: TestValue(Int8, "1"), - }, { - inType: Int16, - inVal: "1", - outVal: TestValue(Int16, "1"), - }, { - inType: Int24, - inVal: "1", - outVal: TestValue(Int24, "1"), - }, { - inType: Int32, - inVal: "1", - outVal: TestValue(Int32, "1"), - }, { - inType: Int64, - inVal: "1", - outVal: TestValue(Int64, "1"), - }, { - inType: Uint8, - inVal: "1", - outVal: TestValue(Uint8, "1"), - }, { - inType: Uint16, - inVal: "1", - outVal: TestValue(Uint16, "1"), - }, { - inType: Uint24, - inVal: "1", - outVal: TestValue(Uint24, "1"), - }, { - inType: Uint32, - inVal: "1", - outVal: TestValue(Uint32, "1"), - }, { - inType: Uint64, - inVal: "1", - outVal: TestValue(Uint64, "1"), - }, { - inType: Float32, - inVal: "1.00", - outVal: TestValue(Float32, "1.00"), - }, { - inType: Float64, - inVal: "1.00", - outVal: TestValue(Float64, "1.00"), - }, { - inType: Decimal, - inVal: "1.00", - outVal: TestValue(Decimal, "1.00"), - }, { - inType: Timestamp, - inVal: "2012-02-24 23:19:43", - outVal: TestValue(Timestamp, "2012-02-24 23:19:43"), - }, { - inType: Date, - inVal: "2012-02-24", - outVal: TestValue(Date, "2012-02-24"), - }, { - inType: Time, - inVal: "23:19:43", - outVal: TestValue(Time, "23:19:43"), - }, { - inType: Datetime, - inVal: "2012-02-24 23:19:43", - outVal: TestValue(Datetime, "2012-02-24 23:19:43"), - }, { - inType: Year, - inVal: "1", - outVal: TestValue(Year, "1"), - }, { - inType: Text, - inVal: "a", - outVal: TestValue(Text, "a"), - }, { - inType: Blob, - inVal: "a", - outVal: TestValue(Blob, "a"), - }, { - inType: VarChar, - inVal: "a", - outVal: TestValue(VarChar, "a"), - }, { - inType: Binary, - inVal: "a", - outVal: TestValue(Binary, "a"), - }, { - inType: Char, - inVal: "a", - outVal: TestValue(Char, "a"), - }, { - inType: Bit, - inVal: "1", - outVal: TestValue(Bit, "1"), - }, { - inType: Enum, - inVal: "a", - outVal: TestValue(Enum, "a"), - }, { - inType: Set, - inVal: "a", - outVal: TestValue(Set, "a"), - }, { - inType: VarBinary, - inVal: "a", - outVal: TestValue(VarBinary, "a"), - }, { - inType: Int64, - inVal: InvalidNeg, - outErr: "out of range", - }, { - inType: Int64, - inVal: InvalidPos, - outErr: "out of range", - }, { - inType: Uint64, - inVal: "-1", - outErr: "invalid syntax", - }, { - inType: Uint64, - inVal: InvalidPos, - outErr: "out of range", - }, { - inType: Float64, - inVal: "a", - outErr: "invalid syntax", - }, { - inType: Expression, - inVal: "a", - outErr: "invalid type specified for MakeValue: EXPRESSION", - }} - for _, tcase := range testcases { - v, err := NewValue(tcase.inType, []byte(tcase.inVal)) - if tcase.outErr != "" { - if err == nil || !strings.Contains(err.Error(), tcase.outErr) { - t.Errorf("ValueFromBytes(%v, %v) error: %v, must contain %v", tcase.inType, tcase.inVal, err, tcase.outErr) - } - continue - } - if err != nil { - t.Errorf("ValueFromBytes(%v, %v) error: %v", tcase.inType, tcase.inVal, err) - continue - } - if !reflect.DeepEqual(v, tcase.outVal) { - t.Errorf("ValueFromBytes(%v, %v) = %v, want %v", tcase.inType, tcase.inVal, v, tcase.outVal) - } - } -} - -// TestNew tests 'New' functions that are not tested -// through other code paths. -func TestNew(t *testing.T) { - got := NewInt32(1) - want := MakeTrusted(Int32, []byte("1")) - if !reflect.DeepEqual(got, want) { - t.Errorf("NewInt32(aa): %v, want %v", got, want) - } - - got = NewVarBinary("aa") - want = MakeTrusted(VarBinary, []byte("aa")) - if !reflect.DeepEqual(got, want) { - t.Errorf("NewVarBinary(aa): %v, want %v", got, want) - } -} - -func TestMakeTrusted(t *testing.T) { - v := MakeTrusted(Null, []byte("abcd")) - if !reflect.DeepEqual(v, NULL) { - t.Errorf("MakeTrusted(Null...) = %v, want null", v) - } - v = MakeTrusted(Int64, []byte("1")) - want := TestValue(Int64, "1") - if !reflect.DeepEqual(v, want) { - t.Errorf("MakeTrusted(Int64, \"1\") = %v, want %v", v, want) - } -} - -func TestIntegralValue(t *testing.T) { - testcases := []struct { - in string - outVal Value - outErr string - }{{ - in: MinNeg, - outVal: TestValue(Int64, MinNeg), - }, { - in: "1", - outVal: TestValue(Int64, "1"), - }, { - in: MinPos, - outVal: TestValue(Uint64, MinPos), - }, { - in: InvalidPos, - outErr: "out of range", - }} - for _, tcase := range testcases { - v, err := NewIntegral(tcase.in) - if tcase.outErr != "" { - if err == nil || !strings.Contains(err.Error(), tcase.outErr) { - t.Errorf("BuildIntegral(%v) error: %v, must contain %v", tcase.in, err, tcase.outErr) - } - continue - } - if err != nil { - t.Errorf("BuildIntegral(%v) error: %v", tcase.in, err) - continue - } - if !reflect.DeepEqual(v, tcase.outVal) { - t.Errorf("BuildIntegral(%v) = %v, want %v", tcase.in, v, tcase.outVal) - } - } -} - -func TestInerfaceValue(t *testing.T) { - testcases := []struct { - in interface{} - out Value - }{{ - in: nil, - out: NULL, - }, { - in: []byte("a"), - out: TestValue(VarBinary, "a"), - }, { - in: int64(1), - out: TestValue(Int64, "1"), - }, { - in: uint64(1), - out: TestValue(Uint64, "1"), - }, { - in: float64(1.2), - out: TestValue(Float64, "1.2"), - }, { - in: "a", - out: TestValue(VarChar, "a"), - }} - for _, tcase := range testcases { - v, err := InterfaceToValue(tcase.in) - if err != nil { - t.Errorf("BuildValue(%#v) error: %v", tcase.in, err) - continue - } - if !reflect.DeepEqual(v, tcase.out) { - t.Errorf("BuildValue(%#v) = %v, want %v", tcase.in, v, tcase.out) - } - } - - _, err := InterfaceToValue(make(chan bool)) - want := "unexpected" - if err == nil || !strings.Contains(err.Error(), want) { - t.Errorf("BuildValue(chan): %v, want %v", err, want) - } -} - -func TestAccessors(t *testing.T) { - v := TestValue(Int64, "1") - if v.Type() != Int64 { - t.Errorf("v.Type=%v, want Int64", v.Type()) - } - if !bytes.Equal(v.Raw(), []byte("1")) { - t.Errorf("v.Raw=%s, want 1", v.Raw()) - } - if v.Len() != 1 { - t.Errorf("v.Len=%d, want 1", v.Len()) - } - if v.ToString() != "1" { - t.Errorf("v.String=%s, want 1", v.ToString()) - } - if v.IsNull() { - t.Error("v.IsNull: true, want false") - } - if !v.IsIntegral() { - t.Error("v.IsIntegral: false, want true") - } - if !v.IsSigned() { - t.Error("v.IsSigned: false, want true") - } - if v.IsUnsigned() { - t.Error("v.IsUnsigned: true, want false") - } - if v.IsFloat() { - t.Error("v.IsFloat: true, want false") - } - if v.IsQuoted() { - t.Error("v.IsQuoted: true, want false") - } - if v.IsText() { - t.Error("v.IsText: true, want false") - } - if v.IsBinary() { - t.Error("v.IsBinary: true, want false") - } -} - -func TestToBytesAndString(t *testing.T) { - for _, v := range []Value{ - NULL, - TestValue(Int64, "1"), - TestValue(Int64, "12"), - } { - if b := v.ToBytes(); bytes.Compare(b, v.Raw()) != 0 { - t.Errorf("%v.ToBytes: %s, want %s", v, b, v.Raw()) - } - if s := v.ToString(); s != string(v.Raw()) { - t.Errorf("%v.ToString: %s, want %s", v, s, v.Raw()) - } - } - - tv := TestValue(Expression, "aa") - if b := tv.ToBytes(); b != nil { - t.Errorf("%v.ToBytes: %s, want nil", tv, b) - } - if s := tv.ToString(); s != "" { - t.Errorf("%v.ToString: %s, want \"\"", tv, s) - } -} - -func TestEncode(t *testing.T) { - testcases := []struct { - in Value - outSQL string - outASCII string - }{{ - in: NULL, - outSQL: "null", - outASCII: "null", - }, { - in: TestValue(Int64, "1"), - outSQL: "1", - outASCII: "1", - }, { - in: TestValue(VarChar, "foo"), - outSQL: "'foo'", - outASCII: "'Zm9v'", - }, { - in: TestValue(VarChar, "\x00'\"\b\n\r\t\x1A\\"), - outSQL: "'\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\'", - outASCII: "'ACciCAoNCRpc'", - }} - for _, tcase := range testcases { - buf := &bytes.Buffer{} - tcase.in.EncodeSQL(buf) - if tcase.outSQL != buf.String() { - t.Errorf("%v.EncodeSQL = %q, want %q", tcase.in, buf.String(), tcase.outSQL) - } - buf = &bytes.Buffer{} - tcase.in.EncodeASCII(buf) - if tcase.outASCII != buf.String() { - t.Errorf("%v.EncodeASCII = %q, want %q", tcase.in, buf.String(), tcase.outASCII) - } - } -} - -// TestEncodeMap ensures DontEscape is not escaped -func TestEncodeMap(t *testing.T) { - if SQLEncodeMap[DontEscape] != DontEscape { - t.Errorf("SQLEncodeMap[DontEscape] = %v, want %v", SQLEncodeMap[DontEscape], DontEscape) - } - if SQLDecodeMap[DontEscape] != DontEscape { - t.Errorf("SQLDecodeMap[DontEscape] = %v, want %v", SQLEncodeMap[DontEscape], DontEscape) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go deleted file mode 100644 index 3bfc7748..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/encodable_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestEncodable(t *testing.T) { - tcases := []struct { - in Encodable - out string - }{{ - in: InsertValues{{ - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("foo('a')"), - }, { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bar(`b`)"), - }}, - out: "(1, 'foo(\\'a\\')'), (2, 'bar(`b`)')", - }, { - // Single column. - in: &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk")}, - Rows: [][]sqltypes.Value{ - {sqltypes.NewInt64(1)}, - {sqltypes.NewVarBinary("aa")}, - }, - }, - out: "pk in (1, 'aa')", - }, { - // Multiple columns. - in: &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk1"), NewColIdent("pk2")}, - Rows: [][]sqltypes.Value{ - { - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("aa"), - }, - { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bb"), - }, - }, - }, - out: "(pk1 = 1 and pk2 = 'aa') or (pk1 = 2 and pk2 = 'bb')", - }} - for _, tcase := range tcases { - buf := new(bytes.Buffer) - tcase.in.EncodeSQL(buf) - if out := buf.String(); out != tcase.out { - t.Errorf("EncodeSQL(%v): %s, want %s", tcase.in, out, tcase.out) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go deleted file mode 100644 index 01ab03ef..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/github_test.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreedto in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package sqlparser - -// Additional tests to address the GitHub issues for this fork. - -import ( - "io" - "strings" - "testing" -) - -func TestParsing(t *testing.T) { - tests := []struct { - id int // Github issue ID - sql string - skip string - }{ - {id: 9, sql: "select 1 as 测试 from dual", skip: "Broken due to ReadByte()"}, - {id: 12, sql: "SELECT * FROM AccessToken LIMIT 10 OFFSET 13"}, - {id: 14, sql: "SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH)"}, - {id: 15, sql: "select STRAIGHT_JOIN t1.* FROM t1 INNER JOIN t2 ON t1.CommonID = t2.CommonID WHERE t1.FilterID = 1"}, - {id: 16, sql: "SELECT a FROM t WHERE FUNC(a) = 1"}, // Doesn't seem broken, need better example - {id: 21, sql: `CREATE TABLE t (UpdateDatetime TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP)`}, - {id: 21, sql: `CREATE TABLE t (UpdateDatetime TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间')`}, - {id: 24, sql: `select * from t1 join t2 using(id)`}, - } - - for _, test := range tests { - if test.skip != "" { - continue - } - - if _, err := Parse(test.sql); err != nil { - t.Errorf("https://github.com/xwb1989/sqlparser/issues/%d:\nParse(%q) err = %s, want nil", test.id, test.sql, err) - } - } -} - -// ExampleParse is the first example from the README.md. -func ExampleParse() { - sql := "SELECT * FROM table WHERE a = 'abc'" - stmt, err := Parse(sql) - if err != nil { - // Do something with the err - } - - // Otherwise do something with stmt - switch stmt := stmt.(type) { - case *Select: - _ = stmt - case *Insert: - } -} - -// ExampleParseNext is the second example from the README.md. -func ExampleParseNext() { - r := strings.NewReader("INSERT INTO table1 VALUES (1, 'a'); INSERT INTO table2 VALUES (3, 4);") - - tokens := NewTokenizer(r) - for { - stmt, err := ParseNext(tokens) - if err == io.EOF { - break - } - // Do something with stmt or err. - _ = stmt - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go deleted file mode 100644 index 20f7e39d..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/normalizer_test.go +++ /dev/null @@ -1,206 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "reflect" - "testing" - - "github.com/xwb1989/sqlparser/dependency/querypb" - "github.com/xwb1989/sqlparser/dependency/sqltypes" -) - -func TestNormalize(t *testing.T) { - prefix := "bv" - testcases := []struct { - in string - outstmt string - outbv map[string]*querypb.BindVariable - }{{ - // str val - in: "select * from t where v1 = 'aa'", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte("aa")), - }, - }, { - // int val - in: "select * from t where v1 = 1", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // float val - in: "select * from t where v1 = 1.2", - outstmt: "select * from t where v1 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Float64BindVariable(1.2), - }, - }, { - // multiple vals - in: "select * from t where v1 = 1.2 and v2 = 2", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Float64BindVariable(1.2), - "bv2": sqltypes.Int64BindVariable(2), - }, - }, { - // bv collision - in: "select * from t where v1 = :bv1 and v2 = 1", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv2": sqltypes.Int64BindVariable(1), - }, - }, { - // val reuse - in: "select * from t where v1 = 1 and v2 = 1", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // ints and strings are different - in: "select * from t where v1 = 1 and v2 = '1'", - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - "bv2": sqltypes.BytesBindVariable([]byte("1")), - }, - }, { - // val should not be reused for non-select statements - in: "insert into a values(1, 1)", - outstmt: "insert into a values (:bv1, :bv2)", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - "bv2": sqltypes.Int64BindVariable(1), - }, - }, { - // val should be reused only in subqueries of DMLs - in: "update a set v1=(select 5 from t), v2=5, v3=(select 5 from t), v4=5", - outstmt: "update a set v1 = (select :bv1 from t), v2 = :bv2, v3 = (select :bv1 from t), v4 = :bv3", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(5), - "bv2": sqltypes.Int64BindVariable(5), - "bv3": sqltypes.Int64BindVariable(5), - }, - }, { - // list vars should work for DMLs also - in: "update a set v1=5 where v2 in (1, 4, 5)", - outstmt: "update a set v1 = :bv1 where v2 in ::bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(5), - "bv2": sqltypes.TestBindVariable([]interface{}{1, 4, 5}), - }, - }, { - // Hex value does not convert - in: "select * from t where v1 = 0x1234", - outstmt: "select * from t where v1 = 0x1234", - outbv: map[string]*querypb.BindVariable{}, - }, { - // Hex value does not convert for DMLs - in: "update a set v1 = 0x1234", - outstmt: "update a set v1 = 0x1234", - outbv: map[string]*querypb.BindVariable{}, - }, { - // Values up to len 256 will reuse. - in: fmt.Sprintf("select * from t where v1 = '%256s' and v2 = '%256s'", "a", "a"), - outstmt: "select * from t where v1 = :bv1 and v2 = :bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%256s", "a"))), - }, - }, { - // Values greater than len 256 will not reuse. - in: fmt.Sprintf("select * from t where v1 = '%257s' and v2 = '%257s'", "b", "b"), - outstmt: "select * from t where v1 = :bv1 and v2 = :bv2", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%257s", "b"))), - "bv2": sqltypes.BytesBindVariable([]byte(fmt.Sprintf("%257s", "b"))), - }, - }, { - // bad int - in: "select * from t where v1 = 12345678901234567890", - outstmt: "select * from t where v1 = 12345678901234567890", - outbv: map[string]*querypb.BindVariable{}, - }, { - // comparison with no vals - in: "select * from t where v1 = v2", - outstmt: "select * from t where v1 = v2", - outbv: map[string]*querypb.BindVariable{}, - }, { - // IN clause with existing bv - in: "select * from t where v1 in ::list", - outstmt: "select * from t where v1 in ::list", - outbv: map[string]*querypb.BindVariable{}, - }, { - // IN clause with non-val values - in: "select * from t where v1 in (1, a)", - outstmt: "select * from t where v1 in (:bv1, a)", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.Int64BindVariable(1), - }, - }, { - // IN clause with vals - in: "select * from t where v1 in (1, '2')", - outstmt: "select * from t where v1 in ::bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.TestBindVariable([]interface{}{1, []byte("2")}), - }, - }, { - // NOT IN clause - in: "select * from t where v1 not in (1, '2')", - outstmt: "select * from t where v1 not in ::bv1", - outbv: map[string]*querypb.BindVariable{ - "bv1": sqltypes.TestBindVariable([]interface{}{1, []byte("2")}), - }, - }} - for _, tc := range testcases { - stmt, err := Parse(tc.in) - if err != nil { - t.Error(err) - continue - } - bv := make(map[string]*querypb.BindVariable) - Normalize(stmt, bv, prefix) - outstmt := String(stmt) - if outstmt != tc.outstmt { - t.Errorf("Query:\n%s:\n%s, want\n%s", tc.in, outstmt, tc.outstmt) - } - if !reflect.DeepEqual(tc.outbv, bv) { - t.Errorf("Query:\n%s:\n%v, want\n%v", tc.in, bv, tc.outbv) - } - } -} - -func TestGetBindVars(t *testing.T) { - stmt, err := Parse("select * from t where :v1 = :v2 and :v2 = :v3 and :v4 in ::v5") - if err != nil { - t.Fatal(err) - } - got := GetBindvars(stmt) - want := map[string]struct{}{ - "v1": {}, - "v2": {}, - "v3": {}, - "v4": {}, - "v5": {}, - } - if !reflect.DeepEqual(got, want) { - t.Errorf("GetBindVars: %v, want: %v", got, want) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go deleted file mode 100644 index bb92f9f2..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_next_test.go +++ /dev/null @@ -1,163 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "io" - "strings" - "testing" -) - -// TestParseNextValid concatenates all the valid SQL test cases and check it can read -// them as one long string. -func TestParseNextValid(t *testing.T) { - var sql bytes.Buffer - for _, tcase := range validSQL { - sql.WriteString(strings.TrimSuffix(tcase.input, ";")) - sql.WriteRune(';') - } - - tokens := NewTokenizer(&sql) - for i, tcase := range validSQL { - input := tcase.input + ";" - want := tcase.output - if want == "" { - want = tcase.input - } - - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[%d] ParseNext(%q) err: %q, want nil", i, input, err) - continue - } - - if got := String(tree); got != want { - t.Fatalf("[%d] ParseNext(%q) = %q, want %q", i, input, got, want) - } - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(tokens) = (%q, %v) want io.EOF", String(tree), err) - } -} - -// TestParseNextErrors tests all the error cases, and ensures a valid -// SQL statement can be passed afterwards. -func TestParseNextErrors(t *testing.T) { - for _, tcase := range invalidSQL { - if tcase.excludeMulti { - // Skip tests which leave unclosed strings, or comments. - continue - } - - sql := tcase.input + "; select 1 from t" - tokens := NewStringTokenizer(sql) - - // The first statement should be an error - _, err := ParseNext(tokens) - if err == nil || err.Error() != tcase.output { - t.Fatalf("[0] ParseNext(%q) err: %q, want %q", sql, err, tcase.output) - continue - } - - // The second should be valid - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[1] ParseNext(%q) err: %q, want nil", sql, err) - continue - } - - want := "select 1 from t" - if got := String(tree); got != want { - t.Fatalf("[1] ParseNext(%q) = %q, want %q", sql, got, want) - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(tokens) = (%q, %v) want io.EOF", String(tree), err) - } - } -} - -// TestParseNextEdgeCases tests various ParseNext edge cases. -func TestParseNextEdgeCases(t *testing.T) { - tests := []struct { - name string - input string - want []string - }{{ - name: "Trailing ;", - input: "select 1 from a; update a set b = 2;", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "No trailing ;", - input: "select 1 from a; update a set b = 2", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Trailing whitespace", - input: "select 1 from a; update a set b = 2 ", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Trailing whitespace and ;", - input: "select 1 from a; update a set b = 2 ; ", - want: []string{"select 1 from a", "update a set b = 2"}, - }, { - name: "Handle ForceEOF statements", - input: "set character set utf8; select 1 from a", - want: []string{"set charset 'utf8'", "select 1 from a"}, - }, { - name: "Semicolin inside a string", - input: "set character set ';'; select 1 from a", - want: []string{"set charset ';'", "select 1 from a"}, - }, { - name: "Partial DDL", - input: "create table a; select 1 from a", - want: []string{"create table a", "select 1 from a"}, - }, { - name: "Partial DDL", - input: "create table a ignore me this is garbage; select 1 from a", - want: []string{"create table a", "select 1 from a"}, - }} - - for _, test := range tests { - tokens := NewStringTokenizer(test.input) - - for i, want := range test.want { - tree, err := ParseNext(tokens) - if err != nil { - t.Fatalf("[%d] ParseNext(%q) err = %q, want nil", i, test.input, err) - continue - } - - if got := String(tree); got != want { - t.Fatalf("[%d] ParseNext(%q) = %q, want %q", i, test.input, got, want) - } - } - - // Read once more and it should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(%q) = (%q, %v) want io.EOF", test.input, String(tree), err) - } - - // And again, once more should be EOF. - if tree, err := ParseNext(tokens); err != io.EOF { - t.Errorf("ParseNext(%q) = (%q, %v) want io.EOF", test.input, String(tree), err) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go deleted file mode 100644 index ac659621..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parse_test.go +++ /dev/null @@ -1,2126 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "bytes" - "fmt" - "strings" - "testing" -) - -var ( - validSQL = []struct { - input string - output string - }{{ - input: "select 1", - output: "select 1 from dual", - }, { - input: "select 1 from t", - }, { - input: "select .1 from t", - }, { - input: "select 1.2e1 from t", - }, { - input: "select 1.2e+1 from t", - }, { - input: "select 1.2e-1 from t", - }, { - input: "select 08.3 from t", - }, { - input: "select -1 from t where b = -2", - }, { - input: "select - -1 from t", - output: "select 1 from t", - }, { - input: "select 1 from t // aa\n", - output: "select 1 from t", - }, { - input: "select 1 from t -- aa\n", - output: "select 1 from t", - }, { - input: "select 1 from t # aa\n", - output: "select 1 from t", - }, { - input: "select 1 --aa\nfrom t", - output: "select 1 from t", - }, { - input: "select 1 #aa\nfrom t", - output: "select 1 from t", - }, { - input: "select /* simplest */ 1 from t", - }, { - input: "select /* double star **/ 1 from t", - }, { - input: "select /* double */ /* comment */ 1 from t", - }, { - input: "select /* back-quote keyword */ `By` from t", - }, { - input: "select /* back-quote num */ `2a` from t", - }, { - input: "select /* back-quote . */ `a.b` from t", - }, { - input: "select /* back-quote back-quote */ `a``b` from t", - }, { - input: "select /* back-quote unnecessary */ 1 from `t`", - output: "select /* back-quote unnecessary */ 1 from t", - }, { - input: "select /* back-quote idnum */ 1 from `a1`", - output: "select /* back-quote idnum */ 1 from a1", - }, { - input: "select /* @ */ @@a from b", - }, { - input: "select /* \\0 */ '\\0' from a", - }, { - input: "select 1 /* drop this comment */ from t", - output: "select 1 from t", - }, { - input: "select /* union */ 1 from t union select 1 from t", - }, { - input: "select /* double union */ 1 from t union select 1 from t union select 1 from t", - }, { - input: "select /* union all */ 1 from t union all select 1 from t", - }, { - input: "select /* union distinct */ 1 from t union distinct select 1 from t", - }, { - input: "(select /* union parenthesized select */ 1 from t order by a) union select 1 from t", - output: "(select /* union parenthesized select */ 1 from t order by a asc) union select 1 from t", - }, { - input: "select /* union parenthesized select 2 */ 1 from t union (select 1 from t)", - }, { - input: "select /* union order by */ 1 from t union select 1 from t order by a", - output: "select /* union order by */ 1 from t union select 1 from t order by a asc", - }, { - input: "select /* union order by limit lock */ 1 from t union select 1 from t order by a limit 1 for update", - output: "select /* union order by limit lock */ 1 from t union select 1 from t order by a asc limit 1 for update", - }, { - input: "select /* union with limit on lhs */ 1 from t limit 1 union select 1 from t", - }, { - input: "(select id, a from t order by id limit 1) union (select id, b as a from s order by id limit 1) order by a limit 1", - output: "(select id, a from t order by id asc limit 1) union (select id, b as a from s order by id asc limit 1) order by a asc limit 1", - }, { - input: "select a from (select 1 as a from tbl1 union select 2 from tbl2) as t", - }, { - input: "select * from t1 join (select * from t2 union select * from t3) as t", - }, { - // Ensure this doesn't generate: ""select * from t1 join t2 on a = b join t3 on a = b". - input: "select * from t1 join t2 on a = b join t3", - }, { - input: "select * from t1 where col in (select 1 from dual union select 2 from dual)", - }, { - input: "select * from t1 where exists (select a from t2 union select b from t3)", - }, { - input: "select /* distinct */ distinct 1 from t", - }, { - input: "select /* straight_join */ straight_join 1 from t", - }, { - input: "select /* for update */ 1 from t for update", - }, { - input: "select /* lock in share mode */ 1 from t lock in share mode", - }, { - input: "select /* select list */ 1, 2 from t", - }, { - input: "select /* * */ * from t", - }, { - input: "select /* a.* */ a.* from t", - }, { - input: "select /* a.b.* */ a.b.* from t", - }, { - input: "select /* column alias */ a b from t", - output: "select /* column alias */ a as b from t", - }, { - input: "select /* column alias with as */ a as b from t", - }, { - input: "select /* keyword column alias */ a as `By` from t", - }, { - input: "select /* column alias as string */ a as \"b\" from t", - output: "select /* column alias as string */ a as b from t", - }, { - input: "select /* column alias as string without as */ a \"b\" from t", - output: "select /* column alias as string without as */ a as b from t", - }, { - input: "select /* a.* */ a.* from t", - }, { - input: "select next value for t", - output: "select next 1 values from t", - }, { - input: "select next value from t", - output: "select next 1 values from t", - }, { - input: "select next 10 values from t", - }, { - input: "select next :a values from t", - }, { - input: "select /* `By`.* */ `By`.* from t", - }, { - input: "select /* select with bool expr */ a = b from t", - }, { - input: "select /* case_when */ case when a = b then c end from t", - }, { - input: "select /* case_when_else */ case when a = b then c else d end from t", - }, { - input: "select /* case_when_when_else */ case when a = b then c when b = d then d else d end from t", - }, { - input: "select /* case */ case aa when a = b then c end from t", - }, { - input: "select /* parenthesis */ 1 from (t)", - }, { - input: "select /* parenthesis multi-table */ 1 from (t1, t2)", - }, { - input: "select /* table list */ 1 from t1, t2", - }, { - input: "select /* parenthessis in table list 1 */ 1 from (t1), t2", - }, { - input: "select /* parenthessis in table list 2 */ 1 from t1, (t2)", - }, { - input: "select /* use */ 1 from t1 use index (a) where b = 1", - }, { - input: "select /* keyword index */ 1 from t1 use index (`By`) where b = 1", - }, { - input: "select /* ignore */ 1 from t1 as t2 ignore index (a), t3 use index (b) where b = 1", - }, { - input: "select /* use */ 1 from t1 as t2 use index (a), t3 use index (b) where b = 1", - }, { - input: "select /* force */ 1 from t1 as t2 force index (a), t3 force index (b) where b = 1", - }, { - input: "select /* table alias */ 1 from t t1", - output: "select /* table alias */ 1 from t as t1", - }, { - input: "select /* table alias with as */ 1 from t as t1", - }, { - input: "select /* string table alias */ 1 from t as 't1'", - output: "select /* string table alias */ 1 from t as t1", - }, { - input: "select /* string table alias without as */ 1 from t 't1'", - output: "select /* string table alias without as */ 1 from t as t1", - }, { - input: "select /* keyword table alias */ 1 from t as `By`", - }, { - input: "select /* join */ 1 from t1 join t2", - }, { - input: "select /* join on */ 1 from t1 join t2 on a = b", - }, { - input: "select /* join on */ 1 from t1 join t2 using (a)", - }, { - input: "select /* inner join */ 1 from t1 inner join t2", - output: "select /* inner join */ 1 from t1 join t2", - }, { - input: "select /* cross join */ 1 from t1 cross join t2", - output: "select /* cross join */ 1 from t1 join t2", - }, { - input: "select /* straight_join */ 1 from t1 straight_join t2", - }, { - input: "select /* straight_join on */ 1 from t1 straight_join t2 on a = b", - }, { - input: "select /* left join */ 1 from t1 left join t2 on a = b", - }, { - input: "select /* left join */ 1 from t1 left join t2 using (a)", - }, { - input: "select /* left outer join */ 1 from t1 left outer join t2 on a = b", - output: "select /* left outer join */ 1 from t1 left join t2 on a = b", - }, { - input: "select /* left outer join */ 1 from t1 left outer join t2 using (a)", - output: "select /* left outer join */ 1 from t1 left join t2 using (a)", - }, { - input: "select /* right join */ 1 from t1 right join t2 on a = b", - }, { - input: "select /* right join */ 1 from t1 right join t2 using (a)", - }, { - input: "select /* right outer join */ 1 from t1 right outer join t2 on a = b", - output: "select /* right outer join */ 1 from t1 right join t2 on a = b", - }, { - input: "select /* right outer join */ 1 from t1 right outer join t2 using (a)", - output: "select /* right outer join */ 1 from t1 right join t2 using (a)", - }, { - input: "select /* natural join */ 1 from t1 natural join t2", - }, { - input: "select /* natural left join */ 1 from t1 natural left join t2", - }, { - input: "select /* natural left outer join */ 1 from t1 natural left join t2", - output: "select /* natural left outer join */ 1 from t1 natural left join t2", - }, { - input: "select /* natural right join */ 1 from t1 natural right join t2", - }, { - input: "select /* natural right outer join */ 1 from t1 natural right join t2", - output: "select /* natural right outer join */ 1 from t1 natural right join t2", - }, { - input: "select /* join on */ 1 from t1 join t2 on a = b", - }, { - input: "select /* join using */ 1 from t1 join t2 using (a)", - }, { - input: "select /* join using (a, b, c) */ 1 from t1 join t2 using (a, b, c)", - }, { - input: "select /* s.t */ 1 from s.t", - }, { - input: "select /* keyword schema & table name */ 1 from `By`.`bY`", - }, { - input: "select /* select in from */ 1 from (select 1 from t) as a", - }, { - input: "select /* select in from with no as */ 1 from (select 1 from t) a", - output: "select /* select in from with no as */ 1 from (select 1 from t) as a", - }, { - input: "select /* where */ 1 from t where a = b", - }, { - input: "select /* and */ 1 from t where a = b and a = c", - }, { - input: "select /* && */ 1 from t where a = b && a = c", - output: "select /* && */ 1 from t where a = b and a = c", - }, { - input: "select /* or */ 1 from t where a = b or a = c", - }, { - input: "select /* || */ 1 from t where a = b || a = c", - output: "select /* || */ 1 from t where a = b or a = c", - }, { - input: "select /* not */ 1 from t where not a = b", - }, { - input: "select /* ! */ 1 from t where a = !1", - }, { - input: "select /* bool is */ 1 from t where a = b is null", - }, { - input: "select /* bool is not */ 1 from t where a = b is not false", - }, { - input: "select /* true */ 1 from t where true", - }, { - input: "select /* false */ 1 from t where false", - }, { - input: "select /* false on left */ 1 from t where false = 0", - }, { - input: "select /* exists */ 1 from t where exists (select 1 from t)", - }, { - input: "select /* (boolean) */ 1 from t where not (a = b)", - }, { - input: "select /* in value list */ 1 from t where a in (b, c)", - }, { - input: "select /* in select */ 1 from t where a in (select 1 from t)", - }, { - input: "select /* not in */ 1 from t where a not in (b, c)", - }, { - input: "select /* like */ 1 from t where a like b", - }, { - input: "select /* like escape */ 1 from t where a like b escape '!'", - }, { - input: "select /* not like */ 1 from t where a not like b", - }, { - input: "select /* not like escape */ 1 from t where a not like b escape '$'", - }, { - input: "select /* regexp */ 1 from t where a regexp b", - }, { - input: "select /* not regexp */ 1 from t where a not regexp b", - }, { - input: "select /* rlike */ 1 from t where a rlike b", - output: "select /* rlike */ 1 from t where a regexp b", - }, { - input: "select /* not rlike */ 1 from t where a not rlike b", - output: "select /* not rlike */ 1 from t where a not regexp b", - }, { - input: "select /* between */ 1 from t where a between b and c", - }, { - input: "select /* not between */ 1 from t where a not between b and c", - }, { - input: "select /* is null */ 1 from t where a is null", - }, { - input: "select /* is not null */ 1 from t where a is not null", - }, { - input: "select /* is true */ 1 from t where a is true", - }, { - input: "select /* is not true */ 1 from t where a is not true", - }, { - input: "select /* is false */ 1 from t where a is false", - }, { - input: "select /* is not false */ 1 from t where a is not false", - }, { - input: "select /* < */ 1 from t where a < b", - }, { - input: "select /* <= */ 1 from t where a <= b", - }, { - input: "select /* >= */ 1 from t where a >= b", - }, { - input: "select /* > */ 1 from t where a > b", - }, { - input: "select /* != */ 1 from t where a != b", - }, { - input: "select /* <> */ 1 from t where a <> b", - output: "select /* <> */ 1 from t where a != b", - }, { - input: "select /* <=> */ 1 from t where a <=> b", - }, { - input: "select /* != */ 1 from t where a != b", - }, { - input: "select /* single value expre list */ 1 from t where a in (b)", - }, { - input: "select /* select as a value expression */ 1 from t where a = (select a from t)", - }, { - input: "select /* parenthesised value */ 1 from t where a = (b)", - }, { - input: "select /* over-parenthesize */ ((1)) from t where ((a)) in (((1))) and ((a, b)) in ((((1, 1))), ((2, 2)))", - }, { - input: "select /* dot-parenthesize */ (a.b) from t where (b.c) = 2", - }, { - input: "select /* & */ 1 from t where a = b & c", - }, { - input: "select /* & */ 1 from t where a = b & c", - }, { - input: "select /* | */ 1 from t where a = b | c", - }, { - input: "select /* ^ */ 1 from t where a = b ^ c", - }, { - input: "select /* + */ 1 from t where a = b + c", - }, { - input: "select /* - */ 1 from t where a = b - c", - }, { - input: "select /* * */ 1 from t where a = b * c", - }, { - input: "select /* / */ 1 from t where a = b / c", - }, { - input: "select /* % */ 1 from t where a = b % c", - }, { - input: "select /* div */ 1 from t where a = b div c", - }, { - input: "select /* MOD */ 1 from t where a = b MOD c", - output: "select /* MOD */ 1 from t where a = b % c", - }, { - input: "select /* << */ 1 from t where a = b << c", - }, { - input: "select /* >> */ 1 from t where a = b >> c", - }, { - input: "select /* % no space */ 1 from t where a = b%c", - output: "select /* % no space */ 1 from t where a = b % c", - }, { - input: "select /* u+ */ 1 from t where a = +b", - }, { - input: "select /* u- */ 1 from t where a = -b", - }, { - input: "select /* u~ */ 1 from t where a = ~b", - }, { - input: "select /* -> */ a.b -> 'ab' from t", - }, { - input: "select /* -> */ a.b ->> 'ab' from t", - }, { - input: "select /* empty function */ 1 from t where a = b()", - }, { - input: "select /* function with 1 param */ 1 from t where a = b(c)", - }, { - input: "select /* function with many params */ 1 from t where a = b(c, d)", - }, { - input: "select /* function with distinct */ count(distinct a) from t", - }, { - input: "select /* if as func */ 1 from t where a = if(b)", - }, { - input: "select /* current_timestamp as func */ current_timestamp() from t", - }, { - input: "select /* mod as func */ a from tab where mod(b, 2) = 0", - }, { - input: "select /* database as func no param */ database() from t", - }, { - input: "select /* database as func 1 param */ database(1) from t", - }, { - input: "select /* a */ a from t", - }, { - input: "select /* a.b */ a.b from t", - }, { - input: "select /* a.b.c */ a.b.c from t", - }, { - input: "select /* keyword a.b */ `By`.`bY` from t", - }, { - input: "select /* string */ 'a' from t", - }, { - input: "select /* double quoted string */ \"a\" from t", - output: "select /* double quoted string */ 'a' from t", - }, { - input: "select /* quote quote in string */ 'a''a' from t", - output: "select /* quote quote in string */ 'a\\'a' from t", - }, { - input: "select /* double quote quote in string */ \"a\"\"a\" from t", - output: "select /* double quote quote in string */ 'a\\\"a' from t", - }, { - input: "select /* quote in double quoted string */ \"a'a\" from t", - output: "select /* quote in double quoted string */ 'a\\'a' from t", - }, { - input: "select /* backslash quote in string */ 'a\\'a' from t", - }, { - input: "select /* literal backslash in string */ 'a\\\\na' from t", - }, { - input: "select /* all escapes */ '\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\' from t", - }, { - input: "select /* non-escape */ '\\x' from t", - output: "select /* non-escape */ 'x' from t", - }, { - input: "select /* unescaped backslash */ '\\n' from t", - }, { - input: "select /* value argument */ :a from t", - }, { - input: "select /* value argument with digit */ :a1 from t", - }, { - input: "select /* value argument with dot */ :a.b from t", - }, { - input: "select /* positional argument */ ? from t", - output: "select /* positional argument */ :v1 from t", - }, { - input: "select /* multiple positional arguments */ ?, ? from t", - output: "select /* multiple positional arguments */ :v1, :v2 from t", - }, { - input: "select /* list arg */ * from t where a in ::list", - }, { - input: "select /* list arg not in */ * from t where a not in ::list", - }, { - input: "select /* null */ null from t", - }, { - input: "select /* octal */ 010 from t", - }, { - input: "select /* hex */ x'f0A1' from t", - output: "select /* hex */ X'f0A1' from t", - }, { - input: "select /* hex caps */ X'F0a1' from t", - }, { - input: "select /* bit literal */ b'0101' from t", - output: "select /* bit literal */ B'0101' from t", - }, { - input: "select /* bit literal caps */ B'010011011010' from t", - }, { - input: "select /* 0x */ 0xf0 from t", - }, { - input: "select /* float */ 0.1 from t", - }, { - input: "select /* group by */ 1 from t group by a", - }, { - input: "select /* having */ 1 from t having a = b", - }, { - input: "select /* simple order by */ 1 from t order by a", - output: "select /* simple order by */ 1 from t order by a asc", - }, { - input: "select /* order by asc */ 1 from t order by a asc", - }, { - input: "select /* order by desc */ 1 from t order by a desc", - }, { - input: "select /* order by null */ 1 from t order by null", - }, { - input: "select /* limit a */ 1 from t limit a", - }, { - input: "select /* limit a,b */ 1 from t limit a, b", - }, { - input: "select /* binary unary */ a- -b from t", - output: "select /* binary unary */ a - -b from t", - }, { - input: "select /* - - */ - -b from t", - }, { - input: "select /* binary binary */ binary binary b from t", - }, { - input: "select /* binary ~ */ binary ~b from t", - }, { - input: "select /* ~ binary */ ~ binary b from t", - }, { - input: "select /* interval */ adddate('2008-01-02', interval 31 day) from t", - }, { - input: "select /* interval keyword */ adddate('2008-01-02', interval 1 year) from t", - }, { - input: "select /* dual */ 1 from dual", - }, { - input: "select /* Dual */ 1 from Dual", - output: "select /* Dual */ 1 from dual", - }, { - input: "select /* DUAL */ 1 from Dual", - output: "select /* DUAL */ 1 from dual", - }, { - input: "select /* column as bool in where */ a from t where b", - }, { - input: "select /* OR of columns in where */ * from t where a or b", - }, { - input: "select /* OR of mixed columns in where */ * from t where a = 5 or b and c is not null", - }, { - input: "select /* OR in select columns */ (a or b) from t where c = 5", - }, { - input: "select /* bool as select value */ a, true from t", - }, { - input: "select /* bool column in ON clause */ * from t join s on t.id = s.id and s.foo where t.bar", - }, { - input: "select /* bool in order by */ * from t order by a is null or b asc", - }, { - input: "select /* string in case statement */ if(max(case a when 'foo' then 1 else 0 end) = 1, 'foo', 'bar') as foobar from t", - }, { - input: "/*!show databases*/", - output: "show databases", - }, { - input: "select /*!40101 * from*/ t", - output: "select * from t", - }, { - input: "select /*! * from*/ t", - output: "select * from t", - }, { - input: "select /*!* from*/ t", - output: "select * from t", - }, { - input: "select /*!401011 from*/ t", - output: "select 1 from t", - }, { - input: "select /* dual */ 1 from dual", - }, { - input: "insert /* simple */ into a values (1)", - }, { - input: "insert /* a.b */ into a.b values (1)", - }, { - input: "insert /* multi-value */ into a values (1, 2)", - }, { - input: "insert /* multi-value list */ into a values (1, 2), (3, 4)", - }, { - input: "insert /* no values */ into a values ()", - }, { - input: "insert /* set */ into a set a = 1, b = 2", - output: "insert /* set */ into a(a, b) values (1, 2)", - }, { - input: "insert /* set default */ into a set a = default, b = 2", - output: "insert /* set default */ into a(a, b) values (default, 2)", - }, { - input: "insert /* value expression list */ into a values (a + 1, 2 * 3)", - }, { - input: "insert /* default */ into a values (default, 2 * 3)", - }, { - input: "insert /* column list */ into a(a, b) values (1, 2)", - }, { - input: "insert into a(a, b) values (1, ifnull(null, default(b)))", - }, { - input: "insert /* qualified column list */ into a(a, b) values (1, 2)", - }, { - input: "insert /* qualified columns */ into t (t.a, t.b) values (1, 2)", - output: "insert /* qualified columns */ into t(a, b) values (1, 2)", - }, { - input: "insert /* select */ into a select b, c from d", - }, { - input: "insert /* no cols & paren select */ into a(select * from t)", - output: "insert /* no cols & paren select */ into a select * from t", - }, { - input: "insert /* cols & paren select */ into a(a,b,c) (select * from t)", - output: "insert /* cols & paren select */ into a(a, b, c) select * from t", - }, { - input: "insert /* cols & union with paren select */ into a(b, c) (select d, e from f) union (select g from h)", - }, { - input: "insert /* on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = d", - }, { - input: "insert /* bool in insert value */ into a values (1, true, false)", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2) on duplicate key update b = false, c = d", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(b), c = d", - }, { - input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(a.b), c = d", - }, { - input: "insert /* bool expression on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = a > d", - }, { - input: "update /* simple */ a set b = 3", - }, { - input: "update /* a.b */ a.b set b = 3", - }, { - input: "update /* list */ a set b = 3, c = 4", - }, { - input: "update /* expression */ a set b = 3 + 4", - }, { - input: "update /* where */ a set b = 3 where a = b", - }, { - input: "update /* order */ a set b = 3 order by c desc", - }, { - input: "update /* limit */ a set b = 3 limit c", - }, { - input: "update /* bool in update */ a set b = true", - }, { - input: "update /* bool expr in update */ a set b = 5 > 2", - }, { - input: "update /* bool in update where */ a set b = 5 where c", - }, { - input: "update /* table qualifier */ a set a.b = 3", - }, { - input: "update /* table qualifier */ a set t.a.b = 3", - }, { - input: "update /* table alias */ tt aa set aa.cc = 3", - output: "update /* table alias */ tt as aa set aa.cc = 3", - }, { - input: "update (select id from foo) subqalias set id = 4", - output: "update (select id from foo) as subqalias set id = 4", - }, { - input: "update foo f, bar b set f.id = b.id where b.name = 'test'", - output: "update foo as f, bar as b set f.id = b.id where b.name = 'test'", - }, { - input: "update foo f join bar b on f.name = b.name set f.id = b.id where b.name = 'test'", - output: "update foo as f join bar as b on f.name = b.name set f.id = b.id where b.name = 'test'", - }, { - input: "delete /* simple */ from a", - }, { - input: "delete /* a.b */ from a.b", - }, { - input: "delete /* where */ from a where a = b", - }, { - input: "delete /* order */ from a order by b desc", - }, { - input: "delete /* limit */ from a limit b", - }, { - input: "delete a from a join b on a.id = b.id where b.name = 'test'", - }, { - input: "delete a, b from a, b where a.id = b.id and b.name = 'test'", - }, { - input: "delete from a1, a2 using t1 as a1 inner join t2 as a2 where a1.id=a2.id", - output: "delete a1, a2 from t1 as a1 join t2 as a2 where a1.id = a2.id", - }, { - input: "set /* simple */ a = 3", - }, { - input: "set #simple\n b = 4", - }, { - input: "set character_set_results = utf8", - }, { - input: "set @@session.autocommit = true", - }, { - input: "set @@session.`autocommit` = true", - }, { - input: "set @@session.'autocommit' = true", - }, { - input: "set @@session.\"autocommit\" = true", - }, { - input: "set names utf8 collate foo", - output: "set names 'utf8'", - }, { - input: "set character set utf8", - output: "set charset 'utf8'", - }, { - input: "set character set 'utf8'", - output: "set charset 'utf8'", - }, { - input: "set character set \"utf8\"", - output: "set charset 'utf8'", - }, { - input: "set charset default", - output: "set charset default", - }, { - input: "set session wait_timeout = 3600", - output: "set session wait_timeout = 3600", - }, { - input: "set /* list */ a = 3, b = 4", - }, { - input: "set /* mixed list */ a = 3, names 'utf8', charset 'ascii', b = 4", - }, { - input: "set session transaction isolation level repeatable read", - output: "set session tx_isolation = 'repeatable read'", - }, { - input: "set global transaction isolation level repeatable read", - output: "set global tx_isolation = 'repeatable read'", - }, { - input: "set transaction isolation level repeatable read", - output: "set tx_isolation = 'repeatable read'", - }, { - input: "set transaction isolation level read committed", - output: "set tx_isolation = 'read committed'", - }, { - input: "set transaction isolation level read uncommitted", - output: "set tx_isolation = 'read uncommitted'", - }, { - input: "set transaction isolation level serializable", - output: "set tx_isolation = 'serializable'", - }, { - input: "set transaction read write", - output: "set tx_read_only = 0", - }, { - input: "set transaction read only", - output: "set tx_read_only = 1", - }, { - input: "set tx_read_only = 1", - }, { - input: "set tx_read_only = 0", - }, { - input: "set tx_isolation = 'repeatable read'", - }, { - input: "set tx_isolation = 'read committed'", - }, { - input: "set tx_isolation = 'read uncommitted'", - }, { - input: "set tx_isolation = 'serializable'", - }, { - input: "set sql_safe_updates = 0", - }, { - input: "set sql_safe_updates = 1", - }, { - input: "alter ignore table a add foo", - output: "alter table a", - }, { - input: "alter table a add foo", - output: "alter table a", - }, { - input: "alter table a add spatial key foo (column1)", - output: "alter table a", - }, { - input: "alter table a add unique key foo (column1)", - output: "alter table a", - }, { - input: "alter table `By` add foo", - output: "alter table `By`", - }, { - input: "alter table a alter foo", - output: "alter table a", - }, { - input: "alter table a change foo", - output: "alter table a", - }, { - input: "alter table a modify foo", - output: "alter table a", - }, { - input: "alter table a drop foo", - output: "alter table a", - }, { - input: "alter table a disable foo", - output: "alter table a", - }, { - input: "alter table a enable foo", - output: "alter table a", - }, { - input: "alter table a order foo", - output: "alter table a", - }, { - input: "alter table a default foo", - output: "alter table a", - }, { - input: "alter table a discard foo", - output: "alter table a", - }, { - input: "alter table a import foo", - output: "alter table a", - }, { - input: "alter table a rename b", - output: "rename table a to b", - }, { - input: "alter table `By` rename `bY`", - output: "rename table `By` to `bY`", - }, { - input: "alter table a rename to b", - output: "rename table a to b", - }, { - input: "alter table a rename as b", - output: "rename table a to b", - }, { - input: "alter table a rename index foo to bar", - output: "alter table a", - }, { - input: "alter table a rename key foo to bar", - output: "alter table a", - }, { - input: "alter table e auto_increment = 20", - output: "alter table e", - }, { - input: "alter table e character set = 'ascii'", - output: "alter table e", - }, { - input: "alter table e default character set = 'ascii'", - output: "alter table e", - }, { - input: "alter table e comment = 'hello'", - output: "alter table e", - }, { - input: "alter table a reorganize partition b into (partition c values less than (?), partition d values less than (maxvalue))", - output: "alter table a reorganize partition b into (partition c values less than (:v1), partition d values less than (maxvalue))", - }, { - input: "alter table a partition by range (id) (partition p0 values less than (10), partition p1 values less than (maxvalue))", - output: "alter table a", - }, { - input: "alter table a add column id int", - output: "alter table a", - }, { - input: "alter table a add index idx (id)", - output: "alter table a", - }, { - input: "alter table a add fulltext index idx (id)", - output: "alter table a", - }, { - input: "alter table a add spatial index idx (id)", - output: "alter table a", - }, { - input: "alter table a add foreign key", - output: "alter table a", - }, { - input: "alter table a add primary key", - output: "alter table a", - }, { - input: "alter table a add constraint", - output: "alter table a", - }, { - input: "alter table a add id", - output: "alter table a", - }, { - input: "alter table a drop column id int", - output: "alter table a", - }, { - input: "alter table a drop partition p2712", - output: "alter table a", - }, { - input: "alter table a drop index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop fulltext index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop spatial index idx (id)", - output: "alter table a", - }, { - input: "alter table a drop foreign key", - output: "alter table a", - }, { - input: "alter table a drop primary key", - output: "alter table a", - }, { - input: "alter table a drop constraint", - output: "alter table a", - }, { - input: "alter table a drop id", - output: "alter table a", - }, { - input: "alter table a add vindex hash (id)", - }, { - input: "alter table a add vindex `hash` (`id`)", - output: "alter table a add vindex hash (id)", - }, { - input: "alter table a add vindex hash (id) using `hash`", - output: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table a add vindex `add` (`add`)", - }, { - input: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table a add vindex hash (id) using `hash`", - output: "alter table a add vindex hash (id) using hash", - }, { - input: "alter table user add vindex name_lookup_vdx (name) using lookup_hash with owner=user, table=name_user_idx, from=name, to=user_id", - }, { - input: "alter table user2 add vindex name_lastname_lookup_vdx (name,lastname) using lookup with owner=`user`, table=`name_lastname_keyspace_id_map`, from=`name,lastname`, to=`keyspace_id`", - output: "alter table user2 add vindex name_lastname_lookup_vdx (name, lastname) using lookup with owner=user, table=name_lastname_keyspace_id_map, from=name,lastname, to=keyspace_id", - }, { - input: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex `hash`", - output: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex hash", - output: "alter table a drop vindex hash", - }, { - input: "alter table a drop vindex `add`", - output: "alter table a drop vindex `add`", - }, { - input: "create table a", - }, { - input: "create table a (\n\t`a` int\n)", - output: "create table a (\n\ta int\n)", - }, { - input: "create table `by` (\n\t`by` char\n)", - }, { - input: "create table if not exists a (\n\t`a` int\n)", - output: "create table a (\n\ta int\n)", - }, { - input: "create table a ignore me this is garbage", - output: "create table a", - }, { - input: "create table a (a int, b char, c garbage)", - output: "create table a", - }, { - input: "create vindex hash_vdx using hash", - }, { - input: "create vindex lookup_vdx using lookup with owner=user, table=name_user_idx, from=name, to=user_id", - }, { - input: "create vindex xyz_vdx using xyz with param1=hello, param2='world', param3=123", - }, { - input: "create index a on b", - output: "alter table b", - }, { - input: "create unique index a on b", - output: "alter table b", - }, { - input: "create unique index a using foo on b", - output: "alter table b", - }, { - input: "create fulltext index a using foo on b", - output: "alter table b", - }, { - input: "create spatial index a using foo on b", - output: "alter table b", - }, { - input: "create view a", - output: "create table a", - }, { - input: "create or replace view a", - output: "create table a", - }, { - input: "alter view a", - output: "alter table a", - }, { - input: "drop view a", - output: "drop table a", - }, { - input: "drop table a", - output: "drop table a", - }, { - input: "drop table if exists a", - output: "drop table if exists a", - }, { - input: "drop view if exists a", - output: "drop table if exists a", - }, { - input: "drop index b on a", - output: "alter table a", - }, { - input: "analyze table a", - output: "alter table a", - }, { - input: "show binary logs", - output: "show binary logs", - }, { - input: "show binlog events", - output: "show binlog", - }, { - input: "show character set", - output: "show character set", - }, { - input: "show character set like '%foo'", - output: "show character set", - }, { - input: "show collation", - output: "show collation", - }, { - input: "show create database d", - output: "show create database", - }, { - input: "show create event e", - output: "show create event", - }, { - input: "show create function f", - output: "show create function", - }, { - input: "show create procedure p", - output: "show create procedure", - }, { - input: "show create table t", - output: "show create table", - }, { - input: "show create trigger t", - output: "show create trigger", - }, { - input: "show create user u", - output: "show create user", - }, { - input: "show create view v", - output: "show create view", - }, { - input: "show databases", - output: "show databases", - }, { - input: "show engine INNODB", - output: "show engine", - }, { - input: "show engines", - output: "show engines", - }, { - input: "show storage engines", - output: "show storage", - }, { - input: "show errors", - output: "show errors", - }, { - input: "show events", - output: "show events", - }, { - input: "show function code func", - output: "show function", - }, { - input: "show function status", - output: "show function", - }, { - input: "show grants for 'root@localhost'", - output: "show grants", - }, { - input: "show index from table", - output: "show index", - }, { - input: "show indexes from table", - output: "show indexes", - }, { - input: "show keys from table", - output: "show keys", - }, { - input: "show master status", - output: "show master", - }, { - input: "show open tables", - output: "show open", - }, { - input: "show plugins", - output: "show plugins", - }, { - input: "show privileges", - output: "show privileges", - }, { - input: "show procedure code p", - output: "show procedure", - }, { - input: "show procedure status", - output: "show procedure", - }, { - input: "show processlist", - output: "show processlist", - }, { - input: "show full processlist", - output: "show processlist", - }, { - input: "show profile cpu for query 1", - output: "show profile", - }, { - input: "show profiles", - output: "show profiles", - }, { - input: "show relaylog events", - output: "show relaylog", - }, { - input: "show slave hosts", - output: "show slave", - }, { - input: "show slave status", - output: "show slave", - }, { - input: "show status", - output: "show status", - }, { - input: "show global status", - output: "show global status", - }, { - input: "show session status", - output: "show session status", - }, { - input: "show table status", - output: "show table", - }, { - input: "show tables", - }, { - input: "show tables like '%keyspace%'", - }, { - input: "show tables where 1 = 0", - }, { - input: "show tables from a", - }, { - input: "show tables from a where 1 = 0", - }, { - input: "show tables from a like '%keyspace%'", - }, { - input: "show full tables", - }, { - input: "show full tables from a", - }, { - input: "show full tables in a", - output: "show full tables from a", - }, { - input: "show full tables from a like '%keyspace%'", - }, { - input: "show full tables from a where 1 = 0", - }, { - input: "show full tables like '%keyspace%'", - }, { - input: "show full tables where 1 = 0", - }, { - input: "show triggers", - output: "show triggers", - }, { - input: "show variables", - output: "show variables", - }, { - input: "show global variables", - output: "show global variables", - }, { - input: "show session variables", - output: "show session variables", - }, { - input: "show vindexes", - output: "show vindexes", - }, { - input: "show vindexes on t", - output: "show vindexes on t", - }, { - input: "show vitess_keyspaces", - }, { - input: "show vitess_shards", - }, { - input: "show vitess_tablets", - }, { - input: "show vschema_tables", - }, { - input: "show warnings", - output: "show warnings", - }, { - input: "show foobar", - output: "show foobar", - }, { - input: "show foobar like select * from table where syntax is 'ignored'", - output: "show foobar", - }, { - input: "use db", - output: "use db", - }, { - input: "use duplicate", - output: "use `duplicate`", - }, { - input: "use `ks:-80@master`", - output: "use `ks:-80@master`", - }, { - input: "describe foobar", - output: "otherread", - }, { - input: "desc foobar", - output: "otherread", - }, { - input: "explain foobar", - output: "otherread", - }, { - input: "truncate table foo", - output: "truncate table foo", - }, { - input: "truncate foo", - output: "truncate table foo", - }, { - input: "repair foo", - output: "otheradmin", - }, { - input: "optimize foo", - output: "otheradmin", - }, { - input: "select /* EQ true */ 1 from t where a = true", - }, { - input: "select /* EQ false */ 1 from t where a = false", - }, { - input: "select /* NE true */ 1 from t where a != true", - }, { - input: "select /* NE false */ 1 from t where a != false", - }, { - input: "select /* LT true */ 1 from t where a < true", - }, { - input: "select /* LT false */ 1 from t where a < false", - }, { - input: "select /* GT true */ 1 from t where a > true", - }, { - input: "select /* GT false */ 1 from t where a > false", - }, { - input: "select /* LE true */ 1 from t where a <= true", - }, { - input: "select /* LE false */ 1 from t where a <= false", - }, { - input: "select /* GE true */ 1 from t where a >= true", - }, { - input: "select /* GE false */ 1 from t where a >= false", - }, { - input: "select * from t order by a collate utf8_general_ci", - output: "select * from t order by a collate utf8_general_ci asc", - }, { - input: "select k collate latin1_german2_ci as k1 from t1 order by k1 asc", - }, { - input: "select * from t group by a collate utf8_general_ci", - }, { - input: "select MAX(k collate latin1_german2_ci) from t1", - }, { - input: "select distinct k collate latin1_german2_ci from t1", - }, { - input: "select * from t1 where 'Müller' collate latin1_german2_ci = k", - }, { - input: "select * from t1 where k like 'Müller' collate latin1_german2_ci", - }, { - input: "select k from t1 group by k having k = 'Müller' collate latin1_german2_ci", - }, { - input: "select k from t1 join t2 order by a collate latin1_german2_ci asc, b collate latin1_german2_ci asc", - }, { - input: "select k collate 'latin1_german2_ci' as k1 from t1 order by k1 asc", - output: "select k collate latin1_german2_ci as k1 from t1 order by k1 asc", - }, { - input: "select /* drop trailing semicolon */ 1 from dual;", - output: "select /* drop trailing semicolon */ 1 from dual", - }, { - input: "select /* cache directive */ sql_no_cache 'foo' from t", - }, { - input: "select binary 'a' = 'A' from t", - }, { - input: "select 1 from t where foo = _binary 'bar'", - }, { - input: "select 1 from t where foo = _binary'bar'", - output: "select 1 from t where foo = _binary 'bar'", - }, { - input: "select match(a) against ('foo') from t", - }, { - input: "select match(a1, a2) against ('foo' in natural language mode with query expansion) from t", - }, { - input: "select title from video as v where match(v.title, v.tag) against ('DEMO' in boolean mode)", - }, { - input: "select name, group_concat(score) from t group by name", - }, { - input: "select name, group_concat(distinct id, score order by id desc separator ':') from t group by name", - }, { - input: "select * from t partition (p0)", - }, { - input: "select * from t partition (p0, p1)", - }, { - input: "select e.id, s.city from employees as e join stores partition (p1) as s on e.store_id = s.id", - }, { - input: "select truncate(120.3333, 2) from dual", - }, { - input: "update t partition (p0) set a = 1", - }, { - input: "insert into t partition (p0) values (1, 'asdf')", - }, { - input: "insert into t1 select * from t2 partition (p0)", - }, { - input: "replace into t partition (p0) values (1, 'asdf')", - }, { - input: "delete from t partition (p0) where a = 1", - }, { - input: "stream * from t", - }, { - input: "stream /* comment */ * from t", - }, { - input: "begin", - }, { - input: "start transaction", - output: "begin", - }, { - input: "commit", - }, { - input: "rollback", - }, { - input: "create database test_db", - }, { - input: "create schema test_db", - output: "create database test_db", - }, { - input: "create database if not exists test_db", - output: "create database test_db", - }, { - input: "drop database test_db", - }, { - input: "drop schema test_db", - output: "drop database test_db", - }, { - input: "drop database if exists test_db", - output: "drop database test_db", - }} -) - -func TestValid(t *testing.T) { - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("Parse(%q) err: %v, want nil", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("Parse(%q) = %q, want: %q", tcase.input, out, tcase.output) - } - // This test just exercises the tree walking functionality. - // There's no way automated way to verify that a node calls - // all its children. But we can examine code coverage and - // ensure that all walkSubtree functions were called. - Walk(func(node SQLNode) (bool, error) { - return true, nil - }, tree) - } -} - -func TestCaseSensitivity(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "create table A (\n\t`B` int\n)", - output: "create table A (\n\tB int\n)", - }, { - input: "create index b on A", - output: "alter table A", - }, { - input: "alter table A foo", - output: "alter table A", - }, { - input: "alter table A convert", - output: "alter table A", - }, { - // View names get lower-cased. - input: "alter view A foo", - output: "alter table a", - }, { - input: "alter table A rename to B", - output: "rename table A to B", - }, { - input: "rename table A to B", - }, { - input: "drop table B", - output: "drop table B", - }, { - input: "drop table if exists B", - output: "drop table if exists B", - }, { - input: "drop index b on A", - output: "alter table A", - }, { - input: "select a from B", - }, { - input: "select A as B from C", - }, { - input: "select B.* from c", - }, { - input: "select B.A from c", - }, { - input: "select * from B as C", - }, { - input: "select * from A.B", - }, { - input: "update A set b = 1", - }, { - input: "update A.B set b = 1", - }, { - input: "select A() from b", - }, { - input: "select A(B, C) from b", - }, { - input: "select A(distinct B, C) from b", - }, { - // IF is an exception. It's always lower-cased. - input: "select IF(B, C) from b", - output: "select if(B, C) from b", - }, { - input: "select * from b use index (A)", - }, { - input: "insert into A(A, B) values (1, 2)", - }, { - input: "CREATE TABLE A (\n\t`A` int\n)", - output: "create table A (\n\tA int\n)", - }, { - input: "create view A", - output: "create table a", - }, { - input: "alter view A", - output: "alter table a", - }, { - input: "drop view A", - output: "drop table a", - }, { - input: "drop view if exists A", - output: "drop table if exists a", - }, { - input: "select /* lock in SHARE MODE */ 1 from t lock in SHARE MODE", - output: "select /* lock in SHARE MODE */ 1 from t lock in share mode", - }, { - input: "select next VALUE from t", - output: "select next 1 values from t", - }, { - input: "select /* use */ 1 from t1 use index (A) where b = 1", - }} - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestKeywords(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select current_timestamp", - output: "select current_timestamp() from dual", - }, { - input: "update t set a = current_timestamp()", - }, { - input: "select a, current_date from t", - output: "select a, current_date() from t", - }, { - input: "insert into t(a, b) values (current_date, current_date())", - output: "insert into t(a, b) values (current_date(), current_date())", - }, { - input: "select * from t where a > utc_timestmp()", - }, { - input: "update t set b = utc_timestamp + 5", - output: "update t set b = utc_timestamp() + 5", - }, { - input: "select utc_time, utc_date", - output: "select utc_time(), utc_date() from dual", - }, { - input: "select 1 from dual where localtime > utc_time", - output: "select 1 from dual where localtime() > utc_time()", - }, { - input: "update t set a = localtimestamp(), b = utc_timestamp", - output: "update t set a = localtimestamp(), b = utc_timestamp()", - }, { - input: "insert into t(a) values (unix_timestamp)", - }, { - input: "select replace(a, 'foo', 'bar') from t", - }, { - input: "update t set a = replace('1234', '2', '1')", - }, { - input: "insert into t(a, b) values ('foo', 'bar') on duplicate key update a = replace(hex('foo'), 'f', 'b')", - }, { - input: "update t set a = left('1234', 3)", - }, { - input: "select left(a, 5) from t", - }, { - input: "update t set d = adddate(date('2003-12-31 01:02:03'), interval 5 days)", - }, { - input: "insert into t(a, b) values (left('foo', 1), 'b')", - }, { - input: "insert /* qualified function */ into t(a, b) values (test.PI(), 'b')", - }, { - input: "select /* keyword in qualified id */ * from t join z on t.key = z.key", - output: "select /* keyword in qualified id */ * from t join z on t.`key` = z.`key`", - }, { - input: "select /* non-reserved keywords as unqualified cols */ date, view, offset from t", - output: "select /* non-reserved keywords as unqualified cols */ `date`, `view`, `offset` from t", - }, { - input: "select /* share and mode as cols */ share, mode from t where share = 'foo'", - output: "select /* share and mode as cols */ `share`, `mode` from t where `share` = 'foo'", - }, { - input: "select /* unused keywords as cols */ write, varying from t where trailing = 'foo'", - output: "select /* unused keywords as cols */ `write`, `varying` from t where `trailing` = 'foo'", - }, { - input: "select status from t", - output: "select `status` from t", - }, { - input: "select variables from t", - output: "select `variables` from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestConvert(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select cast('abc' as date) from t", - output: "select convert('abc', date) from t", - }, { - input: "select convert('abc', binary(4)) from t", - }, { - input: "select convert('abc', binary) from t", - }, { - input: "select convert('abc', char character set binary) from t", - }, { - input: "select convert('abc', char(4) ascii) from t", - }, { - input: "select convert('abc', char unicode) from t", - }, { - input: "select convert('abc', char(4)) from t", - }, { - input: "select convert('abc', char) from t", - }, { - input: "select convert('abc', nchar(4)) from t", - }, { - input: "select convert('abc', nchar) from t", - }, { - input: "select convert('abc', signed) from t", - }, { - input: "select convert('abc', signed integer) from t", - output: "select convert('abc', signed) from t", - }, { - input: "select convert('abc', unsigned) from t", - }, { - input: "select convert('abc', unsigned integer) from t", - output: "select convert('abc', unsigned) from t", - }, { - input: "select convert('abc', decimal(3, 4)) from t", - }, { - input: "select convert('abc', decimal(4)) from t", - }, { - input: "select convert('abc', decimal) from t", - }, { - input: "select convert('abc', date) from t", - }, { - input: "select convert('abc', time(4)) from t", - }, { - input: "select convert('abc', time) from t", - }, { - input: "select convert('abc', datetime(9)) from t", - }, { - input: "select convert('abc', datetime) from t", - }, { - input: "select convert('abc', json) from t", - }, { - input: "select convert('abc' using ascii) from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } - - invalidSQL := []struct { - input string - output string - }{{ - input: "select convert('abc' as date) from t", - output: "syntax error at position 24 near 'as'", - }, { - input: "select convert from t", - output: "syntax error at position 20 near 'from'", - }, { - input: "select cast('foo', decimal) from t", - output: "syntax error at position 19", - }, { - input: "select convert('abc', datetime(4+9)) from t", - output: "syntax error at position 34", - }, { - input: "select convert('abc', decimal(4+9)) from t", - output: "syntax error at position 33", - }} - - for _, tcase := range invalidSQL { - _, err := Parse(tcase.input) - if err == nil || err.Error() != tcase.output { - t.Errorf("%s: %v, want %s", tcase.input, err, tcase.output) - } - } -} - -func TestSubStr(t *testing.T) { - - validSQL := []struct { - input string - output string - }{{ - input: "select substr(a, 1) from t", - }, { - input: "select substr(a, 1, 6) from t", - }, { - input: "select substring(a, 1) from t", - output: "select substr(a, 1) from t", - }, { - input: "select substring(a, 1, 6) from t", - output: "select substr(a, 1, 6) from t", - }, { - input: "select substr(a from 1 for 6) from t", - output: "select substr(a, 1, 6) from t", - }, { - input: "select substring(a from 1 for 6) from t", - output: "select substr(a, 1, 6) from t", - }} - - for _, tcase := range validSQL { - if tcase.output == "" { - tcase.output = tcase.input - } - tree, err := Parse(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - out := String(tree) - if out != tcase.output { - t.Errorf("out: %s, want %s", out, tcase.output) - } - } -} - -func TestCreateTable(t *testing.T) { - validSQL := []string{ - // test all the data types and options - "create table t (\n" + - " col_bit bit,\n" + - " col_tinyint tinyint auto_increment,\n" + - " col_tinyint3 tinyint(3) unsigned,\n" + - " col_smallint smallint,\n" + - " col_smallint4 smallint(4) zerofill,\n" + - " col_mediumint mediumint,\n" + - " col_mediumint5 mediumint(5) unsigned not null,\n" + - " col_int int,\n" + - " col_int10 int(10) not null,\n" + - " col_integer integer comment 'this is an integer',\n" + - " col_bigint bigint,\n" + - " col_bigint10 bigint(10) zerofill not null default 10,\n" + - " col_real real,\n" + - " col_real2 real(1,2) not null default 1.23,\n" + - " col_double double,\n" + - " col_double2 double(3,4) not null default 1.23,\n" + - " col_float float,\n" + - " col_float2 float(3,4) not null default 1.23,\n" + - " col_decimal decimal,\n" + - " col_decimal2 decimal(2),\n" + - " col_decimal3 decimal(2,3),\n" + - " col_numeric numeric,\n" + - " col_numeric2 numeric(2),\n" + - " col_numeric3 numeric(2,3),\n" + - " col_date date,\n" + - " col_time time,\n" + - " col_timestamp timestamp,\n" + - " col_datetime datetime,\n" + - " col_year year,\n" + - " col_char char,\n" + - " col_char2 char(2),\n" + - " col_char3 char(3) character set ascii,\n" + - " col_char4 char(4) character set ascii collate ascii_bin,\n" + - " col_varchar varchar,\n" + - " col_varchar2 varchar(2),\n" + - " col_varchar3 varchar(3) character set ascii,\n" + - " col_varchar4 varchar(4) character set ascii collate ascii_bin,\n" + - " col_binary binary,\n" + - " col_varbinary varbinary(10),\n" + - " col_tinyblob tinyblob,\n" + - " col_blob blob,\n" + - " col_mediumblob mediumblob,\n" + - " col_longblob longblob,\n" + - " col_tinytext tinytext,\n" + - " col_text text,\n" + - " col_mediumtext mediumtext,\n" + - " col_longtext longtext,\n" + - " col_text text character set ascii collate ascii_bin,\n" + - " col_json json,\n" + - " col_enum enum('a', 'b', 'c', 'd'),\n" + - " col_enum2 enum('a', 'b', 'c', 'd') character set ascii,\n" + - " col_enum3 enum('a', 'b', 'c', 'd') collate ascii_bin,\n" + - " col_enum4 enum('a', 'b', 'c', 'd') character set ascii collate ascii_bin,\n" + - " col_set set('a', 'b', 'c', 'd'),\n" + - " col_set2 set('a', 'b', 'c', 'd') character set ascii,\n" + - " col_set3 set('a', 'b', 'c', 'd') collate ascii_bin,\n" + - " col_set4 set('a', 'b', 'c', 'd') character set ascii collate ascii_bin,\n" + - " col_geometry1 geometry,\n" + - " col_geometry2 geometry not null,\n" + - " col_point1 point,\n" + - " col_point2 point not null,\n" + - " col_linestring1 linestring,\n" + - " col_linestring2 linestring not null,\n" + - " col_polygon1 polygon,\n" + - " col_polygon2 polygon not null,\n" + - " col_geometrycollection1 geometrycollection,\n" + - " col_geometrycollection2 geometrycollection not null,\n" + - " col_multipoint1 multipoint,\n" + - " col_multipoint2 multipoint not null,\n" + - " col_multilinestring1 multilinestring,\n" + - " col_multilinestring2 multilinestring not null,\n" + - " col_multipolygon1 multipolygon,\n" + - " col_multipolygon2 multipolygon not null\n" + - ")", - - // test defaults - "create table t (\n" + - " i1 int default 1,\n" + - " i2 int default null,\n" + - " f1 float default 1.23,\n" + - " s1 varchar default 'c',\n" + - " s2 varchar default 'this is a string',\n" + - " s3 varchar default null,\n" + - " s4 timestamp default current_timestamp,\n" + - " s5 bit(1) default B'0'\n" + - ")", - - // test key field options - "create table t (\n" + - " id int auto_increment primary key,\n" + - " username varchar unique key,\n" + - " email varchar unique,\n" + - " full_name varchar key,\n" + - " time1 timestamp on update current_timestamp,\n" + - " time2 timestamp default current_timestamp on update current_timestamp\n" + - ")", - - // test defining indexes separately - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " geom point not null,\n" + - " status_nonkeyword varchar,\n" + - " primary key (id),\n" + - " spatial key geom (geom),\n" + - " unique key by_username (username),\n" + - " unique by_username2 (username),\n" + - " unique index by_username3 (username),\n" + - " index by_status (status_nonkeyword),\n" + - " key by_full_name (full_name)\n" + - ")", - - // test that indexes support USING - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " status_nonkeyword varchar,\n" + - " primary key (id) using BTREE,\n" + - " unique key by_username (username) using HASH,\n" + - " unique by_username2 (username) using OTHER,\n" + - " unique index by_username3 (username) using XYZ,\n" + - " index by_status (status_nonkeyword) using PDQ,\n" + - " key by_full_name (full_name) using OTHER\n" + - ")", - // test other index options - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " primary key (id) comment 'hi',\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique index by_username4 (username) comment 'hi' using BTREE,\n" + - " unique index by_username4 (username) using BTREE key_block_size 4 comment 'hi'\n" + - ")", - - // multi-column indexes - "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " email varchar,\n" + - " full_name varchar,\n" + - " a int,\n" + - " b int,\n" + - " c int,\n" + - " primary key (id, username),\n" + - " unique key by_abc (a, b, c),\n" + - " key by_email (email(10), username)\n" + - ")", - - // table options - "create table t (\n" + - " id int auto_increment\n" + - ") engine InnoDB,\n" + - " auto_increment 123,\n" + - " avg_row_length 1,\n" + - " default character set utf8mb4,\n" + - " character set latin1,\n" + - " checksum 0,\n" + - " default collate binary,\n" + - " collate ascii_bin,\n" + - " comment 'this is a comment',\n" + - " compression 'zlib',\n" + - " connection 'connect_string',\n" + - " data directory 'absolute path to directory',\n" + - " delay_key_write 1,\n" + - " encryption 'n',\n" + - " index directory 'absolute path to directory',\n" + - " insert_method no,\n" + - " key_block_size 1024,\n" + - " max_rows 100,\n" + - " min_rows 10,\n" + - " pack_keys 0,\n" + - " password 'sekret',\n" + - " row_format default,\n" + - " stats_auto_recalc default,\n" + - " stats_persistent 0,\n" + - " stats_sample_pages 1,\n" + - " tablespace tablespace_name storage disk,\n" + - " tablespace tablespace_name\n", - } - for _, sql := range validSQL { - sql = strings.TrimSpace(sql) - tree, err := ParseStrictDDL(sql) - if err != nil { - t.Errorf("input: %s, err: %v", sql, err) - continue - } - got := String(tree.(*DDL)) - - if sql != got { - t.Errorf("want:\n%s\ngot:\n%s", sql, got) - } - } - - sql := "create table t garbage" - tree, err := Parse(sql) - if err != nil { - t.Errorf("input: %s, err: %v", sql, err) - } - - tree, err = ParseStrictDDL(sql) - if tree != nil || err == nil { - t.Errorf("ParseStrictDDL unexpectedly accepted input %s", sql) - } - - testCases := []struct { - input string - output string - }{{ - // test key_block_size - input: "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique key by_username2 (username) key_block_size=8,\n" + - " unique by_username3 (username) key_block_size = 4\n" + - ")", - output: "create table t (\n" + - " id int auto_increment,\n" + - " username varchar,\n" + - " unique key by_username (username) key_block_size 8,\n" + - " unique key by_username2 (username) key_block_size 8,\n" + - " unique by_username3 (username) key_block_size 4\n" + - ")", - }, - } - for _, tcase := range testCases { - tree, err := ParseStrictDDL(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - if got, want := String(tree.(*DDL)), tcase.output; got != want { - t.Errorf("Parse(%s):\n%s, want\n%s", tcase.input, got, want) - } - } -} - -func TestCreateTableEscaped(t *testing.T) { - testCases := []struct { - input string - output string - }{{ - input: "create table `a`(`id` int, primary key(`id`))", - output: "create table a (\n" + - "\tid int,\n" + - "\tprimary key (id)\n" + - ")", - }, { - input: "create table `insert`(`update` int, primary key(`delete`))", - output: "create table `insert` (\n" + - "\t`update` int,\n" + - "\tprimary key (`delete`)\n" + - ")", - }} - for _, tcase := range testCases { - tree, err := ParseStrictDDL(tcase.input) - if err != nil { - t.Errorf("input: %s, err: %v", tcase.input, err) - continue - } - if got, want := String(tree.(*DDL)), tcase.output; got != want { - t.Errorf("Parse(%s):\n%s, want\n%s", tcase.input, got, want) - } - } -} - -var ( - invalidSQL = []struct { - input string - output string - excludeMulti bool // Don't use in the ParseNext multi-statement parsing tests. - }{{ - input: "select $ from t", - output: "syntax error at position 9 near '$'", - }, { - input: "select : from t", - output: "syntax error at position 9 near ':'", - }, { - input: "select 0xH from t", - output: "syntax error at position 10 near '0x'", - }, { - input: "select x'78 from t", - output: "syntax error at position 12 near '78'", - }, { - input: "select x'777' from t", - output: "syntax error at position 14 near '777'", - }, { - input: "select * from t where :1 = 2", - output: "syntax error at position 24 near ':'", - }, { - input: "select * from t where :. = 2", - output: "syntax error at position 24 near ':'", - }, { - input: "select * from t where ::1 = 2", - output: "syntax error at position 25 near '::'", - }, { - input: "select * from t where ::. = 2", - output: "syntax error at position 25 near '::'", - }, { - input: "update a set c = values(1)", - output: "syntax error at position 26 near '1'", - }, { - input: "select(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(", - output: "max nesting level reached at position 406", - }, { - input: "select(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(" + - "F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F(F" + - "(F(F(F(F(F(F(F(F(F(F(F(", - output: "syntax error at position 404", - }, { - // This construct is considered invalid due to a grammar conflict. - input: "insert into a select * from b join c on duplicate key update d=e", - output: "syntax error at position 54 near 'key'", - }, { - input: "select * from a left join b", - output: "syntax error at position 28", - }, { - input: "select * from a natural join b on c = d", - output: "syntax error at position 34 near 'on'", - }, { - input: "select * from a natural join b using (c)", - output: "syntax error at position 37 near 'using'", - }, { - input: "select next id from a", - output: "expecting value after next at position 15 near 'id'", - }, { - input: "select next 1+1 values from a", - output: "syntax error at position 15", - }, { - input: "insert into a values (select * from b)", - output: "syntax error at position 29 near 'select'", - }, { - input: "select database", - output: "syntax error at position 16", - }, { - input: "select mod from t", - output: "syntax error at position 16 near 'from'", - }, { - input: "select 1 from t where div 5", - output: "syntax error at position 26 near 'div'", - }, { - input: "select 1 from t where binary", - output: "syntax error at position 29", - }, { - input: "select match(a1, a2) against ('foo' in boolean mode with query expansion) from t", - output: "syntax error at position 57 near 'with'", - }, { - input: "select /* reserved keyword as unqualified column */ * from t where key = 'test'", - output: "syntax error at position 71 near 'key'", - }, { - input: "select /* vitess-reserved keyword as unqualified column */ * from t where escape = 'test'", - output: "syntax error at position 81 near 'escape'", - }, { - input: "(select /* parenthesized select */ * from t)", - output: "syntax error at position 45", - }, { - input: "select * from t where id = ((select a from t1 union select b from t2) order by a limit 1)", - output: "syntax error at position 76 near 'order'", - }, { - input: "select /* straight_join using */ 1 from t1 straight_join t2 using (a)", - output: "syntax error at position 66 near 'using'", - }, { - input: "select 'aa", - output: "syntax error at position 11 near 'aa'", - excludeMulti: true, - }, { - input: "select 'aa\\", - output: "syntax error at position 12 near 'aa'", - excludeMulti: true, - }, { - input: "select /* aa", - output: "syntax error at position 13 near '/* aa'", - excludeMulti: true, - }} -) - -func TestErrors(t *testing.T) { - for _, tcase := range invalidSQL { - _, err := Parse(tcase.input) - if err == nil || err.Error() != tcase.output { - t.Errorf("%s: %v, want %s", tcase.input, err, tcase.output) - } - } -} - -// Benchmark run on 6/23/17, prior to improvements: -// BenchmarkParse1-4 100000 16334 ns/op -// BenchmarkParse2-4 30000 44121 ns/op - -func BenchmarkParse1(b *testing.B) { - sql := "select 'abcd', 20, 30.0, eid from a where 1=eid and name='3'" - for i := 0; i < b.N; i++ { - ast, err := Parse(sql) - if err != nil { - b.Fatal(err) - } - _ = String(ast) - } -} - -func BenchmarkParse2(b *testing.B) { - sql := "select aaaa, bbb, ccc, ddd, eeee, ffff, gggg, hhhh, iiii from tttt, ttt1, ttt3 where aaaa = bbbb and bbbb = cccc and dddd+1 = eeee group by fff, gggg having hhhh = iiii and iiii = jjjj order by kkkk, llll limit 3, 4" - for i := 0; i < b.N; i++ { - ast, err := Parse(sql) - if err != nil { - b.Fatal(err) - } - _ = String(ast) - } -} - -var benchQuery string - -func init() { - // benchQuerySize is the approximate size of the query. - benchQuerySize := 1000000 - - // Size of value is 1/10 size of query. Then we add - // 10 such values to the where clause. - var baseval bytes.Buffer - for i := 0; i < benchQuerySize/100; i++ { - // Add an escape character: This will force the upcoming - // tokenizer improvement to still create a copy of the string. - // Then we can see if avoiding the copy will be worth it. - baseval.WriteString("\\'123456789") - } - - var buf bytes.Buffer - buf.WriteString("select a from t1 where v = 1") - for i := 0; i < 10; i++ { - fmt.Fprintf(&buf, " and v%d = \"%d%s\"", i, i, baseval.String()) - } - benchQuery = buf.String() -} - -func BenchmarkParse3(b *testing.B) { - for i := 0; i < b.N; i++ { - if _, err := Parse(benchQuery); err != nil { - b.Fatal(err) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go deleted file mode 100644 index dc0e1ac0..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/parsed_query_test.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "reflect" - "testing" - - "github.com/xwb1989/sqlparser/dependency/sqltypes" - - "github.com/xwb1989/sqlparser/dependency/querypb" -) - -func TestNewParsedQuery(t *testing.T) { - stmt, err := Parse("select * from a where id =:id") - if err != nil { - t.Error(err) - return - } - pq := NewParsedQuery(stmt) - want := &ParsedQuery{ - Query: "select * from a where id = :id", - bindLocations: []bindLocation{{offset: 27, length: 3}}, - } - if !reflect.DeepEqual(pq, want) { - t.Errorf("GenerateParsedQuery: %+v, want %+v", pq, want) - } -} - -func TestGenerateQuery(t *testing.T) { - tcases := []struct { - desc string - query string - bindVars map[string]*querypb.BindVariable - extras map[string]Encodable - output string - }{ - { - desc: "no substitutions", - query: "select * from a where id = 2", - bindVars: map[string]*querypb.BindVariable{ - "id": sqltypes.Int64BindVariable(1), - }, - output: "select * from a where id = 2", - }, { - desc: "missing bind var", - query: "select * from a where id1 = :id1 and id2 = :id2", - bindVars: map[string]*querypb.BindVariable{ - "id1": sqltypes.Int64BindVariable(1), - }, - output: "missing bind var id2", - }, { - desc: "simple bindvar substitution", - query: "select * from a where id1 = :id1 and id2 = :id2", - bindVars: map[string]*querypb.BindVariable{ - "id1": sqltypes.Int64BindVariable(1), - "id2": sqltypes.NullBindVariable, - }, - output: "select * from a where id1 = 1 and id2 = null", - }, { - desc: "tuple *querypb.BindVariable", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{1, "aa"}), - }, - output: "select * from a where id in (1, 'aa')", - }, { - desc: "list bind vars 0 arguments", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{}), - }, - output: "empty list supplied for vals", - }, { - desc: "non-list bind var supplied", - query: "select * from a where id in ::vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.Int64BindVariable(1), - }, - output: "unexpected list arg type (INT64) for key vals", - }, { - desc: "list bind var for non-list", - query: "select * from a where id = :vals", - bindVars: map[string]*querypb.BindVariable{ - "vals": sqltypes.TestBindVariable([]interface{}{1}), - }, - output: "unexpected arg type (TUPLE) for non-list key vals", - }, { - desc: "single column tuple equality", - query: "select * from a where b = :equality", - extras: map[string]Encodable{ - "equality": &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk")}, - Rows: [][]sqltypes.Value{ - {sqltypes.NewInt64(1)}, - {sqltypes.NewVarBinary("aa")}, - }, - }, - }, - output: "select * from a where b = pk in (1, 'aa')", - }, { - desc: "multi column tuple equality", - query: "select * from a where b = :equality", - extras: map[string]Encodable{ - "equality": &TupleEqualityList{ - Columns: []ColIdent{NewColIdent("pk1"), NewColIdent("pk2")}, - Rows: [][]sqltypes.Value{ - { - sqltypes.NewInt64(1), - sqltypes.NewVarBinary("aa"), - }, - { - sqltypes.NewInt64(2), - sqltypes.NewVarBinary("bb"), - }, - }, - }, - }, - output: "select * from a where b = (pk1 = 1 and pk2 = 'aa') or (pk1 = 2 and pk2 = 'bb')", - }, - } - - for _, tcase := range tcases { - tree, err := Parse(tcase.query) - if err != nil { - t.Errorf("parse failed for %s: %v", tcase.desc, err) - continue - } - buf := NewTrackedBuffer(nil) - buf.Myprintf("%v", tree) - pq := buf.ParsedQuery() - bytes, err := pq.GenerateQuery(tcase.bindVars, tcase.extras) - var got string - if err != nil { - got = err.Error() - } else { - got = string(bytes) - } - if got != tcase.output { - t.Errorf("for test case: %s, got: '%s', want '%s'", tcase.desc, got, tcase.output) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/bytes2.patch b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/bytes2.patch deleted file mode 100644 index e69de29b..00000000 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch deleted file mode 100644 index abf19eac..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/querypb.patch +++ /dev/null @@ -1,1315 +0,0 @@ -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/proto/query/query.pb.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/querypb/query.pb.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/proto/query/query.pb.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/querypb/query.pb.go 2017-10-18 18:06:33.000000000 -0700 -@@ -62,30 +62,24 @@ - SplitQueryResponse - StreamHealthRequest - RealtimeStats -- AggregateStats - StreamHealthResponse - UpdateStreamRequest - UpdateStreamResponse - TransactionMetadata - */ --package query -+package querypb - --import proto "github.com/golang/protobuf/proto" --import fmt "fmt" --import math "math" --import topodata "vitess.io/vitess/go/vt/proto/topodata" --import vtrpc "vitess.io/vitess/go/vt/proto/vtrpc" -- --// 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.ProtoPackageIsVersion2 // please upgrade the proto package -+import "strconv" -+ -+// EnumName is a helper function to simplify printing protocol buffer enums -+// by name. Given an enum map and a value, it returns a useful string. -+func EnumName(m map[int32]string, v int32) string { -+ s, ok := m[v] -+ if ok { -+ return s -+ } -+ return strconv.Itoa(int(v)) -+} - - // Flags sent from the MySQL C API - type MySqlFlag int32 -@@ -159,9 +153,8 @@ - } - - func (x MySqlFlag) String() string { -- return proto.EnumName(MySqlFlag_name, int32(x)) -+ return EnumName(MySqlFlag_name, int32(x)) - } --func (MySqlFlag) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - - // Flag allows us to qualify types by their common properties. - type Flag int32 -@@ -196,9 +189,8 @@ - } - - func (x Flag) String() string { -- return proto.EnumName(Flag_name, int32(x)) -+ return EnumName(Flag_name, int32(x)) - } --func (Flag) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - - // Type defines the various supported data types in bind vars - // and query results. -@@ -375,9 +367,8 @@ - } - - func (x Type) String() string { -- return proto.EnumName(Type_name, int32(x)) -+ return EnumName(Type_name, int32(x)) - } --func (Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - - // TransactionState represents the state of a distributed transaction. - type TransactionState int32 -@@ -403,9 +394,8 @@ - } - - func (x TransactionState) String() string { -- return proto.EnumName(TransactionState_name, int32(x)) -+ return EnumName(TransactionState_name, int32(x)) - } --func (TransactionState) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - - type ExecuteOptions_IncludedFields int32 - -@@ -427,10 +417,7 @@ - } - - func (x ExecuteOptions_IncludedFields) String() string { -- return proto.EnumName(ExecuteOptions_IncludedFields_name, int32(x)) --} --func (ExecuteOptions_IncludedFields) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{6, 0} -+ return EnumName(ExecuteOptions_IncludedFields_name, int32(x)) - } - - type ExecuteOptions_Workload int32 -@@ -456,9 +443,8 @@ - } - - func (x ExecuteOptions_Workload) String() string { -- return proto.EnumName(ExecuteOptions_Workload_name, int32(x)) -+ return EnumName(ExecuteOptions_Workload_name, int32(x)) - } --func (ExecuteOptions_Workload) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{6, 1} } - - type ExecuteOptions_TransactionIsolation int32 - -@@ -486,10 +472,7 @@ - } - - func (x ExecuteOptions_TransactionIsolation) String() string { -- return proto.EnumName(ExecuteOptions_TransactionIsolation_name, int32(x)) --} --func (ExecuteOptions_TransactionIsolation) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{6, 2} -+ return EnumName(ExecuteOptions_TransactionIsolation_name, int32(x)) - } - - // The category of one statement. -@@ -513,10 +496,7 @@ - } - - func (x StreamEvent_Statement_Category) String() string { -- return proto.EnumName(StreamEvent_Statement_Category_name, int32(x)) --} --func (StreamEvent_Statement_Category) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{11, 0, 0} -+ return EnumName(StreamEvent_Statement_Category_name, int32(x)) - } - - type SplitQueryRequest_Algorithm int32 -@@ -536,27 +516,22 @@ - } - - func (x SplitQueryRequest_Algorithm) String() string { -- return proto.EnumName(SplitQueryRequest_Algorithm_name, int32(x)) --} --func (SplitQueryRequest_Algorithm) EnumDescriptor() ([]byte, []int) { -- return fileDescriptor0, []int{49, 0} -+ return EnumName(SplitQueryRequest_Algorithm_name, int32(x)) - } - -+/* - // Target describes what the client expects the tablet is. - // If the tablet does not match, an error is returned. - type Target struct { - Keyspace string `protobuf:"bytes,1,opt,name=keyspace" json:"keyspace,omitempty"` - Shard string `protobuf:"bytes,2,opt,name=shard" json:"shard,omitempty"` - TabletType topodata.TabletType `protobuf:"varint,3,opt,name=tablet_type,json=tabletType,enum=topodata.TabletType" json:"tablet_type,omitempty"` -- // cell is used for routing queries between vtgate and vttablets. It -- // is not used when Target is part of the Session sent by the client. -- Cell string `protobuf:"bytes,4,opt,name=cell" json:"cell,omitempty"` - } - - func (m *Target) Reset() { *m = Target{} } --func (m *Target) String() string { return proto.CompactTextString(m) } --func (*Target) ProtoMessage() {} --func (*Target) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } -+func (m *Target) String() string { return "TODO" } -+ -+ - - func (m *Target) GetKeyspace() string { - if m != nil { -@@ -579,12 +554,6 @@ - return topodata.TabletType_UNKNOWN - } - --func (m *Target) GetCell() string { -- if m != nil { -- return m.Cell -- } -- return "" --} - - // VTGateCallerID is sent by VTGate to VTTablet to describe the - // caller. If possible, this information is secure. For instance, -@@ -600,9 +569,9 @@ - } - - func (m *VTGateCallerID) Reset() { *m = VTGateCallerID{} } --func (m *VTGateCallerID) String() string { return proto.CompactTextString(m) } --func (*VTGateCallerID) ProtoMessage() {} --func (*VTGateCallerID) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } -+func (m *VTGateCallerID) String() string { return "TODO" } -+ -+ - - func (m *VTGateCallerID) GetUsername() string { - if m != nil { -@@ -634,9 +603,9 @@ - } - - func (m *EventToken) Reset() { *m = EventToken{} } --func (m *EventToken) String() string { return proto.CompactTextString(m) } --func (*EventToken) ProtoMessage() {} --func (*EventToken) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } -+func (m *EventToken) String() string { return "TODO" } -+ -+ - - func (m *EventToken) GetTimestamp() int64 { - if m != nil { -@@ -658,6 +627,7 @@ - } - return "" - } -+*/ - - // Value represents a typed value. - type Value struct { -@@ -665,10 +635,8 @@ - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - } - --func (m *Value) Reset() { *m = Value{} } --func (m *Value) String() string { return proto.CompactTextString(m) } --func (*Value) ProtoMessage() {} --func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } -+func (m *Value) Reset() { *m = Value{} } -+func (m *Value) String() string { return "TODO" } - - func (m *Value) GetType() Type { - if m != nil { -@@ -692,10 +660,8 @@ - Values []*Value `protobuf:"bytes,3,rep,name=values" json:"values,omitempty"` - } - --func (m *BindVariable) Reset() { *m = BindVariable{} } --func (m *BindVariable) String() string { return proto.CompactTextString(m) } --func (*BindVariable) ProtoMessage() {} --func (*BindVariable) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } -+func (m *BindVariable) Reset() { *m = BindVariable{} } -+func (m *BindVariable) String() string { return "TODO" } - - func (m *BindVariable) GetType() Type { - if m != nil { -@@ -727,10 +693,8 @@ - BindVariables map[string]*BindVariable `protobuf:"bytes,2,rep,name=bind_variables,json=bindVariables" json:"bind_variables,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - } - --func (m *BoundQuery) Reset() { *m = BoundQuery{} } --func (m *BoundQuery) String() string { return proto.CompactTextString(m) } --func (*BoundQuery) ProtoMessage() {} --func (*BoundQuery) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } -+func (m *BoundQuery) Reset() { *m = BoundQuery{} } -+func (m *BoundQuery) String() string { return "TODO" } - - func (m *BoundQuery) GetSql() string { - if m != nil { -@@ -746,6 +710,7 @@ - return nil - } - -+/* - // ExecuteOptions is passed around for all Execute calls. - type ExecuteOptions struct { - // If set, we will try to include an EventToken with the responses. -@@ -774,15 +739,12 @@ - // vitess also sets a rowcount limit on queries, the smallest value wins. - SqlSelectLimit int64 `protobuf:"varint,8,opt,name=sql_select_limit,json=sqlSelectLimit" json:"sql_select_limit,omitempty"` - TransactionIsolation ExecuteOptions_TransactionIsolation `protobuf:"varint,9,opt,name=transaction_isolation,json=transactionIsolation,enum=query.ExecuteOptions_TransactionIsolation" json:"transaction_isolation,omitempty"` -- // skip_query_plan_cache specifies if the query plan shoud be cached by vitess. -- // By default all query plans are cached. -- SkipQueryPlanCache bool `protobuf:"varint,10,opt,name=skip_query_plan_cache,json=skipQueryPlanCache" json:"skip_query_plan_cache,omitempty"` - } - - func (m *ExecuteOptions) Reset() { *m = ExecuteOptions{} } --func (m *ExecuteOptions) String() string { return proto.CompactTextString(m) } --func (*ExecuteOptions) ProtoMessage() {} --func (*ExecuteOptions) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } -+func (m *ExecuteOptions) String() string { return "TODO" } -+ -+ - - func (m *ExecuteOptions) GetIncludeEventToken() bool { - if m != nil { -@@ -833,13 +795,6 @@ - return ExecuteOptions_DEFAULT - } - --func (m *ExecuteOptions) GetSkipQueryPlanCache() bool { -- if m != nil { -- return m.SkipQueryPlanCache -- } -- return false --} -- - // Field describes a single column returned by a query - type Field struct { - // name of the field as returned by mysql C API -@@ -864,9 +819,9 @@ - } - - func (m *Field) Reset() { *m = Field{} } --func (m *Field) String() string { return proto.CompactTextString(m) } --func (*Field) ProtoMessage() {} --func (*Field) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } -+func (m *Field) String() string { return "TODO" } -+ -+ - - func (m *Field) GetName() string { - if m != nil { -@@ -950,9 +905,9 @@ - } - - func (m *Row) Reset() { *m = Row{} } --func (m *Row) String() string { return proto.CompactTextString(m) } --func (*Row) ProtoMessage() {} --func (*Row) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } -+func (m *Row) String() string { return "TODO" } -+ -+ - - func (m *Row) GetLengths() []int64 { - if m != nil { -@@ -980,9 +935,9 @@ - } - - func (m *ResultExtras) Reset() { *m = ResultExtras{} } --func (m *ResultExtras) String() string { return proto.CompactTextString(m) } --func (*ResultExtras) ProtoMessage() {} --func (*ResultExtras) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } -+func (m *ResultExtras) String() string { return "TODO" } -+ -+ - - func (m *ResultExtras) GetEventToken() *EventToken { - if m != nil { -@@ -1016,9 +971,9 @@ - } - - func (m *QueryResult) Reset() { *m = QueryResult{} } --func (m *QueryResult) String() string { return proto.CompactTextString(m) } --func (*QueryResult) ProtoMessage() {} --func (*QueryResult) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } -+func (m *QueryResult) String() string { return "TODO" } -+ -+ - - func (m *QueryResult) GetFields() []*Field { - if m != nil { -@@ -1066,9 +1021,9 @@ - } - - func (m *StreamEvent) Reset() { *m = StreamEvent{} } --func (m *StreamEvent) String() string { return proto.CompactTextString(m) } --func (*StreamEvent) ProtoMessage() {} --func (*StreamEvent) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } -+func (m *StreamEvent) String() string { return "TODO" } -+ -+ - - func (m *StreamEvent) GetStatements() []*StreamEvent_Statement { - if m != nil { -@@ -1097,9 +1052,9 @@ - } - - func (m *StreamEvent_Statement) Reset() { *m = StreamEvent_Statement{} } --func (m *StreamEvent_Statement) String() string { return proto.CompactTextString(m) } --func (*StreamEvent_Statement) ProtoMessage() {} --func (*StreamEvent_Statement) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11, 0} } -+func (m *StreamEvent_Statement) String() string { return "TODO" } -+ -+ - - func (m *StreamEvent_Statement) GetCategory() StreamEvent_Statement_Category { - if m != nil { -@@ -1136,6 +1091,7 @@ - return nil - } - -+ - // ExecuteRequest is the payload to Execute - type ExecuteRequest struct { - EffectiveCallerId *vtrpc.CallerID `protobuf:"bytes,1,opt,name=effective_caller_id,json=effectiveCallerId" json:"effective_caller_id,omitempty"` -@@ -1147,9 +1103,9 @@ - } - - func (m *ExecuteRequest) Reset() { *m = ExecuteRequest{} } --func (m *ExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*ExecuteRequest) ProtoMessage() {} --func (*ExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{12} } -+func (m *ExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *ExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1199,9 +1155,9 @@ - } - - func (m *ExecuteResponse) Reset() { *m = ExecuteResponse{} } --func (m *ExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*ExecuteResponse) ProtoMessage() {} --func (*ExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } -+func (m *ExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *ExecuteResponse) GetResult() *QueryResult { - if m != nil { -@@ -1221,9 +1177,9 @@ - } - - func (m *ResultWithError) Reset() { *m = ResultWithError{} } --func (m *ResultWithError) String() string { return proto.CompactTextString(m) } --func (*ResultWithError) ProtoMessage() {} --func (*ResultWithError) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} } -+func (m *ResultWithError) String() string { return "TODO" } -+ -+ - - func (m *ResultWithError) GetError() *vtrpc.RPCError { - if m != nil { -@@ -1251,9 +1207,9 @@ - } - - func (m *ExecuteBatchRequest) Reset() { *m = ExecuteBatchRequest{} } --func (m *ExecuteBatchRequest) String() string { return proto.CompactTextString(m) } --func (*ExecuteBatchRequest) ProtoMessage() {} --func (*ExecuteBatchRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} } -+func (m *ExecuteBatchRequest) String() string { return "TODO" } -+ -+ - - func (m *ExecuteBatchRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1310,9 +1266,9 @@ - } - - func (m *ExecuteBatchResponse) Reset() { *m = ExecuteBatchResponse{} } --func (m *ExecuteBatchResponse) String() string { return proto.CompactTextString(m) } --func (*ExecuteBatchResponse) ProtoMessage() {} --func (*ExecuteBatchResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} } -+func (m *ExecuteBatchResponse) String() string { return "TODO" } -+ -+ - - func (m *ExecuteBatchResponse) GetResults() []*QueryResult { - if m != nil { -@@ -1331,9 +1287,9 @@ - } - - func (m *StreamExecuteRequest) Reset() { *m = StreamExecuteRequest{} } --func (m *StreamExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*StreamExecuteRequest) ProtoMessage() {} --func (*StreamExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} } -+func (m *StreamExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *StreamExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1376,9 +1332,9 @@ - } - - func (m *StreamExecuteResponse) Reset() { *m = StreamExecuteResponse{} } --func (m *StreamExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*StreamExecuteResponse) ProtoMessage() {} --func (*StreamExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18} } -+func (m *StreamExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *StreamExecuteResponse) GetResult() *QueryResult { - if m != nil { -@@ -1396,9 +1352,9 @@ - } - - func (m *BeginRequest) Reset() { *m = BeginRequest{} } --func (m *BeginRequest) String() string { return proto.CompactTextString(m) } --func (*BeginRequest) ProtoMessage() {} --func (*BeginRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{19} } -+func (m *BeginRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1434,9 +1390,9 @@ - } - - func (m *BeginResponse) Reset() { *m = BeginResponse{} } --func (m *BeginResponse) String() string { return proto.CompactTextString(m) } --func (*BeginResponse) ProtoMessage() {} --func (*BeginResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{20} } -+func (m *BeginResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginResponse) GetTransactionId() int64 { - if m != nil { -@@ -1454,9 +1410,9 @@ - } - - func (m *CommitRequest) Reset() { *m = CommitRequest{} } --func (m *CommitRequest) String() string { return proto.CompactTextString(m) } --func (*CommitRequest) ProtoMessage() {} --func (*CommitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{21} } -+func (m *CommitRequest) String() string { return "TODO" } -+ -+ - - func (m *CommitRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1491,9 +1447,9 @@ - } - - func (m *CommitResponse) Reset() { *m = CommitResponse{} } --func (m *CommitResponse) String() string { return proto.CompactTextString(m) } --func (*CommitResponse) ProtoMessage() {} --func (*CommitResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{22} } -+func (m *CommitResponse) String() string { return "TODO" } -+ -+ - - // RollbackRequest is the payload to Rollback - type RollbackRequest struct { -@@ -1504,9 +1460,9 @@ - } - - func (m *RollbackRequest) Reset() { *m = RollbackRequest{} } --func (m *RollbackRequest) String() string { return proto.CompactTextString(m) } --func (*RollbackRequest) ProtoMessage() {} --func (*RollbackRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{23} } -+func (m *RollbackRequest) String() string { return "TODO" } -+ -+ - - func (m *RollbackRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1541,9 +1497,9 @@ - } - - func (m *RollbackResponse) Reset() { *m = RollbackResponse{} } --func (m *RollbackResponse) String() string { return proto.CompactTextString(m) } --func (*RollbackResponse) ProtoMessage() {} --func (*RollbackResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{24} } -+func (m *RollbackResponse) String() string { return "TODO" } -+ -+ - - // PrepareRequest is the payload to Prepare - type PrepareRequest struct { -@@ -1555,9 +1511,9 @@ - } - - func (m *PrepareRequest) Reset() { *m = PrepareRequest{} } --func (m *PrepareRequest) String() string { return proto.CompactTextString(m) } --func (*PrepareRequest) ProtoMessage() {} --func (*PrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{25} } -+func (m *PrepareRequest) String() string { return "TODO" } -+ -+ - - func (m *PrepareRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1599,9 +1555,9 @@ - } - - func (m *PrepareResponse) Reset() { *m = PrepareResponse{} } --func (m *PrepareResponse) String() string { return proto.CompactTextString(m) } --func (*PrepareResponse) ProtoMessage() {} --func (*PrepareResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{26} } -+func (m *PrepareResponse) String() string { return "TODO" } -+ -+ - - // CommitPreparedRequest is the payload to CommitPrepared - type CommitPreparedRequest struct { -@@ -1612,9 +1568,9 @@ - } - - func (m *CommitPreparedRequest) Reset() { *m = CommitPreparedRequest{} } --func (m *CommitPreparedRequest) String() string { return proto.CompactTextString(m) } --func (*CommitPreparedRequest) ProtoMessage() {} --func (*CommitPreparedRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{27} } -+func (m *CommitPreparedRequest) String() string { return "TODO" } -+ -+ - - func (m *CommitPreparedRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1649,9 +1605,9 @@ - } - - func (m *CommitPreparedResponse) Reset() { *m = CommitPreparedResponse{} } --func (m *CommitPreparedResponse) String() string { return proto.CompactTextString(m) } --func (*CommitPreparedResponse) ProtoMessage() {} --func (*CommitPreparedResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{28} } -+func (m *CommitPreparedResponse) String() string { return "TODO" } -+ -+ - - // RollbackPreparedRequest is the payload to RollbackPrepared - type RollbackPreparedRequest struct { -@@ -1663,9 +1619,9 @@ - } - - func (m *RollbackPreparedRequest) Reset() { *m = RollbackPreparedRequest{} } --func (m *RollbackPreparedRequest) String() string { return proto.CompactTextString(m) } --func (*RollbackPreparedRequest) ProtoMessage() {} --func (*RollbackPreparedRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{29} } -+func (m *RollbackPreparedRequest) String() string { return "TODO" } -+ -+ - - func (m *RollbackPreparedRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1707,9 +1663,9 @@ - } - - func (m *RollbackPreparedResponse) Reset() { *m = RollbackPreparedResponse{} } --func (m *RollbackPreparedResponse) String() string { return proto.CompactTextString(m) } --func (*RollbackPreparedResponse) ProtoMessage() {} --func (*RollbackPreparedResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{30} } -+func (m *RollbackPreparedResponse) String() string { return "TODO" } -+ -+ - - // CreateTransactionRequest is the payload to CreateTransaction - type CreateTransactionRequest struct { -@@ -1721,9 +1677,9 @@ - } - - func (m *CreateTransactionRequest) Reset() { *m = CreateTransactionRequest{} } --func (m *CreateTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*CreateTransactionRequest) ProtoMessage() {} --func (*CreateTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{31} } -+func (m *CreateTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *CreateTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1765,9 +1721,9 @@ - } - - func (m *CreateTransactionResponse) Reset() { *m = CreateTransactionResponse{} } --func (m *CreateTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*CreateTransactionResponse) ProtoMessage() {} --func (*CreateTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{32} } -+func (m *CreateTransactionResponse) String() string { return "TODO" } -+ -+ - - // StartCommitRequest is the payload to StartCommit - type StartCommitRequest struct { -@@ -1779,9 +1735,9 @@ - } - - func (m *StartCommitRequest) Reset() { *m = StartCommitRequest{} } --func (m *StartCommitRequest) String() string { return proto.CompactTextString(m) } --func (*StartCommitRequest) ProtoMessage() {} --func (*StartCommitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{33} } -+func (m *StartCommitRequest) String() string { return "TODO" } -+ -+ - - func (m *StartCommitRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1823,9 +1779,9 @@ - } - - func (m *StartCommitResponse) Reset() { *m = StartCommitResponse{} } --func (m *StartCommitResponse) String() string { return proto.CompactTextString(m) } --func (*StartCommitResponse) ProtoMessage() {} --func (*StartCommitResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{34} } -+func (m *StartCommitResponse) String() string { return "TODO" } -+ -+ - - // SetRollbackRequest is the payload to SetRollback - type SetRollbackRequest struct { -@@ -1837,9 +1793,9 @@ - } - - func (m *SetRollbackRequest) Reset() { *m = SetRollbackRequest{} } --func (m *SetRollbackRequest) String() string { return proto.CompactTextString(m) } --func (*SetRollbackRequest) ProtoMessage() {} --func (*SetRollbackRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{35} } -+func (m *SetRollbackRequest) String() string { return "TODO" } -+ -+ - - func (m *SetRollbackRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1881,9 +1837,9 @@ - } - - func (m *SetRollbackResponse) Reset() { *m = SetRollbackResponse{} } --func (m *SetRollbackResponse) String() string { return proto.CompactTextString(m) } --func (*SetRollbackResponse) ProtoMessage() {} --func (*SetRollbackResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{36} } -+func (m *SetRollbackResponse) String() string { return "TODO" } -+ -+ - - // ConcludeTransactionRequest is the payload to ConcludeTransaction - type ConcludeTransactionRequest struct { -@@ -1894,9 +1850,9 @@ - } - - func (m *ConcludeTransactionRequest) Reset() { *m = ConcludeTransactionRequest{} } --func (m *ConcludeTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*ConcludeTransactionRequest) ProtoMessage() {} --func (*ConcludeTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{37} } -+func (m *ConcludeTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *ConcludeTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1931,9 +1887,9 @@ - } - - func (m *ConcludeTransactionResponse) Reset() { *m = ConcludeTransactionResponse{} } --func (m *ConcludeTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*ConcludeTransactionResponse) ProtoMessage() {} --func (*ConcludeTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{38} } -+func (m *ConcludeTransactionResponse) String() string { return "TODO" } -+ -+ - - // ReadTransactionRequest is the payload to ReadTransaction - type ReadTransactionRequest struct { -@@ -1944,9 +1900,9 @@ - } - - func (m *ReadTransactionRequest) Reset() { *m = ReadTransactionRequest{} } --func (m *ReadTransactionRequest) String() string { return proto.CompactTextString(m) } --func (*ReadTransactionRequest) ProtoMessage() {} --func (*ReadTransactionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{39} } -+func (m *ReadTransactionRequest) String() string { return "TODO" } -+ -+ - - func (m *ReadTransactionRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -1982,9 +1938,9 @@ - } - - func (m *ReadTransactionResponse) Reset() { *m = ReadTransactionResponse{} } --func (m *ReadTransactionResponse) String() string { return proto.CompactTextString(m) } --func (*ReadTransactionResponse) ProtoMessage() {} --func (*ReadTransactionResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{40} } -+func (m *ReadTransactionResponse) String() string { return "TODO" } -+ -+ - - func (m *ReadTransactionResponse) GetMetadata() *TransactionMetadata { - if m != nil { -@@ -2003,9 +1959,9 @@ - } - - func (m *BeginExecuteRequest) Reset() { *m = BeginExecuteRequest{} } --func (m *BeginExecuteRequest) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteRequest) ProtoMessage() {} --func (*BeginExecuteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{41} } -+func (m *BeginExecuteRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2054,9 +2010,9 @@ - } - - func (m *BeginExecuteResponse) Reset() { *m = BeginExecuteResponse{} } --func (m *BeginExecuteResponse) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteResponse) ProtoMessage() {} --func (*BeginExecuteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{42} } -+func (m *BeginExecuteResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteResponse) GetError() *vtrpc.RPCError { - if m != nil { -@@ -2090,9 +2046,9 @@ - } - - func (m *BeginExecuteBatchRequest) Reset() { *m = BeginExecuteBatchRequest{} } --func (m *BeginExecuteBatchRequest) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteBatchRequest) ProtoMessage() {} --func (*BeginExecuteBatchRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{43} } -+func (m *BeginExecuteBatchRequest) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteBatchRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2148,9 +2104,9 @@ - } - - func (m *BeginExecuteBatchResponse) Reset() { *m = BeginExecuteBatchResponse{} } --func (m *BeginExecuteBatchResponse) String() string { return proto.CompactTextString(m) } --func (*BeginExecuteBatchResponse) ProtoMessage() {} --func (*BeginExecuteBatchResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{44} } -+func (m *BeginExecuteBatchResponse) String() string { return "TODO" } -+ -+ - - func (m *BeginExecuteBatchResponse) GetError() *vtrpc.RPCError { - if m != nil { -@@ -2183,9 +2139,9 @@ - } - - func (m *MessageStreamRequest) Reset() { *m = MessageStreamRequest{} } --func (m *MessageStreamRequest) String() string { return proto.CompactTextString(m) } --func (*MessageStreamRequest) ProtoMessage() {} --func (*MessageStreamRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{45} } -+func (m *MessageStreamRequest) String() string { return "TODO" } -+ -+ - - func (m *MessageStreamRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2221,9 +2177,9 @@ - } - - func (m *MessageStreamResponse) Reset() { *m = MessageStreamResponse{} } --func (m *MessageStreamResponse) String() string { return proto.CompactTextString(m) } --func (*MessageStreamResponse) ProtoMessage() {} --func (*MessageStreamResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{46} } -+func (m *MessageStreamResponse) String() string { return "TODO" } -+ -+ - - func (m *MessageStreamResponse) GetResult() *QueryResult { - if m != nil { -@@ -2243,9 +2199,9 @@ - } - - func (m *MessageAckRequest) Reset() { *m = MessageAckRequest{} } --func (m *MessageAckRequest) String() string { return proto.CompactTextString(m) } --func (*MessageAckRequest) ProtoMessage() {} --func (*MessageAckRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{47} } -+func (m *MessageAckRequest) String() string { return "TODO" } -+ -+ - - func (m *MessageAckRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2291,9 +2247,9 @@ - } - - func (m *MessageAckResponse) Reset() { *m = MessageAckResponse{} } --func (m *MessageAckResponse) String() string { return proto.CompactTextString(m) } --func (*MessageAckResponse) ProtoMessage() {} --func (*MessageAckResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{48} } -+func (m *MessageAckResponse) String() string { return "TODO" } -+ -+ - - func (m *MessageAckResponse) GetResult() *QueryResult { - if m != nil { -@@ -2317,9 +2273,9 @@ - } - - func (m *SplitQueryRequest) Reset() { *m = SplitQueryRequest{} } --func (m *SplitQueryRequest) String() string { return proto.CompactTextString(m) } --func (*SplitQueryRequest) ProtoMessage() {} --func (*SplitQueryRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{49} } -+func (m *SplitQueryRequest) String() string { return "TODO" } -+ -+ - - func (m *SplitQueryRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2386,9 +2342,9 @@ - } - - func (m *QuerySplit) Reset() { *m = QuerySplit{} } --func (m *QuerySplit) String() string { return proto.CompactTextString(m) } --func (*QuerySplit) ProtoMessage() {} --func (*QuerySplit) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{50} } -+func (m *QuerySplit) String() string { return "TODO" } -+ -+ - - func (m *QuerySplit) GetQuery() *BoundQuery { - if m != nil { -@@ -2411,9 +2367,9 @@ - } - - func (m *SplitQueryResponse) Reset() { *m = SplitQueryResponse{} } --func (m *SplitQueryResponse) String() string { return proto.CompactTextString(m) } --func (*SplitQueryResponse) ProtoMessage() {} --func (*SplitQueryResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{51} } -+func (m *SplitQueryResponse) String() string { return "TODO" } -+ -+ - - func (m *SplitQueryResponse) GetQueries() []*QuerySplit { - if m != nil { -@@ -2427,12 +2383,11 @@ - } - - func (m *StreamHealthRequest) Reset() { *m = StreamHealthRequest{} } --func (m *StreamHealthRequest) String() string { return proto.CompactTextString(m) } --func (*StreamHealthRequest) ProtoMessage() {} --func (*StreamHealthRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{52} } -+func (m *StreamHealthRequest) String() string { return "TODO" } -+ - --// RealtimeStats contains information about the tablet status. --// It is only valid for a single tablet. -+ -+// RealtimeStats contains information about the tablet status - type RealtimeStats struct { - // health_error is the last error we got from health check, - // or empty is the server is healthy. This is used for subset selection, -@@ -2464,9 +2419,9 @@ - } - - func (m *RealtimeStats) Reset() { *m = RealtimeStats{} } --func (m *RealtimeStats) String() string { return proto.CompactTextString(m) } --func (*RealtimeStats) ProtoMessage() {} --func (*RealtimeStats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{53} } -+func (m *RealtimeStats) String() string { return "TODO" } -+ -+ - - func (m *RealtimeStats) GetHealthError() string { - if m != nil { -@@ -2510,80 +2465,17 @@ - return 0 - } - --// AggregateStats contains information about the health of a group of --// tablets for a Target. It is used to propagate stats from a vtgate --// to another, or from the Gateway layer of a vtgate to the routing --// layer. --type AggregateStats struct { -- // healthy_tablet_count is the number of healthy tablets in the group. -- HealthyTabletCount int32 `protobuf:"varint,1,opt,name=healthy_tablet_count,json=healthyTabletCount" json:"healthy_tablet_count,omitempty"` -- // unhealthy_tablet_count is the number of unhealthy tablets in the group. -- UnhealthyTabletCount int32 `protobuf:"varint,2,opt,name=unhealthy_tablet_count,json=unhealthyTabletCount" json:"unhealthy_tablet_count,omitempty"` -- // seconds_behind_master_min is the minimum of the -- // seconds_behind_master values of the healthy tablets. It is unset -- // if the tablet type is master. -- SecondsBehindMasterMin uint32 `protobuf:"varint,3,opt,name=seconds_behind_master_min,json=secondsBehindMasterMin" json:"seconds_behind_master_min,omitempty"` -- // seconds_behind_master_max is the maximum of the -- // seconds_behind_master values of the healthy tablets. It is unset -- // if the tablet type is master. -- SecondsBehindMasterMax uint32 `protobuf:"varint,4,opt,name=seconds_behind_master_max,json=secondsBehindMasterMax" json:"seconds_behind_master_max,omitempty"` --} -- --func (m *AggregateStats) Reset() { *m = AggregateStats{} } --func (m *AggregateStats) String() string { return proto.CompactTextString(m) } --func (*AggregateStats) ProtoMessage() {} --func (*AggregateStats) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{54} } -- --func (m *AggregateStats) GetHealthyTabletCount() int32 { -- if m != nil { -- return m.HealthyTabletCount -- } -- return 0 --} -- --func (m *AggregateStats) GetUnhealthyTabletCount() int32 { -- if m != nil { -- return m.UnhealthyTabletCount -- } -- return 0 --} -- --func (m *AggregateStats) GetSecondsBehindMasterMin() uint32 { -- if m != nil { -- return m.SecondsBehindMasterMin -- } -- return 0 --} -- --func (m *AggregateStats) GetSecondsBehindMasterMax() uint32 { -- if m != nil { -- return m.SecondsBehindMasterMax -- } -- return 0 --} -- --// StreamHealthResponse is streamed by StreamHealth on a regular basis. --// When StreamHealth is used between a vtgate and vttablet: --// - target describes the tablet. --// - realtime_stats is set. --// - aggregate_stats is not set. --// When StreamHealth is used between two vtgates: --// - target describes the group of tablets. --// - realtime_stats is not set. --// - aggregate_stats is set. -+// StreamHealthResponse is streamed by StreamHealth on a regular basis - type StreamHealthResponse struct { - // target is the current server type. Only queries with that exact Target -- // record will be accepted (the cell may not match, however). -+ // record will be accepted. - Target *Target `protobuf:"bytes,1,opt,name=target" json:"target,omitempty"` - // serving is true iff the tablet is serving. A tablet may not be serving - // if filtered replication is enabled on a master for instance, - // or if a replica should not be used because the keyspace is being resharded. - Serving bool `protobuf:"varint,2,opt,name=serving" json:"serving,omitempty"` -- // tablet_externally_reparented_timestamp can be interpreted as the -- // last time we knew that this tablet was the MASTER of this shard -- // (if StreamHealthResponse describes a group of tablets, between -- // two vtgates, only one master will be present in the group, and -- // this is this master's value). -+ // tablet_externally_reparented_timestamp can be interpreted as the last time -+ // we knew that this tablet was the MASTER of this shard. - // - // It is used by vtgate when determining the current MASTER of a shard. - // If vtgate sees more than one MASTER tablet, this timestamp is used -@@ -2606,12 +2498,8 @@ - // OR - // d) 0 if the vttablet was never a MASTER. - TabletExternallyReparentedTimestamp int64 `protobuf:"varint,3,opt,name=tablet_externally_reparented_timestamp,json=tabletExternallyReparentedTimestamp" json:"tablet_externally_reparented_timestamp,omitempty"` -- // realtime_stats contains information about the tablet status. -- // It is only filled in if the information is about a tablet. -+ // realtime_stats contains information about the tablet status - RealtimeStats *RealtimeStats `protobuf:"bytes,4,opt,name=realtime_stats,json=realtimeStats" json:"realtime_stats,omitempty"` -- // AggregateStats constains information about the group of tablet status. -- // It is only filled in if the information is about a group of tablets. -- AggregateStats *AggregateStats `protobuf:"bytes,6,opt,name=aggregate_stats,json=aggregateStats" json:"aggregate_stats,omitempty"` - // tablet_alias is the alias of the sending tablet. The discovery/healthcheck.go - // code uses it to verify that it's talking to the correct tablet and that it - // hasn't changed in the meantime e.g. due to tablet restarts where ports or -@@ -2620,9 +2508,9 @@ - } - - func (m *StreamHealthResponse) Reset() { *m = StreamHealthResponse{} } --func (m *StreamHealthResponse) String() string { return proto.CompactTextString(m) } --func (*StreamHealthResponse) ProtoMessage() {} --func (*StreamHealthResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{55} } -+func (m *StreamHealthResponse) String() string { return "TODO" } -+ -+ - - func (m *StreamHealthResponse) GetTarget() *Target { - if m != nil { -@@ -2652,13 +2540,6 @@ - return nil - } - --func (m *StreamHealthResponse) GetAggregateStats() *AggregateStats { -- if m != nil { -- return m.AggregateStats -- } -- return nil --} -- - func (m *StreamHealthResponse) GetTabletAlias() *topodata.TabletAlias { - if m != nil { - return m.TabletAlias -@@ -2682,9 +2563,9 @@ - } - - func (m *UpdateStreamRequest) Reset() { *m = UpdateStreamRequest{} } --func (m *UpdateStreamRequest) String() string { return proto.CompactTextString(m) } --func (*UpdateStreamRequest) ProtoMessage() {} --func (*UpdateStreamRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{56} } -+func (m *UpdateStreamRequest) String() string { return "TODO" } -+ -+ - - func (m *UpdateStreamRequest) GetEffectiveCallerId() *vtrpc.CallerID { - if m != nil { -@@ -2727,9 +2608,9 @@ - } - - func (m *UpdateStreamResponse) Reset() { *m = UpdateStreamResponse{} } --func (m *UpdateStreamResponse) String() string { return proto.CompactTextString(m) } --func (*UpdateStreamResponse) ProtoMessage() {} --func (*UpdateStreamResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{57} } -+func (m *UpdateStreamResponse) String() string { return "TODO" } -+ -+ - - func (m *UpdateStreamResponse) GetEvent() *StreamEvent { - if m != nil { -@@ -2747,9 +2628,9 @@ - } - - func (m *TransactionMetadata) Reset() { *m = TransactionMetadata{} } --func (m *TransactionMetadata) String() string { return proto.CompactTextString(m) } --func (*TransactionMetadata) ProtoMessage() {} --func (*TransactionMetadata) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{58} } -+func (m *TransactionMetadata) String() string { return "TODO" } -+ -+ - - func (m *TransactionMetadata) GetDtid() string { - if m != nil { -@@ -2835,7 +2716,6 @@ - proto.RegisterType((*SplitQueryResponse)(nil), "query.SplitQueryResponse") - proto.RegisterType((*StreamHealthRequest)(nil), "query.StreamHealthRequest") - proto.RegisterType((*RealtimeStats)(nil), "query.RealtimeStats") -- proto.RegisterType((*AggregateStats)(nil), "query.AggregateStats") - proto.RegisterType((*StreamHealthResponse)(nil), "query.StreamHealthResponse") - proto.RegisterType((*UpdateStreamRequest)(nil), "query.UpdateStreamRequest") - proto.RegisterType((*UpdateStreamResponse)(nil), "query.UpdateStreamResponse") -@@ -2851,207 +2731,4 @@ - proto.RegisterEnum("query.SplitQueryRequest_Algorithm", SplitQueryRequest_Algorithm_name, SplitQueryRequest_Algorithm_value) - } - --func init() { proto.RegisterFile("query.proto", fileDescriptor0) } -- --var fileDescriptor0 = []byte{ -- // 3183 bytes of a gzipped FileDescriptorProto -- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x5a, 0xcb, 0x73, 0x1b, 0xc7, -- 0x99, 0xd7, 0xe0, 0x41, 0x02, 0x1f, 0x08, 0xb0, 0xd9, 0x20, 0x25, 0x88, 0xf2, 0x83, 0x3b, 0xb6, -- 0x6c, 0x2e, 0xed, 0xe5, 0xca, 0x94, 0x56, 0xab, 0xb5, 0x77, 0xbd, 0x1a, 0x82, 0x43, 0x19, 0x16, -- 0x5e, 0x6a, 0x0c, 0x24, 0xcb, 0xe5, 0xaa, 0xa9, 0x21, 0xd0, 0x02, 0xa7, 0x38, 0xc0, 0x40, 0x33, -- 0x03, 0x51, 0xbc, 0x69, 0xd7, 0x71, 0xde, 0x0f, 0xe7, 0xe9, 0x38, 0xa9, 0x38, 0xa9, 0xca, 0x3d, -- 0x7f, 0x43, 0x2a, 0x7f, 0x40, 0x6e, 0x39, 0x24, 0x39, 0xe4, 0x90, 0x4a, 0xe5, 0x90, 0x2a, 0x57, -- 0x4e, 0x39, 0xe4, 0x90, 0x4a, 0xf5, 0x63, 0x06, 0x03, 0x12, 0x7a, 0x58, 0xc9, 0x85, 0xb2, 0x4f, -- 0xe8, 0xfe, 0xbe, 0xaf, 0x1f, 0xbf, 0xdf, 0xf7, 0xcd, 0xd7, 0x8d, 0xee, 0x86, 0xdc, 0xed, 0x11, -- 0xf5, 0x0e, 0xd6, 0x87, 0x9e, 0x1b, 0xb8, 0x38, 0xcd, 0x2b, 0xcb, 0x85, 0xc0, 0x1d, 0xba, 0x5d, -- 0x2b, 0xb0, 0x84, 0x78, 0x39, 0x77, 0x27, 0xf0, 0x86, 0x1d, 0x51, 0x51, 0xdf, 0x53, 0x60, 0xc6, -- 0xb0, 0xbc, 0x1e, 0x0d, 0xf0, 0x32, 0x64, 0xf6, 0xe8, 0x81, 0x3f, 0xb4, 0x3a, 0xb4, 0xa4, 0xac, -- 0x28, 0xab, 0x59, 0x12, 0xd5, 0xf1, 0x22, 0xa4, 0xfd, 0x5d, 0xcb, 0xeb, 0x96, 0x12, 0x5c, 0x21, -- 0x2a, 0xf8, 0x3f, 0x20, 0x17, 0x58, 0x3b, 0x0e, 0x0d, 0xcc, 0xe0, 0x60, 0x48, 0x4b, 0xc9, 0x15, -- 0x65, 0xb5, 0xb0, 0xb1, 0xb8, 0x1e, 0x8d, 0x67, 0x70, 0xa5, 0x71, 0x30, 0xa4, 0x04, 0x82, 0xa8, -- 0x8c, 0x31, 0xa4, 0x3a, 0xd4, 0x71, 0x4a, 0x29, 0xde, 0x17, 0x2f, 0xab, 0x5b, 0x50, 0xb8, 0x6e, -- 0x5c, 0xb1, 0x02, 0x5a, 0xb6, 0x1c, 0x87, 0x7a, 0x95, 0x2d, 0x36, 0x9d, 0x91, 0x4f, 0xbd, 0x81, -- 0xd5, 0x8f, 0xa6, 0x13, 0xd6, 0xf1, 0x49, 0x98, 0xe9, 0x79, 0xee, 0x68, 0xe8, 0x97, 0x12, 0x2b, -- 0xc9, 0xd5, 0x2c, 0x91, 0x35, 0xf5, 0x1d, 0x00, 0xfd, 0x0e, 0x1d, 0x04, 0x86, 0xbb, 0x47, 0x07, -- 0xf8, 0x29, 0xc8, 0x06, 0x76, 0x9f, 0xfa, 0x81, 0xd5, 0x1f, 0xf2, 0x2e, 0x92, 0x64, 0x2c, 0xb8, -- 0x0f, 0xa4, 0x65, 0xc8, 0x0c, 0x5d, 0xdf, 0x0e, 0x6c, 0x77, 0xc0, 0xf1, 0x64, 0x49, 0x54, 0x57, -- 0x5f, 0x87, 0xf4, 0x75, 0xcb, 0x19, 0x51, 0xfc, 0x2c, 0xa4, 0x38, 0x60, 0x85, 0x03, 0xce, 0xad, -- 0x0b, 0xd2, 0x39, 0x4e, 0xae, 0x60, 0x7d, 0xdf, 0x61, 0x96, 0xbc, 0xef, 0x39, 0x22, 0x2a, 0xea, -- 0x1e, 0xcc, 0x6d, 0xda, 0x83, 0xee, 0x75, 0xcb, 0xb3, 0x19, 0x19, 0x8f, 0xd9, 0x0d, 0x7e, 0x1e, -- 0x66, 0x78, 0xc1, 0x2f, 0x25, 0x57, 0x92, 0xab, 0xb9, 0x8d, 0x39, 0xd9, 0x90, 0xcf, 0x8d, 0x48, -- 0x9d, 0xfa, 0x0b, 0x05, 0x60, 0xd3, 0x1d, 0x0d, 0xba, 0xd7, 0x98, 0x12, 0x23, 0x48, 0xfa, 0xb7, -- 0x1d, 0x49, 0x24, 0x2b, 0xe2, 0xab, 0x50, 0xd8, 0xb1, 0x07, 0x5d, 0xf3, 0x8e, 0x9c, 0x8e, 0xe0, -- 0x32, 0xb7, 0xf1, 0xbc, 0xec, 0x6e, 0xdc, 0x78, 0x3d, 0x3e, 0x6b, 0x5f, 0x1f, 0x04, 0xde, 0x01, -- 0xc9, 0xef, 0xc4, 0x65, 0xcb, 0x6d, 0xc0, 0x47, 0x8d, 0xd8, 0xa0, 0x7b, 0xf4, 0x20, 0x1c, 0x74, -- 0x8f, 0x1e, 0xe0, 0x7f, 0x8d, 0x23, 0xca, 0x6d, 0x14, 0xc3, 0xb1, 0x62, 0x6d, 0x25, 0xcc, 0x57, -- 0x13, 0x97, 0x14, 0xf5, 0x4f, 0x69, 0x28, 0xe8, 0x77, 0x69, 0x67, 0x14, 0xd0, 0xc6, 0x90, 0xf9, -- 0xc0, 0xc7, 0xeb, 0x50, 0xb4, 0x07, 0x1d, 0x67, 0xd4, 0xa5, 0x26, 0x65, 0xae, 0x36, 0x03, 0xe6, -- 0x6b, 0xde, 0x5f, 0x86, 0x2c, 0x48, 0x55, 0x2c, 0x08, 0x34, 0x28, 0x76, 0xdc, 0xfe, 0xd0, 0xf2, -- 0x26, 0xed, 0x93, 0x7c, 0xfc, 0x05, 0x39, 0xfe, 0xd8, 0x9e, 0x2c, 0x48, 0xeb, 0x58, 0x17, 0x35, -- 0x98, 0x97, 0xfd, 0x76, 0xcd, 0x5b, 0x36, 0x75, 0xba, 0x3e, 0x0f, 0xdd, 0x42, 0x44, 0xd5, 0xe4, -- 0x14, 0xd7, 0x2b, 0xd2, 0x78, 0x9b, 0xdb, 0x92, 0x82, 0x3d, 0x51, 0xc7, 0x6b, 0xb0, 0xd0, 0x71, -- 0x6c, 0x36, 0x95, 0x5b, 0x8c, 0x62, 0xd3, 0x73, 0xf7, 0xfd, 0x52, 0x9a, 0xcf, 0x7f, 0x5e, 0x28, -- 0xb6, 0x99, 0x9c, 0xb8, 0xfb, 0x3e, 0x7e, 0x15, 0x32, 0xfb, 0xae, 0xb7, 0xe7, 0xb8, 0x56, 0xb7, -- 0x34, 0xc3, 0xc7, 0x7c, 0x66, 0xfa, 0x98, 0x37, 0xa4, 0x15, 0x89, 0xec, 0xf1, 0x2a, 0x20, 0xff, -- 0xb6, 0x63, 0xfa, 0xd4, 0xa1, 0x9d, 0xc0, 0x74, 0xec, 0xbe, 0x1d, 0x94, 0x32, 0xfc, 0x2b, 0x28, -- 0xf8, 0xb7, 0x9d, 0x16, 0x17, 0x57, 0x99, 0x14, 0x9b, 0xb0, 0x14, 0x78, 0xd6, 0xc0, 0xb7, 0x3a, -- 0xac, 0x33, 0xd3, 0xf6, 0x5d, 0xc7, 0xe2, 0x5f, 0x40, 0x96, 0x0f, 0xb9, 0x36, 0x7d, 0x48, 0x63, -- 0xdc, 0xa4, 0x12, 0xb6, 0x20, 0x8b, 0xc1, 0x14, 0x29, 0x7e, 0x05, 0x96, 0xfc, 0x3d, 0x7b, 0x68, -- 0xf2, 0x7e, 0xcc, 0xa1, 0x63, 0x0d, 0xcc, 0x8e, 0xd5, 0xd9, 0xa5, 0x25, 0xe0, 0xb0, 0x31, 0x53, -- 0xf2, 0x50, 0x6b, 0x3a, 0xd6, 0xa0, 0xcc, 0x34, 0xea, 0x6b, 0x50, 0x98, 0xe4, 0x11, 0x2f, 0x40, -- 0xde, 0xb8, 0xd9, 0xd4, 0x4d, 0xad, 0xbe, 0x65, 0xd6, 0xb5, 0x9a, 0x8e, 0x4e, 0xe0, 0x3c, 0x64, -- 0xb9, 0xa8, 0x51, 0xaf, 0xde, 0x44, 0x0a, 0x9e, 0x85, 0xa4, 0x56, 0xad, 0xa2, 0x84, 0x7a, 0x09, -- 0x32, 0x21, 0x21, 0x78, 0x1e, 0x72, 0xed, 0x7a, 0xab, 0xa9, 0x97, 0x2b, 0xdb, 0x15, 0x7d, 0x0b, -- 0x9d, 0xc0, 0x19, 0x48, 0x35, 0xaa, 0x46, 0x13, 0x29, 0xa2, 0xa4, 0x35, 0x51, 0x82, 0xb5, 0xdc, -- 0xda, 0xd4, 0x50, 0x52, 0x0d, 0x60, 0x71, 0x1a, 0x2e, 0x9c, 0x83, 0xd9, 0x2d, 0x7d, 0x5b, 0x6b, -- 0x57, 0x0d, 0x74, 0x02, 0x17, 0x61, 0x9e, 0xe8, 0x4d, 0x5d, 0x33, 0xb4, 0xcd, 0xaa, 0x6e, 0x12, -- 0x5d, 0xdb, 0x42, 0x0a, 0xc6, 0x50, 0x60, 0x25, 0xb3, 0xdc, 0xa8, 0xd5, 0x2a, 0x86, 0xa1, 0x6f, -- 0xa1, 0x04, 0x5e, 0x04, 0xc4, 0x65, 0xed, 0xfa, 0x58, 0x9a, 0xc4, 0x08, 0xe6, 0x5a, 0x3a, 0xa9, -- 0x68, 0xd5, 0xca, 0xdb, 0xac, 0x03, 0x94, 0x7a, 0x33, 0x95, 0x51, 0x50, 0x42, 0xfd, 0x20, 0x01, -- 0x69, 0x8e, 0x95, 0x65, 0xc8, 0x58, 0xde, 0xe3, 0xe5, 0x28, 0x5b, 0x24, 0x1e, 0x90, 0x2d, 0x78, -- 0x92, 0x95, 0x79, 0x4b, 0x54, 0xf0, 0x19, 0xc8, 0xba, 0x5e, 0xcf, 0x14, 0x1a, 0x91, 0x71, 0x33, -- 0xae, 0xd7, 0xe3, 0xa9, 0x99, 0x65, 0x3b, 0x96, 0xa8, 0x77, 0x2c, 0x9f, 0xf2, 0x08, 0xcc, 0x92, -- 0xa8, 0x8e, 0x4f, 0x03, 0xb3, 0x33, 0xf9, 0x3c, 0x66, 0xb8, 0x6e, 0xd6, 0xf5, 0x7a, 0x75, 0x36, -- 0x95, 0xe7, 0x20, 0xdf, 0x71, 0x9d, 0x51, 0x7f, 0x60, 0x3a, 0x74, 0xd0, 0x0b, 0x76, 0x4b, 0xb3, -- 0x2b, 0xca, 0x6a, 0x9e, 0xcc, 0x09, 0x61, 0x95, 0xcb, 0x70, 0x09, 0x66, 0x3b, 0xbb, 0x96, 0xe7, -- 0x53, 0x11, 0x75, 0x79, 0x12, 0x56, 0xf9, 0xa8, 0xb4, 0x63, 0xf7, 0x2d, 0xc7, 0xe7, 0x11, 0x96, -- 0x27, 0x51, 0x9d, 0x81, 0xb8, 0xe5, 0x58, 0x3d, 0x9f, 0x47, 0x46, 0x9e, 0x88, 0x8a, 0xfa, 0x9f, -- 0x90, 0x24, 0xee, 0x3e, 0xeb, 0x52, 0x0c, 0xe8, 0x97, 0x94, 0x95, 0xe4, 0x2a, 0x26, 0x61, 0x95, -- 0x2d, 0x08, 0x32, 0x27, 0x8a, 0x54, 0x19, 0x66, 0xc1, 0x77, 0x60, 0x8e, 0x50, 0x7f, 0xe4, 0x04, -- 0xfa, 0xdd, 0xc0, 0xb3, 0x7c, 0xbc, 0x01, 0xb9, 0x78, 0x16, 0x50, 0xee, 0x97, 0x05, 0x80, 0x8e, -- 0x3f, 0xff, 0x12, 0xcc, 0xde, 0xf2, 0xa8, 0xbf, 0x4b, 0x3d, 0x99, 0x65, 0xc2, 0x2a, 0xcb, 0xb1, -- 0x39, 0x1e, 0xb6, 0x62, 0x0c, 0x96, 0x99, 0x65, 0x7e, 0x50, 0x26, 0x32, 0x33, 0x77, 0x2a, 0x91, -- 0x3a, 0xc6, 0x1e, 0xfb, 0xe4, 0x4d, 0xeb, 0xd6, 0x2d, 0xda, 0x09, 0xa8, 0x58, 0x80, 0x52, 0x64, -- 0x8e, 0x09, 0x35, 0x29, 0x63, 0x6e, 0xb3, 0x07, 0x3e, 0xf5, 0x02, 0xd3, 0xee, 0x72, 0x87, 0xa6, -- 0x48, 0x46, 0x08, 0x2a, 0x5d, 0xfc, 0x0c, 0xa4, 0x78, 0xd2, 0x48, 0xf1, 0x51, 0x40, 0x8e, 0x42, -- 0xdc, 0x7d, 0xc2, 0xe5, 0xf8, 0x25, 0x98, 0xa1, 0x1c, 0x2f, 0x77, 0xea, 0x38, 0xcd, 0xc6, 0xa9, -- 0x20, 0xd2, 0x44, 0xfd, 0x49, 0x12, 0x72, 0xad, 0xc0, 0xa3, 0x56, 0x9f, 0xe3, 0xc7, 0xff, 0x0d, -- 0xe0, 0x07, 0x56, 0x40, 0xfb, 0x74, 0x10, 0x84, 0x40, 0x9e, 0x92, 0x1d, 0xc4, 0xec, 0xd6, 0x5b, -- 0xa1, 0x11, 0x89, 0xd9, 0x1f, 0x26, 0x38, 0xf1, 0x08, 0x04, 0x2f, 0x7f, 0x94, 0x80, 0x6c, 0xd4, -- 0x1b, 0xd6, 0x20, 0xd3, 0xb1, 0x02, 0xda, 0x73, 0xbd, 0x03, 0xb9, 0x32, 0x9e, 0x7d, 0xd0, 0xe8, -- 0xeb, 0x65, 0x69, 0x4c, 0xa2, 0x66, 0xf8, 0x69, 0x10, 0xdb, 0x0d, 0x11, 0xbc, 0x62, 0x7d, 0xcf, -- 0x72, 0x09, 0x0f, 0xdf, 0x57, 0x01, 0x0f, 0x3d, 0xbb, 0x6f, 0x79, 0x07, 0xe6, 0x1e, 0x3d, 0x08, -- 0x53, 0x7a, 0x72, 0x8a, 0xcb, 0x90, 0xb4, 0xbb, 0x4a, 0x0f, 0x64, 0x12, 0xba, 0x34, 0xd9, 0x56, -- 0x06, 0xdd, 0x51, 0x47, 0xc4, 0x5a, 0xf2, 0x75, 0xd9, 0x0f, 0x57, 0xe0, 0x34, 0x8f, 0x4f, 0x56, -- 0x54, 0x5f, 0x84, 0x4c, 0x38, 0x79, 0x9c, 0x85, 0xb4, 0xee, 0x79, 0xae, 0x87, 0x4e, 0xf0, 0x5c, -- 0x54, 0xab, 0x8a, 0x74, 0xb6, 0xb5, 0xc5, 0xd2, 0xd9, 0xcf, 0x13, 0xd1, 0x32, 0x48, 0xe8, 0xed, -- 0x11, 0xf5, 0x03, 0xfc, 0xbf, 0x50, 0xa4, 0x3c, 0x56, 0xec, 0x3b, 0xd4, 0xec, 0xf0, 0x3d, 0x13, -- 0x8b, 0x14, 0x11, 0xd0, 0xf3, 0xeb, 0x62, 0x8b, 0x17, 0xee, 0xa5, 0xc8, 0x42, 0x64, 0x2b, 0x45, -- 0x5d, 0xac, 0x43, 0xd1, 0xee, 0xf7, 0x69, 0xd7, 0xb6, 0x82, 0x78, 0x07, 0xc2, 0x61, 0x4b, 0xe1, -- 0x96, 0x62, 0x62, 0x4b, 0x46, 0x16, 0xa2, 0x16, 0x51, 0x37, 0x67, 0x61, 0x26, 0xe0, 0xdb, 0x47, -- 0xb9, 0xa2, 0xe6, 0xc3, 0xbc, 0xc4, 0x85, 0x44, 0x2a, 0xf1, 0x8b, 0x20, 0x36, 0xa3, 0x3c, 0x03, -- 0x8d, 0x03, 0x62, 0xbc, 0xc7, 0x20, 0x42, 0x8f, 0xcf, 0x42, 0x61, 0x62, 0x29, 0xea, 0x72, 0xc2, -- 0x92, 0x24, 0x1f, 0x5f, 0x57, 0xba, 0xf8, 0xdf, 0x61, 0xd6, 0x15, 0xcb, 0x10, 0xcf, 0x4d, 0xe3, -- 0x19, 0x4f, 0xae, 0x51, 0x24, 0xb4, 0x52, 0xff, 0x07, 0xe6, 0x23, 0x06, 0xfd, 0xa1, 0x3b, 0xf0, -- 0x29, 0x5e, 0x83, 0x19, 0x8f, 0x7f, 0x10, 0x92, 0x35, 0x2c, 0xbb, 0x88, 0x7d, 0xd1, 0x44, 0x5a, -- 0xa8, 0x5d, 0x98, 0x17, 0x92, 0x1b, 0x76, 0xb0, 0xcb, 0x1d, 0x85, 0xcf, 0x42, 0x9a, 0xb2, 0xc2, -- 0x21, 0xce, 0x49, 0xb3, 0xcc, 0xf5, 0x44, 0x68, 0x63, 0xa3, 0x24, 0x1e, 0x3a, 0xca, 0x9f, 0x13, -- 0x50, 0x94, 0xb3, 0xdc, 0xb4, 0x82, 0xce, 0xee, 0x31, 0x75, 0xf6, 0x4b, 0x30, 0xcb, 0xe4, 0x76, -- 0xf4, 0x61, 0x4c, 0x71, 0x77, 0x68, 0xc1, 0x1c, 0x6e, 0xf9, 0x66, 0xcc, 0xbb, 0x72, 0x2b, 0x94, -- 0xb7, 0xfc, 0xd8, 0x42, 0x3c, 0x25, 0x2e, 0x66, 0x1e, 0x12, 0x17, 0xb3, 0x8f, 0x14, 0x17, 0x5b, -- 0xb0, 0x38, 0xc9, 0xb8, 0x0c, 0x8e, 0x97, 0x61, 0x56, 0x38, 0x25, 0x4c, 0x81, 0xd3, 0xfc, 0x16, -- 0x9a, 0xa8, 0x3f, 0x4e, 0xc0, 0xa2, 0xcc, 0x4e, 0x9f, 0x8e, 0xcf, 0x34, 0xc6, 0x73, 0xfa, 0x91, -- 0x78, 0x2e, 0xc3, 0xd2, 0x21, 0x82, 0x1e, 0xe3, 0x2b, 0xfc, 0x58, 0x81, 0xb9, 0x4d, 0xda, 0xb3, -- 0x07, 0xc7, 0x94, 0xde, 0x18, 0x6b, 0xa9, 0x47, 0x62, 0xed, 0x22, 0xe4, 0x25, 0x5e, 0xc9, 0xd6, -- 0xd1, 0xcf, 0x40, 0x99, 0xf2, 0x19, 0xa8, 0x7f, 0x50, 0x20, 0x5f, 0x76, 0xfb, 0x7d, 0x3b, 0x38, -- 0xa6, 0x4c, 0x1d, 0xc5, 0x99, 0x9a, 0x86, 0x13, 0x41, 0x21, 0x84, 0x29, 0x08, 0x52, 0xff, 0xa8, -- 0xc0, 0x3c, 0x71, 0x1d, 0x67, 0xc7, 0xea, 0xec, 0x3d, 0xd9, 0xd8, 0x31, 0xa0, 0x31, 0x50, 0x89, -- 0xfe, 0xaf, 0x0a, 0x14, 0x9a, 0x1e, 0x65, 0xff, 0x5f, 0x9f, 0x68, 0xf0, 0xec, 0x0f, 0x52, 0x37, -- 0x90, 0x9b, 0x83, 0x2c, 0xe1, 0x65, 0x75, 0x01, 0xe6, 0x23, 0xec, 0x92, 0x8f, 0xdf, 0x28, 0xb0, -- 0x24, 0x02, 0x44, 0x6a, 0xba, 0xc7, 0x94, 0x96, 0x10, 0x6f, 0x2a, 0x86, 0xb7, 0x04, 0x27, 0x0f, -- 0x63, 0x93, 0xb0, 0xdf, 0x4d, 0xc0, 0xa9, 0x30, 0x36, 0x8e, 0x39, 0xf0, 0x7f, 0x20, 0x1e, 0x96, -- 0xa1, 0x74, 0x94, 0x04, 0xc9, 0xd0, 0xfb, 0x09, 0x28, 0x95, 0x3d, 0x6a, 0x05, 0x34, 0xb6, 0xc9, -- 0x78, 0x72, 0x62, 0x03, 0xbf, 0x02, 0x73, 0x43, 0xcb, 0x0b, 0xec, 0x8e, 0x3d, 0xb4, 0xd8, 0xdf, -- 0xb8, 0x34, 0xdf, 0xc3, 0x1c, 0xea, 0x60, 0xc2, 0x44, 0x3d, 0x03, 0xa7, 0xa7, 0x30, 0x22, 0xf9, -- 0xfa, 0x9b, 0x02, 0xb8, 0x15, 0x58, 0x5e, 0xf0, 0x29, 0x58, 0x55, 0xa6, 0x06, 0xd3, 0x12, 0x14, -- 0x27, 0xf0, 0xc7, 0x79, 0xa1, 0xc1, 0xa7, 0x62, 0xc5, 0xb9, 0x2f, 0x2f, 0x71, 0xfc, 0x92, 0x97, -- 0xdf, 0x29, 0xb0, 0x5c, 0x76, 0xc5, 0xf9, 0xdd, 0x13, 0xf9, 0x85, 0xa9, 0x4f, 0xc3, 0x99, 0xa9, -- 0x00, 0x25, 0x01, 0xbf, 0x55, 0xe0, 0x24, 0xa1, 0x56, 0xf7, 0xc9, 0x04, 0x7f, 0x0d, 0x4e, 0x1d, -- 0x01, 0x27, 0x77, 0xa8, 0x17, 0x21, 0xd3, 0xa7, 0x81, 0xd5, 0xb5, 0x02, 0x4b, 0x42, 0x5a, 0x0e, -- 0xfb, 0x1d, 0x5b, 0xd7, 0xa4, 0x05, 0x89, 0x6c, 0xd5, 0x8f, 0x12, 0x50, 0xe4, 0x7b, 0xdd, 0xcf, -- 0xfe, 0x41, 0x4d, 0xff, 0x2f, 0xf0, 0xbe, 0x02, 0x8b, 0x93, 0x04, 0x45, 0xff, 0x09, 0xfe, 0xd9, -- 0x07, 0x11, 0x53, 0x12, 0x42, 0x72, 0xda, 0x16, 0xf4, 0x97, 0x09, 0x28, 0xc5, 0xa7, 0xf4, 0xd9, -- 0xa1, 0xc5, 0xe4, 0xa1, 0xc5, 0x27, 0x3e, 0xa5, 0xfa, 0x40, 0x81, 0xd3, 0x53, 0x08, 0xfd, 0x64, -- 0x8e, 0x8e, 0x1d, 0x5d, 0x24, 0x1e, 0x7a, 0x74, 0xf1, 0xa8, 0xae, 0xfe, 0xb5, 0x02, 0x8b, 0x35, -- 0xea, 0xfb, 0x56, 0x8f, 0x8a, 0xff, 0xf1, 0xc7, 0x37, 0x9b, 0xf1, 0x43, 0xe1, 0xd4, 0xf8, 0x66, -- 0x45, 0x2d, 0xc3, 0xd2, 0x21, 0x68, 0x8f, 0x71, 0x36, 0xf1, 0x17, 0x05, 0x16, 0x64, 0x2f, 0xda, -- 0xb1, 0xdd, 0x08, 0x4c, 0x61, 0x07, 0x3f, 0x03, 0x49, 0xbb, 0x1b, 0xee, 0x20, 0x27, 0xef, 0x9a, -- 0x99, 0x42, 0xbd, 0x0c, 0x38, 0x8e, 0xfb, 0x31, 0xa8, 0xfb, 0x55, 0x12, 0x16, 0x5a, 0x43, 0xc7, -- 0x0e, 0xa4, 0xf2, 0xc9, 0x4e, 0xfc, 0xff, 0x02, 0x73, 0x3e, 0x03, 0x6b, 0x8a, 0xdb, 0x32, 0x4e, -- 0x6c, 0x96, 0xe4, 0xb8, 0xac, 0xcc, 0x45, 0xf8, 0x59, 0xc8, 0x85, 0x26, 0xa3, 0x41, 0x20, 0x4f, -- 0x3a, 0x41, 0x5a, 0x8c, 0x06, 0x01, 0xbe, 0x00, 0xa7, 0x06, 0xa3, 0x3e, 0xbf, 0x39, 0x36, 0x87, -- 0xd4, 0x0b, 0xef, 0x55, 0x2d, 0x2f, 0xbc, 0xe1, 0x2d, 0x0e, 0x46, 0x7d, 0xe2, 0xee, 0xfb, 0x4d, -- 0xea, 0x89, 0x7b, 0x55, 0xcb, 0x0b, 0xf0, 0x65, 0xc8, 0x5a, 0x4e, 0xcf, 0xf5, 0xec, 0x60, 0xb7, -- 0x2f, 0xaf, 0x76, 0xd5, 0xf0, 0x6a, 0xe5, 0x30, 0xfd, 0xeb, 0x5a, 0x68, 0x49, 0xc6, 0x8d, 0xd4, -- 0x97, 0x21, 0x1b, 0xc9, 0x31, 0x82, 0x39, 0xfd, 0x5a, 0x5b, 0xab, 0x9a, 0xad, 0x66, 0xb5, 0x62, -- 0xb4, 0xc4, 0x75, 0xec, 0x76, 0xbb, 0x5a, 0x35, 0x5b, 0x65, 0xad, 0x8e, 0x14, 0x95, 0x00, 0xf0, -- 0x2e, 0x79, 0xe7, 0x63, 0x82, 0x94, 0x87, 0x10, 0x74, 0x06, 0xb2, 0x9e, 0xbb, 0x2f, 0xb1, 0x27, -- 0x38, 0x9c, 0x8c, 0xe7, 0xee, 0x73, 0xe4, 0xaa, 0x06, 0x38, 0x3e, 0x57, 0x19, 0x6d, 0xb1, 0xe4, -- 0xad, 0x4c, 0x24, 0xef, 0xf1, 0xf8, 0x51, 0xf2, 0x16, 0x5b, 0x79, 0xf6, 0x9d, 0xbf, 0x41, 0x2d, -- 0x27, 0x08, 0xd7, 0x2b, 0xf5, 0xa7, 0x09, 0xc8, 0x13, 0x26, 0xb1, 0xfb, 0xb4, 0x15, 0x58, 0x81, -- 0xcf, 0x3c, 0xb5, 0xcb, 0x4d, 0xcc, 0x71, 0xda, 0xcd, 0x92, 0x9c, 0x90, 0x89, 0x4b, 0x80, 0x0d, -- 0x58, 0xf2, 0x69, 0xc7, 0x1d, 0x74, 0x7d, 0x73, 0x87, 0xee, 0xda, 0x83, 0xae, 0xd9, 0xb7, 0xfc, -- 0x40, 0xde, 0x14, 0xe6, 0x49, 0x51, 0x2a, 0x37, 0xb9, 0xae, 0xc6, 0x55, 0xf8, 0x1c, 0x2c, 0xee, -- 0xd8, 0x03, 0xc7, 0xed, 0x99, 0x43, 0xc7, 0x3a, 0xa0, 0x9e, 0x2f, 0xa1, 0xb2, 0xf0, 0x4a, 0x13, -- 0x2c, 0x74, 0x4d, 0xa1, 0x12, 0xee, 0x7e, 0x1b, 0xd6, 0xa6, 0x8e, 0x62, 0xde, 0xb2, 0x9d, 0x80, -- 0x7a, 0xb4, 0x6b, 0x7a, 0x74, 0xe8, 0xd8, 0x1d, 0x71, 0x69, 0x2f, 0xf6, 0xee, 0x2f, 0x4c, 0x19, -- 0x7a, 0x5b, 0x9a, 0x93, 0xb1, 0x35, 0x63, 0xbb, 0x33, 0x1c, 0x99, 0x23, 0xf6, 0x01, 0xf3, 0x55, -- 0x4c, 0x21, 0x99, 0xce, 0x70, 0xd4, 0x66, 0x75, 0x8c, 0x20, 0x79, 0x7b, 0x28, 0x16, 0x2f, 0x85, -- 0xb0, 0xa2, 0xfa, 0xb1, 0x02, 0x05, 0xad, 0xd7, 0xf3, 0x68, 0xcf, 0x0a, 0x24, 0x4d, 0xe7, 0x60, -- 0x51, 0x50, 0x72, 0x60, 0xca, 0xd7, 0x40, 0x02, 0x8f, 0x22, 0xf0, 0x48, 0x9d, 0x78, 0x0b, 0x14, -- 0x86, 0xef, 0xc9, 0xd1, 0x60, 0x6a, 0x9b, 0x04, 0x6f, 0xb3, 0x18, 0x69, 0xe3, 0xad, 0xfe, 0x0b, -- 0x4e, 0x4f, 0x67, 0xa1, 0x6f, 0x8b, 0xf7, 0x1c, 0x79, 0x72, 0x72, 0x0a, 0xe8, 0x9a, 0x3d, 0x78, -- 0x40, 0x53, 0xeb, 0x2e, 0xe7, 0xeb, 0x3e, 0x4d, 0xad, 0xbb, 0xea, 0xef, 0xa3, 0xa3, 0xfd, 0x30, -- 0x5c, 0xa2, 0xd5, 0x38, 0xcc, 0x0b, 0xca, 0x83, 0xf2, 0x42, 0x09, 0x66, 0x7d, 0xea, 0xdd, 0xb1, -- 0x07, 0xbd, 0xf0, 0xf6, 0x58, 0x56, 0x71, 0x0b, 0x5e, 0x90, 0xd8, 0xe9, 0xdd, 0x80, 0x7a, 0x03, -- 0xcb, 0x71, 0x0e, 0x4c, 0x71, 0x50, 0x31, 0x08, 0x68, 0xd7, 0x1c, 0xbf, 0x5d, 0x12, 0x2b, 0xf2, -- 0x73, 0xc2, 0x5a, 0x8f, 0x8c, 0x49, 0x64, 0x6b, 0x44, 0xaf, 0x9a, 0x5e, 0x83, 0x82, 0x27, 0x83, -- 0xd8, 0xf4, 0x99, 0x7b, 0x64, 0x3e, 0x5a, 0x8c, 0xae, 0x80, 0x63, 0x11, 0x4e, 0xf2, 0xde, 0x44, -- 0xc0, 0xbf, 0x0e, 0xf3, 0x56, 0xe8, 0x5b, 0xd9, 0x7a, 0x72, 0xdf, 0x32, 0xe9, 0x79, 0x52, 0xb0, -- 0x26, 0x23, 0xe1, 0x12, 0xcc, 0x49, 0x44, 0x96, 0x63, 0x5b, 0xe3, 0x8d, 0xed, 0xa1, 0x07, 0x61, -- 0x1a, 0x53, 0x12, 0xf9, 0x74, 0x8c, 0x57, 0xd8, 0xff, 0xe8, 0x62, 0x7b, 0xd8, 0xe5, 0x3d, 0x1d, -- 0xe3, 0xdd, 0x45, 0xfc, 0xf5, 0x58, 0x6a, 0xf2, 0xf5, 0xd8, 0xe4, 0x6b, 0xb4, 0xf4, 0xa1, 0xd7, -- 0x68, 0xea, 0x65, 0x58, 0x9c, 0xc4, 0x2f, 0xa3, 0x6c, 0x15, 0xd2, 0xfc, 0xa6, 0xfc, 0xd0, 0x32, -- 0x1a, 0xbb, 0x0a, 0x27, 0xc2, 0x40, 0xfd, 0x99, 0x02, 0xc5, 0x29, 0x7f, 0xb1, 0xa2, 0xff, 0x6f, -- 0x4a, 0xec, 0x78, 0xe8, 0xdf, 0x20, 0xcd, 0xef, 0xec, 0xe5, 0x63, 0x92, 0x53, 0x47, 0xff, 0xa1, -- 0xf1, 0xfb, 0x75, 0x22, 0xac, 0x58, 0x22, 0xe4, 0x01, 0xd5, 0xe1, 0xe7, 0x43, 0xe1, 0x0e, 0x31, -- 0xc7, 0x64, 0xe2, 0xc8, 0xe8, 0xe8, 0x81, 0x53, 0xea, 0xa1, 0x07, 0x4e, 0x6b, 0xdf, 0x4a, 0x42, -- 0xb6, 0x76, 0xd0, 0xba, 0xed, 0x6c, 0x3b, 0x56, 0x8f, 0x5f, 0x80, 0xd7, 0x9a, 0xc6, 0x4d, 0x74, -- 0x02, 0x2f, 0x40, 0xbe, 0xde, 0x30, 0xcc, 0x3a, 0x5b, 0x4a, 0xb6, 0xab, 0xda, 0x15, 0xa4, 0xb0, -- 0xb5, 0xa6, 0x49, 0x2a, 0xe6, 0x55, 0xfd, 0xa6, 0x90, 0x24, 0x70, 0x11, 0xe6, 0xdb, 0xf5, 0xca, -- 0xb5, 0xb6, 0x3e, 0x16, 0xa6, 0xf0, 0x12, 0x2c, 0xd4, 0xda, 0x55, 0xa3, 0xd2, 0xac, 0xc6, 0xc4, -- 0x19, 0xb6, 0x2e, 0x6d, 0x56, 0x1b, 0x9b, 0xa2, 0x8a, 0x58, 0xff, 0xed, 0x7a, 0xab, 0x72, 0xa5, -- 0xae, 0x6f, 0x09, 0xd1, 0x0a, 0x13, 0xbd, 0xad, 0x93, 0xc6, 0x76, 0x25, 0x1c, 0xf2, 0x32, 0x46, -- 0x90, 0xdb, 0xac, 0xd4, 0x35, 0x22, 0x7b, 0xb9, 0xa7, 0xe0, 0x02, 0x64, 0xf5, 0x7a, 0xbb, 0x26, -- 0xeb, 0x09, 0x5c, 0x82, 0xa2, 0xd6, 0x36, 0x1a, 0x66, 0xa5, 0x5e, 0x26, 0x7a, 0x4d, 0xaf, 0x1b, -- 0x52, 0x93, 0xc2, 0x45, 0x28, 0x18, 0x95, 0x9a, 0xde, 0x32, 0xb4, 0x5a, 0x53, 0x0a, 0xd9, 0x2c, -- 0x32, 0x2d, 0x3d, 0xb4, 0x41, 0x78, 0x19, 0x96, 0xea, 0x0d, 0x53, 0x3e, 0x2a, 0x32, 0xaf, 0x6b, -- 0xd5, 0xb6, 0x2e, 0x75, 0x2b, 0xf8, 0x14, 0xe0, 0x46, 0xdd, 0x6c, 0x37, 0xb7, 0x34, 0x43, 0x37, -- 0xeb, 0x8d, 0x1b, 0x52, 0x71, 0x19, 0x17, 0x20, 0x33, 0x9e, 0xc1, 0x3d, 0xc6, 0x42, 0xbe, 0xa9, -- 0x11, 0x63, 0x0c, 0xf6, 0xde, 0x3d, 0x46, 0x16, 0x5c, 0x21, 0x8d, 0x76, 0x73, 0x6c, 0xb6, 0x00, -- 0x39, 0x49, 0x96, 0x14, 0xa5, 0x98, 0x68, 0xb3, 0x52, 0x2f, 0x47, 0xf3, 0xbb, 0x97, 0x59, 0x4e, -- 0x20, 0x65, 0x6d, 0x0f, 0x52, 0xdc, 0x1d, 0x19, 0x48, 0xd5, 0x1b, 0x75, 0x1d, 0x9d, 0xc0, 0xf3, -- 0x00, 0x95, 0x56, 0xa5, 0x6e, 0xe8, 0x57, 0x88, 0x56, 0x65, 0xb0, 0xb9, 0x20, 0x24, 0x90, 0xa1, -- 0x9d, 0x83, 0xd9, 0x4a, 0x6b, 0xbb, 0xda, 0xd0, 0x0c, 0x09, 0xb3, 0xd2, 0xba, 0xd6, 0x6e, 0x18, -- 0x4c, 0x89, 0x70, 0x0e, 0x66, 0x2a, 0x2d, 0x43, 0x7f, 0xcb, 0x60, 0xb8, 0xb8, 0x4e, 0xb0, 0x8a, -- 0xee, 0x5d, 0x5e, 0xfb, 0x30, 0x09, 0x29, 0xfe, 0x22, 0x34, 0x0f, 0x59, 0xee, 0x6d, 0xe3, 0x66, -- 0x93, 0x0d, 0x99, 0x85, 0x54, 0xa5, 0x6e, 0x5c, 0x42, 0xff, 0x97, 0xc0, 0x00, 0xe9, 0x36, 0x2f, -- 0xff, 0xff, 0x0c, 0x2b, 0x57, 0xea, 0xc6, 0x2b, 0x17, 0xd1, 0xbb, 0x09, 0xd6, 0x6d, 0x5b, 0x54, -- 0x3e, 0x17, 0x2a, 0x36, 0x2e, 0xa0, 0xf7, 0x22, 0xc5, 0xc6, 0x05, 0xf4, 0xf9, 0x50, 0x71, 0x7e, -- 0x03, 0x7d, 0x21, 0x52, 0x9c, 0xdf, 0x40, 0x5f, 0x0c, 0x15, 0x17, 0x2f, 0xa0, 0x2f, 0x45, 0x8a, -- 0x8b, 0x17, 0xd0, 0x97, 0x67, 0x18, 0x16, 0x8e, 0xe4, 0xfc, 0x06, 0xfa, 0x4a, 0x26, 0xaa, 0x5d, -- 0xbc, 0x80, 0xbe, 0x9a, 0x61, 0xfe, 0x8f, 0xbc, 0x8a, 0xbe, 0x86, 0xd8, 0x34, 0x99, 0x83, 0xd0, -- 0xd7, 0x79, 0x91, 0xa9, 0xd0, 0x37, 0x10, 0xc3, 0xc8, 0xa4, 0xbc, 0xfa, 0x3e, 0xd7, 0xdc, 0xd4, -- 0x35, 0x82, 0xbe, 0x39, 0x23, 0xde, 0x90, 0x95, 0x2b, 0x35, 0xad, 0x8a, 0x30, 0x6f, 0xc1, 0x58, -- 0xf9, 0xf6, 0x39, 0x56, 0x64, 0xe1, 0x89, 0xbe, 0xd3, 0x64, 0x03, 0x5e, 0xd7, 0x48, 0xf9, 0x0d, -- 0x8d, 0xa0, 0xef, 0x9e, 0x63, 0x03, 0x5e, 0xd7, 0x88, 0xe4, 0xeb, 0x7b, 0x4d, 0x66, 0xc8, 0x55, -- 0x1f, 0x9c, 0x63, 0x93, 0x96, 0xf2, 0xef, 0x37, 0x71, 0x06, 0x92, 0x9b, 0x15, 0x03, 0x7d, 0xc8, -- 0x47, 0x63, 0x21, 0x8a, 0x7e, 0x80, 0x98, 0xb0, 0xa5, 0x1b, 0xe8, 0x87, 0x4c, 0x98, 0x36, 0xda, -- 0xcd, 0xaa, 0x8e, 0x9e, 0x62, 0x93, 0xbb, 0xa2, 0x37, 0x6a, 0xba, 0x41, 0x6e, 0xa2, 0x1f, 0x71, -- 0xf3, 0x37, 0x5b, 0x8d, 0x3a, 0xfa, 0x08, 0xe1, 0x02, 0x80, 0xfe, 0x56, 0x93, 0xe8, 0xad, 0x56, -- 0xa5, 0x51, 0x47, 0xcf, 0xae, 0x6d, 0x03, 0x3a, 0x9c, 0x0e, 0x18, 0x80, 0x76, 0xfd, 0x6a, 0xbd, -- 0x71, 0xa3, 0x8e, 0x4e, 0xb0, 0x4a, 0x93, 0xe8, 0x4d, 0x8d, 0xe8, 0x48, 0xc1, 0x00, 0x33, 0xe2, -- 0x85, 0x1b, 0x4a, 0xe0, 0x39, 0xc8, 0x90, 0x46, 0xb5, 0xba, 0xa9, 0x95, 0xaf, 0xa2, 0xe4, 0xe6, -- 0x02, 0xcc, 0xdb, 0xee, 0xfa, 0x1d, 0x3b, 0xa0, 0xbe, 0x2f, 0xde, 0x1c, 0xef, 0xcc, 0xf0, 0x9f, -- 0xf3, 0x7f, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xde, 0xe3, 0xd2, 0x1e, 0xad, 0x2c, 0x00, 0x00, --} -+*/ diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch deleted file mode 100644 index 9cdc14e0..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqlparser.patch +++ /dev/null @@ -1,316 +0,0 @@ -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .git -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .gitignore -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: .travis.yml -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: CONTRIBUTORS.md -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: LICENSE.md -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: README.md -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer.go 2018-06-06 07:45:09.000000000 -0700 -@@ -19,15 +19,13 @@ - // analyzer.go contains utility analysis functions. - - import ( -+ "errors" - "fmt" - "strconv" - "strings" - "unicode" - -- "vitess.io/vitess/go/sqltypes" -- "vitess.io/vitess/go/vt/vterrors" -- -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // These constants are used to identify the SQL statement type. -@@ -219,7 +217,7 @@ - case IntVal: - n, err := sqltypes.NewIntegral(string(node.Val)) - if err != nil { -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err) -+ return sqltypes.PlanValue{}, fmt.Errorf("%v", err) - } - return sqltypes.PlanValue{Value: n}, nil - case StrVal: -@@ -227,7 +225,7 @@ - case HexVal: - v, err := node.HexDecode() - if err != nil { -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err) -+ return sqltypes.PlanValue{}, fmt.Errorf("%v", err) - } - return sqltypes.PlanValue{Value: sqltypes.MakeTrusted(sqltypes.VarBinary, v)}, nil - } -@@ -243,7 +241,7 @@ - return sqltypes.PlanValue{}, err - } - if innerpv.ListKey != "" || innerpv.Values != nil { -- return sqltypes.PlanValue{}, vterrors.New(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: nested lists") -+ return sqltypes.PlanValue{}, errors.New("unsupported: nested lists") - } - pv.Values = append(pv.Values, innerpv) - } -@@ -251,7 +249,7 @@ - case *NullVal: - return sqltypes.PlanValue{}, nil - } -- return sqltypes.PlanValue{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "expression is too complex '%v'", String(node)) -+ return sqltypes.PlanValue{}, fmt.Errorf("expression is too complex '%v'", String(node)) - } - - // StringIn is a convenience function that returns -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/analyzer_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//analyzer_test.go 2018-06-06 07:45:09.000000000 -0700 -@@ -21,7 +21,7 @@ - "strings" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestPreview(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast.go 2018-06-06 07:45:09.000000000 -0700 -@@ -22,14 +22,11 @@ - "encoding/json" - "fmt" - "io" -+ "log" - "strings" - -- "vitess.io/vitess/go/sqltypes" -- "vitess.io/vitess/go/vt/log" -- "vitess.io/vitess/go/vt/vterrors" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // Instructions for creating new types: If a type -@@ -52,11 +49,11 @@ - tokenizer := NewStringTokenizer(sql) - if yyParse(tokenizer) != 0 { - if tokenizer.partialDDL != nil { -- log.Warningf("ignoring error parsing DDL '%s': %v", sql, tokenizer.LastError) -+ log.Printf("ignoring error parsing DDL '%s': %v", sql, tokenizer.LastError) - tokenizer.ParseTree = tokenizer.partialDDL - return tokenizer.ParseTree, nil - } -- return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, tokenizer.LastError.Error()) -+ return nil, tokenizer.LastError - } - return tokenizer.ParseTree, nil - } -@@ -2249,7 +2246,7 @@ - return NewStrVal(value.ToBytes()), nil - default: - // We cannot support sqltypes.Expression, or any other invalid type. -- return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "cannot convert value %v to AST", value) -+ return nil, fmt.Errorf("cannot convert value %v to AST", value) - } - } - -@@ -3394,6 +3391,20 @@ - return nil - } - -+// Backtick produces a backticked literal given an input string. -+func Backtick(in string) string { -+ var buf bytes.Buffer -+ buf.WriteByte('`') -+ for _, c := range in { -+ buf.WriteRune(c) -+ if c == '`' { -+ buf.WriteByte('`') -+ } -+ } -+ buf.WriteByte('`') -+ return buf.String() -+} -+ - func formatID(buf *TrackedBuffer, original, lowered string) { - isDbSystemVariable := false - if len(original) > 1 && original[:2] == "@@" { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/ast_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//ast_test.go 2018-06-05 07:41:09.000000000 -0700 -@@ -24,7 +24,7 @@ - "testing" - "unsafe" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestAppend(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments.go 2018-06-06 07:45:09.000000000 -0700 -@@ -145,7 +145,7 @@ - // Single line comment - index := strings.Index(sql, "\n") - if index == -1 { -- return "" -+ return sql - } - sql = sql[index+1:] - } -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/comments_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//comments_test.go 2018-06-06 07:45:08.000000000 -0700 -@@ -187,7 +187,7 @@ - outSQL: "bar", - }, { - input: "-- /* foo */ bar", -- outSQL: "", -+ outSQL: "-- /* foo */ bar", - }, { - input: "foo -- bar */", - outSQL: "foo -- bar */", -@@ -201,7 +201,7 @@ - outSQL: "a", - }, { - input: `-- foo bar`, -- outSQL: "", -+ outSQL: "-- foo bar", - }} - for _, testCase := range testCases { - gotSQL := StripLeadingComments(testCase.input) -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: dependency -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable.go 2017-10-18 18:06:33.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "bytes" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // This file contains types that are 'Encodable'. -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/encodable_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//encodable_test.go 2017-10-18 18:06:33.000000000 -0700 -@@ -20,7 +20,7 @@ - "bytes" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestEncodable(t *testing.T) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: github_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer.go 2017-10-18 18:06:33.000000000 -0700 -@@ -19,9 +19,9 @@ - import ( - "fmt" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // Normalize changes the statement to use bind values, and -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/normalizer_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//normalizer_test.go 2017-11-27 22:10:51.000000000 -0800 -@@ -21,8 +21,8 @@ - "reflect" - "testing" - -- "vitess.io/vitess/go/sqltypes" -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - func TestNormalize(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query.go 2017-10-22 13:30:37.000000000 -0700 -@@ -18,12 +18,10 @@ - - import ( - "bytes" -- "encoding/json" - "fmt" - -- "vitess.io/vitess/go/sqltypes" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - // ParsedQuery represents a parsed query where -@@ -71,12 +69,6 @@ - return buf.Bytes(), nil - } - --// MarshalJSON is a custom JSON marshaler for ParsedQuery. --// Note that any queries longer that 512 bytes will be truncated. --func (pq *ParsedQuery) MarshalJSON() ([]byte, error) { -- return json.Marshal(TruncateForUI(pq.Query)) --} -- - // EncodeValue encodes one bind variable value into the query. - func EncodeValue(buf *bytes.Buffer, value *querypb.BindVariable) { - if value.Type != querypb.Type_TUPLE { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/parsed_query_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//parsed_query_test.go 2017-10-18 18:06:33.000000000 -0700 -@@ -20,9 +20,9 @@ - "reflect" - "testing" - -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestNewParsedQuery(t *testing.T) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: patches -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: quick -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/redact_query.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//redact_query.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/redact_query.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//redact_query.go 2018-06-06 07:42:56.000000000 -0700 -@@ -1,6 +1,6 @@ - package sqlparser - --import querypb "vitess.io/vitess/go/vt/proto/query" -+import querypb "github.com/xwb1989/sqlparser/dependency/querypb" - - // RedactSQLQuery returns a sql string with the params stripped out for display - func RedactSQLQuery(sql string) (string, error) { -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: tests -diff -u /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/token.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//token.go ---- /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/token.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//token.go 2018-06-06 07:45:09.000000000 -0700 -@@ -22,8 +22,8 @@ - "fmt" - "io" - -- "vitess.io/vitess/go/bytes2" -- "vitess.io/vitess/go/sqltypes" -+ "github.com/xwb1989/sqlparser/dependency/bytes2" -+ "github.com/xwb1989/sqlparser/dependency/sqltypes" - ) - - const ( -Only in /Users/bramp/go/src/vitess.io/vitess/go//vt/sqlparser/: truncate_query.go -Only in /Users/bramp/go/src/github.com/xwb1989/sqlparser//: y.output diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch deleted file mode 100644 index 215ba9d8..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/patches/sqltypes.patch +++ /dev/null @@ -1,290 +0,0 @@ -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: arithmetic.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: arithmetic_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,11 +19,10 @@ - import ( - "errors" - "fmt" -+ "reflect" - "strconv" - -- "github.com/golang/protobuf/proto" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // NullBindVariable is a bindvar with NULL value. -@@ -253,9 +252,8 @@ - } - - // BindVariablesEqual compares two maps of bind variables. --// For protobuf messages we have to use "proto.Equal". - func BindVariablesEqual(x, y map[string]*querypb.BindVariable) bool { -- return proto.Equal(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y}) -+ return reflect.DeepEqual(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y}) - } - - // CopyBindVariables returns a shallow-copy of the given bindVariables map. -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/bind_variables_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/bind_variables_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -21,16 +21,14 @@ - "strings" - "testing" - -- "github.com/golang/protobuf/proto" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestProtoConversions(t *testing.T) { - v := TestValue(Int64, "1") - got := ValueToProto(v) - want := &querypb.Value{Type: Int64, Value: []byte("1")} -- if !proto.Equal(got, want) { -+ if !reflect.DeepEqual(got, want) { - t.Errorf("ValueToProto: %v, want %v", got, want) - } - gotback := ProtoToValue(got) -@@ -240,7 +238,7 @@ - t.Errorf("ToBindVar(%T(%v)) error: nil, want %s", tcase.in, tcase.in, tcase.err) - continue - } -- if !proto.Equal(bv, tcase.out) { -+ if !reflect.DeepEqual(bv, tcase.out) { - t.Errorf("ToBindVar(%T(%v)): %v, want %s", tcase.in, tcase.in, bv, tcase.out) - } - } -@@ -523,7 +521,7 @@ - v, err = BindVariableToValue(&querypb.BindVariable{Type: querypb.Type_TUPLE}) - wantErr := "cannot convert a TUPLE bind var into a value" - if err == nil || err.Error() != wantErr { -- t.Errorf(" BindVarToValue(TUPLE): (%v, %v), want %s", v, err, wantErr) -+ t.Errorf(" BindVarToValue(TUPLE): %v, want %s", err, wantErr) - } - } - -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: event_token.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: event_token_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value.go 2018-06-04 08:05:24.000000000 -0700 -@@ -18,10 +18,10 @@ - - import ( - "encoding/json" -+ "errors" -+ "fmt" - -- querypb "vitess.io/vitess/go/vt/proto/query" -- vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" -- "vitess.io/vitess/go/vt/vterrors" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // PlanValue represents a value or a list of values for -@@ -87,7 +87,7 @@ - case pv.ListKey != "" || pv.Values != nil: - // This code is unreachable because the parser does not allow - // multi-value constructs where a single value is expected. -- return NULL, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "a list was supplied where a single value was expected") -+ return NULL, errors.New("a list was supplied where a single value was expected") - } - return NULL, nil - } -@@ -95,10 +95,10 @@ - func (pv PlanValue) lookupValue(bindVars map[string]*querypb.BindVariable) (*querypb.BindVariable, error) { - bv, ok := bindVars[pv.Key] - if !ok { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "missing bind var %s", pv.Key) -+ return nil, fmt.Errorf("missing bind var %s", pv.Key) - } - if bv.Type == querypb.Type_TUPLE { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "TUPLE was supplied for single value bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("TUPLE was supplied for single value bind var %s", pv.ListKey) - } - return bv, nil - } -@@ -129,16 +129,16 @@ - } - // This code is unreachable because the parser does not allow - // single value constructs where multiple values are expected. -- return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "a single value was supplied where a list was expected") -+ return nil, errors.New("a single value was supplied where a list was expected") - } - - func (pv PlanValue) lookupList(bindVars map[string]*querypb.BindVariable) (*querypb.BindVariable, error) { - bv, ok := bindVars[pv.ListKey] - if !ok { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "missing bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("missing bind var %s", pv.ListKey) - } - if bv.Type != querypb.Type_TUPLE { -- return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "single value was supplied for TUPLE bind var %s", pv.ListKey) -+ return nil, fmt.Errorf("single value was supplied for TUPLE bind var %s", pv.ListKey) - } - return bv, nil - } -@@ -171,7 +171,7 @@ - case l: - return nil - default: -- return vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "mismatch in number of column values") -+ return errors.New("mismatch in number of column values") - } - } - -@@ -221,7 +221,7 @@ - rows[i] = make([]Value, len(pvs)) - } - -- // Using j because we're resolving by columns. -+ // Using j becasue we're resolving by columns. - for j, pv := range pvs { - switch { - case pv.Key != "": -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/plan_value_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/plan_value_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -21,7 +21,7 @@ - "strings" - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestPlanValueIsNull(t *testing.T) { -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: proto3.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: proto3_test.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: query_response.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: result.go -Only in /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/: result_test.go -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/testing.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/testing.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/testing.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/testing.go 2018-06-04 08:06:27.000000000 -0700 -@@ -17,17 +17,14 @@ - package sqltypes - - import ( -- "bytes" -- "fmt" -- "strings" -- -- querypb "vitess.io/vitess/go/vt/proto/query" -+ querypb "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // Functions in this file should only be used for testing. - // This is an experiment to see if test code bloat can be - // reduced and readability improved. - -+/* - // MakeTestFields builds a []*querypb.Field for testing. - // fields := sqltypes.MakeTestFields( - // "a|b", -@@ -110,6 +107,7 @@ - } - return results - } -+*/ - - // TestBindVariable makes a *querypb.BindVariable from - // an interface{}.It panics on invalid input. -@@ -131,6 +129,7 @@ - return MakeTrusted(typ, []byte(val)) - } - -+/* - // PrintResults prints []*Results into a string. - // This function should only be used for testing. - func PrintResults(results []*Result) string { -@@ -152,3 +151,4 @@ - } - return splits - } -+*/ -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "fmt" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - // This file provides wrappers and support -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/type_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/type_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -19,7 +19,7 @@ - import ( - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - func TestTypeValues(t *testing.T) { -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value.go 2018-06-04 08:05:24.000000000 -0700 -@@ -23,10 +23,10 @@ - "fmt" - "strconv" - -- "vitess.io/vitess/go/bytes2" -- "vitess.io/vitess/go/hack" -+ "github.com/xwb1989/sqlparser/dependency/bytes2" -+ "github.com/xwb1989/sqlparser/dependency/hack" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - var ( -@@ -48,7 +48,7 @@ - } - - // Value can store any SQL value. If the value represents --// an integral type, the bytes are always stored as a canonical -+// an integral type, the bytes are always stored as a cannonical - // representation that matches how MySQL returns such values. - type Value struct { - typ querypb.Type -@@ -126,7 +126,7 @@ - return MakeTrusted(VarBinary, []byte(v)) - } - --// NewIntegral builds an integral type from a string representation. -+// NewIntegral builds an integral type from a string representaion. - // The type will be Int64 or Uint64. Int64 will be preferred where possible. - func NewIntegral(val string) (n Value, err error) { - signed, err := strconv.ParseInt(val, 0, 64) -@@ -169,7 +169,7 @@ - return v.typ - } - --// Raw returns the internal representation of the value. For newer types, -+// Raw returns the internal represenation of the value. For newer types, - // this may not match MySQL's representation. - func (v Value) Raw() []byte { - return v.val -diff -u /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value_test.go /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value_test.go ---- /Users/bramp/go/src/vitess.io/vitess/go//sqltypes/value_test.go 2018-06-05 08:45:47.000000000 -0700 -+++ /Users/bramp/go/src/github.com/xwb1989/sqlparser//dependency/sqltypes/value_test.go 2018-06-04 08:05:24.000000000 -0700 -@@ -22,7 +22,7 @@ - "strings" - "testing" - -- querypb "vitess.io/vitess/go/vt/proto/query" -+ "github.com/xwb1989/sqlparser/dependency/querypb" - ) - - const ( diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go deleted file mode 100644 index f6a1c93f..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/precedence_test.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "testing" -) - -func readable(node Expr) string { - switch node := node.(type) { - case *OrExpr: - return fmt.Sprintf("(%s or %s)", readable(node.Left), readable(node.Right)) - case *AndExpr: - return fmt.Sprintf("(%s and %s)", readable(node.Left), readable(node.Right)) - case *BinaryExpr: - return fmt.Sprintf("(%s %s %s)", readable(node.Left), node.Operator, readable(node.Right)) - case *IsExpr: - return fmt.Sprintf("(%s %s)", readable(node.Expr), node.Operator) - default: - return String(node) - } -} - -func TestAndOrPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select * from a where a=b and c=d or e=f", - output: "((a = b and c = d) or e = f)", - }, { - input: "select * from a where a=b or c=d and e=f", - output: "(a = b or (c = d and e = f))", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).Where.Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} - -func TestPlusStarPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select 1+2*3 from a", - output: "(1 + (2 * 3))", - }, { - input: "select 1*2+3 from a", - output: "((1 * 2) + 3)", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).SelectExprs[0].(*AliasedExpr).Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} - -func TestIsPrecedence(t *testing.T) { - validSQL := []struct { - input string - output string - }{{ - input: "select * from a where a+b is true", - output: "((a + b) is true)", - }, { - input: "select * from a where a=1 and b=2 is true", - output: "(a = 1 and (b = 2 is true))", - }, { - input: "select * from a where (a=1 and b=2) is true", - output: "((a = 1 and b = 2) is true)", - }} - for _, tcase := range validSQL { - tree, err := Parse(tcase.input) - if err != nil { - t.Error(err) - continue - } - expr := readable(tree.(*Select).Where.Expr) - if expr != tcase.output { - t.Errorf("Parse: \n%s, want: \n%s", expr, tcase.output) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go deleted file mode 100644 index 553e6ee0..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/redact_query_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package sqlparser - -import ( - "testing" -) - -func TestRedactSQLStatements(t *testing.T) { - sql := "select a,b,c from t where x = 1234 and y = 1234 and z = 'apple'" - redactedSQL, err := RedactSQLQuery(sql) - if err != nil { - t.Fatalf("redacting sql failed: %v", err) - } - - if redactedSQL != "select a, b, c from t where x = :redacted1 and y = :redacted1 and z = :redacted2" { - t.Fatalf("Unknown sql redaction: %v", redactedSQL) - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go deleted file mode 100644 index 93543545..00000000 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/xwb1989/sqlparser/token_test.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sqlparser - -import ( - "fmt" - "testing" -) - -func TestLiteralID(t *testing.T) { - testcases := []struct { - in string - id int - out string - }{{ - in: "`aa`", - id: ID, - out: "aa", - }, { - in: "```a```", - id: ID, - out: "`a`", - }, { - in: "`a``b`", - id: ID, - out: "a`b", - }, { - in: "`a``b`c", - id: ID, - out: "a`b", - }, { - in: "`a``b", - id: LEX_ERROR, - out: "a`b", - }, { - in: "`a``b``", - id: LEX_ERROR, - out: "a`b`", - }, { - in: "``", - id: LEX_ERROR, - out: "", - }} - - for _, tcase := range testcases { - tkn := NewStringTokenizer(tcase.in) - id, out := tkn.Scan() - if tcase.id != id || string(out) != tcase.out { - t.Errorf("Scan(%s): %d, %s, want %d, %s", tcase.in, id, out, tcase.id, tcase.out) - } - } -} - -func tokenName(id int) string { - if id == STRING { - return "STRING" - } else if id == LEX_ERROR { - return "LEX_ERROR" - } - return fmt.Sprintf("%d", id) -} - -func TestString(t *testing.T) { - testcases := []struct { - in string - id int - want string - }{{ - in: "''", - id: STRING, - want: "", - }, { - in: "''''", - id: STRING, - want: "'", - }, { - in: "'hello'", - id: STRING, - want: "hello", - }, { - in: "'\\n'", - id: STRING, - want: "\n", - }, { - in: "'\\nhello\\n'", - id: STRING, - want: "\nhello\n", - }, { - in: "'a''b'", - id: STRING, - want: "a'b", - }, { - in: "'a\\'b'", - id: STRING, - want: "a'b", - }, { - in: "'\\'", - id: LEX_ERROR, - want: "'", - }, { - in: "'", - id: LEX_ERROR, - want: "", - }, { - in: "'hello\\'", - id: LEX_ERROR, - want: "hello'", - }, { - in: "'hello", - id: LEX_ERROR, - want: "hello", - }, { - in: "'hello\\", - id: LEX_ERROR, - want: "hello", - }} - - for _, tcase := range testcases { - id, got := NewStringTokenizer(tcase.in).Scan() - if tcase.id != id || string(got) != tcase.want { - t.Errorf("Scan(%q) = (%s, %q), want (%s, %q)", tcase.in, tokenName(id), got, tokenName(tcase.id), tcase.want) - } - } -} - -func TestSplitStatement(t *testing.T) { - testcases := []struct { - in string - sql string - rem string - }{{ - in: "select * from table", - sql: "select * from table", - }, { - in: "select * from table; ", - sql: "select * from table", - rem: " ", - }, { - in: "select * from table; select * from table2;", - sql: "select * from table", - rem: " select * from table2;", - }, { - in: "select * from /* comment */ table;", - sql: "select * from /* comment */ table", - }, { - in: "select * from /* comment ; */ table;", - sql: "select * from /* comment ; */ table", - }, { - in: "select * from table where semi = ';';", - sql: "select * from table where semi = ';'", - }, { - in: "-- select * from table", - sql: "-- select * from table", - }, { - in: " ", - sql: " ", - }, { - in: "", - sql: "", - }} - - for _, tcase := range testcases { - sql, rem, err := SplitStatement(tcase.in) - if err != nil { - t.Errorf("EndOfStatementPosition(%s): ERROR: %v", tcase.in, err) - continue - } - - if tcase.sql != sql { - t.Errorf("EndOfStatementPosition(%s) got sql \"%s\" want \"%s\"", tcase.in, sql, tcase.sql) - } - - if tcase.rem != rem { - t.Errorf("EndOfStatementPosition(%s) got remainder \"%s\" want \"%s\"", tcase.in, rem, tcase.rem) - } - } -} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml new file mode 100644 index 00000000..6d4d1be7 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.codecov.yml @@ -0,0 +1,15 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + enabled: yes # must be yes|true to enable this status + target: 100 # specify the target coverage for each commit status + # option: "auto" (must increase from parent commit or pull request base) + # option: "X%" a static target percentage to hit + if_not_found: success # if parent is not found report status as success, error, or failure + if_ci_failed: error # if ci fails report status as success, error, or failure + diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore new file mode 100644 index 00000000..0a4504f1 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +/vendor +/cover +cover.out +lint.log + +# Binaries +*.test + +# Profiling output +*.prof diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml new file mode 100644 index 00000000..58957222 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/.travis.yml @@ -0,0 +1,23 @@ +sudo: false +language: go +go_import_path: go.uber.org/atomic + +go: + - 1.7 + - 1.8 + - 1.9 + +cache: + directories: + - vendor + +install: + - make install_ci + +script: + - make test_ci + - scripts/test-ubergo.sh + - make lint + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/LICENSE.txt b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/LICENSE.txt similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/LICENSE.txt rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/LICENSE.txt diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/Makefile b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/Makefile similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/Makefile rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/Makefile diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/README.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/README.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/README.md diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/atomic.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/atomic.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/atomic.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/atomic.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/glide.lock b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.lock similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/glide.lock rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.lock diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml new file mode 100644 index 00000000..4cf608ec --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/glide.yaml @@ -0,0 +1,6 @@ +package: go.uber.org/atomic +testImport: +- package: github.com/stretchr/testify + subpackages: + - assert + - require diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/string.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/string.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/atomic/string.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/atomic/string.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml new file mode 100644 index 00000000..6d4d1be7 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.codecov.yml @@ -0,0 +1,15 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + enabled: yes # must be yes|true to enable this status + target: 100 # specify the target coverage for each commit status + # option: "auto" (must increase from parent commit or pull request base) + # option: "X%" a static target percentage to hit + if_not_found: success # if parent is not found report status as success, error, or failure + if_ci_failed: error # if ci fails report status as success, error, or failure + diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore new file mode 100644 index 00000000..61ead866 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml new file mode 100644 index 00000000..5ffa8fed --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/.travis.yml @@ -0,0 +1,33 @@ +sudo: false +language: go +go_import_path: go.uber.org/multierr + +env: + global: + - GO15VENDOREXPERIMENT=1 + +go: + - 1.7 + - 1.8 + - tip + +cache: + directories: + - vendor + +before_install: +- go version + +install: +- | + set -e + make install_ci + +script: +- | + set -e + make lint + make test_ci + +after_success: +- bash <(curl -s https://codecov.io/bash) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/CHANGELOG.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/CHANGELOG.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/CHANGELOG.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/CHANGELOG.md diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/LICENSE.txt b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/LICENSE.txt similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/LICENSE.txt rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/LICENSE.txt diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/Makefile b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/Makefile similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/Makefile rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/Makefile diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/README.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/README.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/README.md diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/error.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/error.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/error.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/error.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/glide.lock b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.lock similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/go.uber.org/multierr/glide.lock rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.lock diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml new file mode 100644 index 00000000..6ef084ec --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/go.uber.org/multierr/glide.yaml @@ -0,0 +1,8 @@ +package: go.uber.org/multierr +import: +- package: go.uber.org/atomic + version: ^1 +testImport: +- package: github.com/stretchr/testify + subpackages: + - assert diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/AUTHORS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/AUTHORS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/AUTHORS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/AUTHORS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/CONTRIBUTORS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/CONTRIBUTORS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/CONTRIBUTORS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/CONTRIBUTORS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/LICENSE similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/PATENTS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/PATENTS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/PATENTS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/PATENTS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore new file mode 100644 index 00000000..e3e0fc6f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/.gitignore @@ -0,0 +1,2 @@ +_obj/ +unix.test diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/README.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/README.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/README.md diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/affinity_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/affinity_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/affinity_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/affinity_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/aliases.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/aliases.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/aliases.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/aliases.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_386.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_386.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_386.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_386.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_darwin_arm64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_386.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_386.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_386.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_386.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_freebsd_arm.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_386.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_386.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_386.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_386.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_arm64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_arm64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mips64x.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_mipsx.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s new file mode 100644 index 00000000..88f71255 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s @@ -0,0 +1,44 @@ +// Copyright 2014 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. + +// +build linux +// +build ppc64 ppc64le +// +build !gccgo + +#include "textflag.h" + +// +// System calls for ppc64, Linux +// + +// Just jump to package syscall's implementation for all these functions. +// The runtime may know about them. + +TEXT ·SyscallNoError(SB),NOSPLIT,$0-48 + BL runtime·entersyscall(SB) + MOVD a1+8(FP), R3 + MOVD a2+16(FP), R4 + MOVD a3+24(FP), R5 + MOVD R0, R6 + MOVD R0, R7 + MOVD R0, R8 + MOVD trap+0(FP), R9 // syscall entry + SYSCALL R9 + MOVD R3, r1+32(FP) + MOVD R4, r2+40(FP) + BL runtime·exitsyscall(SB) + RET + +TEXT ·RawSyscallNoError(SB),NOSPLIT,$0-48 + MOVD a1+8(FP), R3 + MOVD a2+16(FP), R4 + MOVD a3+24(FP), R5 + MOVD R0, R6 + MOVD R0, R7 + MOVD R0, R8 + MOVD trap+0(FP), R9 // syscall entry + SYSCALL R9 + MOVD R3, r1+32(FP) + MOVD R4, r2+40(FP) + RET diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_s390x.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_s390x.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_linux_s390x.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_linux_s390x.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_386.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_386.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_386.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_386.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_netbsd_arm.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_386.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_386.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_386.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_386.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/asm_solaris_amd64.s diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/bluetooth_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/bluetooth_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/bluetooth_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/bluetooth_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/cap_freebsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/cap_freebsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/cap_freebsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/cap_freebsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/constants.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/constants.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/constants.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/constants.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_aix_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_darwin.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_darwin.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_darwin.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_darwin.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_dragonfly.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_dragonfly.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_dragonfly.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_dragonfly.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_freebsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_freebsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_freebsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_freebsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_netbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_netbsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_netbsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_netbsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_openbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_openbsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dev_openbsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dev_openbsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dirent.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dirent.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/dirent.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/dirent.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_big.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_big.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_big.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_big.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_little.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_little.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/endian_little.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/endian_little.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/env_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/env_unix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/env_unix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/env_unix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/errors_freebsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/fcntl_linux_32bit.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_c.c b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_c.c similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_c.c rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_c.c diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ioctl.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ioctl.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ioctl.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ioctl.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mkall.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkall.sh similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mkall.sh rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkall.sh diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh new file mode 100644 index 00000000..aa860fa2 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkerrors.sh @@ -0,0 +1,656 @@ +#!/usr/bin/env bash +# 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. + +# Generate Go code listing errors and other #defined constant +# values (ENAMETOOLONG etc.), by asking the preprocessor +# about the definitions. + +unset LANG +export LC_ALL=C +export LC_CTYPE=C + +if test -z "$GOARCH" -o -z "$GOOS"; then + echo 1>&2 "GOARCH or GOOS not defined in environment" + exit 1 +fi + +# Check that we are using the new build system if we should +if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then + if [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then + echo 1>&2 "In the new build system, mkerrors should not be called directly." + echo 1>&2 "See README.md" + exit 1 + fi +fi + +if [[ "$GOOS" = "aix" ]]; then + CC=${CC:-gcc} +else + CC=${CC:-cc} +fi + +if [[ "$GOOS" = "solaris" ]]; then + # Assumes GNU versions of utilities in PATH. + export PATH=/usr/gnu/bin:$PATH +fi + +uname=$(uname) + +includes_AIX=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AF_LOCAL AF_UNIX +' + +includes_Darwin=' +#define _DARWIN_C_SOURCE +#define KERNEL +#define _DARWIN_USE_64_BIT_INODE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + +includes_DragonFly=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + +includes_FreeBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if __FreeBSD__ >= 10 +#define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 +#undef SIOCAIFADDR +#define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data +#undef SIOCSIFPHYADDR +#define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data +#endif +' + +includes_Linux=' +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#ifndef __LP64__ +#define _FILE_OFFSET_BITS 64 +#endif +#define _GNU_SOURCE + +// is broken on powerpc64, as it fails to include definitions of +// these structures. We just include them copied from . +#if defined(__powerpc__) +struct sgttyb { + char sg_ispeed; + char sg_ospeed; + char sg_erase; + char sg_kill; + short sg_flags; +}; + +struct tchars { + char t_intrc; + char t_quitc; + char t_startc; + char t_stopc; + char t_eofc; + char t_brkc; +}; + +struct ltchars { + char t_suspc; + char t_dsuspc; + char t_rprntc; + char t_flushc; + char t_werasc; + char t_lnextc; +}; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef MSG_FASTOPEN +#define MSG_FASTOPEN 0x20000000 +#endif + +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS 0xc +#endif + +#ifndef PTRACE_SETREGS +#define PTRACE_SETREGS 0xd +#endif + +#ifndef SOL_NETLINK +#define SOL_NETLINK 270 +#endif + +#ifdef SOL_BLUETOOTH +// SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h +// but it is already in bluetooth_linux.go +#undef SOL_BLUETOOTH +#endif + +// Certain constants are missing from the fs/crypto UAPI +#define FS_KEY_DESC_PREFIX "fscrypt:" +#define FS_KEY_DESC_PREFIX_SIZE 8 +#define FS_MAX_KEY_SIZE 64 + +// XDP socket constants do not appear to be picked up otherwise. +// Copied from samples/bpf/xdpsock_user.c. +#ifndef SOL_XDP +#define SOL_XDP 283 +#endif + +#ifndef AF_XDP +#define AF_XDP 44 +#endif +' + +includes_NetBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Needed since refers to it... +#define schedppq 1 +' + +includes_OpenBSD=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// We keep some constants not supported in OpenBSD 5.5 and beyond for +// the promise of compatibility. +#define EMUL_ENABLED 0x1 +#define EMUL_NATIVE 0x2 +#define IPV6_FAITH 0x1d +#define IPV6_OPTIONS 0x1 +#define IPV6_RTHDR_STRICT 0x1 +#define IPV6_SOCKOPT_RESERVED1 0x3 +#define SIOCGIFGENERIC 0xc020693a +#define SIOCSIFGENERIC 0x80206939 +#define WALTSIG 0x4 +' + +includes_SunOS=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + + +includes=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' +ccflags="$@" + +# Write go tool cgo -godefs input. +( + echo package unix + echo + echo '/*' + indirect="includes_$(uname)" + echo "${!indirect} $includes" + echo '*/' + echo 'import "C"' + echo 'import "syscall"' + echo + echo 'const (' + + # The gcc command line prints all the #defines + # it encounters while processing the input + echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | + awk ' + $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} + + $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers + $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} + $2 ~ /^(SCM_SRCRT)$/ {next} + $2 ~ /^(MAP_FAILED)$/ {next} + $2 ~ /^ELF_.*$/ {next}# contains ELF_ARCH, etc. + + $2 ~ /^EXTATTR_NAMESPACE_NAMES/ || + $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} + + $2 !~ /^ECCAPBITS/ && + $2 !~ /^ETH_/ && + $2 !~ /^EPROC_/ && + $2 !~ /^EQUIV_/ && + $2 !~ /^EXPR_/ && + $2 ~ /^E[A-Z0-9_]+$/ || + $2 ~ /^B[0-9_]+$/ || + $2 ~ /^(OLD|NEW)DEV$/ || + $2 == "BOTHER" || + $2 ~ /^CI?BAUD(EX)?$/ || + $2 == "IBSHIFT" || + $2 ~ /^V[A-Z0-9]+$/ || + $2 ~ /^CS[A-Z0-9]/ || + $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || + $2 ~ /^IGN/ || + $2 ~ /^IX(ON|ANY|OFF)$/ || + $2 ~ /^IN(LCR|PCK)$/ || + $2 !~ "X86_CR3_PCID_NOFLUSH" && + $2 ~ /(^FLU?SH)|(FLU?SH$)/ || + $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || + $2 == "BRKINT" || + $2 == "HUPCL" || + $2 == "PENDIN" || + $2 == "TOSTOP" || + $2 == "XCASE" || + $2 == "ALTWERASE" || + $2 == "NOKERNINFO" || + $2 ~ /^PAR/ || + $2 ~ /^SIG[^_]/ || + $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || + $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || + $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || + $2 ~ /^O?XTABS$/ || + $2 ~ /^TC[IO](ON|OFF)$/ || + $2 ~ /^IN_/ || + $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || + $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || + $2 ~ /^TP_STATUS_/ || + $2 ~ /^FALLOC_/ || + $2 == "ICMPV6_FILTER" || + $2 == "SOMAXCONN" || + $2 == "NAME_MAX" || + $2 == "IFNAMSIZ" || + $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ || + $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ || + $2 ~ /^HW_MACHINE$/ || + $2 ~ /^SYSCTL_VERS/ || + $2 !~ "MNT_BITS" && + $2 ~ /^(MS|MNT|UMOUNT)_/ || + $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || + $2 ~ /^(O|F|E?FD|NAME|S|PTRACE|PT)_/ || + $2 ~ /^KEXEC_/ || + $2 ~ /^LINUX_REBOOT_CMD_/ || + $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || + $2 ~ /^MODULE_INIT_/ || + $2 !~ "NLA_TYPE_MASK" && + $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || + $2 ~ /^SIOC/ || + $2 ~ /^TIOC/ || + $2 ~ /^TCGET/ || + $2 ~ /^TCSET/ || + $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || + $2 !~ "RTF_BITS" && + $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || + $2 ~ /^BIOC/ || + $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || + $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ || + $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || + $2 ~ /^CLONE_[A-Z_]+/ || + $2 !~ /^(BPF_TIMEVAL)$/ && + $2 ~ /^(BPF|DLT)_/ || + $2 ~ /^CLOCK_/ || + $2 ~ /^CAN_/ || + $2 ~ /^CAP_/ || + $2 ~ /^ALG_/ || + $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE|IOC_(GET|SET)_ENCRYPTION)/ || + $2 ~ /^GRND_/ || + $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || + $2 ~ /^KEYCTL_/ || + $2 ~ /^PERF_EVENT_IOC_/ || + $2 ~ /^SECCOMP_MODE_/ || + $2 ~ /^SPLICE_/ || + $2 ~ /^SYNC_FILE_RANGE_/ || + $2 !~ /^AUDIT_RECORD_MAGIC/ && + $2 !~ /IOC_MAGIC/ && + $2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ || + $2 ~ /^(VM|VMADDR)_/ || + $2 ~ /^IOCTL_VM_SOCKETS_/ || + $2 ~ /^(TASKSTATS|TS)_/ || + $2 ~ /^CGROUPSTATS_/ || + $2 ~ /^GENL_/ || + $2 ~ /^STATX_/ || + $2 ~ /^RENAME/ || + $2 ~ /^UBI_IOC[A-Z]/ || + $2 ~ /^UTIME_/ || + $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || + $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || + $2 ~ /^FSOPT_/ || + $2 ~ /^WDIOC_/ || + $2 ~ /^NFN/ || + $2 ~ /^XDP_/ || + $2 ~ /^(HDIO|WIN|SMART)_/ || + $2 !~ "WMESGLEN" && + $2 ~ /^W[A-Z0-9]+$/ || + $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} + $2 ~ /^__WCOREFLAG$/ {next} + $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} + + {next} + ' | sort + + echo ')' +) >_const.go + +# Pull out the error names for later. +errors=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | + sort +) + +# Pull out the signal names for later. +signals=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | + sort +) + +# Again, writing regexps to a file. +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | + sort >_error.grep +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | + sort >_signal.grep + +echo '// mkerrors.sh' "$@" +echo '// Code generated by the command above; see README.md. DO NOT EDIT.' +echo +echo "// +build ${GOARCH},${GOOS}" +echo +go tool cgo -godefs -- "$@" _const.go >_error.out +cat _error.out | grep -vf _error.grep | grep -vf _signal.grep +echo +echo '// Errors' +echo 'const (' +cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' +echo ')' + +echo +echo '// Signals' +echo 'const (' +cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' +echo ')' + +# Run C program to print error and syscall strings. +( + echo -E " +#include +#include +#include +#include +#include +#include + +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + +enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below + +struct tuple { + int num; + const char *name; +}; + +struct tuple errors[] = { +" + for i in $errors + do + echo -E ' {'$i', "'$i'" },' + done + + echo -E " +}; + +struct tuple signals[] = { +" + for i in $signals + do + echo -E ' {'$i', "'$i'" },' + done + + # Use -E because on some systems bash builtin interprets \n itself. + echo -E ' +}; + +static int +tuplecmp(const void *a, const void *b) +{ + return ((struct tuple *)a)->num - ((struct tuple *)b)->num; +} + +int +main(void) +{ + int i, e; + char buf[1024], *p; + + printf("\n\n// Error table\n"); + printf("var errorList = [...]struct {\n"); + printf("\tnum syscall.Errno\n"); + printf("\tname string\n"); + printf("\tdesc string\n"); + printf("} {\n"); + qsort(errors, nelem(errors), sizeof errors[0], tuplecmp); + for(i=0; i 0 && errors[i-1].num == e) + continue; + strcpy(buf, strerror(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf); + } + printf("}\n\n"); + + printf("\n\n// Signal table\n"); + printf("var signalList = [...]struct {\n"); + printf("\tnum syscall.Signal\n"); + printf("\tname string\n"); + printf("\tdesc string\n"); + printf("} {\n"); + qsort(signals, nelem(signals), sizeof signals[0], tuplecmp); + for(i=0; i 0 && signals[i-1].num == e) + continue; + strcpy(buf, strsignal(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + // cut trailing : number. + p = strrchr(buf, ":"[0]); + if(p) + *p = '\0'; + printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf); + } + printf("}\n\n"); + + return 0; +} + +' +) >_errors.c + +$CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go new file mode 100644 index 00000000..6d263cf1 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mkpost.go @@ -0,0 +1,106 @@ +// 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. + +// +build ignore + +// mkpost processes the output of cgo -godefs to +// modify the generated types. It is used to clean up +// the sys API in an architecture specific manner. +// +// mkpost is run after cgo -godefs; see README.md. +package main + +import ( + "bytes" + "fmt" + "go/format" + "io/ioutil" + "log" + "os" + "regexp" +) + +func main() { + // Get the OS and architecture (using GOARCH_TARGET if it exists) + goos := os.Getenv("GOOS") + goarch := os.Getenv("GOARCH_TARGET") + if goarch == "" { + goarch = os.Getenv("GOARCH") + } + // Check that we are using the new build system if we should be. + if goos == "linux" && goarch != "sparc64" { + if os.Getenv("GOLANG_SYS_BUILD") != "docker" { + os.Stderr.WriteString("In the new build system, mkpost should not be called directly.\n") + os.Stderr.WriteString("See README.md\n") + os.Exit(1) + } + } + + b, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Fatal(err) + } + + // Intentionally export __val fields in Fsid and Sigset_t + valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__val(\s+\S+\s+)}`) + b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$3}")) + + // Intentionally export __fds_bits field in FdSet + fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`) + b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}")) + + // If we have empty Ptrace structs, we should delete them. Only s390x emits + // nonempty Ptrace structs. + ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) + b = ptraceRexexp.ReplaceAll(b, nil) + + // Replace the control_regs union with a blank identifier for now. + controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`) + b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64")) + + // Remove fields that are added by glibc + // Note that this is unstable as the identifers are private. + removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`) + b = removeFieldsRegex.ReplaceAll(b, []byte("_")) + + // Convert [65]int8 to [65]byte in Utsname members to simplify + // conversion to string; see golang.org/issue/20753 + convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`) + b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte")) + + // Convert [1024]int8 to [1024]byte in Ptmget members + convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`) + b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte")) + + // Remove spare fields (e.g. in Statx_t) + spareFieldsRegex := regexp.MustCompile(`X__spare\S*`) + b = spareFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove cgo padding fields + removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`) + b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove padding, hidden, or unused fields + removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`) + b = removeFieldsRegex.ReplaceAll(b, []byte("_")) + + // Remove the first line of warning from cgo + b = b[bytes.IndexByte(b, '\n')+1:] + // Modify the command in the header to include: + // mkpost, our own warning, and a build tag. + replacement := fmt.Sprintf(`$1 | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build %s,%s`, goarch, goos) + cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`) + b = cgoCommandRegex.ReplaceAll(b, []byte(replacement)) + + // gofmt + b, err = format.Source(b) + if err != nil { + log.Fatal(err) + } + + os.Stdout.Write(b) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksyscall_solaris.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_darwin.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_pledge.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_pledge.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_pledge.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_pledge.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_unveil.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_unveil.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/openbsd_unveil.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/openbsd_unveil.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/pagesize_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/pagesize_unix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/pagesize_unix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/pagesize_unix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/race0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/race0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_unix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/sockcmsg_unix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/sockcmsg_unix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/str.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/str.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/str.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/str.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_bsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_bsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_bsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_bsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go new file mode 100644 index 00000000..75651057 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly.go @@ -0,0 +1,531 @@ +// 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. + +// DragonFly BSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import "unsafe" + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 + Rcf uint16 + Route [16]uint16 + raw RawSockaddrDatalink +} + +// Translate "kern.hostname" to []_C_int{0,1,2,3}. +func nametomib(name string) (mib []_C_int, err error) { + const siz = unsafe.Sizeof(mib[0]) + + // NOTE(rsc): It seems strange to set the buffer to have + // size CTL_MAXNAME+2 but use only CTL_MAXNAME + // as the size. I don't know why the +2 is here, but the + // kernel uses +2 for its own implementation of this function. + // I am scared that if we don't include the +2 here, the kernel + // will silently write 2 words farther than we specify + // and we'll get memory corruption. + var buf [CTL_MAXNAME + 2]_C_int + n := uintptr(CTL_MAXNAME) * siz + + p := (*byte)(unsafe.Pointer(&buf[0])) + bytes, err := ByteSliceFromString(name) + if err != nil { + return nil, err + } + + // Magic sysctl: "setting" 0.3 to a string name + // lets you read back the array of integers form. + if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { + return nil, err + } + return buf[0 : n/siz], nil +} + +//sysnb pipe() (r int, w int, err error) + +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + p[0], p[1], err = pipe() + return +} + +//sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) +func Pread(fd int, p []byte, offset int64) (n int, err error) { + return extpread(fd, p, 0, offset) +} + +//sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + return extpwrite(fd, p, 0, offset) +} + +func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) { + var rsa RawSockaddrAny + var len _Socklen = SizeofSockaddrAny + nfd, err = accept4(fd, &rsa, &len, flags) + if err != nil { + return + } + if len > SizeofSockaddrAny { + panic("RawSockaddrAny too small") + } + sa, err = anyToSockaddr(fd, &rsa) + if err != nil { + Close(nfd) + nfd = 0 + } + return +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { + var _p0 unsafe.Pointer + var bufsize uintptr + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + } + r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func sysctlUname(mib []_C_int, old *byte, oldlen *uintptr) error { + err := sysctl(mib, old, oldlen, nil, 0) + if err != nil { + // Utsname members on Dragonfly are only 32 bytes and + // the syscall returns ENOMEM in case the actual value + // is longer. + if err == ENOMEM { + err = nil + } + } + return err +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctlUname(mib, &uname.Sysname[0], &n); err != nil { + return err + } + uname.Sysname[unsafe.Sizeof(uname.Sysname)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctlUname(mib, &uname.Nodename[0], &n); err != nil { + return err + } + uname.Nodename[unsafe.Sizeof(uname.Nodename)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctlUname(mib, &uname.Release[0], &n); err != nil { + return err + } + uname.Release[unsafe.Sizeof(uname.Release)-1] = 0 + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctlUname(mib, &uname.Version[0], &n); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctlUname(mib, &uname.Machine[0], &n); err != nil { + return err + } + uname.Machine[unsafe.Sizeof(uname.Machine)-1] = 0 + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fstatfs(fd int, stat *Statfs_t) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) +//sys Getdtablesize() (size int) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(fd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sys Setlogin(name string) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setresgid(rgid int, egid int, sgid int) (err error) +//sysnb Setresuid(ruid int, euid int, suid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Statfs(path string, stat *Statfs_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Undelete(path string) (err error) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + * TODO(jsing): Update this list for DragonFly. + */ +// Profil +// Sigaction +// Sigprocmask +// Getlogin +// Sigpending +// Sigaltstack +// Reboot +// Execve +// Vfork +// Sbrk +// Sstk +// Ovadvise +// Mincore +// Setitimer +// Swapon +// Select +// Sigsuspend +// Readv +// Writev +// Nfssvc +// Getfh +// Quotactl +// Mount +// Csops +// Waitid +// Add_profil +// Kdebug_trace +// Sigreturn +// Atsocket +// Kqueue_from_portset_np +// Kqueue_portset +// Getattrlist +// Setattrlist +// Getdirentriesattr +// Searchfs +// Delete +// Copyfile +// Watchevent +// Waitevent +// Modwatch +// Getxattr +// Fgetxattr +// Setxattr +// Fsetxattr +// Removexattr +// Fremovexattr +// Listxattr +// Flistxattr +// Fsctl +// Initgroups +// Posix_spawn +// Nfsclnt +// Fhopen +// Minherit +// Semsys +// Msgsys +// Shmsys +// Semctl +// Semget +// Semop +// Msgctl +// Msgget +// Msgsnd +// Msgrcv +// Shmat +// Shmctl +// Shmdt +// Shmget +// Shm_open +// Shm_unlink +// Sem_open +// Sem_close +// Sem_unlink +// Sem_wait +// Sem_trywait +// Sem_post +// Sem_getvalue +// Sem_init +// Sem_destroy +// Open_extended +// Umask_extended +// Stat_extended +// Lstat_extended +// Fstat_extended +// Chmod_extended +// Fchmod_extended +// Access_extended +// Settid +// Gettid +// Setsgroups +// Getsgroups +// Setwgroups +// Getwgroups +// Mkfifo_extended +// Mkdir_extended +// Identitysvc +// Shared_region_check_np +// Shared_region_map_np +// __pthread_mutex_destroy +// __pthread_mutex_init +// __pthread_mutex_lock +// __pthread_mutex_trylock +// __pthread_mutex_unlock +// __pthread_cond_init +// __pthread_cond_destroy +// __pthread_cond_broadcast +// __pthread_cond_signal +// Setsid_with_pid +// __pthread_cond_timedwait +// Aio_fsync +// Aio_return +// Aio_suspend +// Aio_cancel +// Aio_error +// Aio_read +// Aio_write +// Lio_listio +// __pthread_cond_wait +// Iopolicysys +// __pthread_kill +// __pthread_sigmask +// __sigwait +// __disable_threadsignal +// __pthread_markcancel +// __pthread_canceled +// __semwait_signal +// Proc_info +// Stat64_extended +// Lstat64_extended +// Fstat64_extended +// __pthread_chdir +// __pthread_fchdir +// Audit +// Auditon +// Getauid +// Setauid +// Getaudit +// Setaudit +// Getaudit_addr +// Setaudit_addr +// Auditctl +// Bsdthread_create +// Bsdthread_terminate +// Stack_snapshot +// Bsdthread_register +// Workq_open +// Workq_ops +// __mac_execve +// __mac_syscall +// __mac_get_file +// __mac_set_file +// __mac_get_link +// __mac_set_link +// __mac_get_proc +// __mac_set_proc +// __mac_get_fd +// __mac_set_fd +// __mac_get_pid +// __mac_get_lcid +// __mac_get_lctx +// __mac_set_lctx +// Setlcid +// Read_nocancel +// Write_nocancel +// Open_nocancel +// Close_nocancel +// Wait4_nocancel +// Recvmsg_nocancel +// Sendmsg_nocancel +// Recvfrom_nocancel +// Accept_nocancel +// Fcntl_nocancel +// Select_nocancel +// Fsync_nocancel +// Connect_nocancel +// Sigsuspend_nocancel +// Readv_nocancel +// Writev_nocancel +// Sendto_nocancel +// Pread_nocancel +// Pwrite_nocancel +// Waitid_nocancel +// Msgsnd_nocancel +// Msgrcv_nocancel +// Sem_wait_nocancel +// Aio_suspend_nocancel +// __sigwait_nocancel +// __semwait_signal_nocancel +// __mac_mount +// __mac_get_mount +// __mac_getfsstat diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go new file mode 100644 index 00000000..059327a3 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd.go @@ -0,0 +1,615 @@ +// Copyright 2009,2010 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. + +// NetBSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import ( + "runtime" + "syscall" + "unsafe" +) + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 + raw RawSockaddrDatalink +} + +func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) + +func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) { + var olen uintptr + + // Get a list of all sysctl nodes below the given MIB by performing + // a sysctl for the given MIB with CTL_QUERY appended. + mib = append(mib, CTL_QUERY) + qnode := Sysctlnode{Flags: SYSCTL_VERS_1} + qp := (*byte)(unsafe.Pointer(&qnode)) + sz := unsafe.Sizeof(qnode) + if err = sysctl(mib, nil, &olen, qp, sz); err != nil { + return nil, err + } + + // Now that we know the size, get the actual nodes. + nodes = make([]Sysctlnode, olen/sz) + np := (*byte)(unsafe.Pointer(&nodes[0])) + if err = sysctl(mib, np, &olen, qp, sz); err != nil { + return nil, err + } + + return nodes, nil +} + +func nametomib(name string) (mib []_C_int, err error) { + // Split name into components. + var parts []string + last := 0 + for i := 0; i < len(name); i++ { + if name[i] == '.' { + parts = append(parts, name[last:i]) + last = i + 1 + } + } + parts = append(parts, name[last:]) + + // Discover the nodes and construct the MIB OID. + for partno, part := range parts { + nodes, err := sysctlNodes(mib) + if err != nil { + return nil, err + } + for _, node := range nodes { + n := make([]byte, 0) + for i := range node.Name { + if node.Name[i] != 0 { + n = append(n, byte(node.Name[i])) + } + } + if string(n) == part { + mib = append(mib, _C_int(node.Num)) + break + } + } + if len(mib) != partno+1 { + return nil, EINVAL + } + } + + return mib, nil +} + +func SysctlClockinfo(name string) (*Clockinfo, error) { + mib, err := sysctlmib(name) + if err != nil { + return nil, err + } + + n := uintptr(SizeofClockinfo) + var ci Clockinfo + if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { + return nil, err + } + if n != SizeofClockinfo { + return nil, EIO + } + return &ci, nil +} + +//sysnb pipe() (fd1 int, fd2 int, err error) +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + p[0], p[1], err = pipe() + return +} + +//sys getdents(fd int, buf []byte) (n int, err error) +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + return getdents(fd, buf) +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +// TODO +func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + return -1, ENOSYS +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) { + var value Ptmget + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + runtime.KeepAlive(value) + return &value, err +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { + return err + } + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) +//sys ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) +//sys ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) +//sys ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) +//sys ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_POSIX_FADVISE +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mkfifoat(dirfd int, path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys Pread(fd int, p []byte, offset int64) (n int, err error) +//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Renameat(fromfd int, from string, tofd int, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + */ +// ____semctl13 +// __clone +// __fhopen40 +// __fhstat40 +// __fhstatvfs140 +// __fstat30 +// __getcwd +// __getfh30 +// __getlogin +// __lstat30 +// __mount50 +// __msgctl13 +// __msync13 +// __ntp_gettime30 +// __posix_chown +// __posix_fchown +// __posix_lchown +// __posix_rename +// __setlogin +// __shmctl13 +// __sigaction_sigtramp +// __sigaltstack14 +// __sigpending14 +// __sigprocmask14 +// __sigsuspend14 +// __sigtimedwait +// __stat30 +// __syscall +// __vfork14 +// _ksem_close +// _ksem_destroy +// _ksem_getvalue +// _ksem_init +// _ksem_open +// _ksem_post +// _ksem_trywait +// _ksem_unlink +// _ksem_wait +// _lwp_continue +// _lwp_create +// _lwp_ctl +// _lwp_detach +// _lwp_exit +// _lwp_getname +// _lwp_getprivate +// _lwp_kill +// _lwp_park +// _lwp_self +// _lwp_setname +// _lwp_setprivate +// _lwp_suspend +// _lwp_unpark +// _lwp_unpark_all +// _lwp_wait +// _lwp_wakeup +// _pset_bind +// _sched_getaffinity +// _sched_getparam +// _sched_setaffinity +// _sched_setparam +// acct +// aio_cancel +// aio_error +// aio_fsync +// aio_read +// aio_return +// aio_suspend +// aio_write +// break +// clock_getres +// clock_gettime +// clock_settime +// compat_09_ogetdomainname +// compat_09_osetdomainname +// compat_09_ouname +// compat_10_omsgsys +// compat_10_osemsys +// compat_10_oshmsys +// compat_12_fstat12 +// compat_12_getdirentries +// compat_12_lstat12 +// compat_12_msync +// compat_12_oreboot +// compat_12_oswapon +// compat_12_stat12 +// compat_13_sigaction13 +// compat_13_sigaltstack13 +// compat_13_sigpending13 +// compat_13_sigprocmask13 +// compat_13_sigreturn13 +// compat_13_sigsuspend13 +// compat_14___semctl +// compat_14_msgctl +// compat_14_shmctl +// compat_16___sigaction14 +// compat_16___sigreturn14 +// compat_20_fhstatfs +// compat_20_fstatfs +// compat_20_getfsstat +// compat_20_statfs +// compat_30___fhstat30 +// compat_30___fstat13 +// compat_30___lstat13 +// compat_30___stat13 +// compat_30_fhopen +// compat_30_fhstat +// compat_30_fhstatvfs1 +// compat_30_getdents +// compat_30_getfh +// compat_30_ntp_gettime +// compat_30_socket +// compat_40_mount +// compat_43_fstat43 +// compat_43_lstat43 +// compat_43_oaccept +// compat_43_ocreat +// compat_43_oftruncate +// compat_43_ogetdirentries +// compat_43_ogetdtablesize +// compat_43_ogethostid +// compat_43_ogethostname +// compat_43_ogetkerninfo +// compat_43_ogetpagesize +// compat_43_ogetpeername +// compat_43_ogetrlimit +// compat_43_ogetsockname +// compat_43_okillpg +// compat_43_olseek +// compat_43_ommap +// compat_43_oquota +// compat_43_orecv +// compat_43_orecvfrom +// compat_43_orecvmsg +// compat_43_osend +// compat_43_osendmsg +// compat_43_osethostid +// compat_43_osethostname +// compat_43_osetrlimit +// compat_43_osigblock +// compat_43_osigsetmask +// compat_43_osigstack +// compat_43_osigvec +// compat_43_otruncate +// compat_43_owait +// compat_43_stat43 +// execve +// extattr_delete_fd +// extattr_delete_file +// extattr_delete_link +// extattr_get_fd +// extattr_get_file +// extattr_get_link +// extattr_list_fd +// extattr_list_file +// extattr_list_link +// extattr_set_fd +// extattr_set_file +// extattr_set_link +// extattrctl +// fchroot +// fdatasync +// fgetxattr +// fktrace +// flistxattr +// fork +// fremovexattr +// fsetxattr +// fstatvfs1 +// fsync_range +// getcontext +// getitimer +// getvfsstat +// getxattr +// ktrace +// lchflags +// lchmod +// lfs_bmapv +// lfs_markv +// lfs_segclean +// lfs_segwait +// lgetxattr +// lio_listio +// listxattr +// llistxattr +// lremovexattr +// lseek +// lsetxattr +// lutimes +// madvise +// mincore +// minherit +// modctl +// mq_close +// mq_getattr +// mq_notify +// mq_open +// mq_receive +// mq_send +// mq_setattr +// mq_timedreceive +// mq_timedsend +// mq_unlink +// mremap +// msgget +// msgrcv +// msgsnd +// nfssvc +// ntp_adjtime +// pmc_control +// pmc_get_info +// pollts +// preadv +// profil +// pselect +// pset_assign +// pset_create +// pset_destroy +// ptrace +// pwritev +// quotactl +// rasctl +// readv +// reboot +// removexattr +// sa_enable +// sa_preempt +// sa_register +// sa_setconcurrency +// sa_stacks +// sa_yield +// sbrk +// sched_yield +// semconfig +// semget +// semop +// setcontext +// setitimer +// setxattr +// shmat +// shmdt +// shmget +// sstk +// statvfs1 +// swapctl +// sysarch +// syscall +// timer_create +// timer_delete +// timer_getoverrun +// timer_gettime +// timer_settime +// undelete +// utrace +// uuidgen +// vadvise +// vfork +// writev diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go new file mode 100644 index 00000000..5a398f81 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd.go @@ -0,0 +1,392 @@ +// Copyright 2009,2010 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. + +// OpenBSD system calls. +// This file is compiled as ordinary Go code, +// but it is also input to mksyscall, +// which parses the //sys lines and generates system call stubs. +// Note that sometimes we use a lowercase //sys name and wrap +// it in our own nicer implementation, either here or in +// syscall_bsd.go or syscall_unix.go. + +package unix + +import ( + "sort" + "syscall" + "unsafe" +) + +// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. +type SockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [24]int8 + raw RawSockaddrDatalink +} + +func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) + +func nametomib(name string) (mib []_C_int, err error) { + i := sort.Search(len(sysctlMib), func(i int) bool { + return sysctlMib[i].ctlname >= name + }) + if i < len(sysctlMib) && sysctlMib[i].ctlname == name { + return sysctlMib[i].ctloid, nil + } + return nil, EINVAL +} + +func SysctlUvmexp(name string) (*Uvmexp, error) { + mib, err := sysctlmib(name) + if err != nil { + return nil, err + } + + n := uintptr(SizeofUvmexp) + var u Uvmexp + if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil { + return nil, err + } + if n != SizeofUvmexp { + return nil, EIO + } + return &u, nil +} + +//sysnb pipe(p *[2]_C_int) (err error) +func Pipe(p []int) (err error) { + if len(p) != 2 { + return EINVAL + } + var pp [2]_C_int + err = pipe(&pp) + p[0] = int(pp[0]) + p[1] = int(pp[1]) + return +} + +//sys getdents(fd int, buf []byte) (n int, err error) +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + return getdents(fd, buf) +} + +const ImplementsGetwd = true + +//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + +// TODO +func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + return -1, ENOSYS +} + +func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { + var _p0 unsafe.Pointer + var bufsize uintptr + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + } + r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +func setattrlistTimes(path string, times []Timespec, flags int) error { + // used on Darwin for UtimesNano + return ENOSYS +} + +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func ioctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func ioctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +//sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) + +func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + if len(fds) == 0 { + return ppoll(nil, 0, timeout, sigmask) + } + return ppoll(&fds[0], len(fds), timeout, sigmask) +} + +func Uname(uname *Utsname) error { + mib := []_C_int{CTL_KERN, KERN_OSTYPE} + n := unsafe.Sizeof(uname.Sysname) + if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_HOSTNAME} + n = unsafe.Sizeof(uname.Nodename) + if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_OSRELEASE} + n = unsafe.Sizeof(uname.Release) + if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { + return err + } + + mib = []_C_int{CTL_KERN, KERN_VERSION} + n = unsafe.Sizeof(uname.Version) + if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { + return err + } + + // The version might have newlines or tabs in it, convert them to + // spaces. + for i, b := range uname.Version { + if b == '\n' || b == '\t' { + if i == len(uname.Version)-1 { + uname.Version[i] = 0 + } else { + uname.Version[i] = ' ' + } + } + } + + mib = []_C_int{CTL_HW, HW_MACHINE} + n = unsafe.Sizeof(uname.Machine) + if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { + return err + } + + return nil +} + +/* + * Exposed directly + */ +//sys Access(path string, mode uint32) (err error) +//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) +//sys Chdir(path string) (err error) +//sys Chflags(path string, flags int) (err error) +//sys Chmod(path string, mode uint32) (err error) +//sys Chown(path string, uid int, gid int) (err error) +//sys Chroot(path string) (err error) +//sys Close(fd int) (err error) +//sys Dup(fd int) (nfd int, err error) +//sys Dup2(from int, to int) (err error) +//sys Exit(code int) +//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchdir(fd int) (err error) +//sys Fchflags(fd int, flags int) (err error) +//sys Fchmod(fd int, mode uint32) (err error) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) +//sys Fchown(fd int, uid int, gid int) (err error) +//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) +//sys Flock(fd int, how int) (err error) +//sys Fpathconf(fd int, name int) (val int, err error) +//sys Fstat(fd int, stat *Stat_t) (err error) +//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) +//sys Fstatfs(fd int, stat *Statfs_t) (err error) +//sys Fsync(fd int) (err error) +//sys Ftruncate(fd int, length int64) (err error) +//sysnb Getegid() (egid int) +//sysnb Geteuid() (uid int) +//sysnb Getgid() (gid int) +//sysnb Getpgid(pid int) (pgid int, err error) +//sysnb Getpgrp() (pgrp int) +//sysnb Getpid() (pid int) +//sysnb Getppid() (ppid int) +//sys Getpriority(which int, who int) (prio int, err error) +//sysnb Getrlimit(which int, lim *Rlimit) (err error) +//sysnb Getrtable() (rtable int, err error) +//sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) +//sysnb Gettimeofday(tv *Timeval) (err error) +//sysnb Getuid() (uid int) +//sys Issetugid() (tainted bool) +//sys Kill(pid int, signum syscall.Signal) (err error) +//sys Kqueue() (fd int, err error) +//sys Lchown(path string, uid int, gid int) (err error) +//sys Link(path string, link string) (err error) +//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) +//sys Listen(s int, backlog int) (err error) +//sys Lstat(path string, stat *Stat_t) (err error) +//sys Mkdir(path string, mode uint32) (err error) +//sys Mkdirat(dirfd int, path string, mode uint32) (err error) +//sys Mkfifo(path string, mode uint32) (err error) +//sys Mkfifoat(dirfd int, path string, mode uint32) (err error) +//sys Mknod(path string, mode uint32, dev int) (err error) +//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) +//sys Nanosleep(time *Timespec, leftover *Timespec) (err error) +//sys Open(path string, mode int, perm uint32) (fd int, err error) +//sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) +//sys Pathconf(path string, name int) (val int, err error) +//sys Pread(fd int, p []byte, offset int64) (n int, err error) +//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) +//sys read(fd int, p []byte) (n int, err error) +//sys Readlink(path string, buf []byte) (n int, err error) +//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) +//sys Rename(from string, to string) (err error) +//sys Renameat(fromfd int, from string, tofd int, to string) (err error) +//sys Revoke(path string) (err error) +//sys Rmdir(path string) (err error) +//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK +//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) +//sysnb Setegid(egid int) (err error) +//sysnb Seteuid(euid int) (err error) +//sysnb Setgid(gid int) (err error) +//sys Setlogin(name string) (err error) +//sysnb Setpgid(pid int, pgid int) (err error) +//sys Setpriority(which int, who int, prio int) (err error) +//sysnb Setregid(rgid int, egid int) (err error) +//sysnb Setreuid(ruid int, euid int) (err error) +//sysnb Setresgid(rgid int, egid int, sgid int) (err error) +//sysnb Setresuid(ruid int, euid int, suid int) (err error) +//sysnb Setrlimit(which int, lim *Rlimit) (err error) +//sysnb Setrtable(rtable int) (err error) +//sysnb Setsid() (pid int, err error) +//sysnb Settimeofday(tp *Timeval) (err error) +//sysnb Setuid(uid int) (err error) +//sys Stat(path string, stat *Stat_t) (err error) +//sys Statfs(path string, stat *Statfs_t) (err error) +//sys Symlink(path string, link string) (err error) +//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) +//sys Sync() (err error) +//sys Truncate(path string, length int64) (err error) +//sys Umask(newmask int) (oldmask int) +//sys Unlink(path string) (err error) +//sys Unlinkat(dirfd int, path string, flags int) (err error) +//sys Unmount(path string, flags int) (err error) +//sys write(fd int, p []byte) (n int, err error) +//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) +//sys munmap(addr uintptr, length uintptr) (err error) +//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ +//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) + +/* + * Unimplemented + */ +// __getcwd +// __semctl +// __syscall +// __sysctl +// adjfreq +// break +// clock_getres +// clock_gettime +// clock_settime +// closefrom +// execve +// fcntl +// fhopen +// fhstat +// fhstatfs +// fork +// futimens +// getfh +// getgid +// getitimer +// getlogin +// getresgid +// getresuid +// getthrid +// ktrace +// lfs_bmapv +// lfs_markv +// lfs_segclean +// lfs_segwait +// mincore +// minherit +// mount +// mquery +// msgctl +// msgget +// msgrcv +// msgsnd +// nfssvc +// nnpfspioctl +// preadv +// profil +// pwritev +// quotactl +// readv +// reboot +// renameat +// rfork +// sched_yield +// semget +// semop +// setgroups +// setitimer +// setsockopt +// shmat +// shmctl +// shmdt +// shmget +// sigaction +// sigaltstack +// sigpending +// sigprocmask +// sigreturn +// sigsuspend +// sysarch +// syscall +// threxit +// thrsigdivert +// thrsleep +// thrwakeup +// vfork +// writev diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_unix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/syscall_unix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go new file mode 100644 index 00000000..1c70d1b6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc.go @@ -0,0 +1,15 @@ +// 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. + +// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build !gccgo,!ppc64le,!ppc64 + +package unix + +import "syscall" + +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go new file mode 100644 index 00000000..86dc765a --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go @@ -0,0 +1,24 @@ +// Copyright 2018 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. + +// +build linux +// +build ppc64le ppc64 +// +build !gccgo + +package unix + +import "syscall" + +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.Syscall(trap, a1, a2, a3) +} +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.Syscall6(trap, a1, a2, a3, a4, a5, a6) +} +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.RawSyscall(trap, a1, a2, a3) +} +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + return syscall.RawSyscall6(trap, a1, a2, a3, a4, a5, a6) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/timestruct.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/timestruct.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/timestruct.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/timestruct.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_aix.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_aix.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_aix.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_aix.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_darwin.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_darwin.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_darwin.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_darwin.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_dragonfly.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_dragonfly.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_dragonfly.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_dragonfly.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go new file mode 100644 index 00000000..74707989 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_freebsd.go @@ -0,0 +1,356 @@ +// 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. + +// +build ignore + +/* +Input to cgo -godefs. See README.md +*/ + +// +godefs map struct_in_addr [4]byte /* in_addr */ +// +godefs map struct_in6_addr [16]byte /* in6_addr */ + +package unix + +/* +#define _WANT_FREEBSD11_STAT 1 +#define _WANT_FREEBSD11_STATFS 1 +#define _WANT_FREEBSD11_DIRENT 1 +#define _WANT_FREEBSD11_KEVENT 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +union sockaddr_all { + struct sockaddr s1; // this one gets used for fields + struct sockaddr_in s2; // these pad it out + struct sockaddr_in6 s3; + struct sockaddr_un s4; + struct sockaddr_dl s5; +}; + +struct sockaddr_any { + struct sockaddr addr; + char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; +}; + +// This structure is a duplicate of if_data on FreeBSD 8-STABLE. +// See /usr/include/net/if.h. +struct if_data8 { + u_char ifi_type; + u_char ifi_physical; + u_char ifi_addrlen; + u_char ifi_hdrlen; + u_char ifi_link_state; + u_char ifi_spare_char1; + u_char ifi_spare_char2; + u_char ifi_datalen; + u_long ifi_mtu; + u_long ifi_metric; + u_long ifi_baudrate; + u_long ifi_ipackets; + u_long ifi_ierrors; + u_long ifi_opackets; + u_long ifi_oerrors; + u_long ifi_collisions; + u_long ifi_ibytes; + u_long ifi_obytes; + u_long ifi_imcasts; + u_long ifi_omcasts; + u_long ifi_iqdrops; + u_long ifi_noproto; + u_long ifi_hwassist; +// FIXME: these are now unions, so maybe need to change definitions? +#undef ifi_epoch + time_t ifi_epoch; +#undef ifi_lastchange + struct timeval ifi_lastchange; +}; + +// This structure is a duplicate of if_msghdr on FreeBSD 8-STABLE. +// See /usr/include/net/if.h. +struct if_msghdr8 { + u_short ifm_msglen; + u_char ifm_version; + u_char ifm_type; + int ifm_addrs; + int ifm_flags; + u_short ifm_index; + struct if_data8 ifm_data; +}; +*/ +import "C" + +// Machine characteristics + +const ( + SizeofPtr = C.sizeofPtr + SizeofShort = C.sizeof_short + SizeofInt = C.sizeof_int + SizeofLong = C.sizeof_long + SizeofLongLong = C.sizeof_longlong +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +// Time + +type Timespec C.struct_timespec + +type Timeval C.struct_timeval + +// Processes + +type Rusage C.struct_rusage + +type Rlimit C.struct_rlimit + +type _Gid_t C.gid_t + +// Files + +const ( + _statfsVersion = C.STATFS_VERSION + _dirblksiz = C.DIRBLKSIZ +) + +type Stat_t C.struct_stat + +type stat_freebsd11_t C.struct_freebsd11_stat + +type Statfs_t C.struct_statfs + +type statfs_freebsd11_t C.struct_freebsd11_statfs + +type Flock_t C.struct_flock + +type Dirent C.struct_dirent + +type dirent_freebsd11 C.struct_freebsd11_dirent + +type Fsid C.struct_fsid + +// File system limits + +const ( + PathMax = C.PATH_MAX +) + +// Advice to Fadvise + +const ( + FADV_NORMAL = C.POSIX_FADV_NORMAL + FADV_RANDOM = C.POSIX_FADV_RANDOM + FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL + FADV_WILLNEED = C.POSIX_FADV_WILLNEED + FADV_DONTNEED = C.POSIX_FADV_DONTNEED + FADV_NOREUSE = C.POSIX_FADV_NOREUSE +) + +// Sockets + +type RawSockaddrInet4 C.struct_sockaddr_in + +type RawSockaddrInet6 C.struct_sockaddr_in6 + +type RawSockaddrUnix C.struct_sockaddr_un + +type RawSockaddrDatalink C.struct_sockaddr_dl + +type RawSockaddr C.struct_sockaddr + +type RawSockaddrAny C.struct_sockaddr_any + +type _Socklen C.socklen_t + +type Linger C.struct_linger + +type Iovec C.struct_iovec + +type IPMreq C.struct_ip_mreq + +type IPMreqn C.struct_ip_mreqn + +type IPv6Mreq C.struct_ipv6_mreq + +type Msghdr C.struct_msghdr + +type Cmsghdr C.struct_cmsghdr + +type Inet6Pktinfo C.struct_in6_pktinfo + +type IPv6MTUInfo C.struct_ip6_mtuinfo + +type ICMPv6Filter C.struct_icmp6_filter + +const ( + SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in + SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 + SizeofSockaddrAny = C.sizeof_struct_sockaddr_any + SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un + SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl + SizeofLinger = C.sizeof_struct_linger + SizeofIPMreq = C.sizeof_struct_ip_mreq + SizeofIPMreqn = C.sizeof_struct_ip_mreqn + SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq + SizeofMsghdr = C.sizeof_struct_msghdr + SizeofCmsghdr = C.sizeof_struct_cmsghdr + SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo + SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo + SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter +) + +// Ptrace requests + +const ( + PTRACE_TRACEME = C.PT_TRACE_ME + PTRACE_CONT = C.PT_CONTINUE + PTRACE_KILL = C.PT_KILL +) + +// Events (kqueue, kevent) + +type Kevent_t C.struct_kevent_freebsd11 + +// Select + +type FdSet C.fd_set + +// Routing and interface messages + +const ( + sizeofIfMsghdr = C.sizeof_struct_if_msghdr + SizeofIfMsghdr = C.sizeof_struct_if_msghdr8 + sizeofIfData = C.sizeof_struct_if_data + SizeofIfData = C.sizeof_struct_if_data8 + SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr + SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr + SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr + SizeofRtMsghdr = C.sizeof_struct_rt_msghdr + SizeofRtMetrics = C.sizeof_struct_rt_metrics +) + +type ifMsghdr C.struct_if_msghdr + +type IfMsghdr C.struct_if_msghdr8 + +type ifData C.struct_if_data + +type IfData C.struct_if_data8 + +type IfaMsghdr C.struct_ifa_msghdr + +type IfmaMsghdr C.struct_ifma_msghdr + +type IfAnnounceMsghdr C.struct_if_announcemsghdr + +type RtMsghdr C.struct_rt_msghdr + +type RtMetrics C.struct_rt_metrics + +// Berkeley packet filter + +const ( + SizeofBpfVersion = C.sizeof_struct_bpf_version + SizeofBpfStat = C.sizeof_struct_bpf_stat + SizeofBpfZbuf = C.sizeof_struct_bpf_zbuf + SizeofBpfProgram = C.sizeof_struct_bpf_program + SizeofBpfInsn = C.sizeof_struct_bpf_insn + SizeofBpfHdr = C.sizeof_struct_bpf_hdr + SizeofBpfZbufHeader = C.sizeof_struct_bpf_zbuf_header +) + +type BpfVersion C.struct_bpf_version + +type BpfStat C.struct_bpf_stat + +type BpfZbuf C.struct_bpf_zbuf + +type BpfProgram C.struct_bpf_program + +type BpfInsn C.struct_bpf_insn + +type BpfHdr C.struct_bpf_hdr + +type BpfZbufHeader C.struct_bpf_zbuf_header + +// Terminal handling + +type Termios C.struct_termios + +type Winsize C.struct_winsize + +// fchmodat-like syscalls. + +const ( + AT_FDCWD = C.AT_FDCWD + AT_REMOVEDIR = C.AT_REMOVEDIR + AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW + AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW +) + +// poll + +type PollFd C.struct_pollfd + +const ( + POLLERR = C.POLLERR + POLLHUP = C.POLLHUP + POLLIN = C.POLLIN + POLLINIGNEOF = C.POLLINIGNEOF + POLLNVAL = C.POLLNVAL + POLLOUT = C.POLLOUT + POLLPRI = C.POLLPRI + POLLRDBAND = C.POLLRDBAND + POLLRDNORM = C.POLLRDNORM + POLLWRBAND = C.POLLWRBAND + POLLWRNORM = C.POLLWRNORM +) + +// Capabilities + +type CapRights C.struct_cap_rights + +// Uname + +type Utsname C.struct_utsname diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go new file mode 100644 index 00000000..2dd4f954 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_netbsd.go @@ -0,0 +1,289 @@ +// 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. + +// +build ignore + +/* +Input to cgo -godefs. See README.md +*/ + +// +godefs map struct_in_addr [4]byte /* in_addr */ +// +godefs map struct_in6_addr [16]byte /* in6_addr */ + +package unix + +/* +#define KERNEL +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +union sockaddr_all { + struct sockaddr s1; // this one gets used for fields + struct sockaddr_in s2; // these pad it out + struct sockaddr_in6 s3; + struct sockaddr_un s4; + struct sockaddr_dl s5; +}; + +struct sockaddr_any { + struct sockaddr addr; + char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; +}; + +*/ +import "C" + +// Machine characteristics + +const ( + SizeofPtr = C.sizeofPtr + SizeofShort = C.sizeof_short + SizeofInt = C.sizeof_int + SizeofLong = C.sizeof_long + SizeofLongLong = C.sizeof_longlong +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +// Time + +type Timespec C.struct_timespec + +type Timeval C.struct_timeval + +// Processes + +type Rusage C.struct_rusage + +type Rlimit C.struct_rlimit + +type _Gid_t C.gid_t + +// Files + +type Stat_t C.struct_stat + +type Statfs_t C.struct_statfs + +type Flock_t C.struct_flock + +type Dirent C.struct_dirent + +type Fsid C.fsid_t + +// File system limits + +const ( + PathMax = C.PATH_MAX +) + +// Advice to Fadvise + +const ( + FADV_NORMAL = C.POSIX_FADV_NORMAL + FADV_RANDOM = C.POSIX_FADV_RANDOM + FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL + FADV_WILLNEED = C.POSIX_FADV_WILLNEED + FADV_DONTNEED = C.POSIX_FADV_DONTNEED + FADV_NOREUSE = C.POSIX_FADV_NOREUSE +) + +// Sockets + +type RawSockaddrInet4 C.struct_sockaddr_in + +type RawSockaddrInet6 C.struct_sockaddr_in6 + +type RawSockaddrUnix C.struct_sockaddr_un + +type RawSockaddrDatalink C.struct_sockaddr_dl + +type RawSockaddr C.struct_sockaddr + +type RawSockaddrAny C.struct_sockaddr_any + +type _Socklen C.socklen_t + +type Linger C.struct_linger + +type Iovec C.struct_iovec + +type IPMreq C.struct_ip_mreq + +type IPv6Mreq C.struct_ipv6_mreq + +type Msghdr C.struct_msghdr + +type Cmsghdr C.struct_cmsghdr + +type Inet6Pktinfo C.struct_in6_pktinfo + +type IPv6MTUInfo C.struct_ip6_mtuinfo + +type ICMPv6Filter C.struct_icmp6_filter + +const ( + SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in + SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 + SizeofSockaddrAny = C.sizeof_struct_sockaddr_any + SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un + SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl + SizeofLinger = C.sizeof_struct_linger + SizeofIPMreq = C.sizeof_struct_ip_mreq + SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq + SizeofMsghdr = C.sizeof_struct_msghdr + SizeofCmsghdr = C.sizeof_struct_cmsghdr + SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo + SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo + SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter +) + +// Ptrace requests + +const ( + PTRACE_TRACEME = C.PT_TRACE_ME + PTRACE_CONT = C.PT_CONTINUE + PTRACE_KILL = C.PT_KILL +) + +// Events (kqueue, kevent) + +type Kevent_t C.struct_kevent + +// Select + +type FdSet C.fd_set + +// Routing and interface messages + +const ( + SizeofIfMsghdr = C.sizeof_struct_if_msghdr + SizeofIfData = C.sizeof_struct_if_data + SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr + SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr + SizeofRtMsghdr = C.sizeof_struct_rt_msghdr + SizeofRtMetrics = C.sizeof_struct_rt_metrics +) + +type IfMsghdr C.struct_if_msghdr + +type IfData C.struct_if_data + +type IfaMsghdr C.struct_ifa_msghdr + +type IfAnnounceMsghdr C.struct_if_announcemsghdr + +type RtMsghdr C.struct_rt_msghdr + +type RtMetrics C.struct_rt_metrics + +type Mclpool C.struct_mclpool + +// Berkeley packet filter + +const ( + SizeofBpfVersion = C.sizeof_struct_bpf_version + SizeofBpfStat = C.sizeof_struct_bpf_stat + SizeofBpfProgram = C.sizeof_struct_bpf_program + SizeofBpfInsn = C.sizeof_struct_bpf_insn + SizeofBpfHdr = C.sizeof_struct_bpf_hdr +) + +type BpfVersion C.struct_bpf_version + +type BpfStat C.struct_bpf_stat + +type BpfProgram C.struct_bpf_program + +type BpfInsn C.struct_bpf_insn + +type BpfHdr C.struct_bpf_hdr + +type BpfTimeval C.struct_bpf_timeval + +// Terminal handling + +type Termios C.struct_termios + +type Winsize C.struct_winsize + +type Ptmget C.struct_ptmget + +// fchmodat-like syscalls. + +const ( + AT_FDCWD = C.AT_FDCWD + AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW +) + +// poll + +type PollFd C.struct_pollfd + +const ( + POLLERR = C.POLLERR + POLLHUP = C.POLLHUP + POLLIN = C.POLLIN + POLLNVAL = C.POLLNVAL + POLLOUT = C.POLLOUT + POLLPRI = C.POLLPRI + POLLRDBAND = C.POLLRDBAND + POLLRDNORM = C.POLLRDNORM + POLLWRBAND = C.POLLWRBAND + POLLWRNORM = C.POLLWRNORM +) + +// Sysctl + +type Sysctlnode C.struct_sysctlnode + +// Uname + +type Utsname C.struct_utsname + +// Clockinfo + +const SizeofClockinfo = C.sizeof_struct_clockinfo + +type Clockinfo C.struct_clockinfo diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_openbsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_openbsd.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_openbsd.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_openbsd.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_solaris.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_solaris.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/types_solaris.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/types_solaris.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go new file mode 100644 index 00000000..30c1d71f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/xattr_bsd.go @@ -0,0 +1,240 @@ +// Copyright 2018 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. + +// +build freebsd netbsd + +package unix + +import ( + "strings" + "unsafe" +) + +// Derive extattr namespace and attribute name + +func xattrnamespace(fullattr string) (ns int, attr string, err error) { + s := strings.IndexByte(fullattr, '.') + if s == -1 { + return -1, "", ENOATTR + } + + namespace := fullattr[0:s] + attr = fullattr[s+1:] + + switch namespace { + case "user": + return EXTATTR_NAMESPACE_USER, attr, nil + case "system": + return EXTATTR_NAMESPACE_SYSTEM, attr, nil + default: + return -1, "", ENOATTR + } +} + +func initxattrdest(dest []byte, idx int) (d unsafe.Pointer) { + if len(dest) > idx { + return unsafe.Pointer(&dest[idx]) + } else { + return unsafe.Pointer(_zero) + } +} + +// FreeBSD and NetBSD implement their own syscalls to handle extended attributes + +func Getxattr(file string, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetFile(file, nsid, a, uintptr(d), destsize) +} + +func Fgetxattr(fd int, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetFd(fd, nsid, a, uintptr(d), destsize) +} + +func Lgetxattr(link string, attr string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsize := len(dest) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return -1, err + } + + return ExtattrGetLink(link, nsid, a, uintptr(d), destsize) +} + +// flags are unused on FreeBSD + +func Fsetxattr(fd int, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetFd(fd, nsid, a, uintptr(d), datasiz) + return +} + +func Setxattr(file string, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetFile(file, nsid, a, uintptr(d), datasiz) + return +} + +func Lsetxattr(link string, attr string, data []byte, flags int) (err error) { + var d unsafe.Pointer + if len(data) > 0 { + d = unsafe.Pointer(&data[0]) + } + datasiz := len(data) + + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + _, err = ExtattrSetLink(link, nsid, a, uintptr(d), datasiz) + return +} + +func Removexattr(file string, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteFile(file, nsid, a) + return +} + +func Fremovexattr(fd int, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteFd(fd, nsid, a) + return +} + +func Lremovexattr(link string, attr string) (err error) { + nsid, a, err := xattrnamespace(attr) + if err != nil { + return + } + + err = ExtattrDeleteLink(link, nsid, a) + return +} + +func Listxattr(file string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + // FreeBSD won't allow you to list xattrs from multiple namespaces + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListFile(file, nsid, uintptr(d), destsiz) + + /* Errors accessing system attrs are ignored so that + * we can implement the Linux-like behavior of omitting errors that + * we don't have read permissions on + * + * Linux will still error if we ask for user attributes on a file that + * we don't have read permissions on, so don't ignore those errors + */ + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} + +func Flistxattr(fd int, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListFd(fd, nsid, uintptr(d), destsiz) + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} + +func Llistxattr(link string, dest []byte) (sz int, err error) { + d := initxattrdest(dest, 0) + destsiz := len(dest) + + s := 0 + for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} { + stmp, e := ExtattrListLink(link, nsid, uintptr(d), destsiz) + if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER { + continue + } else if e != nil { + return s, e + } + + s += stmp + destsiz -= s + if destsiz < 0 { + destsiz = 0 + } + d = initxattrdest(dest, s) + } + + return s, nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptrace386_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptrace386_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptrace386_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptrace386_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracearm_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracearm_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracearm_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracearm_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemips_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemips_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemips_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemips_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zptracemipsle_linux.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go new file mode 100644 index 00000000..96a67134 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go @@ -0,0 +1,1639 @@ +// mksyscall.pl -dragonfly -tags dragonfly,amd64 syscall_bsd.go syscall_dragonfly.go syscall_dragonfly_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build dragonfly,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (r int, w int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + r = int(r0) + w = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func extpread(fd int, p []byte, flags int, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_EXTPREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_EXTPWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getdtablesize() (size int) { + r0, _, _ := Syscall(SYS_GETDTABLESIZE, 0, 0, 0) + size = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(fd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Undelete(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNDELETE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) { + r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go new file mode 100644 index 00000000..9ed7c71f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -l32 -netbsd -tags netbsd,386 syscall_bsd.go syscall_netbsd.go syscall_netbsd_386.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,386 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall9(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), 0, uintptr(length), uintptr(length>>32), uintptr(advice), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go new file mode 100644 index 00000000..613b7fd9 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -netbsd -tags netbsd,amd64 syscall_bsd.go syscall_netbsd.go syscall_netbsd_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall6(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), 0, uintptr(length), uintptr(advice)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go new file mode 100644 index 00000000..08475087 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go @@ -0,0 +1,1826 @@ +// mksyscall.pl -l32 -netbsd -arm -tags netbsd,arm syscall_bsd.go syscall_netbsd.go syscall_netbsd_arm.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build netbsd,arm + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe() (fd1 int, fd2 int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) + fd1 = int(r0) + fd2 = int(r1) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FD, uintptr(fd), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FD, uintptr(fd), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(file) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_FILE, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_GET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_SET_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1)), uintptr(data), uintptr(nbytes), 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(attrname) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_EXTATTR_DELETE_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(link) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_EXTATTR_LIST_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(attrnamespace), uintptr(data), uintptr(nbytes), 0, 0) + ret = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fadvise(fd int, offset int64, length int64, advice int) (err error) { + _, _, e1 := Syscall9(SYS_POSIX_FADVISE, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), 0, uintptr(length), uintptr(length>>32), uintptr(advice), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go new file mode 100644 index 00000000..414cd13c --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -l32 -openbsd -tags openbsd,386 syscall_bsd.go syscall_openbsd.go syscall_openbsd_386.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,386 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go new file mode 100644 index 00000000..846f5fa6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -openbsd -tags openbsd,amd64 syscall_bsd.go syscall_openbsd.go syscall_openbsd_amd64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,amd64 + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, _, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(whence), 0, 0) + newoffset = int64(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go new file mode 100644 index 00000000..59911659 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go @@ -0,0 +1,1692 @@ +// mksyscall.pl -l32 -openbsd -arm -tags openbsd,arm syscall_bsd.go syscall_openbsd.go syscall_openbsd_arm.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build openbsd,arm + +package unix + +import ( + "syscall" + "unsafe" +) + +var _ syscall.Errno + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getgroups(ngid int, gid *_Gid_t) (n int, err error) { + r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setgroups(ngid int, gid *_Gid_t) (err error) { + _, _, e1 := RawSyscall(SYS_SETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error) { + r0, _, e1 := Syscall6(SYS_WAIT4, uintptr(pid), uintptr(unsafe.Pointer(wstatus)), uintptr(options), uintptr(unsafe.Pointer(rusage)), 0, 0) + wpid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { + r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { + _, _, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socket(domain int, typ int, proto int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { + _, _, e1 := Syscall6(SYS_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { + _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETPEERNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { + _, _, e1 := RawSyscall(SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Shutdown(s int, how int) (err error) { + _, _, e1 := Syscall(SYS_SHUTDOWN, uintptr(s), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { + _, _, e1 := RawSyscall6(SYS_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(proto), uintptr(unsafe.Pointer(fd)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_RECVFROM, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_SENDTO, uintptr(s), uintptr(_p0), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { + r0, _, e1 := Syscall(SYS_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error) { + r0, _, e1 := Syscall6(SYS_KEVENT, uintptr(kq), uintptr(change), uintptr(nchange), uintptr(event), uintptr(nevent), uintptr(unsafe.Pointer(timeout))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimes(path string, timeval *[2]Timeval) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func futimes(fd int, timeval *[2]Timeval) (err error) { + _, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Madvise(b []byte, behav int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MADVISE, uintptr(_p0), uintptr(len(b)), uintptr(behav)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mlockall(flags int) (err error) { + _, _, e1 := Syscall(SYS_MLOCKALL, uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mprotect(b []byte, prot int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Msync(b []byte, flags int) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MSYNC, uintptr(_p0), uintptr(len(b)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlock(b []byte) (err error) { + var _p0 unsafe.Pointer + if len(b) > 0 { + _p0 = unsafe.Pointer(&b[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall(SYS_MUNLOCK, uintptr(_p0), uintptr(len(b)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Munlockall() (err error) { + _, _, e1 := Syscall(SYS_MUNLOCKALL, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pipe(p *[2]_C_int) (err error) { + _, _, e1 := RawSyscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getdents(fd int, buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS___GETCWD, uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + r0, _, e1 := Syscall6(SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Access(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Adjtime(delta *Timeval, olddelta *Timeval) (err error) { + _, _, e1 := Syscall(SYS_ADJTIME, uintptr(unsafe.Pointer(delta)), uintptr(unsafe.Pointer(olddelta)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chflags(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHFLAGS, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chmod(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Close(fd int) (err error) { + _, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup(fd int) (nfd int, err error) { + r0, _, e1 := Syscall(SYS_DUP, uintptr(fd), 0, 0) + nfd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Dup2(from int, to int) (err error) { + _, _, e1 := Syscall(SYS_DUP2, uintptr(from), uintptr(to), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Exit(code int) { + Syscall(SYS_EXIT, uintptr(code), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchdir(fd int) (err error) { + _, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchflags(fd int, flags int) (err error) { + _, _, e1 := Syscall(SYS_FCHFLAGS, uintptr(fd), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmod(fd int, mode uint32) (err error) { + _, _, e1 := Syscall(SYS_FCHMOD, uintptr(fd), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchown(fd int, uid int, gid int) (err error) { + _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Flock(fd int, how int) (err error) { + _, _, e1 := Syscall(SYS_FLOCK, uintptr(fd), uintptr(how), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fpathconf(fd int, name int) (val int, err error) { + r0, _, e1 := Syscall(SYS_FPATHCONF, uintptr(fd), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstat(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fstatfs(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Fsync(fd int) (err error) { + _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Ftruncate(fd int, length int64) (err error) { + _, _, e1 := Syscall6(SYS_FTRUNCATE, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getegid() (egid int) { + r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0) + egid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Geteuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETEUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getgid() (gid int) { + r0, _, _ := RawSyscall(SYS_GETGID, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgid(pid int) (pgid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETPGID, uintptr(pid), 0, 0) + pgid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpgrp() (pgrp int) { + r0, _, _ := RawSyscall(SYS_GETPGRP, 0, 0, 0) + pgrp = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpid() (pid int) { + r0, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getppid() (ppid int) { + r0, _, _ := RawSyscall(SYS_GETPPID, 0, 0, 0) + ppid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getpriority(which int, who int) (prio int, err error) { + r0, _, e1 := Syscall(SYS_GETPRIORITY, uintptr(which), uintptr(who), 0) + prio = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrtable() (rtable int, err error) { + r0, _, e1 := RawSyscall(SYS_GETRTABLE, 0, 0, 0) + rtable = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := RawSyscall(SYS_GETSID, uintptr(pid), 0, 0) + sid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Gettimeofday(tv *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Getuid() (uid int) { + r0, _, _ := RawSyscall(SYS_GETUID, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Issetugid() (tainted bool) { + r0, _, _ := Syscall(SYS_ISSETUGID, 0, 0, 0) + tainted = bool(r0 != 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kill(pid int, signum syscall.Signal) (err error) { + _, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Kqueue() (fd int, err error) { + r0, _, e1 := Syscall(SYS_KQUEUE, 0, 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lchown(path string, uid int, gid int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Link(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_LINKAT, uintptr(pathfd), uintptr(unsafe.Pointer(_p0)), uintptr(linkfd), uintptr(unsafe.Pointer(_p1)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Listen(s int, backlog int) (err error) { + _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(backlog), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Lstat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdir(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkdirat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifo(path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFO, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mkfifoat(dirfd int, path string, mode uint32) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKFIFOAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknod(path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Nanosleep(time *Timespec, leftover *Timespec) (err error) { + _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Open(path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm), 0, 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pathconf(path string, name int) (val int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, _, e1 := Syscall(SYS_PATHCONF, uintptr(unsafe.Pointer(_p0)), uintptr(name), 0) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pread(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Pwrite(fd int, p []byte, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func read(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlink(path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Readlinkat(dirfd int, path string, buf []byte) (n int, err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 unsafe.Pointer + if len(buf) > 0 { + _p1 = unsafe.Pointer(&buf[0]) + } else { + _p1 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_READLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rename(from string, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Revoke(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_REVOKE, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Rmdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { + r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0) + newoffset = int64(int64(r1)<<32 | int64(r0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) { + _, _, e1 := Syscall6(SYS_SELECT, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setegid(egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEGID, uintptr(egid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Seteuid(euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETEUID, uintptr(euid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setgid(gid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETGID, uintptr(gid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setlogin(name string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(name) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SETLOGIN, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpgid(pid int, pgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETPGID, uintptr(pid), uintptr(pgid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setpriority(which int, who int, prio int) (err error) { + _, _, e1 := Syscall(SYS_SETPRIORITY, uintptr(which), uintptr(who), uintptr(prio)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREGID, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETREUID, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresgid(rgid int, egid int, sgid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESGID, uintptr(rgid), uintptr(egid), uintptr(sgid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setresuid(ruid int, euid int, suid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRESUID, uintptr(ruid), uintptr(euid), uintptr(suid)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrlimit(which int, lim *Rlimit) (err error) { + _, _, e1 := RawSyscall(SYS_SETRLIMIT, uintptr(which), uintptr(unsafe.Pointer(lim)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setrtable(rtable int) (err error) { + _, _, e1 := RawSyscall(SYS_SETRTABLE, uintptr(rtable), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setsid() (pid int, err error) { + r0, _, e1 := RawSyscall(SYS_SETSID, 0, 0, 0) + pid = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Settimeofday(tp *Timeval) (err error) { + _, _, e1 := RawSyscall(SYS_SETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Setuid(uid int) (err error) { + _, _, e1 := RawSyscall(SYS_SETUID, uintptr(uid), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Stat(path string, stat *Stat_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Statfs(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlink(path string, link string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(link) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Sync() (err error) { + _, _, e1 := Syscall(SYS_SYNC, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Truncate(path string, length int64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_TRUNCATE, uintptr(unsafe.Pointer(_p0)), 0, uintptr(length), uintptr(length>>32), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Umask(newmask int) (oldmask int) { + r0, _, _ := Syscall(SYS_UMASK, uintptr(newmask), 0, 0) + oldmask = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlink(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unlinkat(dirfd int, path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Unmount(path string, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func write(fd int, p []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(p) > 0 { + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { + r0, _, e1 := Syscall9(SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0) + ret = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func munmap(addr uintptr, length uintptr) (err error) { + _, _, e1 := Syscall(SYS_MUNMAP, uintptr(addr), uintptr(length), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func readlen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writelen(fd int, buf *byte, nbuf int) (n int, err error) { + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go new file mode 100644 index 00000000..c146c1ad --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go @@ -0,0 +1,603 @@ +// cgo -godefs types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build 386,freebsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int32 + Nsec int32 +} + +type Timeval struct { + Sec int32 + Usec int32 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim_ext int32 + Atim Timespec + Mtim_ext int32 + Mtim Timespec + Ctim_ext int32 + Ctim Timespec + Btim_ext int32 + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec + _ [8]byte +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter int16 + Flags uint16 + Fflags uint32 + Data int32 + Udata *byte +} + +type FdSet struct { + Bits [32]uint32 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0x60 + sizeofIfData = 0x98 + SizeofIfData = 0x50 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x5c + SizeofRtMetrics = 0x38 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint32 + Metric uint32 + Baudrate uint32 + Ipackets uint32 + Ierrors uint32 + Opackets uint32 + Oerrors uint32 + Collisions uint32 + Ibytes uint32 + Obytes uint32 + Imcasts uint32 + Omcasts uint32 + Iqdrops uint32 + Noproto uint32 + Hwassist uint32 + Epoch int32 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint32 + Mtu uint32 + Hopcount uint32 + Expire uint32 + Recvpipe uint32 + Sendpipe uint32 + Ssthresh uint32 + Rtt uint32 + Rttvar uint32 + Pksent uint32 + Weight uint32 + Filler [3]uint32 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0xc + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint32 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [2]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go new file mode 100644 index 00000000..ac33a8dd --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go @@ -0,0 +1,602 @@ +// cgo -godefs types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build amd64,freebsd + +package unix + +const ( + SizeofPtr = 0x8 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x8 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int64 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint64 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + _ [4]byte + Iov *Iovec + Iovlen int32 + _ [4]byte + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x30 + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint64 + Filter int16 + Flags uint16 + Fflags uint32 + Data int64 + Udata *byte +} + +type FdSet struct { + Bits [16]uint64 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0xa8 + sizeofIfData = 0x98 + SizeofIfData = 0x98 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x98 + SizeofRtMetrics = 0x70 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Hwassist uint64 + Epoch int64 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint64 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Expire uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Pksent uint64 + Weight uint64 + Filler [3]uint64 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0x18 + SizeofBpfProgram = 0x10 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint64 +} + +type BpfProgram struct { + Len uint32 + _ [4]byte + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go new file mode 100644 index 00000000..e27511a6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go @@ -0,0 +1,602 @@ +// cgo -godefs -- -fsigned-char types_freebsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build arm,freebsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 + _ [4]byte +} + +type Timeval struct { + Sec int64 + Usec int32 + _ [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int64 + Max int64 +} + +type _Gid_t uint32 + +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + +type Stat_t struct { + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec +} + +type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [88]int8 + Mntonname [88]int8 +} + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte +} + +type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { + Fileno uint32 + Reclen uint16 + Type uint8 + Namlen uint8 + Name [256]int8 +} + +type Fsid struct { + Val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [46]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPMreqn struct { + Multiaddr [4]byte /* in_addr */ + Address [4]byte /* in_addr */ + Ifindex int32 +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x36 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPMreqn = 0xc + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter int16 + Flags uint16 + Fflags uint32 + Data int32 + Udata *byte +} + +type FdSet struct { + Bits [32]uint32 +} + +const ( + sizeofIfMsghdr = 0xa8 + SizeofIfMsghdr = 0x70 + sizeofIfData = 0x98 + SizeofIfData = 0x60 + SizeofIfaMsghdr = 0x14 + SizeofIfmaMsghdr = 0x10 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x5c + SizeofRtMetrics = 0x38 +) + +type ifMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData +} + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData +} + +type ifData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte +} + +type IfData struct { + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Spare_char1 uint8 + Spare_char2 uint8 + Datalen uint8 + Mtu uint32 + Metric uint32 + Baudrate uint32 + Ipackets uint32 + Ierrors uint32 + Opackets uint32 + Oerrors uint32 + Collisions uint32 + Ibytes uint32 + Obytes uint32 + Imcasts uint32 + Omcasts uint32 + Iqdrops uint32 + Noproto uint32 + Hwassist uint32 + _ [4]byte + Epoch int64 + Lastchange Timeval +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 +} + +type IfmaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint32 + Mtu uint32 + Hopcount uint32 + Expire uint32 + Recvpipe uint32 + Sendpipe uint32 + Ssthresh uint32 + Rtt uint32 + Rttvar uint32 + Pksent uint32 + Weight uint32 + Filler [3]uint32 +} + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x8 + SizeofBpfZbuf = 0xc + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 + SizeofBpfZbufHeader = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint32 + Drop uint32 +} + +type BpfZbuf struct { + Bufa *byte + Bufb *byte + Buflen uint32 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte +} + +type BpfZbufHeader struct { + Kernel_gen uint32 + Kernel_len uint32 + User_gen uint32 + _ [5]uint32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed uint32 + Ospeed uint32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +const ( + AT_FDCWD = -0x64 + AT_REMOVEDIR = 0x800 + AT_SYMLINK_FOLLOW = 0x400 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLINIGNEOF = 0x2000 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type CapRights struct { + Rights [2]uint64 +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go new file mode 100644 index 00000000..2dae0c17 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go @@ -0,0 +1,465 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build 386,netbsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 +} + +type Timeval struct { + Sec int64 + Usec int32 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter uint32 + Flags uint32 + Fflags uint32 + Data int64 + Udata int32 +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x84 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData + Pad_cgo_1 [4]byte +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [2]byte +} + +type BpfTimeval struct { + Sec int32 + Usec int32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go new file mode 100644 index 00000000..1f0e76c0 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go @@ -0,0 +1,472 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build amd64,netbsd + +package unix + +const ( + SizeofPtr = 0x8 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x8 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int32 + Pad_cgo_0 [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Pad_cgo_0 [4]byte + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Pad_cgo_1 [4]byte + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 + Pad_cgo_2 [4]byte +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint64 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Pad_cgo_0 [4]byte + Iov *Iovec + Iovlen int32 + Pad_cgo_1 [4]byte + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x30 + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint64 + Filter uint32 + Flags uint32 + Fflags uint32 + Pad_cgo_0 [4]byte + Data int64 + Udata int64 +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x88 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x10 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x20 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Pad_cgo_0 [4]byte + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [6]byte +} + +type BpfTimeval struct { + Sec int64 + Usec int64 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go new file mode 100644 index 00000000..53f2159c --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go @@ -0,0 +1,470 @@ +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build arm,netbsd + +package unix + +const ( + SizeofPtr = 0x4 + SizeofShort = 0x2 + SizeofInt = 0x4 + SizeofLong = 0x4 + SizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int32 + Pad_cgo_0 [4]byte +} + +type Timeval struct { + Sec int64 + Usec int32 + Pad_cgo_0 [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type _Gid_t uint32 + +type Stat_t struct { + Dev uint64 + Mode uint32 + Pad_cgo_0 [4]byte + Ino uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Pad_cgo_1 [4]byte + Rdev uint64 + Atimespec Timespec + Mtimespec Timespec + Ctimespec Timespec + Birthtimespec Timespec + Size int64 + Blocks int64 + Blksize uint32 + Flags uint32 + Gen uint32 + Spare [2]uint32 + Pad_cgo_2 [4]byte +} + +type Statfs_t [0]byte + +type Flock_t struct { + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 +} + +type Dirent struct { + Fileno uint64 + Reclen uint16 + Namlen uint16 + Type uint8 + Name [512]int8 + Pad_cgo_0 [3]byte +} + +type Fsid struct { + X__fsid_val [2]int32 +} + +const ( + PathMax = 0x400 +) + +const ( + FADV_NORMAL = 0x0 + FADV_RANDOM = 0x1 + FADV_SEQUENTIAL = 0x2 + FADV_WILLNEED = 0x3 + FADV_DONTNEED = 0x4 + FADV_NOREUSE = 0x5 +) + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + +type RawSockaddrUnix struct { + Len uint8 + Family uint8 + Path [104]int8 +} + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [12]int8 +} + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrAny struct { + Addr RawSockaddr + Pad [92]int8 +} + +type _Socklen uint32 + +type Linger struct { + Onoff int32 + Linger int32 +} + +type Iovec struct { + Base *byte + Len uint32 +} + +type IPMreq struct { + Multiaddr [4]byte /* in_addr */ + Interface [4]byte /* in_addr */ +} + +type IPv6Mreq struct { + Multiaddr [16]byte /* in6_addr */ + Interface uint32 +} + +type Msghdr struct { + Name *byte + Namelen uint32 + Iov *Iovec + Iovlen int32 + Control *byte + Controllen uint32 + Flags int32 +} + +type Cmsghdr struct { + Len uint32 + Level int32 + Type int32 +} + +type Inet6Pktinfo struct { + Addr [16]byte /* in6_addr */ + Ifindex uint32 +} + +type IPv6MTUInfo struct { + Addr RawSockaddrInet6 + Mtu uint32 +} + +type ICMPv6Filter struct { + Filt [8]uint32 +} + +const ( + SizeofSockaddrInet4 = 0x10 + SizeofSockaddrInet6 = 0x1c + SizeofSockaddrAny = 0x6c + SizeofSockaddrUnix = 0x6a + SizeofSockaddrDatalink = 0x14 + SizeofLinger = 0x8 + SizeofIPMreq = 0x8 + SizeofIPv6Mreq = 0x14 + SizeofMsghdr = 0x1c + SizeofCmsghdr = 0xc + SizeofInet6Pktinfo = 0x14 + SizeofIPv6MTUInfo = 0x20 + SizeofICMPv6Filter = 0x20 +) + +const ( + PTRACE_TRACEME = 0x0 + PTRACE_CONT = 0x7 + PTRACE_KILL = 0x8 +) + +type Kevent_t struct { + Ident uint32 + Filter uint32 + Flags uint32 + Fflags uint32 + Data int64 + Udata int32 + Pad_cgo_0 [4]byte +} + +type FdSet struct { + Bits [8]uint32 +} + +const ( + SizeofIfMsghdr = 0x98 + SizeofIfData = 0x88 + SizeofIfaMsghdr = 0x18 + SizeofIfAnnounceMsghdr = 0x18 + SizeofRtMsghdr = 0x78 + SizeofRtMetrics = 0x50 +) + +type IfMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Pad_cgo_0 [2]byte + Data IfData +} + +type IfData struct { + Type uint8 + Addrlen uint8 + Hdrlen uint8 + Pad_cgo_0 [1]byte + Link_state int32 + Mtu uint64 + Metric uint64 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Lastchange Timespec +} + +type IfaMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Metric int32 + Index uint16 + Pad_cgo_0 [6]byte +} + +type IfAnnounceMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Name [16]int8 + What uint16 +} + +type RtMsghdr struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Pad_cgo_0 [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Use int32 + Inits int32 + Pad_cgo_1 [4]byte + Rmx RtMetrics +} + +type RtMetrics struct { + Locks uint64 + Mtu uint64 + Hopcount uint64 + Recvpipe uint64 + Sendpipe uint64 + Ssthresh uint64 + Rtt uint64 + Rttvar uint64 + Expire int64 + Pksent int64 +} + +type Mclpool [0]byte + +const ( + SizeofBpfVersion = 0x4 + SizeofBpfStat = 0x80 + SizeofBpfProgram = 0x8 + SizeofBpfInsn = 0x8 + SizeofBpfHdr = 0x14 +) + +type BpfVersion struct { + Major uint16 + Minor uint16 +} + +type BpfStat struct { + Recv uint64 + Drop uint64 + Capt uint64 + Padding [13]uint64 +} + +type BpfProgram struct { + Len uint32 + Insns *BpfInsn +} + +type BpfInsn struct { + Code uint16 + Jt uint8 + Jf uint8 + K uint32 +} + +type BpfHdr struct { + Tstamp BpfTimeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + Pad_cgo_0 [2]byte +} + +type BpfTimeval struct { + Sec int32 + Usec int32 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +} + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Ptmget struct { + Cfd int32 + Sfd int32 + Cn [1024]byte + Sn [1024]byte +} + +const ( + AT_FDCWD = -0x64 + AT_SYMLINK_NOFOLLOW = 0x200 +) + +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + +type Sysctlnode struct { + Flags uint32 + Num int32 + Name [32]int8 + Ver uint32 + X__rsvd uint32 + Un [16]byte + X_sysctl_size [8]byte + X_sysctl_func [8]byte + X_sysctl_parent [8]byte + X_sysctl_desc [8]byte +} + +type Utsname struct { + Sysname [256]byte + Nodename [256]byte + Release [256]byte + Version [256]byte + Machine [256]byte +} + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/AUTHORS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/AUTHORS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/AUTHORS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/AUTHORS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/CONTRIBUTORS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/CONTRIBUTORS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/CONTRIBUTORS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/CONTRIBUTORS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/LICENSE similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/PATENTS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/PATENTS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/PATENTS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/PATENTS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/transform/transform.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/transform/transform.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/transform/transform.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/transform/transform.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bidi.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bidi.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bidi.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bidi.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bracket.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bracket.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/bracket.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/bracket.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/core.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/core.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/core.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/core.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_ranges.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/gen_trieval.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/prop.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/prop.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/prop.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/prop.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/trieval.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/trieval.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/bidi/trieval.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/bidi/trieval.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/composition.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/composition.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/composition.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/composition.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/forminfo.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/forminfo.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/forminfo.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/forminfo.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/input.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/input.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/input.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/input.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/iter.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/iter.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/iter.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/iter.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/maketables.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/maketables.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/maketables.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/maketables.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/normalize.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/normalize.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/normalize.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/normalize.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/readwriter.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/readwriter.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/readwriter.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/readwriter.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/transform.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/transform.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/transform.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/transform.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/trie.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/trie.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/trie.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/trie.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/triegen.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/triegen.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/golang.org/x/text/unicode/norm/triegen.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/golang.org/x/text/unicode/norm/triegen.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/LICENSE similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml new file mode 100644 index 00000000..f443eec9 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/.travis.yml @@ -0,0 +1,37 @@ +language: go + +matrix: + include: + - go: 1.11.x + env: VET=1 GO111MODULE=on + - go: 1.11.x + env: RACE=1 GO111MODULE=on + - go: 1.11.x + env: RUN386=1 + - go: 1.11.x + env: GRPC_GO_RETRY=on + - go: 1.10.x + - go: 1.9.x + - go: 1.9.x + env: GAE=1 + +go_import_path: google.golang.org/grpc + +before_install: + - if [[ "${GO111MODULE}" = "on" ]]; then mkdir "${HOME}/go"; export GOPATH="${HOME}/go"; fi + - if [[ -n "${RUN386}" ]]; then export GOARCH=386; fi + - if [[ "${TRAVIS_EVENT_TYPE}" = "cron" && -z "${RUN386}" ]]; then RACE=1; fi + - if [[ "${TRAVIS_EVENT_TYPE}" != "cron" ]]; then VET_SKIP_PROTO=1; fi + +install: + - try3() { eval "$*" || eval "$*" || eval "$*"; } + - try3 'if [[ "${GO111MODULE}" = "on" ]]; then go mod download; else make testdeps; fi' + - if [[ "${GAE}" = 1 ]]; then source ./install_gae.sh; make testappenginedeps; fi + - if [[ "${VET}" = 1 ]]; then ./vet.sh -install; fi + +script: + - set -e + - if [[ "${VET}" = 1 ]]; then ./vet.sh; fi + - if [[ "${GAE}" = 1 ]]; then make testappengine; exit 0; fi + - if [[ "${RACE}" = 1 ]]; then make testrace; exit 0; fi + - make test diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/AUTHORS b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/AUTHORS similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/AUTHORS rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/AUTHORS diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/CONTRIBUTING.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/CONTRIBUTING.md similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/CONTRIBUTING.md rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/CONTRIBUTING.md diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/LICENSE b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/LICENSE similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/LICENSE rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/LICENSE diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/Makefile b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/Makefile similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/Makefile rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/Makefile diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md new file mode 100644 index 00000000..e3fb3c75 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/README.md @@ -0,0 +1,67 @@ +# gRPC-Go + +[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc) [![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go) + +The Go implementation of [gRPC](https://grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start: Go](https://grpc.io/docs/quickstart/go.html) guide. + +Installation +------------ + +To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run: + +``` +$ go get -u google.golang.org/grpc +``` + +Prerequisites +------------- + +gRPC-Go requires Go 1.9 or later. + +Constraints +----------- +The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](http://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants. + +Documentation +------------- +See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/). + +Performance +----------- +See the current benchmarks for some of the languages supported in [this dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696). + +Status +------ +General Availability [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages). + +FAQ +--- + +#### Compiling error, undefined: grpc.SupportPackageIsVersion + +Please update proto package, gRPC package and rebuild the proto files: + - `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}` + - `go get -u google.golang.org/grpc` + - `protoc --go_out=plugins=grpc:. *.proto` + +#### How to turn on logging + +The default logger is controlled by the environment variables. Turn everything +on by setting: + +``` +GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info +``` + +#### The RPC failed with error `"code = Unavailable desc = transport is closing"` + +This error means the connection the RPC is using was closed, and there are many +possible reasons, including: + 1. mis-configured transport credentials, connection failed on handshaking + 1. bytes disrupted, possibly by a proxy in between + 1. server shutdown + +It can be tricky to debug this because the error happens on the client side but +the root cause of the connection being closed is on the server side. Turn on +logging on __both client and server__, and see if there are any transport +errors. diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/backoff.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/backoff.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/backoff.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/backoff.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go new file mode 100644 index 00000000..a78e702b --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer.go @@ -0,0 +1,391 @@ +/* + * + * Copyright 2016 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 grpc + +import ( + "context" + "net" + "sync" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/naming" + "google.golang.org/grpc/status" +) + +// Address represents a server the client connects to. +// +// Deprecated: please use package balancer. +type Address struct { + // Addr is the server address on which a connection will be established. + Addr string + // Metadata is the information associated with Addr, which may be used + // to make load balancing decision. + Metadata interface{} +} + +// BalancerConfig specifies the configurations for Balancer. +// +// Deprecated: please use package balancer. +type BalancerConfig struct { + // DialCreds is the transport credential the Balancer implementation can + // use to dial to a remote load balancer server. The Balancer implementations + // can ignore this if it does not need to talk to another party securely. + DialCreds credentials.TransportCredentials + // Dialer is the custom dialer the Balancer implementation can use to dial + // to a remote load balancer server. The Balancer implementations + // can ignore this if it doesn't need to talk to remote balancer. + Dialer func(context.Context, string) (net.Conn, error) +} + +// BalancerGetOptions configures a Get call. +// +// Deprecated: please use package balancer. +type BalancerGetOptions struct { + // BlockingWait specifies whether Get should block when there is no + // connected address. + BlockingWait bool +} + +// Balancer chooses network addresses for RPCs. +// +// Deprecated: please use package balancer. +type Balancer interface { + // Start does the initialization work to bootstrap a Balancer. For example, + // this function may start the name resolution and watch the updates. It will + // be called when dialing. + Start(target string, config BalancerConfig) error + // Up informs the Balancer that gRPC has a connection to the server at + // addr. It returns down which is called once the connection to addr gets + // lost or closed. + // TODO: It is not clear how to construct and take advantage of the meaningful error + // parameter for down. Need realistic demands to guide. + Up(addr Address) (down func(error)) + // Get gets the address of a server for the RPC corresponding to ctx. + // i) If it returns a connected address, gRPC internals issues the RPC on the + // connection to this address; + // ii) If it returns an address on which the connection is under construction + // (initiated by Notify(...)) but not connected, gRPC internals + // * fails RPC if the RPC is fail-fast and connection is in the TransientFailure or + // Shutdown state; + // or + // * issues RPC on the connection otherwise. + // iii) If it returns an address on which the connection does not exist, gRPC + // internals treats it as an error and will fail the corresponding RPC. + // + // Therefore, the following is the recommended rule when writing a custom Balancer. + // If opts.BlockingWait is true, it should return a connected address or + // block if there is no connected address. It should respect the timeout or + // cancellation of ctx when blocking. If opts.BlockingWait is false (for fail-fast + // RPCs), it should return an address it has notified via Notify(...) immediately + // instead of blocking. + // + // The function returns put which is called once the rpc has completed or failed. + // put can collect and report RPC stats to a remote load balancer. + // + // This function should only return the errors Balancer cannot recover by itself. + // gRPC internals will fail the RPC if an error is returned. + Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) + // Notify returns a channel that is used by gRPC internals to watch the addresses + // gRPC needs to connect. The addresses might be from a name resolver or remote + // load balancer. gRPC internals will compare it with the existing connected + // addresses. If the address Balancer notified is not in the existing connected + // addresses, gRPC starts to connect the address. If an address in the existing + // connected addresses is not in the notification list, the corresponding connection + // is shutdown gracefully. Otherwise, there are no operations to take. Note that + // the Address slice must be the full list of the Addresses which should be connected. + // It is NOT delta. + Notify() <-chan []Address + // Close shuts down the balancer. + Close() error +} + +// RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch +// the name resolution updates and updates the addresses available correspondingly. +// +// Deprecated: please use package balancer/roundrobin. +func RoundRobin(r naming.Resolver) Balancer { + return &roundRobin{r: r} +} + +type addrInfo struct { + addr Address + connected bool +} + +type roundRobin struct { + r naming.Resolver + w naming.Watcher + addrs []*addrInfo // all the addresses the client should potentially connect + mu sync.Mutex + addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to. + next int // index of the next address to return for Get() + waitCh chan struct{} // the channel to block when there is no connected address available + done bool // The Balancer is closed. +} + +func (rr *roundRobin) watchAddrUpdates() error { + updates, err := rr.w.Next() + if err != nil { + grpclog.Warningf("grpc: the naming watcher stops working due to %v.", err) + return err + } + rr.mu.Lock() + defer rr.mu.Unlock() + for _, update := range updates { + addr := Address{ + Addr: update.Addr, + Metadata: update.Metadata, + } + switch update.Op { + case naming.Add: + var exist bool + for _, v := range rr.addrs { + if addr == v.addr { + exist = true + grpclog.Infoln("grpc: The name resolver wanted to add an existing address: ", addr) + break + } + } + if exist { + continue + } + rr.addrs = append(rr.addrs, &addrInfo{addr: addr}) + case naming.Delete: + for i, v := range rr.addrs { + if addr == v.addr { + copy(rr.addrs[i:], rr.addrs[i+1:]) + rr.addrs = rr.addrs[:len(rr.addrs)-1] + break + } + } + default: + grpclog.Errorln("Unknown update.Op ", update.Op) + } + } + // Make a copy of rr.addrs and write it onto rr.addrCh so that gRPC internals gets notified. + open := make([]Address, len(rr.addrs)) + for i, v := range rr.addrs { + open[i] = v.addr + } + if rr.done { + return ErrClientConnClosing + } + select { + case <-rr.addrCh: + default: + } + rr.addrCh <- open + return nil +} + +func (rr *roundRobin) Start(target string, config BalancerConfig) error { + rr.mu.Lock() + defer rr.mu.Unlock() + if rr.done { + return ErrClientConnClosing + } + if rr.r == nil { + // If there is no name resolver installed, it is not needed to + // do name resolution. In this case, target is added into rr.addrs + // as the only address available and rr.addrCh stays nil. + rr.addrs = append(rr.addrs, &addrInfo{addr: Address{Addr: target}}) + return nil + } + w, err := rr.r.Resolve(target) + if err != nil { + return err + } + rr.w = w + rr.addrCh = make(chan []Address, 1) + go func() { + for { + if err := rr.watchAddrUpdates(); err != nil { + return + } + } + }() + return nil +} + +// Up sets the connected state of addr and sends notification if there are pending +// Get() calls. +func (rr *roundRobin) Up(addr Address) func(error) { + rr.mu.Lock() + defer rr.mu.Unlock() + var cnt int + for _, a := range rr.addrs { + if a.addr == addr { + if a.connected { + return nil + } + a.connected = true + } + if a.connected { + cnt++ + } + } + // addr is only one which is connected. Notify the Get() callers who are blocking. + if cnt == 1 && rr.waitCh != nil { + close(rr.waitCh) + rr.waitCh = nil + } + return func(err error) { + rr.down(addr, err) + } +} + +// down unsets the connected state of addr. +func (rr *roundRobin) down(addr Address, err error) { + rr.mu.Lock() + defer rr.mu.Unlock() + for _, a := range rr.addrs { + if addr == a.addr { + a.connected = false + break + } + } +} + +// Get returns the next addr in the rotation. +func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) { + var ch chan struct{} + rr.mu.Lock() + if rr.done { + rr.mu.Unlock() + err = ErrClientConnClosing + return + } + + if len(rr.addrs) > 0 { + if rr.next >= len(rr.addrs) { + rr.next = 0 + } + next := rr.next + for { + a := rr.addrs[next] + next = (next + 1) % len(rr.addrs) + if a.connected { + addr = a.addr + rr.next = next + rr.mu.Unlock() + return + } + if next == rr.next { + // Has iterated all the possible address but none is connected. + break + } + } + } + if !opts.BlockingWait { + if len(rr.addrs) == 0 { + rr.mu.Unlock() + err = status.Errorf(codes.Unavailable, "there is no address available") + return + } + // Returns the next addr on rr.addrs for failfast RPCs. + addr = rr.addrs[rr.next].addr + rr.next++ + rr.mu.Unlock() + return + } + // Wait on rr.waitCh for non-failfast RPCs. + if rr.waitCh == nil { + ch = make(chan struct{}) + rr.waitCh = ch + } else { + ch = rr.waitCh + } + rr.mu.Unlock() + for { + select { + case <-ctx.Done(): + err = ctx.Err() + return + case <-ch: + rr.mu.Lock() + if rr.done { + rr.mu.Unlock() + err = ErrClientConnClosing + return + } + + if len(rr.addrs) > 0 { + if rr.next >= len(rr.addrs) { + rr.next = 0 + } + next := rr.next + for { + a := rr.addrs[next] + next = (next + 1) % len(rr.addrs) + if a.connected { + addr = a.addr + rr.next = next + rr.mu.Unlock() + return + } + if next == rr.next { + // Has iterated all the possible address but none is connected. + break + } + } + } + // The newly added addr got removed by Down() again. + if rr.waitCh == nil { + ch = make(chan struct{}) + rr.waitCh = ch + } else { + ch = rr.waitCh + } + rr.mu.Unlock() + } + } +} + +func (rr *roundRobin) Notify() <-chan []Address { + return rr.addrCh +} + +func (rr *roundRobin) Close() error { + rr.mu.Lock() + defer rr.mu.Unlock() + if rr.done { + return errBalancerClosed + } + rr.done = true + if rr.w != nil { + rr.w.Close() + } + if rr.waitCh != nil { + close(rr.waitCh) + rr.waitCh = nil + } + if rr.addrCh != nil { + close(rr.addrCh) + } + return nil +} + +// pickFirst is used to test multi-addresses in one addrConn in which all addresses share the same addrConn. +// It is a wrapper around roundRobin balancer. The logic of all methods works fine because balancer.Get() +// returns the only address Up by resetTransport(). +type pickFirst struct { + *roundRobin +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go new file mode 100644 index 00000000..1bf46aaf --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/balancer.go @@ -0,0 +1,290 @@ +/* + * + * 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 balancer defines APIs for load balancing in gRPC. +// All APIs in this package are experimental. +package balancer + +import ( + "context" + "errors" + "net" + "strings" + + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/resolver" +) + +var ( + // m is a map from name to balancer builder. + m = make(map[string]Builder) +) + +// Register registers the balancer builder to the balancer map. b.Name +// (lowercased) will be used as the name registered with this builder. +// +// NOTE: this function must only be called during initialization time (i.e. in +// an init() function), and is not thread-safe. If multiple Balancers are +// registered with the same name, the one registered last will take effect. +func Register(b Builder) { + m[strings.ToLower(b.Name())] = b +} + +// Get returns the resolver builder registered with the given name. +// Note that the compare is done in a case-insenstive fashion. +// If no builder is register with the name, nil will be returned. +func Get(name string) Builder { + if b, ok := m[strings.ToLower(name)]; ok { + return b + } + return nil +} + +// SubConn represents a gRPC sub connection. +// Each sub connection contains a list of addresses. gRPC will +// try to connect to them (in sequence), and stop trying the +// remainder once one connection is successful. +// +// The reconnect backoff will be applied on the list, not a single address. +// For example, try_on_all_addresses -> backoff -> try_on_all_addresses. +// +// All SubConns start in IDLE, and will not try to connect. To trigger +// the connecting, Balancers must call Connect. +// When the connection encounters an error, it will reconnect immediately. +// When the connection becomes IDLE, it will not reconnect unless Connect is +// called. +// +// This interface is to be implemented by gRPC. Users should not need a +// brand new implementation of this interface. For the situations like +// testing, the new implementation should embed this interface. This allows +// gRPC to add new methods to this interface. +type SubConn interface { + // UpdateAddresses updates the addresses used in this SubConn. + // gRPC checks if currently-connected address is still in the new list. + // If it's in the list, the connection will be kept. + // If it's not in the list, the connection will gracefully closed, and + // a new connection will be created. + // + // This will trigger a state transition for the SubConn. + UpdateAddresses([]resolver.Address) + // Connect starts the connecting for this SubConn. + Connect() +} + +// NewSubConnOptions contains options to create new SubConn. +type NewSubConnOptions struct { + // CredsBundle is the credentials bundle that will be used in the created + // SubConn. If it's nil, the original creds from grpc DialOptions will be + // used. + CredsBundle credentials.Bundle + // HealthCheckEnabled indicates whether health check service should be + // enabled on this SubConn + HealthCheckEnabled bool +} + +// ClientConn represents a gRPC ClientConn. +// +// This interface is to be implemented by gRPC. Users should not need a +// brand new implementation of this interface. For the situations like +// testing, the new implementation should embed this interface. This allows +// gRPC to add new methods to this interface. +type ClientConn interface { + // NewSubConn is called by balancer to create a new SubConn. + // It doesn't block and wait for the connections to be established. + // Behaviors of the SubConn can be controlled by options. + NewSubConn([]resolver.Address, NewSubConnOptions) (SubConn, error) + // RemoveSubConn removes the SubConn from ClientConn. + // The SubConn will be shutdown. + RemoveSubConn(SubConn) + + // UpdateBalancerState is called by balancer to nofity gRPC that some internal + // state in balancer has changed. + // + // gRPC will update the connectivity state of the ClientConn, and will call pick + // on the new picker to pick new SubConn. + UpdateBalancerState(s connectivity.State, p Picker) + + // ResolveNow is called by balancer to notify gRPC to do a name resolving. + ResolveNow(resolver.ResolveNowOption) + + // Target returns the dial target for this ClientConn. + Target() string +} + +// BuildOptions contains additional information for Build. +type BuildOptions struct { + // DialCreds is the transport credential the Balancer implementation can + // use to dial to a remote load balancer server. The Balancer implementations + // can ignore this if it does not need to talk to another party securely. + DialCreds credentials.TransportCredentials + // CredsBundle is the credentials bundle that the Balancer can use. + CredsBundle credentials.Bundle + // Dialer is the custom dialer the Balancer implementation can use to dial + // to a remote load balancer server. The Balancer implementations + // can ignore this if it doesn't need to talk to remote balancer. + Dialer func(context.Context, string) (net.Conn, error) + // ChannelzParentID is the entity parent's channelz unique identification number. + ChannelzParentID int64 +} + +// Builder creates a balancer. +type Builder interface { + // Build creates a new balancer with the ClientConn. + Build(cc ClientConn, opts BuildOptions) Balancer + // Name returns the name of balancers built by this builder. + // It will be used to pick balancers (for example in service config). + Name() string +} + +// PickOptions contains addition information for the Pick operation. +type PickOptions struct { + // FullMethodName is the method name that NewClientStream() is called + // with. The canonical format is /service/Method. + FullMethodName string + // Header contains the metadata from the RPC's client header. The metadata + // should not be modified; make a copy first if needed. + Header metadata.MD +} + +// DoneInfo contains additional information for done. +type DoneInfo struct { + // Err is the rpc error the RPC finished with. It could be nil. + Err error + // Trailer contains the metadata from the RPC's trailer, if present. + Trailer metadata.MD + // BytesSent indicates if any bytes have been sent to the server. + BytesSent bool + // BytesReceived indicates if any byte has been received from the server. + BytesReceived bool +} + +var ( + // ErrNoSubConnAvailable indicates no SubConn is available for pick(). + // gRPC will block the RPC until a new picker is available via UpdateBalancerState(). + ErrNoSubConnAvailable = errors.New("no SubConn is available") + // ErrTransientFailure indicates all SubConns are in TransientFailure. + // WaitForReady RPCs will block, non-WaitForReady RPCs will fail. + ErrTransientFailure = errors.New("all SubConns are in TransientFailure") +) + +// Picker is used by gRPC to pick a SubConn to send an RPC. +// Balancer is expected to generate a new picker from its snapshot every time its +// internal state has changed. +// +// The pickers used by gRPC can be updated by ClientConn.UpdateBalancerState(). +type Picker interface { + // Pick returns the SubConn to be used to send the RPC. + // The returned SubConn must be one returned by NewSubConn(). + // + // This functions is expected to return: + // - a SubConn that is known to be READY; + // - ErrNoSubConnAvailable if no SubConn is available, but progress is being + // made (for example, some SubConn is in CONNECTING mode); + // - other errors if no active connecting is happening (for example, all SubConn + // are in TRANSIENT_FAILURE mode). + // + // If a SubConn is returned: + // - If it is READY, gRPC will send the RPC on it; + // - If it is not ready, or becomes not ready after it's returned, gRPC will block + // until UpdateBalancerState() is called and will call pick on the new picker. + // + // If the returned error is not nil: + // - If the error is ErrNoSubConnAvailable, gRPC will block until UpdateBalancerState() + // - If the error is ErrTransientFailure: + // - If the RPC is wait-for-ready, gRPC will block until UpdateBalancerState() + // is called to pick again; + // - Otherwise, RPC will fail with unavailable error. + // - Else (error is other non-nil error): + // - The RPC will fail with unavailable error. + // + // The returned done() function will be called once the rpc has finished, with the + // final status of that RPC. + // done may be nil if balancer doesn't care about the RPC status. + Pick(ctx context.Context, opts PickOptions) (conn SubConn, done func(DoneInfo), err error) +} + +// Balancer takes input from gRPC, manages SubConns, and collects and aggregates +// the connectivity states. +// +// It also generates and updates the Picker used by gRPC to pick SubConns for RPCs. +// +// HandleSubConnectionStateChange, HandleResolvedAddrs and Close are guaranteed +// to be called synchronously from the same goroutine. +// There's no guarantee on picker.Pick, it may be called anytime. +type Balancer interface { + // HandleSubConnStateChange is called by gRPC when the connectivity state + // of sc has changed. + // Balancer is expected to aggregate all the state of SubConn and report + // that back to gRPC. + // Balancer should also generate and update Pickers when its internal state has + // been changed by the new state. + HandleSubConnStateChange(sc SubConn, state connectivity.State) + // HandleResolvedAddrs is called by gRPC to send updated resolved addresses to + // balancers. + // Balancer can create new SubConn or remove SubConn with the addresses. + // An empty address slice and a non-nil error will be passed if the resolver returns + // non-nil error to gRPC. + HandleResolvedAddrs([]resolver.Address, error) + // Close closes the balancer. The balancer is not required to call + // ClientConn.RemoveSubConn for its existing SubConns. + Close() +} + +// ConnectivityStateEvaluator takes the connectivity states of multiple SubConns +// and returns one aggregated connectivity state. +// +// It's not thread safe. +type ConnectivityStateEvaluator struct { + numReady uint64 // Number of addrConns in ready state. + numConnecting uint64 // Number of addrConns in connecting state. + numTransientFailure uint64 // Number of addrConns in transientFailure. +} + +// RecordTransition records state change happening in subConn and based on that +// it evaluates what aggregated state should be. +// +// - If at least one SubConn in Ready, the aggregated state is Ready; +// - Else if at least one SubConn in Connecting, the aggregated state is Connecting; +// - Else the aggregated state is TransientFailure. +// +// Idle and Shutdown are not considered. +func (cse *ConnectivityStateEvaluator) RecordTransition(oldState, newState connectivity.State) connectivity.State { + // Update counters. + for idx, state := range []connectivity.State{oldState, newState} { + updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. + switch state { + case connectivity.Ready: + cse.numReady += updateVal + case connectivity.Connecting: + cse.numConnecting += updateVal + case connectivity.TransientFailure: + cse.numTransientFailure += updateVal + } + } + + // Evaluate. + if cse.numReady > 0 { + return connectivity.Ready + } + if cse.numConnecting > 0 { + return connectivity.Connecting + } + return connectivity.TransientFailure +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go new file mode 100644 index 00000000..5f55b274 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/balancer.go @@ -0,0 +1,212 @@ +/* + * + * 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 base + +import ( + "context" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +type baseBuilder struct { + name string + pickerBuilder PickerBuilder + config Config +} + +func (bb *baseBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { + return &baseBalancer{ + cc: cc, + pickerBuilder: bb.pickerBuilder, + + subConns: make(map[resolver.Address]balancer.SubConn), + scStates: make(map[balancer.SubConn]connectivity.State), + csEvltr: &connectivityStateEvaluator{}, + // Initialize picker to a picker that always return + // ErrNoSubConnAvailable, because when state of a SubConn changes, we + // may call UpdateBalancerState with this picker. + picker: NewErrPicker(balancer.ErrNoSubConnAvailable), + config: bb.config, + } +} + +func (bb *baseBuilder) Name() string { + return bb.name +} + +type baseBalancer struct { + cc balancer.ClientConn + pickerBuilder PickerBuilder + + csEvltr *connectivityStateEvaluator + state connectivity.State + + subConns map[resolver.Address]balancer.SubConn + scStates map[balancer.SubConn]connectivity.State + picker balancer.Picker + config Config +} + +func (b *baseBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) { + if err != nil { + grpclog.Infof("base.baseBalancer: HandleResolvedAddrs called with error %v", err) + return + } + grpclog.Infoln("base.baseBalancer: got new resolved addresses: ", addrs) + // addrsSet is the set converted from addrs, it's used for quick lookup of an address. + addrsSet := make(map[resolver.Address]struct{}) + for _, a := range addrs { + addrsSet[a] = struct{}{} + if _, ok := b.subConns[a]; !ok { + // a is a new address (not existing in b.subConns). + sc, err := b.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{HealthCheckEnabled: b.config.HealthCheck}) + if err != nil { + grpclog.Warningf("base.baseBalancer: failed to create new SubConn: %v", err) + continue + } + b.subConns[a] = sc + b.scStates[sc] = connectivity.Idle + sc.Connect() + } + } + for a, sc := range b.subConns { + // a was removed by resolver. + if _, ok := addrsSet[a]; !ok { + b.cc.RemoveSubConn(sc) + delete(b.subConns, a) + // Keep the state of this sc in b.scStates until sc's state becomes Shutdown. + // The entry will be deleted in HandleSubConnStateChange. + } + } +} + +// regeneratePicker takes a snapshot of the balancer, and generates a picker +// from it. The picker is +// - errPicker with ErrTransientFailure if the balancer is in TransientFailure, +// - built by the pickerBuilder with all READY SubConns otherwise. +func (b *baseBalancer) regeneratePicker() { + if b.state == connectivity.TransientFailure { + b.picker = NewErrPicker(balancer.ErrTransientFailure) + return + } + readySCs := make(map[resolver.Address]balancer.SubConn) + + // Filter out all ready SCs from full subConn map. + for addr, sc := range b.subConns { + if st, ok := b.scStates[sc]; ok && st == connectivity.Ready { + readySCs[addr] = sc + } + } + b.picker = b.pickerBuilder.Build(readySCs) +} + +func (b *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + grpclog.Infof("base.baseBalancer: handle SubConn state change: %p, %v", sc, s) + oldS, ok := b.scStates[sc] + if !ok { + grpclog.Infof("base.baseBalancer: got state changes for an unknown SubConn: %p, %v", sc, s) + return + } + b.scStates[sc] = s + switch s { + case connectivity.Idle: + sc.Connect() + case connectivity.Shutdown: + // When an address was removed by resolver, b called RemoveSubConn but + // kept the sc's state in scStates. Remove state for this sc here. + delete(b.scStates, sc) + } + + oldAggrState := b.state + b.state = b.csEvltr.recordTransition(oldS, s) + + // Regenerate picker when one of the following happens: + // - this sc became ready from not-ready + // - this sc became not-ready from ready + // - the aggregated state of balancer became TransientFailure from non-TransientFailure + // - the aggregated state of balancer became non-TransientFailure from TransientFailure + if (s == connectivity.Ready) != (oldS == connectivity.Ready) || + (b.state == connectivity.TransientFailure) != (oldAggrState == connectivity.TransientFailure) { + b.regeneratePicker() + } + + b.cc.UpdateBalancerState(b.state, b.picker) +} + +// Close is a nop because base balancer doesn't have internal state to clean up, +// and it doesn't need to call RemoveSubConn for the SubConns. +func (b *baseBalancer) Close() { +} + +// NewErrPicker returns a picker that always returns err on Pick(). +func NewErrPicker(err error) balancer.Picker { + return &errPicker{err: err} +} + +type errPicker struct { + err error // Pick() always returns this err. +} + +func (p *errPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + return nil, nil, p.err +} + +// connectivityStateEvaluator gets updated by addrConns when their +// states transition, based on which it evaluates the state of +// ClientConn. +type connectivityStateEvaluator struct { + numReady uint64 // Number of addrConns in ready state. + numConnecting uint64 // Number of addrConns in connecting state. + numTransientFailure uint64 // Number of addrConns in transientFailure. +} + +// recordTransition records state change happening in every subConn and based on +// that it evaluates what aggregated state should be. +// It can only transition between Ready, Connecting and TransientFailure. Other states, +// Idle and Shutdown are transitioned into by ClientConn; in the beginning of the connection +// before any subConn is created ClientConn is in idle state. In the end when ClientConn +// closes it is in Shutdown state. +// +// recordTransition should only be called synchronously from the same goroutine. +func (cse *connectivityStateEvaluator) recordTransition(oldState, newState connectivity.State) connectivity.State { + // Update counters. + for idx, state := range []connectivity.State{oldState, newState} { + updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new. + switch state { + case connectivity.Ready: + cse.numReady += updateVal + case connectivity.Connecting: + cse.numConnecting += updateVal + case connectivity.TransientFailure: + cse.numTransientFailure += updateVal + } + } + + // Evaluate. + if cse.numReady > 0 { + return connectivity.Ready + } + if cse.numConnecting > 0 { + return connectivity.Connecting + } + return connectivity.TransientFailure +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go new file mode 100644 index 00000000..34b1f299 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/base/base.go @@ -0,0 +1,64 @@ +/* + * + * 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 base defines a balancer base that can be used to build balancers with +// different picking algorithms. +// +// The base balancer creates a new SubConn for each resolved address. The +// provided picker will only be notified about READY SubConns. +// +// This package is the base of round_robin balancer, its purpose is to be used +// to build round_robin like balancers with complex picking algorithms. +// Balancers with more complicated logic should try to implement a balancer +// builder from scratch. +// +// All APIs in this package are experimental. +package base + +import ( + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/resolver" +) + +// PickerBuilder creates balancer.Picker. +type PickerBuilder interface { + // Build takes a slice of ready SubConns, and returns a picker that will be + // used by gRPC to pick a SubConn. + Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker +} + +// NewBalancerBuilder returns a balancer builder. The balancers +// built by this builder will use the picker builder to build pickers. +func NewBalancerBuilder(name string, pb PickerBuilder) balancer.Builder { + return NewBalancerBuilderWithConfig(name, pb, Config{}) +} + +// Config contains the config info about the base balancer builder. +type Config struct { + // HealthCheck indicates whether health checking should be enabled for this specific balancer. + HealthCheck bool +} + +// NewBalancerBuilderWithConfig returns a base balancer builder configured by the provided config. +func NewBalancerBuilderWithConfig(name string, pb PickerBuilder, config Config) balancer.Builder { + return &baseBuilder{ + name: name, + pickerBuilder: pb, + config: config, + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go new file mode 100644 index 00000000..57aea9fb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go @@ -0,0 +1,79 @@ +/* + * + * 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 roundrobin defines a roundrobin balancer. Roundrobin balancer is +// installed as one of the default balancers in gRPC, users don't need to +// explicitly install this balancer. +package roundrobin + +import ( + "context" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/balancer/base" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// Name is the name of round_robin balancer. +const Name = "round_robin" + +// newBuilder creates a new roundrobin balancer builder. +func newBuilder() balancer.Builder { + return base.NewBalancerBuilderWithConfig(Name, &rrPickerBuilder{}, base.Config{HealthCheck: true}) +} + +func init() { + balancer.Register(newBuilder()) +} + +type rrPickerBuilder struct{} + +func (*rrPickerBuilder) Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker { + grpclog.Infof("roundrobinPicker: newPicker called with readySCs: %v", readySCs) + var scs []balancer.SubConn + for _, sc := range readySCs { + scs = append(scs, sc) + } + return &rrPicker{ + subConns: scs, + } +} + +type rrPicker struct { + // subConns is the snapshot of the roundrobin balancer when this picker was + // created. The slice is immutable. Each Get() will do a round robin + // selection from it and return the selected SubConn. + subConns []balancer.SubConn + + mu sync.Mutex + next int +} + +func (p *rrPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + if len(p.subConns) <= 0 { + return nil, nil, balancer.ErrNoSubConnAvailable + } + + p.mu.Lock() + sc := p.subConns[p.next] + p.next = (p.next + 1) % len(p.subConns) + p.mu.Unlock() + return sc, nil, nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go new file mode 100644 index 00000000..77b68477 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_conn_wrappers.go @@ -0,0 +1,306 @@ +/* + * + * 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 grpc + +import ( + "fmt" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// scStateUpdate contains the subConn and the new state it changed to. +type scStateUpdate struct { + sc balancer.SubConn + state connectivity.State +} + +// scStateUpdateBuffer is an unbounded channel for scStateChangeTuple. +// TODO make a general purpose buffer that uses interface{}. +type scStateUpdateBuffer struct { + c chan *scStateUpdate + mu sync.Mutex + backlog []*scStateUpdate +} + +func newSCStateUpdateBuffer() *scStateUpdateBuffer { + return &scStateUpdateBuffer{ + c: make(chan *scStateUpdate, 1), + } +} + +func (b *scStateUpdateBuffer) put(t *scStateUpdate) { + b.mu.Lock() + defer b.mu.Unlock() + if len(b.backlog) == 0 { + select { + case b.c <- t: + return + default: + } + } + b.backlog = append(b.backlog, t) +} + +func (b *scStateUpdateBuffer) load() { + b.mu.Lock() + defer b.mu.Unlock() + if len(b.backlog) > 0 { + select { + case b.c <- b.backlog[0]: + b.backlog[0] = nil + b.backlog = b.backlog[1:] + default: + } + } +} + +// get returns the channel that the scStateUpdate will be sent to. +// +// Upon receiving, the caller should call load to send another +// scStateChangeTuple onto the channel if there is any. +func (b *scStateUpdateBuffer) get() <-chan *scStateUpdate { + return b.c +} + +// resolverUpdate contains the new resolved addresses or error if there's +// any. +type resolverUpdate struct { + addrs []resolver.Address + err error +} + +// ccBalancerWrapper is a wrapper on top of cc for balancers. +// It implements balancer.ClientConn interface. +type ccBalancerWrapper struct { + cc *ClientConn + balancer balancer.Balancer + stateChangeQueue *scStateUpdateBuffer + resolverUpdateCh chan *resolverUpdate + done chan struct{} + + mu sync.Mutex + subConns map[*acBalancerWrapper]struct{} +} + +func newCCBalancerWrapper(cc *ClientConn, b balancer.Builder, bopts balancer.BuildOptions) *ccBalancerWrapper { + ccb := &ccBalancerWrapper{ + cc: cc, + stateChangeQueue: newSCStateUpdateBuffer(), + resolverUpdateCh: make(chan *resolverUpdate, 1), + done: make(chan struct{}), + subConns: make(map[*acBalancerWrapper]struct{}), + } + go ccb.watcher() + ccb.balancer = b.Build(ccb, bopts) + return ccb +} + +// watcher balancer functions sequentially, so the balancer can be implemented +// lock-free. +func (ccb *ccBalancerWrapper) watcher() { + for { + select { + case t := <-ccb.stateChangeQueue.get(): + ccb.stateChangeQueue.load() + select { + case <-ccb.done: + ccb.balancer.Close() + return + default: + } + ccb.balancer.HandleSubConnStateChange(t.sc, t.state) + case t := <-ccb.resolverUpdateCh: + select { + case <-ccb.done: + ccb.balancer.Close() + return + default: + } + ccb.balancer.HandleResolvedAddrs(t.addrs, t.err) + case <-ccb.done: + } + + select { + case <-ccb.done: + ccb.balancer.Close() + ccb.mu.Lock() + scs := ccb.subConns + ccb.subConns = nil + ccb.mu.Unlock() + for acbw := range scs { + ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain) + } + return + default: + } + } +} + +func (ccb *ccBalancerWrapper) close() { + close(ccb.done) +} + +func (ccb *ccBalancerWrapper) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + // When updating addresses for a SubConn, if the address in use is not in + // the new addresses, the old ac will be tearDown() and a new ac will be + // created. tearDown() generates a state change with Shutdown state, we + // don't want the balancer to receive this state change. So before + // tearDown() on the old ac, ac.acbw (acWrapper) will be set to nil, and + // this function will be called with (nil, Shutdown). We don't need to call + // balancer method in this case. + if sc == nil { + return + } + ccb.stateChangeQueue.put(&scStateUpdate{ + sc: sc, + state: s, + }) +} + +func (ccb *ccBalancerWrapper) handleResolvedAddrs(addrs []resolver.Address, err error) { + select { + case <-ccb.resolverUpdateCh: + default: + } + ccb.resolverUpdateCh <- &resolverUpdate{ + addrs: addrs, + err: err, + } +} + +func (ccb *ccBalancerWrapper) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { + if len(addrs) <= 0 { + return nil, fmt.Errorf("grpc: cannot create SubConn with empty address list") + } + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return nil, fmt.Errorf("grpc: ClientConn balancer wrapper was closed") + } + ac, err := ccb.cc.newAddrConn(addrs, opts) + if err != nil { + return nil, err + } + acbw := &acBalancerWrapper{ac: ac} + acbw.ac.mu.Lock() + ac.acbw = acbw + acbw.ac.mu.Unlock() + ccb.subConns[acbw] = struct{}{} + return acbw, nil +} + +func (ccb *ccBalancerWrapper) RemoveSubConn(sc balancer.SubConn) { + acbw, ok := sc.(*acBalancerWrapper) + if !ok { + return + } + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return + } + delete(ccb.subConns, acbw) + ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain) +} + +func (ccb *ccBalancerWrapper) UpdateBalancerState(s connectivity.State, p balancer.Picker) { + ccb.mu.Lock() + defer ccb.mu.Unlock() + if ccb.subConns == nil { + return + } + // Update picker before updating state. Even though the ordering here does + // not matter, it can lead to multiple calls of Pick in the common start-up + // case where we wait for ready and then perform an RPC. If the picker is + // updated later, we could call the "connecting" picker when the state is + // updated, and then call the "ready" picker after the picker gets updated. + ccb.cc.blockingpicker.updatePicker(p) + ccb.cc.csMgr.updateState(s) +} + +func (ccb *ccBalancerWrapper) ResolveNow(o resolver.ResolveNowOption) { + ccb.cc.resolveNow(o) +} + +func (ccb *ccBalancerWrapper) Target() string { + return ccb.cc.target +} + +// acBalancerWrapper is a wrapper on top of ac for balancers. +// It implements balancer.SubConn interface. +type acBalancerWrapper struct { + mu sync.Mutex + ac *addrConn +} + +func (acbw *acBalancerWrapper) UpdateAddresses(addrs []resolver.Address) { + acbw.mu.Lock() + defer acbw.mu.Unlock() + if len(addrs) <= 0 { + acbw.ac.tearDown(errConnDrain) + return + } + if !acbw.ac.tryUpdateAddrs(addrs) { + cc := acbw.ac.cc + opts := acbw.ac.scopts + acbw.ac.mu.Lock() + // Set old ac.acbw to nil so the Shutdown state update will be ignored + // by balancer. + // + // TODO(bar) the state transition could be wrong when tearDown() old ac + // and creating new ac, fix the transition. + acbw.ac.acbw = nil + acbw.ac.mu.Unlock() + acState := acbw.ac.getState() + acbw.ac.tearDown(errConnDrain) + + if acState == connectivity.Shutdown { + return + } + + ac, err := cc.newAddrConn(addrs, opts) + if err != nil { + grpclog.Warningf("acBalancerWrapper: UpdateAddresses: failed to newAddrConn: %v", err) + return + } + acbw.ac = ac + ac.mu.Lock() + ac.acbw = acbw + ac.mu.Unlock() + if acState != connectivity.Idle { + ac.connect() + } + } +} + +func (acbw *acBalancerWrapper) Connect() { + acbw.mu.Lock() + defer acbw.mu.Unlock() + acbw.ac.connect() +} + +func (acbw *acBalancerWrapper) getAddrConn() *addrConn { + acbw.mu.Lock() + defer acbw.mu.Unlock() + return acbw.ac +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go new file mode 100644 index 00000000..ca07c154 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/balancer_v1_wrapper.go @@ -0,0 +1,328 @@ +/* + * + * 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 grpc + +import ( + "context" + "strings" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" + "google.golang.org/grpc/status" +) + +type balancerWrapperBuilder struct { + b Balancer // The v1 balancer. +} + +func (bwb *balancerWrapperBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { + targetAddr := cc.Target() + targetSplitted := strings.Split(targetAddr, ":///") + if len(targetSplitted) >= 2 { + targetAddr = targetSplitted[1] + } + + bwb.b.Start(targetAddr, BalancerConfig{ + DialCreds: opts.DialCreds, + Dialer: opts.Dialer, + }) + _, pickfirst := bwb.b.(*pickFirst) + bw := &balancerWrapper{ + balancer: bwb.b, + pickfirst: pickfirst, + cc: cc, + targetAddr: targetAddr, + startCh: make(chan struct{}), + conns: make(map[resolver.Address]balancer.SubConn), + connSt: make(map[balancer.SubConn]*scState), + csEvltr: &balancer.ConnectivityStateEvaluator{}, + state: connectivity.Idle, + } + cc.UpdateBalancerState(connectivity.Idle, bw) + go bw.lbWatcher() + return bw +} + +func (bwb *balancerWrapperBuilder) Name() string { + return "wrapper" +} + +type scState struct { + addr Address // The v1 address type. + s connectivity.State + down func(error) +} + +type balancerWrapper struct { + balancer Balancer // The v1 balancer. + pickfirst bool + + cc balancer.ClientConn + targetAddr string // Target without the scheme. + + mu sync.Mutex + conns map[resolver.Address]balancer.SubConn + connSt map[balancer.SubConn]*scState + // This channel is closed when handling the first resolver result. + // lbWatcher blocks until this is closed, to avoid race between + // - NewSubConn is created, cc wants to notify balancer of state changes; + // - Build hasn't return, cc doesn't have access to balancer. + startCh chan struct{} + + // To aggregate the connectivity state. + csEvltr *balancer.ConnectivityStateEvaluator + state connectivity.State +} + +// lbWatcher watches the Notify channel of the balancer and manages +// connections accordingly. +func (bw *balancerWrapper) lbWatcher() { + <-bw.startCh + notifyCh := bw.balancer.Notify() + if notifyCh == nil { + // There's no resolver in the balancer. Connect directly. + a := resolver.Address{ + Addr: bw.targetAddr, + Type: resolver.Backend, + } + sc, err := bw.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", a, err) + } else { + bw.mu.Lock() + bw.conns[a] = sc + bw.connSt[sc] = &scState{ + addr: Address{Addr: bw.targetAddr}, + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + return + } + + for addrs := range notifyCh { + grpclog.Infof("balancerWrapper: got update addr from Notify: %v\n", addrs) + if bw.pickfirst { + var ( + oldA resolver.Address + oldSC balancer.SubConn + ) + bw.mu.Lock() + for oldA, oldSC = range bw.conns { + break + } + bw.mu.Unlock() + if len(addrs) <= 0 { + if oldSC != nil { + // Teardown old sc. + bw.mu.Lock() + delete(bw.conns, oldA) + delete(bw.connSt, oldSC) + bw.mu.Unlock() + bw.cc.RemoveSubConn(oldSC) + } + continue + } + + var newAddrs []resolver.Address + for _, a := range addrs { + newAddr := resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, // All addresses from balancer are all backends. + ServerName: "", + Metadata: a.Metadata, + } + newAddrs = append(newAddrs, newAddr) + } + if oldSC == nil { + // Create new sc. + sc, err := bw.cc.NewSubConn(newAddrs, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", newAddrs, err) + } else { + bw.mu.Lock() + // For pickfirst, there should be only one SubConn, so the + // address doesn't matter. All states updating (up and down) + // and picking should all happen on that only SubConn. + bw.conns[resolver.Address{}] = sc + bw.connSt[sc] = &scState{ + addr: addrs[0], // Use the first address. + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + } else { + bw.mu.Lock() + bw.connSt[oldSC].addr = addrs[0] + bw.mu.Unlock() + oldSC.UpdateAddresses(newAddrs) + } + } else { + var ( + add []resolver.Address // Addresses need to setup connections. + del []balancer.SubConn // Connections need to tear down. + ) + resAddrs := make(map[resolver.Address]Address) + for _, a := range addrs { + resAddrs[resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, // All addresses from balancer are all backends. + ServerName: "", + Metadata: a.Metadata, + }] = a + } + bw.mu.Lock() + for a := range resAddrs { + if _, ok := bw.conns[a]; !ok { + add = append(add, a) + } + } + for a, c := range bw.conns { + if _, ok := resAddrs[a]; !ok { + del = append(del, c) + delete(bw.conns, a) + // Keep the state of this sc in bw.connSt until its state becomes Shutdown. + } + } + bw.mu.Unlock() + for _, a := range add { + sc, err := bw.cc.NewSubConn([]resolver.Address{a}, balancer.NewSubConnOptions{}) + if err != nil { + grpclog.Warningf("Error creating connection to %v. Err: %v", a, err) + } else { + bw.mu.Lock() + bw.conns[a] = sc + bw.connSt[sc] = &scState{ + addr: resAddrs[a], + s: connectivity.Idle, + } + bw.mu.Unlock() + sc.Connect() + } + } + for _, c := range del { + bw.cc.RemoveSubConn(c) + } + } + } +} + +func (bw *balancerWrapper) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + bw.mu.Lock() + defer bw.mu.Unlock() + scSt, ok := bw.connSt[sc] + if !ok { + return + } + if s == connectivity.Idle { + sc.Connect() + } + oldS := scSt.s + scSt.s = s + if oldS != connectivity.Ready && s == connectivity.Ready { + scSt.down = bw.balancer.Up(scSt.addr) + } else if oldS == connectivity.Ready && s != connectivity.Ready { + if scSt.down != nil { + scSt.down(errConnClosing) + } + } + sa := bw.csEvltr.RecordTransition(oldS, s) + if bw.state != sa { + bw.state = sa + } + bw.cc.UpdateBalancerState(bw.state, bw) + if s == connectivity.Shutdown { + // Remove state for this sc. + delete(bw.connSt, sc) + } +} + +func (bw *balancerWrapper) HandleResolvedAddrs([]resolver.Address, error) { + bw.mu.Lock() + defer bw.mu.Unlock() + select { + case <-bw.startCh: + default: + close(bw.startCh) + } + // There should be a resolver inside the balancer. + // All updates here, if any, are ignored. +} + +func (bw *balancerWrapper) Close() { + bw.mu.Lock() + defer bw.mu.Unlock() + select { + case <-bw.startCh: + default: + close(bw.startCh) + } + bw.balancer.Close() +} + +// The picker is the balancerWrapper itself. +// Pick should never return ErrNoSubConnAvailable. +// It either blocks or returns error, consistent with v1 balancer Get(). +func (bw *balancerWrapper) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + failfast := true // Default failfast is true. + if ss, ok := rpcInfoFromContext(ctx); ok { + failfast = ss.failfast + } + a, p, err := bw.balancer.Get(ctx, BalancerGetOptions{BlockingWait: !failfast}) + if err != nil { + return nil, nil, err + } + var done func(balancer.DoneInfo) + if p != nil { + done = func(i balancer.DoneInfo) { p() } + } + var sc balancer.SubConn + bw.mu.Lock() + defer bw.mu.Unlock() + if bw.pickfirst { + // Get the first sc in conns. + for _, sc = range bw.conns { + break + } + } else { + var ok bool + sc, ok = bw.conns[resolver.Address{ + Addr: a.Addr, + Type: resolver.Backend, + ServerName: "", + Metadata: a.Metadata, + }] + if !ok && failfast { + return nil, nil, status.Errorf(codes.Unavailable, "there is no connection available") + } + if s, ok := bw.connSt[sc]; failfast && (!ok || s.s != connectivity.Ready) { + // If the returned sc is not ready and RPC is failfast, + // return error, and this RPC will fail. + return nil, nil, status.Errorf(codes.Unavailable, "there is no connection available") + } + } + + return sc, done, nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go new file mode 100644 index 00000000..f393bb66 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go @@ -0,0 +1,900 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: grpc/binarylog/grpc_binarylog_v1/binarylog.proto + +package grpc_binarylog_v1 // import "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import duration "github.com/golang/protobuf/ptypes/duration" +import timestamp "github.com/golang/protobuf/ptypes/timestamp" + +// 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.ProtoPackageIsVersion2 // please upgrade the proto package + +// Enumerates the type of event +// Note the terminology is different from the RPC semantics +// definition, but the same meaning is expressed here. +type GrpcLogEntry_EventType int32 + +const ( + GrpcLogEntry_EVENT_TYPE_UNKNOWN GrpcLogEntry_EventType = 0 + // Header sent from client to server + GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER GrpcLogEntry_EventType = 1 + // Header sent from server to client + GrpcLogEntry_EVENT_TYPE_SERVER_HEADER GrpcLogEntry_EventType = 2 + // Message sent from client to server + GrpcLogEntry_EVENT_TYPE_CLIENT_MESSAGE GrpcLogEntry_EventType = 3 + // Message sent from server to client + GrpcLogEntry_EVENT_TYPE_SERVER_MESSAGE GrpcLogEntry_EventType = 4 + // A signal that client is done sending + GrpcLogEntry_EVENT_TYPE_CLIENT_HALF_CLOSE GrpcLogEntry_EventType = 5 + // Trailer indicates the end of the RPC. + // On client side, this event means a trailer was either received + // from the network or the gRPC library locally generated a status + // to inform the application about a failure. + // On server side, this event means the server application requested + // to send a trailer. Note: EVENT_TYPE_CANCEL may still arrive after + // this due to races on server side. + GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER GrpcLogEntry_EventType = 6 + // A signal that the RPC is cancelled. On client side, this + // indicates the client application requests a cancellation. + // On server side, this indicates that cancellation was detected. + // Note: This marks the end of the RPC. Events may arrive after + // this due to races. For example, on client side a trailer + // may arrive even though the application requested to cancel the RPC. + GrpcLogEntry_EVENT_TYPE_CANCEL GrpcLogEntry_EventType = 7 +) + +var GrpcLogEntry_EventType_name = map[int32]string{ + 0: "EVENT_TYPE_UNKNOWN", + 1: "EVENT_TYPE_CLIENT_HEADER", + 2: "EVENT_TYPE_SERVER_HEADER", + 3: "EVENT_TYPE_CLIENT_MESSAGE", + 4: "EVENT_TYPE_SERVER_MESSAGE", + 5: "EVENT_TYPE_CLIENT_HALF_CLOSE", + 6: "EVENT_TYPE_SERVER_TRAILER", + 7: "EVENT_TYPE_CANCEL", +} +var GrpcLogEntry_EventType_value = map[string]int32{ + "EVENT_TYPE_UNKNOWN": 0, + "EVENT_TYPE_CLIENT_HEADER": 1, + "EVENT_TYPE_SERVER_HEADER": 2, + "EVENT_TYPE_CLIENT_MESSAGE": 3, + "EVENT_TYPE_SERVER_MESSAGE": 4, + "EVENT_TYPE_CLIENT_HALF_CLOSE": 5, + "EVENT_TYPE_SERVER_TRAILER": 6, + "EVENT_TYPE_CANCEL": 7, +} + +func (x GrpcLogEntry_EventType) String() string { + return proto.EnumName(GrpcLogEntry_EventType_name, int32(x)) +} +func (GrpcLogEntry_EventType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0, 0} +} + +// Enumerates the entity that generates the log entry +type GrpcLogEntry_Logger int32 + +const ( + GrpcLogEntry_LOGGER_UNKNOWN GrpcLogEntry_Logger = 0 + GrpcLogEntry_LOGGER_CLIENT GrpcLogEntry_Logger = 1 + GrpcLogEntry_LOGGER_SERVER GrpcLogEntry_Logger = 2 +) + +var GrpcLogEntry_Logger_name = map[int32]string{ + 0: "LOGGER_UNKNOWN", + 1: "LOGGER_CLIENT", + 2: "LOGGER_SERVER", +} +var GrpcLogEntry_Logger_value = map[string]int32{ + "LOGGER_UNKNOWN": 0, + "LOGGER_CLIENT": 1, + "LOGGER_SERVER": 2, +} + +func (x GrpcLogEntry_Logger) String() string { + return proto.EnumName(GrpcLogEntry_Logger_name, int32(x)) +} +func (GrpcLogEntry_Logger) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0, 1} +} + +type Address_Type int32 + +const ( + Address_TYPE_UNKNOWN Address_Type = 0 + // address is in 1.2.3.4 form + Address_TYPE_IPV4 Address_Type = 1 + // address is in IPv6 canonical form (RFC5952 section 4) + // The scope is NOT included in the address string. + Address_TYPE_IPV6 Address_Type = 2 + // address is UDS string + Address_TYPE_UNIX Address_Type = 3 +) + +var Address_Type_name = map[int32]string{ + 0: "TYPE_UNKNOWN", + 1: "TYPE_IPV4", + 2: "TYPE_IPV6", + 3: "TYPE_UNIX", +} +var Address_Type_value = map[string]int32{ + "TYPE_UNKNOWN": 0, + "TYPE_IPV4": 1, + "TYPE_IPV6": 2, + "TYPE_UNIX": 3, +} + +func (x Address_Type) String() string { + return proto.EnumName(Address_Type_name, int32(x)) +} +func (Address_Type) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{7, 0} +} + +// Log entry we store in binary logs +type GrpcLogEntry struct { + // The timestamp of the binary log message + Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + // Uniquely identifies a call. The value must not be 0 in order to disambiguate + // from an unset value. + // Each call may have several log entries, they will all have the same call_id. + // Nothing is guaranteed about their value other than they are unique across + // different RPCs in the same gRPC process. + CallId uint64 `protobuf:"varint,2,opt,name=call_id,json=callId,proto3" json:"call_id,omitempty"` + // The entry sequence id for this call. The first GrpcLogEntry has a + // value of 1, to disambiguate from an unset value. The purpose of + // this field is to detect missing entries in environments where + // durability or ordering is not guaranteed. + SequenceIdWithinCall uint64 `protobuf:"varint,3,opt,name=sequence_id_within_call,json=sequenceIdWithinCall,proto3" json:"sequence_id_within_call,omitempty"` + Type GrpcLogEntry_EventType `protobuf:"varint,4,opt,name=type,proto3,enum=grpc.binarylog.v1.GrpcLogEntry_EventType" json:"type,omitempty"` + Logger GrpcLogEntry_Logger `protobuf:"varint,5,opt,name=logger,proto3,enum=grpc.binarylog.v1.GrpcLogEntry_Logger" json:"logger,omitempty"` + // The logger uses one of the following fields to record the payload, + // according to the type of the log entry. + // + // Types that are valid to be assigned to Payload: + // *GrpcLogEntry_ClientHeader + // *GrpcLogEntry_ServerHeader + // *GrpcLogEntry_Message + // *GrpcLogEntry_Trailer + Payload isGrpcLogEntry_Payload `protobuf_oneof:"payload"` + // true if payload does not represent the full message or metadata. + PayloadTruncated bool `protobuf:"varint,10,opt,name=payload_truncated,json=payloadTruncated,proto3" json:"payload_truncated,omitempty"` + // Peer address information, will only be recorded on the first + // incoming event. On client side, peer is logged on + // EVENT_TYPE_SERVER_HEADER normally or EVENT_TYPE_SERVER_TRAILER in + // the case of trailers-only. On server side, peer is always + // logged on EVENT_TYPE_CLIENT_HEADER. + Peer *Address `protobuf:"bytes,11,opt,name=peer,proto3" json:"peer,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GrpcLogEntry) Reset() { *m = GrpcLogEntry{} } +func (m *GrpcLogEntry) String() string { return proto.CompactTextString(m) } +func (*GrpcLogEntry) ProtoMessage() {} +func (*GrpcLogEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{0} +} +func (m *GrpcLogEntry) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GrpcLogEntry.Unmarshal(m, b) +} +func (m *GrpcLogEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GrpcLogEntry.Marshal(b, m, deterministic) +} +func (dst *GrpcLogEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrpcLogEntry.Merge(dst, src) +} +func (m *GrpcLogEntry) XXX_Size() int { + return xxx_messageInfo_GrpcLogEntry.Size(m) +} +func (m *GrpcLogEntry) XXX_DiscardUnknown() { + xxx_messageInfo_GrpcLogEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_GrpcLogEntry proto.InternalMessageInfo + +func (m *GrpcLogEntry) GetTimestamp() *timestamp.Timestamp { + if m != nil { + return m.Timestamp + } + return nil +} + +func (m *GrpcLogEntry) GetCallId() uint64 { + if m != nil { + return m.CallId + } + return 0 +} + +func (m *GrpcLogEntry) GetSequenceIdWithinCall() uint64 { + if m != nil { + return m.SequenceIdWithinCall + } + return 0 +} + +func (m *GrpcLogEntry) GetType() GrpcLogEntry_EventType { + if m != nil { + return m.Type + } + return GrpcLogEntry_EVENT_TYPE_UNKNOWN +} + +func (m *GrpcLogEntry) GetLogger() GrpcLogEntry_Logger { + if m != nil { + return m.Logger + } + return GrpcLogEntry_LOGGER_UNKNOWN +} + +type isGrpcLogEntry_Payload interface { + isGrpcLogEntry_Payload() +} + +type GrpcLogEntry_ClientHeader struct { + ClientHeader *ClientHeader `protobuf:"bytes,6,opt,name=client_header,json=clientHeader,proto3,oneof"` +} + +type GrpcLogEntry_ServerHeader struct { + ServerHeader *ServerHeader `protobuf:"bytes,7,opt,name=server_header,json=serverHeader,proto3,oneof"` +} + +type GrpcLogEntry_Message struct { + Message *Message `protobuf:"bytes,8,opt,name=message,proto3,oneof"` +} + +type GrpcLogEntry_Trailer struct { + Trailer *Trailer `protobuf:"bytes,9,opt,name=trailer,proto3,oneof"` +} + +func (*GrpcLogEntry_ClientHeader) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_ServerHeader) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_Message) isGrpcLogEntry_Payload() {} + +func (*GrpcLogEntry_Trailer) isGrpcLogEntry_Payload() {} + +func (m *GrpcLogEntry) GetPayload() isGrpcLogEntry_Payload { + if m != nil { + return m.Payload + } + return nil +} + +func (m *GrpcLogEntry) GetClientHeader() *ClientHeader { + if x, ok := m.GetPayload().(*GrpcLogEntry_ClientHeader); ok { + return x.ClientHeader + } + return nil +} + +func (m *GrpcLogEntry) GetServerHeader() *ServerHeader { + if x, ok := m.GetPayload().(*GrpcLogEntry_ServerHeader); ok { + return x.ServerHeader + } + return nil +} + +func (m *GrpcLogEntry) GetMessage() *Message { + if x, ok := m.GetPayload().(*GrpcLogEntry_Message); ok { + return x.Message + } + return nil +} + +func (m *GrpcLogEntry) GetTrailer() *Trailer { + if x, ok := m.GetPayload().(*GrpcLogEntry_Trailer); ok { + return x.Trailer + } + return nil +} + +func (m *GrpcLogEntry) GetPayloadTruncated() bool { + if m != nil { + return m.PayloadTruncated + } + return false +} + +func (m *GrpcLogEntry) GetPeer() *Address { + if m != nil { + return m.Peer + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*GrpcLogEntry) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _GrpcLogEntry_OneofMarshaler, _GrpcLogEntry_OneofUnmarshaler, _GrpcLogEntry_OneofSizer, []interface{}{ + (*GrpcLogEntry_ClientHeader)(nil), + (*GrpcLogEntry_ServerHeader)(nil), + (*GrpcLogEntry_Message)(nil), + (*GrpcLogEntry_Trailer)(nil), + } +} + +func _GrpcLogEntry_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*GrpcLogEntry) + // payload + switch x := m.Payload.(type) { + case *GrpcLogEntry_ClientHeader: + b.EncodeVarint(6<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.ClientHeader); err != nil { + return err + } + case *GrpcLogEntry_ServerHeader: + b.EncodeVarint(7<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.ServerHeader); err != nil { + return err + } + case *GrpcLogEntry_Message: + b.EncodeVarint(8<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Message); err != nil { + return err + } + case *GrpcLogEntry_Trailer: + b.EncodeVarint(9<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Trailer); err != nil { + return err + } + case nil: + default: + return fmt.Errorf("GrpcLogEntry.Payload has unexpected type %T", x) + } + return nil +} + +func _GrpcLogEntry_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*GrpcLogEntry) + switch tag { + case 6: // payload.client_header + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ClientHeader) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_ClientHeader{msg} + return true, err + case 7: // payload.server_header + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ServerHeader) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_ServerHeader{msg} + return true, err + case 8: // payload.message + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Message) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_Message{msg} + return true, err + case 9: // payload.trailer + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Trailer) + err := b.DecodeMessage(msg) + m.Payload = &GrpcLogEntry_Trailer{msg} + return true, err + default: + return false, nil + } +} + +func _GrpcLogEntry_OneofSizer(msg proto.Message) (n int) { + m := msg.(*GrpcLogEntry) + // payload + switch x := m.Payload.(type) { + case *GrpcLogEntry_ClientHeader: + s := proto.Size(x.ClientHeader) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_ServerHeader: + s := proto.Size(x.ServerHeader) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_Message: + s := proto.Size(x.Message) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *GrpcLogEntry_Trailer: + s := proto.Size(x.Trailer) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type ClientHeader struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + // The name of the RPC method, which looks something like: + // // + // Note the leading "/" character. + MethodName string `protobuf:"bytes,2,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` + // A single process may be used to run multiple virtual + // servers with different identities. + // The authority is the name of such a server identitiy. + // It is typically a portion of the URI in the form of + // or : . + Authority string `protobuf:"bytes,3,opt,name=authority,proto3" json:"authority,omitempty"` + // the RPC timeout + Timeout *duration.Duration `protobuf:"bytes,4,opt,name=timeout,proto3" json:"timeout,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ClientHeader) Reset() { *m = ClientHeader{} } +func (m *ClientHeader) String() string { return proto.CompactTextString(m) } +func (*ClientHeader) ProtoMessage() {} +func (*ClientHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{1} +} +func (m *ClientHeader) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ClientHeader.Unmarshal(m, b) +} +func (m *ClientHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ClientHeader.Marshal(b, m, deterministic) +} +func (dst *ClientHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientHeader.Merge(dst, src) +} +func (m *ClientHeader) XXX_Size() int { + return xxx_messageInfo_ClientHeader.Size(m) +} +func (m *ClientHeader) XXX_DiscardUnknown() { + xxx_messageInfo_ClientHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientHeader proto.InternalMessageInfo + +func (m *ClientHeader) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *ClientHeader) GetMethodName() string { + if m != nil { + return m.MethodName + } + return "" +} + +func (m *ClientHeader) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *ClientHeader) GetTimeout() *duration.Duration { + if m != nil { + return m.Timeout + } + return nil +} + +type ServerHeader struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerHeader) Reset() { *m = ServerHeader{} } +func (m *ServerHeader) String() string { return proto.CompactTextString(m) } +func (*ServerHeader) ProtoMessage() {} +func (*ServerHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{2} +} +func (m *ServerHeader) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerHeader.Unmarshal(m, b) +} +func (m *ServerHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerHeader.Marshal(b, m, deterministic) +} +func (dst *ServerHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerHeader.Merge(dst, src) +} +func (m *ServerHeader) XXX_Size() int { + return xxx_messageInfo_ServerHeader.Size(m) +} +func (m *ServerHeader) XXX_DiscardUnknown() { + xxx_messageInfo_ServerHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerHeader proto.InternalMessageInfo + +func (m *ServerHeader) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +type Trailer struct { + // This contains only the metadata from the application. + Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` + // The gRPC status code. + StatusCode uint32 `protobuf:"varint,2,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` + // An original status message before any transport specific + // encoding. + StatusMessage string `protobuf:"bytes,3,opt,name=status_message,json=statusMessage,proto3" json:"status_message,omitempty"` + // The value of the 'grpc-status-details-bin' metadata key. If + // present, this is always an encoded 'google.rpc.Status' message. + StatusDetails []byte `protobuf:"bytes,4,opt,name=status_details,json=statusDetails,proto3" json:"status_details,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Trailer) Reset() { *m = Trailer{} } +func (m *Trailer) String() string { return proto.CompactTextString(m) } +func (*Trailer) ProtoMessage() {} +func (*Trailer) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{3} +} +func (m *Trailer) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Trailer.Unmarshal(m, b) +} +func (m *Trailer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Trailer.Marshal(b, m, deterministic) +} +func (dst *Trailer) XXX_Merge(src proto.Message) { + xxx_messageInfo_Trailer.Merge(dst, src) +} +func (m *Trailer) XXX_Size() int { + return xxx_messageInfo_Trailer.Size(m) +} +func (m *Trailer) XXX_DiscardUnknown() { + xxx_messageInfo_Trailer.DiscardUnknown(m) +} + +var xxx_messageInfo_Trailer proto.InternalMessageInfo + +func (m *Trailer) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *Trailer) GetStatusCode() uint32 { + if m != nil { + return m.StatusCode + } + return 0 +} + +func (m *Trailer) GetStatusMessage() string { + if m != nil { + return m.StatusMessage + } + return "" +} + +func (m *Trailer) GetStatusDetails() []byte { + if m != nil { + return m.StatusDetails + } + return nil +} + +// Message payload, used by CLIENT_MESSAGE and SERVER_MESSAGE +type Message struct { + // Length of the message. It may not be the same as the length of the + // data field, as the logging payload can be truncated or omitted. + Length uint32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + // May be truncated or omitted. + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +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_binarylog_264c8c9c551ce911, []int{4} +} +func (m *Message) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Message.Unmarshal(m, b) +} +func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Message.Marshal(b, m, deterministic) +} +func (dst *Message) XXX_Merge(src proto.Message) { + xxx_messageInfo_Message.Merge(dst, src) +} +func (m *Message) XXX_Size() int { + return xxx_messageInfo_Message.Size(m) +} +func (m *Message) XXX_DiscardUnknown() { + xxx_messageInfo_Message.DiscardUnknown(m) +} + +var xxx_messageInfo_Message proto.InternalMessageInfo + +func (m *Message) GetLength() uint32 { + if m != nil { + return m.Length + } + return 0 +} + +func (m *Message) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +// A list of metadata pairs, used in the payload of client header, +// server header, and server trailer. +// Implementations may omit some entries to honor the header limits +// of GRPC_BINARY_LOG_CONFIG. +// +// Header keys added by gRPC are omitted. To be more specific, +// implementations will not log the following entries, and this is +// not to be treated as a truncation: +// - entries handled by grpc that are not user visible, such as those +// that begin with 'grpc-' (with exception of grpc-trace-bin) +// or keys like 'lb-token' +// - transport specific entries, including but not limited to: +// ':path', ':authority', 'content-encoding', 'user-agent', 'te', etc +// - entries added for call credentials +// +// Implementations must always log grpc-trace-bin if it is present. +// Practically speaking it will only be visible on server side because +// grpc-trace-bin is managed by low level client side mechanisms +// inaccessible from the application level. On server side, the +// header is just a normal metadata key. +// The pair will not count towards the size limit. +type Metadata struct { + Entry []*MetadataEntry `protobuf:"bytes,1,rep,name=entry,proto3" json:"entry,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Metadata) Reset() { *m = Metadata{} } +func (m *Metadata) String() string { return proto.CompactTextString(m) } +func (*Metadata) ProtoMessage() {} +func (*Metadata) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{5} +} +func (m *Metadata) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Metadata.Unmarshal(m, b) +} +func (m *Metadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Metadata.Marshal(b, m, deterministic) +} +func (dst *Metadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_Metadata.Merge(dst, src) +} +func (m *Metadata) XXX_Size() int { + return xxx_messageInfo_Metadata.Size(m) +} +func (m *Metadata) XXX_DiscardUnknown() { + xxx_messageInfo_Metadata.DiscardUnknown(m) +} + +var xxx_messageInfo_Metadata proto.InternalMessageInfo + +func (m *Metadata) GetEntry() []*MetadataEntry { + if m != nil { + return m.Entry + } + return nil +} + +// A metadata key value pair +type MetadataEntry struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + 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 *MetadataEntry) Reset() { *m = MetadataEntry{} } +func (m *MetadataEntry) String() string { return proto.CompactTextString(m) } +func (*MetadataEntry) ProtoMessage() {} +func (*MetadataEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{6} +} +func (m *MetadataEntry) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_MetadataEntry.Unmarshal(m, b) +} +func (m *MetadataEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_MetadataEntry.Marshal(b, m, deterministic) +} +func (dst *MetadataEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MetadataEntry.Merge(dst, src) +} +func (m *MetadataEntry) XXX_Size() int { + return xxx_messageInfo_MetadataEntry.Size(m) +} +func (m *MetadataEntry) XXX_DiscardUnknown() { + xxx_messageInfo_MetadataEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_MetadataEntry proto.InternalMessageInfo + +func (m *MetadataEntry) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *MetadataEntry) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +// Address information +type Address struct { + Type Address_Type `protobuf:"varint,1,opt,name=type,proto3,enum=grpc.binarylog.v1.Address_Type" json:"type,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // only for TYPE_IPV4 and TYPE_IPV6 + IpPort uint32 `protobuf:"varint,3,opt,name=ip_port,json=ipPort,proto3" json:"ip_port,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Address) Reset() { *m = Address{} } +func (m *Address) String() string { return proto.CompactTextString(m) } +func (*Address) ProtoMessage() {} +func (*Address) Descriptor() ([]byte, []int) { + return fileDescriptor_binarylog_264c8c9c551ce911, []int{7} +} +func (m *Address) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Address.Unmarshal(m, b) +} +func (m *Address) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Address.Marshal(b, m, deterministic) +} +func (dst *Address) XXX_Merge(src proto.Message) { + xxx_messageInfo_Address.Merge(dst, src) +} +func (m *Address) XXX_Size() int { + return xxx_messageInfo_Address.Size(m) +} +func (m *Address) XXX_DiscardUnknown() { + xxx_messageInfo_Address.DiscardUnknown(m) +} + +var xxx_messageInfo_Address proto.InternalMessageInfo + +func (m *Address) GetType() Address_Type { + if m != nil { + return m.Type + } + return Address_TYPE_UNKNOWN +} + +func (m *Address) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Address) GetIpPort() uint32 { + if m != nil { + return m.IpPort + } + return 0 +} + +func init() { + proto.RegisterType((*GrpcLogEntry)(nil), "grpc.binarylog.v1.GrpcLogEntry") + proto.RegisterType((*ClientHeader)(nil), "grpc.binarylog.v1.ClientHeader") + proto.RegisterType((*ServerHeader)(nil), "grpc.binarylog.v1.ServerHeader") + proto.RegisterType((*Trailer)(nil), "grpc.binarylog.v1.Trailer") + proto.RegisterType((*Message)(nil), "grpc.binarylog.v1.Message") + proto.RegisterType((*Metadata)(nil), "grpc.binarylog.v1.Metadata") + proto.RegisterType((*MetadataEntry)(nil), "grpc.binarylog.v1.MetadataEntry") + proto.RegisterType((*Address)(nil), "grpc.binarylog.v1.Address") + proto.RegisterEnum("grpc.binarylog.v1.GrpcLogEntry_EventType", GrpcLogEntry_EventType_name, GrpcLogEntry_EventType_value) + proto.RegisterEnum("grpc.binarylog.v1.GrpcLogEntry_Logger", GrpcLogEntry_Logger_name, GrpcLogEntry_Logger_value) + proto.RegisterEnum("grpc.binarylog.v1.Address_Type", Address_Type_name, Address_Type_value) +} + +func init() { + proto.RegisterFile("grpc/binarylog/grpc_binarylog_v1/binarylog.proto", fileDescriptor_binarylog_264c8c9c551ce911) +} + +var fileDescriptor_binarylog_264c8c9c551ce911 = []byte{ + // 900 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x51, 0x6f, 0xe3, 0x44, + 0x10, 0x3e, 0x37, 0x69, 0xdc, 0x4c, 0x92, 0xca, 0x5d, 0x95, 0x3b, 0x5f, 0x29, 0x34, 0xb2, 0x04, + 0x0a, 0x42, 0x72, 0xb9, 0x94, 0xeb, 0xf1, 0x02, 0x52, 0x92, 0xfa, 0xd2, 0x88, 0x5c, 0x1a, 0x6d, + 0x72, 0x3d, 0x40, 0x48, 0xd6, 0x36, 0x5e, 0x1c, 0x0b, 0xc7, 0x6b, 0xd6, 0x9b, 0xa0, 0xfc, 0x2c, + 0xde, 0x90, 0xee, 0x77, 0xf1, 0x8e, 0xbc, 0x6b, 0x27, 0xa6, 0x69, 0x0f, 0x09, 0xde, 0x3c, 0xdf, + 0x7c, 0xf3, 0xcd, 0xee, 0x78, 0x66, 0x16, 0xbe, 0xf2, 0x79, 0x3c, 0x3b, 0xbf, 0x0b, 0x22, 0xc2, + 0xd7, 0x21, 0xf3, 0xcf, 0x53, 0xd3, 0xdd, 0x98, 0xee, 0xea, 0xc5, 0xd6, 0x67, 0xc7, 0x9c, 0x09, + 0x86, 0x8e, 0x52, 0x8a, 0xbd, 0x45, 0x57, 0x2f, 0x4e, 0x3e, 0xf5, 0x19, 0xf3, 0x43, 0x7a, 0x2e, + 0x09, 0x77, 0xcb, 0x5f, 0xce, 0xbd, 0x25, 0x27, 0x22, 0x60, 0x91, 0x0a, 0x39, 0x39, 0xbb, 0xef, + 0x17, 0xc1, 0x82, 0x26, 0x82, 0x2c, 0x62, 0x45, 0xb0, 0xde, 0xeb, 0x50, 0xef, 0xf3, 0x78, 0x36, + 0x64, 0xbe, 0x13, 0x09, 0xbe, 0x46, 0xdf, 0x40, 0x75, 0xc3, 0x31, 0xb5, 0xa6, 0xd6, 0xaa, 0xb5, + 0x4f, 0x6c, 0xa5, 0x62, 0xe7, 0x2a, 0xf6, 0x34, 0x67, 0xe0, 0x2d, 0x19, 0x3d, 0x03, 0x7d, 0x46, + 0xc2, 0xd0, 0x0d, 0x3c, 0x73, 0xaf, 0xa9, 0xb5, 0xca, 0xb8, 0x92, 0x9a, 0x03, 0x0f, 0xbd, 0x84, + 0x67, 0x09, 0xfd, 0x6d, 0x49, 0xa3, 0x19, 0x75, 0x03, 0xcf, 0xfd, 0x3d, 0x10, 0xf3, 0x20, 0x72, + 0x53, 0xa7, 0x59, 0x92, 0xc4, 0xe3, 0xdc, 0x3d, 0xf0, 0xde, 0x49, 0x67, 0x8f, 0x84, 0x21, 0xfa, + 0x16, 0xca, 0x62, 0x1d, 0x53, 0xb3, 0xdc, 0xd4, 0x5a, 0x87, 0xed, 0x2f, 0xec, 0x9d, 0xdb, 0xdb, + 0xc5, 0x83, 0xdb, 0xce, 0x8a, 0x46, 0x62, 0xba, 0x8e, 0x29, 0x96, 0x61, 0xe8, 0x3b, 0xa8, 0x84, + 0xcc, 0xf7, 0x29, 0x37, 0xf7, 0xa5, 0xc0, 0xe7, 0xff, 0x26, 0x30, 0x94, 0x6c, 0x9c, 0x45, 0xa1, + 0xd7, 0xd0, 0x98, 0x85, 0x01, 0x8d, 0x84, 0x3b, 0xa7, 0xc4, 0xa3, 0xdc, 0xac, 0xc8, 0x62, 0x9c, + 0x3d, 0x20, 0xd3, 0x93, 0xbc, 0x6b, 0x49, 0xbb, 0x7e, 0x82, 0xeb, 0xb3, 0x82, 0x9d, 0xea, 0x24, + 0x94, 0xaf, 0x28, 0xcf, 0x75, 0xf4, 0x47, 0x75, 0x26, 0x92, 0xb7, 0xd5, 0x49, 0x0a, 0x36, 0xba, + 0x04, 0x7d, 0x41, 0x93, 0x84, 0xf8, 0xd4, 0x3c, 0xc8, 0x7f, 0xcb, 0x8e, 0xc2, 0x1b, 0xc5, 0xb8, + 0x7e, 0x82, 0x73, 0x72, 0x1a, 0x27, 0x38, 0x09, 0x42, 0xca, 0xcd, 0xea, 0xa3, 0x71, 0x53, 0xc5, + 0x48, 0xe3, 0x32, 0x32, 0xfa, 0x12, 0x8e, 0x62, 0xb2, 0x0e, 0x19, 0xf1, 0x5c, 0xc1, 0x97, 0xd1, + 0x8c, 0x08, 0xea, 0x99, 0xd0, 0xd4, 0x5a, 0x07, 0xd8, 0xc8, 0x1c, 0xd3, 0x1c, 0x47, 0x36, 0x94, + 0x63, 0x4a, 0xb9, 0x59, 0x7b, 0x34, 0x43, 0xc7, 0xf3, 0x38, 0x4d, 0x12, 0x2c, 0x79, 0xd6, 0x5f, + 0x1a, 0x54, 0x37, 0x3f, 0x0c, 0x3d, 0x05, 0xe4, 0xdc, 0x3a, 0xa3, 0xa9, 0x3b, 0xfd, 0x71, 0xec, + 0xb8, 0x6f, 0x47, 0xdf, 0x8f, 0x6e, 0xde, 0x8d, 0x8c, 0x27, 0xe8, 0x14, 0xcc, 0x02, 0xde, 0x1b, + 0x0e, 0xd2, 0xef, 0x6b, 0xa7, 0x73, 0xe5, 0x60, 0x43, 0xbb, 0xe7, 0x9d, 0x38, 0xf8, 0xd6, 0xc1, + 0xb9, 0x77, 0x0f, 0x7d, 0x02, 0xcf, 0x77, 0x63, 0xdf, 0x38, 0x93, 0x49, 0xa7, 0xef, 0x18, 0xa5, + 0x7b, 0xee, 0x2c, 0x38, 0x77, 0x97, 0x51, 0x13, 0x4e, 0x1f, 0xc8, 0xdc, 0x19, 0xbe, 0x76, 0x7b, + 0xc3, 0x9b, 0x89, 0x63, 0xec, 0x3f, 0x2c, 0x30, 0xc5, 0x9d, 0xc1, 0xd0, 0xc1, 0x46, 0x05, 0x7d, + 0x04, 0x47, 0x45, 0x81, 0xce, 0xa8, 0xe7, 0x0c, 0x0d, 0xdd, 0xea, 0x42, 0x45, 0xb5, 0x19, 0x42, + 0x70, 0x38, 0xbc, 0xe9, 0xf7, 0x1d, 0x5c, 0xb8, 0xef, 0x11, 0x34, 0x32, 0x4c, 0x65, 0x34, 0xb4, + 0x02, 0xa4, 0x52, 0x18, 0x7b, 0xdd, 0x2a, 0xe8, 0x59, 0xfd, 0xad, 0xf7, 0x1a, 0xd4, 0x8b, 0xcd, + 0x87, 0x5e, 0xc1, 0xc1, 0x82, 0x0a, 0xe2, 0x11, 0x41, 0xb2, 0xe1, 0xfd, 0xf8, 0xc1, 0x2e, 0x51, + 0x14, 0xbc, 0x21, 0xa3, 0x33, 0xa8, 0x2d, 0xa8, 0x98, 0x33, 0xcf, 0x8d, 0xc8, 0x82, 0xca, 0x01, + 0xae, 0x62, 0x50, 0xd0, 0x88, 0x2c, 0x28, 0x3a, 0x85, 0x2a, 0x59, 0x8a, 0x39, 0xe3, 0x81, 0x58, + 0xcb, 0xb1, 0xad, 0xe2, 0x2d, 0x80, 0x2e, 0x40, 0x4f, 0x17, 0x01, 0x5b, 0x0a, 0x39, 0xae, 0xb5, + 0xf6, 0xf3, 0x9d, 0x9d, 0x71, 0x95, 0x6d, 0x26, 0x9c, 0x33, 0xad, 0x3e, 0xd4, 0x8b, 0x1d, 0xff, + 0x9f, 0x0f, 0x6f, 0xfd, 0xa1, 0x81, 0x9e, 0x75, 0xf0, 0xff, 0xaa, 0x40, 0x22, 0x88, 0x58, 0x26, + 0xee, 0x8c, 0x79, 0xaa, 0x02, 0x0d, 0x0c, 0x0a, 0xea, 0x31, 0x8f, 0xa2, 0xcf, 0xe0, 0x30, 0x23, + 0xe4, 0x73, 0xa8, 0xca, 0xd0, 0x50, 0x68, 0x36, 0x7a, 0x05, 0x9a, 0x47, 0x05, 0x09, 0xc2, 0x44, + 0x56, 0xa4, 0x9e, 0xd3, 0xae, 0x14, 0x68, 0xbd, 0x04, 0x3d, 0x8f, 0x78, 0x0a, 0x95, 0x90, 0x46, + 0xbe, 0x98, 0xcb, 0x03, 0x37, 0x70, 0x66, 0x21, 0x04, 0x65, 0x79, 0x8d, 0x3d, 0x19, 0x2f, 0xbf, + 0xad, 0x2e, 0x1c, 0xe4, 0x67, 0x47, 0x97, 0xb0, 0x4f, 0xd3, 0xcd, 0x65, 0x6a, 0xcd, 0x52, 0xab, + 0xd6, 0x6e, 0x7e, 0xe0, 0x9e, 0x72, 0xc3, 0x61, 0x45, 0xb7, 0x5e, 0x41, 0xe3, 0x1f, 0x38, 0x32, + 0xa0, 0xf4, 0x2b, 0x5d, 0xcb, 0xec, 0x55, 0x9c, 0x7e, 0xa2, 0x63, 0xd8, 0x5f, 0x91, 0x70, 0x49, + 0xb3, 0xdc, 0xca, 0xb0, 0xfe, 0xd4, 0x40, 0xcf, 0xe6, 0x18, 0x5d, 0x64, 0xdb, 0x59, 0x93, 0xcb, + 0xf5, 0xec, 0xf1, 0x89, 0xb7, 0x0b, 0x3b, 0xd9, 0x04, 0x9d, 0x28, 0x34, 0xeb, 0xb0, 0xdc, 0x4c, + 0x1f, 0x8f, 0x20, 0x76, 0x63, 0xc6, 0x85, 0xac, 0x6a, 0x03, 0x57, 0x82, 0x78, 0xcc, 0xb8, 0xb0, + 0x1c, 0x28, 0xcb, 0x1d, 0x61, 0x40, 0xfd, 0xde, 0x76, 0x68, 0x40, 0x55, 0x22, 0x83, 0xf1, 0xed, + 0xd7, 0x86, 0x56, 0x34, 0x2f, 0x8d, 0xbd, 0x8d, 0xf9, 0x76, 0x34, 0xf8, 0xc1, 0x28, 0x75, 0x7f, + 0x86, 0xe3, 0x80, 0xed, 0x1e, 0xb2, 0x7b, 0xd8, 0x95, 0xd6, 0x90, 0xf9, 0xe3, 0xb4, 0x51, 0xc7, + 0xda, 0x4f, 0xed, 0xac, 0x71, 0x7d, 0x16, 0x92, 0xc8, 0xb7, 0x19, 0x57, 0x4f, 0xf3, 0x87, 0x5e, + 0xea, 0xbb, 0x8a, 0xec, 0xf2, 0x8b, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xf6, 0x4b, 0x50, + 0xd4, 0x07, 0x00, 0x00, +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go new file mode 100644 index 00000000..100f05dc --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/call.go @@ -0,0 +1,74 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" +) + +// Invoke sends the RPC request on the wire and returns after response is +// received. This is typically called by generated code. +// +// All errors returned by Invoke are compatible with the status package. +func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error { + // allow interceptor to see all applicable call options, which means those + // configured as defaults from dial option as well as per-call options + opts = combine(cc.dopts.callOptions, opts) + + if cc.dopts.unaryInt != nil { + return cc.dopts.unaryInt(ctx, method, args, reply, cc, invoke, opts...) + } + return invoke(ctx, method, args, reply, cc, opts...) +} + +func combine(o1 []CallOption, o2 []CallOption) []CallOption { + // we don't use append because o1 could have extra capacity whose + // elements would be overwritten, which could cause inadvertent + // sharing (and race connditions) between concurrent calls + if len(o1) == 0 { + return o2 + } else if len(o2) == 0 { + return o1 + } + ret := make([]CallOption, len(o1)+len(o2)) + copy(ret, o1) + copy(ret[len(o1):], o2) + return ret +} + +// Invoke sends the RPC request on the wire and returns after response is +// received. This is typically called by generated code. +// +// DEPRECATED: Use ClientConn.Invoke instead. +func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) error { + return cc.Invoke(ctx, method, args, reply, opts...) +} + +var unaryStreamDesc = &StreamDesc{ServerStreams: false, ClientStreams: false} + +func invoke(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error { + cs, err := newClientStream(ctx, unaryStreamDesc, cc, method, opts...) + if err != nil { + return err + } + if err := cs.SendMsg(req); err != nil { + return err + } + return cs.RecvMsg(reply) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go new file mode 100644 index 00000000..84b6dbe3 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/clientconn.go @@ -0,0 +1,1508 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "fmt" + "math" + "net" + "reflect" + "strings" + "sync" + "sync/atomic" + "time" + + "google.golang.org/grpc/balancer" + _ "google.golang.org/grpc/balancer/roundrobin" // To register roundrobin. + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/envconfig" + "google.golang.org/grpc/internal/grpcsync" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/resolver" + _ "google.golang.org/grpc/resolver/dns" // To register dns resolver. + _ "google.golang.org/grpc/resolver/passthrough" // To register passthrough resolver. + "google.golang.org/grpc/status" +) + +const ( + // minimum time to give a connection to complete + minConnectTimeout = 20 * time.Second + // must match grpclbName in grpclb/grpclb.go + grpclbName = "grpclb" +) + +var ( + // ErrClientConnClosing indicates that the operation is illegal because + // the ClientConn is closing. + // + // Deprecated: this error should not be relied upon by users; use the status + // code of Canceled instead. + ErrClientConnClosing = status.Error(codes.Canceled, "grpc: the client connection is closing") + // errConnDrain indicates that the connection starts to be drained and does not accept any new RPCs. + errConnDrain = errors.New("grpc: the connection is drained") + // errConnClosing indicates that the connection is closing. + errConnClosing = errors.New("grpc: the connection is closing") + // errBalancerClosed indicates that the balancer is closed. + errBalancerClosed = errors.New("grpc: balancer is closed") + // We use an accessor so that minConnectTimeout can be + // atomically read and updated while testing. + getMinConnectTimeout = func() time.Duration { + return minConnectTimeout + } +) + +// The following errors are returned from Dial and DialContext +var ( + // errNoTransportSecurity indicates that there is no transport security + // being set for ClientConn. Users should either set one or explicitly + // call WithInsecure DialOption to disable security. + errNoTransportSecurity = errors.New("grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)") + // errTransportCredsAndBundle indicates that creds bundle is used together + // with other individual Transport Credentials. + errTransportCredsAndBundle = errors.New("grpc: credentials.Bundle may not be used with individual TransportCredentials") + // errTransportCredentialsMissing indicates that users want to transmit security + // information (e.g., oauth2 token) which requires secure connection on an insecure + // connection. + errTransportCredentialsMissing = errors.New("grpc: the credentials require transport level security (use grpc.WithTransportCredentials() to set)") + // errCredentialsConflict indicates that grpc.WithTransportCredentials() + // and grpc.WithInsecure() are both called for a connection. + errCredentialsConflict = errors.New("grpc: transport credentials are set for an insecure connection (grpc.WithTransportCredentials() and grpc.WithInsecure() are both called)") +) + +const ( + defaultClientMaxReceiveMessageSize = 1024 * 1024 * 4 + defaultClientMaxSendMessageSize = math.MaxInt32 + // http2IOBufSize specifies the buffer size for sending frames. + defaultWriteBufSize = 32 * 1024 + defaultReadBufSize = 32 * 1024 +) + +// Dial creates a client connection to the given target. +func Dial(target string, opts ...DialOption) (*ClientConn, error) { + return DialContext(context.Background(), target, opts...) +} + +// DialContext creates a client connection to the given target. By default, it's +// a non-blocking dial (the function won't wait for connections to be +// established, and connecting happens in the background). To make it a blocking +// dial, use WithBlock() dial option. +// +// In the non-blocking case, the ctx does not act against the connection. It +// only controls the setup steps. +// +// In the blocking case, ctx can be used to cancel or expire the pending +// connection. Once this function returns, the cancellation and expiration of +// ctx will be noop. Users should call ClientConn.Close to terminate all the +// pending operations after this function returns. +// +// The target name syntax is defined in +// https://github.com/grpc/grpc/blob/master/doc/naming.md. +// e.g. to use dns resolver, a "dns:///" prefix should be applied to the target. +func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) { + cc := &ClientConn{ + target: target, + csMgr: &connectivityStateManager{}, + conns: make(map[*addrConn]struct{}), + dopts: defaultDialOptions(), + blockingpicker: newPickerWrapper(), + czData: new(channelzData), + firstResolveEvent: grpcsync.NewEvent(), + } + cc.retryThrottler.Store((*retryThrottler)(nil)) + cc.ctx, cc.cancel = context.WithCancel(context.Background()) + + for _, opt := range opts { + opt.apply(&cc.dopts) + } + + if channelz.IsOn() { + if cc.dopts.channelzParentID != 0 { + cc.channelzID = channelz.RegisterChannel(&channelzChannel{cc}, cc.dopts.channelzParentID, target) + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Channel Created", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Nested Channel(id:%d) created", cc.channelzID), + Severity: channelz.CtINFO, + }, + }) + } else { + cc.channelzID = channelz.RegisterChannel(&channelzChannel{cc}, 0, target) + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Channel Created", + Severity: channelz.CtINFO, + }) + } + cc.csMgr.channelzID = cc.channelzID + } + + if !cc.dopts.insecure { + if cc.dopts.copts.TransportCredentials == nil && cc.dopts.copts.CredsBundle == nil { + return nil, errNoTransportSecurity + } + if cc.dopts.copts.TransportCredentials != nil && cc.dopts.copts.CredsBundle != nil { + return nil, errTransportCredsAndBundle + } + } else { + if cc.dopts.copts.TransportCredentials != nil || cc.dopts.copts.CredsBundle != nil { + return nil, errCredentialsConflict + } + for _, cd := range cc.dopts.copts.PerRPCCredentials { + if cd.RequireTransportSecurity() { + return nil, errTransportCredentialsMissing + } + } + } + + cc.mkp = cc.dopts.copts.KeepaliveParams + + if cc.dopts.copts.Dialer == nil { + cc.dopts.copts.Dialer = newProxyDialer( + func(ctx context.Context, addr string) (net.Conn, error) { + network, addr := parseDialTarget(addr) + return (&net.Dialer{}).DialContext(ctx, network, addr) + }, + ) + } + + if cc.dopts.copts.UserAgent != "" { + cc.dopts.copts.UserAgent += " " + grpcUA + } else { + cc.dopts.copts.UserAgent = grpcUA + } + + if cc.dopts.timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, cc.dopts.timeout) + defer cancel() + } + + defer func() { + select { + case <-ctx.Done(): + conn, err = nil, ctx.Err() + default: + } + + if err != nil { + cc.Close() + } + }() + + scSet := false + if cc.dopts.scChan != nil { + // Try to get an initial service config. + select { + case sc, ok := <-cc.dopts.scChan: + if ok { + cc.sc = sc + scSet = true + } + default: + } + } + if cc.dopts.bs == nil { + cc.dopts.bs = backoff.Exponential{ + MaxDelay: DefaultBackoffConfig.MaxDelay, + } + } + if cc.dopts.resolverBuilder == nil { + // Only try to parse target when resolver builder is not already set. + cc.parsedTarget = parseTarget(cc.target) + grpclog.Infof("parsed scheme: %q", cc.parsedTarget.Scheme) + cc.dopts.resolverBuilder = resolver.Get(cc.parsedTarget.Scheme) + if cc.dopts.resolverBuilder == nil { + // If resolver builder is still nil, the parse target's scheme is + // not registered. Fallback to default resolver and set Endpoint to + // the original unparsed target. + grpclog.Infof("scheme %q not registered, fallback to default scheme", cc.parsedTarget.Scheme) + cc.parsedTarget = resolver.Target{ + Scheme: resolver.GetDefaultScheme(), + Endpoint: target, + } + cc.dopts.resolverBuilder = resolver.Get(cc.parsedTarget.Scheme) + } + } else { + cc.parsedTarget = resolver.Target{Endpoint: target} + } + creds := cc.dopts.copts.TransportCredentials + if creds != nil && creds.Info().ServerName != "" { + cc.authority = creds.Info().ServerName + } else if cc.dopts.insecure && cc.dopts.authority != "" { + cc.authority = cc.dopts.authority + } else { + // Use endpoint from "scheme://authority/endpoint" as the default + // authority for ClientConn. + cc.authority = cc.parsedTarget.Endpoint + } + + if cc.dopts.scChan != nil && !scSet { + // Blocking wait for the initial service config. + select { + case sc, ok := <-cc.dopts.scChan: + if ok { + cc.sc = sc + } + case <-ctx.Done(): + return nil, ctx.Err() + } + } + if cc.dopts.scChan != nil { + go cc.scWatcher() + } + + var credsClone credentials.TransportCredentials + if creds := cc.dopts.copts.TransportCredentials; creds != nil { + credsClone = creds.Clone() + } + cc.balancerBuildOpts = balancer.BuildOptions{ + DialCreds: credsClone, + CredsBundle: cc.dopts.copts.CredsBundle, + Dialer: cc.dopts.copts.Dialer, + ChannelzParentID: cc.channelzID, + } + + // Build the resolver. + rWrapper, err := newCCResolverWrapper(cc) + if err != nil { + return nil, fmt.Errorf("failed to build resolver: %v", err) + } + + cc.mu.Lock() + cc.resolverWrapper = rWrapper + cc.mu.Unlock() + // A blocking dial blocks until the clientConn is ready. + if cc.dopts.block { + for { + s := cc.GetState() + if s == connectivity.Ready { + break + } else if cc.dopts.copts.FailOnNonTempDialError && s == connectivity.TransientFailure { + if err = cc.blockingpicker.connectionError(); err != nil { + terr, ok := err.(interface { + Temporary() bool + }) + if ok && !terr.Temporary() { + return nil, err + } + } + } + if !cc.WaitForStateChange(ctx, s) { + // ctx got timeout or canceled. + return nil, ctx.Err() + } + } + } + + return cc, nil +} + +// connectivityStateManager keeps the connectivity.State of ClientConn. +// This struct will eventually be exported so the balancers can access it. +type connectivityStateManager struct { + mu sync.Mutex + state connectivity.State + notifyChan chan struct{} + channelzID int64 +} + +// updateState updates the connectivity.State of ClientConn. +// If there's a change it notifies goroutines waiting on state change to +// happen. +func (csm *connectivityStateManager) updateState(state connectivity.State) { + csm.mu.Lock() + defer csm.mu.Unlock() + if csm.state == connectivity.Shutdown { + return + } + if csm.state == state { + return + } + csm.state = state + if channelz.IsOn() { + channelz.AddTraceEvent(csm.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel Connectivity change to %v", state), + Severity: channelz.CtINFO, + }) + } + if csm.notifyChan != nil { + // There are other goroutines waiting on this channel. + close(csm.notifyChan) + csm.notifyChan = nil + } +} + +func (csm *connectivityStateManager) getState() connectivity.State { + csm.mu.Lock() + defer csm.mu.Unlock() + return csm.state +} + +func (csm *connectivityStateManager) getNotifyChan() <-chan struct{} { + csm.mu.Lock() + defer csm.mu.Unlock() + if csm.notifyChan == nil { + csm.notifyChan = make(chan struct{}) + } + return csm.notifyChan +} + +// ClientConn represents a client connection to an RPC server. +type ClientConn struct { + ctx context.Context + cancel context.CancelFunc + + target string + parsedTarget resolver.Target + authority string + dopts dialOptions + csMgr *connectivityStateManager + + balancerBuildOpts balancer.BuildOptions + blockingpicker *pickerWrapper + + mu sync.RWMutex + resolverWrapper *ccResolverWrapper + sc ServiceConfig + scRaw string + conns map[*addrConn]struct{} + // Keepalive parameter can be updated if a GoAway is received. + mkp keepalive.ClientParameters + curBalancerName string + preBalancerName string // previous balancer name. + curAddresses []resolver.Address + balancerWrapper *ccBalancerWrapper + retryThrottler atomic.Value + + firstResolveEvent *grpcsync.Event + + channelzID int64 // channelz unique identification number + czData *channelzData +} + +// WaitForStateChange waits until the connectivity.State of ClientConn changes from sourceState or +// ctx expires. A true value is returned in former case and false in latter. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) WaitForStateChange(ctx context.Context, sourceState connectivity.State) bool { + ch := cc.csMgr.getNotifyChan() + if cc.csMgr.getState() != sourceState { + return true + } + select { + case <-ctx.Done(): + return false + case <-ch: + return true + } +} + +// GetState returns the connectivity.State of ClientConn. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) GetState() connectivity.State { + return cc.csMgr.getState() +} + +func (cc *ClientConn) scWatcher() { + for { + select { + case sc, ok := <-cc.dopts.scChan: + if !ok { + return + } + cc.mu.Lock() + // TODO: load balance policy runtime change is ignored. + // We may revist this decision in the future. + cc.sc = sc + cc.scRaw = "" + cc.mu.Unlock() + case <-cc.ctx.Done(): + return + } + } +} + +// waitForResolvedAddrs blocks until the resolver has provided addresses or the +// context expires. Returns nil unless the context expires first; otherwise +// returns a status error based on the context. +func (cc *ClientConn) waitForResolvedAddrs(ctx context.Context) error { + // This is on the RPC path, so we use a fast path to avoid the + // more-expensive "select" below after the resolver has returned once. + if cc.firstResolveEvent.HasFired() { + return nil + } + select { + case <-cc.firstResolveEvent.Done(): + return nil + case <-ctx.Done(): + return status.FromContextError(ctx.Err()).Err() + case <-cc.ctx.Done(): + return ErrClientConnClosing + } +} + +func (cc *ClientConn) handleResolvedAddrs(addrs []resolver.Address, err error) { + cc.mu.Lock() + defer cc.mu.Unlock() + if cc.conns == nil { + // cc was closed. + return + } + + if reflect.DeepEqual(cc.curAddresses, addrs) { + return + } + + cc.curAddresses = addrs + cc.firstResolveEvent.Fire() + + if cc.dopts.balancerBuilder == nil { + // Only look at balancer types and switch balancer if balancer dial + // option is not set. + var isGRPCLB bool + for _, a := range addrs { + if a.Type == resolver.GRPCLB { + isGRPCLB = true + break + } + } + var newBalancerName string + if isGRPCLB { + newBalancerName = grpclbName + } else { + // Address list doesn't contain grpclb address. Try to pick a + // non-grpclb balancer. + newBalancerName = cc.curBalancerName + // If current balancer is grpclb, switch to the previous one. + if newBalancerName == grpclbName { + newBalancerName = cc.preBalancerName + } + // The following could be true in two cases: + // - the first time handling resolved addresses + // (curBalancerName="") + // - the first time handling non-grpclb addresses + // (curBalancerName="grpclb", preBalancerName="") + if newBalancerName == "" { + newBalancerName = PickFirstBalancerName + } + } + cc.switchBalancer(newBalancerName) + } else if cc.balancerWrapper == nil { + // Balancer dial option was set, and this is the first time handling + // resolved addresses. Build a balancer with dopts.balancerBuilder. + cc.balancerWrapper = newCCBalancerWrapper(cc, cc.dopts.balancerBuilder, cc.balancerBuildOpts) + } + + cc.balancerWrapper.handleResolvedAddrs(addrs, nil) +} + +// switchBalancer starts the switching from current balancer to the balancer +// with the given name. +// +// It will NOT send the current address list to the new balancer. If needed, +// caller of this function should send address list to the new balancer after +// this function returns. +// +// Caller must hold cc.mu. +func (cc *ClientConn) switchBalancer(name string) { + if cc.conns == nil { + return + } + + if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) { + return + } + + grpclog.Infof("ClientConn switching balancer to %q", name) + if cc.dopts.balancerBuilder != nil { + grpclog.Infoln("ignoring balancer switching: Balancer DialOption used instead") + return + } + // TODO(bar switching) change this to two steps: drain and close. + // Keep track of sc in wrapper. + if cc.balancerWrapper != nil { + cc.balancerWrapper.close() + } + + builder := balancer.Get(name) + // TODO(yuxuanli): If user send a service config that does not contain a valid balancer name, should + // we reuse previous one? + if channelz.IsOn() { + if builder == nil { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel switches to new LB policy %q due to fallback from invalid balancer name", PickFirstBalancerName), + Severity: channelz.CtWarning, + }) + } else { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Channel switches to new LB policy %q", name), + Severity: channelz.CtINFO, + }) + } + } + if builder == nil { + grpclog.Infof("failed to get balancer builder for: %v, using pick_first instead", name) + builder = newPickfirstBuilder() + } + + cc.preBalancerName = cc.curBalancerName + cc.curBalancerName = builder.Name() + cc.balancerWrapper = newCCBalancerWrapper(cc, builder, cc.balancerBuildOpts) +} + +func (cc *ClientConn) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return + } + // TODO(bar switching) send updates to all balancer wrappers when balancer + // gracefully switching is supported. + cc.balancerWrapper.handleSubConnStateChange(sc, s) + cc.mu.Unlock() +} + +// newAddrConn creates an addrConn for addrs and adds it to cc.conns. +// +// Caller needs to make sure len(addrs) > 0. +func (cc *ClientConn) newAddrConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (*addrConn, error) { + ac := &addrConn{ + cc: cc, + addrs: addrs, + scopts: opts, + dopts: cc.dopts, + czData: new(channelzData), + successfulHandshake: true, // make the first nextAddr() call _not_ move addrIdx up by 1 + resetBackoff: make(chan struct{}), + } + ac.ctx, ac.cancel = context.WithCancel(cc.ctx) + // Track ac in cc. This needs to be done before any getTransport(...) is called. + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return nil, ErrClientConnClosing + } + if channelz.IsOn() { + ac.channelzID = channelz.RegisterSubChannel(ac, cc.channelzID, "") + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel Created", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel(id:%d) created", ac.channelzID), + Severity: channelz.CtINFO, + }, + }) + } + cc.conns[ac] = struct{}{} + cc.mu.Unlock() + return ac, nil +} + +// removeAddrConn removes the addrConn in the subConn from clientConn. +// It also tears down the ac with the given error. +func (cc *ClientConn) removeAddrConn(ac *addrConn, err error) { + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return + } + delete(cc.conns, ac) + cc.mu.Unlock() + ac.tearDown(err) +} + +func (cc *ClientConn) channelzMetric() *channelz.ChannelInternalMetric { + return &channelz.ChannelInternalMetric{ + State: cc.GetState(), + Target: cc.target, + CallsStarted: atomic.LoadInt64(&cc.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&cc.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&cc.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&cc.czData.lastCallStartedTime)), + } +} + +// Target returns the target string of the ClientConn. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) Target() string { + return cc.target +} + +func (cc *ClientConn) incrCallsStarted() { + atomic.AddInt64(&cc.czData.callsStarted, 1) + atomic.StoreInt64(&cc.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (cc *ClientConn) incrCallsSucceeded() { + atomic.AddInt64(&cc.czData.callsSucceeded, 1) +} + +func (cc *ClientConn) incrCallsFailed() { + atomic.AddInt64(&cc.czData.callsFailed, 1) +} + +// connect starts creating a transport. +// It does nothing if the ac is not IDLE. +// TODO(bar) Move this to the addrConn section. +func (ac *addrConn) connect() error { + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return errConnClosing + } + if ac.state != connectivity.Idle { + ac.mu.Unlock() + return nil + } + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.mu.Unlock() + + // Start a goroutine connecting to the server asynchronously. + go ac.resetTransport(false) + return nil +} + +// tryUpdateAddrs tries to update ac.addrs with the new addresses list. +// +// It checks whether current connected address of ac is in the new addrs list. +// - If true, it updates ac.addrs and returns true. The ac will keep using +// the existing connection. +// - If false, it does nothing and returns false. +func (ac *addrConn) tryUpdateAddrs(addrs []resolver.Address) bool { + ac.mu.Lock() + defer ac.mu.Unlock() + grpclog.Infof("addrConn: tryUpdateAddrs curAddr: %v, addrs: %v", ac.curAddr, addrs) + if ac.state == connectivity.Shutdown { + ac.addrs = addrs + return true + } + + var curAddrFound bool + for _, a := range addrs { + if reflect.DeepEqual(ac.curAddr, a) { + curAddrFound = true + break + } + } + grpclog.Infof("addrConn: tryUpdateAddrs curAddrFound: %v", curAddrFound) + if curAddrFound { + ac.addrs = addrs + ac.addrIdx = 0 // Start reconnecting from beginning in the new list. + } + + return curAddrFound +} + +// GetMethodConfig gets the method config of the input method. +// If there's an exact match for input method (i.e. /service/method), we return +// the corresponding MethodConfig. +// If there isn't an exact match for the input method, we look for the default config +// under the service (i.e /service/). If there is a default MethodConfig for +// the service, we return it. +// Otherwise, we return an empty MethodConfig. +func (cc *ClientConn) GetMethodConfig(method string) MethodConfig { + // TODO: Avoid the locking here. + cc.mu.RLock() + defer cc.mu.RUnlock() + m, ok := cc.sc.Methods[method] + if !ok { + i := strings.LastIndex(method, "/") + m = cc.sc.Methods[method[:i+1]] + } + return m +} + +func (cc *ClientConn) healthCheckConfig() *healthCheckConfig { + cc.mu.RLock() + defer cc.mu.RUnlock() + return cc.sc.healthCheckConfig +} + +func (cc *ClientConn) getTransport(ctx context.Context, failfast bool, method string) (transport.ClientTransport, func(balancer.DoneInfo), error) { + hdr, _ := metadata.FromOutgoingContext(ctx) + t, done, err := cc.blockingpicker.pick(ctx, failfast, balancer.PickOptions{ + FullMethodName: method, + Header: hdr, + }) + if err != nil { + return nil, nil, toRPCErr(err) + } + return t, done, nil +} + +// handleServiceConfig parses the service config string in JSON format to Go native +// struct ServiceConfig, and store both the struct and the JSON string in ClientConn. +func (cc *ClientConn) handleServiceConfig(js string) error { + if cc.dopts.disableServiceConfig { + return nil + } + if cc.scRaw == js { + return nil + } + if channelz.IsOn() { + channelz.AddTraceEvent(cc.channelzID, &channelz.TraceEventDesc{ + // The special formatting of \"%s\" instead of %q is to provide nice printing of service config + // for human consumption. + Desc: fmt.Sprintf("Channel has a new service config \"%s\"", js), + Severity: channelz.CtINFO, + }) + } + sc, err := parseServiceConfig(js) + if err != nil { + return err + } + cc.mu.Lock() + // Check if the ClientConn is already closed. Some fields (e.g. + // balancerWrapper) are set to nil when closing the ClientConn, and could + // cause nil pointer panic if we don't have this check. + if cc.conns == nil { + cc.mu.Unlock() + return nil + } + cc.scRaw = js + cc.sc = sc + + if sc.retryThrottling != nil { + newThrottler := &retryThrottler{ + tokens: sc.retryThrottling.MaxTokens, + max: sc.retryThrottling.MaxTokens, + thresh: sc.retryThrottling.MaxTokens / 2, + ratio: sc.retryThrottling.TokenRatio, + } + cc.retryThrottler.Store(newThrottler) + } else { + cc.retryThrottler.Store((*retryThrottler)(nil)) + } + + if sc.LB != nil && *sc.LB != grpclbName { // "grpclb" is not a valid balancer option in service config. + if cc.curBalancerName == grpclbName { + // If current balancer is grpclb, there's at least one grpclb + // balancer address in the resolved list. Don't switch the balancer, + // but change the previous balancer name, so if a new resolved + // address list doesn't contain grpclb address, balancer will be + // switched to *sc.LB. + cc.preBalancerName = *sc.LB + } else { + cc.switchBalancer(*sc.LB) + cc.balancerWrapper.handleResolvedAddrs(cc.curAddresses, nil) + } + } + + cc.mu.Unlock() + return nil +} + +func (cc *ClientConn) resolveNow(o resolver.ResolveNowOption) { + cc.mu.RLock() + r := cc.resolverWrapper + cc.mu.RUnlock() + if r == nil { + return + } + go r.resolveNow(o) +} + +// ResetConnectBackoff wakes up all subchannels in transient failure and causes +// them to attempt another connection immediately. It also resets the backoff +// times used for subsequent attempts regardless of the current state. +// +// In general, this function should not be used. Typical service or network +// outages result in a reasonable client reconnection strategy by default. +// However, if a previously unavailable network becomes available, this may be +// used to trigger an immediate reconnect. +// +// This API is EXPERIMENTAL. +func (cc *ClientConn) ResetConnectBackoff() { + cc.mu.Lock() + defer cc.mu.Unlock() + for ac := range cc.conns { + ac.resetConnectBackoff() + } +} + +// Close tears down the ClientConn and all underlying connections. +func (cc *ClientConn) Close() error { + defer cc.cancel() + + cc.mu.Lock() + if cc.conns == nil { + cc.mu.Unlock() + return ErrClientConnClosing + } + conns := cc.conns + cc.conns = nil + cc.csMgr.updateState(connectivity.Shutdown) + + rWrapper := cc.resolverWrapper + cc.resolverWrapper = nil + bWrapper := cc.balancerWrapper + cc.balancerWrapper = nil + cc.mu.Unlock() + + cc.blockingpicker.close() + + if rWrapper != nil { + rWrapper.close() + } + if bWrapper != nil { + bWrapper.close() + } + + for ac := range conns { + ac.tearDown(ErrClientConnClosing) + } + if channelz.IsOn() { + ted := &channelz.TraceEventDesc{ + Desc: "Channel Deleted", + Severity: channelz.CtINFO, + } + if cc.dopts.channelzParentID != 0 { + ted.Parent = &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Nested channel(id:%d) deleted", cc.channelzID), + Severity: channelz.CtINFO, + } + } + channelz.AddTraceEvent(cc.channelzID, ted) + // TraceEvent needs to be called before RemoveEntry, as TraceEvent may add trace reference to + // the entity beng deleted, and thus prevent it from being deleted right away. + channelz.RemoveEntry(cc.channelzID) + } + return nil +} + +// addrConn is a network connection to a given address. +type addrConn struct { + ctx context.Context + cancel context.CancelFunc + + cc *ClientConn + dopts dialOptions + acbw balancer.SubConn + scopts balancer.NewSubConnOptions + + // transport is set when there's a viable transport (note: ac state may not be READY as LB channel + // health checking may require server to report healthy to set ac to READY), and is reset + // to nil when the current transport should no longer be used to create a stream (e.g. after GoAway + // is received, transport is closed, ac has been torn down). + transport transport.ClientTransport // The current transport. + + mu sync.Mutex + addrIdx int // The index in addrs list to start reconnecting from. + curAddr resolver.Address // The current address. + addrs []resolver.Address // All addresses that the resolver resolved to. + + // Use updateConnectivityState for updating addrConn's connectivity state. + state connectivity.State + + tearDownErr error // The reason this addrConn is torn down. + + backoffIdx int + // backoffDeadline is the time until which resetTransport needs to + // wait before increasing backoffIdx count. + backoffDeadline time.Time + // connectDeadline is the time by which all connection + // negotiations must complete. + connectDeadline time.Time + + resetBackoff chan struct{} + + channelzID int64 // channelz unique identification number + czData *channelzData + + successfulHandshake bool + + healthCheckEnabled bool +} + +// Note: this requires a lock on ac.mu. +func (ac *addrConn) updateConnectivityState(s connectivity.State) { + ac.state = s + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel Connectivity change to %v", s), + Severity: channelz.CtINFO, + }) + } +} + +// adjustParams updates parameters used to create transports upon +// receiving a GoAway. +func (ac *addrConn) adjustParams(r transport.GoAwayReason) { + switch r { + case transport.GoAwayTooManyPings: + v := 2 * ac.dopts.copts.KeepaliveParams.Time + ac.cc.mu.Lock() + if v > ac.cc.mkp.Time { + ac.cc.mkp.Time = v + } + ac.cc.mu.Unlock() + } +} + +// resetTransport makes sure that a healthy ac.transport exists. +// +// The transport will close itself when it encounters an error, or on GOAWAY, or on deadline waiting for handshake, or +// when the clientconn is closed. Each iteration creating a new transport will try a different address that the balancer +// assigned to the addrConn, until it has tried all addresses. Once it has tried all addresses, it will re-resolve to +// get a new address list. If an error is received, the list is re-resolved and the next reset attempt will try from the +// beginning. This method has backoff built in. The backoff amount starts at 0 and increases each time resolution occurs +// (addresses are exhausted). The backoff amount is reset to 0 each time a handshake is received. +// +// If the DialOption WithWaitForHandshake was set, resetTransport returns successfully only after handshake is received. +func (ac *addrConn) resetTransport(resolveNow bool) { + for { + // If this is the first in a line of resets, we want to resolve immediately. The only other time we + // want to reset is if we have tried all the addresses handed to us. + if resolveNow { + ac.mu.Lock() + ac.cc.resolveNow(resolver.ResolveNowOption{}) + ac.mu.Unlock() + } + + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + // The transport that was used before is no longer viable. + ac.transport = nil + // If the connection is READY, a failure must have occurred. + // Otherwise, we'll consider this is a transient failure when: + // We've exhausted all addresses + // We're in CONNECTING + // And it's not the very first addr to try TODO(deklerk) find a better way to do this than checking ac.successfulHandshake + if ac.state == connectivity.Ready || (ac.addrIdx == len(ac.addrs)-1 && ac.state == connectivity.Connecting && !ac.successfulHandshake) { + ac.updateConnectivityState(connectivity.TransientFailure) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + ac.transport = nil + ac.mu.Unlock() + + if err := ac.nextAddr(); err != nil { + return + } + + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + backoffIdx := ac.backoffIdx + backoffFor := ac.dopts.bs.Backoff(backoffIdx) + + // This will be the duration that dial gets to finish. + dialDuration := getMinConnectTimeout() + if backoffFor > dialDuration { + // Give dial more time as we keep failing to connect. + dialDuration = backoffFor + } + start := time.Now() + connectDeadline := start.Add(dialDuration) + ac.backoffDeadline = start.Add(backoffFor) + ac.connectDeadline = connectDeadline + + ac.mu.Unlock() + + ac.cc.mu.RLock() + ac.dopts.copts.KeepaliveParams = ac.cc.mkp + ac.cc.mu.RUnlock() + + ac.mu.Lock() + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + + if ac.state != connectivity.Connecting { + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + + addr := ac.addrs[ac.addrIdx] + copts := ac.dopts.copts + if ac.scopts.CredsBundle != nil { + copts.CredsBundle = ac.scopts.CredsBundle + } + ac.mu.Unlock() + + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchannel picks a new address %q to connect", addr.Addr), + Severity: channelz.CtINFO, + }) + } + + if err := ac.createTransport(backoffIdx, addr, copts, connectDeadline); err != nil { + continue + } + + return + } +} + +// createTransport creates a connection to one of the backends in addrs. +func (ac *addrConn) createTransport(backoffNum int, addr resolver.Address, copts transport.ConnectOptions, connectDeadline time.Time) error { + oneReset := sync.Once{} + skipReset := make(chan struct{}) + allowedToReset := make(chan struct{}) + prefaceReceived := make(chan struct{}) + onCloseCalled := make(chan struct{}) + + var prefaceMu sync.Mutex + var serverPrefaceReceived bool + var clientPrefaceWrote bool + + hcCtx, hcCancel := context.WithCancel(ac.ctx) + + onGoAway := func(r transport.GoAwayReason) { + hcCancel() + ac.mu.Lock() + ac.adjustParams(r) + ac.mu.Unlock() + select { + case <-skipReset: // The outer resetTransport loop will handle reconnection. + return + case <-allowedToReset: // We're in the clear to reset. + go oneReset.Do(func() { ac.resetTransport(false) }) + } + } + + prefaceTimer := time.NewTimer(connectDeadline.Sub(time.Now())) + + onClose := func() { + hcCancel() + close(onCloseCalled) + prefaceTimer.Stop() + + select { + case <-skipReset: // The outer resetTransport loop will handle reconnection. + return + case <-allowedToReset: // We're in the clear to reset. + oneReset.Do(func() { ac.resetTransport(false) }) + } + } + + target := transport.TargetInfo{ + Addr: addr.Addr, + Metadata: addr.Metadata, + Authority: ac.cc.authority, + } + + onPrefaceReceipt := func() { + close(prefaceReceived) + prefaceTimer.Stop() + + // TODO(deklerk): optimization; does anyone else actually use this lock? maybe we can just remove it for this scope + ac.mu.Lock() + + prefaceMu.Lock() + serverPrefaceReceived = true + if clientPrefaceWrote { + ac.successfulHandshake = true + } + prefaceMu.Unlock() + + ac.mu.Unlock() + } + + connectCtx, cancel := context.WithDeadline(ac.ctx, connectDeadline) + defer cancel() + if channelz.IsOn() { + copts.ChannelzParentID = ac.channelzID + } + + newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, target, copts, onPrefaceReceipt, onGoAway, onClose) + + if err == nil { + prefaceMu.Lock() + clientPrefaceWrote = true + if serverPrefaceReceived || ac.dopts.reqHandshake == envconfig.RequireHandshakeOff { + ac.successfulHandshake = true + } + prefaceMu.Unlock() + + if ac.dopts.reqHandshake == envconfig.RequireHandshakeOn { + select { + case <-prefaceTimer.C: + // We didn't get the preface in time. + newTr.Close() + err = errors.New("timed out waiting for server handshake") + case <-prefaceReceived: + // We got the preface - huzzah! things are good. + case <-onCloseCalled: + // The transport has already closed - noop. + close(allowedToReset) + return nil + } + } else if ac.dopts.reqHandshake == envconfig.RequireHandshakeHybrid { + go func() { + select { + case <-prefaceTimer.C: + // We didn't get the preface in time. + newTr.Close() + case <-prefaceReceived: + // We got the preface just in the nick of time - huzzah! + case <-onCloseCalled: + // The transport has already closed - noop. + } + }() + } + } + + if err != nil { + // newTr is either nil, or closed. + ac.cc.blockingpicker.updateConnectionError(err) + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + // ac.tearDown(...) has been invoked. + ac.mu.Unlock() + + // We don't want to reset during this close because we prefer to kick out of this function and let the loop + // in resetTransport take care of reconnecting. + close(skipReset) + + return errConnClosing + } + ac.mu.Unlock() + grpclog.Warningf("grpc: addrConn.createTransport failed to connect to %v. Err :%v. Reconnecting...", addr, err) + + // We don't want to reset during this close because we prefer to kick out of this function and let the loop + // in resetTransport take care of reconnecting. + close(skipReset) + + return err + } + + // Now there is a viable transport to be use, so set ac.transport to reflect the new viable transport. + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + close(skipReset) + newTr.Close() + return nil + } + ac.transport = newTr + ac.mu.Unlock() + + healthCheckConfig := ac.cc.healthCheckConfig() + // LB channel health checking is only enabled when all the four requirements below are met: + // 1. it is not disabled by the user with the WithDisableHealthCheck DialOption, + // 2. the internal.HealthCheckFunc is set by importing the grpc/healthcheck package, + // 3. a service config with non-empty healthCheckConfig field is provided, + // 4. the current load balancer allows it. + if !ac.cc.dopts.disableHealthCheck && healthCheckConfig != nil && ac.scopts.HealthCheckEnabled { + if internal.HealthCheckFunc != nil { + go ac.startHealthCheck(hcCtx, newTr, addr, healthCheckConfig.ServiceName) + close(allowedToReset) + return nil + } + // TODO: add a link to the health check doc in the error message. + grpclog.Error("the client side LB channel health check function has not been set.") + } + + // No LB channel health check case + ac.mu.Lock() + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + + // unblock onGoAway/onClose callback. + close(skipReset) + return errConnClosing + } + + ac.updateConnectivityState(connectivity.Ready) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.curAddr = addr + + ac.mu.Unlock() + + // Ok, _now_ we will finally let the transport reset if it encounters a closable error. Without this, the reader + // goroutine failing races with all the code in this method that sets the connection to "ready". + close(allowedToReset) + return nil +} + +func (ac *addrConn) startHealthCheck(ctx context.Context, newTr transport.ClientTransport, addr resolver.Address, serviceName string) { + // Set up the health check helper functions + newStream := func() (interface{}, error) { + return ac.newClientStream(ctx, &StreamDesc{ServerStreams: true}, "/grpc.health.v1.Health/Watch", newTr) + } + firstReady := true + reportHealth := func(ok bool) { + ac.mu.Lock() + defer ac.mu.Unlock() + if ac.transport != newTr { + return + } + if ok { + if firstReady { + firstReady = false + ac.curAddr = addr + } + if ac.state != connectivity.Ready { + ac.updateConnectivityState(connectivity.Ready) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + } else { + if ac.state != connectivity.TransientFailure { + ac.updateConnectivityState(connectivity.TransientFailure) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + } + } + + err := internal.HealthCheckFunc(ctx, newStream, reportHealth, serviceName) + if err != nil { + if status.Code(err) == codes.Unimplemented { + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel health check is unimplemented at server side, thus health check is disabled", + Severity: channelz.CtError, + }) + } + grpclog.Error("Subchannel health check is unimplemented at server side, thus health check is disabled") + } else { + grpclog.Errorf("HealthCheckFunc exits with unexpected error %v", err) + } + } +} + +// nextAddr increments the addrIdx if there are more addresses to try. If +// there are no more addrs to try it will re-resolve, set addrIdx to 0, and +// increment the backoffIdx. +// +// nextAddr must be called without ac.mu being held. +func (ac *addrConn) nextAddr() error { + ac.mu.Lock() + + // If a handshake has been observed, we want the next usage to start at + // index 0 immediately. + if ac.successfulHandshake { + ac.successfulHandshake = false + ac.backoffDeadline = time.Time{} + ac.connectDeadline = time.Time{} + ac.addrIdx = 0 + ac.backoffIdx = 0 + ac.mu.Unlock() + return nil + } + + if ac.addrIdx < len(ac.addrs)-1 { + ac.addrIdx++ + ac.mu.Unlock() + return nil + } + + ac.addrIdx = 0 + ac.backoffIdx++ + + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return errConnClosing + } + ac.cc.resolveNow(resolver.ResolveNowOption{}) + backoffDeadline := ac.backoffDeadline + b := ac.resetBackoff + ac.mu.Unlock() + timer := time.NewTimer(backoffDeadline.Sub(time.Now())) + select { + case <-timer.C: + case <-b: + timer.Stop() + case <-ac.ctx.Done(): + timer.Stop() + return ac.ctx.Err() + } + return nil +} + +func (ac *addrConn) resetConnectBackoff() { + ac.mu.Lock() + close(ac.resetBackoff) + ac.backoffIdx = 0 + ac.resetBackoff = make(chan struct{}) + ac.mu.Unlock() +} + +// getReadyTransport returns the transport if ac's state is READY. +// Otherwise it returns nil, false. +// If ac's state is IDLE, it will trigger ac to connect. +func (ac *addrConn) getReadyTransport() (transport.ClientTransport, bool) { + ac.mu.Lock() + if ac.state == connectivity.Ready && ac.transport != nil { + t := ac.transport + ac.mu.Unlock() + return t, true + } + var idle bool + if ac.state == connectivity.Idle { + idle = true + } + ac.mu.Unlock() + // Trigger idle ac to connect. + if idle { + ac.connect() + } + return nil, false +} + +// tearDown starts to tear down the addrConn. +// TODO(zhaoq): Make this synchronous to avoid unbounded memory consumption in +// some edge cases (e.g., the caller opens and closes many addrConn's in a +// tight loop. +// tearDown doesn't remove ac from ac.cc.conns. +func (ac *addrConn) tearDown(err error) { + ac.mu.Lock() + if ac.state == connectivity.Shutdown { + ac.mu.Unlock() + return + } + curTr := ac.transport + ac.transport = nil + // We have to set the state to Shutdown before anything else to prevent races + // between setting the state and logic that waits on context cancelation / etc. + ac.updateConnectivityState(connectivity.Shutdown) + ac.cancel() + ac.tearDownErr = err + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + ac.curAddr = resolver.Address{} + if err == errConnDrain && curTr != nil { + // GracefulClose(...) may be executed multiple times when + // i) receiving multiple GoAway frames from the server; or + // ii) there are concurrent name resolver/Balancer triggered + // address removal and GoAway. + // We have to unlock and re-lock here because GracefulClose => Close => onClose, which requires locking ac.mu. + ac.mu.Unlock() + curTr.GracefulClose() + ac.mu.Lock() + } + if channelz.IsOn() { + channelz.AddTraceEvent(ac.channelzID, &channelz.TraceEventDesc{ + Desc: "Subchannel Deleted", + Severity: channelz.CtINFO, + Parent: &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Subchanel(id:%d) deleted", ac.channelzID), + Severity: channelz.CtINFO, + }, + }) + // TraceEvent needs to be called before RemoveEntry, as TraceEvent may add trace reference to + // the entity beng deleted, and thus prevent it from being deleted right away. + channelz.RemoveEntry(ac.channelzID) + } + ac.mu.Unlock() +} + +func (ac *addrConn) getState() connectivity.State { + ac.mu.Lock() + defer ac.mu.Unlock() + return ac.state +} + +func (ac *addrConn) ChannelzMetric() *channelz.ChannelInternalMetric { + ac.mu.Lock() + addr := ac.curAddr.Addr + ac.mu.Unlock() + return &channelz.ChannelInternalMetric{ + State: ac.getState(), + Target: addr, + CallsStarted: atomic.LoadInt64(&ac.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&ac.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&ac.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&ac.czData.lastCallStartedTime)), + } +} + +func (ac *addrConn) incrCallsStarted() { + atomic.AddInt64(&ac.czData.callsStarted, 1) + atomic.StoreInt64(&ac.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (ac *addrConn) incrCallsSucceeded() { + atomic.AddInt64(&ac.czData.callsSucceeded, 1) +} + +func (ac *addrConn) incrCallsFailed() { + atomic.AddInt64(&ac.czData.callsFailed, 1) +} + +type retryThrottler struct { + max float64 + thresh float64 + ratio float64 + + mu sync.Mutex + tokens float64 // TODO(dfawley): replace with atomic and remove lock. +} + +// throttle subtracts a retry token from the pool and returns whether a retry +// should be throttled (disallowed) based upon the retry throttling policy in +// the service config. +func (rt *retryThrottler) throttle() bool { + if rt == nil { + return false + } + rt.mu.Lock() + defer rt.mu.Unlock() + rt.tokens-- + if rt.tokens < 0 { + rt.tokens = 0 + } + return rt.tokens <= rt.thresh +} + +func (rt *retryThrottler) successfulRPC() { + if rt == nil { + return + } + rt.mu.Lock() + defer rt.mu.Unlock() + rt.tokens += rt.ratio + if rt.tokens > rt.max { + rt.tokens = rt.max + } +} + +type channelzChannel struct { + cc *ClientConn +} + +func (c *channelzChannel) ChannelzMetric() *channelz.ChannelInternalMetric { + return c.cc.channelzMetric() +} + +// ErrClientConnTimeout indicates that the ClientConn cannot establish the +// underlying connections within the specified timeout. +// +// Deprecated: This error is never returned by grpc and should not be +// referenced by users. +var ErrClientConnTimeout = errors.New("grpc: timed out when dialing") diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codec.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codec.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codec.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codec.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codegen.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codegen.sh similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codegen.sh rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codegen.sh diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/code_string.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/code_string.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/code_string.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/code_string.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/codes.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/codes.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/codes/codes.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/codes/codes.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go new file mode 100644 index 00000000..b1d7dbc5 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/connectivity/connectivity.go @@ -0,0 +1,73 @@ +/* + * + * 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 connectivity defines connectivity semantics. +// For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md. +// All APIs in this package are experimental. +package connectivity + +import ( + "context" + + "google.golang.org/grpc/grpclog" +) + +// State indicates the state of connectivity. +// It can be the state of a ClientConn or SubConn. +type State int + +func (s State) String() string { + switch s { + case Idle: + return "IDLE" + case Connecting: + return "CONNECTING" + case Ready: + return "READY" + case TransientFailure: + return "TRANSIENT_FAILURE" + case Shutdown: + return "SHUTDOWN" + default: + grpclog.Errorf("unknown connectivity state: %d", s) + return "Invalid-State" + } +} + +const ( + // Idle indicates the ClientConn is idle. + Idle State = iota + // Connecting indicates the ClienConn is connecting. + Connecting + // Ready indicates the ClientConn is ready for work. + Ready + // TransientFailure indicates the ClientConn has seen a failure but expects to recover. + TransientFailure + // Shutdown indicates the ClientConn has started shutting down. + Shutdown +) + +// Reporter reports the connectivity states. +type Reporter interface { + // CurrentState returns the current state of the reporter. + CurrentState() State + // WaitForStateChange blocks until the reporter's state is different from the given state, + // and returns true. + // It returns false if <-ctx.Done() can proceed (ctx got timeout or got canceled). + WaitForStateChange(context.Context, State) bool +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go new file mode 100644 index 00000000..a8515604 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/credentials.go @@ -0,0 +1,328 @@ +/* + * + * Copyright 2014 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 credentials implements various credentials supported by gRPC library, +// which encapsulate all the state needed by a client to authenticate with a +// server and make various assertions, e.g., about the client's identity, role, +// or whether it is authorized to make a particular call. +package credentials // import "google.golang.org/grpc/credentials" + +import ( + "context" + "crypto/tls" + "crypto/x509" + "errors" + "fmt" + "io/ioutil" + "net" + "strings" + + "github.com/golang/protobuf/proto" + "google.golang.org/grpc/credentials/internal" +) + +// alpnProtoStr are the specified application level protocols for gRPC. +var alpnProtoStr = []string{"h2"} + +// PerRPCCredentials defines the common interface for the credentials which need to +// attach security information to every RPC (e.g., oauth2). +type PerRPCCredentials interface { + // GetRequestMetadata gets the current request metadata, refreshing + // tokens if required. This should be called by the transport layer on + // each request, and the data should be populated in headers or other + // context. If a status code is returned, it will be used as the status + // for the RPC. uri is the URI of the entry point for the request. + // When supported by the underlying implementation, ctx can be used for + // timeout and cancellation. + // TODO(zhaoq): Define the set of the qualified keys instead of leaving + // it as an arbitrary string. + GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) + // RequireTransportSecurity indicates whether the credentials requires + // transport security. + RequireTransportSecurity() bool +} + +// ProtocolInfo provides information regarding the gRPC wire protocol version, +// security protocol, security protocol version in use, server name, etc. +type ProtocolInfo struct { + // ProtocolVersion is the gRPC wire protocol version. + ProtocolVersion string + // SecurityProtocol is the security protocol in use. + SecurityProtocol string + // SecurityVersion is the security protocol version. + SecurityVersion string + // ServerName is the user-configured server name. + ServerName string +} + +// AuthInfo defines the common interface for the auth information the users are interested in. +type AuthInfo interface { + AuthType() string +} + +// ErrConnDispatched indicates that rawConn has been dispatched out of gRPC +// and the caller should not close rawConn. +var ErrConnDispatched = errors.New("credentials: rawConn is dispatched out of gRPC") + +// TransportCredentials defines the common interface for all the live gRPC wire +// protocols and supported transport security protocols (e.g., TLS, SSL). +type TransportCredentials interface { + // ClientHandshake does the authentication handshake specified by the corresponding + // authentication protocol on rawConn for clients. It returns the authenticated + // connection and the corresponding auth information about the connection. + // Implementations must use the provided context to implement timely cancellation. + // gRPC will try to reconnect if the error returned is a temporary error + // (io.EOF, context.DeadlineExceeded or err.Temporary() == true). + // If the returned error is a wrapper error, implementations should make sure that + // the error implements Temporary() to have the correct retry behaviors. + // + // If the returned net.Conn is closed, it MUST close the net.Conn provided. + ClientHandshake(context.Context, string, net.Conn) (net.Conn, AuthInfo, error) + // ServerHandshake does the authentication handshake for servers. It returns + // the authenticated connection and the corresponding auth information about + // the connection. + // + // If the returned net.Conn is closed, it MUST close the net.Conn provided. + ServerHandshake(net.Conn) (net.Conn, AuthInfo, error) + // Info provides the ProtocolInfo of this TransportCredentials. + Info() ProtocolInfo + // Clone makes a copy of this TransportCredentials. + Clone() TransportCredentials + // OverrideServerName overrides the server name used to verify the hostname on the returned certificates from the server. + // gRPC internals also use it to override the virtual hosting name if it is set. + // It must be called before dialing. Currently, this is only used by grpclb. + OverrideServerName(string) error +} + +// Bundle is a combination of TransportCredentials and PerRPCCredentials. +// +// It also contains a mode switching method, so it can be used as a combination +// of different credential policies. +// +// Bundle cannot be used together with individual TransportCredentials. +// PerRPCCredentials from Bundle will be appended to other PerRPCCredentials. +// +// This API is experimental. +type Bundle interface { + TransportCredentials() TransportCredentials + PerRPCCredentials() PerRPCCredentials + // NewWithMode should make a copy of Bundle, and switch mode. Modifying the + // existing Bundle may cause races. + // + // NewWithMode returns nil if the requested mode is not supported. + NewWithMode(mode string) (Bundle, error) +} + +// TLSInfo contains the auth information for a TLS authenticated connection. +// It implements the AuthInfo interface. +type TLSInfo struct { + State tls.ConnectionState +} + +// AuthType returns the type of TLSInfo as a string. +func (t TLSInfo) AuthType() string { + return "tls" +} + +// GetSecurityValue returns security info requested by channelz. +func (t TLSInfo) GetSecurityValue() ChannelzSecurityValue { + v := &TLSChannelzSecurityValue{ + StandardName: cipherSuiteLookup[t.State.CipherSuite], + } + // Currently there's no way to get LocalCertificate info from tls package. + if len(t.State.PeerCertificates) > 0 { + v.RemoteCertificate = t.State.PeerCertificates[0].Raw + } + return v +} + +// tlsCreds is the credentials required for authenticating a connection using TLS. +type tlsCreds struct { + // TLS configuration + config *tls.Config +} + +func (c tlsCreds) Info() ProtocolInfo { + return ProtocolInfo{ + SecurityProtocol: "tls", + SecurityVersion: "1.2", + ServerName: c.config.ServerName, + } +} + +func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawConn net.Conn) (_ net.Conn, _ AuthInfo, err error) { + // use local cfg to avoid clobbering ServerName if using multiple endpoints + cfg := cloneTLSConfig(c.config) + if cfg.ServerName == "" { + colonPos := strings.LastIndex(authority, ":") + if colonPos == -1 { + colonPos = len(authority) + } + cfg.ServerName = authority[:colonPos] + } + conn := tls.Client(rawConn, cfg) + errChannel := make(chan error, 1) + go func() { + errChannel <- conn.Handshake() + }() + select { + case err := <-errChannel: + if err != nil { + return nil, nil, err + } + case <-ctx.Done(): + return nil, nil, ctx.Err() + } + return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState()}, nil +} + +func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) { + conn := tls.Server(rawConn, c.config) + if err := conn.Handshake(); err != nil { + return nil, nil, err + } + return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState()}, nil +} + +func (c *tlsCreds) Clone() TransportCredentials { + return NewTLS(c.config) +} + +func (c *tlsCreds) OverrideServerName(serverNameOverride string) error { + c.config.ServerName = serverNameOverride + return nil +} + +// NewTLS uses c to construct a TransportCredentials based on TLS. +func NewTLS(c *tls.Config) TransportCredentials { + tc := &tlsCreds{cloneTLSConfig(c)} + tc.config.NextProtos = alpnProtoStr + return tc +} + +// NewClientTLSFromCert constructs TLS credentials from the input certificate for client. +// serverNameOverride is for testing only. If set to a non empty string, +// it will override the virtual host name of authority (e.g. :authority header field) in requests. +func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) TransportCredentials { + return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}) +} + +// NewClientTLSFromFile constructs TLS credentials from the input certificate file for client. +// serverNameOverride is for testing only. If set to a non empty string, +// it will override the virtual host name of authority (e.g. :authority header field) in requests. +func NewClientTLSFromFile(certFile, serverNameOverride string) (TransportCredentials, error) { + b, err := ioutil.ReadFile(certFile) + if err != nil { + return nil, err + } + cp := x509.NewCertPool() + if !cp.AppendCertsFromPEM(b) { + return nil, fmt.Errorf("credentials: failed to append certificates") + } + return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}), nil +} + +// NewServerTLSFromCert constructs TLS credentials from the input certificate for server. +func NewServerTLSFromCert(cert *tls.Certificate) TransportCredentials { + return NewTLS(&tls.Config{Certificates: []tls.Certificate{*cert}}) +} + +// NewServerTLSFromFile constructs TLS credentials from the input certificate file and key +// file for server. +func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error) { + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + if err != nil { + return nil, err + } + return NewTLS(&tls.Config{Certificates: []tls.Certificate{cert}}), nil +} + +// ChannelzSecurityInfo defines the interface that security protocols should implement +// in order to provide security info to channelz. +type ChannelzSecurityInfo interface { + GetSecurityValue() ChannelzSecurityValue +} + +// ChannelzSecurityValue defines the interface that GetSecurityValue() return value +// should satisfy. This interface should only be satisfied by *TLSChannelzSecurityValue +// and *OtherChannelzSecurityValue. +type ChannelzSecurityValue interface { + isChannelzSecurityValue() +} + +// TLSChannelzSecurityValue defines the struct that TLS protocol should return +// from GetSecurityValue(), containing security info like cipher and certificate used. +type TLSChannelzSecurityValue struct { + StandardName string + LocalCertificate []byte + RemoteCertificate []byte +} + +func (*TLSChannelzSecurityValue) isChannelzSecurityValue() {} + +// OtherChannelzSecurityValue defines the struct that non-TLS protocol should return +// from GetSecurityValue(), which contains protocol specific security info. Note +// the Value field will be sent to users of channelz requesting channel info, and +// thus sensitive info should better be avoided. +type OtherChannelzSecurityValue struct { + Name string + Value proto.Message +} + +func (*OtherChannelzSecurityValue) isChannelzSecurityValue() {} + +var cipherSuiteLookup = map[uint16]string{ + tls.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA", + tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA", + tls.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA", + tls.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA", + tls.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256", + tls.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384", + tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA", + tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + tls.TLS_FALLBACK_SCSV: "TLS_FALLBACK_SCSV", + tls.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", +} + +// cloneTLSConfig returns a shallow clone of the exported +// fields of cfg, ignoring the unexported sync.Once, which +// contains a mutex and must not be copied. +// +// If cfg is nil, a new zero tls.Config is returned. +// +// TODO: inline this function if possible. +func cloneTLSConfig(cfg *tls.Config) *tls.Config { + if cfg == nil { + return &tls.Config{} + } + + return cfg.Clone() +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go new file mode 100644 index 00000000..2f4472be --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn.go @@ -0,0 +1,61 @@ +// +build !appengine + +/* + * + * 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 internal contains credentials-internal code. +package internal + +import ( + "net" + "syscall" +) + +type sysConn = syscall.Conn + +// syscallConn keeps reference of rawConn to support syscall.Conn for channelz. +// SyscallConn() (the method in interface syscall.Conn) is explicitly +// implemented on this type, +// +// Interface syscall.Conn is implemented by most net.Conn implementations (e.g. +// TCPConn, UnixConn), but is not part of net.Conn interface. So wrapper conns +// that embed net.Conn don't implement syscall.Conn. (Side note: tls.Conn +// doesn't embed net.Conn, so even if syscall.Conn is part of net.Conn, it won't +// help here). +type syscallConn struct { + net.Conn + // sysConn is a type alias of syscall.Conn. It's necessary because the name + // `Conn` collides with `net.Conn`. + sysConn +} + +// WrapSyscallConn tries to wrap rawConn and newConn into a net.Conn that +// implements syscall.Conn. rawConn will be used to support syscall, and newConn +// will be used for read/write. +// +// This function returns newConn if rawConn doesn't implement syscall.Conn. +func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn { + sysConn, ok := rawConn.(syscall.Conn) + if !ok { + return newConn + } + return &syscallConn{ + Conn: newConn, + sysConn: sysConn, + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go new file mode 100644 index 00000000..d4346e9e --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/credentials/internal/syscallconn_appengine.go @@ -0,0 +1,30 @@ +// +build appengine + +/* + * + * 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 internal + +import ( + "net" +) + +// WrapSyscallConn returns newConn on appengine. +func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn { + return newConn +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go new file mode 100644 index 00000000..fe00a254 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/dialoptions.go @@ -0,0 +1,480 @@ +/* + * + * 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 grpc + +import ( + "context" + "fmt" + "net" + "time" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/internal" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/envconfig" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/resolver" + "google.golang.org/grpc/stats" +) + +// dialOptions configure a Dial call. dialOptions are set by the DialOption +// values passed to Dial. +type dialOptions struct { + unaryInt UnaryClientInterceptor + streamInt StreamClientInterceptor + cp Compressor + dc Decompressor + bs backoff.Strategy + block bool + insecure bool + timeout time.Duration + scChan <-chan ServiceConfig + authority string + copts transport.ConnectOptions + callOptions []CallOption + // This is used by v1 balancer dial option WithBalancer to support v1 + // balancer, and also by WithBalancerName dial option. + balancerBuilder balancer.Builder + // This is to support grpclb. + resolverBuilder resolver.Builder + reqHandshake envconfig.RequireHandshakeSetting + channelzParentID int64 + disableServiceConfig bool + disableRetry bool + disableHealthCheck bool +} + +// DialOption configures how we set up the connection. +type DialOption interface { + apply(*dialOptions) +} + +// EmptyDialOption does not alter the dial configuration. It can be embedded in +// another structure to build custom dial options. +// +// This API is EXPERIMENTAL. +type EmptyDialOption struct{} + +func (EmptyDialOption) apply(*dialOptions) {} + +// funcDialOption wraps a function that modifies dialOptions into an +// implementation of the DialOption interface. +type funcDialOption struct { + f func(*dialOptions) +} + +func (fdo *funcDialOption) apply(do *dialOptions) { + fdo.f(do) +} + +func newFuncDialOption(f func(*dialOptions)) *funcDialOption { + return &funcDialOption{ + f: f, + } +} + +// WithWaitForHandshake blocks until the initial settings frame is received from +// the server before assigning RPCs to the connection. +// +// Deprecated: this will become the default behavior in the 1.17 release, and +// will be removed after the 1.18 release. To override the default behavior in +// the 1.17 release, either use this dial option or set the environment +// variable GRPC_GO_READY_BEFORE_HANDSHAKE=on. +func WithWaitForHandshake() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.reqHandshake = envconfig.RequireHandshakeOn + }) +} + +// WithWriteBufferSize determines how much data can be batched before doing a +// write on the wire. The corresponding memory allocation for this buffer will +// be twice the size to keep syscalls low. The default value for this buffer is +// 32KB. +// +// Zero will disable the write buffer such that each write will be on underlying +// connection. Note: A Send call may not directly translate to a write. +func WithWriteBufferSize(s int) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.WriteBufferSize = s + }) +} + +// WithReadBufferSize lets you set the size of read buffer, this determines how +// much data can be read at most for each read syscall. +// +// The default value for this buffer is 32KB. Zero will disable read buffer for +// a connection so data framer can access the underlying conn directly. +func WithReadBufferSize(s int) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.ReadBufferSize = s + }) +} + +// WithInitialWindowSize returns a DialOption which sets the value for initial +// window size on a stream. The lower bound for window size is 64K and any value +// smaller than that will be ignored. +func WithInitialWindowSize(s int32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.InitialWindowSize = s + }) +} + +// WithInitialConnWindowSize returns a DialOption which sets the value for +// initial window size on a connection. The lower bound for window size is 64K +// and any value smaller than that will be ignored. +func WithInitialConnWindowSize(s int32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.InitialConnWindowSize = s + }) +} + +// WithMaxMsgSize returns a DialOption which sets the maximum message size the +// client can receive. +// +// Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead. +func WithMaxMsgSize(s int) DialOption { + return WithDefaultCallOptions(MaxCallRecvMsgSize(s)) +} + +// WithDefaultCallOptions returns a DialOption which sets the default +// CallOptions for calls over the connection. +func WithDefaultCallOptions(cos ...CallOption) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.callOptions = append(o.callOptions, cos...) + }) +} + +// WithCodec returns a DialOption which sets a codec for message marshaling and +// unmarshaling. +// +// Deprecated: use WithDefaultCallOptions(CallCustomCodec(c)) instead. +func WithCodec(c Codec) DialOption { + return WithDefaultCallOptions(CallCustomCodec(c)) +} + +// WithCompressor returns a DialOption which sets a Compressor to use for +// message compression. It has lower priority than the compressor set by the +// UseCompressor CallOption. +// +// Deprecated: use UseCompressor instead. +func WithCompressor(cp Compressor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.cp = cp + }) +} + +// WithDecompressor returns a DialOption which sets a Decompressor to use for +// incoming message decompression. If incoming response messages are encoded +// using the decompressor's Type(), it will be used. Otherwise, the message +// encoding will be used to look up the compressor registered via +// encoding.RegisterCompressor, which will then be used to decompress the +// message. If no compressor is registered for the encoding, an Unimplemented +// status error will be returned. +// +// Deprecated: use encoding.RegisterCompressor instead. +func WithDecompressor(dc Decompressor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.dc = dc + }) +} + +// WithBalancer returns a DialOption which sets a load balancer with the v1 API. +// Name resolver will be ignored if this DialOption is specified. +// +// Deprecated: use the new balancer APIs in balancer package and +// WithBalancerName. +func WithBalancer(b Balancer) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.balancerBuilder = &balancerWrapperBuilder{ + b: b, + } + }) +} + +// WithBalancerName sets the balancer that the ClientConn will be initialized +// with. Balancer registered with balancerName will be used. This function +// panics if no balancer was registered by balancerName. +// +// The balancer cannot be overridden by balancer option specified by service +// config. +// +// This is an EXPERIMENTAL API. +func WithBalancerName(balancerName string) DialOption { + builder := balancer.Get(balancerName) + if builder == nil { + panic(fmt.Sprintf("grpc.WithBalancerName: no balancer is registered for name %v", balancerName)) + } + return newFuncDialOption(func(o *dialOptions) { + o.balancerBuilder = builder + }) +} + +// withResolverBuilder is only for grpclb. +func withResolverBuilder(b resolver.Builder) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.resolverBuilder = b + }) +} + +// WithServiceConfig returns a DialOption which has a channel to read the +// service configuration. +// +// Deprecated: service config should be received through name resolver, as +// specified here. +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +func WithServiceConfig(c <-chan ServiceConfig) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.scChan = c + }) +} + +// WithBackoffMaxDelay configures the dialer to use the provided maximum delay +// when backing off after failed connection attempts. +func WithBackoffMaxDelay(md time.Duration) DialOption { + return WithBackoffConfig(BackoffConfig{MaxDelay: md}) +} + +// WithBackoffConfig configures the dialer to use the provided backoff +// parameters after connection failures. +// +// Use WithBackoffMaxDelay until more parameters on BackoffConfig are opened up +// for use. +func WithBackoffConfig(b BackoffConfig) DialOption { + return withBackoff(backoff.Exponential{ + MaxDelay: b.MaxDelay, + }) +} + +// withBackoff sets the backoff strategy used for connectRetryNum after a failed +// connection attempt. +// +// This can be exported if arbitrary backoff strategies are allowed by gRPC. +func withBackoff(bs backoff.Strategy) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.bs = bs + }) +} + +// WithBlock returns a DialOption which makes caller of Dial blocks until the +// underlying connection is up. Without this, Dial returns immediately and +// connecting the server happens in background. +func WithBlock() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.block = true + }) +} + +// WithInsecure returns a DialOption which disables transport security for this +// ClientConn. Note that transport security is required unless WithInsecure is +// set. +func WithInsecure() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.insecure = true + }) +} + +// WithTransportCredentials returns a DialOption which configures a connection +// level security credentials (e.g., TLS/SSL). This should not be used together +// with WithCredentialsBundle. +func WithTransportCredentials(creds credentials.TransportCredentials) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.TransportCredentials = creds + }) +} + +// WithPerRPCCredentials returns a DialOption which sets credentials and places +// auth state on each outbound RPC. +func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.PerRPCCredentials = append(o.copts.PerRPCCredentials, creds) + }) +} + +// WithCredentialsBundle returns a DialOption to set a credentials bundle for +// the ClientConn.WithCreds. This should not be used together with +// WithTransportCredentials. +// +// This API is experimental. +func WithCredentialsBundle(b credentials.Bundle) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.CredsBundle = b + }) +} + +// WithTimeout returns a DialOption that configures a timeout for dialing a +// ClientConn initially. This is valid if and only if WithBlock() is present. +// +// Deprecated: use DialContext and context.WithTimeout instead. +func WithTimeout(d time.Duration) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.timeout = d + }) +} + +func withContextDialer(f func(context.Context, string) (net.Conn, error)) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.Dialer = f + }) +} + +func init() { + internal.WithContextDialer = withContextDialer + internal.WithResolverBuilder = withResolverBuilder +} + +// WithDialer returns a DialOption that specifies a function to use for dialing +// network addresses. If FailOnNonTempDialError() is set to true, and an error +// is returned by f, gRPC checks the error's Temporary() method to decide if it +// should try to reconnect to the network address. +func WithDialer(f func(string, time.Duration) (net.Conn, error)) DialOption { + return withContextDialer( + func(ctx context.Context, addr string) (net.Conn, error) { + if deadline, ok := ctx.Deadline(); ok { + return f(addr, deadline.Sub(time.Now())) + } + return f(addr, 0) + }) +} + +// WithStatsHandler returns a DialOption that specifies the stats handler for +// all the RPCs and underlying network connections in this ClientConn. +func WithStatsHandler(h stats.Handler) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.StatsHandler = h + }) +} + +// FailOnNonTempDialError returns a DialOption that specifies if gRPC fails on +// non-temporary dial errors. If f is true, and dialer returns a non-temporary +// error, gRPC will fail the connection to the network address and won't try to +// reconnect. The default value of FailOnNonTempDialError is false. +// +// FailOnNonTempDialError only affects the initial dial, and does not do +// anything useful unless you are also using WithBlock(). +// +// This is an EXPERIMENTAL API. +func FailOnNonTempDialError(f bool) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.FailOnNonTempDialError = f + }) +} + +// WithUserAgent returns a DialOption that specifies a user agent string for all +// the RPCs. +func WithUserAgent(s string) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.UserAgent = s + }) +} + +// WithKeepaliveParams returns a DialOption that specifies keepalive parameters +// for the client transport. +func WithKeepaliveParams(kp keepalive.ClientParameters) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.KeepaliveParams = kp + }) +} + +// WithUnaryInterceptor returns a DialOption that specifies the interceptor for +// unary RPCs. +func WithUnaryInterceptor(f UnaryClientInterceptor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.unaryInt = f + }) +} + +// WithStreamInterceptor returns a DialOption that specifies the interceptor for +// streaming RPCs. +func WithStreamInterceptor(f StreamClientInterceptor) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.streamInt = f + }) +} + +// WithAuthority returns a DialOption that specifies the value to be used as the +// :authority pseudo-header. This value only works with WithInsecure and has no +// effect if TransportCredentials are present. +func WithAuthority(a string) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.authority = a + }) +} + +// WithChannelzParentID returns a DialOption that specifies the channelz ID of +// current ClientConn's parent. This function is used in nested channel creation +// (e.g. grpclb dial). +func WithChannelzParentID(id int64) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.channelzParentID = id + }) +} + +// WithDisableServiceConfig returns a DialOption that causes grpc to ignore any +// service config provided by the resolver and provides a hint to the resolver +// to not fetch service configs. +func WithDisableServiceConfig() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableServiceConfig = true + }) +} + +// WithDisableRetry returns a DialOption that disables retries, even if the +// service config enables them. This does not impact transparent retries, which +// will happen automatically if no data is written to the wire or if the RPC is +// unprocessed by the remote server. +// +// Retry support is currently disabled by default, but will be enabled by +// default in the future. Until then, it may be enabled by setting the +// environment variable "GRPC_GO_RETRY" to "on". +// +// This API is EXPERIMENTAL. +func WithDisableRetry() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableRetry = true + }) +} + +// WithMaxHeaderListSize returns a DialOption that specifies the maximum +// (uncompressed) size of header list that the client is prepared to accept. +func WithMaxHeaderListSize(s uint32) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.copts.MaxHeaderListSize = &s + }) +} + +// WithDisableHealthCheck disables the LB channel health checking for all SubConns of this ClientConn. +// +// This API is EXPERIMENTAL. +func WithDisableHealthCheck() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.disableHealthCheck = true + }) +} +func defaultDialOptions() dialOptions { + return dialOptions{ + disableRetry: !envconfig.Retry, + reqHandshake: envconfig.RequireHandshake, + copts: transport.ConnectOptions{ + WriteBufferSize: defaultWriteBufSize, + ReadBufferSize: defaultReadBufSize, + }, + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/doc.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/doc.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/doc.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/doc.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/encoding.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/encoding.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/encoding.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/encoding.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/proto/proto.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/proto/proto.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/encoding/proto/proto.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/encoding/proto/proto.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod new file mode 100644 index 00000000..f296dcf4 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.mod @@ -0,0 +1,20 @@ +module google.golang.org/grpc + +require ( + cloud.google.com/go v0.26.0 // indirect + github.com/client9/misspell v0.3.4 + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b + github.com/golang/mock v1.1.1 + github.com/golang/protobuf v1.2.0 + github.com/kisielk/gotool v1.0.0 // indirect + golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 + golang.org/x/net v0.0.0-20180826012351-8a410e7b638d + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be + golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect + golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 + golang.org/x/text v0.3.0 // indirect + golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 + google.golang.org/appengine v1.1.0 // indirect + google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 + honnef.co/go/tools v0.0.0-20180728063816-88497007e858 +) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum new file mode 100644 index 00000000..bfb6bb7c --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/go.sum @@ -0,0 +1,32 @@ +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/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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 h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/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-20180828015842-6cd1fcedba52 h1:JG/0uqcGdTNgq7FdU+61l5Pdmb8putNZlXb65bJBROs= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858 h1:wN+eVZ7U+gqdqkec6C6VXR1OFf9a5Ul9ETzeYsYv20g= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/grpclog.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/grpclog.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/grpclog.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/grpclog.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/logger.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/logger.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/logger.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/loggerv2.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/loggerv2.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/grpclog/loggerv2.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/grpclog/loggerv2.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/install_gae.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/install_gae.sh similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/install_gae.sh rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/install_gae.sh diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go new file mode 100644 index 00000000..8b735002 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/interceptor.go @@ -0,0 +1,77 @@ +/* + * + * Copyright 2016 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 grpc + +import ( + "context" +) + +// UnaryInvoker is called by UnaryClientInterceptor to complete RPCs. +type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error + +// UnaryClientInterceptor intercepts the execution of a unary RPC on the client. invoker is the handler to complete the RPC +// and it is the responsibility of the interceptor to call it. +// This is an EXPERIMENTAL API. +type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error + +// Streamer is called by StreamClientInterceptor to create a ClientStream. +type Streamer func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) + +// StreamClientInterceptor intercepts the creation of ClientStream. It may return a custom ClientStream to intercept all I/O +// operations. streamer is the handler to create a ClientStream and it is the responsibility of the interceptor to call it. +// This is an EXPERIMENTAL API. +type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error) + +// UnaryServerInfo consists of various information about a unary RPC on +// server side. All per-rpc information may be mutated by the interceptor. +type UnaryServerInfo struct { + // Server is the service implementation the user provides. This is read-only. + Server interface{} + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string +} + +// UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal +// execution of a unary RPC. If a UnaryHandler returns an error, it should be produced by the +// status package, or else gRPC will use codes.Unknown as the status code and err.Error() as +// the status message of the RPC. +type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error) + +// UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info +// contains all the information of this RPC the interceptor can operate on. And handler is the wrapper +// of the service method implementation. It is the responsibility of the interceptor to invoke handler +// to complete the RPC. +type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error) + +// StreamServerInfo consists of various information about a streaming RPC on +// server side. All per-rpc information may be mutated by the interceptor. +type StreamServerInfo struct { + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // IsClientStream indicates whether the RPC is a client streaming RPC. + IsClientStream bool + // IsServerStream indicates whether the RPC is a server streaming RPC. + IsServerStream bool +} + +// StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server. +// info contains all the information of this RPC the interceptor can operate on. And handler is the +// service method implementation. It is the responsibility of the interceptor to invoke handler to +// complete the RPC. +type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/backoff/backoff.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/backoff/backoff.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/backoff/backoff.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/backoff/backoff.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go new file mode 100644 index 00000000..fee6aecd --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog.go @@ -0,0 +1,167 @@ +/* + * + * 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 binarylog implementation binary logging as defined in +// https://github.com/grpc/proposal/blob/master/A16-binary-logging.md. +package binarylog + +import ( + "fmt" + "os" + + "google.golang.org/grpc/grpclog" +) + +// Logger is the global binary logger. It can be used to get binary logger for +// each method. +type Logger interface { + getMethodLogger(methodName string) *MethodLogger +} + +// binLogger is the global binary logger for the binary. One of this should be +// built at init time from the configuration (environment varialbe or flags). +// +// It is used to get a methodLogger for each individual method. +var binLogger Logger + +// SetLogger sets the binarg logger. +// +// Only call this at init time. +func SetLogger(l Logger) { + binLogger = l +} + +// GetMethodLogger returns the methodLogger for the given methodName. +// +// methodName should be in the format of "/service/method". +// +// Each methodLogger returned by this method is a new instance. This is to +// generate sequence id within the call. +func GetMethodLogger(methodName string) *MethodLogger { + if binLogger == nil { + return nil + } + return binLogger.getMethodLogger(methodName) +} + +func init() { + const envStr = "GRPC_BINARY_LOG_FILTER" + configStr := os.Getenv(envStr) + binLogger = NewLoggerFromConfigString(configStr) +} + +type methodLoggerConfig struct { + // Max length of header and message. + hdr, msg uint64 +} + +type logger struct { + all *methodLoggerConfig + services map[string]*methodLoggerConfig + methods map[string]*methodLoggerConfig + + blacklist map[string]struct{} +} + +// newEmptyLogger creates an empty logger. The map fields need to be filled in +// using the set* functions. +func newEmptyLogger() *logger { + return &logger{} +} + +// Set method logger for "*". +func (l *logger) setDefaultMethodLogger(ml *methodLoggerConfig) error { + if l.all != nil { + return fmt.Errorf("conflicting global rules found") + } + l.all = ml + return nil +} + +// Set method logger for "service/*". +// +// New methodLogger with same service overrides the old one. +func (l *logger) setServiceMethodLogger(service string, ml *methodLoggerConfig) error { + if _, ok := l.services[service]; ok { + return fmt.Errorf("conflicting rules for service %v found", service) + } + if l.services == nil { + l.services = make(map[string]*methodLoggerConfig) + } + l.services[service] = ml + return nil +} + +// Set method logger for "service/method". +// +// New methodLogger with same method overrides the old one. +func (l *logger) setMethodMethodLogger(method string, ml *methodLoggerConfig) error { + if _, ok := l.blacklist[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if _, ok := l.methods[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if l.methods == nil { + l.methods = make(map[string]*methodLoggerConfig) + } + l.methods[method] = ml + return nil +} + +// Set blacklist method for "-service/method". +func (l *logger) setBlacklist(method string) error { + if _, ok := l.blacklist[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if _, ok := l.methods[method]; ok { + return fmt.Errorf("conflicting rules for method %v found", method) + } + if l.blacklist == nil { + l.blacklist = make(map[string]struct{}) + } + l.blacklist[method] = struct{}{} + return nil +} + +// getMethodLogger returns the methodLogger for the given methodName. +// +// methodName should be in the format of "/service/method". +// +// Each methodLogger returned by this method is a new instance. This is to +// generate sequence id within the call. +func (l *logger) getMethodLogger(methodName string) *MethodLogger { + s, m, err := parseMethodName(methodName) + if err != nil { + grpclog.Infof("binarylogging: failed to parse %q: %v", methodName, err) + return nil + } + if ml, ok := l.methods[s+"/"+m]; ok { + return newMethodLogger(ml.hdr, ml.msg) + } + if _, ok := l.blacklist[s+"/"+m]; ok { + return nil + } + if ml, ok := l.services[s]; ok { + return newMethodLogger(ml.hdr, ml.msg) + } + if l.all == nil { + return nil + } + return newMethodLogger(l.all.hdr, l.all.msg) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go new file mode 100644 index 00000000..1ee00a39 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/binarylog_testutil.go @@ -0,0 +1,42 @@ +/* + * + * 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. + * + */ + +// This file contains exported variables/functions that are exported for testing +// only. +// +// An ideal way for this would be to put those in a *_test.go but in binarylog +// package. But this doesn't work with staticcheck with go module. Error was: +// "MdToMetadataProto not declared by package binarylog". This could be caused +// by the way staticcheck looks for files for a certain package, which doesn't +// support *_test.go files. +// +// Move those to binary_test.go when staticcheck is fixed. + +package binarylog + +var ( + // AllLogger is a logger that logs all headers/messages for all RPCs. It's + // for testing only. + AllLogger = NewLoggerFromConfigString("*") + // MdToMetadataProto converts metadata to a binary logging proto message. + // It's for testing only. + MdToMetadataProto = mdToMetadataProto + // AddrToProto converts an address to a binary logging proto message. It's + // for testing only. + AddrToProto = addrToProto +) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go new file mode 100644 index 00000000..eb188eae --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/env_config.go @@ -0,0 +1,210 @@ +/* + * + * 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 binarylog + +import ( + "errors" + "fmt" + "regexp" + "strconv" + "strings" + + "google.golang.org/grpc/grpclog" +) + +// NewLoggerFromConfigString reads the string and build a logger. It can be used +// to build a new logger and assign it to binarylog.Logger. +// +// Example filter config strings: +// - "" Nothing will be logged +// - "*" All headers and messages will be fully logged. +// - "*{h}" Only headers will be logged. +// - "*{m:256}" Only the first 256 bytes of each message will be logged. +// - "Foo/*" Logs every method in service Foo +// - "Foo/*,-Foo/Bar" Logs every method in service Foo except method /Foo/Bar +// - "Foo/*,Foo/Bar{m:256}" Logs the first 256 bytes of each message in method +// /Foo/Bar, logs all headers and messages in every other method in service +// Foo. +// +// If two configs exist for one certain method or service, the one specified +// later overrides the privous config. +func NewLoggerFromConfigString(s string) Logger { + if s == "" { + return nil + } + l := newEmptyLogger() + methods := strings.Split(s, ",") + for _, method := range methods { + if err := l.fillMethodLoggerWithConfigString(method); err != nil { + grpclog.Warningf("failed to parse binary log config: %v", err) + return nil + } + } + return l +} + +// fillMethodLoggerWithConfigString parses config, creates methodLogger and adds +// it to the right map in the logger. +func (l *logger) fillMethodLoggerWithConfigString(config string) error { + // "" is invalid. + if config == "" { + return errors.New("empty string is not a valid method binary logging config") + } + + // "-service/method", blacklist, no * or {} allowed. + if config[0] == '-' { + s, m, suffix, err := parseMethodConfigAndSuffix(config[1:]) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + if m == "*" { + return fmt.Errorf("invalid config: %q, %v", config, "* not allowd in blacklist config") + } + if suffix != "" { + return fmt.Errorf("invalid config: %q, %v", config, "header/message limit not allowed in blacklist config") + } + if err := l.setBlacklist(s + "/" + m); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + return nil + } + + // "*{h:256;m:256}" + if config[0] == '*' { + hdr, msg, err := parseHeaderMessageLengthConfig(config[1:]) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + if err := l.setDefaultMethodLogger(&methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + return nil + } + + s, m, suffix, err := parseMethodConfigAndSuffix(config) + if err != nil { + return fmt.Errorf("invalid config: %q, %v", config, err) + } + hdr, msg, err := parseHeaderMessageLengthConfig(suffix) + if err != nil { + return fmt.Errorf("invalid header/message length config: %q, %v", suffix, err) + } + if m == "*" { + if err := l.setServiceMethodLogger(s, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + } else { + if err := l.setMethodMethodLogger(s+"/"+m, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil { + return fmt.Errorf("invalid config: %v", err) + } + } + return nil +} + +const ( + // TODO: this const is only used by env_config now. But could be useful for + // other config. Move to binarylog.go if necessary. + maxUInt = ^uint64(0) + + // For "p.s/m" plus any suffix. Suffix will be parsed again. See test for + // expected output. + longMethodConfigRegexpStr = `^([\w./]+)/((?:\w+)|[*])(.+)?$` + + // For suffix from above, "{h:123,m:123}". See test for expected output. + optionalLengthRegexpStr = `(?::(\d+))?` // Optional ":123". + headerConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `}$` + messageConfigRegexpStr = `^{m` + optionalLengthRegexpStr + `}$` + headerMessageConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `;m` + optionalLengthRegexpStr + `}$` +) + +var ( + longMethodConfigRegexp = regexp.MustCompile(longMethodConfigRegexpStr) + headerConfigRegexp = regexp.MustCompile(headerConfigRegexpStr) + messageConfigRegexp = regexp.MustCompile(messageConfigRegexpStr) + headerMessageConfigRegexp = regexp.MustCompile(headerMessageConfigRegexpStr) +) + +// Turn "service/method{h;m}" into "service", "method", "{h;m}". +func parseMethodConfigAndSuffix(c string) (service, method, suffix string, _ error) { + // Regexp result: + // + // in: "p.s/m{h:123,m:123}", + // out: []string{"p.s/m{h:123,m:123}", "p.s", "m", "{h:123,m:123}"}, + match := longMethodConfigRegexp.FindStringSubmatch(c) + if match == nil { + return "", "", "", fmt.Errorf("%q contains invalid substring", c) + } + service = match[1] + method = match[2] + suffix = match[3] + return +} + +// Turn "{h:123;m:345}" into 123, 345. +// +// Return maxUInt if length is unspecified. +func parseHeaderMessageLengthConfig(c string) (hdrLenStr, msgLenStr uint64, err error) { + if c == "" { + return maxUInt, maxUInt, nil + } + // Header config only. + if match := headerConfigRegexp.FindStringSubmatch(c); match != nil { + if s := match[1]; s != "" { + hdrLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("failed to convert %q to uint", s) + } + return hdrLenStr, 0, nil + } + return maxUInt, 0, nil + } + + // Message config only. + if match := messageConfigRegexp.FindStringSubmatch(c); match != nil { + if s := match[1]; s != "" { + msgLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + return 0, msgLenStr, nil + } + return 0, maxUInt, nil + } + + // Header and message config both. + if match := headerMessageConfigRegexp.FindStringSubmatch(c); match != nil { + // Both hdr and msg are specified, but one or two of them might be empty. + hdrLenStr = maxUInt + msgLenStr = maxUInt + if s := match[1]; s != "" { + hdrLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + } + if s := match[2]; s != "" { + msgLenStr, err = strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, 0, fmt.Errorf("Failed to convert %q to uint", s) + } + } + return hdrLenStr, msgLenStr, nil + } + return 0, 0, fmt.Errorf("%q contains invalid substring", c) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go new file mode 100644 index 00000000..b06cdd4d --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go @@ -0,0 +1,426 @@ +/* + * + * 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 binarylog + +import ( + "net" + "strings" + "sync/atomic" + "time" + + "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes" + pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +type callIDGenerator struct { + id uint64 +} + +func (g *callIDGenerator) next() uint64 { + id := atomic.AddUint64(&g.id, 1) + return id +} + +// reset is for testing only, and doesn't need to be thread safe. +func (g *callIDGenerator) reset() { + g.id = 0 +} + +var idGen callIDGenerator + +// MethodLogger is the sub-logger for each method. +type MethodLogger struct { + headerMaxLen, messageMaxLen uint64 + + callID uint64 + idWithinCallGen *callIDGenerator + + sink Sink // TODO(blog): make this plugable. +} + +func newMethodLogger(h, m uint64) *MethodLogger { + return &MethodLogger{ + headerMaxLen: h, + messageMaxLen: m, + + callID: idGen.next(), + idWithinCallGen: &callIDGenerator{}, + + sink: defaultSink, // TODO(blog): make it plugable. + } +} + +// Log creates a proto binary log entry, and logs it to the sink. +func (ml *MethodLogger) Log(c LogEntryConfig) { + m := c.toProto() + timestamp, _ := ptypes.TimestampProto(time.Now()) + m.Timestamp = timestamp + m.CallId = ml.callID + m.SequenceIdWithinCall = ml.idWithinCallGen.next() + + switch pay := m.Payload.(type) { + case *pb.GrpcLogEntry_ClientHeader: + m.PayloadTruncated = ml.truncateMetadata(pay.ClientHeader.GetMetadata()) + case *pb.GrpcLogEntry_ServerHeader: + m.PayloadTruncated = ml.truncateMetadata(pay.ServerHeader.GetMetadata()) + case *pb.GrpcLogEntry_Message: + m.PayloadTruncated = ml.truncateMessage(pay.Message) + } + + ml.sink.Write(m) +} + +func (ml *MethodLogger) truncateMetadata(mdPb *pb.Metadata) (truncated bool) { + if ml.headerMaxLen == maxUInt { + return false + } + var ( + bytesLimit = ml.headerMaxLen + index int + ) + // At the end of the loop, index will be the first entry where the total + // size is greater than the limit: + // + // len(entry[:index]) <= ml.hdr && len(entry[:index+1]) > ml.hdr. + for ; index < len(mdPb.Entry); index++ { + entry := mdPb.Entry[index] + if entry.Key == "grpc-trace-bin" { + // "grpc-trace-bin" is a special key. It's kept in the log entry, + // but not counted towards the size limit. + continue + } + currentEntryLen := uint64(len(entry.Value)) + if currentEntryLen > bytesLimit { + break + } + bytesLimit -= currentEntryLen + } + truncated = index < len(mdPb.Entry) + mdPb.Entry = mdPb.Entry[:index] + return truncated +} + +func (ml *MethodLogger) truncateMessage(msgPb *pb.Message) (truncated bool) { + if ml.messageMaxLen == maxUInt { + return false + } + if ml.messageMaxLen >= uint64(len(msgPb.Data)) { + return false + } + msgPb.Data = msgPb.Data[:ml.messageMaxLen] + return true +} + +// LogEntryConfig represents the configuration for binary log entry. +type LogEntryConfig interface { + toProto() *pb.GrpcLogEntry +} + +// ClientHeader configs the binary log entry to be a ClientHeader entry. +type ClientHeader struct { + OnClientSide bool + Header metadata.MD + MethodName string + Authority string + Timeout time.Duration + // PeerAddr is required only when it's on server side. + PeerAddr net.Addr +} + +func (c *ClientHeader) toProto() *pb.GrpcLogEntry { + // This function doesn't need to set all the fields (e.g. seq ID). The Log + // function will set the fields when necessary. + clientHeader := &pb.ClientHeader{ + Metadata: mdToMetadataProto(c.Header), + MethodName: c.MethodName, + Authority: c.Authority, + } + if c.Timeout > 0 { + clientHeader.Timeout = ptypes.DurationProto(c.Timeout) + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER, + Payload: &pb.GrpcLogEntry_ClientHeader{ + ClientHeader: clientHeader, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// ServerHeader configs the binary log entry to be a ServerHeader entry. +type ServerHeader struct { + OnClientSide bool + Header metadata.MD + // PeerAddr is required only when it's on client side. + PeerAddr net.Addr +} + +func (c *ServerHeader) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_HEADER, + Payload: &pb.GrpcLogEntry_ServerHeader{ + ServerHeader: &pb.ServerHeader{ + Metadata: mdToMetadataProto(c.Header), + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// ClientMessage configs the binary log entry to be a ClientMessage entry. +type ClientMessage struct { + OnClientSide bool + // Message can be a proto.Message or []byte. Other messages formats are not + // supported. + Message interface{} +} + +func (c *ClientMessage) toProto() *pb.GrpcLogEntry { + var ( + data []byte + err error + ) + if m, ok := c.Message.(proto.Message); ok { + data, err = proto.Marshal(m) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal proto message: %v", err) + } + } else if b, ok := c.Message.([]byte); ok { + data = b + } else { + grpclog.Infof("binarylogging: message to log is neither proto.message nor []byte") + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_MESSAGE, + Payload: &pb.GrpcLogEntry_Message{ + Message: &pb.Message{ + Length: uint32(len(data)), + Data: data, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ServerMessage configs the binary log entry to be a ServerMessage entry. +type ServerMessage struct { + OnClientSide bool + // Message can be a proto.Message or []byte. Other messages formats are not + // supported. + Message interface{} +} + +func (c *ServerMessage) toProto() *pb.GrpcLogEntry { + var ( + data []byte + err error + ) + if m, ok := c.Message.(proto.Message); ok { + data, err = proto.Marshal(m) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal proto message: %v", err) + } + } else if b, ok := c.Message.([]byte); ok { + data = b + } else { + grpclog.Infof("binarylogging: message to log is neither proto.message nor []byte") + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_MESSAGE, + Payload: &pb.GrpcLogEntry_Message{ + Message: &pb.Message{ + Length: uint32(len(data)), + Data: data, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ClientHalfClose configs the binary log entry to be a ClientHalfClose entry. +type ClientHalfClose struct { + OnClientSide bool +} + +func (c *ClientHalfClose) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CLIENT_HALF_CLOSE, + Payload: nil, // No payload here. + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// ServerTrailer configs the binary log entry to be a ServerTrailer entry. +type ServerTrailer struct { + OnClientSide bool + Trailer metadata.MD + // Err is the status error. + Err error + // PeerAddr is required only when it's on client side and the RPC is trailer + // only. + PeerAddr net.Addr +} + +func (c *ServerTrailer) toProto() *pb.GrpcLogEntry { + st, ok := status.FromError(c.Err) + if !ok { + grpclog.Info("binarylogging: error in trailer is not a status error") + } + var ( + detailsBytes []byte + err error + ) + stProto := st.Proto() + if stProto != nil && len(stProto.Details) != 0 { + detailsBytes, err = proto.Marshal(stProto) + if err != nil { + grpclog.Infof("binarylogging: failed to marshal status proto: %v", err) + } + } + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER, + Payload: &pb.GrpcLogEntry_Trailer{ + Trailer: &pb.Trailer{ + Metadata: mdToMetadataProto(c.Trailer), + StatusCode: uint32(st.Code()), + StatusMessage: st.Message(), + StatusDetails: detailsBytes, + }, + }, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + if c.PeerAddr != nil { + ret.Peer = addrToProto(c.PeerAddr) + } + return ret +} + +// Cancel configs the binary log entry to be a Cancel entry. +type Cancel struct { + OnClientSide bool +} + +func (c *Cancel) toProto() *pb.GrpcLogEntry { + ret := &pb.GrpcLogEntry{ + Type: pb.GrpcLogEntry_EVENT_TYPE_CANCEL, + Payload: nil, + } + if c.OnClientSide { + ret.Logger = pb.GrpcLogEntry_LOGGER_CLIENT + } else { + ret.Logger = pb.GrpcLogEntry_LOGGER_SERVER + } + return ret +} + +// metadataKeyOmit returns whether the metadata entry with this key should be +// omitted. +func metadataKeyOmit(key string) bool { + switch key { + case "lb-token", ":path", ":authority", "content-encoding", "content-type", "user-agent", "te": + return true + case "grpc-trace-bin": // grpc-trace-bin is special because it's visiable to users. + return false + } + if strings.HasPrefix(key, "grpc-") { + return true + } + return false +} + +func mdToMetadataProto(md metadata.MD) *pb.Metadata { + ret := &pb.Metadata{} + for k, vv := range md { + if metadataKeyOmit(k) { + continue + } + for _, v := range vv { + ret.Entry = append(ret.Entry, + &pb.MetadataEntry{ + Key: k, + Value: []byte(v), + }, + ) + } + } + return ret +} + +func addrToProto(addr net.Addr) *pb.Address { + ret := &pb.Address{} + switch a := addr.(type) { + case *net.TCPAddr: + if a.IP.To4() != nil { + ret.Type = pb.Address_TYPE_IPV4 + } else if a.IP.To16() != nil { + ret.Type = pb.Address_TYPE_IPV6 + } else { + ret.Type = pb.Address_TYPE_UNKNOWN + // Do not set address and port fields. + break + } + ret.Address = a.IP.String() + ret.IpPort = uint32(a.Port) + case *net.UnixAddr: + ret.Type = pb.Address_TYPE_UNIX + ret.Address = a.String() + default: + ret.Type = pb.Address_TYPE_UNKNOWN + } + return ret +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh new file mode 100644 index 00000000..113d40cb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/regenerate.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# 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. + +set -eux -o pipefail + +TMP=$(mktemp -d) + +function finish { + rm -rf "$TMP" +} +trap finish EXIT + +pushd "$TMP" +mkdir -p grpc/binarylog/grpc_binarylog_v1 +curl https://raw.githubusercontent.com/grpc/grpc-proto/master/grpc/binlog/v1/binarylog.proto > grpc/binarylog/grpc_binarylog_v1/binarylog.proto + +protoc --go_out=plugins=grpc,paths=source_relative:. -I. grpc/binarylog/grpc_binarylog_v1/*.proto +popd +rm -f ./grpc_binarylog_v1/*.pb.go +cp "$TMP"/grpc/binarylog/grpc_binarylog_v1/*.pb.go ../../binarylog/grpc_binarylog_v1/ + diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go new file mode 100644 index 00000000..20d044f0 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/sink.go @@ -0,0 +1,162 @@ +/* + * + * 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 binarylog + +import ( + "bufio" + "encoding/binary" + "fmt" + "io" + "io/ioutil" + "sync" + "time" + + "github.com/golang/protobuf/proto" + pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + "google.golang.org/grpc/grpclog" +) + +var ( + defaultSink Sink = &noopSink{} // TODO(blog): change this default (file in /tmp). +) + +// SetDefaultSink sets the sink where binary logs will be written to. +// +// Not thread safe. Only set during initialization. +func SetDefaultSink(s Sink) { + if defaultSink != nil { + defaultSink.Close() + } + defaultSink = s +} + +// Sink writes log entry into the binary log sink. +type Sink interface { + // Write will be called to write the log entry into the sink. + // + // It should be thread-safe so it can be called in parallel. + Write(*pb.GrpcLogEntry) error + // Close will be called when the Sink is replaced by a new Sink. + Close() error +} + +type noopSink struct{} + +func (ns *noopSink) Write(*pb.GrpcLogEntry) error { return nil } +func (ns *noopSink) Close() error { return nil } + +// newWriterSink creates a binary log sink with the given writer. +// +// Write() marshalls the proto message and writes it to the given writer. Each +// message is prefixed with a 4 byte big endian unsigned integer as the length. +// +// No buffer is done, Close() doesn't try to close the writer. +func newWriterSink(w io.Writer) *writerSink { + return &writerSink{out: w} +} + +type writerSink struct { + out io.Writer +} + +func (ws *writerSink) Write(e *pb.GrpcLogEntry) error { + b, err := proto.Marshal(e) + if err != nil { + grpclog.Infof("binary logging: failed to marshal proto message: %v", err) + } + hdr := make([]byte, 4) + binary.BigEndian.PutUint32(hdr, uint32(len(b))) + if _, err := ws.out.Write(hdr); err != nil { + return err + } + if _, err := ws.out.Write(b); err != nil { + return err + } + return nil +} + +func (ws *writerSink) Close() error { return nil } + +type bufWriteCloserSink struct { + mu sync.Mutex + closer io.Closer + out *writerSink // out is built on buf. + buf *bufio.Writer // buf is kept for flush. + + writeStartOnce sync.Once + writeTicker *time.Ticker +} + +func (fs *bufWriteCloserSink) Write(e *pb.GrpcLogEntry) error { + // Start the write loop when Write is called. + fs.writeStartOnce.Do(fs.startFlushGoroutine) + fs.mu.Lock() + if err := fs.out.Write(e); err != nil { + fs.mu.Unlock() + return err + } + fs.mu.Unlock() + return nil +} + +const ( + bufFlushDuration = 60 * time.Second +) + +func (fs *bufWriteCloserSink) startFlushGoroutine() { + fs.writeTicker = time.NewTicker(bufFlushDuration) + go func() { + for range fs.writeTicker.C { + fs.mu.Lock() + fs.buf.Flush() + fs.mu.Unlock() + } + }() +} + +func (fs *bufWriteCloserSink) Close() error { + if fs.writeTicker != nil { + fs.writeTicker.Stop() + } + fs.mu.Lock() + fs.buf.Flush() + fs.closer.Close() + fs.out.Close() + fs.mu.Unlock() + return nil +} + +func newBufWriteCloserSink(o io.WriteCloser) Sink { + bufW := bufio.NewWriter(o) + return &bufWriteCloserSink{ + closer: o, + out: newWriterSink(bufW), + buf: bufW, + } +} + +// NewTempFileSink creates a temp file and returns a Sink that writes to this +// file. +func NewTempFileSink() (Sink, error) { + tempFile, err := ioutil.TempFile("/tmp", "grpcgo_binarylog_*.txt") + if err != nil { + return nil, fmt.Errorf("failed to create temp file: %v", err) + } + return newBufWriteCloserSink(tempFile), nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go new file mode 100644 index 00000000..15dc7803 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/binarylog/util.go @@ -0,0 +1,41 @@ +/* + * + * 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 binarylog + +import ( + "errors" + "strings" +) + +// parseMethodName splits service and method from the input. It expects format +// "/service/method". +// +// TODO: move to internal/grpcutil. +func parseMethodName(methodName string) (service, method string, _ error) { + if !strings.HasPrefix(methodName, "/") { + return "", "", errors.New("invalid method name: should start with /") + } + methodName = methodName[1:] + + pos := strings.LastIndex(methodName, "/") + if pos < 0 { + return "", "", errors.New("invalid method name: suffix /method is missing") + } + return methodName[:pos], methodName[pos+1:], nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go new file mode 100644 index 00000000..3021a31a --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/funcs.go @@ -0,0 +1,668 @@ +/* + * + * 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 channelz defines APIs for enabling channelz service, entry +// registration/deletion, and accessing channelz data. It also defines channelz +// metric struct formats. +// +// All APIs in this package are experimental. +package channelz + +import ( + "sort" + "sync" + "sync/atomic" + "time" + + "google.golang.org/grpc/grpclog" +) + +const ( + defaultMaxTraceEntry int32 = 30 +) + +var ( + db dbWrapper + idGen idGenerator + // EntryPerPage defines the number of channelz entries to be shown on a web page. + EntryPerPage = 50 + curState int32 + maxTraceEntry = defaultMaxTraceEntry +) + +// TurnOn turns on channelz data collection. +func TurnOn() { + if !IsOn() { + NewChannelzStorage() + atomic.StoreInt32(&curState, 1) + } +} + +// IsOn returns whether channelz data collection is on. +func IsOn() bool { + return atomic.CompareAndSwapInt32(&curState, 1, 1) +} + +// SetMaxTraceEntry sets maximum number of trace entry per entity (i.e. channel/subchannel). +// Setting it to 0 will disable channel tracing. +func SetMaxTraceEntry(i int32) { + atomic.StoreInt32(&maxTraceEntry, i) +} + +// ResetMaxTraceEntryToDefault resets the maximum number of trace entry per entity to default. +func ResetMaxTraceEntryToDefault() { + atomic.StoreInt32(&maxTraceEntry, defaultMaxTraceEntry) +} + +func getMaxTraceEntry() int { + i := atomic.LoadInt32(&maxTraceEntry) + return int(i) +} + +// dbWarpper wraps around a reference to internal channelz data storage, and +// provide synchronized functionality to set and get the reference. +type dbWrapper struct { + mu sync.RWMutex + DB *channelMap +} + +func (d *dbWrapper) set(db *channelMap) { + d.mu.Lock() + d.DB = db + d.mu.Unlock() +} + +func (d *dbWrapper) get() *channelMap { + d.mu.RLock() + defer d.mu.RUnlock() + return d.DB +} + +// NewChannelzStorage initializes channelz data storage and id generator. +// +// Note: This function is exported for testing purpose only. User should not call +// it in most cases. +func NewChannelzStorage() { + db.set(&channelMap{ + topLevelChannels: make(map[int64]struct{}), + channels: make(map[int64]*channel), + listenSockets: make(map[int64]*listenSocket), + normalSockets: make(map[int64]*normalSocket), + servers: make(map[int64]*server), + subChannels: make(map[int64]*subChannel), + }) + idGen.reset() +} + +// GetTopChannels returns a slice of top channel's ChannelMetric, along with a +// boolean indicating whether there's more top channels to be queried for. +// +// The arg id specifies that only top channel with id at or above it will be included +// in the result. The returned slice is up to a length of EntryPerPage, and is +// sorted in ascending id order. +func GetTopChannels(id int64) ([]*ChannelMetric, bool) { + return db.get().GetTopChannels(id) +} + +// GetServers returns a slice of server's ServerMetric, along with a +// boolean indicating whether there's more servers to be queried for. +// +// The arg id specifies that only server with id at or above it will be included +// in the result. The returned slice is up to a length of EntryPerPage, and is +// sorted in ascending id order. +func GetServers(id int64) ([]*ServerMetric, bool) { + return db.get().GetServers(id) +} + +// GetServerSockets returns a slice of server's (identified by id) normal socket's +// SocketMetric, along with a boolean indicating whether there's more sockets to +// be queried for. +// +// The arg startID specifies that only sockets with id at or above it will be +// included in the result. The returned slice is up to a length of EntryPerPage, +// and is sorted in ascending id order. +func GetServerSockets(id int64, startID int64) ([]*SocketMetric, bool) { + return db.get().GetServerSockets(id, startID) +} + +// GetChannel returns the ChannelMetric for the channel (identified by id). +func GetChannel(id int64) *ChannelMetric { + return db.get().GetChannel(id) +} + +// GetSubChannel returns the SubChannelMetric for the subchannel (identified by id). +func GetSubChannel(id int64) *SubChannelMetric { + return db.get().GetSubChannel(id) +} + +// GetSocket returns the SocketInternalMetric for the socket (identified by id). +func GetSocket(id int64) *SocketMetric { + return db.get().GetSocket(id) +} + +// RegisterChannel registers the given channel c in channelz database with ref +// as its reference name, and add it to the child list of its parent (identified +// by pid). pid = 0 means no parent. It returns the unique channelz tracking id +// assigned to this channel. +func RegisterChannel(c Channel, pid int64, ref string) int64 { + id := idGen.genID() + cn := &channel{ + refName: ref, + c: c, + subChans: make(map[int64]string), + nestedChans: make(map[int64]string), + id: id, + pid: pid, + trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())}, + } + if pid == 0 { + db.get().addChannel(id, cn, true, pid, ref) + } else { + db.get().addChannel(id, cn, false, pid, ref) + } + return id +} + +// RegisterSubChannel registers the given channel c in channelz database with ref +// as its reference name, and add it to the child list of its parent (identified +// by pid). It returns the unique channelz tracking id assigned to this subchannel. +func RegisterSubChannel(c Channel, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a SubChannel's parent id cannot be 0") + return 0 + } + id := idGen.genID() + sc := &subChannel{ + refName: ref, + c: c, + sockets: make(map[int64]string), + id: id, + pid: pid, + trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())}, + } + db.get().addSubChannel(id, sc, pid, ref) + return id +} + +// RegisterServer registers the given server s in channelz database. It returns +// the unique channelz tracking id assigned to this server. +func RegisterServer(s Server, ref string) int64 { + id := idGen.genID() + svr := &server{ + refName: ref, + s: s, + sockets: make(map[int64]string), + listenSockets: make(map[int64]string), + id: id, + } + db.get().addServer(id, svr) + return id +} + +// RegisterListenSocket registers the given listen socket s in channelz database +// with ref as its reference name, and add it to the child list of its parent +// (identified by pid). It returns the unique channelz tracking id assigned to +// this listen socket. +func RegisterListenSocket(s Socket, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a ListenSocket's parent id cannot be 0") + return 0 + } + id := idGen.genID() + ls := &listenSocket{refName: ref, s: s, id: id, pid: pid} + db.get().addListenSocket(id, ls, pid, ref) + return id +} + +// RegisterNormalSocket registers the given normal socket s in channelz database +// with ref as its reference name, and add it to the child list of its parent +// (identified by pid). It returns the unique channelz tracking id assigned to +// this normal socket. +func RegisterNormalSocket(s Socket, pid int64, ref string) int64 { + if pid == 0 { + grpclog.Error("a NormalSocket's parent id cannot be 0") + return 0 + } + id := idGen.genID() + ns := &normalSocket{refName: ref, s: s, id: id, pid: pid} + db.get().addNormalSocket(id, ns, pid, ref) + return id +} + +// RemoveEntry removes an entry with unique channelz trakcing id to be id from +// channelz database. +func RemoveEntry(id int64) { + db.get().removeEntry(id) +} + +// TraceEventDesc is what the caller of AddTraceEvent should provide to describe the event to be added +// to the channel trace. +// The Parent field is optional. It is used for event that will be recorded in the entity's parent +// trace also. +type TraceEventDesc struct { + Desc string + Severity Severity + Parent *TraceEventDesc +} + +// AddTraceEvent adds trace related to the entity with specified id, using the provided TraceEventDesc. +func AddTraceEvent(id int64, desc *TraceEventDesc) { + if getMaxTraceEntry() == 0 { + return + } + db.get().traceEvent(id, desc) +} + +// channelMap is the storage data structure for channelz. +// Methods of channelMap can be divided in two two categories with respect to locking. +// 1. Methods acquire the global lock. +// 2. Methods that can only be called when global lock is held. +// A second type of method need always to be called inside a first type of method. +type channelMap struct { + mu sync.RWMutex + topLevelChannels map[int64]struct{} + servers map[int64]*server + channels map[int64]*channel + subChannels map[int64]*subChannel + listenSockets map[int64]*listenSocket + normalSockets map[int64]*normalSocket +} + +func (c *channelMap) addServer(id int64, s *server) { + c.mu.Lock() + s.cm = c + c.servers[id] = s + c.mu.Unlock() +} + +func (c *channelMap) addChannel(id int64, cn *channel, isTopChannel bool, pid int64, ref string) { + c.mu.Lock() + cn.cm = c + cn.trace.cm = c + c.channels[id] = cn + if isTopChannel { + c.topLevelChannels[id] = struct{}{} + } else { + c.findEntry(pid).addChild(id, cn) + } + c.mu.Unlock() +} + +func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64, ref string) { + c.mu.Lock() + sc.cm = c + sc.trace.cm = c + c.subChannels[id] = sc + c.findEntry(pid).addChild(id, sc) + c.mu.Unlock() +} + +func (c *channelMap) addListenSocket(id int64, ls *listenSocket, pid int64, ref string) { + c.mu.Lock() + ls.cm = c + c.listenSockets[id] = ls + c.findEntry(pid).addChild(id, ls) + c.mu.Unlock() +} + +func (c *channelMap) addNormalSocket(id int64, ns *normalSocket, pid int64, ref string) { + c.mu.Lock() + ns.cm = c + c.normalSockets[id] = ns + c.findEntry(pid).addChild(id, ns) + c.mu.Unlock() +} + +// removeEntry triggers the removal of an entry, which may not indeed delete the entry, if it has to +// wait on the deletion of its children and until no other entity's channel trace references it. +// It may lead to a chain of entry deletion. For example, deleting the last socket of a gracefully +// shutting down server will lead to the server being also deleted. +func (c *channelMap) removeEntry(id int64) { + c.mu.Lock() + c.findEntry(id).triggerDelete() + c.mu.Unlock() +} + +// c.mu must be held by the caller +func (c *channelMap) decrTraceRefCount(id int64) { + e := c.findEntry(id) + if v, ok := e.(tracedChannel); ok { + v.decrTraceRefCount() + e.deleteSelfIfReady() + } +} + +// c.mu must be held by the caller. +func (c *channelMap) findEntry(id int64) entry { + var v entry + var ok bool + if v, ok = c.channels[id]; ok { + return v + } + if v, ok = c.subChannels[id]; ok { + return v + } + if v, ok = c.servers[id]; ok { + return v + } + if v, ok = c.listenSockets[id]; ok { + return v + } + if v, ok = c.normalSockets[id]; ok { + return v + } + return &dummyEntry{idNotFound: id} +} + +// c.mu must be held by the caller +// deleteEntry simply deletes an entry from the channelMap. Before calling this +// method, caller must check this entry is ready to be deleted, i.e removeEntry() +// has been called on it, and no children still exist. +// Conditionals are ordered by the expected frequency of deletion of each entity +// type, in order to optimize performance. +func (c *channelMap) deleteEntry(id int64) { + var ok bool + if _, ok = c.normalSockets[id]; ok { + delete(c.normalSockets, id) + return + } + if _, ok = c.subChannels[id]; ok { + delete(c.subChannels, id) + return + } + if _, ok = c.channels[id]; ok { + delete(c.channels, id) + delete(c.topLevelChannels, id) + return + } + if _, ok = c.listenSockets[id]; ok { + delete(c.listenSockets, id) + return + } + if _, ok = c.servers[id]; ok { + delete(c.servers, id) + return + } +} + +func (c *channelMap) traceEvent(id int64, desc *TraceEventDesc) { + c.mu.Lock() + child := c.findEntry(id) + childTC, ok := child.(tracedChannel) + if !ok { + c.mu.Unlock() + return + } + childTC.getChannelTrace().append(&TraceEvent{Desc: desc.Desc, Severity: desc.Severity, Timestamp: time.Now()}) + if desc.Parent != nil { + parent := c.findEntry(child.getParentID()) + var chanType RefChannelType + switch child.(type) { + case *channel: + chanType = RefChannel + case *subChannel: + chanType = RefSubChannel + } + if parentTC, ok := parent.(tracedChannel); ok { + parentTC.getChannelTrace().append(&TraceEvent{ + Desc: desc.Parent.Desc, + Severity: desc.Parent.Severity, + Timestamp: time.Now(), + RefID: id, + RefName: childTC.getRefName(), + RefType: chanType, + }) + childTC.incrTraceRefCount() + } + } + c.mu.Unlock() +} + +type int64Slice []int64 + +func (s int64Slice) Len() int { return len(s) } +func (s int64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s int64Slice) Less(i, j int) bool { return s[i] < s[j] } + +func copyMap(m map[int64]string) map[int64]string { + n := make(map[int64]string) + for k, v := range m { + n[k] = v + } + return n +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func (c *channelMap) GetTopChannels(id int64) ([]*ChannelMetric, bool) { + c.mu.RLock() + l := len(c.topLevelChannels) + ids := make([]int64, 0, l) + cns := make([]*channel, 0, min(l, EntryPerPage)) + + for k := range c.topLevelChannels { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= id }) + count := 0 + var end bool + var t []*ChannelMetric + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if cn, ok := c.channels[v]; ok { + cns = append(cns, cn) + t = append(t, &ChannelMetric{ + NestedChans: copyMap(cn.nestedChans), + SubChans: copyMap(cn.subChans), + }) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + + for i, cn := range cns { + t[i].ChannelData = cn.c.ChannelzMetric() + t[i].ID = cn.id + t[i].RefName = cn.refName + t[i].Trace = cn.trace.dumpData() + } + return t, end +} + +func (c *channelMap) GetServers(id int64) ([]*ServerMetric, bool) { + c.mu.RLock() + l := len(c.servers) + ids := make([]int64, 0, l) + ss := make([]*server, 0, min(l, EntryPerPage)) + for k := range c.servers { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= id }) + count := 0 + var end bool + var s []*ServerMetric + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if svr, ok := c.servers[v]; ok { + ss = append(ss, svr) + s = append(s, &ServerMetric{ + ListenSockets: copyMap(svr.listenSockets), + }) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + + for i, svr := range ss { + s[i].ServerData = svr.s.ChannelzMetric() + s[i].ID = svr.id + s[i].RefName = svr.refName + } + return s, end +} + +func (c *channelMap) GetServerSockets(id int64, startID int64) ([]*SocketMetric, bool) { + var svr *server + var ok bool + c.mu.RLock() + if svr, ok = c.servers[id]; !ok { + // server with id doesn't exist. + c.mu.RUnlock() + return nil, true + } + svrskts := svr.sockets + l := len(svrskts) + ids := make([]int64, 0, l) + sks := make([]*normalSocket, 0, min(l, EntryPerPage)) + for k := range svrskts { + ids = append(ids, k) + } + sort.Sort(int64Slice(ids)) + idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= startID }) + count := 0 + var end bool + for i, v := range ids[idx:] { + if count == EntryPerPage { + break + } + if ns, ok := c.normalSockets[v]; ok { + sks = append(sks, ns) + count++ + } + if i == len(ids[idx:])-1 { + end = true + break + } + } + c.mu.RUnlock() + if count == 0 { + end = true + } + var s []*SocketMetric + for _, ns := range sks { + sm := &SocketMetric{} + sm.SocketData = ns.s.ChannelzMetric() + sm.ID = ns.id + sm.RefName = ns.refName + s = append(s, sm) + } + return s, end +} + +func (c *channelMap) GetChannel(id int64) *ChannelMetric { + cm := &ChannelMetric{} + var cn *channel + var ok bool + c.mu.RLock() + if cn, ok = c.channels[id]; !ok { + // channel with id doesn't exist. + c.mu.RUnlock() + return nil + } + cm.NestedChans = copyMap(cn.nestedChans) + cm.SubChans = copyMap(cn.subChans) + // cn.c can be set to &dummyChannel{} when deleteSelfFromMap is called. Save a copy of cn.c when + // holding the lock to prevent potential data race. + chanCopy := cn.c + c.mu.RUnlock() + cm.ChannelData = chanCopy.ChannelzMetric() + cm.ID = cn.id + cm.RefName = cn.refName + cm.Trace = cn.trace.dumpData() + return cm +} + +func (c *channelMap) GetSubChannel(id int64) *SubChannelMetric { + cm := &SubChannelMetric{} + var sc *subChannel + var ok bool + c.mu.RLock() + if sc, ok = c.subChannels[id]; !ok { + // subchannel with id doesn't exist. + c.mu.RUnlock() + return nil + } + cm.Sockets = copyMap(sc.sockets) + // sc.c can be set to &dummyChannel{} when deleteSelfFromMap is called. Save a copy of sc.c when + // holding the lock to prevent potential data race. + chanCopy := sc.c + c.mu.RUnlock() + cm.ChannelData = chanCopy.ChannelzMetric() + cm.ID = sc.id + cm.RefName = sc.refName + cm.Trace = sc.trace.dumpData() + return cm +} + +func (c *channelMap) GetSocket(id int64) *SocketMetric { + sm := &SocketMetric{} + c.mu.RLock() + if ls, ok := c.listenSockets[id]; ok { + c.mu.RUnlock() + sm.SocketData = ls.s.ChannelzMetric() + sm.ID = ls.id + sm.RefName = ls.refName + return sm + } + if ns, ok := c.normalSockets[id]; ok { + c.mu.RUnlock() + sm.SocketData = ns.s.ChannelzMetric() + sm.ID = ns.id + sm.RefName = ns.refName + return sm + } + c.mu.RUnlock() + return nil +} + +type idGenerator struct { + id int64 +} + +func (i *idGenerator) reset() { + atomic.StoreInt64(&i.id, 0) +} + +func (i *idGenerator) genID() int64 { + return atomic.AddInt64(&i.id, 1) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/channelz/types.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/channelz/types.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go new file mode 100644 index 00000000..692dd618 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_linux.go @@ -0,0 +1,53 @@ +// +build !appengine + +/* + * + * 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 channelz + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// SocketOptionData defines the struct to hold socket option data, and related +// getter function to obtain info from fd. +type SocketOptionData struct { + Linger *unix.Linger + RecvTimeout *unix.Timeval + SendTimeout *unix.Timeval + TCPInfo *unix.TCPInfo +} + +// Getsockopt defines the function to get socket options requested by channelz. +// It is to be passed to syscall.RawConn.Control(). +func (s *SocketOptionData) Getsockopt(fd uintptr) { + if v, err := unix.GetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER); err == nil { + s.Linger = v + } + if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVTIMEO); err == nil { + s.RecvTimeout = v + } + if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDTIMEO); err == nil { + s.SendTimeout = v + } + if v, err := unix.GetsockoptTCPInfo(int(fd), syscall.SOL_TCP, syscall.TCP_INFO); err == nil { + s.TCPInfo = v + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go new file mode 100644 index 00000000..79edbefc --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/types_nonlinux.go @@ -0,0 +1,44 @@ +// +build !linux appengine + +/* + * + * 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 channelz + +import ( + "sync" + + "google.golang.org/grpc/grpclog" +) + +var once sync.Once + +// SocketOptionData defines the struct to hold socket option data, and related +// getter function to obtain info from fd. +// Windows OS doesn't support Socket Option +type SocketOptionData struct { +} + +// Getsockopt defines the function to get socket options requested by channelz. +// It is to be passed to syscall.RawConn.Control(). +// Windows OS doesn't support Socket Option +func (s *SocketOptionData) Getsockopt(fd uintptr) { + once.Do(func() { + grpclog.Warningln("Channelz: socket options are not supported on non-linux os and appengine.") + }) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go new file mode 100644 index 00000000..fdf409d5 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_linux.go @@ -0,0 +1,39 @@ +// +build linux,!appengine + +/* + * + * 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 channelz + +import ( + "syscall" +) + +// GetSocketOption gets the socket option info of the conn. +func GetSocketOption(socket interface{}) *SocketOptionData { + c, ok := socket.(syscall.Conn) + if !ok { + return nil + } + data := &SocketOptionData{} + if rawConn, err := c.SyscallConn(); err == nil { + rawConn.Control(data.Getsockopt) + return data + } + return nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go new file mode 100644 index 00000000..8864a081 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/channelz/util_nonlinux.go @@ -0,0 +1,26 @@ +// +build !linux appengine + +/* + * + * 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 channelz + +// GetSocketOption gets the socket option info of the conn. +func GetSocketOption(c interface{}) *SocketOptionData { + return nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go new file mode 100644 index 00000000..a3e02b66 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go @@ -0,0 +1,69 @@ +/* + * + * 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 envconfig contains grpc settings configured by environment variables. +package envconfig + +import ( + "os" + "strings" +) + +const ( + prefix = "GRPC_GO_" + retryStr = prefix + "RETRY" + requireHandshakeStr = prefix + "REQUIRE_HANDSHAKE" +) + +// RequireHandshakeSetting describes the settings for handshaking. +type RequireHandshakeSetting int + +const ( + // RequireHandshakeHybrid (default, deprecated) indicates to wait for + // handshake before considering a connection ready, but wait before + // considering successful. + RequireHandshakeHybrid RequireHandshakeSetting = iota + // RequireHandshakeOn (default after the 1.17 release) indicates to wait + // for handshake before considering a connection ready/successful. + RequireHandshakeOn + // RequireHandshakeOff indicates to not wait for handshake before + // considering a connection ready/successful. + RequireHandshakeOff +) + +var ( + // Retry is set if retry is explicitly enabled via "GRPC_GO_RETRY=on". + Retry = strings.EqualFold(os.Getenv(retryStr), "on") + // RequireHandshake is set based upon the GRPC_GO_REQUIRE_HANDSHAKE + // environment variable. + // + // Will be removed after the 1.18 release. + RequireHandshake RequireHandshakeSetting +) + +func init() { + switch strings.ToLower(os.Getenv(requireHandshakeStr)) { + case "on": + RequireHandshake = RequireHandshakeOn + case "off": + RequireHandshake = RequireHandshakeOff + case "hybrid": + // Will be removed after the 1.17 release. + RequireHandshake = RequireHandshakeHybrid + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go new file mode 100644 index 00000000..fbe697c3 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/grpcsync/event.go @@ -0,0 +1,61 @@ +/* + * + * 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 grpcsync implements additional synchronization primitives built upon +// the sync package. +package grpcsync + +import ( + "sync" + "sync/atomic" +) + +// Event represents a one-time event that may occur in the future. +type Event struct { + fired int32 + c chan struct{} + o sync.Once +} + +// Fire causes e to complete. It is safe to call multiple times, and +// concurrently. It returns true iff this call to Fire caused the signaling +// channel returned by Done to close. +func (e *Event) Fire() bool { + ret := false + e.o.Do(func() { + atomic.StoreInt32(&e.fired, 1) + close(e.c) + ret = true + }) + return ret +} + +// Done returns a channel that will be closed when Fire is called. +func (e *Event) Done() <-chan struct{} { + return e.c +} + +// HasFired returns true if Fire has been called. +func (e *Event) HasFired() bool { + return atomic.LoadInt32(&e.fired) == 1 +} + +// NewEvent returns a new, ready-to-use Event. +func NewEvent() *Event { + return &Event{c: make(chan struct{})} +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go new file mode 100644 index 00000000..f8932b1d --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/internal.go @@ -0,0 +1,43 @@ +/* + * Copyright 2016 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 internal contains gRPC-internal code, to avoid polluting +// the godoc of the top-level grpc package. It must not import any grpc +// symbols to avoid circular dependencies. +package internal + +import "context" + +var ( + // WithContextDialer is exported by clientconn.go + WithContextDialer interface{} // func(context.Context, string) (net.Conn, error) grpc.DialOption + // WithResolverBuilder is exported by clientconn.go + WithResolverBuilder interface{} // func (resolver.Builder) grpc.DialOption + // HealthCheckFunc is used to provide client-side LB channel health checking + HealthCheckFunc func(ctx context.Context, newStream func() (interface{}, error), reportHealth func(bool), serviceName string) error +) + +const ( + // CredsBundleModeFallback switches GoogleDefaultCreds to fallback mode. + CredsBundleModeFallback = "fallback" + // CredsBundleModeBalancer switches GoogleDefaultCreds to grpclb balancer + // mode. + CredsBundleModeBalancer = "balancer" + // CredsBundleModeBackendFromBalancer switches GoogleDefaultCreds to mode + // that supports backend returned by grpclb balancer. + CredsBundleModeBackendFromBalancer = "backend-from-balancer" +) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go new file mode 100644 index 00000000..43281a3e --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_linux.go @@ -0,0 +1,114 @@ +// +build !appengine + +/* + * + * 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 syscall provides functionalities that grpc uses to get low-level operating system +// stats/info. +package syscall + +import ( + "fmt" + "net" + "syscall" + "time" + + "golang.org/x/sys/unix" + "google.golang.org/grpc/grpclog" +) + +// GetCPUTime returns the how much CPU time has passed since the start of this process. +func GetCPUTime() int64 { + var ts unix.Timespec + if err := unix.ClockGettime(unix.CLOCK_PROCESS_CPUTIME_ID, &ts); err != nil { + grpclog.Fatal(err) + } + return ts.Nano() +} + +// Rusage is an alias for syscall.Rusage under linux non-appengine environment. +type Rusage syscall.Rusage + +// GetRusage returns the resource usage of current process. +func GetRusage() (rusage *Rusage) { + rusage = new(Rusage) + syscall.Getrusage(syscall.RUSAGE_SELF, (*syscall.Rusage)(rusage)) + return +} + +// CPUTimeDiff returns the differences of user CPU time and system CPU time used +// between two Rusage structs. +func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) { + f := (*syscall.Rusage)(first) + l := (*syscall.Rusage)(latest) + var ( + utimeDiffs = l.Utime.Sec - f.Utime.Sec + utimeDiffus = l.Utime.Usec - f.Utime.Usec + stimeDiffs = l.Stime.Sec - f.Stime.Sec + stimeDiffus = l.Stime.Usec - f.Stime.Usec + ) + + uTimeElapsed := float64(utimeDiffs) + float64(utimeDiffus)*1.0e-6 + sTimeElapsed := float64(stimeDiffs) + float64(stimeDiffus)*1.0e-6 + + return uTimeElapsed, sTimeElapsed +} + +// SetTCPUserTimeout sets the TCP user timeout on a connection's socket +func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error { + tcpconn, ok := conn.(*net.TCPConn) + if !ok { + // not a TCP connection. exit early + return nil + } + rawConn, err := tcpconn.SyscallConn() + if err != nil { + return fmt.Errorf("error getting raw connection: %v", err) + } + err = rawConn.Control(func(fd uintptr) { + err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout/time.Millisecond)) + }) + if err != nil { + return fmt.Errorf("error setting option on socket: %v", err) + } + + return nil +} + +// GetTCPUserTimeout gets the TCP user timeout on a connection's socket +func GetTCPUserTimeout(conn net.Conn) (opt int, err error) { + tcpconn, ok := conn.(*net.TCPConn) + if !ok { + err = fmt.Errorf("conn is not *net.TCPConn. got %T", conn) + return + } + rawConn, err := tcpconn.SyscallConn() + if err != nil { + err = fmt.Errorf("error getting raw connection: %v", err) + return + } + err = rawConn.Control(func(fd uintptr) { + opt, err = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT) + }) + if err != nil { + err = fmt.Errorf("error getting option on socket: %v", err) + return + } + + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go new file mode 100644 index 00000000..61678feb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/syscall/syscall_nonlinux.go @@ -0,0 +1,63 @@ +// +build !linux appengine + +/* + * + * 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 syscall + +import ( + "net" + "time" + + "google.golang.org/grpc/grpclog" +) + +func init() { + grpclog.Info("CPU time info is unavailable on non-linux or appengine environment.") +} + +// GetCPUTime returns the how much CPU time has passed since the start of this process. +// It always returns 0 under non-linux or appengine environment. +func GetCPUTime() int64 { + return 0 +} + +// Rusage is an empty struct under non-linux or appengine environment. +type Rusage struct{} + +// GetRusage is a no-op function under non-linux or appengine environment. +func GetRusage() (rusage *Rusage) { + return nil +} + +// CPUTimeDiff returns the differences of user CPU time and system CPU time used +// between two Rusage structs. It a no-op function for non-linux or appengine environment. +func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) { + return 0, 0 +} + +// SetTCPUserTimeout is a no-op function under non-linux or appengine environments +func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error { + return nil +} + +// GetTCPUserTimeout is a no-op function under non-linux or appengine environments +// a negative return value indicates the operation is not supported +func GetTCPUserTimeout(conn net.Conn) (int, error) { + return -1, nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go new file mode 100644 index 00000000..070680ed --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/bdp_estimator.go @@ -0,0 +1,141 @@ +/* + * + * 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 transport + +import ( + "sync" + "time" +) + +const ( + // bdpLimit is the maximum value the flow control windows will be increased + // to. TCP typically limits this to 4MB, but some systems go up to 16MB. + // Since this is only a limit, it is safe to make it optimistic. + bdpLimit = (1 << 20) * 16 + // alpha is a constant factor used to keep a moving average + // of RTTs. + alpha = 0.9 + // If the current bdp sample is greater than or equal to + // our beta * our estimated bdp and the current bandwidth + // sample is the maximum bandwidth observed so far, we + // increase our bbp estimate by a factor of gamma. + beta = 0.66 + // To put our bdp to be smaller than or equal to twice the real BDP, + // we should multiply our current sample with 4/3, however to round things out + // we use 2 as the multiplication factor. + gamma = 2 +) + +// Adding arbitrary data to ping so that its ack can be identified. +// Easter-egg: what does the ping message say? +var bdpPing = &ping{data: [8]byte{2, 4, 16, 16, 9, 14, 7, 7}} + +type bdpEstimator struct { + // sentAt is the time when the ping was sent. + sentAt time.Time + + mu sync.Mutex + // bdp is the current bdp estimate. + bdp uint32 + // sample is the number of bytes received in one measurement cycle. + sample uint32 + // bwMax is the maximum bandwidth noted so far (bytes/sec). + bwMax float64 + // bool to keep track of the beginning of a new measurement cycle. + isSent bool + // Callback to update the window sizes. + updateFlowControl func(n uint32) + // sampleCount is the number of samples taken so far. + sampleCount uint64 + // round trip time (seconds) + rtt float64 +} + +// timesnap registers the time bdp ping was sent out so that +// network rtt can be calculated when its ack is received. +// It is called (by controller) when the bdpPing is +// being written on the wire. +func (b *bdpEstimator) timesnap(d [8]byte) { + if bdpPing.data != d { + return + } + b.sentAt = time.Now() +} + +// add adds bytes to the current sample for calculating bdp. +// It returns true only if a ping must be sent. This can be used +// by the caller (handleData) to make decision about batching +// a window update with it. +func (b *bdpEstimator) add(n uint32) bool { + b.mu.Lock() + defer b.mu.Unlock() + if b.bdp == bdpLimit { + return false + } + if !b.isSent { + b.isSent = true + b.sample = n + b.sentAt = time.Time{} + b.sampleCount++ + return true + } + b.sample += n + return false +} + +// calculate is called when an ack for a bdp ping is received. +// Here we calculate the current bdp and bandwidth sample and +// decide if the flow control windows should go up. +func (b *bdpEstimator) calculate(d [8]byte) { + // Check if the ping acked for was the bdp ping. + if bdpPing.data != d { + return + } + b.mu.Lock() + rttSample := time.Since(b.sentAt).Seconds() + if b.sampleCount < 10 { + // Bootstrap rtt with an average of first 10 rtt samples. + b.rtt += (rttSample - b.rtt) / float64(b.sampleCount) + } else { + // Heed to the recent past more. + b.rtt += (rttSample - b.rtt) * float64(alpha) + } + b.isSent = false + // The number of bytes accumulated so far in the sample is smaller + // than or equal to 1.5 times the real BDP on a saturated connection. + bwCurrent := float64(b.sample) / (b.rtt * float64(1.5)) + if bwCurrent > b.bwMax { + b.bwMax = bwCurrent + } + // If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is + // greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we + // should update our perception of the network BDP. + if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit { + sampleFloat := float64(b.sample) + b.bdp = uint32(gamma * sampleFloat) + if b.bdp > bdpLimit { + b.bdp = bdpLimit + } + bdp := b.bdp + b.mu.Unlock() + b.updateFlowControl(bdp) + return + } + b.mu.Unlock() +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/controlbuf.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/controlbuf.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/controlbuf.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/controlbuf.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/defaults.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/defaults.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/defaults.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/defaults.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go new file mode 100644 index 00000000..73b41ea7 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -0,0 +1,449 @@ +/* + * + * Copyright 2016 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. + * + */ + +// This file is the implementation of a gRPC server using HTTP/2 which +// uses the standard Go http2 Server implementation (via the +// http.Handler interface), rather than speaking low-level HTTP/2 +// frames itself. It is the implementation of *grpc.Server.ServeHTTP. + +package transport + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "net/http" + "strings" + "sync" + "time" + + "github.com/golang/protobuf/proto" + "golang.org/x/net/http2" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// NewServerHandlerTransport returns a ServerTransport handling gRPC +// from inside an http.Handler. It requires that the http Server +// supports HTTP/2. +func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request, stats stats.Handler) (ServerTransport, error) { + if r.ProtoMajor != 2 { + return nil, errors.New("gRPC requires HTTP/2") + } + if r.Method != "POST" { + return nil, errors.New("invalid gRPC request method") + } + contentType := r.Header.Get("Content-Type") + // TODO: do we assume contentType is lowercase? we did before + contentSubtype, validContentType := contentSubtype(contentType) + if !validContentType { + return nil, errors.New("invalid gRPC request content-type") + } + if _, ok := w.(http.Flusher); !ok { + return nil, errors.New("gRPC requires a ResponseWriter supporting http.Flusher") + } + if _, ok := w.(http.CloseNotifier); !ok { + return nil, errors.New("gRPC requires a ResponseWriter supporting http.CloseNotifier") + } + + st := &serverHandlerTransport{ + rw: w, + req: r, + closedCh: make(chan struct{}), + writes: make(chan func()), + contentType: contentType, + contentSubtype: contentSubtype, + stats: stats, + } + + if v := r.Header.Get("grpc-timeout"); v != "" { + to, err := decodeTimeout(v) + if err != nil { + return nil, status.Errorf(codes.Internal, "malformed time-out: %v", err) + } + st.timeoutSet = true + st.timeout = to + } + + metakv := []string{"content-type", contentType} + if r.Host != "" { + metakv = append(metakv, ":authority", r.Host) + } + for k, vv := range r.Header { + k = strings.ToLower(k) + if isReservedHeader(k) && !isWhitelistedHeader(k) { + continue + } + for _, v := range vv { + v, err := decodeMetadataHeader(k, v) + if err != nil { + return nil, status.Errorf(codes.Internal, "malformed binary metadata: %v", err) + } + metakv = append(metakv, k, v) + } + } + st.headerMD = metadata.Pairs(metakv...) + + return st, nil +} + +// serverHandlerTransport is an implementation of ServerTransport +// which replies to exactly one gRPC request (exactly one HTTP request), +// using the net/http.Handler interface. This http.Handler is guaranteed +// at this point to be speaking over HTTP/2, so it's able to speak valid +// gRPC. +type serverHandlerTransport struct { + rw http.ResponseWriter + req *http.Request + timeoutSet bool + timeout time.Duration + didCommonHeaders bool + + headerMD metadata.MD + + closeOnce sync.Once + closedCh chan struct{} // closed on Close + + // writes is a channel of code to run serialized in the + // ServeHTTP (HandleStreams) goroutine. The channel is closed + // when WriteStatus is called. + writes chan func() + + // block concurrent WriteStatus calls + // e.g. grpc/(*serverStream).SendMsg/RecvMsg + writeStatusMu sync.Mutex + + // we just mirror the request content-type + contentType string + // we store both contentType and contentSubtype so we don't keep recreating them + // TODO make sure this is consistent across handler_server and http2_server + contentSubtype string + + stats stats.Handler +} + +func (ht *serverHandlerTransport) Close() error { + ht.closeOnce.Do(ht.closeCloseChanOnce) + return nil +} + +func (ht *serverHandlerTransport) closeCloseChanOnce() { close(ht.closedCh) } + +func (ht *serverHandlerTransport) RemoteAddr() net.Addr { return strAddr(ht.req.RemoteAddr) } + +// strAddr is a net.Addr backed by either a TCP "ip:port" string, or +// the empty string if unknown. +type strAddr string + +func (a strAddr) Network() string { + if a != "" { + // Per the documentation on net/http.Request.RemoteAddr, if this is + // set, it's set to the IP:port of the peer (hence, TCP): + // https://golang.org/pkg/net/http/#Request + // + // If we want to support Unix sockets later, we can + // add our own grpc-specific convention within the + // grpc codebase to set RemoteAddr to a different + // format, or probably better: we can attach it to the + // context and use that from serverHandlerTransport.RemoteAddr. + return "tcp" + } + return "" +} + +func (a strAddr) String() string { return string(a) } + +// do runs fn in the ServeHTTP goroutine. +func (ht *serverHandlerTransport) do(fn func()) error { + // Avoid a panic writing to closed channel. Imperfect but maybe good enough. + select { + case <-ht.closedCh: + return ErrConnClosing + default: + select { + case ht.writes <- fn: + return nil + case <-ht.closedCh: + return ErrConnClosing + } + } +} + +func (ht *serverHandlerTransport) WriteStatus(s *Stream, st *status.Status) error { + ht.writeStatusMu.Lock() + defer ht.writeStatusMu.Unlock() + + err := ht.do(func() { + ht.writeCommonHeaders(s) + + // And flush, in case no header or body has been sent yet. + // This forces a separation of headers and trailers if this is the + // first call (for example, in end2end tests's TestNoService). + ht.rw.(http.Flusher).Flush() + + h := ht.rw.Header() + h.Set("Grpc-Status", fmt.Sprintf("%d", st.Code())) + if m := st.Message(); m != "" { + h.Set("Grpc-Message", encodeGrpcMessage(m)) + } + + if p := st.Proto(); p != nil && len(p.Details) > 0 { + stBytes, err := proto.Marshal(p) + if err != nil { + // TODO: return error instead, when callers are able to handle it. + panic(err) + } + + h.Set("Grpc-Status-Details-Bin", encodeBinHeader(stBytes)) + } + + if md := s.Trailer(); len(md) > 0 { + for k, vv := range md { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + // http2 ResponseWriter mechanism to send undeclared Trailers after + // the headers have possibly been written. + h.Add(http2.TrailerPrefix+k, encodeMetadataHeader(k, v)) + } + } + } + }) + + if err == nil { // transport has not been closed + if ht.stats != nil { + ht.stats.HandleRPC(s.Context(), &stats.OutTrailer{}) + } + close(ht.writes) + } + ht.Close() + return err +} + +// writeCommonHeaders sets common headers on the first write +// call (Write, WriteHeader, or WriteStatus). +func (ht *serverHandlerTransport) writeCommonHeaders(s *Stream) { + if ht.didCommonHeaders { + return + } + ht.didCommonHeaders = true + + h := ht.rw.Header() + h["Date"] = nil // suppress Date to make tests happy; TODO: restore + h.Set("Content-Type", ht.contentType) + + // Predeclare trailers we'll set later in WriteStatus (after the body). + // This is a SHOULD in the HTTP RFC, and the way you add (known) + // Trailers per the net/http.ResponseWriter contract. + // See https://golang.org/pkg/net/http/#ResponseWriter + // and https://golang.org/pkg/net/http/#example_ResponseWriter_trailers + h.Add("Trailer", "Grpc-Status") + h.Add("Trailer", "Grpc-Message") + h.Add("Trailer", "Grpc-Status-Details-Bin") + + if s.sendCompress != "" { + h.Set("Grpc-Encoding", s.sendCompress) + } +} + +func (ht *serverHandlerTransport) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + return ht.do(func() { + ht.writeCommonHeaders(s) + ht.rw.Write(hdr) + ht.rw.Write(data) + ht.rw.(http.Flusher).Flush() + }) +} + +func (ht *serverHandlerTransport) WriteHeader(s *Stream, md metadata.MD) error { + err := ht.do(func() { + ht.writeCommonHeaders(s) + h := ht.rw.Header() + for k, vv := range md { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + v = encodeMetadataHeader(k, v) + h.Add(k, v) + } + } + ht.rw.WriteHeader(200) + ht.rw.(http.Flusher).Flush() + }) + + if err == nil { + if ht.stats != nil { + ht.stats.HandleRPC(s.Context(), &stats.OutHeader{}) + } + } + return err +} + +func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream), traceCtx func(context.Context, string) context.Context) { + // With this transport type there will be exactly 1 stream: this HTTP request. + + ctx := ht.req.Context() + var cancel context.CancelFunc + if ht.timeoutSet { + ctx, cancel = context.WithTimeout(ctx, ht.timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + + // requestOver is closed when either the request's context is done + // or the status has been written via WriteStatus. + requestOver := make(chan struct{}) + + // clientGone receives a single value if peer is gone, either + // because the underlying connection is dead or because the + // peer sends an http2 RST_STREAM. + clientGone := ht.rw.(http.CloseNotifier).CloseNotify() + go func() { + select { + case <-requestOver: + case <-ht.closedCh: + case <-clientGone: + } + cancel() + ht.Close() + }() + + req := ht.req + + s := &Stream{ + id: 0, // irrelevant + requestRead: func(int) {}, + cancel: cancel, + buf: newRecvBuffer(), + st: ht, + method: req.URL.Path, + recvCompress: req.Header.Get("grpc-encoding"), + contentSubtype: ht.contentSubtype, + } + pr := &peer.Peer{ + Addr: ht.RemoteAddr(), + } + if req.TLS != nil { + pr.AuthInfo = credentials.TLSInfo{State: *req.TLS} + } + ctx = metadata.NewIncomingContext(ctx, ht.headerMD) + s.ctx = peer.NewContext(ctx, pr) + if ht.stats != nil { + s.ctx = ht.stats.TagRPC(s.ctx, &stats.RPCTagInfo{FullMethodName: s.method}) + inHeader := &stats.InHeader{ + FullMethod: s.method, + RemoteAddr: ht.RemoteAddr(), + Compression: s.recvCompress, + } + ht.stats.HandleRPC(s.ctx, inHeader) + } + s.trReader = &transportReader{ + reader: &recvBufferReader{ctx: s.ctx, ctxDone: s.ctx.Done(), recv: s.buf}, + windowHandler: func(int) {}, + } + + // readerDone is closed when the Body.Read-ing goroutine exits. + readerDone := make(chan struct{}) + go func() { + defer close(readerDone) + + // TODO: minimize garbage, optimize recvBuffer code/ownership + const readSize = 8196 + for buf := make([]byte, readSize); ; { + n, err := req.Body.Read(buf) + if n > 0 { + s.buf.put(recvMsg{data: buf[:n:n]}) + buf = buf[n:] + } + if err != nil { + s.buf.put(recvMsg{err: mapRecvMsgError(err)}) + return + } + if len(buf) == 0 { + buf = make([]byte, readSize) + } + } + }() + + // startStream is provided by the *grpc.Server's serveStreams. + // It starts a goroutine serving s and exits immediately. + // The goroutine that is started is the one that then calls + // into ht, calling WriteHeader, Write, WriteStatus, Close, etc. + startStream(s) + + ht.runStream() + close(requestOver) + + // Wait for reading goroutine to finish. + req.Body.Close() + <-readerDone +} + +func (ht *serverHandlerTransport) runStream() { + for { + select { + case fn, ok := <-ht.writes: + if !ok { + return + } + fn() + case <-ht.closedCh: + return + } + } +} + +func (ht *serverHandlerTransport) IncrMsgSent() {} + +func (ht *serverHandlerTransport) IncrMsgRecv() {} + +func (ht *serverHandlerTransport) Drain() { + panic("Drain() is not implemented") +} + +// mapRecvMsgError returns the non-nil err into the appropriate +// error value as expected by callers of *grpc.parser.recvMsg. +// In particular, in can only be: +// * io.EOF +// * io.ErrUnexpectedEOF +// * of type transport.ConnectionError +// * an error from the status package +func mapRecvMsgError(err error) error { + if err == io.EOF || err == io.ErrUnexpectedEOF { + return err + } + if se, ok := err.(http2.StreamError); ok { + if code, ok := http2ErrConvTab[se.Code]; ok { + return status.Error(code, se.Error()) + } + } + if strings.Contains(err.Error(), "body closed by handler") { + return status.Error(codes.Canceled, err.Error()) + } + return connectionErrorf(true, err, err.Error()) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go new file mode 100644 index 00000000..39208b14 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -0,0 +1,1377 @@ +/* + * + * Copyright 2014 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 transport + +import ( + "context" + "fmt" + "io" + "math" + "net" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + + "golang.org/x/net/http2" + "golang.org/x/net/http2/hpack" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/syscall" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// http2Client implements the ClientTransport interface with HTTP2. +type http2Client struct { + ctx context.Context + cancel context.CancelFunc + ctxDone <-chan struct{} // Cache the ctx.Done() chan. + userAgent string + md interface{} + conn net.Conn // underlying communication channel + loopy *loopyWriter + remoteAddr net.Addr + localAddr net.Addr + authInfo credentials.AuthInfo // auth info about the connection + + readerDone chan struct{} // sync point to enable testing. + writerDone chan struct{} // sync point to enable testing. + // goAway is closed to notify the upper layer (i.e., addrConn.transportMonitor) + // that the server sent GoAway on this transport. + goAway chan struct{} + // awakenKeepalive is used to wake up keepalive when after it has gone dormant. + awakenKeepalive chan struct{} + + framer *framer + // controlBuf delivers all the control related tasks (e.g., window + // updates, reset streams, and various settings) to the controller. + controlBuf *controlBuffer + fc *trInFlow + // The scheme used: https if TLS is on, http otherwise. + scheme string + + isSecure bool + + perRPCCreds []credentials.PerRPCCredentials + + // Boolean to keep track of reading activity on transport. + // 1 is true and 0 is false. + activity uint32 // Accessed atomically. + kp keepalive.ClientParameters + keepaliveEnabled bool + + statsHandler stats.Handler + + initialWindowSize int32 + + // configured by peer through SETTINGS_MAX_HEADER_LIST_SIZE + maxSendHeaderListSize *uint32 + + bdpEst *bdpEstimator + // onSuccess is a callback that client transport calls upon + // receiving server preface to signal that a succefull HTTP2 + // connection was established. + onSuccess func() + + maxConcurrentStreams uint32 + streamQuota int64 + streamsQuotaAvailable chan struct{} + waitingStreams uint32 + nextID uint32 + + mu sync.Mutex // guard the following variables + state transportState + activeStreams map[uint32]*Stream + // prevGoAway ID records the Last-Stream-ID in the previous GOAway frame. + prevGoAwayID uint32 + // goAwayReason records the http2.ErrCode and debug data received with the + // GoAway frame. + goAwayReason GoAwayReason + + // Fields below are for channelz metric collection. + channelzID int64 // channelz unique identification number + czData *channelzData + + onGoAway func(GoAwayReason) + onClose func() +} + +func dial(ctx context.Context, fn func(context.Context, string) (net.Conn, error), addr string) (net.Conn, error) { + if fn != nil { + return fn(ctx, addr) + } + return (&net.Dialer{}).DialContext(ctx, "tcp", addr) +} + +func isTemporary(err error) bool { + switch err := err.(type) { + case interface { + Temporary() bool + }: + return err.Temporary() + case interface { + Timeout() bool + }: + // Timeouts may be resolved upon retry, and are thus treated as + // temporary. + return err.Timeout() + } + return true +} + +// newHTTP2Client constructs a connected ClientTransport to addr based on HTTP2 +// and starts to receive messages on it. Non-nil error returns if construction +// fails. +func newHTTP2Client(connectCtx, ctx context.Context, addr TargetInfo, opts ConnectOptions, onSuccess func(), onGoAway func(GoAwayReason), onClose func()) (_ *http2Client, err error) { + scheme := "http" + ctx, cancel := context.WithCancel(ctx) + defer func() { + if err != nil { + cancel() + } + }() + + conn, err := dial(connectCtx, opts.Dialer, addr.Addr) + if err != nil { + if opts.FailOnNonTempDialError { + return nil, connectionErrorf(isTemporary(err), err, "transport: error while dialing: %v", err) + } + return nil, connectionErrorf(true, err, "transport: Error while dialing %v", err) + } + // Any further errors will close the underlying connection + defer func(conn net.Conn) { + if err != nil { + conn.Close() + } + }(conn) + kp := opts.KeepaliveParams + // Validate keepalive parameters. + if kp.Time == 0 { + kp.Time = defaultClientKeepaliveTime + } + if kp.Timeout == 0 { + kp.Timeout = defaultClientKeepaliveTimeout + } + keepaliveEnabled := false + if kp.Time != infinity { + if err = syscall.SetTCPUserTimeout(conn, kp.Timeout); err != nil { + return nil, connectionErrorf(false, err, "transport: failed to set TCP_USER_TIMEOUT: %v", err) + } + keepaliveEnabled = true + } + var ( + isSecure bool + authInfo credentials.AuthInfo + ) + transportCreds := opts.TransportCredentials + perRPCCreds := opts.PerRPCCredentials + + if b := opts.CredsBundle; b != nil { + if t := b.TransportCredentials(); t != nil { + transportCreds = t + } + if t := b.PerRPCCredentials(); t != nil { + perRPCCreds = append(perRPCCreds, t) + } + } + if transportCreds != nil { + scheme = "https" + conn, authInfo, err = transportCreds.ClientHandshake(connectCtx, addr.Authority, conn) + if err != nil { + return nil, connectionErrorf(isTemporary(err), err, "transport: authentication handshake failed: %v", err) + } + isSecure = true + } + dynamicWindow := true + icwz := int32(initialWindowSize) + if opts.InitialConnWindowSize >= defaultWindowSize { + icwz = opts.InitialConnWindowSize + dynamicWindow = false + } + writeBufSize := opts.WriteBufferSize + readBufSize := opts.ReadBufferSize + maxHeaderListSize := defaultClientMaxHeaderListSize + if opts.MaxHeaderListSize != nil { + maxHeaderListSize = *opts.MaxHeaderListSize + } + t := &http2Client{ + ctx: ctx, + ctxDone: ctx.Done(), // Cache Done chan. + cancel: cancel, + userAgent: opts.UserAgent, + md: addr.Metadata, + conn: conn, + remoteAddr: conn.RemoteAddr(), + localAddr: conn.LocalAddr(), + authInfo: authInfo, + readerDone: make(chan struct{}), + writerDone: make(chan struct{}), + goAway: make(chan struct{}), + awakenKeepalive: make(chan struct{}, 1), + framer: newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize), + fc: &trInFlow{limit: uint32(icwz)}, + scheme: scheme, + activeStreams: make(map[uint32]*Stream), + isSecure: isSecure, + perRPCCreds: perRPCCreds, + kp: kp, + statsHandler: opts.StatsHandler, + initialWindowSize: initialWindowSize, + onSuccess: onSuccess, + nextID: 1, + maxConcurrentStreams: defaultMaxStreamsClient, + streamQuota: defaultMaxStreamsClient, + streamsQuotaAvailable: make(chan struct{}, 1), + czData: new(channelzData), + onGoAway: onGoAway, + onClose: onClose, + keepaliveEnabled: keepaliveEnabled, + } + t.controlBuf = newControlBuffer(t.ctxDone) + if opts.InitialWindowSize >= defaultWindowSize { + t.initialWindowSize = opts.InitialWindowSize + dynamicWindow = false + } + if dynamicWindow { + t.bdpEst = &bdpEstimator{ + bdp: initialWindowSize, + updateFlowControl: t.updateFlowControl, + } + } + // Make sure awakenKeepalive can't be written upon. + // keepalive routine will make it writable, if need be. + t.awakenKeepalive <- struct{}{} + if t.statsHandler != nil { + t.ctx = t.statsHandler.TagConn(t.ctx, &stats.ConnTagInfo{ + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + }) + connBegin := &stats.ConnBegin{ + Client: true, + } + t.statsHandler.HandleConn(t.ctx, connBegin) + } + if channelz.IsOn() { + t.channelzID = channelz.RegisterNormalSocket(t, opts.ChannelzParentID, fmt.Sprintf("%s -> %s", t.localAddr, t.remoteAddr)) + } + if t.keepaliveEnabled { + go t.keepalive() + } + // Start the reader goroutine for incoming message. Each transport has + // a dedicated goroutine which reads HTTP2 frame from network. Then it + // dispatches the frame to the corresponding stream entity. + go t.reader() + + // Send connection preface to server. + n, err := t.conn.Write(clientPreface) + if err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write client preface: %v", err) + } + if n != len(clientPreface) { + t.Close() + return nil, connectionErrorf(true, err, "transport: preface mismatch, wrote %d bytes; want %d", n, len(clientPreface)) + } + var ss []http2.Setting + + if t.initialWindowSize != defaultWindowSize { + ss = append(ss, http2.Setting{ + ID: http2.SettingInitialWindowSize, + Val: uint32(t.initialWindowSize), + }) + } + if opts.MaxHeaderListSize != nil { + ss = append(ss, http2.Setting{ + ID: http2.SettingMaxHeaderListSize, + Val: *opts.MaxHeaderListSize, + }) + } + err = t.framer.fr.WriteSettings(ss...) + if err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write initial settings frame: %v", err) + } + // Adjust the connection flow control window if needed. + if delta := uint32(icwz - defaultWindowSize); delta > 0 { + if err := t.framer.fr.WriteWindowUpdate(0, delta); err != nil { + t.Close() + return nil, connectionErrorf(true, err, "transport: failed to write window update: %v", err) + } + } + + t.framer.writer.Flush() + go func() { + t.loopy = newLoopyWriter(clientSide, t.framer, t.controlBuf, t.bdpEst) + err := t.loopy.run() + if err != nil { + errorf("transport: loopyWriter.run returning. Err: %v", err) + } + // If it's a connection error, let reader goroutine handle it + // since there might be data in the buffers. + if _, ok := err.(net.Error); !ok { + t.conn.Close() + } + close(t.writerDone) + }() + return t, nil +} + +func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr) *Stream { + // TODO(zhaoq): Handle uint32 overflow of Stream.id. + s := &Stream{ + done: make(chan struct{}), + method: callHdr.Method, + sendCompress: callHdr.SendCompress, + buf: newRecvBuffer(), + headerChan: make(chan struct{}), + contentSubtype: callHdr.ContentSubtype, + } + s.wq = newWriteQuota(defaultWriteQuota, s.done) + s.requestRead = func(n int) { + t.adjustWindow(s, uint32(n)) + } + // The client side stream context should have exactly the same life cycle with the user provided context. + // That means, s.ctx should be read-only. And s.ctx is done iff ctx is done. + // So we use the original context here instead of creating a copy. + s.ctx = ctx + s.trReader = &transportReader{ + reader: &recvBufferReader{ + ctx: s.ctx, + ctxDone: s.ctx.Done(), + recv: s.buf, + }, + windowHandler: func(n int) { + t.updateWindow(s, uint32(n)) + }, + } + return s +} + +func (t *http2Client) getPeer() *peer.Peer { + pr := &peer.Peer{ + Addr: t.remoteAddr, + } + // Attach Auth info if there is any. + if t.authInfo != nil { + pr.AuthInfo = t.authInfo + } + return pr +} + +func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) ([]hpack.HeaderField, error) { + aud := t.createAudience(callHdr) + authData, err := t.getTrAuthData(ctx, aud) + if err != nil { + return nil, err + } + callAuthData, err := t.getCallAuthData(ctx, aud, callHdr) + if err != nil { + return nil, err + } + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + // Make the slice of certain predictable size to reduce allocations made by append. + hfLen := 7 // :method, :scheme, :path, :authority, content-type, user-agent, te + hfLen += len(authData) + len(callAuthData) + headerFields := make([]hpack.HeaderField, 0, hfLen) + headerFields = append(headerFields, hpack.HeaderField{Name: ":method", Value: "POST"}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":scheme", Value: t.scheme}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":path", Value: callHdr.Method}) + headerFields = append(headerFields, hpack.HeaderField{Name: ":authority", Value: callHdr.Host}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(callHdr.ContentSubtype)}) + headerFields = append(headerFields, hpack.HeaderField{Name: "user-agent", Value: t.userAgent}) + headerFields = append(headerFields, hpack.HeaderField{Name: "te", Value: "trailers"}) + if callHdr.PreviousAttempts > 0 { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-previous-rpc-attempts", Value: strconv.Itoa(callHdr.PreviousAttempts)}) + } + + if callHdr.SendCompress != "" { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: callHdr.SendCompress}) + } + if dl, ok := ctx.Deadline(); ok { + // Send out timeout regardless its value. The server can detect timeout context by itself. + // TODO(mmukhi): Perhaps this field should be updated when actually writing out to the wire. + timeout := dl.Sub(time.Now()) + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-timeout", Value: encodeTimeout(timeout)}) + } + for k, v := range authData { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + for k, v := range callAuthData { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + if b := stats.OutgoingTags(ctx); b != nil { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-tags-bin", Value: encodeBinHeader(b)}) + } + if b := stats.OutgoingTrace(ctx); b != nil { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-trace-bin", Value: encodeBinHeader(b)}) + } + + if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok { + var k string + for _, vv := range added { + for i, v := range vv { + if i%2 == 0 { + k = v + continue + } + // HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set. + if isReservedHeader(k) { + continue + } + headerFields = append(headerFields, hpack.HeaderField{Name: strings.ToLower(k), Value: encodeMetadataHeader(k, v)}) + } + } + for k, vv := range md { + // HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set. + if isReservedHeader(k) { + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + } + if md, ok := t.md.(*metadata.MD); ok { + for k, vv := range *md { + if isReservedHeader(k) { + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + } + return headerFields, nil +} + +func (t *http2Client) createAudience(callHdr *CallHdr) string { + // Create an audience string only if needed. + if len(t.perRPCCreds) == 0 && callHdr.Creds == nil { + return "" + } + // Construct URI required to get auth request metadata. + // Omit port if it is the default one. + host := strings.TrimSuffix(callHdr.Host, ":443") + pos := strings.LastIndex(callHdr.Method, "/") + if pos == -1 { + pos = len(callHdr.Method) + } + return "https://" + host + callHdr.Method[:pos] +} + +func (t *http2Client) getTrAuthData(ctx context.Context, audience string) (map[string]string, error) { + authData := map[string]string{} + for _, c := range t.perRPCCreds { + data, err := c.GetRequestMetadata(ctx, audience) + if err != nil { + if _, ok := status.FromError(err); ok { + return nil, err + } + + return nil, status.Errorf(codes.Unauthenticated, "transport: %v", err) + } + for k, v := range data { + // Capital header names are illegal in HTTP/2. + k = strings.ToLower(k) + authData[k] = v + } + } + return authData, nil +} + +func (t *http2Client) getCallAuthData(ctx context.Context, audience string, callHdr *CallHdr) (map[string]string, error) { + callAuthData := map[string]string{} + // Check if credentials.PerRPCCredentials were provided via call options. + // Note: if these credentials are provided both via dial options and call + // options, then both sets of credentials will be applied. + if callCreds := callHdr.Creds; callCreds != nil { + if !t.isSecure && callCreds.RequireTransportSecurity() { + return nil, status.Error(codes.Unauthenticated, "transport: cannot send secure credentials on an insecure connection") + } + data, err := callCreds.GetRequestMetadata(ctx, audience) + if err != nil { + return nil, status.Errorf(codes.Internal, "transport: %v", err) + } + for k, v := range data { + // Capital header names are illegal in HTTP/2 + k = strings.ToLower(k) + callAuthData[k] = v + } + } + return callAuthData, nil +} + +// NewStream creates a stream and registers it into the transport as "active" +// streams. +func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Stream, err error) { + ctx = peer.NewContext(ctx, t.getPeer()) + headerFields, err := t.createHeaderFields(ctx, callHdr) + if err != nil { + return nil, err + } + s := t.newStream(ctx, callHdr) + cleanup := func(err error) { + if s.swapState(streamDone) == streamDone { + // If it was already done, return. + return + } + // The stream was unprocessed by the server. + atomic.StoreUint32(&s.unprocessed, 1) + s.write(recvMsg{err: err}) + close(s.done) + // If headerChan isn't closed, then close it. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + close(s.headerChan) + } + + } + hdr := &headerFrame{ + hf: headerFields, + endStream: false, + initStream: func(id uint32) (bool, error) { + t.mu.Lock() + if state := t.state; state != reachable { + t.mu.Unlock() + // Do a quick cleanup. + err := error(errStreamDrain) + if state == closing { + err = ErrConnClosing + } + cleanup(err) + return false, err + } + t.activeStreams[id] = s + if channelz.IsOn() { + atomic.AddInt64(&t.czData.streamsStarted, 1) + atomic.StoreInt64(&t.czData.lastStreamCreatedTime, time.Now().UnixNano()) + } + var sendPing bool + // If the number of active streams change from 0 to 1, then check if keepalive + // has gone dormant. If so, wake it up. + if len(t.activeStreams) == 1 && t.keepaliveEnabled { + select { + case t.awakenKeepalive <- struct{}{}: + sendPing = true + // Fill the awakenKeepalive channel again as this channel must be + // kept non-writable except at the point that the keepalive() + // goroutine is waiting either to be awaken or shutdown. + t.awakenKeepalive <- struct{}{} + default: + } + } + t.mu.Unlock() + return sendPing, nil + }, + onOrphaned: cleanup, + wq: s.wq, + } + firstTry := true + var ch chan struct{} + checkForStreamQuota := func(it interface{}) bool { + if t.streamQuota <= 0 { // Can go negative if server decreases it. + if firstTry { + t.waitingStreams++ + } + ch = t.streamsQuotaAvailable + return false + } + if !firstTry { + t.waitingStreams-- + } + t.streamQuota-- + h := it.(*headerFrame) + h.streamID = t.nextID + t.nextID += 2 + s.id = h.streamID + s.fc = &inFlow{limit: uint32(t.initialWindowSize)} + if t.streamQuota > 0 && t.waitingStreams > 0 { + select { + case t.streamsQuotaAvailable <- struct{}{}: + default: + } + } + return true + } + var hdrListSizeErr error + checkForHeaderListSize := func(it interface{}) bool { + if t.maxSendHeaderListSize == nil { + return true + } + hdrFrame := it.(*headerFrame) + var sz int64 + for _, f := range hdrFrame.hf { + if sz += int64(f.Size()); sz > int64(*t.maxSendHeaderListSize) { + hdrListSizeErr = status.Errorf(codes.Internal, "header list size to send violates the maximum size (%d bytes) set by server", *t.maxSendHeaderListSize) + return false + } + } + return true + } + for { + success, err := t.controlBuf.executeAndPut(func(it interface{}) bool { + if !checkForStreamQuota(it) { + return false + } + if !checkForHeaderListSize(it) { + return false + } + return true + }, hdr) + if err != nil { + return nil, err + } + if success { + break + } + if hdrListSizeErr != nil { + return nil, hdrListSizeErr + } + firstTry = false + select { + case <-ch: + case <-s.ctx.Done(): + return nil, ContextErr(s.ctx.Err()) + case <-t.goAway: + return nil, errStreamDrain + case <-t.ctx.Done(): + return nil, ErrConnClosing + } + } + if t.statsHandler != nil { + outHeader := &stats.OutHeader{ + Client: true, + FullMethod: callHdr.Method, + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + Compression: callHdr.SendCompress, + } + t.statsHandler.HandleRPC(s.ctx, outHeader) + } + return s, nil +} + +// CloseStream clears the footprint of a stream when the stream is not needed any more. +// This must not be executed in reader's goroutine. +func (t *http2Client) CloseStream(s *Stream, err error) { + var ( + rst bool + rstCode http2.ErrCode + ) + if err != nil { + rst = true + rstCode = http2.ErrCodeCancel + } + t.closeStream(s, err, rst, rstCode, status.Convert(err), nil, false) +} + +func (t *http2Client) closeStream(s *Stream, err error, rst bool, rstCode http2.ErrCode, st *status.Status, mdata map[string][]string, eosReceived bool) { + // Set stream status to done. + if s.swapState(streamDone) == streamDone { + // If it was already done, return. If multiple closeStream calls + // happen simultaneously, wait for the first to finish. + <-s.done + return + } + // status and trailers can be updated here without any synchronization because the stream goroutine will + // only read it after it sees an io.EOF error from read or write and we'll write those errors + // only after updating this. + s.status = st + if len(mdata) > 0 { + s.trailer = mdata + } + if err != nil { + // This will unblock reads eventually. + s.write(recvMsg{err: err}) + } + // If headerChan isn't closed, then close it. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + s.noHeaders = true + close(s.headerChan) + } + cleanup := &cleanupStream{ + streamID: s.id, + onWrite: func() { + t.mu.Lock() + if t.activeStreams != nil { + delete(t.activeStreams, s.id) + } + t.mu.Unlock() + if channelz.IsOn() { + if eosReceived { + atomic.AddInt64(&t.czData.streamsSucceeded, 1) + } else { + atomic.AddInt64(&t.czData.streamsFailed, 1) + } + } + }, + rst: rst, + rstCode: rstCode, + } + addBackStreamQuota := func(interface{}) bool { + t.streamQuota++ + if t.streamQuota > 0 && t.waitingStreams > 0 { + select { + case t.streamsQuotaAvailable <- struct{}{}: + default: + } + } + return true + } + t.controlBuf.executeAndPut(addBackStreamQuota, cleanup) + // This will unblock write. + close(s.done) +} + +// Close kicks off the shutdown process of the transport. This should be called +// only once on a transport. Once it is called, the transport should not be +// accessed any more. +// +// This method blocks until the addrConn that initiated this transport is +// re-connected. This happens because t.onClose() begins reconnect logic at the +// addrConn level and blocks until the addrConn is successfully connected. +func (t *http2Client) Close() error { + t.mu.Lock() + // Make sure we only Close once. + if t.state == closing { + t.mu.Unlock() + return nil + } + t.state = closing + streams := t.activeStreams + t.activeStreams = nil + t.mu.Unlock() + t.controlBuf.finish() + t.cancel() + err := t.conn.Close() + if channelz.IsOn() { + channelz.RemoveEntry(t.channelzID) + } + // Notify all active streams. + for _, s := range streams { + t.closeStream(s, ErrConnClosing, false, http2.ErrCodeNo, status.New(codes.Unavailable, ErrConnClosing.Desc), nil, false) + } + if t.statsHandler != nil { + connEnd := &stats.ConnEnd{ + Client: true, + } + t.statsHandler.HandleConn(t.ctx, connEnd) + } + go t.onClose() + return err +} + +// GracefulClose sets the state to draining, which prevents new streams from +// being created and causes the transport to be closed when the last active +// stream is closed. If there are no active streams, the transport is closed +// immediately. This does nothing if the transport is already draining or +// closing. +func (t *http2Client) GracefulClose() error { + t.mu.Lock() + // Make sure we move to draining only from active. + if t.state == draining || t.state == closing { + t.mu.Unlock() + return nil + } + t.state = draining + active := len(t.activeStreams) + t.mu.Unlock() + if active == 0 { + return t.Close() + } + t.controlBuf.put(&incomingGoAway{}) + return nil +} + +// Write formats the data into HTTP2 data frame(s) and sends it out. The caller +// should proceed only if Write returns nil. +func (t *http2Client) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + if opts.Last { + // If it's the last message, update stream state. + if !s.compareAndSwapState(streamActive, streamWriteDone) { + return errStreamDone + } + } else if s.getState() != streamActive { + return errStreamDone + } + df := &dataFrame{ + streamID: s.id, + endStream: opts.Last, + } + if hdr != nil || data != nil { // If it's not an empty data frame. + // Add some data to grpc message header so that we can equally + // distribute bytes across frames. + emptyLen := http2MaxFrameLen - len(hdr) + if emptyLen > len(data) { + emptyLen = len(data) + } + hdr = append(hdr, data[:emptyLen]...) + data = data[emptyLen:] + df.h, df.d = hdr, data + // TODO(mmukhi): The above logic in this if can be moved to loopyWriter's data handler. + if err := s.wq.get(int32(len(hdr) + len(data))); err != nil { + return err + } + } + return t.controlBuf.put(df) +} + +func (t *http2Client) getStream(f http2.Frame) (*Stream, bool) { + t.mu.Lock() + defer t.mu.Unlock() + s, ok := t.activeStreams[f.Header().StreamID] + return s, ok +} + +// adjustWindow sends out extra window update over the initial window size +// of stream if the application is requesting data larger in size than +// the window. +func (t *http2Client) adjustWindow(s *Stream, n uint32) { + if w := s.fc.maybeAdjust(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } +} + +// updateWindow adjusts the inbound quota for the stream. +// Window updates will be sent out when the cumulative quota +// exceeds the corresponding threshold. +func (t *http2Client) updateWindow(s *Stream, n uint32) { + if w := s.fc.onRead(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } +} + +// updateFlowControl updates the incoming flow control windows +// for the transport and the stream based on the current bdp +// estimation. +func (t *http2Client) updateFlowControl(n uint32) { + t.mu.Lock() + for _, s := range t.activeStreams { + s.fc.newLimit(n) + } + t.mu.Unlock() + updateIWS := func(interface{}) bool { + t.initialWindowSize = int32(n) + return true + } + t.controlBuf.executeAndPut(updateIWS, &outgoingWindowUpdate{streamID: 0, increment: t.fc.newLimit(n)}) + t.controlBuf.put(&outgoingSettings{ + ss: []http2.Setting{ + { + ID: http2.SettingInitialWindowSize, + Val: n, + }, + }, + }) +} + +func (t *http2Client) handleData(f *http2.DataFrame) { + size := f.Header().Length + var sendBDPPing bool + if t.bdpEst != nil { + sendBDPPing = t.bdpEst.add(size) + } + // Decouple connection's flow control from application's read. + // An update on connection's flow control should not depend on + // whether user application has read the data or not. Such a + // restriction is already imposed on the stream's flow control, + // and therefore the sender will be blocked anyways. + // Decoupling the connection flow control will prevent other + // active(fast) streams from starving in presence of slow or + // inactive streams. + // + if w := t.fc.onData(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + if sendBDPPing { + // Avoid excessive ping detection (e.g. in an L7 proxy) + // by sending a window update prior to the BDP ping. + + if w := t.fc.reset(); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + + t.controlBuf.put(bdpPing) + } + // Select the right stream to dispatch. + s, ok := t.getStream(f) + if !ok { + return + } + if size > 0 { + if err := s.fc.onData(size); err != nil { + t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil, false) + return + } + if f.Header().Flags.Has(http2.FlagDataPadded) { + if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + } + } + // TODO(bradfitz, zhaoq): A copy is required here because there is no + // guarantee f.Data() is consumed before the arrival of next frame. + // Can this copy be eliminated? + if len(f.Data()) > 0 { + data := make([]byte, len(f.Data())) + copy(data, f.Data()) + s.write(recvMsg{data: data}) + } + } + // The server has closed the stream without sending trailers. Record that + // the read direction is closed, and set the status appropriately. + if f.FrameHeader.Flags.Has(http2.FlagDataEndStream) { + t.closeStream(s, io.EOF, false, http2.ErrCodeNo, status.New(codes.Internal, "server closed the stream without sending trailers"), nil, true) + } +} + +func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) { + s, ok := t.getStream(f) + if !ok { + return + } + if f.ErrCode == http2.ErrCodeRefusedStream { + // The stream was unprocessed by the server. + atomic.StoreUint32(&s.unprocessed, 1) + } + statusCode, ok := http2ErrConvTab[f.ErrCode] + if !ok { + warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error %v", f.ErrCode) + statusCode = codes.Unknown + } + if statusCode == codes.Canceled { + // Our deadline was already exceeded, and that was likely the cause of + // this cancelation. Alter the status code accordingly. + if d, ok := s.ctx.Deadline(); ok && d.After(time.Now()) { + statusCode = codes.DeadlineExceeded + } + } + t.closeStream(s, io.EOF, false, http2.ErrCodeNo, status.Newf(statusCode, "stream terminated by RST_STREAM with error code: %v", f.ErrCode), nil, false) +} + +func (t *http2Client) handleSettings(f *http2.SettingsFrame, isFirst bool) { + if f.IsAck() { + return + } + var maxStreams *uint32 + var ss []http2.Setting + var updateFuncs []func() + f.ForeachSetting(func(s http2.Setting) error { + switch s.ID { + case http2.SettingMaxConcurrentStreams: + maxStreams = new(uint32) + *maxStreams = s.Val + case http2.SettingMaxHeaderListSize: + updateFuncs = append(updateFuncs, func() { + t.maxSendHeaderListSize = new(uint32) + *t.maxSendHeaderListSize = s.Val + }) + default: + ss = append(ss, s) + } + return nil + }) + if isFirst && maxStreams == nil { + maxStreams = new(uint32) + *maxStreams = math.MaxUint32 + } + sf := &incomingSettings{ + ss: ss, + } + if maxStreams != nil { + updateStreamQuota := func() { + delta := int64(*maxStreams) - int64(t.maxConcurrentStreams) + t.maxConcurrentStreams = *maxStreams + t.streamQuota += delta + if delta > 0 && t.waitingStreams > 0 { + close(t.streamsQuotaAvailable) // wake all of them up. + t.streamsQuotaAvailable = make(chan struct{}, 1) + } + } + updateFuncs = append(updateFuncs, updateStreamQuota) + } + t.controlBuf.executeAndPut(func(interface{}) bool { + for _, f := range updateFuncs { + f() + } + return true + }, sf) +} + +func (t *http2Client) handlePing(f *http2.PingFrame) { + if f.IsAck() { + // Maybe it's a BDP ping. + if t.bdpEst != nil { + t.bdpEst.calculate(f.Data) + } + return + } + pingAck := &ping{ack: true} + copy(pingAck.data[:], f.Data[:]) + t.controlBuf.put(pingAck) +} + +func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) { + t.mu.Lock() + if t.state == closing { + t.mu.Unlock() + return + } + if f.ErrCode == http2.ErrCodeEnhanceYourCalm { + infof("Client received GoAway with http2.ErrCodeEnhanceYourCalm.") + } + id := f.LastStreamID + if id > 0 && id%2 != 1 { + t.mu.Unlock() + t.Close() + return + } + // A client can receive multiple GoAways from the server (see + // https://github.com/grpc/grpc-go/issues/1387). The idea is that the first + // GoAway will be sent with an ID of MaxInt32 and the second GoAway will be + // sent after an RTT delay with the ID of the last stream the server will + // process. + // + // Therefore, when we get the first GoAway we don't necessarily close any + // streams. While in case of second GoAway we close all streams created after + // the GoAwayId. This way streams that were in-flight while the GoAway from + // server was being sent don't get killed. + select { + case <-t.goAway: // t.goAway has been closed (i.e.,multiple GoAways). + // If there are multiple GoAways the first one should always have an ID greater than the following ones. + if id > t.prevGoAwayID { + t.mu.Unlock() + t.Close() + return + } + default: + t.setGoAwayReason(f) + close(t.goAway) + t.state = draining + t.controlBuf.put(&incomingGoAway{}) + + // This has to be a new goroutine because we're still using the current goroutine to read in the transport. + t.onGoAway(t.goAwayReason) + } + // All streams with IDs greater than the GoAwayId + // and smaller than the previous GoAway ID should be killed. + upperLimit := t.prevGoAwayID + if upperLimit == 0 { // This is the first GoAway Frame. + upperLimit = math.MaxUint32 // Kill all streams after the GoAway ID. + } + for streamID, stream := range t.activeStreams { + if streamID > id && streamID <= upperLimit { + // The stream was unprocessed by the server. + atomic.StoreUint32(&stream.unprocessed, 1) + t.closeStream(stream, errStreamDrain, false, http2.ErrCodeNo, statusGoAway, nil, false) + } + } + t.prevGoAwayID = id + active := len(t.activeStreams) + t.mu.Unlock() + if active == 0 { + t.Close() + } +} + +// setGoAwayReason sets the value of t.goAwayReason based +// on the GoAway frame received. +// It expects a lock on transport's mutext to be held by +// the caller. +func (t *http2Client) setGoAwayReason(f *http2.GoAwayFrame) { + t.goAwayReason = GoAwayNoReason + switch f.ErrCode { + case http2.ErrCodeEnhanceYourCalm: + if string(f.DebugData()) == "too_many_pings" { + t.goAwayReason = GoAwayTooManyPings + } + } +} + +func (t *http2Client) GetGoAwayReason() GoAwayReason { + t.mu.Lock() + defer t.mu.Unlock() + return t.goAwayReason +} + +func (t *http2Client) handleWindowUpdate(f *http2.WindowUpdateFrame) { + t.controlBuf.put(&incomingWindowUpdate{ + streamID: f.Header().StreamID, + increment: f.Increment, + }) +} + +// operateHeaders takes action on the decoded headers. +func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { + s, ok := t.getStream(frame) + if !ok { + return + } + atomic.StoreUint32(&s.bytesReceived, 1) + var state decodeState + if err := state.decodeHeader(frame); err != nil { + t.closeStream(s, err, true, http2.ErrCodeProtocol, status.New(codes.Internal, err.Error()), nil, false) + // Something wrong. Stops reading even when there is remaining. + return + } + + endStream := frame.StreamEnded() + var isHeader bool + defer func() { + if t.statsHandler != nil { + if isHeader { + inHeader := &stats.InHeader{ + Client: true, + WireLength: int(frame.Header().Length), + } + t.statsHandler.HandleRPC(s.ctx, inHeader) + } else { + inTrailer := &stats.InTrailer{ + Client: true, + WireLength: int(frame.Header().Length), + } + t.statsHandler.HandleRPC(s.ctx, inTrailer) + } + } + }() + // If headers haven't been received yet. + if atomic.SwapUint32(&s.headerDone, 1) == 0 { + if !endStream { + // Headers frame is not actually a trailers-only frame. + isHeader = true + // These values can be set without any synchronization because + // stream goroutine will read it only after seeing a closed + // headerChan which we'll close after setting this. + s.recvCompress = state.encoding + if len(state.mdata) > 0 { + s.header = state.mdata + } + } else { + s.noHeaders = true + } + close(s.headerChan) + } + if !endStream { + return + } + // if client received END_STREAM from server while stream was still active, send RST_STREAM + rst := s.getState() == streamActive + t.closeStream(s, io.EOF, rst, http2.ErrCodeNo, state.status(), state.mdata, true) +} + +// reader runs as a separate goroutine in charge of reading data from network +// connection. +// +// TODO(zhaoq): currently one reader per transport. Investigate whether this is +// optimal. +// TODO(zhaoq): Check the validity of the incoming frame sequence. +func (t *http2Client) reader() { + defer close(t.readerDone) + // Check the validity of server preface. + frame, err := t.framer.fr.ReadFrame() + if err != nil { + t.Close() // this kicks off resetTransport, so must be last before return + return + } + t.conn.SetReadDeadline(time.Time{}) // reset deadline once we get the settings frame (we didn't time out, yay!) + if t.keepaliveEnabled { + atomic.CompareAndSwapUint32(&t.activity, 0, 1) + } + sf, ok := frame.(*http2.SettingsFrame) + if !ok { + t.Close() // this kicks off resetTransport, so must be last before return + return + } + t.onSuccess() + t.handleSettings(sf, true) + + // loop to keep reading incoming messages on this transport. + for { + frame, err := t.framer.fr.ReadFrame() + if t.keepaliveEnabled { + atomic.CompareAndSwapUint32(&t.activity, 0, 1) + } + if err != nil { + // Abort an active stream if the http2.Framer returns a + // http2.StreamError. This can happen only if the server's response + // is malformed http2. + if se, ok := err.(http2.StreamError); ok { + t.mu.Lock() + s := t.activeStreams[se.StreamID] + t.mu.Unlock() + if s != nil { + // use error detail to provide better err message + code := http2ErrConvTab[se.Code] + msg := t.framer.fr.ErrorDetail().Error() + t.closeStream(s, status.Error(code, msg), true, http2.ErrCodeProtocol, status.New(code, msg), nil, false) + } + continue + } else { + // Transport error. + t.Close() + return + } + } + switch frame := frame.(type) { + case *http2.MetaHeadersFrame: + t.operateHeaders(frame) + case *http2.DataFrame: + t.handleData(frame) + case *http2.RSTStreamFrame: + t.handleRSTStream(frame) + case *http2.SettingsFrame: + t.handleSettings(frame, false) + case *http2.PingFrame: + t.handlePing(frame) + case *http2.GoAwayFrame: + t.handleGoAway(frame) + case *http2.WindowUpdateFrame: + t.handleWindowUpdate(frame) + default: + errorf("transport: http2Client.reader got unhandled frame type %v.", frame) + } + } +} + +// keepalive running in a separate goroutune makes sure the connection is alive by sending pings. +func (t *http2Client) keepalive() { + p := &ping{data: [8]byte{}} + timer := time.NewTimer(t.kp.Time) + for { + select { + case <-timer.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + timer.Reset(t.kp.Time) + continue + } + // Check if keepalive should go dormant. + t.mu.Lock() + if len(t.activeStreams) < 1 && !t.kp.PermitWithoutStream { + // Make awakenKeepalive writable. + <-t.awakenKeepalive + t.mu.Unlock() + select { + case <-t.awakenKeepalive: + // If the control gets here a ping has been sent + // need to reset the timer with keepalive.Timeout. + case <-t.ctx.Done(): + return + } + } else { + t.mu.Unlock() + if channelz.IsOn() { + atomic.AddInt64(&t.czData.kpCount, 1) + } + // Send ping. + t.controlBuf.put(p) + } + + // By the time control gets here a ping has been sent one way or the other. + timer.Reset(t.kp.Timeout) + select { + case <-timer.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + timer.Reset(t.kp.Time) + continue + } + t.Close() + return + case <-t.ctx.Done(): + if !timer.Stop() { + <-timer.C + } + return + } + case <-t.ctx.Done(): + if !timer.Stop() { + <-timer.C + } + return + } + } +} + +func (t *http2Client) Error() <-chan struct{} { + return t.ctx.Done() +} + +func (t *http2Client) GoAway() <-chan struct{} { + return t.goAway +} + +func (t *http2Client) ChannelzMetric() *channelz.SocketInternalMetric { + s := channelz.SocketInternalMetric{ + StreamsStarted: atomic.LoadInt64(&t.czData.streamsStarted), + StreamsSucceeded: atomic.LoadInt64(&t.czData.streamsSucceeded), + StreamsFailed: atomic.LoadInt64(&t.czData.streamsFailed), + MessagesSent: atomic.LoadInt64(&t.czData.msgSent), + MessagesReceived: atomic.LoadInt64(&t.czData.msgRecv), + KeepAlivesSent: atomic.LoadInt64(&t.czData.kpCount), + LastLocalStreamCreatedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastStreamCreatedTime)), + LastMessageSentTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgSentTime)), + LastMessageReceivedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgRecvTime)), + LocalFlowControlWindow: int64(t.fc.getSize()), + SocketOptions: channelz.GetSocketOption(t.conn), + LocalAddr: t.localAddr, + RemoteAddr: t.remoteAddr, + // RemoteName : + } + if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok { + s.Security = au.GetSecurityValue() + } + s.RemoteFlowControlWindow = t.getOutFlowWindow() + return &s +} + +func (t *http2Client) IncrMsgSent() { + atomic.AddInt64(&t.czData.msgSent, 1) + atomic.StoreInt64(&t.czData.lastMsgSentTime, time.Now().UnixNano()) +} + +func (t *http2Client) IncrMsgRecv() { + atomic.AddInt64(&t.czData.msgRecv, 1) + atomic.StoreInt64(&t.czData.lastMsgRecvTime, time.Now().UnixNano()) +} + +func (t *http2Client) getOutFlowWindow() int64 { + resp := make(chan uint32, 1) + timer := time.NewTimer(time.Second) + defer timer.Stop() + t.controlBuf.put(&outFlowControlSizeRequest{resp}) + select { + case sz := <-resp: + return int64(sz) + case <-t.ctxDone: + return -1 + case <-timer.C: + return -2 + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go new file mode 100644 index 00000000..df274039 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -0,0 +1,1180 @@ +/* + * + * Copyright 2014 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 transport + +import ( + "bytes" + "context" + "errors" + "fmt" + "io" + "math" + "net" + "strconv" + "sync" + "sync/atomic" + "time" + + "github.com/golang/protobuf/proto" + "golang.org/x/net/http2" + "golang.org/x/net/http2/hpack" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +var ( + // ErrIllegalHeaderWrite indicates that setting header is illegal because of + // the stream's state. + ErrIllegalHeaderWrite = errors.New("transport: the stream is done or WriteHeader was already called") + // ErrHeaderListSizeLimitViolation indicates that the header list size is larger + // than the limit set by peer. + ErrHeaderListSizeLimitViolation = errors.New("transport: trying to send header list size larger than the limit set by peer") +) + +// http2Server implements the ServerTransport interface with HTTP2. +type http2Server struct { + ctx context.Context + ctxDone <-chan struct{} // Cache the context.Done() chan + cancel context.CancelFunc + conn net.Conn + loopy *loopyWriter + readerDone chan struct{} // sync point to enable testing. + writerDone chan struct{} // sync point to enable testing. + remoteAddr net.Addr + localAddr net.Addr + maxStreamID uint32 // max stream ID ever seen + authInfo credentials.AuthInfo // auth info about the connection + inTapHandle tap.ServerInHandle + framer *framer + // The max number of concurrent streams. + maxStreams uint32 + // controlBuf delivers all the control related tasks (e.g., window + // updates, reset streams, and various settings) to the controller. + controlBuf *controlBuffer + fc *trInFlow + stats stats.Handler + // Flag to keep track of reading activity on transport. + // 1 is true and 0 is false. + activity uint32 // Accessed atomically. + // Keepalive and max-age parameters for the server. + kp keepalive.ServerParameters + + // Keepalive enforcement policy. + kep keepalive.EnforcementPolicy + // The time instance last ping was received. + lastPingAt time.Time + // Number of times the client has violated keepalive ping policy so far. + pingStrikes uint8 + // Flag to signify that number of ping strikes should be reset to 0. + // This is set whenever data or header frames are sent. + // 1 means yes. + resetPingStrikes uint32 // Accessed atomically. + initialWindowSize int32 + bdpEst *bdpEstimator + maxSendHeaderListSize *uint32 + + mu sync.Mutex // guard the following + + // drainChan is initialized when drain(...) is called the first time. + // After which the server writes out the first GoAway(with ID 2^31-1) frame. + // Then an independent goroutine will be launched to later send the second GoAway. + // During this time we don't want to write another first GoAway(with ID 2^31 -1) frame. + // Thus call to drain(...) will be a no-op if drainChan is already initialized since draining is + // already underway. + drainChan chan struct{} + state transportState + activeStreams map[uint32]*Stream + // idle is the time instant when the connection went idle. + // This is either the beginning of the connection or when the number of + // RPCs go down to 0. + // When the connection is busy, this value is set to 0. + idle time.Time + + // Fields below are for channelz metric collection. + channelzID int64 // channelz unique identification number + czData *channelzData +} + +// newHTTP2Server constructs a ServerTransport based on HTTP2. ConnectionError is +// returned if something goes wrong. +func newHTTP2Server(conn net.Conn, config *ServerConfig) (_ ServerTransport, err error) { + writeBufSize := config.WriteBufferSize + readBufSize := config.ReadBufferSize + maxHeaderListSize := defaultServerMaxHeaderListSize + if config.MaxHeaderListSize != nil { + maxHeaderListSize = *config.MaxHeaderListSize + } + framer := newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize) + // Send initial settings as connection preface to client. + var isettings []http2.Setting + // TODO(zhaoq): Have a better way to signal "no limit" because 0 is + // permitted in the HTTP2 spec. + maxStreams := config.MaxStreams + if maxStreams == 0 { + maxStreams = math.MaxUint32 + } else { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingMaxConcurrentStreams, + Val: maxStreams, + }) + } + dynamicWindow := true + iwz := int32(initialWindowSize) + if config.InitialWindowSize >= defaultWindowSize { + iwz = config.InitialWindowSize + dynamicWindow = false + } + icwz := int32(initialWindowSize) + if config.InitialConnWindowSize >= defaultWindowSize { + icwz = config.InitialConnWindowSize + dynamicWindow = false + } + if iwz != defaultWindowSize { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingInitialWindowSize, + Val: uint32(iwz)}) + } + if config.MaxHeaderListSize != nil { + isettings = append(isettings, http2.Setting{ + ID: http2.SettingMaxHeaderListSize, + Val: *config.MaxHeaderListSize, + }) + } + if err := framer.fr.WriteSettings(isettings...); err != nil { + return nil, connectionErrorf(false, err, "transport: %v", err) + } + // Adjust the connection flow control window if needed. + if delta := uint32(icwz - defaultWindowSize); delta > 0 { + if err := framer.fr.WriteWindowUpdate(0, delta); err != nil { + return nil, connectionErrorf(false, err, "transport: %v", err) + } + } + kp := config.KeepaliveParams + if kp.MaxConnectionIdle == 0 { + kp.MaxConnectionIdle = defaultMaxConnectionIdle + } + if kp.MaxConnectionAge == 0 { + kp.MaxConnectionAge = defaultMaxConnectionAge + } + // Add a jitter to MaxConnectionAge. + kp.MaxConnectionAge += getJitter(kp.MaxConnectionAge) + if kp.MaxConnectionAgeGrace == 0 { + kp.MaxConnectionAgeGrace = defaultMaxConnectionAgeGrace + } + if kp.Time == 0 { + kp.Time = defaultServerKeepaliveTime + } + if kp.Timeout == 0 { + kp.Timeout = defaultServerKeepaliveTimeout + } + kep := config.KeepalivePolicy + if kep.MinTime == 0 { + kep.MinTime = defaultKeepalivePolicyMinTime + } + ctx, cancel := context.WithCancel(context.Background()) + t := &http2Server{ + ctx: ctx, + cancel: cancel, + ctxDone: ctx.Done(), + conn: conn, + remoteAddr: conn.RemoteAddr(), + localAddr: conn.LocalAddr(), + authInfo: config.AuthInfo, + framer: framer, + readerDone: make(chan struct{}), + writerDone: make(chan struct{}), + maxStreams: maxStreams, + inTapHandle: config.InTapHandle, + fc: &trInFlow{limit: uint32(icwz)}, + state: reachable, + activeStreams: make(map[uint32]*Stream), + stats: config.StatsHandler, + kp: kp, + idle: time.Now(), + kep: kep, + initialWindowSize: iwz, + czData: new(channelzData), + } + t.controlBuf = newControlBuffer(t.ctxDone) + if dynamicWindow { + t.bdpEst = &bdpEstimator{ + bdp: initialWindowSize, + updateFlowControl: t.updateFlowControl, + } + } + if t.stats != nil { + t.ctx = t.stats.TagConn(t.ctx, &stats.ConnTagInfo{ + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + }) + connBegin := &stats.ConnBegin{} + t.stats.HandleConn(t.ctx, connBegin) + } + if channelz.IsOn() { + t.channelzID = channelz.RegisterNormalSocket(t, config.ChannelzParentID, fmt.Sprintf("%s -> %s", t.remoteAddr, t.localAddr)) + } + t.framer.writer.Flush() + + defer func() { + if err != nil { + t.Close() + } + }() + + // Check the validity of client preface. + preface := make([]byte, len(clientPreface)) + if _, err := io.ReadFull(t.conn, preface); err != nil { + return nil, connectionErrorf(false, err, "transport: http2Server.HandleStreams failed to receive the preface from client: %v", err) + } + if !bytes.Equal(preface, clientPreface) { + return nil, connectionErrorf(false, nil, "transport: http2Server.HandleStreams received bogus greeting from client: %q", preface) + } + + frame, err := t.framer.fr.ReadFrame() + if err == io.EOF || err == io.ErrUnexpectedEOF { + return nil, err + } + if err != nil { + return nil, connectionErrorf(false, err, "transport: http2Server.HandleStreams failed to read initial settings frame: %v", err) + } + atomic.StoreUint32(&t.activity, 1) + sf, ok := frame.(*http2.SettingsFrame) + if !ok { + return nil, connectionErrorf(false, nil, "transport: http2Server.HandleStreams saw invalid preface type %T from client", frame) + } + t.handleSettings(sf) + + go func() { + t.loopy = newLoopyWriter(serverSide, t.framer, t.controlBuf, t.bdpEst) + t.loopy.ssGoAwayHandler = t.outgoingGoAwayHandler + if err := t.loopy.run(); err != nil { + errorf("transport: loopyWriter.run returning. Err: %v", err) + } + t.conn.Close() + close(t.writerDone) + }() + go t.keepalive() + return t, nil +} + +// operateHeader takes action on the decoded headers. +func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream), traceCtx func(context.Context, string) context.Context) (fatal bool) { + streamID := frame.Header().StreamID + state := decodeState{serverSide: true} + if err := state.decodeHeader(frame); err != nil { + if se, ok := status.FromError(err); ok { + t.controlBuf.put(&cleanupStream{ + streamID: streamID, + rst: true, + rstCode: statusCodeConvTab[se.Code()], + onWrite: func() {}, + }) + } + return false + } + + buf := newRecvBuffer() + s := &Stream{ + id: streamID, + st: t, + buf: buf, + fc: &inFlow{limit: uint32(t.initialWindowSize)}, + recvCompress: state.encoding, + method: state.method, + contentSubtype: state.contentSubtype, + } + if frame.StreamEnded() { + // s is just created by the caller. No lock needed. + s.state = streamReadDone + } + if state.timeoutSet { + s.ctx, s.cancel = context.WithTimeout(t.ctx, state.timeout) + } else { + s.ctx, s.cancel = context.WithCancel(t.ctx) + } + pr := &peer.Peer{ + Addr: t.remoteAddr, + } + // Attach Auth info if there is any. + if t.authInfo != nil { + pr.AuthInfo = t.authInfo + } + s.ctx = peer.NewContext(s.ctx, pr) + // Attach the received metadata to the context. + if len(state.mdata) > 0 { + s.ctx = metadata.NewIncomingContext(s.ctx, state.mdata) + } + if state.statsTags != nil { + s.ctx = stats.SetIncomingTags(s.ctx, state.statsTags) + } + if state.statsTrace != nil { + s.ctx = stats.SetIncomingTrace(s.ctx, state.statsTrace) + } + if t.inTapHandle != nil { + var err error + info := &tap.Info{ + FullMethodName: state.method, + } + s.ctx, err = t.inTapHandle(s.ctx, info) + if err != nil { + warningf("transport: http2Server.operateHeaders got an error from InTapHandle: %v", err) + t.controlBuf.put(&cleanupStream{ + streamID: s.id, + rst: true, + rstCode: http2.ErrCodeRefusedStream, + onWrite: func() {}, + }) + return false + } + } + t.mu.Lock() + if t.state != reachable { + t.mu.Unlock() + return false + } + if uint32(len(t.activeStreams)) >= t.maxStreams { + t.mu.Unlock() + t.controlBuf.put(&cleanupStream{ + streamID: streamID, + rst: true, + rstCode: http2.ErrCodeRefusedStream, + onWrite: func() {}, + }) + return false + } + if streamID%2 != 1 || streamID <= t.maxStreamID { + t.mu.Unlock() + // illegal gRPC stream id. + errorf("transport: http2Server.HandleStreams received an illegal stream id: %v", streamID) + return true + } + t.maxStreamID = streamID + t.activeStreams[streamID] = s + if len(t.activeStreams) == 1 { + t.idle = time.Time{} + } + t.mu.Unlock() + if channelz.IsOn() { + atomic.AddInt64(&t.czData.streamsStarted, 1) + atomic.StoreInt64(&t.czData.lastStreamCreatedTime, time.Now().UnixNano()) + } + s.requestRead = func(n int) { + t.adjustWindow(s, uint32(n)) + } + s.ctx = traceCtx(s.ctx, s.method) + if t.stats != nil { + s.ctx = t.stats.TagRPC(s.ctx, &stats.RPCTagInfo{FullMethodName: s.method}) + inHeader := &stats.InHeader{ + FullMethod: s.method, + RemoteAddr: t.remoteAddr, + LocalAddr: t.localAddr, + Compression: s.recvCompress, + WireLength: int(frame.Header().Length), + } + t.stats.HandleRPC(s.ctx, inHeader) + } + s.ctxDone = s.ctx.Done() + s.wq = newWriteQuota(defaultWriteQuota, s.ctxDone) + s.trReader = &transportReader{ + reader: &recvBufferReader{ + ctx: s.ctx, + ctxDone: s.ctxDone, + recv: s.buf, + }, + windowHandler: func(n int) { + t.updateWindow(s, uint32(n)) + }, + } + // Register the stream with loopy. + t.controlBuf.put(®isterStream{ + streamID: s.id, + wq: s.wq, + }) + handle(s) + return false +} + +// HandleStreams receives incoming streams using the given handler. This is +// typically run in a separate goroutine. +// traceCtx attaches trace to ctx and returns the new context. +func (t *http2Server) HandleStreams(handle func(*Stream), traceCtx func(context.Context, string) context.Context) { + defer close(t.readerDone) + for { + frame, err := t.framer.fr.ReadFrame() + atomic.StoreUint32(&t.activity, 1) + if err != nil { + if se, ok := err.(http2.StreamError); ok { + warningf("transport: http2Server.HandleStreams encountered http2.StreamError: %v", se) + t.mu.Lock() + s := t.activeStreams[se.StreamID] + t.mu.Unlock() + if s != nil { + t.closeStream(s, true, se.Code, nil, false) + } else { + t.controlBuf.put(&cleanupStream{ + streamID: se.StreamID, + rst: true, + rstCode: se.Code, + onWrite: func() {}, + }) + } + continue + } + if err == io.EOF || err == io.ErrUnexpectedEOF { + t.Close() + return + } + warningf("transport: http2Server.HandleStreams failed to read frame: %v", err) + t.Close() + return + } + switch frame := frame.(type) { + case *http2.MetaHeadersFrame: + if t.operateHeaders(frame, handle, traceCtx) { + t.Close() + break + } + case *http2.DataFrame: + t.handleData(frame) + case *http2.RSTStreamFrame: + t.handleRSTStream(frame) + case *http2.SettingsFrame: + t.handleSettings(frame) + case *http2.PingFrame: + t.handlePing(frame) + case *http2.WindowUpdateFrame: + t.handleWindowUpdate(frame) + case *http2.GoAwayFrame: + // TODO: Handle GoAway from the client appropriately. + default: + errorf("transport: http2Server.HandleStreams found unhandled frame type %v.", frame) + } + } +} + +func (t *http2Server) getStream(f http2.Frame) (*Stream, bool) { + t.mu.Lock() + defer t.mu.Unlock() + if t.activeStreams == nil { + // The transport is closing. + return nil, false + } + s, ok := t.activeStreams[f.Header().StreamID] + if !ok { + // The stream is already done. + return nil, false + } + return s, true +} + +// adjustWindow sends out extra window update over the initial window size +// of stream if the application is requesting data larger in size than +// the window. +func (t *http2Server) adjustWindow(s *Stream, n uint32) { + if w := s.fc.maybeAdjust(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, increment: w}) + } + +} + +// updateWindow adjusts the inbound quota for the stream and the transport. +// Window updates will deliver to the controller for sending when +// the cumulative quota exceeds the corresponding threshold. +func (t *http2Server) updateWindow(s *Stream, n uint32) { + if w := s.fc.onRead(n); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{streamID: s.id, + increment: w, + }) + } +} + +// updateFlowControl updates the incoming flow control windows +// for the transport and the stream based on the current bdp +// estimation. +func (t *http2Server) updateFlowControl(n uint32) { + t.mu.Lock() + for _, s := range t.activeStreams { + s.fc.newLimit(n) + } + t.initialWindowSize = int32(n) + t.mu.Unlock() + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: t.fc.newLimit(n), + }) + t.controlBuf.put(&outgoingSettings{ + ss: []http2.Setting{ + { + ID: http2.SettingInitialWindowSize, + Val: n, + }, + }, + }) + +} + +func (t *http2Server) handleData(f *http2.DataFrame) { + size := f.Header().Length + var sendBDPPing bool + if t.bdpEst != nil { + sendBDPPing = t.bdpEst.add(size) + } + // Decouple connection's flow control from application's read. + // An update on connection's flow control should not depend on + // whether user application has read the data or not. Such a + // restriction is already imposed on the stream's flow control, + // and therefore the sender will be blocked anyways. + // Decoupling the connection flow control will prevent other + // active(fast) streams from starving in presence of slow or + // inactive streams. + if w := t.fc.onData(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + if sendBDPPing { + // Avoid excessive ping detection (e.g. in an L7 proxy) + // by sending a window update prior to the BDP ping. + if w := t.fc.reset(); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: 0, + increment: w, + }) + } + t.controlBuf.put(bdpPing) + } + // Select the right stream to dispatch. + s, ok := t.getStream(f) + if !ok { + return + } + if size > 0 { + if err := s.fc.onData(size); err != nil { + t.closeStream(s, true, http2.ErrCodeFlowControl, nil, false) + return + } + if f.Header().Flags.Has(http2.FlagDataPadded) { + if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + } + } + // TODO(bradfitz, zhaoq): A copy is required here because there is no + // guarantee f.Data() is consumed before the arrival of next frame. + // Can this copy be eliminated? + if len(f.Data()) > 0 { + data := make([]byte, len(f.Data())) + copy(data, f.Data()) + s.write(recvMsg{data: data}) + } + } + if f.Header().Flags.Has(http2.FlagDataEndStream) { + // Received the end of stream from the client. + s.compareAndSwapState(streamActive, streamReadDone) + s.write(recvMsg{err: io.EOF}) + } +} + +func (t *http2Server) handleRSTStream(f *http2.RSTStreamFrame) { + s, ok := t.getStream(f) + if !ok { + return + } + t.closeStream(s, false, 0, nil, false) +} + +func (t *http2Server) handleSettings(f *http2.SettingsFrame) { + if f.IsAck() { + return + } + var ss []http2.Setting + var updateFuncs []func() + f.ForeachSetting(func(s http2.Setting) error { + switch s.ID { + case http2.SettingMaxHeaderListSize: + updateFuncs = append(updateFuncs, func() { + t.maxSendHeaderListSize = new(uint32) + *t.maxSendHeaderListSize = s.Val + }) + default: + ss = append(ss, s) + } + return nil + }) + t.controlBuf.executeAndPut(func(interface{}) bool { + for _, f := range updateFuncs { + f() + } + return true + }, &incomingSettings{ + ss: ss, + }) +} + +const ( + maxPingStrikes = 2 + defaultPingTimeout = 2 * time.Hour +) + +func (t *http2Server) handlePing(f *http2.PingFrame) { + if f.IsAck() { + if f.Data == goAwayPing.data && t.drainChan != nil { + close(t.drainChan) + return + } + // Maybe it's a BDP ping. + if t.bdpEst != nil { + t.bdpEst.calculate(f.Data) + } + return + } + pingAck := &ping{ack: true} + copy(pingAck.data[:], f.Data[:]) + t.controlBuf.put(pingAck) + + now := time.Now() + defer func() { + t.lastPingAt = now + }() + // A reset ping strikes means that we don't need to check for policy + // violation for this ping and the pingStrikes counter should be set + // to 0. + if atomic.CompareAndSwapUint32(&t.resetPingStrikes, 1, 0) { + t.pingStrikes = 0 + return + } + t.mu.Lock() + ns := len(t.activeStreams) + t.mu.Unlock() + if ns < 1 && !t.kep.PermitWithoutStream { + // Keepalive shouldn't be active thus, this new ping should + // have come after at least defaultPingTimeout. + if t.lastPingAt.Add(defaultPingTimeout).After(now) { + t.pingStrikes++ + } + } else { + // Check if keepalive policy is respected. + if t.lastPingAt.Add(t.kep.MinTime).After(now) { + t.pingStrikes++ + } + } + + if t.pingStrikes > maxPingStrikes { + // Send goaway and close the connection. + errorf("transport: Got too many pings from the client, closing the connection.") + t.controlBuf.put(&goAway{code: http2.ErrCodeEnhanceYourCalm, debugData: []byte("too_many_pings"), closeConn: true}) + } +} + +func (t *http2Server) handleWindowUpdate(f *http2.WindowUpdateFrame) { + t.controlBuf.put(&incomingWindowUpdate{ + streamID: f.Header().StreamID, + increment: f.Increment, + }) +} + +func appendHeaderFieldsFromMD(headerFields []hpack.HeaderField, md metadata.MD) []hpack.HeaderField { + for k, vv := range md { + if isReservedHeader(k) { + // Clients don't tolerate reading restricted headers after some non restricted ones were sent. + continue + } + for _, v := range vv { + headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) + } + } + return headerFields +} + +func (t *http2Server) checkForHeaderListSize(it interface{}) bool { + if t.maxSendHeaderListSize == nil { + return true + } + hdrFrame := it.(*headerFrame) + var sz int64 + for _, f := range hdrFrame.hf { + if sz += int64(f.Size()); sz > int64(*t.maxSendHeaderListSize) { + errorf("header list size to send violates the maximum size (%d bytes) set by client", *t.maxSendHeaderListSize) + return false + } + } + return true +} + +// WriteHeader sends the header metedata md back to the client. +func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error { + if s.updateHeaderSent() || s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + if md.Len() > 0 { + if s.header.Len() > 0 { + s.header = metadata.Join(s.header, md) + } else { + s.header = md + } + } + if err := t.writeHeaderLocked(s); err != nil { + s.hdrMu.Unlock() + return err + } + s.hdrMu.Unlock() + return nil +} + +func (t *http2Server) writeHeaderLocked(s *Stream) error { + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + headerFields := make([]hpack.HeaderField, 0, 2) // at least :status, content-type will be there if none else. + headerFields = append(headerFields, hpack.HeaderField{Name: ":status", Value: "200"}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(s.contentSubtype)}) + if s.sendCompress != "" { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: s.sendCompress}) + } + headerFields = appendHeaderFieldsFromMD(headerFields, s.header) + success, err := t.controlBuf.executeAndPut(t.checkForHeaderListSize, &headerFrame{ + streamID: s.id, + hf: headerFields, + endStream: false, + onWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + }) + if !success { + if err != nil { + return err + } + t.closeStream(s, true, http2.ErrCodeInternal, nil, false) + return ErrHeaderListSizeLimitViolation + } + if t.stats != nil { + // Note: WireLength is not set in outHeader. + // TODO(mmukhi): Revisit this later, if needed. + outHeader := &stats.OutHeader{} + t.stats.HandleRPC(s.Context(), outHeader) + } + return nil +} + +// WriteStatus sends stream status to the client and terminates the stream. +// There is no further I/O operations being able to perform on this stream. +// TODO(zhaoq): Now it indicates the end of entire stream. Revisit if early +// OK is adopted. +func (t *http2Server) WriteStatus(s *Stream, st *status.Status) error { + if s.getState() == streamDone { + return nil + } + s.hdrMu.Lock() + // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields + // first and create a slice of that exact size. + headerFields := make([]hpack.HeaderField, 0, 2) // grpc-status and grpc-message will be there if none else. + if !s.updateHeaderSent() { // No headers have been sent. + if len(s.header) > 0 { // Send a separate header frame. + if err := t.writeHeaderLocked(s); err != nil { + s.hdrMu.Unlock() + return err + } + } else { // Send a trailer only response. + headerFields = append(headerFields, hpack.HeaderField{Name: ":status", Value: "200"}) + headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: contentType(s.contentSubtype)}) + } + } + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-status", Value: strconv.Itoa(int(st.Code()))}) + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-message", Value: encodeGrpcMessage(st.Message())}) + + if p := st.Proto(); p != nil && len(p.Details) > 0 { + stBytes, err := proto.Marshal(p) + if err != nil { + // TODO: return error instead, when callers are able to handle it. + grpclog.Errorf("transport: failed to marshal rpc status: %v, error: %v", p, err) + } else { + headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-status-details-bin", Value: encodeBinHeader(stBytes)}) + } + } + + // Attach the trailer metadata. + headerFields = appendHeaderFieldsFromMD(headerFields, s.trailer) + trailingHeader := &headerFrame{ + streamID: s.id, + hf: headerFields, + endStream: true, + onWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + } + s.hdrMu.Unlock() + success, err := t.controlBuf.execute(t.checkForHeaderListSize, trailingHeader) + if !success { + if err != nil { + return err + } + t.closeStream(s, true, http2.ErrCodeInternal, nil, false) + return ErrHeaderListSizeLimitViolation + } + t.closeStream(s, false, 0, trailingHeader, true) + if t.stats != nil { + t.stats.HandleRPC(s.Context(), &stats.OutTrailer{}) + } + return nil +} + +// Write converts the data into HTTP2 data frame and sends it out. Non-nil error +// is returns if it fails (e.g., framing error, transport error). +func (t *http2Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) error { + if !s.isHeaderSent() { // Headers haven't been written yet. + if err := t.WriteHeader(s, nil); err != nil { + // TODO(mmukhi, dfawley): Make sure this is the right code to return. + return status.Errorf(codes.Internal, "transport: %v", err) + } + } else { + // Writing headers checks for this condition. + if s.getState() == streamDone { + // TODO(mmukhi, dfawley): Should the server write also return io.EOF? + s.cancel() + select { + case <-t.ctx.Done(): + return ErrConnClosing + default: + } + return ContextErr(s.ctx.Err()) + } + } + // Add some data to header frame so that we can equally distribute bytes across frames. + emptyLen := http2MaxFrameLen - len(hdr) + if emptyLen > len(data) { + emptyLen = len(data) + } + hdr = append(hdr, data[:emptyLen]...) + data = data[emptyLen:] + df := &dataFrame{ + streamID: s.id, + h: hdr, + d: data, + onEachWrite: func() { + atomic.StoreUint32(&t.resetPingStrikes, 1) + }, + } + if err := s.wq.get(int32(len(hdr) + len(data))); err != nil { + select { + case <-t.ctx.Done(): + return ErrConnClosing + default: + } + return ContextErr(s.ctx.Err()) + } + return t.controlBuf.put(df) +} + +// keepalive running in a separate goroutine does the following: +// 1. Gracefully closes an idle connection after a duration of keepalive.MaxConnectionIdle. +// 2. Gracefully closes any connection after a duration of keepalive.MaxConnectionAge. +// 3. Forcibly closes a connection after an additive period of keepalive.MaxConnectionAgeGrace over keepalive.MaxConnectionAge. +// 4. Makes sure a connection is alive by sending pings with a frequency of keepalive.Time and closes a non-responsive connection +// after an additional duration of keepalive.Timeout. +func (t *http2Server) keepalive() { + p := &ping{} + var pingSent bool + maxIdle := time.NewTimer(t.kp.MaxConnectionIdle) + maxAge := time.NewTimer(t.kp.MaxConnectionAge) + keepalive := time.NewTimer(t.kp.Time) + // NOTE: All exit paths of this function should reset their + // respective timers. A failure to do so will cause the + // following clean-up to deadlock and eventually leak. + defer func() { + if !maxIdle.Stop() { + <-maxIdle.C + } + if !maxAge.Stop() { + <-maxAge.C + } + if !keepalive.Stop() { + <-keepalive.C + } + }() + for { + select { + case <-maxIdle.C: + t.mu.Lock() + idle := t.idle + if idle.IsZero() { // The connection is non-idle. + t.mu.Unlock() + maxIdle.Reset(t.kp.MaxConnectionIdle) + continue + } + val := t.kp.MaxConnectionIdle - time.Since(idle) + t.mu.Unlock() + if val <= 0 { + // The connection has been idle for a duration of keepalive.MaxConnectionIdle or more. + // Gracefully close the connection. + t.drain(http2.ErrCodeNo, []byte{}) + // Resetting the timer so that the clean-up doesn't deadlock. + maxIdle.Reset(infinity) + return + } + maxIdle.Reset(val) + case <-maxAge.C: + t.drain(http2.ErrCodeNo, []byte{}) + maxAge.Reset(t.kp.MaxConnectionAgeGrace) + select { + case <-maxAge.C: + // Close the connection after grace period. + t.Close() + // Resetting the timer so that the clean-up doesn't deadlock. + maxAge.Reset(infinity) + case <-t.ctx.Done(): + } + return + case <-keepalive.C: + if atomic.CompareAndSwapUint32(&t.activity, 1, 0) { + pingSent = false + keepalive.Reset(t.kp.Time) + continue + } + if pingSent { + t.Close() + // Resetting the timer so that the clean-up doesn't deadlock. + keepalive.Reset(infinity) + return + } + pingSent = true + if channelz.IsOn() { + atomic.AddInt64(&t.czData.kpCount, 1) + } + t.controlBuf.put(p) + keepalive.Reset(t.kp.Timeout) + case <-t.ctx.Done(): + return + } + } +} + +// Close starts shutting down the http2Server transport. +// TODO(zhaoq): Now the destruction is not blocked on any pending streams. This +// could cause some resource issue. Revisit this later. +func (t *http2Server) Close() error { + t.mu.Lock() + if t.state == closing { + t.mu.Unlock() + return errors.New("transport: Close() was already called") + } + t.state = closing + streams := t.activeStreams + t.activeStreams = nil + t.mu.Unlock() + t.controlBuf.finish() + t.cancel() + err := t.conn.Close() + if channelz.IsOn() { + channelz.RemoveEntry(t.channelzID) + } + // Cancel all active streams. + for _, s := range streams { + s.cancel() + } + if t.stats != nil { + connEnd := &stats.ConnEnd{} + t.stats.HandleConn(t.ctx, connEnd) + } + return err +} + +// closeStream clears the footprint of a stream when the stream is not needed +// any more. +func (t *http2Server) closeStream(s *Stream, rst bool, rstCode http2.ErrCode, hdr *headerFrame, eosReceived bool) { + if s.swapState(streamDone) == streamDone { + // If the stream was already done, return. + return + } + // In case stream sending and receiving are invoked in separate + // goroutines (e.g., bi-directional streaming), cancel needs to be + // called to interrupt the potential blocking on other goroutines. + s.cancel() + cleanup := &cleanupStream{ + streamID: s.id, + rst: rst, + rstCode: rstCode, + onWrite: func() { + t.mu.Lock() + if t.activeStreams != nil { + delete(t.activeStreams, s.id) + if len(t.activeStreams) == 0 { + t.idle = time.Now() + } + } + t.mu.Unlock() + if channelz.IsOn() { + if eosReceived { + atomic.AddInt64(&t.czData.streamsSucceeded, 1) + } else { + atomic.AddInt64(&t.czData.streamsFailed, 1) + } + } + }, + } + if hdr != nil { + hdr.cleanup = cleanup + t.controlBuf.put(hdr) + } else { + t.controlBuf.put(cleanup) + } +} + +func (t *http2Server) RemoteAddr() net.Addr { + return t.remoteAddr +} + +func (t *http2Server) Drain() { + t.drain(http2.ErrCodeNo, []byte{}) +} + +func (t *http2Server) drain(code http2.ErrCode, debugData []byte) { + t.mu.Lock() + defer t.mu.Unlock() + if t.drainChan != nil { + return + } + t.drainChan = make(chan struct{}) + t.controlBuf.put(&goAway{code: code, debugData: debugData, headsUp: true}) +} + +var goAwayPing = &ping{data: [8]byte{1, 6, 1, 8, 0, 3, 3, 9}} + +// Handles outgoing GoAway and returns true if loopy needs to put itself +// in draining mode. +func (t *http2Server) outgoingGoAwayHandler(g *goAway) (bool, error) { + t.mu.Lock() + if t.state == closing { // TODO(mmukhi): This seems unnecessary. + t.mu.Unlock() + // The transport is closing. + return false, ErrConnClosing + } + sid := t.maxStreamID + if !g.headsUp { + // Stop accepting more streams now. + t.state = draining + if len(t.activeStreams) == 0 { + g.closeConn = true + } + t.mu.Unlock() + if err := t.framer.fr.WriteGoAway(sid, g.code, g.debugData); err != nil { + return false, err + } + if g.closeConn { + // Abruptly close the connection following the GoAway (via + // loopywriter). But flush out what's inside the buffer first. + t.framer.writer.Flush() + return false, fmt.Errorf("transport: Connection closing") + } + return true, nil + } + t.mu.Unlock() + // For a graceful close, send out a GoAway with stream ID of MaxUInt32, + // Follow that with a ping and wait for the ack to come back or a timer + // to expire. During this time accept new streams since they might have + // originated before the GoAway reaches the client. + // After getting the ack or timer expiration send out another GoAway this + // time with an ID of the max stream server intends to process. + if err := t.framer.fr.WriteGoAway(math.MaxUint32, http2.ErrCodeNo, []byte{}); err != nil { + return false, err + } + if err := t.framer.fr.WritePing(false, goAwayPing.data); err != nil { + return false, err + } + go func() { + timer := time.NewTimer(time.Minute) + defer timer.Stop() + select { + case <-t.drainChan: + case <-timer.C: + case <-t.ctx.Done(): + return + } + t.controlBuf.put(&goAway{code: g.code, debugData: g.debugData}) + }() + return false, nil +} + +func (t *http2Server) ChannelzMetric() *channelz.SocketInternalMetric { + s := channelz.SocketInternalMetric{ + StreamsStarted: atomic.LoadInt64(&t.czData.streamsStarted), + StreamsSucceeded: atomic.LoadInt64(&t.czData.streamsSucceeded), + StreamsFailed: atomic.LoadInt64(&t.czData.streamsFailed), + MessagesSent: atomic.LoadInt64(&t.czData.msgSent), + MessagesReceived: atomic.LoadInt64(&t.czData.msgRecv), + KeepAlivesSent: atomic.LoadInt64(&t.czData.kpCount), + LastRemoteStreamCreatedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastStreamCreatedTime)), + LastMessageSentTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgSentTime)), + LastMessageReceivedTimestamp: time.Unix(0, atomic.LoadInt64(&t.czData.lastMsgRecvTime)), + LocalFlowControlWindow: int64(t.fc.getSize()), + SocketOptions: channelz.GetSocketOption(t.conn), + LocalAddr: t.localAddr, + RemoteAddr: t.remoteAddr, + // RemoteName : + } + if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok { + s.Security = au.GetSecurityValue() + } + s.RemoteFlowControlWindow = t.getOutFlowWindow() + return &s +} + +func (t *http2Server) IncrMsgSent() { + atomic.AddInt64(&t.czData.msgSent, 1) + atomic.StoreInt64(&t.czData.lastMsgSentTime, time.Now().UnixNano()) +} + +func (t *http2Server) IncrMsgRecv() { + atomic.AddInt64(&t.czData.msgRecv, 1) + atomic.StoreInt64(&t.czData.lastMsgRecvTime, time.Now().UnixNano()) +} + +func (t *http2Server) getOutFlowWindow() int64 { + resp := make(chan uint32) + timer := time.NewTimer(time.Second) + defer timer.Stop() + t.controlBuf.put(&outFlowControlSizeRequest{resp}) + select { + case sz := <-resp: + return int64(sz) + case <-t.ctxDone: + return -1 + case <-timer.C: + return -2 + } +} + +func getJitter(v time.Duration) time.Duration { + if v == infinity { + return 0 + } + // Generate a jitter between +/- 10% of the value. + r := int64(v / 10) + j := grpcrand.Int63n(2*r) - r + return time.Duration(j) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/http_util.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http_util.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/http_util.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/http_util.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/log.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/log.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/internal/transport/log.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/log.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go new file mode 100644 index 00000000..4d7e8906 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -0,0 +1,736 @@ +/* + * + * Copyright 2014 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 transport defines and implements message oriented communication +// channel to complete various transactions (e.g., an RPC). It is meant for +// grpc-internal usage and is not intended to be imported directly by users. +package transport + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "sync" + "sync/atomic" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +// recvMsg represents the received msg from the transport. All transport +// protocol specific info has been removed. +type recvMsg struct { + data []byte + // nil: received some data + // io.EOF: stream is completed. data is nil. + // other non-nil error: transport failure. data is nil. + err error +} + +// recvBuffer is an unbounded channel of recvMsg structs. +// Note recvBuffer differs from controlBuffer only in that recvBuffer +// holds a channel of only recvMsg structs instead of objects implementing "item" interface. +// recvBuffer is written to much more often than +// controlBuffer and using strict recvMsg structs helps avoid allocation in "recvBuffer.put" +type recvBuffer struct { + c chan recvMsg + mu sync.Mutex + backlog []recvMsg + err error +} + +func newRecvBuffer() *recvBuffer { + b := &recvBuffer{ + c: make(chan recvMsg, 1), + } + return b +} + +func (b *recvBuffer) put(r recvMsg) { + b.mu.Lock() + if b.err != nil { + b.mu.Unlock() + // An error had occurred earlier, don't accept more + // data or errors. + return + } + b.err = r.err + if len(b.backlog) == 0 { + select { + case b.c <- r: + b.mu.Unlock() + return + default: + } + } + b.backlog = append(b.backlog, r) + b.mu.Unlock() +} + +func (b *recvBuffer) load() { + b.mu.Lock() + if len(b.backlog) > 0 { + select { + case b.c <- b.backlog[0]: + b.backlog[0] = recvMsg{} + b.backlog = b.backlog[1:] + default: + } + } + b.mu.Unlock() +} + +// get returns the channel that receives a recvMsg in the buffer. +// +// Upon receipt of a recvMsg, the caller should call load to send another +// recvMsg onto the channel if there is any. +func (b *recvBuffer) get() <-chan recvMsg { + return b.c +} + +// +// recvBufferReader implements io.Reader interface to read the data from +// recvBuffer. +type recvBufferReader struct { + ctx context.Context + ctxDone <-chan struct{} // cache of ctx.Done() (for performance). + recv *recvBuffer + last []byte // Stores the remaining data in the previous calls. + err error +} + +// Read reads the next len(p) bytes from last. If last is drained, it tries to +// read additional data from recv. It blocks if there no additional data available +// in recv. If Read returns any non-nil error, it will continue to return that error. +func (r *recvBufferReader) Read(p []byte) (n int, err error) { + if r.err != nil { + return 0, r.err + } + n, r.err = r.read(p) + return n, r.err +} + +func (r *recvBufferReader) read(p []byte) (n int, err error) { + if r.last != nil && len(r.last) > 0 { + // Read remaining data left in last call. + copied := copy(p, r.last) + r.last = r.last[copied:] + return copied, nil + } + select { + case <-r.ctxDone: + return 0, ContextErr(r.ctx.Err()) + case m := <-r.recv.get(): + r.recv.load() + if m.err != nil { + return 0, m.err + } + copied := copy(p, m.data) + r.last = m.data[copied:] + return copied, nil + } +} + +type streamState uint32 + +const ( + streamActive streamState = iota + streamWriteDone // EndStream sent + streamReadDone // EndStream received + streamDone // the entire stream is finished. +) + +// Stream represents an RPC in the transport layer. +type Stream struct { + id uint32 + st ServerTransport // nil for client side Stream + ctx context.Context // the associated context of the stream + cancel context.CancelFunc // always nil for client side Stream + done chan struct{} // closed at the end of stream to unblock writers. On the client side. + ctxDone <-chan struct{} // same as done chan but for server side. Cache of ctx.Done() (for performance) + method string // the associated RPC method of the stream + recvCompress string + sendCompress string + buf *recvBuffer + trReader io.Reader + fc *inFlow + wq *writeQuota + + // Callback to state application's intentions to read data. This + // is used to adjust flow control, if needed. + requestRead func(int) + + headerChan chan struct{} // closed to indicate the end of header metadata. + headerDone uint32 // set when headerChan is closed. Used to avoid closing headerChan multiple times. + + // hdrMu protects header and trailer metadata on the server-side. + hdrMu sync.Mutex + // On client side, header keeps the received header metadata. + // + // On server side, header keeps the header set by SetHeader(). The complete + // header will merged into this after t.WriteHeader() is called. + header metadata.MD + trailer metadata.MD // the key-value map of trailer metadata. + + noHeaders bool // set if the client never received headers (set only after the stream is done). + + // On the server-side, headerSent is atomically set to 1 when the headers are sent out. + headerSent uint32 + + state streamState + + // On client-side it is the status error received from the server. + // On server-side it is unused. + status *status.Status + + bytesReceived uint32 // indicates whether any bytes have been received on this stream + unprocessed uint32 // set if the server sends a refused stream or GOAWAY including this stream + + // contentSubtype is the content-subtype for requests. + // this must be lowercase or the behavior is undefined. + contentSubtype string +} + +// isHeaderSent is only valid on the server-side. +func (s *Stream) isHeaderSent() bool { + return atomic.LoadUint32(&s.headerSent) == 1 +} + +// updateHeaderSent updates headerSent and returns true +// if it was alreay set. It is valid only on server-side. +func (s *Stream) updateHeaderSent() bool { + return atomic.SwapUint32(&s.headerSent, 1) == 1 +} + +func (s *Stream) swapState(st streamState) streamState { + return streamState(atomic.SwapUint32((*uint32)(&s.state), uint32(st))) +} + +func (s *Stream) compareAndSwapState(oldState, newState streamState) bool { + return atomic.CompareAndSwapUint32((*uint32)(&s.state), uint32(oldState), uint32(newState)) +} + +func (s *Stream) getState() streamState { + return streamState(atomic.LoadUint32((*uint32)(&s.state))) +} + +func (s *Stream) waitOnHeader() error { + if s.headerChan == nil { + // On the server headerChan is always nil since a stream originates + // only after having received headers. + return nil + } + select { + case <-s.ctx.Done(): + return ContextErr(s.ctx.Err()) + case <-s.headerChan: + return nil + } +} + +// RecvCompress returns the compression algorithm applied to the inbound +// message. It is empty string if there is no compression applied. +func (s *Stream) RecvCompress() string { + if err := s.waitOnHeader(); err != nil { + return "" + } + return s.recvCompress +} + +// SetSendCompress sets the compression algorithm to the stream. +func (s *Stream) SetSendCompress(str string) { + s.sendCompress = str +} + +// Done returns a channel which is closed when it receives the final status +// from the server. +func (s *Stream) Done() <-chan struct{} { + return s.done +} + +// Header returns the header metadata of the stream. +// +// On client side, it acquires the key-value pairs of header metadata once it is +// available. It blocks until i) the metadata is ready or ii) there is no header +// metadata or iii) the stream is canceled/expired. +// +// On server side, it returns the out header after t.WriteHeader is called. +func (s *Stream) Header() (metadata.MD, error) { + if s.headerChan == nil && s.header != nil { + // On server side, return the header in stream. It will be the out + // header after t.WriteHeader is called. + return s.header.Copy(), nil + } + err := s.waitOnHeader() + // Even if the stream is closed, header is returned if available. + select { + case <-s.headerChan: + if s.header == nil { + return nil, nil + } + return s.header.Copy(), nil + default: + } + return nil, err +} + +// TrailersOnly blocks until a header or trailers-only frame is received and +// then returns true if the stream was trailers-only. If the stream ends +// before headers are received, returns true, nil. If a context error happens +// first, returns it as a status error. Client-side only. +func (s *Stream) TrailersOnly() (bool, error) { + err := s.waitOnHeader() + if err != nil { + return false, err + } + // if !headerDone, some other connection error occurred. + return s.noHeaders && atomic.LoadUint32(&s.headerDone) == 1, nil +} + +// Trailer returns the cached trailer metedata. Note that if it is not called +// after the entire stream is done, it could return an empty MD. Client +// side only. +// It can be safely read only after stream has ended that is either read +// or write have returned io.EOF. +func (s *Stream) Trailer() metadata.MD { + c := s.trailer.Copy() + return c +} + +// ContentSubtype returns the content-subtype for a request. For example, a +// content-subtype of "proto" will result in a content-type of +// "application/grpc+proto". This will always be lowercase. See +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. +func (s *Stream) ContentSubtype() string { + return s.contentSubtype +} + +// Context returns the context of the stream. +func (s *Stream) Context() context.Context { + return s.ctx +} + +// Method returns the method for the stream. +func (s *Stream) Method() string { + return s.method +} + +// Status returns the status received from the server. +// Status can be read safely only after the stream has ended, +// that is, after Done() is closed. +func (s *Stream) Status() *status.Status { + return s.status +} + +// SetHeader sets the header metadata. This can be called multiple times. +// Server side only. +// This should not be called in parallel to other data writes. +func (s *Stream) SetHeader(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + if s.isHeaderSent() || s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + s.header = metadata.Join(s.header, md) + s.hdrMu.Unlock() + return nil +} + +// SendHeader sends the given header metadata. The given metadata is +// combined with any metadata set by previous calls to SetHeader and +// then written to the transport stream. +func (s *Stream) SendHeader(md metadata.MD) error { + return s.st.WriteHeader(s, md) +} + +// SetTrailer sets the trailer metadata which will be sent with the RPC status +// by the server. This can be called multiple times. Server side only. +// This should not be called parallel to other data writes. +func (s *Stream) SetTrailer(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + if s.getState() == streamDone { + return ErrIllegalHeaderWrite + } + s.hdrMu.Lock() + s.trailer = metadata.Join(s.trailer, md) + s.hdrMu.Unlock() + return nil +} + +func (s *Stream) write(m recvMsg) { + s.buf.put(m) +} + +// Read reads all p bytes from the wire for this stream. +func (s *Stream) Read(p []byte) (n int, err error) { + // Don't request a read if there was an error earlier + if er := s.trReader.(*transportReader).er; er != nil { + return 0, er + } + s.requestRead(len(p)) + return io.ReadFull(s.trReader, p) +} + +// tranportReader reads all the data available for this Stream from the transport and +// passes them into the decoder, which converts them into a gRPC message stream. +// The error is io.EOF when the stream is done or another non-nil error if +// the stream broke. +type transportReader struct { + reader io.Reader + // The handler to control the window update procedure for both this + // particular stream and the associated transport. + windowHandler func(int) + er error +} + +func (t *transportReader) Read(p []byte) (n int, err error) { + n, err = t.reader.Read(p) + if err != nil { + t.er = err + return + } + t.windowHandler(n) + return +} + +// BytesReceived indicates whether any bytes have been received on this stream. +func (s *Stream) BytesReceived() bool { + return atomic.LoadUint32(&s.bytesReceived) == 1 +} + +// Unprocessed indicates whether the server did not process this stream -- +// i.e. it sent a refused stream or GOAWAY including this stream ID. +func (s *Stream) Unprocessed() bool { + return atomic.LoadUint32(&s.unprocessed) == 1 +} + +// GoString is implemented by Stream so context.String() won't +// race when printing %#v. +func (s *Stream) GoString() string { + return fmt.Sprintf("", s, s.method) +} + +// state of transport +type transportState int + +const ( + reachable transportState = iota + closing + draining +) + +// ServerConfig consists of all the configurations to establish a server transport. +type ServerConfig struct { + MaxStreams uint32 + AuthInfo credentials.AuthInfo + InTapHandle tap.ServerInHandle + StatsHandler stats.Handler + KeepaliveParams keepalive.ServerParameters + KeepalivePolicy keepalive.EnforcementPolicy + InitialWindowSize int32 + InitialConnWindowSize int32 + WriteBufferSize int + ReadBufferSize int + ChannelzParentID int64 + MaxHeaderListSize *uint32 +} + +// NewServerTransport creates a ServerTransport with conn or non-nil error +// if it fails. +func NewServerTransport(protocol string, conn net.Conn, config *ServerConfig) (ServerTransport, error) { + return newHTTP2Server(conn, config) +} + +// ConnectOptions covers all relevant options for communicating with the server. +type ConnectOptions struct { + // UserAgent is the application user agent. + UserAgent string + // Dialer specifies how to dial a network address. + Dialer func(context.Context, string) (net.Conn, error) + // FailOnNonTempDialError specifies if gRPC fails on non-temporary dial errors. + FailOnNonTempDialError bool + // PerRPCCredentials stores the PerRPCCredentials required to issue RPCs. + PerRPCCredentials []credentials.PerRPCCredentials + // TransportCredentials stores the Authenticator required to setup a client + // connection. Only one of TransportCredentials and CredsBundle is non-nil. + TransportCredentials credentials.TransportCredentials + // CredsBundle is the credentials bundle to be used. Only one of + // TransportCredentials and CredsBundle is non-nil. + CredsBundle credentials.Bundle + // KeepaliveParams stores the keepalive parameters. + KeepaliveParams keepalive.ClientParameters + // StatsHandler stores the handler for stats. + StatsHandler stats.Handler + // InitialWindowSize sets the initial window size for a stream. + InitialWindowSize int32 + // InitialConnWindowSize sets the initial window size for a connection. + InitialConnWindowSize int32 + // WriteBufferSize sets the size of write buffer which in turn determines how much data can be batched before it's written on the wire. + WriteBufferSize int + // ReadBufferSize sets the size of read buffer, which in turn determines how much data can be read at most for one read syscall. + ReadBufferSize int + // ChannelzParentID sets the addrConn id which initiate the creation of this client transport. + ChannelzParentID int64 + // MaxHeaderListSize sets the max (uncompressed) size of header list that is prepared to be received. + MaxHeaderListSize *uint32 +} + +// TargetInfo contains the information of the target such as network address and metadata. +type TargetInfo struct { + Addr string + Metadata interface{} + Authority string +} + +// NewClientTransport establishes the transport with the required ConnectOptions +// and returns it to the caller. +func NewClientTransport(connectCtx, ctx context.Context, target TargetInfo, opts ConnectOptions, onSuccess func(), onGoAway func(GoAwayReason), onClose func()) (ClientTransport, error) { + return newHTTP2Client(connectCtx, ctx, target, opts, onSuccess, onGoAway, onClose) +} + +// Options provides additional hints and information for message +// transmission. +type Options struct { + // Last indicates whether this write is the last piece for + // this stream. + Last bool +} + +// CallHdr carries the information of a particular RPC. +type CallHdr struct { + // Host specifies the peer's host. + Host string + + // Method specifies the operation to perform. + Method string + + // SendCompress specifies the compression algorithm applied on + // outbound message. + SendCompress string + + // Creds specifies credentials.PerRPCCredentials for a call. + Creds credentials.PerRPCCredentials + + // ContentSubtype specifies the content-subtype for a request. For example, a + // content-subtype of "proto" will result in a content-type of + // "application/grpc+proto". The value of ContentSubtype must be all + // lowercase, otherwise the behavior is undefined. See + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests + // for more details. + ContentSubtype string + + PreviousAttempts int // value of grpc-previous-rpc-attempts header to set +} + +// ClientTransport is the common interface for all gRPC client-side transport +// implementations. +type ClientTransport interface { + // Close tears down this transport. Once it returns, the transport + // should not be accessed any more. The caller must make sure this + // is called only once. + Close() error + + // GracefulClose starts to tear down the transport. It stops accepting + // new RPCs and wait the completion of the pending RPCs. + GracefulClose() error + + // Write sends the data for the given stream. A nil stream indicates + // the write is to be performed on the transport as a whole. + Write(s *Stream, hdr []byte, data []byte, opts *Options) error + + // NewStream creates a Stream for an RPC. + NewStream(ctx context.Context, callHdr *CallHdr) (*Stream, error) + + // CloseStream clears the footprint of a stream when the stream is + // not needed any more. The err indicates the error incurred when + // CloseStream is called. Must be called when a stream is finished + // unless the associated transport is closing. + CloseStream(stream *Stream, err error) + + // Error returns a channel that is closed when some I/O error + // happens. Typically the caller should have a goroutine to monitor + // this in order to take action (e.g., close the current transport + // and create a new one) in error case. It should not return nil + // once the transport is initiated. + Error() <-chan struct{} + + // GoAway returns a channel that is closed when ClientTransport + // receives the draining signal from the server (e.g., GOAWAY frame in + // HTTP/2). + GoAway() <-chan struct{} + + // GetGoAwayReason returns the reason why GoAway frame was received. + GetGoAwayReason() GoAwayReason + + // IncrMsgSent increments the number of message sent through this transport. + IncrMsgSent() + + // IncrMsgRecv increments the number of message received through this transport. + IncrMsgRecv() +} + +// ServerTransport is the common interface for all gRPC server-side transport +// implementations. +// +// Methods may be called concurrently from multiple goroutines, but +// Write methods for a given Stream will be called serially. +type ServerTransport interface { + // HandleStreams receives incoming streams using the given handler. + HandleStreams(func(*Stream), func(context.Context, string) context.Context) + + // WriteHeader sends the header metadata for the given stream. + // WriteHeader may not be called on all streams. + WriteHeader(s *Stream, md metadata.MD) error + + // Write sends the data for the given stream. + // Write may not be called on all streams. + Write(s *Stream, hdr []byte, data []byte, opts *Options) error + + // WriteStatus sends the status of a stream to the client. WriteStatus is + // the final call made on a stream and always occurs. + WriteStatus(s *Stream, st *status.Status) error + + // Close tears down the transport. Once it is called, the transport + // should not be accessed any more. All the pending streams and their + // handlers will be terminated asynchronously. + Close() error + + // RemoteAddr returns the remote network address. + RemoteAddr() net.Addr + + // Drain notifies the client this ServerTransport stops accepting new RPCs. + Drain() + + // IncrMsgSent increments the number of message sent through this transport. + IncrMsgSent() + + // IncrMsgRecv increments the number of message received through this transport. + IncrMsgRecv() +} + +// connectionErrorf creates an ConnectionError with the specified error description. +func connectionErrorf(temp bool, e error, format string, a ...interface{}) ConnectionError { + return ConnectionError{ + Desc: fmt.Sprintf(format, a...), + temp: temp, + err: e, + } +} + +// ConnectionError is an error that results in the termination of the +// entire connection and the retry of all the active streams. +type ConnectionError struct { + Desc string + temp bool + err error +} + +func (e ConnectionError) Error() string { + return fmt.Sprintf("connection error: desc = %q", e.Desc) +} + +// Temporary indicates if this connection error is temporary or fatal. +func (e ConnectionError) Temporary() bool { + return e.temp +} + +// Origin returns the original error of this connection error. +func (e ConnectionError) Origin() error { + // Never return nil error here. + // If the original error is nil, return itself. + if e.err == nil { + return e + } + return e.err +} + +var ( + // ErrConnClosing indicates that the transport is closing. + ErrConnClosing = connectionErrorf(true, nil, "transport is closing") + // errStreamDrain indicates that the stream is rejected because the + // connection is draining. This could be caused by goaway or balancer + // removing the address. + errStreamDrain = status.Error(codes.Unavailable, "the connection is draining") + // errStreamDone is returned from write at the client side to indiacte application + // layer of an error. + errStreamDone = errors.New("the stream is done") + // StatusGoAway indicates that the server sent a GOAWAY that included this + // stream's ID in unprocessed RPCs. + statusGoAway = status.New(codes.Unavailable, "the stream is rejected because server is draining the connection") +) + +// GoAwayReason contains the reason for the GoAway frame received. +type GoAwayReason uint8 + +const ( + // GoAwayInvalid indicates that no GoAway frame is received. + GoAwayInvalid GoAwayReason = 0 + // GoAwayNoReason is the default value when GoAway frame is received. + GoAwayNoReason GoAwayReason = 1 + // GoAwayTooManyPings indicates that a GoAway frame with + // ErrCodeEnhanceYourCalm was received and that the debug data said + // "too_many_pings". + GoAwayTooManyPings GoAwayReason = 2 +) + +// channelzData is used to store channelz related data for http2Client and http2Server. +// These fields cannot be embedded in the original structs (e.g. http2Client), since to do atomic +// operation on int64 variable on 32-bit machine, user is responsible to enforce memory alignment. +// Here, by grouping those int64 fields inside a struct, we are enforcing the alignment. +type channelzData struct { + kpCount int64 + // The number of streams that have started, including already finished ones. + streamsStarted int64 + // Client side: The number of streams that have ended successfully by receiving + // EoS bit set frame from server. + // Server side: The number of streams that have ended successfully by sending + // frame with EoS bit set. + streamsSucceeded int64 + streamsFailed int64 + // lastStreamCreatedTime stores the timestamp that the last stream gets created. It is of int64 type + // instead of time.Time since it's more costly to atomically update time.Time variable than int64 + // variable. The same goes for lastMsgSentTime and lastMsgRecvTime. + lastStreamCreatedTime int64 + msgSent int64 + msgRecv int64 + lastMsgSentTime int64 + lastMsgRecvTime int64 +} + +// ContextErr converts the error from context package into a status error. +func ContextErr(err error) error { + switch err { + case context.DeadlineExceeded: + return status.Error(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return status.Error(codes.Canceled, err.Error()) + } + return status.Errorf(codes.Internal, "Unexpected error from context packet: %v", err) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/keepalive/keepalive.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/keepalive/keepalive.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/keepalive/keepalive.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/keepalive/keepalive.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go new file mode 100644 index 00000000..cf6d1b94 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/metadata/metadata.go @@ -0,0 +1,209 @@ +/* + * + * Copyright 2014 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 metadata define the structure of the metadata supported by gRPC library. +// Please refer to https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md +// for more information about custom-metadata. +package metadata // import "google.golang.org/grpc/metadata" + +import ( + "context" + "fmt" + "strings" +) + +// DecodeKeyValue returns k, v, nil. +// +// Deprecated: use k and v directly instead. +func DecodeKeyValue(k, v string) (string, string, error) { + return k, v, nil +} + +// MD is a mapping from metadata keys to values. Users should use the following +// two convenience functions New and Pairs to generate MD. +type MD map[string][]string + +// New creates an MD from a given key-value map. +// +// Only the following ASCII characters are allowed in keys: +// - digits: 0-9 +// - uppercase letters: A-Z (normalized to lower) +// - lowercase letters: a-z +// - special characters: -_. +// Uppercase letters are automatically converted to lowercase. +// +// Keys beginning with "grpc-" are reserved for grpc-internal use only and may +// result in errors if set in metadata. +func New(m map[string]string) MD { + md := MD{} + for k, val := range m { + key := strings.ToLower(k) + md[key] = append(md[key], val) + } + return md +} + +// Pairs returns an MD formed by the mapping of key, value ... +// Pairs panics if len(kv) is odd. +// +// Only the following ASCII characters are allowed in keys: +// - digits: 0-9 +// - uppercase letters: A-Z (normalized to lower) +// - lowercase letters: a-z +// - special characters: -_. +// Uppercase letters are automatically converted to lowercase. +// +// Keys beginning with "grpc-" are reserved for grpc-internal use only and may +// result in errors if set in metadata. +func Pairs(kv ...string) MD { + if len(kv)%2 == 1 { + panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv))) + } + md := MD{} + var key string + for i, s := range kv { + if i%2 == 0 { + key = strings.ToLower(s) + continue + } + md[key] = append(md[key], s) + } + return md +} + +// Len returns the number of items in md. +func (md MD) Len() int { + return len(md) +} + +// Copy returns a copy of md. +func (md MD) Copy() MD { + return Join(md) +} + +// Get obtains the values for a given key. +func (md MD) Get(k string) []string { + k = strings.ToLower(k) + return md[k] +} + +// Set sets the value of a given key with a slice of values. +func (md MD) Set(k string, vals ...string) { + if len(vals) == 0 { + return + } + k = strings.ToLower(k) + md[k] = vals +} + +// Append adds the values to key k, not overwriting what was already stored at that key. +func (md MD) Append(k string, vals ...string) { + if len(vals) == 0 { + return + } + k = strings.ToLower(k) + md[k] = append(md[k], vals...) +} + +// Join joins any number of mds into a single MD. +// The order of values for each key is determined by the order in which +// the mds containing those values are presented to Join. +func Join(mds ...MD) MD { + out := MD{} + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return out +} + +type mdIncomingKey struct{} +type mdOutgoingKey struct{} + +// NewIncomingContext creates a new context with incoming md attached. +func NewIncomingContext(ctx context.Context, md MD) context.Context { + return context.WithValue(ctx, mdIncomingKey{}, md) +} + +// NewOutgoingContext creates a new context with outgoing md attached. If used +// in conjunction with AppendToOutgoingContext, NewOutgoingContext will +// overwrite any previously-appended metadata. +func NewOutgoingContext(ctx context.Context, md MD) context.Context { + return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md}) +} + +// AppendToOutgoingContext returns a new context with the provided kv merged +// with any existing metadata in the context. Please refer to the +// documentation of Pairs for a description of kv. +func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context { + if len(kv)%2 == 1 { + panic(fmt.Sprintf("metadata: AppendToOutgoingContext got an odd number of input pairs for metadata: %d", len(kv))) + } + md, _ := ctx.Value(mdOutgoingKey{}).(rawMD) + added := make([][]string, len(md.added)+1) + copy(added, md.added) + added[len(added)-1] = make([]string, len(kv)) + copy(added[len(added)-1], kv) + return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md.md, added: added}) +} + +// FromIncomingContext returns the incoming metadata in ctx if it exists. The +// returned MD should not be modified. Writing to it may cause races. +// Modification should be made to copies of the returned MD. +func FromIncomingContext(ctx context.Context) (md MD, ok bool) { + md, ok = ctx.Value(mdIncomingKey{}).(MD) + return +} + +// FromOutgoingContextRaw returns the un-merged, intermediary contents +// of rawMD. Remember to perform strings.ToLower on the keys. The returned +// MD should not be modified. Writing to it may cause races. Modification +// should be made to copies of the returned MD. +// +// This is intended for gRPC-internal use ONLY. +func FromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) { + raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD) + if !ok { + return nil, nil, false + } + + return raw.md, raw.added, true +} + +// FromOutgoingContext returns the outgoing metadata in ctx if it exists. The +// returned MD should not be modified. Writing to it may cause races. +// Modification should be made to copies of the returned MD. +func FromOutgoingContext(ctx context.Context) (MD, bool) { + raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD) + if !ok { + return nil, false + } + + mds := make([]MD, 0, len(raw.added)+1) + mds = append(mds, raw.md) + for _, vv := range raw.added { + mds = append(mds, Pairs(vv...)) + } + return Join(mds...), ok +} + +type rawMD struct { + md MD + added [][]string +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go new file mode 100644 index 00000000..fd8cd3b5 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/dns_resolver.go @@ -0,0 +1,293 @@ +/* + * + * 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 naming + +import ( + "context" + "errors" + "fmt" + "net" + "strconv" + "time" + + "google.golang.org/grpc/grpclog" +) + +const ( + defaultPort = "443" + defaultFreq = time.Minute * 30 +) + +var ( + errMissingAddr = errors.New("missing address") + errWatcherClose = errors.New("watcher has been closed") + + lookupHost = net.DefaultResolver.LookupHost + lookupSRV = net.DefaultResolver.LookupSRV +) + +// 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 +} + +// 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) +} + +// dnsResolver handles name resolution for names following the DNS scheme +type dnsResolver struct { + // frequency of polling the DNS server that the watchers created by this resolver will use. + freq time.Duration +} + +// formatIP returns ok = false if addr is not a valid textual representation of an IP address. +// If addr is an IPv4 address, return the addr and ok = true. +// If addr is an IPv6 address, return the addr enclosed in square brackets and ok = true. +func formatIP(addr string) (addrIP string, ok bool) { + ip := net.ParseIP(addr) + if ip == nil { + return "", false + } + if ip.To4() != nil { + return addr, true + } + return "[" + addr + "]", true +} + +// parseTarget takes the user input target string, returns formatted host and port info. +// If target doesn't specify a port, set the port to be the defaultPort. +// If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets +// are strippd when setting the host. +// examples: +// target: "www.google.com" returns host: "www.google.com", port: "443" +// target: "ipv4-host:80" returns host: "ipv4-host", port: "80" +// target: "[ipv6-host]" returns host: "ipv6-host", port: "443" +// target: ":80" returns host: "localhost", port: "80" +// target: ":" returns host: "localhost", port: "443" +func parseTarget(target string) (host, port string, err error) { + if target == "" { + return "", "", errMissingAddr + } + + if ip := net.ParseIP(target); ip != nil { + // target is an IPv4 or IPv6(without brackets) address + return target, defaultPort, nil + } + if host, port, err := net.SplitHostPort(target); err == nil { + // target has port, i.e ipv4-host:port, [ipv6-host]:port, host-name:port + if host == "" { + // Keep consistent with net.Dial(): If the host is empty, as in ":80", the local system is assumed. + host = "localhost" + } + if port == "" { + // If the port field is empty(target ends with colon), e.g. "[::1]:", defaultPort is used. + port = defaultPort + } + return host, port, nil + } + if host, port, err := net.SplitHostPort(target + ":" + defaultPort); err == nil { + // target doesn't have port + return host, port, nil + } + return "", "", fmt.Errorf("invalid target address %v", target) +} + +// Resolve creates a watcher that watches the name resolution of the target. +func (r *dnsResolver) Resolve(target string) (Watcher, error) { + host, port, err := parseTarget(target) + if err != nil { + return nil, err + } + + if net.ParseIP(host) != nil { + ipWatcher := &ipWatcher{ + updateChan: make(chan *Update, 1), + } + host, _ = formatIP(host) + ipWatcher.updateChan <- &Update{Op: Add, Addr: host + ":" + port} + return ipWatcher, nil + } + + ctx, cancel := context.WithCancel(context.Background()) + return &dnsWatcher{ + r: r, + host: host, + port: port, + ctx: ctx, + cancel: cancel, + t: time.NewTimer(0), + }, nil +} + +// dnsWatcher watches for the name resolution update for a specific target +type dnsWatcher struct { + r *dnsResolver + host string + port string + // The latest resolved address set + curAddrs map[string]*Update + ctx context.Context + cancel context.CancelFunc + t *time.Timer +} + +// ipWatcher watches for the name resolution update for an IP address. +type ipWatcher struct { + updateChan chan *Update +} + +// Next returns the address resolution Update for the target. For IP address, +// the resolution is itself, thus polling name server is unnecessary. Therefore, +// Next() will return an Update the first time it is called, and will be blocked +// for all following calls as no Update exists until watcher is closed. +func (i *ipWatcher) Next() ([]*Update, error) { + u, ok := <-i.updateChan + if !ok { + return nil, errWatcherClose + } + return []*Update{u}, nil +} + +// Close closes the ipWatcher. +func (i *ipWatcher) Close() { + close(i.updateChan) +} + +// AddressType indicates the address type returned by name resolution. +type AddressType uint8 + +const ( + // Backend indicates the server is a backend server. + Backend AddressType = iota + // GRPCLB indicates the server is a grpclb load balancer. + GRPCLB +) + +// AddrMetadataGRPCLB contains the information the name resolver for grpclb should provide. The +// name resolver used by the grpclb balancer is required to provide this type of metadata in +// its address updates. +type AddrMetadataGRPCLB struct { + // AddrType is the type of server (grpc load balancer or backend). + AddrType AddressType + // ServerName is the name of the grpc load balancer. Used for authentication. + ServerName string +} + +// compileUpdate compares the old resolved addresses and newly resolved addresses, +// and generates an update list +func (w *dnsWatcher) compileUpdate(newAddrs map[string]*Update) []*Update { + var res []*Update + for a, u := range w.curAddrs { + if _, ok := newAddrs[a]; !ok { + u.Op = Delete + res = append(res, u) + } + } + for a, u := range newAddrs { + if _, ok := w.curAddrs[a]; !ok { + res = append(res, u) + } + } + return res +} + +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) + return nil + } + for _, s := range srvs { + lbAddrs, err := lookupHost(w.ctx, s.Target) + if err != nil { + grpclog.Warningf("grpc: failed load banlacer address dns lookup due to %v.\n", err) + continue + } + for _, a := range lbAddrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + strconv.Itoa(int(s.Port)) + newAddrs[addr] = &Update{Addr: addr, + Metadata: AddrMetadataGRPCLB{AddrType: GRPCLB, ServerName: s.Target}} + } + } + return newAddrs +} + +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) + return nil + } + for _, a := range addrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + w.port + newAddrs[addr] = &Update{Addr: addr} + } + return newAddrs +} + +func (w *dnsWatcher) lookup() []*Update { + newAddrs := w.lookupSRV() + if newAddrs == nil { + // If failed to get any balancer address (either no corresponding SRV for the + // target, or caused by failure during resolution/parsing of the balancer target), + // return any A record info available. + newAddrs = w.lookupHost() + } + result := w.compileUpdate(newAddrs) + w.curAddrs = newAddrs + return result +} + +// Next returns the resolved address update(delta) for the target. If there's no +// change, it will sleep for 30 mins and try to resolve again after that. +func (w *dnsWatcher) Next() ([]*Update, error) { + for { + select { + case <-w.ctx.Done(): + return nil, errWatcherClose + case <-w.t.C: + } + result := w.lookup() + // Next lookup should happen after an interval defined by w.r.freq. + w.t.Reset(w.r.freq) + if len(result) > 0 { + return result, nil + } + } +} + +func (w *dnsWatcher) Close() { + w.cancel() +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/naming/naming.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/naming.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/naming/naming.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/naming/naming.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go new file mode 100644 index 00000000..e01d219f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/peer/peer.go @@ -0,0 +1,51 @@ +/* + * + * Copyright 2014 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 peer defines various peer information associated with RPCs and +// corresponding utils. +package peer + +import ( + "context" + "net" + + "google.golang.org/grpc/credentials" +) + +// Peer contains the information of the peer for an RPC, such as the address +// and authentication information. +type Peer struct { + // Addr is the peer address. + Addr net.Addr + // AuthInfo is the authentication information of the transport. + // It is nil if there is no transport security being used. + AuthInfo credentials.AuthInfo +} + +type peerKey struct{} + +// NewContext creates a new context with peer information attached. +func NewContext(ctx context.Context, p *Peer) context.Context { + return context.WithValue(ctx, peerKey{}, p) +} + +// FromContext returns the peer information in ctx if it exists. +func FromContext(ctx context.Context) (p *Peer, ok bool) { + p, ok = ctx.Value(peerKey{}).(*Peer) + return +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go new file mode 100644 index 00000000..14f915d6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/picker_wrapper.go @@ -0,0 +1,180 @@ +/* + * + * 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 grpc + +import ( + "context" + "io" + "sync" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/status" +) + +// pickerWrapper is a wrapper of balancer.Picker. It blocks on certain pick +// actions and unblock when there's a picker update. +type pickerWrapper struct { + mu sync.Mutex + done bool + blockingCh chan struct{} + picker balancer.Picker + + // The latest connection happened. + connErrMu sync.Mutex + connErr error +} + +func newPickerWrapper() *pickerWrapper { + bp := &pickerWrapper{blockingCh: make(chan struct{})} + return bp +} + +func (bp *pickerWrapper) updateConnectionError(err error) { + bp.connErrMu.Lock() + bp.connErr = err + bp.connErrMu.Unlock() +} + +func (bp *pickerWrapper) connectionError() error { + bp.connErrMu.Lock() + err := bp.connErr + bp.connErrMu.Unlock() + return err +} + +// updatePicker is called by UpdateBalancerState. It unblocks all blocked pick. +func (bp *pickerWrapper) updatePicker(p balancer.Picker) { + bp.mu.Lock() + if bp.done { + bp.mu.Unlock() + return + } + bp.picker = p + // bp.blockingCh should never be nil. + close(bp.blockingCh) + bp.blockingCh = make(chan struct{}) + bp.mu.Unlock() +} + +func doneChannelzWrapper(acw *acBalancerWrapper, done func(balancer.DoneInfo)) func(balancer.DoneInfo) { + acw.mu.Lock() + ac := acw.ac + acw.mu.Unlock() + ac.incrCallsStarted() + return func(b balancer.DoneInfo) { + if b.Err != nil && b.Err != io.EOF { + ac.incrCallsFailed() + } else { + ac.incrCallsSucceeded() + } + if done != nil { + done(b) + } + } +} + +// pick returns the transport that will be used for the RPC. +// It may block in the following cases: +// - there's no picker +// - the current picker returns ErrNoSubConnAvailable +// - the current picker returns other errors and failfast is false. +// - the subConn returned by the current picker is not READY +// When one of these situations happens, pick blocks until the picker gets updated. +func (bp *pickerWrapper) pick(ctx context.Context, failfast bool, opts balancer.PickOptions) (transport.ClientTransport, func(balancer.DoneInfo), error) { + var ( + p balancer.Picker + ch chan struct{} + ) + + for { + bp.mu.Lock() + if bp.done { + bp.mu.Unlock() + return nil, nil, ErrClientConnClosing + } + + if bp.picker == nil { + ch = bp.blockingCh + } + if ch == bp.blockingCh { + // This could happen when either: + // - bp.picker is nil (the previous if condition), or + // - has called pick on the current picker. + bp.mu.Unlock() + select { + case <-ctx.Done(): + return nil, nil, ctx.Err() + case <-ch: + } + continue + } + + ch = bp.blockingCh + p = bp.picker + bp.mu.Unlock() + + subConn, done, err := p.Pick(ctx, opts) + + if err != nil { + switch err { + case balancer.ErrNoSubConnAvailable: + continue + case balancer.ErrTransientFailure: + if !failfast { + continue + } + return nil, nil, status.Errorf(codes.Unavailable, "%v, latest connection error: %v", err, bp.connectionError()) + default: + // err is some other error. + return nil, nil, toRPCErr(err) + } + } + + acw, ok := subConn.(*acBalancerWrapper) + if !ok { + grpclog.Infof("subconn returned from pick is not *acBalancerWrapper") + continue + } + if t, ok := acw.getAddrConn().getReadyTransport(); ok { + if channelz.IsOn() { + return t, doneChannelzWrapper(acw, done), nil + } + return t, done, nil + } + grpclog.Infof("blockingPicker: the picked transport is not ready, loop back to repick") + // If ok == false, ac.state is not READY. + // A valid picker always returns READY subConn. This means the state of ac + // just changed, and picker will be updated shortly. + // continue back to the beginning of the for loop to repick. + } +} + +func (bp *pickerWrapper) close() { + bp.mu.Lock() + defer bp.mu.Unlock() + if bp.done { + return + } + bp.done = true + close(bp.blockingCh) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go new file mode 100644 index 00000000..d1e38aad --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/pickfirst.go @@ -0,0 +1,110 @@ +/* + * + * 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 grpc + +import ( + "context" + + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/resolver" +) + +// PickFirstBalancerName is the name of the pick_first balancer. +const PickFirstBalancerName = "pick_first" + +func newPickfirstBuilder() balancer.Builder { + return &pickfirstBuilder{} +} + +type pickfirstBuilder struct{} + +func (*pickfirstBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { + return &pickfirstBalancer{cc: cc} +} + +func (*pickfirstBuilder) Name() string { + return PickFirstBalancerName +} + +type pickfirstBalancer struct { + cc balancer.ClientConn + sc balancer.SubConn +} + +func (b *pickfirstBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) { + if err != nil { + grpclog.Infof("pickfirstBalancer: HandleResolvedAddrs called with error %v", err) + return + } + if b.sc == nil { + b.sc, err = b.cc.NewSubConn(addrs, balancer.NewSubConnOptions{}) + if err != nil { + //TODO(yuxuanli): why not change the cc state to Idle? + grpclog.Errorf("pickfirstBalancer: failed to NewSubConn: %v", err) + return + } + b.cc.UpdateBalancerState(connectivity.Idle, &picker{sc: b.sc}) + b.sc.Connect() + } else { + b.sc.UpdateAddresses(addrs) + b.sc.Connect() + } +} + +func (b *pickfirstBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { + grpclog.Infof("pickfirstBalancer: HandleSubConnStateChange: %p, %v", sc, s) + if b.sc != sc { + grpclog.Infof("pickfirstBalancer: ignored state change because sc is not recognized") + return + } + if s == connectivity.Shutdown { + b.sc = nil + return + } + + switch s { + case connectivity.Ready, connectivity.Idle: + b.cc.UpdateBalancerState(s, &picker{sc: sc}) + case connectivity.Connecting: + b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrNoSubConnAvailable}) + case connectivity.TransientFailure: + b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrTransientFailure}) + } +} + +func (b *pickfirstBalancer) Close() { +} + +type picker struct { + err error + sc balancer.SubConn +} + +func (p *picker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { + if p.err != nil { + return nil, nil, p.err + } + return p.sc, nil, nil +} + +func init() { + balancer.Register(newPickfirstBuilder()) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go new file mode 100644 index 00000000..f8f69bfb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/proxy.go @@ -0,0 +1,152 @@ +/* + * + * 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 grpc + +import ( + "bufio" + "context" + "encoding/base64" + "errors" + "fmt" + "io" + "net" + "net/http" + "net/http/httputil" + "net/url" +) + +const proxyAuthHeaderKey = "Proxy-Authorization" + +var ( + // errDisabled indicates that proxy is disabled for the address. + errDisabled = errors.New("proxy is disabled for the address") + // The following variable will be overwritten in the tests. + httpProxyFromEnvironment = http.ProxyFromEnvironment +) + +func mapAddress(ctx context.Context, address string) (*url.URL, error) { + req := &http.Request{ + URL: &url.URL{ + Scheme: "https", + Host: address, + }, + } + url, err := httpProxyFromEnvironment(req) + if err != nil { + return nil, err + } + if url == nil { + return nil, errDisabled + } + return url, nil +} + +// To read a response from a net.Conn, http.ReadResponse() takes a bufio.Reader. +// It's possible that this reader reads more than what's need for the response and stores +// those bytes in the buffer. +// bufConn wraps the original net.Conn and the bufio.Reader to make sure we don't lose the +// bytes in the buffer. +type bufConn struct { + net.Conn + r io.Reader +} + +func (c *bufConn) Read(b []byte) (int, error) { + return c.r.Read(b) +} + +func basicAuth(username, password string) string { + auth := username + ":" + password + return base64.StdEncoding.EncodeToString([]byte(auth)) +} + +func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, backendAddr string, proxyURL *url.URL) (_ net.Conn, err error) { + defer func() { + if err != nil { + conn.Close() + } + }() + + req := &http.Request{ + Method: http.MethodConnect, + URL: &url.URL{Host: backendAddr}, + Header: map[string][]string{"User-Agent": {grpcUA}}, + } + if t := proxyURL.User; t != nil { + u := t.Username() + p, _ := t.Password() + req.Header.Add(proxyAuthHeaderKey, "Basic "+basicAuth(u, p)) + } + + if err := sendHTTPRequest(ctx, req, conn); err != nil { + return nil, fmt.Errorf("failed to write the HTTP request: %v", err) + } + + r := bufio.NewReader(conn) + resp, err := http.ReadResponse(r, req) + if err != nil { + return nil, fmt.Errorf("reading server HTTP response: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + dump, err := httputil.DumpResponse(resp, true) + if err != nil { + return nil, fmt.Errorf("failed to do connect handshake, status code: %s", resp.Status) + } + return nil, fmt.Errorf("failed to do connect handshake, response: %q", dump) + } + + return &bufConn{Conn: conn, r: r}, nil +} + +// newProxyDialer returns a dialer that connects to proxy first if necessary. +// The returned dialer checks if a proxy is necessary, dial to the proxy with the +// provided dialer, does HTTP CONNECT handshake and returns the connection. +func newProxyDialer(dialer func(context.Context, string) (net.Conn, error)) func(context.Context, string) (net.Conn, error) { + return func(ctx context.Context, addr string) (conn net.Conn, err error) { + var newAddr string + proxyURL, err := mapAddress(ctx, addr) + if err != nil { + if err != errDisabled { + return nil, err + } + newAddr = addr + } else { + newAddr = proxyURL.Host + } + + conn, err = dialer(ctx, newAddr) + if err != nil { + return + } + if proxyURL != nil { + // proxy is disabled if proxyURL is nil. + conn, err = doHTTPConnectHandshake(ctx, conn, addr, proxyURL) + } + return + } +} + +func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { + req = req.WithContext(ctx) + if err := req.Write(conn); err != nil { + return fmt.Errorf("failed to write the HTTP request: %v", err) + } + return nil +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go new file mode 100644 index 00000000..f33189fe --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/dns/dns_resolver.go @@ -0,0 +1,436 @@ +/* + * + * 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 dns implements a dns resolver to be installed as the default resolver +// in grpc. +package dns + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net" + "os" + "strconv" + "strings" + "sync" + "time" + + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/backoff" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/resolver" +) + +func init() { + resolver.Register(NewBuilder()) +} + +const ( + defaultPort = "443" + defaultFreq = time.Minute * 30 + defaultDNSSvrPort = "53" + golang = "GO" + // In DNS, service config is encoded in a TXT record via the mechanism + // described in RFC-1464 using the attribute name grpc_config. + txtAttribute = "grpc_config=" +) + +var ( + errMissingAddr = errors.New("dns resolver: missing address") + + // Addresses ending with a colon that is supposed to be the separator + // between host and port is not allowed. E.g. "::" is a valid address as + // it is an IPv6 address (host only) and "[::]:" is invalid as it ends with + // a colon as the host and port separator + errEndsWithColon = errors.New("dns resolver: missing port after port-separator colon") +) + +var ( + defaultResolver netResolver = net.DefaultResolver +) + +var customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) { + return func(ctx context.Context, network, address string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, authority) + } +} + +var customAuthorityResolver = func(authority string) (netResolver, error) { + host, port, err := parseTarget(authority, defaultDNSSvrPort) + if err != nil { + return nil, err + } + + authorityWithPort := net.JoinHostPort(host, port) + + return &net.Resolver{ + PreferGo: true, + Dial: customAuthorityDialler(authorityWithPort), + }, nil +} + +// NewBuilder creates a dnsBuilder which is used to factory DNS resolvers. +func NewBuilder() resolver.Builder { + return &dnsBuilder{minFreq: defaultFreq} +} + +type dnsBuilder struct { + // minimum frequency of polling the DNS server. + minFreq time.Duration +} + +// Build creates and starts a DNS resolver that watches the name resolution of the target. +func (b *dnsBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) { + host, port, err := parseTarget(target.Endpoint, defaultPort) + if err != nil { + return nil, err + } + + // IP address. + if net.ParseIP(host) != nil { + host, _ = formatIP(host) + addr := []resolver.Address{{Addr: host + ":" + port}} + i := &ipResolver{ + cc: cc, + ip: addr, + rn: make(chan struct{}, 1), + q: make(chan struct{}), + } + cc.NewAddress(addr) + go i.watcher() + return i, nil + } + + // DNS address (non-IP). + ctx, cancel := context.WithCancel(context.Background()) + d := &dnsResolver{ + freq: b.minFreq, + backoff: backoff.Exponential{MaxDelay: b.minFreq}, + host: host, + port: port, + ctx: ctx, + cancel: cancel, + cc: cc, + t: time.NewTimer(0), + rn: make(chan struct{}, 1), + disableServiceConfig: opts.DisableServiceConfig, + } + + if target.Authority == "" { + d.resolver = defaultResolver + } else { + d.resolver, err = customAuthorityResolver(target.Authority) + if err != nil { + return nil, err + } + } + + d.wg.Add(1) + go d.watcher() + return d, nil +} + +// Scheme returns the naming scheme of this resolver builder, which is "dns". +func (b *dnsBuilder) Scheme() string { + return "dns" +} + +type netResolver interface { + LookupHost(ctx context.Context, host string) (addrs []string, err error) + LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error) + LookupTXT(ctx context.Context, name string) (txts []string, err error) +} + +// ipResolver watches for the name resolution update for an IP address. +type ipResolver struct { + cc resolver.ClientConn + ip []resolver.Address + // rn channel is used by ResolveNow() to force an immediate resolution of the target. + rn chan struct{} + q chan struct{} +} + +// ResolveNow resend the address it stores, no resolution is needed. +func (i *ipResolver) ResolveNow(opt resolver.ResolveNowOption) { + select { + case i.rn <- struct{}{}: + default: + } +} + +// Close closes the ipResolver. +func (i *ipResolver) Close() { + close(i.q) +} + +func (i *ipResolver) watcher() { + for { + select { + case <-i.rn: + i.cc.NewAddress(i.ip) + case <-i.q: + return + } + } +} + +// dnsResolver watches for the name resolution update for a non-IP target. +type dnsResolver struct { + freq time.Duration + backoff backoff.Exponential + retryCount int + host string + port string + resolver netResolver + ctx context.Context + cancel context.CancelFunc + cc resolver.ClientConn + // rn channel is used by ResolveNow() to force an immediate resolution of the target. + rn chan struct{} + t *time.Timer + // wg is used to enforce Close() to return after the watcher() goroutine has finished. + // Otherwise, data race will be possible. [Race Example] in dns_resolver_test we + // replace the real lookup functions with mocked ones to facilitate testing. + // If Close() doesn't wait for watcher() goroutine finishes, race detector sometimes + // will warns lookup (READ the lookup function pointers) inside watcher() goroutine + // has data race with replaceNetFunc (WRITE the lookup function pointers). + wg sync.WaitGroup + disableServiceConfig bool +} + +// ResolveNow invoke an immediate resolution of the target that this dnsResolver watches. +func (d *dnsResolver) ResolveNow(opt resolver.ResolveNowOption) { + select { + case d.rn <- struct{}{}: + default: + } +} + +// Close closes the dnsResolver. +func (d *dnsResolver) Close() { + d.cancel() + d.wg.Wait() + d.t.Stop() +} + +func (d *dnsResolver) watcher() { + defer d.wg.Done() + for { + select { + case <-d.ctx.Done(): + return + case <-d.t.C: + case <-d.rn: + } + result, sc := d.lookup() + // Next lookup should happen within an interval defined by d.freq. It may be + // more often due to exponential retry on empty address list. + if len(result) == 0 { + d.retryCount++ + d.t.Reset(d.backoff.Backoff(d.retryCount)) + } else { + d.retryCount = 0 + d.t.Reset(d.freq) + } + d.cc.NewServiceConfig(sc) + d.cc.NewAddress(result) + } +} + +func (d *dnsResolver) lookupSRV() []resolver.Address { + var newAddrs []resolver.Address + _, srvs, err := d.resolver.LookupSRV(d.ctx, "grpclb", "tcp", d.host) + if err != nil { + grpclog.Infof("grpc: failed dns SRV record lookup due to %v.\n", err) + return nil + } + for _, s := range srvs { + lbAddrs, err := d.resolver.LookupHost(d.ctx, s.Target) + if err != nil { + grpclog.Infof("grpc: failed load balancer address dns lookup due to %v.\n", err) + continue + } + for _, a := range lbAddrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + strconv.Itoa(int(s.Port)) + newAddrs = append(newAddrs, resolver.Address{Addr: addr, Type: resolver.GRPCLB, ServerName: s.Target}) + } + } + return newAddrs +} + +func (d *dnsResolver) lookupTXT() string { + ss, err := d.resolver.LookupTXT(d.ctx, d.host) + if err != nil { + grpclog.Infof("grpc: failed dns TXT record lookup due to %v.\n", err) + return "" + } + var res string + for _, s := range ss { + res += s + } + + // TXT record must have "grpc_config=" attribute in order to be used as service config. + if !strings.HasPrefix(res, txtAttribute) { + grpclog.Warningf("grpc: TXT record %v missing %v attribute", res, txtAttribute) + return "" + } + return strings.TrimPrefix(res, txtAttribute) +} + +func (d *dnsResolver) lookupHost() []resolver.Address { + var newAddrs []resolver.Address + addrs, err := d.resolver.LookupHost(d.ctx, d.host) + if err != nil { + grpclog.Warningf("grpc: failed dns A record lookup due to %v.\n", err) + return nil + } + for _, a := range addrs { + a, ok := formatIP(a) + if !ok { + grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + continue + } + addr := a + ":" + d.port + newAddrs = append(newAddrs, resolver.Address{Addr: addr}) + } + return newAddrs +} + +func (d *dnsResolver) lookup() ([]resolver.Address, string) { + newAddrs := d.lookupSRV() + // Support fallback to non-balancer address. + newAddrs = append(newAddrs, d.lookupHost()...) + if d.disableServiceConfig { + return newAddrs, "" + } + sc := d.lookupTXT() + return newAddrs, canaryingSC(sc) +} + +// formatIP returns ok = false if addr is not a valid textual representation of an IP address. +// If addr is an IPv4 address, return the addr and ok = true. +// If addr is an IPv6 address, return the addr enclosed in square brackets and ok = true. +func formatIP(addr string) (addrIP string, ok bool) { + ip := net.ParseIP(addr) + if ip == nil { + return "", false + } + if ip.To4() != nil { + return addr, true + } + return "[" + addr + "]", true +} + +// parseTarget takes the user input target string and default port, returns formatted host and port info. +// If target doesn't specify a port, set the port to be the defaultPort. +// If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets +// are strippd when setting the host. +// examples: +// target: "www.google.com" defaultPort: "443" returns host: "www.google.com", port: "443" +// target: "ipv4-host:80" defaultPort: "443" returns host: "ipv4-host", port: "80" +// target: "[ipv6-host]" defaultPort: "443" returns host: "ipv6-host", port: "443" +// target: ":80" defaultPort: "443" returns host: "localhost", port: "80" +func parseTarget(target, defaultPort string) (host, port string, err error) { + if target == "" { + return "", "", errMissingAddr + } + if ip := net.ParseIP(target); ip != nil { + // target is an IPv4 or IPv6(without brackets) address + return target, defaultPort, nil + } + if host, port, err = net.SplitHostPort(target); err == nil { + if port == "" { + // If the port field is empty (target ends with colon), e.g. "[::1]:", this is an error. + return "", "", errEndsWithColon + } + // target has port, i.e ipv4-host:port, [ipv6-host]:port, host-name:port + if host == "" { + // Keep consistent with net.Dial(): If the host is empty, as in ":80", the local system is assumed. + host = "localhost" + } + return host, port, nil + } + if host, port, err = net.SplitHostPort(target + ":" + defaultPort); err == nil { + // target doesn't have port + return host, port, nil + } + return "", "", fmt.Errorf("invalid target address %v, error info: %v", target, err) +} + +type rawChoice struct { + ClientLanguage *[]string `json:"clientLanguage,omitempty"` + Percentage *int `json:"percentage,omitempty"` + ClientHostName *[]string `json:"clientHostName,omitempty"` + ServiceConfig *json.RawMessage `json:"serviceConfig,omitempty"` +} + +func containsString(a *[]string, b string) bool { + if a == nil { + return true + } + for _, c := range *a { + if c == b { + return true + } + } + return false +} + +func chosenByPercentage(a *int) bool { + if a == nil { + return true + } + return grpcrand.Intn(100)+1 <= *a +} + +func canaryingSC(js string) string { + if js == "" { + return "" + } + var rcs []rawChoice + err := json.Unmarshal([]byte(js), &rcs) + if err != nil { + grpclog.Warningf("grpc: failed to parse service config json string due to %v.\n", err) + return "" + } + cliHostname, err := os.Hostname() + if err != nil { + grpclog.Warningf("grpc: failed to get client hostname due to %v.\n", err) + return "" + } + var sc string + for _, c := range rcs { + if !containsString(c.ClientLanguage, golang) || + !chosenByPercentage(c.Percentage) || + !containsString(c.ClientHostName, cliHostname) || + c.ServiceConfig == nil { + continue + } + sc = string(*c.ServiceConfig) + break + } + return sc +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/resolver.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/resolver.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/resolver/resolver.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver/resolver.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go new file mode 100644 index 00000000..9d760253 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/resolver_conn_wrapper.go @@ -0,0 +1,155 @@ +/* + * + * 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 grpc + +import ( + "fmt" + "strings" + + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/resolver" +) + +// ccResolverWrapper is a wrapper on top of cc for resolvers. +// It implements resolver.ClientConnection interface. +type ccResolverWrapper struct { + cc *ClientConn + resolver resolver.Resolver + addrCh chan []resolver.Address + scCh chan string + done chan struct{} + lastAddressesCount int +} + +// split2 returns the values from strings.SplitN(s, sep, 2). +// If sep is not found, it returns ("", s, false) instead. +func split2(s, sep string) (string, string, bool) { + spl := strings.SplitN(s, sep, 2) + if len(spl) < 2 { + return "", "", false + } + return spl[0], spl[1], true +} + +// parseTarget splits target into a struct containing scheme, authority and +// endpoint. +// +// If target is not a valid scheme://authority/endpoint, it returns {Endpoint: +// target}. +func parseTarget(target string) (ret resolver.Target) { + var ok bool + ret.Scheme, ret.Endpoint, ok = split2(target, "://") + if !ok { + return resolver.Target{Endpoint: target} + } + ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/") + if !ok { + return resolver.Target{Endpoint: target} + } + return ret +} + +// newCCResolverWrapper parses cc.target for scheme and gets the resolver +// builder for this scheme and builds the resolver. The monitoring goroutine +// for it is not started yet and can be created by calling start(). +// +// If withResolverBuilder dial option is set, the specified resolver will be +// used instead. +func newCCResolverWrapper(cc *ClientConn) (*ccResolverWrapper, error) { + rb := cc.dopts.resolverBuilder + if rb == nil { + return nil, fmt.Errorf("could not get resolver for scheme: %q", cc.parsedTarget.Scheme) + } + + ccr := &ccResolverWrapper{ + cc: cc, + addrCh: make(chan []resolver.Address, 1), + scCh: make(chan string, 1), + done: make(chan struct{}), + } + + var err error + ccr.resolver, err = rb.Build(cc.parsedTarget, ccr, resolver.BuildOption{DisableServiceConfig: cc.dopts.disableServiceConfig}) + if err != nil { + return nil, err + } + return ccr, nil +} + +func (ccr *ccResolverWrapper) resolveNow(o resolver.ResolveNowOption) { + ccr.resolver.ResolveNow(o) +} + +func (ccr *ccResolverWrapper) close() { + ccr.resolver.Close() + close(ccr.done) +} + +// NewAddress is called by the resolver implemenetion to send addresses to gRPC. +func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) { + select { + case <-ccr.done: + return + default: + } + grpclog.Infof("ccResolverWrapper: sending new addresses to cc: %v", addrs) + if channelz.IsOn() { + ccr.addChannelzTraceEvent(addrs) + } + ccr.cc.handleResolvedAddrs(addrs, nil) +} + +// NewServiceConfig is called by the resolver implemenetion to send service +// configs to gRPC. +func (ccr *ccResolverWrapper) NewServiceConfig(sc string) { + select { + case <-ccr.done: + return + default: + } + grpclog.Infof("ccResolverWrapper: got new service config: %v", sc) + ccr.cc.handleServiceConfig(sc) +} + +func (ccr *ccResolverWrapper) addChannelzTraceEvent(addrs []resolver.Address) { + if len(addrs) == 0 && ccr.lastAddressesCount != 0 { + channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{ + Desc: "Resolver returns an empty address list", + Severity: channelz.CtWarning, + }) + } else if len(addrs) != 0 && ccr.lastAddressesCount == 0 { + var s string + for i, a := range addrs { + if a.ServerName != "" { + s += a.Addr + "(" + a.ServerName + ")" + } else { + s += a.Addr + } + if i != len(addrs)-1 { + s += " " + } + } + channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{ + Desc: fmt.Sprintf("Resolver returns a non-empty address list (previous one was empty) %q", s), + Severity: channelz.CtINFO, + }) + } + ccr.lastAddressesCount = len(addrs) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go new file mode 100644 index 00000000..86f00e5a --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/rpc_util.go @@ -0,0 +1,815 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "bytes" + "compress/gzip" + "context" + "encoding/binary" + "fmt" + "io" + "io/ioutil" + "math" + "net/url" + "strings" + "sync" + "time" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// Compressor defines the interface gRPC uses to compress a message. +// +// Deprecated: use package encoding. +type Compressor interface { + // Do compresses p into w. + Do(w io.Writer, p []byte) error + // Type returns the compression algorithm the Compressor uses. + Type() string +} + +type gzipCompressor struct { + pool sync.Pool +} + +// NewGZIPCompressor creates a Compressor based on GZIP. +// +// Deprecated: use package encoding/gzip. +func NewGZIPCompressor() Compressor { + c, _ := NewGZIPCompressorWithLevel(gzip.DefaultCompression) + return c +} + +// NewGZIPCompressorWithLevel is like NewGZIPCompressor but specifies the gzip compression level instead +// of assuming DefaultCompression. +// +// The error returned will be nil if the level is valid. +// +// Deprecated: use package encoding/gzip. +func NewGZIPCompressorWithLevel(level int) (Compressor, error) { + if level < gzip.DefaultCompression || level > gzip.BestCompression { + return nil, fmt.Errorf("grpc: invalid compression level: %d", level) + } + return &gzipCompressor{ + pool: sync.Pool{ + New: func() interface{} { + w, err := gzip.NewWriterLevel(ioutil.Discard, level) + if err != nil { + panic(err) + } + return w + }, + }, + }, nil +} + +func (c *gzipCompressor) Do(w io.Writer, p []byte) error { + z := c.pool.Get().(*gzip.Writer) + defer c.pool.Put(z) + z.Reset(w) + if _, err := z.Write(p); err != nil { + return err + } + return z.Close() +} + +func (c *gzipCompressor) Type() string { + return "gzip" +} + +// Decompressor defines the interface gRPC uses to decompress a message. +// +// Deprecated: use package encoding. +type Decompressor interface { + // Do reads the data from r and uncompress them. + Do(r io.Reader) ([]byte, error) + // Type returns the compression algorithm the Decompressor uses. + Type() string +} + +type gzipDecompressor struct { + pool sync.Pool +} + +// NewGZIPDecompressor creates a Decompressor based on GZIP. +// +// Deprecated: use package encoding/gzip. +func NewGZIPDecompressor() Decompressor { + return &gzipDecompressor{} +} + +func (d *gzipDecompressor) Do(r io.Reader) ([]byte, error) { + var z *gzip.Reader + switch maybeZ := d.pool.Get().(type) { + case nil: + newZ, err := gzip.NewReader(r) + if err != nil { + return nil, err + } + z = newZ + case *gzip.Reader: + z = maybeZ + if err := z.Reset(r); err != nil { + d.pool.Put(z) + return nil, err + } + } + + defer func() { + z.Close() + d.pool.Put(z) + }() + return ioutil.ReadAll(z) +} + +func (d *gzipDecompressor) Type() string { + return "gzip" +} + +// callInfo contains all related configuration and information about an RPC. +type callInfo struct { + compressorType string + failFast bool + stream ClientStream + maxReceiveMessageSize *int + maxSendMessageSize *int + creds credentials.PerRPCCredentials + contentSubtype string + codec baseCodec + maxRetryRPCBufferSize int +} + +func defaultCallInfo() *callInfo { + return &callInfo{ + failFast: true, + maxRetryRPCBufferSize: 256 * 1024, // 256KB + } +} + +// CallOption configures a Call before it starts or extracts information from +// a Call after it completes. +type CallOption interface { + // before is called before the call is sent to any server. If before + // returns a non-nil error, the RPC fails with that error. + before(*callInfo) error + + // after is called after the call has completed. after cannot return an + // error, so any failures should be reported via output parameters. + after(*callInfo) +} + +// EmptyCallOption does not alter the Call configuration. +// It can be embedded in another structure to carry satellite data for use +// by interceptors. +type EmptyCallOption struct{} + +func (EmptyCallOption) before(*callInfo) error { return nil } +func (EmptyCallOption) after(*callInfo) {} + +// Header returns a CallOptions that retrieves the header metadata +// for a unary RPC. +func Header(md *metadata.MD) CallOption { + return HeaderCallOption{HeaderAddr: md} +} + +// HeaderCallOption is a CallOption for collecting response header metadata. +// The metadata field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type HeaderCallOption struct { + HeaderAddr *metadata.MD +} + +func (o HeaderCallOption) before(c *callInfo) error { return nil } +func (o HeaderCallOption) after(c *callInfo) { + if c.stream != nil { + *o.HeaderAddr, _ = c.stream.Header() + } +} + +// Trailer returns a CallOptions that retrieves the trailer metadata +// for a unary RPC. +func Trailer(md *metadata.MD) CallOption { + return TrailerCallOption{TrailerAddr: md} +} + +// TrailerCallOption is a CallOption for collecting response trailer metadata. +// The metadata field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type TrailerCallOption struct { + TrailerAddr *metadata.MD +} + +func (o TrailerCallOption) before(c *callInfo) error { return nil } +func (o TrailerCallOption) after(c *callInfo) { + if c.stream != nil { + *o.TrailerAddr = c.stream.Trailer() + } +} + +// Peer returns a CallOption that retrieves peer information for a unary RPC. +// The peer field will be populated *after* the RPC completes. +func Peer(p *peer.Peer) CallOption { + return PeerCallOption{PeerAddr: p} +} + +// PeerCallOption is a CallOption for collecting the identity of the remote +// peer. The peer field will be populated *after* the RPC completes. +// This is an EXPERIMENTAL API. +type PeerCallOption struct { + PeerAddr *peer.Peer +} + +func (o PeerCallOption) before(c *callInfo) error { return nil } +func (o PeerCallOption) after(c *callInfo) { + if c.stream != nil { + if x, ok := peer.FromContext(c.stream.Context()); ok { + *o.PeerAddr = *x + } + } +} + +// FailFast configures the action to take when an RPC is attempted on broken +// connections or unreachable servers. If failFast is true, the RPC will fail +// immediately. Otherwise, the RPC client will block the call until a +// connection is available (or the call is canceled or times out) and will +// retry the call if it fails due to a transient error. gRPC will not retry if +// data was written to the wire unless the server indicates it did not process +// the data. Please refer to +// https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md. +// +// By default, RPCs are "Fail Fast". +func FailFast(failFast bool) CallOption { + return FailFastCallOption{FailFast: failFast} +} + +// FailFastCallOption is a CallOption for indicating whether an RPC should fail +// fast or not. +// This is an EXPERIMENTAL API. +type FailFastCallOption struct { + FailFast bool +} + +func (o FailFastCallOption) before(c *callInfo) error { + c.failFast = o.FailFast + return nil +} +func (o FailFastCallOption) after(c *callInfo) {} + +// MaxCallRecvMsgSize returns a CallOption which sets the maximum message size the client can receive. +func MaxCallRecvMsgSize(s int) CallOption { + return MaxRecvMsgSizeCallOption{MaxRecvMsgSize: s} +} + +// MaxRecvMsgSizeCallOption is a CallOption that indicates the maximum message +// size the client can receive. +// This is an EXPERIMENTAL API. +type MaxRecvMsgSizeCallOption struct { + MaxRecvMsgSize int +} + +func (o MaxRecvMsgSizeCallOption) before(c *callInfo) error { + c.maxReceiveMessageSize = &o.MaxRecvMsgSize + return nil +} +func (o MaxRecvMsgSizeCallOption) after(c *callInfo) {} + +// MaxCallSendMsgSize returns a CallOption which sets the maximum message size the client can send. +func MaxCallSendMsgSize(s int) CallOption { + return MaxSendMsgSizeCallOption{MaxSendMsgSize: s} +} + +// MaxSendMsgSizeCallOption is a CallOption that indicates the maximum message +// size the client can send. +// This is an EXPERIMENTAL API. +type MaxSendMsgSizeCallOption struct { + MaxSendMsgSize int +} + +func (o MaxSendMsgSizeCallOption) before(c *callInfo) error { + c.maxSendMessageSize = &o.MaxSendMsgSize + return nil +} +func (o MaxSendMsgSizeCallOption) after(c *callInfo) {} + +// PerRPCCredentials returns a CallOption that sets credentials.PerRPCCredentials +// for a call. +func PerRPCCredentials(creds credentials.PerRPCCredentials) CallOption { + return PerRPCCredsCallOption{Creds: creds} +} + +// PerRPCCredsCallOption is a CallOption that indicates the per-RPC +// credentials to use for the call. +// This is an EXPERIMENTAL API. +type PerRPCCredsCallOption struct { + Creds credentials.PerRPCCredentials +} + +func (o PerRPCCredsCallOption) before(c *callInfo) error { + c.creds = o.Creds + return nil +} +func (o PerRPCCredsCallOption) after(c *callInfo) {} + +// UseCompressor returns a CallOption which sets the compressor used when +// sending the request. If WithCompressor is also set, UseCompressor has +// higher priority. +// +// This API is EXPERIMENTAL. +func UseCompressor(name string) CallOption { + return CompressorCallOption{CompressorType: name} +} + +// CompressorCallOption is a CallOption that indicates the compressor to use. +// This is an EXPERIMENTAL API. +type CompressorCallOption struct { + CompressorType string +} + +func (o CompressorCallOption) before(c *callInfo) error { + c.compressorType = o.CompressorType + return nil +} +func (o CompressorCallOption) after(c *callInfo) {} + +// CallContentSubtype returns a CallOption that will set the content-subtype +// for a call. For example, if content-subtype is "json", the Content-Type over +// the wire will be "application/grpc+json". The content-subtype is converted +// to lowercase before being included in Content-Type. See Content-Type on +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. +// +// If CallCustomCodec is not also used, the content-subtype will be used to +// look up the Codec to use in the registry controlled by RegisterCodec. See +// the documentation on RegisterCodec for details on registration. The lookup +// of content-subtype is case-insensitive. If no such Codec is found, the call +// will result in an error with code codes.Internal. +// +// If CallCustomCodec is also used, that Codec will be used for all request and +// response messages, with the content-subtype set to the given contentSubtype +// here for requests. +func CallContentSubtype(contentSubtype string) CallOption { + return ContentSubtypeCallOption{ContentSubtype: strings.ToLower(contentSubtype)} +} + +// ContentSubtypeCallOption is a CallOption that indicates the content-subtype +// used for marshaling messages. +// This is an EXPERIMENTAL API. +type ContentSubtypeCallOption struct { + ContentSubtype string +} + +func (o ContentSubtypeCallOption) before(c *callInfo) error { + c.contentSubtype = o.ContentSubtype + return nil +} +func (o ContentSubtypeCallOption) after(c *callInfo) {} + +// CallCustomCodec returns a CallOption that will set the given Codec to be +// used for all request and response messages for a call. The result of calling +// String() will be used as the content-subtype in a case-insensitive manner. +// +// See Content-Type on +// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for +// more details. Also see the documentation on RegisterCodec and +// CallContentSubtype for more details on the interaction between Codec and +// content-subtype. +// +// This function is provided for advanced users; prefer to use only +// CallContentSubtype to select a registered codec instead. +func CallCustomCodec(codec Codec) CallOption { + return CustomCodecCallOption{Codec: codec} +} + +// CustomCodecCallOption is a CallOption that indicates the codec used for +// marshaling messages. +// This is an EXPERIMENTAL API. +type CustomCodecCallOption struct { + Codec Codec +} + +func (o CustomCodecCallOption) before(c *callInfo) error { + c.codec = o.Codec + return nil +} +func (o CustomCodecCallOption) after(c *callInfo) {} + +// MaxRetryRPCBufferSize returns a CallOption that limits the amount of memory +// used for buffering this RPC's requests for retry purposes. +// +// This API is EXPERIMENTAL. +func MaxRetryRPCBufferSize(bytes int) CallOption { + return MaxRetryRPCBufferSizeCallOption{bytes} +} + +// MaxRetryRPCBufferSizeCallOption is a CallOption indicating the amount of +// memory to be used for caching this RPC for retry purposes. +// This is an EXPERIMENTAL API. +type MaxRetryRPCBufferSizeCallOption struct { + MaxRetryRPCBufferSize int +} + +func (o MaxRetryRPCBufferSizeCallOption) before(c *callInfo) error { + c.maxRetryRPCBufferSize = o.MaxRetryRPCBufferSize + return nil +} +func (o MaxRetryRPCBufferSizeCallOption) after(c *callInfo) {} + +// The format of the payload: compressed or not? +type payloadFormat uint8 + +const ( + compressionNone payloadFormat = 0 // no compression + compressionMade payloadFormat = 1 // compressed +) + +// parser reads complete gRPC messages from the underlying reader. +type parser struct { + // r is the underlying reader. + // See the comment on recvMsg for the permissible + // error types. + r io.Reader + + // The header of a gRPC message. Find more detail at + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md + header [5]byte +} + +// recvMsg reads a complete gRPC message from the stream. +// +// It returns the message and its payload (compression/encoding) +// format. The caller owns the returned msg memory. +// +// If there is an error, possible values are: +// * io.EOF, when no messages remain +// * io.ErrUnexpectedEOF +// * of type transport.ConnectionError +// * an error from the status package +// No other error values or types must be returned, which also means +// that the underlying io.Reader must not return an incompatible +// error. +func (p *parser) recvMsg(maxReceiveMessageSize int) (pf payloadFormat, msg []byte, err error) { + if _, err := p.r.Read(p.header[:]); err != nil { + return 0, nil, err + } + + pf = payloadFormat(p.header[0]) + length := binary.BigEndian.Uint32(p.header[1:]) + + if length == 0 { + return pf, nil, nil + } + if int64(length) > int64(maxInt) { + return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max length allowed on current machine (%d vs. %d)", length, maxInt) + } + if int(length) > maxReceiveMessageSize { + return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", length, maxReceiveMessageSize) + } + // TODO(bradfitz,zhaoq): garbage. reuse buffer after proto decoding instead + // of making it for each message: + msg = make([]byte, int(length)) + if _, err := p.r.Read(msg); err != nil { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + return 0, nil, err + } + return pf, msg, nil +} + +// encode serializes msg and returns a buffer containing the message, or an +// error if it is too large to be transmitted by grpc. If msg is nil, it +// generates an empty message. +func encode(c baseCodec, msg interface{}) ([]byte, error) { + if msg == nil { // NOTE: typed nils will not be caught by this check + return nil, nil + } + b, err := c.Marshal(msg) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: error while marshaling: %v", err.Error()) + } + if uint(len(b)) > math.MaxUint32 { + return nil, status.Errorf(codes.ResourceExhausted, "grpc: message too large (%d bytes)", len(b)) + } + return b, nil +} + +// compress returns the input bytes compressed by compressor or cp. If both +// compressors are nil, returns nil. +// +// TODO(dfawley): eliminate cp parameter by wrapping Compressor in an encoding.Compressor. +func compress(in []byte, cp Compressor, compressor encoding.Compressor) ([]byte, error) { + if compressor == nil && cp == nil { + return nil, nil + } + wrapErr := func(err error) error { + return status.Errorf(codes.Internal, "grpc: error while compressing: %v", err.Error()) + } + cbuf := &bytes.Buffer{} + if compressor != nil { + z, err := compressor.Compress(cbuf) + if err != nil { + return nil, wrapErr(err) + } + if _, err := z.Write(in); err != nil { + return nil, wrapErr(err) + } + if err := z.Close(); err != nil { + return nil, wrapErr(err) + } + } else { + if err := cp.Do(cbuf, in); err != nil { + return nil, wrapErr(err) + } + } + return cbuf.Bytes(), nil +} + +const ( + payloadLen = 1 + sizeLen = 4 + headerLen = payloadLen + sizeLen +) + +// msgHeader returns a 5-byte header for the message being transmitted and the +// payload, which is compData if non-nil or data otherwise. +func msgHeader(data, compData []byte) (hdr []byte, payload []byte) { + hdr = make([]byte, headerLen) + if compData != nil { + hdr[0] = byte(compressionMade) + data = compData + } else { + hdr[0] = byte(compressionNone) + } + + // Write length of payload into buf + binary.BigEndian.PutUint32(hdr[payloadLen:], uint32(len(data))) + return hdr, data +} + +func outPayload(client bool, msg interface{}, data, payload []byte, t time.Time) *stats.OutPayload { + return &stats.OutPayload{ + Client: client, + Payload: msg, + Data: data, + Length: len(data), + WireLength: len(payload) + headerLen, + SentTime: t, + } +} + +func checkRecvPayload(pf payloadFormat, recvCompress string, haveCompressor bool) *status.Status { + switch pf { + case compressionNone: + case compressionMade: + if recvCompress == "" || recvCompress == encoding.Identity { + return status.New(codes.Internal, "grpc: compressed flag set with identity or empty encoding") + } + if !haveCompressor { + return status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", recvCompress) + } + default: + return status.Newf(codes.Internal, "grpc: received unexpected payload format %d", pf) + } + return nil +} + +type payloadInfo struct { + wireLength int // The compressed length got from wire. + uncompressedBytes []byte +} + +func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) ([]byte, error) { + pf, d, err := p.recvMsg(maxReceiveMessageSize) + if err != nil { + return nil, err + } + if payInfo != nil { + payInfo.wireLength = len(d) + } + + if st := checkRecvPayload(pf, s.RecvCompress(), compressor != nil || dc != nil); st != nil { + return nil, st.Err() + } + + if pf == compressionMade { + // To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor, + // use this decompressor as the default. + if dc != nil { + d, err = dc.Do(bytes.NewReader(d)) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + } else { + dcReader, err := compressor.Decompress(bytes.NewReader(d)) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + d, err = ioutil.ReadAll(dcReader) + if err != nil { + return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) + } + } + } + if len(d) > maxReceiveMessageSize { + // TODO: Revisit the error code. Currently keep it consistent with java + // implementation. + return nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", len(d), maxReceiveMessageSize) + } + return d, nil +} + +// For the two compressor parameters, both should not be set, but if they are, +// dc takes precedence over compressor. +// TODO(dfawley): wrap the old compressor/decompressor using the new API? +func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interface{}, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) error { + d, err := recvAndDecompress(p, s, dc, maxReceiveMessageSize, payInfo, compressor) + if err != nil { + return err + } + if err := c.Unmarshal(d, m); err != nil { + return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message %v", err) + } + if payInfo != nil { + payInfo.uncompressedBytes = d + } + return nil +} + +type rpcInfo struct { + failfast bool +} + +type rpcInfoContextKey struct{} + +func newContextWithRPCInfo(ctx context.Context, failfast bool) context.Context { + return context.WithValue(ctx, rpcInfoContextKey{}, &rpcInfo{failfast: failfast}) +} + +func rpcInfoFromContext(ctx context.Context) (s *rpcInfo, ok bool) { + s, ok = ctx.Value(rpcInfoContextKey{}).(*rpcInfo) + return +} + +// Code returns the error code for err if it was produced by the rpc system. +// Otherwise, it returns codes.Unknown. +// +// Deprecated: use status.FromError and Code method instead. +func Code(err error) codes.Code { + if s, ok := status.FromError(err); ok { + return s.Code() + } + return codes.Unknown +} + +// ErrorDesc returns the error description of err if it was produced by the rpc system. +// Otherwise, it returns err.Error() or empty string when err is nil. +// +// Deprecated: use status.FromError and Message method instead. +func ErrorDesc(err error) string { + if s, ok := status.FromError(err); ok { + return s.Message() + } + return err.Error() +} + +// Errorf returns an error containing an error code and a description; +// Errorf returns nil if c is OK. +// +// Deprecated: use status.Errorf instead. +func Errorf(c codes.Code, format string, a ...interface{}) error { + return status.Errorf(c, format, a...) +} + +// toRPCErr converts an error into an error from the status package. +func toRPCErr(err error) error { + if err == nil || err == io.EOF { + return err + } + if err == io.ErrUnexpectedEOF { + return status.Error(codes.Internal, err.Error()) + } + if _, ok := status.FromError(err); ok { + return err + } + switch e := err.(type) { + case transport.ConnectionError: + return status.Error(codes.Unavailable, e.Desc) + default: + switch err { + case context.DeadlineExceeded: + return status.Error(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return status.Error(codes.Canceled, err.Error()) + } + } + return status.Error(codes.Unknown, err.Error()) +} + +// setCallInfoCodec should only be called after CallOptions have been applied. +func setCallInfoCodec(c *callInfo) error { + if c.codec != nil { + // codec was already set by a CallOption; use it. + return nil + } + + if c.contentSubtype == "" { + // No codec specified in CallOptions; use proto by default. + c.codec = encoding.GetCodec(proto.Name) + return nil + } + + // c.contentSubtype is already lowercased in CallContentSubtype + c.codec = encoding.GetCodec(c.contentSubtype) + if c.codec == nil { + return status.Errorf(codes.Internal, "no codec registered for content-subtype %s", c.contentSubtype) + } + return nil +} + +// parseDialTarget returns the network and address to pass to dialer +func parseDialTarget(target string) (net string, addr string) { + net = "tcp" + + m1 := strings.Index(target, ":") + m2 := strings.Index(target, ":/") + + // handle unix:addr which will fail with url.Parse + if m1 >= 0 && m2 < 0 { + if n := target[0:m1]; n == "unix" { + net = n + addr = target[m1+1:] + return net, addr + } + } + if m2 >= 0 { + t, err := url.Parse(target) + if err != nil { + return net, target + } + scheme := t.Scheme + addr = t.Path + if scheme == "unix" { + net = scheme + if addr == "" { + addr = t.Host + } + return net, addr + } + } + + return net, target +} + +// channelzData is used to store channelz related data for ClientConn, addrConn and Server. +// These fields cannot be embedded in the original structs (e.g. ClientConn), since to do atomic +// operation on int64 variable on 32-bit machine, user is responsible to enforce memory alignment. +// Here, by grouping those int64 fields inside a struct, we are enforcing the alignment. +type channelzData struct { + callsStarted int64 + callsFailed int64 + callsSucceeded int64 + // lastCallStartedTime stores the timestamp that last call starts. It is of int64 type instead of + // time.Time since it's more costly to atomically update time.Time variable than int64 variable. + lastCallStartedTime int64 +} + +// The SupportPackageIsVersion variables are referenced from generated protocol +// buffer files to ensure compatibility with the gRPC version used. The latest +// support package version is 5. +// +// Older versions are kept for compatibility. They may be removed if +// compatibility cannot be maintained. +// +// These constants should not be referenced from any other code. +const ( + SupportPackageIsVersion3 = true + SupportPackageIsVersion4 = true + SupportPackageIsVersion5 = true +) + +const grpcUA = "grpc-go/" + Version diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go new file mode 100644 index 00000000..d705d7a8 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/server.go @@ -0,0 +1,1486 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "fmt" + "io" + "math" + "net" + "net/http" + "reflect" + "runtime" + "strings" + "sync" + "sync/atomic" + "time" + + "golang.org/x/net/trace" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/binarylog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + "google.golang.org/grpc/tap" +) + +const ( + defaultServerMaxReceiveMessageSize = 1024 * 1024 * 4 + defaultServerMaxSendMessageSize = math.MaxInt32 +) + +type methodHandler func(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor UnaryServerInterceptor) (interface{}, error) + +// MethodDesc represents an RPC service's method specification. +type MethodDesc struct { + MethodName string + Handler methodHandler +} + +// ServiceDesc represents an RPC service's specification. +type ServiceDesc struct { + ServiceName string + // The pointer to the service interface. Used to check whether the user + // provided implementation satisfies the interface requirements. + HandlerType interface{} + Methods []MethodDesc + Streams []StreamDesc + Metadata interface{} +} + +// service consists of the information of the server serving this service and +// the methods in this service. +type service struct { + server interface{} // the server for service methods + md map[string]*MethodDesc + sd map[string]*StreamDesc + mdata interface{} +} + +// Server is a gRPC server to serve RPC requests. +type Server struct { + opts options + + mu sync.Mutex // guards following + lis map[net.Listener]bool + conns map[io.Closer]bool + serve bool + drain bool + cv *sync.Cond // signaled when connections close for GracefulStop + m map[string]*service // service name -> service info + events trace.EventLog + + quit chan struct{} + done chan struct{} + quitOnce sync.Once + doneOnce sync.Once + channelzRemoveOnce sync.Once + serveWG sync.WaitGroup // counts active Serve goroutines for GracefulStop + + channelzID int64 // channelz unique identification number + czData *channelzData +} + +type options struct { + creds credentials.TransportCredentials + codec baseCodec + cp Compressor + dc Decompressor + unaryInt UnaryServerInterceptor + streamInt StreamServerInterceptor + inTapHandle tap.ServerInHandle + statsHandler stats.Handler + maxConcurrentStreams uint32 + maxReceiveMessageSize int + maxSendMessageSize int + unknownStreamDesc *StreamDesc + keepaliveParams keepalive.ServerParameters + keepalivePolicy keepalive.EnforcementPolicy + initialWindowSize int32 + initialConnWindowSize int32 + writeBufferSize int + readBufferSize int + connectionTimeout time.Duration + maxHeaderListSize *uint32 +} + +var defaultServerOptions = options{ + maxReceiveMessageSize: defaultServerMaxReceiveMessageSize, + maxSendMessageSize: defaultServerMaxSendMessageSize, + connectionTimeout: 120 * time.Second, + writeBufferSize: defaultWriteBufSize, + readBufferSize: defaultReadBufSize, +} + +// A ServerOption sets options such as credentials, codec and keepalive parameters, etc. +type ServerOption func(*options) + +// WriteBufferSize determines how much data can be batched before doing a write on the wire. +// The corresponding memory allocation for this buffer will be twice the size to keep syscalls low. +// The default value for this buffer is 32KB. +// Zero will disable the write buffer such that each write will be on underlying connection. +// Note: A Send call may not directly translate to a write. +func WriteBufferSize(s int) ServerOption { + return func(o *options) { + o.writeBufferSize = s + } +} + +// ReadBufferSize lets you set the size of read buffer, this determines how much data can be read at most +// for one read syscall. +// The default value for this buffer is 32KB. +// Zero will disable read buffer for a connection so data framer can access the underlying +// conn directly. +func ReadBufferSize(s int) ServerOption { + return func(o *options) { + o.readBufferSize = s + } +} + +// InitialWindowSize returns a ServerOption that sets window size for stream. +// The lower bound for window size is 64K and any value smaller than that will be ignored. +func InitialWindowSize(s int32) ServerOption { + return func(o *options) { + o.initialWindowSize = s + } +} + +// InitialConnWindowSize returns a ServerOption that sets window size for a connection. +// The lower bound for window size is 64K and any value smaller than that will be ignored. +func InitialConnWindowSize(s int32) ServerOption { + return func(o *options) { + o.initialConnWindowSize = s + } +} + +// KeepaliveParams returns a ServerOption that sets keepalive and max-age parameters for the server. +func KeepaliveParams(kp keepalive.ServerParameters) ServerOption { + return func(o *options) { + o.keepaliveParams = kp + } +} + +// KeepaliveEnforcementPolicy returns a ServerOption that sets keepalive enforcement policy for the server. +func KeepaliveEnforcementPolicy(kep keepalive.EnforcementPolicy) ServerOption { + return func(o *options) { + o.keepalivePolicy = kep + } +} + +// CustomCodec returns a ServerOption that sets a codec for message marshaling and unmarshaling. +// +// This will override any lookups by content-subtype for Codecs registered with RegisterCodec. +func CustomCodec(codec Codec) ServerOption { + return func(o *options) { + o.codec = codec + } +} + +// RPCCompressor returns a ServerOption that sets a compressor for outbound +// messages. For backward compatibility, all outbound messages will be sent +// using this compressor, regardless of incoming message compression. By +// default, server messages will be sent using the same compressor with which +// request messages were sent. +// +// Deprecated: use encoding.RegisterCompressor instead. +func RPCCompressor(cp Compressor) ServerOption { + return func(o *options) { + o.cp = cp + } +} + +// RPCDecompressor returns a ServerOption that sets a decompressor for inbound +// messages. It has higher priority than decompressors registered via +// encoding.RegisterCompressor. +// +// Deprecated: use encoding.RegisterCompressor instead. +func RPCDecompressor(dc Decompressor) ServerOption { + return func(o *options) { + o.dc = dc + } +} + +// MaxMsgSize returns a ServerOption to set the max message size in bytes the server can receive. +// If this is not set, gRPC uses the default limit. +// +// Deprecated: use MaxRecvMsgSize instead. +func MaxMsgSize(m int) ServerOption { + return MaxRecvMsgSize(m) +} + +// MaxRecvMsgSize returns a ServerOption to set the max message size in bytes the server can receive. +// If this is not set, gRPC uses the default 4MB. +func MaxRecvMsgSize(m int) ServerOption { + return func(o *options) { + o.maxReceiveMessageSize = m + } +} + +// MaxSendMsgSize returns a ServerOption to set the max message size in bytes the server can send. +// If this is not set, gRPC uses the default 4MB. +func MaxSendMsgSize(m int) ServerOption { + return func(o *options) { + o.maxSendMessageSize = m + } +} + +// MaxConcurrentStreams returns a ServerOption that will apply a limit on the number +// of concurrent streams to each ServerTransport. +func MaxConcurrentStreams(n uint32) ServerOption { + return func(o *options) { + o.maxConcurrentStreams = n + } +} + +// Creds returns a ServerOption that sets credentials for server connections. +func Creds(c credentials.TransportCredentials) ServerOption { + return func(o *options) { + o.creds = c + } +} + +// UnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the +// server. Only one unary interceptor can be installed. The construction of multiple +// interceptors (e.g., chaining) can be implemented at the caller. +func UnaryInterceptor(i UnaryServerInterceptor) ServerOption { + return func(o *options) { + if o.unaryInt != nil { + panic("The unary server interceptor was already set and may not be reset.") + } + o.unaryInt = i + } +} + +// StreamInterceptor returns a ServerOption that sets the StreamServerInterceptor for the +// server. Only one stream interceptor can be installed. +func StreamInterceptor(i StreamServerInterceptor) ServerOption { + return func(o *options) { + if o.streamInt != nil { + panic("The stream server interceptor was already set and may not be reset.") + } + o.streamInt = i + } +} + +// InTapHandle returns a ServerOption that sets the tap handle for all the server +// transport to be created. Only one can be installed. +func InTapHandle(h tap.ServerInHandle) ServerOption { + return func(o *options) { + if o.inTapHandle != nil { + panic("The tap handle was already set and may not be reset.") + } + o.inTapHandle = h + } +} + +// StatsHandler returns a ServerOption that sets the stats handler for the server. +func StatsHandler(h stats.Handler) ServerOption { + return func(o *options) { + o.statsHandler = h + } +} + +// UnknownServiceHandler returns a ServerOption that allows for adding a custom +// unknown service handler. The provided method is a bidi-streaming RPC service +// handler that will be invoked instead of returning the "unimplemented" gRPC +// error whenever a request is received for an unregistered service or method. +// The handling function has full access to the Context of the request and the +// stream, and the invocation bypasses interceptors. +func UnknownServiceHandler(streamHandler StreamHandler) ServerOption { + return func(o *options) { + o.unknownStreamDesc = &StreamDesc{ + StreamName: "unknown_service_handler", + Handler: streamHandler, + // We need to assume that the users of the streamHandler will want to use both. + ClientStreams: true, + ServerStreams: true, + } + } +} + +// ConnectionTimeout returns a ServerOption that sets the timeout for +// connection establishment (up to and including HTTP/2 handshaking) for all +// new connections. If this is not set, the default is 120 seconds. A zero or +// negative value will result in an immediate timeout. +// +// This API is EXPERIMENTAL. +func ConnectionTimeout(d time.Duration) ServerOption { + return func(o *options) { + o.connectionTimeout = d + } +} + +// MaxHeaderListSize returns a ServerOption that sets the max (uncompressed) size +// of header list that the server is prepared to accept. +func MaxHeaderListSize(s uint32) ServerOption { + return func(o *options) { + o.maxHeaderListSize = &s + } +} + +// NewServer creates a gRPC server which has no service registered and has not +// started to accept requests yet. +func NewServer(opt ...ServerOption) *Server { + opts := defaultServerOptions + for _, o := range opt { + o(&opts) + } + s := &Server{ + lis: make(map[net.Listener]bool), + opts: opts, + conns: make(map[io.Closer]bool), + m: make(map[string]*service), + quit: make(chan struct{}), + done: make(chan struct{}), + czData: new(channelzData), + } + s.cv = sync.NewCond(&s.mu) + if EnableTracing { + _, file, line, _ := runtime.Caller(1) + s.events = trace.NewEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line)) + } + + if channelz.IsOn() { + s.channelzID = channelz.RegisterServer(&channelzServer{s}, "") + } + return s +} + +// printf records an event in s's event log, unless s has been stopped. +// REQUIRES s.mu is held. +func (s *Server) printf(format string, a ...interface{}) { + if s.events != nil { + s.events.Printf(format, a...) + } +} + +// errorf records an error in s's event log, unless s has been stopped. +// REQUIRES s.mu is held. +func (s *Server) errorf(format string, a ...interface{}) { + if s.events != nil { + s.events.Errorf(format, a...) + } +} + +// RegisterService registers a service and its implementation to the gRPC +// server. It is called from the IDL generated code. This must be called before +// invoking Serve. +func (s *Server) RegisterService(sd *ServiceDesc, ss interface{}) { + ht := reflect.TypeOf(sd.HandlerType).Elem() + st := reflect.TypeOf(ss) + if !st.Implements(ht) { + grpclog.Fatalf("grpc: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht) + } + s.register(sd, ss) +} + +func (s *Server) register(sd *ServiceDesc, ss interface{}) { + s.mu.Lock() + defer s.mu.Unlock() + s.printf("RegisterService(%q)", sd.ServiceName) + if s.serve { + grpclog.Fatalf("grpc: Server.RegisterService after Server.Serve for %q", sd.ServiceName) + } + if _, ok := s.m[sd.ServiceName]; ok { + grpclog.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName) + } + srv := &service{ + server: ss, + md: make(map[string]*MethodDesc), + sd: make(map[string]*StreamDesc), + mdata: sd.Metadata, + } + for i := range sd.Methods { + d := &sd.Methods[i] + srv.md[d.MethodName] = d + } + for i := range sd.Streams { + d := &sd.Streams[i] + srv.sd[d.StreamName] = d + } + s.m[sd.ServiceName] = srv +} + +// MethodInfo contains the information of an RPC including its method name and type. +type MethodInfo struct { + // Name is the method name only, without the service name or package name. + Name string + // IsClientStream indicates whether the RPC is a client streaming RPC. + IsClientStream bool + // IsServerStream indicates whether the RPC is a server streaming RPC. + IsServerStream bool +} + +// ServiceInfo contains unary RPC method info, streaming RPC method info and metadata for a service. +type ServiceInfo struct { + Methods []MethodInfo + // Metadata is the metadata specified in ServiceDesc when registering service. + Metadata interface{} +} + +// GetServiceInfo returns a map from service names to ServiceInfo. +// Service names include the package names, in the form of .. +func (s *Server) GetServiceInfo() map[string]ServiceInfo { + ret := make(map[string]ServiceInfo) + for n, srv := range s.m { + methods := make([]MethodInfo, 0, len(srv.md)+len(srv.sd)) + for m := range srv.md { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: false, + IsServerStream: false, + }) + } + for m, d := range srv.sd { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: d.ClientStreams, + IsServerStream: d.ServerStreams, + }) + } + + ret[n] = ServiceInfo{ + Methods: methods, + Metadata: srv.mdata, + } + } + return ret +} + +// ErrServerStopped indicates that the operation is now illegal because of +// the server being stopped. +var ErrServerStopped = errors.New("grpc: the server has been stopped") + +func (s *Server) useTransportAuthenticator(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) { + if s.opts.creds == nil { + return rawConn, nil, nil + } + return s.opts.creds.ServerHandshake(rawConn) +} + +type listenSocket struct { + net.Listener + channelzID int64 +} + +func (l *listenSocket) ChannelzMetric() *channelz.SocketInternalMetric { + return &channelz.SocketInternalMetric{ + SocketOptions: channelz.GetSocketOption(l.Listener), + LocalAddr: l.Listener.Addr(), + } +} + +func (l *listenSocket) Close() error { + err := l.Listener.Close() + if channelz.IsOn() { + channelz.RemoveEntry(l.channelzID) + } + return err +} + +// Serve accepts incoming connections on the listener lis, creating a new +// ServerTransport and service goroutine for each. The service goroutines +// read gRPC requests and then call the registered handlers to reply to them. +// Serve returns when lis.Accept fails with fatal errors. lis will be closed when +// this method returns. +// Serve will return a non-nil error unless Stop or GracefulStop is called. +func (s *Server) Serve(lis net.Listener) error { + s.mu.Lock() + s.printf("serving") + s.serve = true + if s.lis == nil { + // Serve called after Stop or GracefulStop. + s.mu.Unlock() + lis.Close() + return ErrServerStopped + } + + s.serveWG.Add(1) + defer func() { + s.serveWG.Done() + select { + // Stop or GracefulStop called; block until done and return nil. + case <-s.quit: + <-s.done + default: + } + }() + + ls := &listenSocket{Listener: lis} + s.lis[ls] = true + + if channelz.IsOn() { + ls.channelzID = channelz.RegisterListenSocket(ls, s.channelzID, lis.Addr().String()) + } + s.mu.Unlock() + + defer func() { + s.mu.Lock() + if s.lis != nil && s.lis[ls] { + ls.Close() + delete(s.lis, ls) + } + s.mu.Unlock() + }() + + var tempDelay time.Duration // how long to sleep on accept failure + + for { + rawConn, err := lis.Accept() + if err != nil { + if ne, ok := err.(interface { + Temporary() bool + }); ok && ne.Temporary() { + if tempDelay == 0 { + tempDelay = 5 * time.Millisecond + } else { + tempDelay *= 2 + } + if max := 1 * time.Second; tempDelay > max { + tempDelay = max + } + s.mu.Lock() + s.printf("Accept error: %v; retrying in %v", err, tempDelay) + s.mu.Unlock() + timer := time.NewTimer(tempDelay) + select { + case <-timer.C: + case <-s.quit: + timer.Stop() + return nil + } + continue + } + s.mu.Lock() + s.printf("done serving; Accept = %v", err) + s.mu.Unlock() + + select { + case <-s.quit: + return nil + default: + } + return err + } + tempDelay = 0 + // Start a new goroutine to deal with rawConn so we don't stall this Accept + // loop goroutine. + // + // Make sure we account for the goroutine so GracefulStop doesn't nil out + // s.conns before this conn can be added. + s.serveWG.Add(1) + go func() { + s.handleRawConn(rawConn) + s.serveWG.Done() + }() + } +} + +// handleRawConn forks a goroutine to handle a just-accepted connection that +// has not had any I/O performed on it yet. +func (s *Server) handleRawConn(rawConn net.Conn) { + rawConn.SetDeadline(time.Now().Add(s.opts.connectionTimeout)) + conn, authInfo, err := s.useTransportAuthenticator(rawConn) + if err != nil { + s.mu.Lock() + s.errorf("ServerHandshake(%q) failed: %v", rawConn.RemoteAddr(), err) + s.mu.Unlock() + grpclog.Warningf("grpc: Server.Serve failed to complete security handshake from %q: %v", rawConn.RemoteAddr(), err) + // If serverHandshake returns ErrConnDispatched, keep rawConn open. + if err != credentials.ErrConnDispatched { + rawConn.Close() + } + rawConn.SetDeadline(time.Time{}) + return + } + + s.mu.Lock() + if s.conns == nil { + s.mu.Unlock() + conn.Close() + return + } + s.mu.Unlock() + + // Finish handshaking (HTTP2) + st := s.newHTTP2Transport(conn, authInfo) + if st == nil { + return + } + + rawConn.SetDeadline(time.Time{}) + if !s.addConn(st) { + return + } + go func() { + s.serveStreams(st) + s.removeConn(st) + }() +} + +// newHTTP2Transport sets up a http/2 transport (using the +// gRPC http2 server transport in transport/http2_server.go). +func (s *Server) newHTTP2Transport(c net.Conn, authInfo credentials.AuthInfo) transport.ServerTransport { + config := &transport.ServerConfig{ + MaxStreams: s.opts.maxConcurrentStreams, + AuthInfo: authInfo, + InTapHandle: s.opts.inTapHandle, + StatsHandler: s.opts.statsHandler, + KeepaliveParams: s.opts.keepaliveParams, + KeepalivePolicy: s.opts.keepalivePolicy, + InitialWindowSize: s.opts.initialWindowSize, + InitialConnWindowSize: s.opts.initialConnWindowSize, + WriteBufferSize: s.opts.writeBufferSize, + ReadBufferSize: s.opts.readBufferSize, + ChannelzParentID: s.channelzID, + MaxHeaderListSize: s.opts.maxHeaderListSize, + } + st, err := transport.NewServerTransport("http2", c, config) + if err != nil { + s.mu.Lock() + s.errorf("NewServerTransport(%q) failed: %v", c.RemoteAddr(), err) + s.mu.Unlock() + c.Close() + grpclog.Warningln("grpc: Server.Serve failed to create ServerTransport: ", err) + return nil + } + + return st +} + +func (s *Server) serveStreams(st transport.ServerTransport) { + defer st.Close() + var wg sync.WaitGroup + st.HandleStreams(func(stream *transport.Stream) { + wg.Add(1) + go func() { + defer wg.Done() + s.handleStream(st, stream, s.traceInfo(st, stream)) + }() + }, func(ctx context.Context, method string) context.Context { + if !EnableTracing { + return ctx + } + tr := trace.New("grpc.Recv."+methodFamily(method), method) + return trace.NewContext(ctx, tr) + }) + wg.Wait() +} + +var _ http.Handler = (*Server)(nil) + +// ServeHTTP implements the Go standard library's http.Handler +// interface by responding to the gRPC request r, by looking up +// the requested gRPC method in the gRPC server s. +// +// The provided HTTP request must have arrived on an HTTP/2 +// connection. When using the Go standard library's server, +// practically this means that the Request must also have arrived +// over TLS. +// +// To share one port (such as 443 for https) between gRPC and an +// existing http.Handler, use a root http.Handler such as: +// +// if r.ProtoMajor == 2 && strings.HasPrefix( +// r.Header.Get("Content-Type"), "application/grpc") { +// grpcServer.ServeHTTP(w, r) +// } else { +// yourMux.ServeHTTP(w, r) +// } +// +// Note that ServeHTTP uses Go's HTTP/2 server implementation which is totally +// separate from grpc-go's HTTP/2 server. Performance and features may vary +// between the two paths. ServeHTTP does not support some gRPC features +// available through grpc-go's HTTP/2 server, and it is currently EXPERIMENTAL +// and subject to change. +func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + st, err := transport.NewServerHandlerTransport(w, r, s.opts.statsHandler) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + if !s.addConn(st) { + return + } + defer s.removeConn(st) + s.serveStreams(st) +} + +// traceInfo returns a traceInfo and associates it with stream, if tracing is enabled. +// If tracing is not enabled, it returns nil. +func (s *Server) traceInfo(st transport.ServerTransport, stream *transport.Stream) (trInfo *traceInfo) { + tr, ok := trace.FromContext(stream.Context()) + if !ok { + return nil + } + + trInfo = &traceInfo{ + tr: tr, + } + trInfo.firstLine.client = false + trInfo.firstLine.remoteAddr = st.RemoteAddr() + + if dl, ok := stream.Context().Deadline(); ok { + trInfo.firstLine.deadline = dl.Sub(time.Now()) + } + return trInfo +} + +func (s *Server) addConn(c io.Closer) bool { + s.mu.Lock() + defer s.mu.Unlock() + if s.conns == nil { + c.Close() + return false + } + if s.drain { + // Transport added after we drained our existing conns: drain it + // immediately. + c.(transport.ServerTransport).Drain() + } + s.conns[c] = true + return true +} + +func (s *Server) removeConn(c io.Closer) { + s.mu.Lock() + defer s.mu.Unlock() + if s.conns != nil { + delete(s.conns, c) + s.cv.Broadcast() + } +} + +func (s *Server) channelzMetric() *channelz.ServerInternalMetric { + return &channelz.ServerInternalMetric{ + CallsStarted: atomic.LoadInt64(&s.czData.callsStarted), + CallsSucceeded: atomic.LoadInt64(&s.czData.callsSucceeded), + CallsFailed: atomic.LoadInt64(&s.czData.callsFailed), + LastCallStartedTimestamp: time.Unix(0, atomic.LoadInt64(&s.czData.lastCallStartedTime)), + } +} + +func (s *Server) incrCallsStarted() { + atomic.AddInt64(&s.czData.callsStarted, 1) + atomic.StoreInt64(&s.czData.lastCallStartedTime, time.Now().UnixNano()) +} + +func (s *Server) incrCallsSucceeded() { + atomic.AddInt64(&s.czData.callsSucceeded, 1) +} + +func (s *Server) incrCallsFailed() { + atomic.AddInt64(&s.czData.callsFailed, 1) +} + +func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Stream, msg interface{}, cp Compressor, opts *transport.Options, comp encoding.Compressor) error { + data, err := encode(s.getCodec(stream.ContentSubtype()), msg) + if err != nil { + grpclog.Errorln("grpc: server failed to encode response: ", err) + return err + } + compData, err := compress(data, cp, comp) + if err != nil { + grpclog.Errorln("grpc: server failed to compress response: ", err) + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > s.opts.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(payload), s.opts.maxSendMessageSize) + } + err = t.Write(stream, hdr, payload, opts) + if err == nil && s.opts.statsHandler != nil { + s.opts.statsHandler.HandleRPC(stream.Context(), outPayload(false, msg, data, payload, time.Now())) + } + return err +} + +func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, md *MethodDesc, trInfo *traceInfo) (err error) { + if channelz.IsOn() { + s.incrCallsStarted() + defer func() { + if err != nil && err != io.EOF { + s.incrCallsFailed() + } else { + s.incrCallsSucceeded() + } + }() + } + sh := s.opts.statsHandler + if sh != nil { + beginTime := time.Now() + begin := &stats.Begin{ + BeginTime: beginTime, + } + sh.HandleRPC(stream.Context(), begin) + defer func() { + end := &stats.End{ + BeginTime: beginTime, + EndTime: time.Now(), + } + if err != nil && err != io.EOF { + end.Error = toRPCErr(err) + } + sh.HandleRPC(stream.Context(), end) + }() + } + if trInfo != nil { + defer trInfo.tr.Finish() + trInfo.firstLine.client = false + trInfo.tr.LazyLog(&trInfo.firstLine, false) + defer func() { + if err != nil && err != io.EOF { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + }() + } + + binlog := binarylog.GetMethodLogger(stream.Method()) + if binlog != nil { + ctx := stream.Context() + md, _ := metadata.FromIncomingContext(ctx) + logEntry := &binarylog.ClientHeader{ + Header: md, + MethodName: stream.Method(), + PeerAddr: nil, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + if a := md[":authority"]; len(a) > 0 { + logEntry.Authority = a[0] + } + if peer, ok := peer.FromContext(ctx); ok { + logEntry.PeerAddr = peer.Addr + } + binlog.Log(logEntry) + } + + // comp and cp are used for compression. decomp and dc are used for + // decompression. If comp and decomp are both set, they are the same; + // however they are kept separate to ensure that at most one of the + // compressor/decompressor variable pairs are set for use later. + var comp, decomp encoding.Compressor + var cp Compressor + var dc Decompressor + + // If dc is set and matches the stream's compression, use it. Otherwise, try + // to find a matching registered compressor for decomp. + if rc := stream.RecvCompress(); s.opts.dc != nil && s.opts.dc.Type() == rc { + dc = s.opts.dc + } else if rc != "" && rc != encoding.Identity { + decomp = encoding.GetCompressor(rc) + if decomp == nil { + st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) + t.WriteStatus(stream, st) + return st.Err() + } + } + + // If cp is set, use it. Otherwise, attempt to compress the response using + // the incoming message compression method. + // + // NOTE: this needs to be ahead of all handling, https://github.com/grpc/grpc-go/issues/686. + if s.opts.cp != nil { + cp = s.opts.cp + stream.SetSendCompress(cp.Type()) + } else if rc := stream.RecvCompress(); rc != "" && rc != encoding.Identity { + // Legacy compressor not specified; attempt to respond with same encoding. + comp = encoding.GetCompressor(rc) + if comp != nil { + stream.SetSendCompress(rc) + } + } + + var payInfo *payloadInfo + if sh != nil || binlog != nil { + payInfo = &payloadInfo{} + } + d, err := recvAndDecompress(&parser{r: stream}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp) + if err != nil { + if st, ok := status.FromError(err); ok { + if e := t.WriteStatus(stream, st); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status %v", e) + } + } + return err + } + if channelz.IsOn() { + t.IncrMsgRecv() + } + df := func(v interface{}) error { + if err := s.getCodec(stream.ContentSubtype()).Unmarshal(d, v); err != nil { + return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err) + } + if sh != nil { + sh.HandleRPC(stream.Context(), &stats.InPayload{ + RecvTime: time.Now(), + Payload: v, + Data: d, + Length: len(d), + }) + } + if binlog != nil { + binlog.Log(&binarylog.ClientMessage{ + Message: d, + }) + } + if trInfo != nil { + trInfo.tr.LazyLog(&payload{sent: false, msg: v}, true) + } + return nil + } + ctx := NewContextWithServerTransportStream(stream.Context(), stream) + reply, appErr := md.Handler(srv.server, ctx, df, s.opts.unaryInt) + if appErr != nil { + appStatus, ok := status.FromError(appErr) + if !ok { + // Convert appErr if it is not a grpc status error. + appErr = status.Error(codes.Unknown, appErr.Error()) + appStatus, _ = status.FromError(appErr) + } + if trInfo != nil { + trInfo.tr.LazyLog(stringer(appStatus.Message()), true) + trInfo.tr.SetError() + } + if e := t.WriteStatus(stream, appStatus); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status: %v", e) + } + if binlog != nil { + if h, _ := stream.Header(); h.Len() > 0 { + // Only log serverHeader if there was header. Otherwise it can + // be trailer only. + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + } + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return appErr + } + if trInfo != nil { + trInfo.tr.LazyLog(stringer("OK"), false) + } + opts := &transport.Options{Last: true} + + if err := s.sendResponse(t, stream, reply, cp, opts, comp); err != nil { + if err == io.EOF { + // The entire stream is done (for unary RPC only). + return err + } + if s, ok := status.FromError(err); ok { + if e := t.WriteStatus(stream, s); e != nil { + grpclog.Warningf("grpc: Server.processUnaryRPC failed to write status: %v", e) + } + } else { + switch st := err.(type) { + case transport.ConnectionError: + // Nothing to do here. + default: + panic(fmt.Sprintf("grpc: Unexpected error (%T) from sendResponse: %v", st, st)) + } + } + if binlog != nil { + h, _ := stream.Header() + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return err + } + if binlog != nil { + h, _ := stream.Header() + binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + binlog.Log(&binarylog.ServerMessage{ + Message: reply, + }) + } + if channelz.IsOn() { + t.IncrMsgSent() + } + if trInfo != nil { + trInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true) + } + // TODO: Should we be logging if writing status failed here, like above? + // Should the logging be in WriteStatus? Should we ignore the WriteStatus + // error or allow the stats handler to see it? + err = t.WriteStatus(stream, status.New(codes.OK, "")) + if binlog != nil { + binlog.Log(&binarylog.ServerTrailer{ + Trailer: stream.Trailer(), + Err: appErr, + }) + } + return err +} + +func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, sd *StreamDesc, trInfo *traceInfo) (err error) { + if channelz.IsOn() { + s.incrCallsStarted() + defer func() { + if err != nil && err != io.EOF { + s.incrCallsFailed() + } else { + s.incrCallsSucceeded() + } + }() + } + sh := s.opts.statsHandler + if sh != nil { + beginTime := time.Now() + begin := &stats.Begin{ + BeginTime: beginTime, + } + sh.HandleRPC(stream.Context(), begin) + defer func() { + end := &stats.End{ + BeginTime: beginTime, + EndTime: time.Now(), + } + if err != nil && err != io.EOF { + end.Error = toRPCErr(err) + } + sh.HandleRPC(stream.Context(), end) + }() + } + ctx := NewContextWithServerTransportStream(stream.Context(), stream) + ss := &serverStream{ + ctx: ctx, + t: t, + s: stream, + p: &parser{r: stream}, + codec: s.getCodec(stream.ContentSubtype()), + maxReceiveMessageSize: s.opts.maxReceiveMessageSize, + maxSendMessageSize: s.opts.maxSendMessageSize, + trInfo: trInfo, + statsHandler: sh, + } + + ss.binlog = binarylog.GetMethodLogger(stream.Method()) + if ss.binlog != nil { + md, _ := metadata.FromIncomingContext(ctx) + logEntry := &binarylog.ClientHeader{ + Header: md, + MethodName: stream.Method(), + PeerAddr: nil, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + if a := md[":authority"]; len(a) > 0 { + logEntry.Authority = a[0] + } + if peer, ok := peer.FromContext(ss.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + ss.binlog.Log(logEntry) + } + + // If dc is set and matches the stream's compression, use it. Otherwise, try + // to find a matching registered compressor for decomp. + if rc := stream.RecvCompress(); s.opts.dc != nil && s.opts.dc.Type() == rc { + ss.dc = s.opts.dc + } else if rc != "" && rc != encoding.Identity { + ss.decomp = encoding.GetCompressor(rc) + if ss.decomp == nil { + st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) + t.WriteStatus(ss.s, st) + return st.Err() + } + } + + // If cp is set, use it. Otherwise, attempt to compress the response using + // the incoming message compression method. + // + // NOTE: this needs to be ahead of all handling, https://github.com/grpc/grpc-go/issues/686. + if s.opts.cp != nil { + ss.cp = s.opts.cp + stream.SetSendCompress(s.opts.cp.Type()) + } else if rc := stream.RecvCompress(); rc != "" && rc != encoding.Identity { + // Legacy compressor not specified; attempt to respond with same encoding. + ss.comp = encoding.GetCompressor(rc) + if ss.comp != nil { + stream.SetSendCompress(rc) + } + } + + if trInfo != nil { + trInfo.tr.LazyLog(&trInfo.firstLine, false) + defer func() { + ss.mu.Lock() + if err != nil && err != io.EOF { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + ss.trInfo.tr.Finish() + ss.trInfo.tr = nil + ss.mu.Unlock() + }() + } + var appErr error + var server interface{} + if srv != nil { + server = srv.server + } + if s.opts.streamInt == nil { + appErr = sd.Handler(server, ss) + } else { + info := &StreamServerInfo{ + FullMethod: stream.Method(), + IsClientStream: sd.ClientStreams, + IsServerStream: sd.ServerStreams, + } + appErr = s.opts.streamInt(server, ss, info, sd.Handler) + } + if appErr != nil { + appStatus, ok := status.FromError(appErr) + if !ok { + appStatus = status.New(codes.Unknown, appErr.Error()) + appErr = appStatus.Err() + } + if trInfo != nil { + ss.mu.Lock() + ss.trInfo.tr.LazyLog(stringer(appStatus.Message()), true) + ss.trInfo.tr.SetError() + ss.mu.Unlock() + } + t.WriteStatus(ss.s, appStatus) + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ServerTrailer{ + Trailer: ss.s.Trailer(), + Err: appErr, + }) + } + // TODO: Should we log an error from WriteStatus here and below? + return appErr + } + if trInfo != nil { + ss.mu.Lock() + ss.trInfo.tr.LazyLog(stringer("OK"), false) + ss.mu.Unlock() + } + err = t.WriteStatus(ss.s, status.New(codes.OK, "")) + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ServerTrailer{ + Trailer: ss.s.Trailer(), + Err: appErr, + }) + } + return err +} + +func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Stream, trInfo *traceInfo) { + sm := stream.Method() + if sm != "" && sm[0] == '/' { + sm = sm[1:] + } + pos := strings.LastIndex(sm, "/") + if pos == -1 { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"Malformed method name %q", []interface{}{sm}}, true) + trInfo.tr.SetError() + } + errDesc := fmt.Sprintf("malformed method name: %q", stream.Method()) + if err := t.WriteStatus(stream, status.New(codes.ResourceExhausted, errDesc)); err != nil { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + grpclog.Warningf("grpc: Server.handleStream failed to write status: %v", err) + } + if trInfo != nil { + trInfo.tr.Finish() + } + return + } + service := sm[:pos] + method := sm[pos+1:] + + if srv, ok := s.m[service]; ok { + if md, ok := srv.md[method]; ok { + s.processUnaryRPC(t, stream, srv, md, trInfo) + return + } + if sd, ok := srv.sd[method]; ok { + s.processStreamingRPC(t, stream, srv, sd, trInfo) + return + } + } + // Unknown service, or known server unknown method. + if unknownDesc := s.opts.unknownStreamDesc; unknownDesc != nil { + s.processStreamingRPC(t, stream, nil, unknownDesc, trInfo) + return + } + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"Unknown service %v", []interface{}{service}}, true) + trInfo.tr.SetError() + } + errDesc := fmt.Sprintf("unknown service %v", service) + if err := t.WriteStatus(stream, status.New(codes.Unimplemented, errDesc)); err != nil { + if trInfo != nil { + trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + trInfo.tr.SetError() + } + grpclog.Warningf("grpc: Server.handleStream failed to write status: %v", err) + } + if trInfo != nil { + trInfo.tr.Finish() + } +} + +// The key to save ServerTransportStream in the context. +type streamKey struct{} + +// NewContextWithServerTransportStream creates a new context from ctx and +// attaches stream to it. +// +// This API is EXPERIMENTAL. +func NewContextWithServerTransportStream(ctx context.Context, stream ServerTransportStream) context.Context { + return context.WithValue(ctx, streamKey{}, stream) +} + +// ServerTransportStream is a minimal interface that a transport stream must +// implement. This can be used to mock an actual transport stream for tests of +// handler code that use, for example, grpc.SetHeader (which requires some +// stream to be in context). +// +// See also NewContextWithServerTransportStream. +// +// This API is EXPERIMENTAL. +type ServerTransportStream interface { + Method() string + SetHeader(md metadata.MD) error + SendHeader(md metadata.MD) error + SetTrailer(md metadata.MD) error +} + +// ServerTransportStreamFromContext returns the ServerTransportStream saved in +// ctx. Returns nil if the given context has no stream associated with it +// (which implies it is not an RPC invocation context). +// +// This API is EXPERIMENTAL. +func ServerTransportStreamFromContext(ctx context.Context) ServerTransportStream { + s, _ := ctx.Value(streamKey{}).(ServerTransportStream) + return s +} + +// Stop stops the gRPC server. It immediately closes all open +// connections and listeners. +// It cancels all active RPCs on the server side and the corresponding +// pending RPCs on the client side will get notified by connection +// errors. +func (s *Server) Stop() { + s.quitOnce.Do(func() { + close(s.quit) + }) + + defer func() { + s.serveWG.Wait() + s.doneOnce.Do(func() { + close(s.done) + }) + }() + + s.channelzRemoveOnce.Do(func() { + if channelz.IsOn() { + channelz.RemoveEntry(s.channelzID) + } + }) + + s.mu.Lock() + listeners := s.lis + s.lis = nil + st := s.conns + s.conns = nil + // interrupt GracefulStop if Stop and GracefulStop are called concurrently. + s.cv.Broadcast() + s.mu.Unlock() + + for lis := range listeners { + lis.Close() + } + for c := range st { + c.Close() + } + + s.mu.Lock() + if s.events != nil { + s.events.Finish() + s.events = nil + } + s.mu.Unlock() +} + +// GracefulStop stops the gRPC server gracefully. It stops the server from +// accepting new connections and RPCs and blocks until all the pending RPCs are +// finished. +func (s *Server) GracefulStop() { + s.quitOnce.Do(func() { + close(s.quit) + }) + + defer func() { + s.doneOnce.Do(func() { + close(s.done) + }) + }() + + s.channelzRemoveOnce.Do(func() { + if channelz.IsOn() { + channelz.RemoveEntry(s.channelzID) + } + }) + s.mu.Lock() + if s.conns == nil { + s.mu.Unlock() + return + } + + for lis := range s.lis { + lis.Close() + } + s.lis = nil + if !s.drain { + for c := range s.conns { + c.(transport.ServerTransport).Drain() + } + s.drain = true + } + + // Wait for serving threads to be ready to exit. Only then can we be sure no + // new conns will be created. + s.mu.Unlock() + s.serveWG.Wait() + s.mu.Lock() + + for len(s.conns) != 0 { + s.cv.Wait() + } + s.conns = nil + if s.events != nil { + s.events.Finish() + s.events = nil + } + s.mu.Unlock() +} + +// contentSubtype must be lowercase +// cannot return nil +func (s *Server) getCodec(contentSubtype string) baseCodec { + if s.opts.codec != nil { + return s.opts.codec + } + if contentSubtype == "" { + return encoding.GetCodec(proto.Name) + } + codec := encoding.GetCodec(contentSubtype) + if codec == nil { + return encoding.GetCodec(proto.Name) + } + return codec +} + +// SetHeader sets the header metadata. +// When called multiple times, all the provided metadata will be merged. +// All the metadata will be sent out when one of the following happens: +// - grpc.SendHeader() is called; +// - The first response is sent out; +// - An RPC status is sent out (error or success). +func SetHeader(ctx context.Context, md metadata.MD) error { + if md.Len() == 0 { + return nil + } + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + return stream.SetHeader(md) +} + +// SendHeader sends header metadata. It may be called at most once. +// The provided md and headers set by SetHeader() will be sent. +func SendHeader(ctx context.Context, md metadata.MD) error { + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + if err := stream.SendHeader(md); err != nil { + return toRPCErr(err) + } + return nil +} + +// SetTrailer sets the trailer metadata that will be sent when an RPC returns. +// When called more than once, all the provided metadata will be merged. +func SetTrailer(ctx context.Context, md metadata.MD) error { + if md.Len() == 0 { + return nil + } + stream := ServerTransportStreamFromContext(ctx) + if stream == nil { + return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) + } + return stream.SetTrailer(md) +} + +// Method returns the method string for the server context. The returned +// string is in the format of "/service/method". +func Method(ctx context.Context) (string, bool) { + s := ServerTransportStreamFromContext(ctx) + if s == nil { + return "", false + } + return s.Method(), true +} + +type channelzServer struct { + s *Server +} + +func (c *channelzServer) ChannelzMetric() *channelz.ServerInternalMetric { + return c.s.channelzMetric() +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go new file mode 100644 index 00000000..162857e2 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/service_config.go @@ -0,0 +1,372 @@ +/* + * + * 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 grpc + +import ( + "encoding/json" + "fmt" + "strconv" + "strings" + "time" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" +) + +const maxInt = int(^uint(0) >> 1) + +// MethodConfig defines the configuration recommended by the service providers for a +// particular method. +// +// Deprecated: Users should not use this struct. Service config should be received +// through name resolver, as specified here +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +type MethodConfig struct { + // WaitForReady indicates whether RPCs sent to this method should wait until + // the connection is ready by default (!failfast). The value specified via the + // gRPC client API will override the value set here. + WaitForReady *bool + // Timeout is the default timeout for RPCs sent to this method. The actual + // deadline used will be the minimum of the value specified here and the value + // set by the application via the gRPC client API. If either one is not set, + // then the other will be used. If neither is set, then the RPC has no deadline. + Timeout *time.Duration + // MaxReqSize is the maximum allowed payload size for an individual request in a + // stream (client->server) in bytes. The size which is measured is the serialized + // payload after per-message compression (but before stream compression) in bytes. + // The actual value used is the minimum of the value specified here and the value set + // by the application via the gRPC client API. If either one is not set, then the other + // will be used. If neither is set, then the built-in default is used. + MaxReqSize *int + // MaxRespSize is the maximum allowed payload size for an individual response in a + // stream (server->client) in bytes. + MaxRespSize *int + // RetryPolicy configures retry options for the method. + retryPolicy *retryPolicy +} + +// ServiceConfig is provided by the service provider and contains parameters for how +// clients that connect to the service should behave. +// +// Deprecated: Users should not use this struct. Service config should be received +// through name resolver, as specified here +// https://github.com/grpc/grpc/blob/master/doc/service_config.md +type ServiceConfig struct { + // LB is the load balancer the service providers recommends. The balancer specified + // via grpc.WithBalancer will override this. + LB *string + + // Methods contains a map for the methods in this service. If there is an + // exact match for a method (i.e. /service/method) in the map, use the + // corresponding MethodConfig. If there's no exact match, look for the + // default config for the service (/service/) and use the corresponding + // MethodConfig if it exists. Otherwise, the method has no MethodConfig to + // use. + Methods map[string]MethodConfig + + // If a retryThrottlingPolicy is provided, gRPC will automatically throttle + // retry attempts and hedged RPCs when the client’s ratio of failures to + // successes exceeds a threshold. + // + // For each server name, the gRPC client will maintain a token_count which is + // initially set to maxTokens, and can take values between 0 and maxTokens. + // + // Every outgoing RPC (regardless of service or method invoked) will change + // token_count as follows: + // + // - Every failed RPC will decrement the token_count by 1. + // - Every successful RPC will increment the token_count by tokenRatio. + // + // If token_count is less than or equal to maxTokens / 2, then RPCs will not + // be retried and hedged RPCs will not be sent. + retryThrottling *retryThrottlingPolicy + // healthCheckConfig must be set as one of the requirement to enable LB channel + // health check. + healthCheckConfig *healthCheckConfig +} + +// healthCheckConfig defines the go-native version of the LB channel health check config. +type healthCheckConfig struct { + // serviceName is the service name to use in the health-checking request. + ServiceName string +} + +// retryPolicy defines the go-native version of the retry policy defined by the +// service config here: +// https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config +type retryPolicy struct { + // MaxAttempts is the maximum number of attempts, including the original RPC. + // + // This field is required and must be two or greater. + maxAttempts int + + // Exponential backoff parameters. The initial retry attempt will occur at + // random(0, initialBackoffMS). In general, the nth attempt will occur at + // random(0, + // min(initialBackoffMS*backoffMultiplier**(n-1), maxBackoffMS)). + // + // These fields are required and must be greater than zero. + initialBackoff time.Duration + maxBackoff time.Duration + backoffMultiplier float64 + + // The set of status codes which may be retried. + // + // Status codes are specified as strings, e.g., "UNAVAILABLE". + // + // This field is required and must be non-empty. + // Note: a set is used to store this for easy lookup. + retryableStatusCodes map[codes.Code]bool +} + +type jsonRetryPolicy struct { + MaxAttempts int + InitialBackoff string + MaxBackoff string + BackoffMultiplier float64 + RetryableStatusCodes []codes.Code +} + +// retryThrottlingPolicy defines the go-native version of the retry throttling +// policy defined by the service config here: +// https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config +type retryThrottlingPolicy struct { + // The number of tokens starts at maxTokens. The token_count will always be + // between 0 and maxTokens. + // + // This field is required and must be greater than zero. + MaxTokens float64 + // The amount of tokens to add on each successful RPC. Typically this will + // be some number between 0 and 1, e.g., 0.1. + // + // This field is required and must be greater than zero. Up to 3 decimal + // places are supported. + TokenRatio float64 +} + +func parseDuration(s *string) (*time.Duration, error) { + if s == nil { + return nil, nil + } + if !strings.HasSuffix(*s, "s") { + return nil, fmt.Errorf("malformed duration %q", *s) + } + ss := strings.SplitN((*s)[:len(*s)-1], ".", 3) + if len(ss) > 2 { + return nil, fmt.Errorf("malformed duration %q", *s) + } + // hasDigits is set if either the whole or fractional part of the number is + // present, since both are optional but one is required. + hasDigits := false + var d time.Duration + if len(ss[0]) > 0 { + i, err := strconv.ParseInt(ss[0], 10, 32) + if err != nil { + return nil, fmt.Errorf("malformed duration %q: %v", *s, err) + } + d = time.Duration(i) * time.Second + hasDigits = true + } + if len(ss) == 2 && len(ss[1]) > 0 { + if len(ss[1]) > 9 { + return nil, fmt.Errorf("malformed duration %q", *s) + } + f, err := strconv.ParseInt(ss[1], 10, 64) + if err != nil { + return nil, fmt.Errorf("malformed duration %q: %v", *s, err) + } + for i := 9; i > len(ss[1]); i-- { + f *= 10 + } + d += time.Duration(f) + hasDigits = true + } + if !hasDigits { + return nil, fmt.Errorf("malformed duration %q", *s) + } + + return &d, nil +} + +type jsonName struct { + Service *string + Method *string +} + +func (j jsonName) generatePath() (string, bool) { + if j.Service == nil { + return "", false + } + res := "/" + *j.Service + "/" + if j.Method != nil { + res += *j.Method + } + return res, true +} + +// TODO(lyuxuan): delete this struct after cleaning up old service config implementation. +type jsonMC struct { + Name *[]jsonName + WaitForReady *bool + Timeout *string + MaxRequestMessageBytes *int64 + MaxResponseMessageBytes *int64 + RetryPolicy *jsonRetryPolicy +} + +// TODO(lyuxuan): delete this struct after cleaning up old service config implementation. +type jsonSC struct { + LoadBalancingPolicy *string + MethodConfig *[]jsonMC + RetryThrottling *retryThrottlingPolicy + HealthCheckConfig *healthCheckConfig +} + +func parseServiceConfig(js string) (ServiceConfig, error) { + if len(js) == 0 { + return ServiceConfig{}, fmt.Errorf("no JSON service config provided") + } + var rsc jsonSC + err := json.Unmarshal([]byte(js), &rsc) + if err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + sc := ServiceConfig{ + LB: rsc.LoadBalancingPolicy, + Methods: make(map[string]MethodConfig), + retryThrottling: rsc.RetryThrottling, + healthCheckConfig: rsc.HealthCheckConfig, + } + if rsc.MethodConfig == nil { + return sc, nil + } + + for _, m := range *rsc.MethodConfig { + if m.Name == nil { + continue + } + d, err := parseDuration(m.Timeout) + if err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + + mc := MethodConfig{ + WaitForReady: m.WaitForReady, + Timeout: d, + } + if mc.retryPolicy, err = convertRetryPolicy(m.RetryPolicy); err != nil { + grpclog.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err) + return ServiceConfig{}, err + } + if m.MaxRequestMessageBytes != nil { + if *m.MaxRequestMessageBytes > int64(maxInt) { + mc.MaxReqSize = newInt(maxInt) + } else { + mc.MaxReqSize = newInt(int(*m.MaxRequestMessageBytes)) + } + } + if m.MaxResponseMessageBytes != nil { + if *m.MaxResponseMessageBytes > int64(maxInt) { + mc.MaxRespSize = newInt(maxInt) + } else { + mc.MaxRespSize = newInt(int(*m.MaxResponseMessageBytes)) + } + } + for _, n := range *m.Name { + if path, valid := n.generatePath(); valid { + sc.Methods[path] = mc + } + } + } + + if sc.retryThrottling != nil { + if sc.retryThrottling.MaxTokens <= 0 || + sc.retryThrottling.MaxTokens >= 1000 || + sc.retryThrottling.TokenRatio <= 0 { + // Illegal throttling config; disable throttling. + sc.retryThrottling = nil + } + } + return sc, nil +} + +func convertRetryPolicy(jrp *jsonRetryPolicy) (p *retryPolicy, err error) { + if jrp == nil { + return nil, nil + } + ib, err := parseDuration(&jrp.InitialBackoff) + if err != nil { + return nil, err + } + mb, err := parseDuration(&jrp.MaxBackoff) + if err != nil { + return nil, err + } + + if jrp.MaxAttempts <= 1 || + *ib <= 0 || + *mb <= 0 || + jrp.BackoffMultiplier <= 0 || + len(jrp.RetryableStatusCodes) == 0 { + grpclog.Warningf("grpc: ignoring retry policy %v due to illegal configuration", jrp) + return nil, nil + } + + rp := &retryPolicy{ + maxAttempts: jrp.MaxAttempts, + initialBackoff: *ib, + maxBackoff: *mb, + backoffMultiplier: jrp.BackoffMultiplier, + retryableStatusCodes: make(map[codes.Code]bool), + } + if rp.maxAttempts > 5 { + // TODO(retry): Make the max maxAttempts configurable. + rp.maxAttempts = 5 + } + for _, code := range jrp.RetryableStatusCodes { + rp.retryableStatusCodes[code] = true + } + return rp, nil +} + +func min(a, b *int) *int { + if *a < *b { + return a + } + return b +} + +func getMaxSize(mcMax, doptMax *int, defaultVal int) *int { + if mcMax == nil && doptMax == nil { + return &defaultVal + } + if mcMax != nil && doptMax != nil { + return min(mcMax, doptMax) + } + if mcMax != nil { + return mcMax + } + return doptMax +} + +func newInt(b int) *int { + return &b +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go new file mode 100644 index 00000000..dc03731e --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/handlers.go @@ -0,0 +1,63 @@ +/* + * + * Copyright 2016 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 stats + +import ( + "context" + "net" +) + +// ConnTagInfo defines the relevant information needed by connection context tagger. +type ConnTagInfo struct { + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr +} + +// RPCTagInfo defines the relevant information needed by RPC context tagger. +type RPCTagInfo struct { + // FullMethodName is the RPC method in the format of /package.service/method. + FullMethodName string + // FailFast indicates if this RPC is failfast. + // This field is only valid on client side, it's always false on server side. + FailFast bool +} + +// Handler defines the interface for the related stats handling (e.g., RPCs, connections). +type Handler interface { + // TagRPC can attach some information to the given context. + // The context used for the rest lifetime of the RPC will be derived from + // the returned context. + TagRPC(context.Context, *RPCTagInfo) context.Context + // HandleRPC processes the RPC stats. + HandleRPC(context.Context, RPCStats) + + // TagConn can attach some information to the given context. + // The returned context will be used for stats handling. + // For conn stats handling, the context used in HandleConn for this + // connection will be derived from the context returned. + // For RPC stats handling, + // - On server side, the context used in HandleRPC for all RPCs on this + // connection will be derived from the context returned. + // - On client side, the context is not derived from the context returned. + TagConn(context.Context, *ConnTagInfo) context.Context + // HandleConn processes the Conn stats. + HandleConn(context.Context, ConnStats) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go new file mode 100644 index 00000000..84f77daf --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stats/stats.go @@ -0,0 +1,295 @@ +/* + * + * Copyright 2016 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. + * + */ + +//go:generate protoc --go_out=plugins=grpc:. grpc_testing/test.proto + +// Package stats is for collecting and reporting various network and RPC stats. +// This package is for monitoring purpose only. All fields are read-only. +// All APIs are experimental. +package stats // import "google.golang.org/grpc/stats" + +import ( + "context" + "net" + "time" +) + +// RPCStats contains stats information about RPCs. +type RPCStats interface { + isRPCStats() + // IsClient returns true if this RPCStats is from client side. + IsClient() bool +} + +// Begin contains stats when an RPC begins. +// FailFast is only valid if this Begin is from client side. +type Begin struct { + // Client is true if this Begin is from client side. + Client bool + // BeginTime is the time when the RPC begins. + BeginTime time.Time + // FailFast indicates if this RPC is failfast. + FailFast bool +} + +// IsClient indicates if the stats information is from client side. +func (s *Begin) IsClient() bool { return s.Client } + +func (s *Begin) isRPCStats() {} + +// InPayload contains the information for an incoming payload. +type InPayload struct { + // Client is true if this InPayload is from client side. + Client bool + // Payload is the payload with original type. + Payload interface{} + // Data is the serialized message payload. + Data []byte + // Length is the length of uncompressed data. + Length int + // WireLength is the length of data on wire (compressed, signed, encrypted). + WireLength int + // RecvTime is the time when the payload is received. + RecvTime time.Time +} + +// IsClient indicates if the stats information is from client side. +func (s *InPayload) IsClient() bool { return s.Client } + +func (s *InPayload) isRPCStats() {} + +// InHeader contains stats when a header is received. +type InHeader struct { + // Client is true if this InHeader is from client side. + Client bool + // WireLength is the wire length of header. + WireLength int + + // The following fields are valid only if Client is false. + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr + // Compression is the compression algorithm used for the RPC. + Compression string +} + +// IsClient indicates if the stats information is from client side. +func (s *InHeader) IsClient() bool { return s.Client } + +func (s *InHeader) isRPCStats() {} + +// InTrailer contains stats when a trailer is received. +type InTrailer struct { + // Client is true if this InTrailer is from client side. + Client bool + // WireLength is the wire length of trailer. + WireLength int +} + +// IsClient indicates if the stats information is from client side. +func (s *InTrailer) IsClient() bool { return s.Client } + +func (s *InTrailer) isRPCStats() {} + +// OutPayload contains the information for an outgoing payload. +type OutPayload struct { + // Client is true if this OutPayload is from client side. + Client bool + // Payload is the payload with original type. + Payload interface{} + // Data is the serialized message payload. + Data []byte + // Length is the length of uncompressed data. + Length int + // WireLength is the length of data on wire (compressed, signed, encrypted). + WireLength int + // SentTime is the time when the payload is sent. + SentTime time.Time +} + +// IsClient indicates if this stats information is from client side. +func (s *OutPayload) IsClient() bool { return s.Client } + +func (s *OutPayload) isRPCStats() {} + +// OutHeader contains stats when a header is sent. +type OutHeader struct { + // Client is true if this OutHeader is from client side. + Client bool + + // The following fields are valid only if Client is true. + // FullMethod is the full RPC method string, i.e., /package.service/method. + FullMethod string + // RemoteAddr is the remote address of the corresponding connection. + RemoteAddr net.Addr + // LocalAddr is the local address of the corresponding connection. + LocalAddr net.Addr + // Compression is the compression algorithm used for the RPC. + Compression string +} + +// IsClient indicates if this stats information is from client side. +func (s *OutHeader) IsClient() bool { return s.Client } + +func (s *OutHeader) isRPCStats() {} + +// OutTrailer contains stats when a trailer is sent. +type OutTrailer struct { + // Client is true if this OutTrailer is from client side. + Client bool + // WireLength is the wire length of trailer. + WireLength int +} + +// IsClient indicates if this stats information is from client side. +func (s *OutTrailer) IsClient() bool { return s.Client } + +func (s *OutTrailer) isRPCStats() {} + +// End contains stats when an RPC ends. +type End struct { + // Client is true if this End is from client side. + Client bool + // BeginTime is the time when the RPC began. + BeginTime time.Time + // EndTime is the time when the RPC ends. + EndTime time.Time + // Error is the error the RPC ended with. It is an error generated from + // status.Status and can be converted back to status.Status using + // status.FromError if non-nil. + Error error +} + +// IsClient indicates if this is from client side. +func (s *End) IsClient() bool { return s.Client } + +func (s *End) isRPCStats() {} + +// ConnStats contains stats information about connections. +type ConnStats interface { + isConnStats() + // IsClient returns true if this ConnStats is from client side. + IsClient() bool +} + +// ConnBegin contains the stats of a connection when it is established. +type ConnBegin struct { + // Client is true if this ConnBegin is from client side. + Client bool +} + +// IsClient indicates if this is from client side. +func (s *ConnBegin) IsClient() bool { return s.Client } + +func (s *ConnBegin) isConnStats() {} + +// ConnEnd contains the stats of a connection when it ends. +type ConnEnd struct { + // Client is true if this ConnEnd is from client side. + Client bool +} + +// IsClient indicates if this is from client side. +func (s *ConnEnd) IsClient() bool { return s.Client } + +func (s *ConnEnd) isConnStats() {} + +type incomingTagsKey struct{} +type outgoingTagsKey struct{} + +// SetTags attaches stats tagging data to the context, which will be sent in +// the outgoing RPC with the header grpc-tags-bin. Subsequent calls to +// SetTags will overwrite the values from earlier calls. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func SetTags(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, outgoingTagsKey{}, b) +} + +// Tags returns the tags from the context for the inbound RPC. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func Tags(ctx context.Context) []byte { + b, _ := ctx.Value(incomingTagsKey{}).([]byte) + return b +} + +// SetIncomingTags attaches stats tagging data to the context, to be read by +// the application (not sent in outgoing RPCs). +// +// This is intended for gRPC-internal use ONLY. +func SetIncomingTags(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, incomingTagsKey{}, b) +} + +// OutgoingTags returns the tags from the context for the outbound RPC. +// +// This is intended for gRPC-internal use ONLY. +func OutgoingTags(ctx context.Context) []byte { + b, _ := ctx.Value(outgoingTagsKey{}).([]byte) + return b +} + +type incomingTraceKey struct{} +type outgoingTraceKey struct{} + +// SetTrace attaches stats tagging data to the context, which will be sent in +// the outgoing RPC with the header grpc-trace-bin. Subsequent calls to +// SetTrace will overwrite the values from earlier calls. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func SetTrace(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, outgoingTraceKey{}, b) +} + +// Trace returns the trace from the context for the inbound RPC. +// +// NOTE: this is provided only for backward compatibility with existing clients +// and will likely be removed in an upcoming release. New uses should transmit +// this type of data using metadata with a different, non-reserved (i.e. does +// not begin with "grpc-") header name. +func Trace(ctx context.Context) []byte { + b, _ := ctx.Value(incomingTraceKey{}).([]byte) + return b +} + +// SetIncomingTrace attaches stats tagging data to the context, to be read by +// the application (not sent in outgoing RPCs). It is intended for +// gRPC-internal use. +func SetIncomingTrace(ctx context.Context, b []byte) context.Context { + return context.WithValue(ctx, incomingTraceKey{}, b) +} + +// OutgoingTrace returns the trace from the context for the outbound RPC. It is +// intended for gRPC-internal use. +func OutgoingTrace(ctx context.Context) []byte { + b, _ := ctx.Value(outgoingTraceKey{}).([]byte) + return b +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go new file mode 100644 index 00000000..ed36681b --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/status/status.go @@ -0,0 +1,210 @@ +/* + * + * 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 status implements errors returned by gRPC. These errors are +// serialized and transmitted on the wire between server and client, and allow +// for additional data to be transmitted via the Details field in the status +// proto. gRPC service handlers should return an error created by this +// package, and gRPC clients should expect a corresponding error to be +// returned from the RPC call. +// +// This package upholds the invariants that a non-nil error may not +// contain an OK code, and an OK code must result in a nil error. +package status + +import ( + "context" + "errors" + "fmt" + + "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes" + spb "google.golang.org/genproto/googleapis/rpc/status" + "google.golang.org/grpc/codes" +) + +// statusError is an alias of a status proto. It implements error and Status, +// and a nil statusError should never be returned by this package. +type statusError spb.Status + +func (se *statusError) Error() string { + p := (*spb.Status)(se) + return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(p.GetCode()), p.GetMessage()) +} + +func (se *statusError) GRPCStatus() *Status { + return &Status{s: (*spb.Status)(se)} +} + +// Status represents an RPC status code, message, and details. It is immutable +// and should be created with New, Newf, or FromProto. +type Status struct { + s *spb.Status +} + +// Code returns the status code contained in s. +func (s *Status) Code() codes.Code { + if s == nil || s.s == nil { + return codes.OK + } + return codes.Code(s.s.Code) +} + +// Message returns the message contained in s. +func (s *Status) Message() string { + if s == nil || s.s == nil { + return "" + } + return s.s.Message +} + +// Proto returns s's status as an spb.Status proto message. +func (s *Status) Proto() *spb.Status { + if s == nil { + return nil + } + return proto.Clone(s.s).(*spb.Status) +} + +// Err returns an immutable error representing s; returns nil if s.Code() is +// OK. +func (s *Status) Err() error { + if s.Code() == codes.OK { + return nil + } + return (*statusError)(s.s) +} + +// New returns a Status representing c and msg. +func New(c codes.Code, msg string) *Status { + return &Status{s: &spb.Status{Code: int32(c), Message: msg}} +} + +// Newf returns New(c, fmt.Sprintf(format, a...)). +func Newf(c codes.Code, format string, a ...interface{}) *Status { + return New(c, fmt.Sprintf(format, a...)) +} + +// Error returns an error representing c and msg. If c is OK, returns nil. +func Error(c codes.Code, msg string) error { + return New(c, msg).Err() +} + +// Errorf returns Error(c, fmt.Sprintf(format, a...)). +func Errorf(c codes.Code, format string, a ...interface{}) error { + return Error(c, fmt.Sprintf(format, a...)) +} + +// ErrorProto returns an error representing s. If s.Code is OK, returns nil. +func ErrorProto(s *spb.Status) error { + return FromProto(s).Err() +} + +// FromProto returns a Status representing s. +func FromProto(s *spb.Status) *Status { + return &Status{s: proto.Clone(s).(*spb.Status)} +} + +// FromError returns a Status representing err if it was produced from this +// package or has a method `GRPCStatus() *Status`. Otherwise, ok is false and a +// Status is returned with codes.Unknown and the original error message. +func FromError(err error) (s *Status, ok bool) { + if err == nil { + return &Status{s: &spb.Status{Code: int32(codes.OK)}}, true + } + if se, ok := err.(interface { + GRPCStatus() *Status + }); ok { + return se.GRPCStatus(), true + } + return New(codes.Unknown, err.Error()), false +} + +// Convert is a convenience function which removes the need to handle the +// boolean return value from FromError. +func Convert(err error) *Status { + s, _ := FromError(err) + return s +} + +// WithDetails returns a new status with the provided details messages appended to the status. +// If any errors are encountered, it returns nil and the first error encountered. +func (s *Status) WithDetails(details ...proto.Message) (*Status, error) { + if s.Code() == codes.OK { + return nil, errors.New("no error details for status with code OK") + } + // s.Code() != OK implies that s.Proto() != nil. + p := s.Proto() + for _, detail := range details { + any, err := ptypes.MarshalAny(detail) + if err != nil { + return nil, err + } + p.Details = append(p.Details, any) + } + return &Status{s: p}, nil +} + +// Details returns a slice of details messages attached to the status. +// If a detail cannot be decoded, the error is returned in place of the detail. +func (s *Status) Details() []interface{} { + if s == nil || s.s == nil { + return nil + } + details := make([]interface{}, 0, len(s.s.Details)) + for _, any := range s.s.Details { + detail := &ptypes.DynamicAny{} + if err := ptypes.UnmarshalAny(any, detail); err != nil { + details = append(details, err) + continue + } + details = append(details, detail.Message) + } + return details +} + +// Code returns the Code of the error if it is a Status error, codes.OK if err +// is nil, or codes.Unknown otherwise. +func Code(err error) codes.Code { + // Don't use FromError to avoid allocation of OK status. + if err == nil { + return codes.OK + } + if se, ok := err.(interface { + GRPCStatus() *Status + }); ok { + return se.GRPCStatus().Code() + } + return codes.Unknown +} + +// FromContextError converts a context error into a Status. It returns a +// Status with codes.OK if err is nil, or a Status with codes.Unknown if err is +// non-nil and not a context error. +func FromContextError(err error) *Status { + switch err { + case nil: + return New(codes.OK, "") + case context.DeadlineExceeded: + return New(codes.DeadlineExceeded, err.Error()) + case context.Canceled: + return New(codes.Canceled, err.Error()) + default: + return New(codes.Unknown, err.Error()) + } +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go new file mode 100644 index 00000000..0c266d6f --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/stream.go @@ -0,0 +1,1489 @@ +/* + * + * Copyright 2014 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 grpc + +import ( + "context" + "errors" + "io" + "math" + "strconv" + "sync" + "time" + + "golang.org/x/net/trace" + "google.golang.org/grpc/balancer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/binarylog" + "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/internal/transport" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" +) + +// StreamHandler defines the handler called by gRPC server to complete the +// execution of a streaming RPC. If a StreamHandler returns an error, it +// should be produced by the status package, or else gRPC will use +// codes.Unknown as the status code and err.Error() as the status message +// of the RPC. +type StreamHandler func(srv interface{}, stream ServerStream) error + +// StreamDesc represents a streaming RPC service's method specification. +type StreamDesc struct { + StreamName string + Handler StreamHandler + + // At least one of these is true. + ServerStreams bool + ClientStreams bool +} + +// Stream defines the common interface a client or server stream has to satisfy. +// +// Deprecated: See ClientStream and ServerStream documentation instead. +type Stream interface { + // Deprecated: See ClientStream and ServerStream documentation instead. + Context() context.Context + // Deprecated: See ClientStream and ServerStream documentation instead. + SendMsg(m interface{}) error + // Deprecated: See ClientStream and ServerStream documentation instead. + RecvMsg(m interface{}) error +} + +// ClientStream defines the client-side behavior of a streaming RPC. +// +// All errors returned from ClientStream methods are compatible with the +// status package. +type ClientStream interface { + // Header returns the header metadata received from the server if there + // is any. It blocks if the metadata is not ready to read. + Header() (metadata.MD, error) + // Trailer returns the trailer metadata from the server, if there is any. + // It must only be called after stream.CloseAndRecv has returned, or + // stream.Recv has returned a non-nil error (including io.EOF). + Trailer() metadata.MD + // CloseSend closes the send direction of the stream. It closes the stream + // when non-nil error is met. It is also not safe to call CloseSend + // concurrently with SendMsg. + CloseSend() error + // Context returns the context for this stream. + // + // It should not be called until after Header or RecvMsg has returned. Once + // called, subsequent client-side retries are disabled. + Context() context.Context + // SendMsg is generally called by generated code. On error, SendMsg aborts + // the stream. If the error was generated by the client, the status is + // returned directly; otherwise, io.EOF is returned and the status of + // the stream may be discovered using RecvMsg. + // + // SendMsg blocks until: + // - There is sufficient flow control to schedule m with the transport, or + // - The stream is done, or + // - The stream breaks. + // + // SendMsg does not wait until the message is received by the server. An + // untimely stream closure may result in lost messages. To ensure delivery, + // users should ensure the RPC completed successfully using RecvMsg. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not safe + // to call SendMsg on the same stream in different goroutines. It is also + // not safe to call CloseSend concurrently with SendMsg. + SendMsg(m interface{}) error + // RecvMsg blocks until it receives a message into m or the stream is + // done. It returns io.EOF when the stream completes successfully. On + // any other error, the stream is aborted and the error contains the RPC + // status. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not + // safe to call RecvMsg on the same stream in different goroutines. + RecvMsg(m interface{}) error +} + +// NewStream creates a new Stream for the client side. This is typically +// called by generated code. ctx is used for the lifetime of the stream. +// +// To ensure resources are not leaked due to the stream returned, one of the following +// actions must be performed: +// +// 1. Call Close on the ClientConn. +// 2. Cancel the context provided. +// 3. Call RecvMsg until a non-nil error is returned. A protobuf-generated +// client-streaming RPC, for instance, might use the helper function +// CloseAndRecv (note that CloseSend does not Recv, therefore is not +// guaranteed to release all resources). +// 4. Receive a non-nil, non-io.EOF error from Header or SendMsg. +// +// If none of the above happen, a goroutine and a context will be leaked, and grpc +// will not call the optionally-configured stats handler with a stats.End message. +func (cc *ClientConn) NewStream(ctx context.Context, desc *StreamDesc, method string, opts ...CallOption) (ClientStream, error) { + // allow interceptor to see all applicable call options, which means those + // configured as defaults from dial option as well as per-call options + opts = combine(cc.dopts.callOptions, opts) + + if cc.dopts.streamInt != nil { + return cc.dopts.streamInt(ctx, desc, cc, method, newClientStream, opts...) + } + return newClientStream(ctx, desc, cc, method, opts...) +} + +// NewClientStream is a wrapper for ClientConn.NewStream. +func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) { + return cc.NewStream(ctx, desc, method, opts...) +} + +func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (_ ClientStream, err error) { + if channelz.IsOn() { + cc.incrCallsStarted() + defer func() { + if err != nil { + cc.incrCallsFailed() + } + }() + } + c := defaultCallInfo() + // Provide an opportunity for the first RPC to see the first service config + // provided by the resolver. + if err := cc.waitForResolvedAddrs(ctx); err != nil { + return nil, err + } + mc := cc.GetMethodConfig(method) + if mc.WaitForReady != nil { + c.failFast = !*mc.WaitForReady + } + + // Possible context leak: + // The cancel function for the child context we create will only be called + // when RecvMsg returns a non-nil error, if the ClientConn is closed, or if + // an error is generated by SendMsg. + // https://github.com/grpc/grpc-go/issues/1818. + var cancel context.CancelFunc + if mc.Timeout != nil && *mc.Timeout >= 0 { + ctx, cancel = context.WithTimeout(ctx, *mc.Timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer func() { + if err != nil { + cancel() + } + }() + + for _, o := range opts { + if err := o.before(c); err != nil { + return nil, toRPCErr(err) + } + } + c.maxSendMessageSize = getMaxSize(mc.MaxReqSize, c.maxSendMessageSize, defaultClientMaxSendMessageSize) + c.maxReceiveMessageSize = getMaxSize(mc.MaxRespSize, c.maxReceiveMessageSize, defaultClientMaxReceiveMessageSize) + if err := setCallInfoCodec(c); err != nil { + return nil, err + } + + callHdr := &transport.CallHdr{ + Host: cc.authority, + Method: method, + ContentSubtype: c.contentSubtype, + } + + // Set our outgoing compression according to the UseCompressor CallOption, if + // set. In that case, also find the compressor from the encoding package. + // Otherwise, use the compressor configured by the WithCompressor DialOption, + // if set. + var cp Compressor + var comp encoding.Compressor + if ct := c.compressorType; ct != "" { + callHdr.SendCompress = ct + if ct != encoding.Identity { + comp = encoding.GetCompressor(ct) + if comp == nil { + return nil, status.Errorf(codes.Internal, "grpc: Compressor is not installed for requested grpc-encoding %q", ct) + } + } + } else if cc.dopts.cp != nil { + callHdr.SendCompress = cc.dopts.cp.Type() + cp = cc.dopts.cp + } + if c.creds != nil { + callHdr.Creds = c.creds + } + var trInfo traceInfo + if EnableTracing { + trInfo.tr = trace.New("grpc.Sent."+methodFamily(method), method) + trInfo.firstLine.client = true + if deadline, ok := ctx.Deadline(); ok { + trInfo.firstLine.deadline = deadline.Sub(time.Now()) + } + trInfo.tr.LazyLog(&trInfo.firstLine, false) + ctx = trace.NewContext(ctx, trInfo.tr) + } + ctx = newContextWithRPCInfo(ctx, c.failFast) + sh := cc.dopts.copts.StatsHandler + var beginTime time.Time + if sh != nil { + ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{FullMethodName: method, FailFast: c.failFast}) + beginTime = time.Now() + begin := &stats.Begin{ + Client: true, + BeginTime: beginTime, + FailFast: c.failFast, + } + sh.HandleRPC(ctx, begin) + } + + cs := &clientStream{ + callHdr: callHdr, + ctx: ctx, + methodConfig: &mc, + opts: opts, + callInfo: c, + cc: cc, + desc: desc, + codec: c.codec, + cp: cp, + comp: comp, + cancel: cancel, + beginTime: beginTime, + firstAttempt: true, + } + if !cc.dopts.disableRetry { + cs.retryThrottler = cc.retryThrottler.Load().(*retryThrottler) + } + cs.binlog = binarylog.GetMethodLogger(method) + + cs.callInfo.stream = cs + // Only this initial attempt has stats/tracing. + // TODO(dfawley): move to newAttempt when per-attempt stats are implemented. + if err := cs.newAttemptLocked(sh, trInfo); err != nil { + cs.finish(err) + return nil, err + } + + op := func(a *csAttempt) error { return a.newStream() } + if err := cs.withRetry(op, func() { cs.bufferForRetryLocked(0, op) }); err != nil { + cs.finish(err) + return nil, err + } + + if cs.binlog != nil { + md, _ := metadata.FromOutgoingContext(ctx) + logEntry := &binarylog.ClientHeader{ + OnClientSide: true, + Header: md, + MethodName: method, + Authority: cs.cc.authority, + } + if deadline, ok := ctx.Deadline(); ok { + logEntry.Timeout = deadline.Sub(time.Now()) + if logEntry.Timeout < 0 { + logEntry.Timeout = 0 + } + } + cs.binlog.Log(logEntry) + } + + if desc != unaryStreamDesc { + // Listen on cc and stream contexts to cleanup when the user closes the + // ClientConn or cancels the stream context. In all other cases, an error + // should already be injected into the recv buffer by the transport, which + // the client will eventually receive, and then we will cancel the stream's + // context in clientStream.finish. + go func() { + select { + case <-cc.ctx.Done(): + cs.finish(ErrClientConnClosing) + case <-ctx.Done(): + cs.finish(toRPCErr(ctx.Err())) + } + }() + } + return cs, nil +} + +func (cs *clientStream) newAttemptLocked(sh stats.Handler, trInfo traceInfo) error { + cs.attempt = &csAttempt{ + cs: cs, + dc: cs.cc.dopts.dc, + statsHandler: sh, + trInfo: trInfo, + } + + if err := cs.ctx.Err(); err != nil { + return toRPCErr(err) + } + t, done, err := cs.cc.getTransport(cs.ctx, cs.callInfo.failFast, cs.callHdr.Method) + if err != nil { + return err + } + cs.attempt.t = t + cs.attempt.done = done + return nil +} + +func (a *csAttempt) newStream() error { + cs := a.cs + cs.callHdr.PreviousAttempts = cs.numRetries + s, err := a.t.NewStream(cs.ctx, cs.callHdr) + if err != nil { + return toRPCErr(err) + } + cs.attempt.s = s + cs.attempt.p = &parser{r: s} + return nil +} + +// clientStream implements a client side Stream. +type clientStream struct { + callHdr *transport.CallHdr + opts []CallOption + callInfo *callInfo + cc *ClientConn + desc *StreamDesc + + codec baseCodec + cp Compressor + comp encoding.Compressor + + cancel context.CancelFunc // cancels all attempts + + sentLast bool // sent an end stream + beginTime time.Time + + methodConfig *MethodConfig + + ctx context.Context // the application's context, wrapped by stats/tracing + + retryThrottler *retryThrottler // The throttler active when the RPC began. + + binlog *binarylog.MethodLogger // Binary logger, can be nil. + // serverHeaderBinlogged is a boolean for whether server header has been + // logged. Server header will be logged when the first time one of those + // happens: stream.Header(), stream.Recv(). + // + // It's only read and used by Recv() and Header(), so it doesn't need to be + // synchronized. + serverHeaderBinlogged bool + + mu sync.Mutex + firstAttempt bool // if true, transparent retry is valid + numRetries int // exclusive of transparent retry attempt(s) + numRetriesSincePushback int // retries since pushback; to reset backoff + finished bool // TODO: replace with atomic cmpxchg or sync.Once? + attempt *csAttempt // the active client stream attempt + // TODO(hedging): hedging will have multiple attempts simultaneously. + committed bool // active attempt committed for retry? + buffer []func(a *csAttempt) error // operations to replay on retry + bufferSize int // current size of buffer +} + +// csAttempt implements a single transport stream attempt within a +// clientStream. +type csAttempt struct { + cs *clientStream + t transport.ClientTransport + s *transport.Stream + p *parser + done func(balancer.DoneInfo) + + finished bool + dc Decompressor + decomp encoding.Compressor + decompSet bool + + mu sync.Mutex // guards trInfo.tr + // trInfo.tr is set when created (if EnableTracing is true), + // and cleared when the finish method is called. + trInfo traceInfo + + statsHandler stats.Handler +} + +func (cs *clientStream) commitAttemptLocked() { + cs.committed = true + cs.buffer = nil +} + +func (cs *clientStream) commitAttempt() { + cs.mu.Lock() + cs.commitAttemptLocked() + cs.mu.Unlock() +} + +// shouldRetry returns nil if the RPC should be retried; otherwise it returns +// the error that should be returned by the operation. +func (cs *clientStream) shouldRetry(err error) error { + if cs.attempt.s == nil && !cs.callInfo.failFast { + // In the event of any error from NewStream (attempt.s == nil), we + // never attempted to write anything to the wire, so we can retry + // indefinitely for non-fail-fast RPCs. + return nil + } + if cs.finished || cs.committed { + // RPC is finished or committed; cannot retry. + return err + } + // Wait for the trailers. + if cs.attempt.s != nil { + <-cs.attempt.s.Done() + } + if cs.firstAttempt && !cs.callInfo.failFast && (cs.attempt.s == nil || cs.attempt.s.Unprocessed()) { + // First attempt, wait-for-ready, stream unprocessed: transparently retry. + cs.firstAttempt = false + return nil + } + cs.firstAttempt = false + if cs.cc.dopts.disableRetry { + return err + } + + pushback := 0 + hasPushback := false + if cs.attempt.s != nil { + if to, toErr := cs.attempt.s.TrailersOnly(); toErr != nil { + // Context error; stop now. + return toErr + } else if !to { + return err + } + + // TODO(retry): Move down if the spec changes to not check server pushback + // before considering this a failure for throttling. + sps := cs.attempt.s.Trailer()["grpc-retry-pushback-ms"] + if len(sps) == 1 { + var e error + if pushback, e = strconv.Atoi(sps[0]); e != nil || pushback < 0 { + grpclog.Infof("Server retry pushback specified to abort (%q).", sps[0]) + cs.retryThrottler.throttle() // This counts as a failure for throttling. + return err + } + hasPushback = true + } else if len(sps) > 1 { + grpclog.Warningf("Server retry pushback specified multiple values (%q); not retrying.", sps) + cs.retryThrottler.throttle() // This counts as a failure for throttling. + return err + } + } + + var code codes.Code + if cs.attempt.s != nil { + code = cs.attempt.s.Status().Code() + } else { + code = status.Convert(err).Code() + } + + rp := cs.methodConfig.retryPolicy + if rp == nil || !rp.retryableStatusCodes[code] { + return err + } + + // Note: the ordering here is important; we count this as a failure + // only if the code matched a retryable code. + if cs.retryThrottler.throttle() { + return err + } + if cs.numRetries+1 >= rp.maxAttempts { + return err + } + + var dur time.Duration + if hasPushback { + dur = time.Millisecond * time.Duration(pushback) + cs.numRetriesSincePushback = 0 + } else { + fact := math.Pow(rp.backoffMultiplier, float64(cs.numRetriesSincePushback)) + cur := float64(rp.initialBackoff) * fact + if max := float64(rp.maxBackoff); cur > max { + cur = max + } + dur = time.Duration(grpcrand.Int63n(int64(cur))) + cs.numRetriesSincePushback++ + } + + // TODO(dfawley): we could eagerly fail here if dur puts us past the + // deadline, but unsure if it is worth doing. + t := time.NewTimer(dur) + select { + case <-t.C: + cs.numRetries++ + return nil + case <-cs.ctx.Done(): + t.Stop() + return status.FromContextError(cs.ctx.Err()).Err() + } +} + +// Returns nil if a retry was performed and succeeded; error otherwise. +func (cs *clientStream) retryLocked(lastErr error) error { + for { + cs.attempt.finish(lastErr) + if err := cs.shouldRetry(lastErr); err != nil { + cs.commitAttemptLocked() + return err + } + if err := cs.newAttemptLocked(nil, traceInfo{}); err != nil { + return err + } + if lastErr = cs.replayBufferLocked(); lastErr == nil { + return nil + } + } +} + +func (cs *clientStream) Context() context.Context { + cs.commitAttempt() + // No need to lock before using attempt, since we know it is committed and + // cannot change. + return cs.attempt.s.Context() +} + +func (cs *clientStream) withRetry(op func(a *csAttempt) error, onSuccess func()) error { + cs.mu.Lock() + for { + if cs.committed { + cs.mu.Unlock() + return op(cs.attempt) + } + a := cs.attempt + cs.mu.Unlock() + err := op(a) + cs.mu.Lock() + if a != cs.attempt { + // We started another attempt already. + continue + } + if err == io.EOF { + <-a.s.Done() + } + if err == nil || (err == io.EOF && a.s.Status().Code() == codes.OK) { + onSuccess() + cs.mu.Unlock() + return err + } + if err := cs.retryLocked(err); err != nil { + cs.mu.Unlock() + return err + } + } +} + +func (cs *clientStream) Header() (metadata.MD, error) { + var m metadata.MD + err := cs.withRetry(func(a *csAttempt) error { + var err error + m, err = a.s.Header() + return toRPCErr(err) + }, cs.commitAttemptLocked) + if err != nil { + cs.finish(err) + return nil, err + } + if cs.binlog != nil && !cs.serverHeaderBinlogged { + // Only log if binary log is on and header has not been logged. + logEntry := &binarylog.ServerHeader{ + OnClientSide: true, + Header: m, + PeerAddr: nil, + } + if peer, ok := peer.FromContext(cs.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + cs.binlog.Log(logEntry) + cs.serverHeaderBinlogged = true + } + return m, err +} + +func (cs *clientStream) Trailer() metadata.MD { + // On RPC failure, we never need to retry, because usage requires that + // RecvMsg() returned a non-nil error before calling this function is valid. + // We would have retried earlier if necessary. + // + // Commit the attempt anyway, just in case users are not following those + // directions -- it will prevent races and should not meaningfully impact + // performance. + cs.commitAttempt() + if cs.attempt.s == nil { + return nil + } + return cs.attempt.s.Trailer() +} + +func (cs *clientStream) replayBufferLocked() error { + a := cs.attempt + for _, f := range cs.buffer { + if err := f(a); err != nil { + return err + } + } + return nil +} + +func (cs *clientStream) bufferForRetryLocked(sz int, op func(a *csAttempt) error) { + // Note: we still will buffer if retry is disabled (for transparent retries). + if cs.committed { + return + } + cs.bufferSize += sz + if cs.bufferSize > cs.callInfo.maxRetryRPCBufferSize { + cs.commitAttemptLocked() + return + } + cs.buffer = append(cs.buffer, op) +} + +func (cs *clientStream) SendMsg(m interface{}) (err error) { + defer func() { + if err != nil && err != io.EOF { + // Call finish on the client stream for errors generated by this SendMsg + // call, as these indicate problems created by this client. (Transport + // errors are converted to an io.EOF error in csAttempt.sendMsg; the real + // error will be returned from RecvMsg eventually in that case, or be + // retried.) + cs.finish(err) + } + }() + if cs.sentLast { + return status.Errorf(codes.Internal, "SendMsg called after CloseSend") + } + if !cs.desc.ClientStreams { + cs.sentLast = true + } + data, err := encode(cs.codec, m) + if err != nil { + return err + } + compData, err := compress(data, cs.cp, cs.comp) + if err != nil { + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > *cs.callInfo.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payload), *cs.callInfo.maxSendMessageSize) + } + msgBytes := data // Store the pointer before setting to nil. For binary logging. + op := func(a *csAttempt) error { + err := a.sendMsg(m, hdr, payload, data) + // nil out the message and uncomp when replaying; they are only needed for + // stats which is disabled for subsequent attempts. + m, data = nil, nil + return err + } + err = cs.withRetry(op, func() { cs.bufferForRetryLocked(len(hdr)+len(payload), op) }) + if cs.binlog != nil && err == nil { + cs.binlog.Log(&binarylog.ClientMessage{ + OnClientSide: true, + Message: msgBytes, + }) + } + return +} + +func (cs *clientStream) RecvMsg(m interface{}) error { + if cs.binlog != nil && !cs.serverHeaderBinlogged { + // Call Header() to binary log header if it's not already logged. + cs.Header() + } + var recvInfo *payloadInfo + if cs.binlog != nil { + recvInfo = &payloadInfo{} + } + err := cs.withRetry(func(a *csAttempt) error { + return a.recvMsg(m, recvInfo) + }, cs.commitAttemptLocked) + if cs.binlog != nil && err == nil { + cs.binlog.Log(&binarylog.ServerMessage{ + OnClientSide: true, + Message: recvInfo.uncompressedBytes, + }) + } + if err != nil || !cs.desc.ServerStreams { + // err != nil or non-server-streaming indicates end of stream. + cs.finish(err) + + if cs.binlog != nil { + // finish will not log Trailer. Log Trailer here. + logEntry := &binarylog.ServerTrailer{ + OnClientSide: true, + Trailer: cs.Trailer(), + Err: err, + } + if logEntry.Err == io.EOF { + logEntry.Err = nil + } + if peer, ok := peer.FromContext(cs.Context()); ok { + logEntry.PeerAddr = peer.Addr + } + cs.binlog.Log(logEntry) + } + } + return err +} + +func (cs *clientStream) CloseSend() error { + if cs.sentLast { + // TODO: return an error and finish the stream instead, due to API misuse? + return nil + } + cs.sentLast = true + op := func(a *csAttempt) error { + a.t.Write(a.s, nil, nil, &transport.Options{Last: true}) + // Always return nil; io.EOF is the only error that might make sense + // instead, but there is no need to signal the client to call RecvMsg + // as the only use left for the stream after CloseSend is to call + // RecvMsg. This also matches historical behavior. + return nil + } + cs.withRetry(op, func() { cs.bufferForRetryLocked(0, op) }) + if cs.binlog != nil { + cs.binlog.Log(&binarylog.ClientHalfClose{ + OnClientSide: true, + }) + } + // We never returned an error here for reasons. + return nil +} + +func (cs *clientStream) finish(err error) { + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + cs.mu.Lock() + if cs.finished { + cs.mu.Unlock() + return + } + cs.finished = true + cs.commitAttemptLocked() + cs.mu.Unlock() + // For binary logging. only log cancel in finish (could be caused by RPC ctx + // canceled or ClientConn closed). Trailer will be logged in RecvMsg. + // + // Only one of cancel or trailer needs to be logged. In the cases where + // users don't call RecvMsg, users must have already canceled the RPC. + if cs.binlog != nil && status.Code(err) == codes.Canceled { + cs.binlog.Log(&binarylog.Cancel{ + OnClientSide: true, + }) + } + if err == nil { + cs.retryThrottler.successfulRPC() + } + if channelz.IsOn() { + if err != nil { + cs.cc.incrCallsFailed() + } else { + cs.cc.incrCallsSucceeded() + } + } + if cs.attempt != nil { + cs.attempt.finish(err) + } + // after functions all rely upon having a stream. + if cs.attempt.s != nil { + for _, o := range cs.opts { + o.after(cs.callInfo) + } + } + cs.cancel() +} + +func (a *csAttempt) sendMsg(m interface{}, hdr, payld, data []byte) error { + cs := a.cs + if EnableTracing { + a.mu.Lock() + if a.trInfo.tr != nil { + a.trInfo.tr.LazyLog(&payload{sent: true, msg: m}, true) + } + a.mu.Unlock() + } + if err := a.t.Write(a.s, hdr, payld, &transport.Options{Last: !cs.desc.ClientStreams}); err != nil { + if !cs.desc.ClientStreams { + // For non-client-streaming RPCs, we return nil instead of EOF on error + // because the generated code requires it. finish is not called; RecvMsg() + // will call it with the stream's status independently. + return nil + } + return io.EOF + } + if a.statsHandler != nil { + a.statsHandler.HandleRPC(cs.ctx, outPayload(true, m, data, payld, time.Now())) + } + if channelz.IsOn() { + a.t.IncrMsgSent() + } + return nil +} + +func (a *csAttempt) recvMsg(m interface{}, payInfo *payloadInfo) (err error) { + cs := a.cs + if a.statsHandler != nil && payInfo == nil { + payInfo = &payloadInfo{} + } + + if !a.decompSet { + // Block until we receive headers containing received message encoding. + if ct := a.s.RecvCompress(); ct != "" && ct != encoding.Identity { + if a.dc == nil || a.dc.Type() != ct { + // No configured decompressor, or it does not match the incoming + // message encoding; attempt to find a registered compressor that does. + a.dc = nil + a.decomp = encoding.GetCompressor(ct) + } + } else { + // No compression is used; disable our decompressor. + a.dc = nil + } + // Only initialize this state once per stream. + a.decompSet = true + } + err = recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, payInfo, a.decomp) + if err != nil { + if err == io.EOF { + if statusErr := a.s.Status().Err(); statusErr != nil { + return statusErr + } + return io.EOF // indicates successful end of stream. + } + return toRPCErr(err) + } + if EnableTracing { + a.mu.Lock() + if a.trInfo.tr != nil { + a.trInfo.tr.LazyLog(&payload{sent: false, msg: m}, true) + } + a.mu.Unlock() + } + if a.statsHandler != nil { + a.statsHandler.HandleRPC(cs.ctx, &stats.InPayload{ + Client: true, + RecvTime: time.Now(), + Payload: m, + // TODO truncate large payload. + Data: payInfo.uncompressedBytes, + Length: len(payInfo.uncompressedBytes), + }) + } + if channelz.IsOn() { + a.t.IncrMsgRecv() + } + if cs.desc.ServerStreams { + // Subsequent messages should be received by subsequent RecvMsg calls. + return nil + } + // Special handling for non-server-stream rpcs. + // This recv expects EOF or errors, so we don't collect inPayload. + err = recv(a.p, cs.codec, a.s, a.dc, m, *cs.callInfo.maxReceiveMessageSize, nil, a.decomp) + if err == nil { + return toRPCErr(errors.New("grpc: client streaming protocol violation: get , want ")) + } + if err == io.EOF { + return a.s.Status().Err() // non-server streaming Recv returns nil on success + } + return toRPCErr(err) +} + +func (a *csAttempt) finish(err error) { + a.mu.Lock() + if a.finished { + a.mu.Unlock() + return + } + a.finished = true + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + if a.s != nil { + a.t.CloseStream(a.s, err) + } + + if a.done != nil { + br := false + var tr metadata.MD + if a.s != nil { + br = a.s.BytesReceived() + tr = a.s.Trailer() + } + a.done(balancer.DoneInfo{ + Err: err, + Trailer: tr, + BytesSent: a.s != nil, + BytesReceived: br, + }) + } + if a.statsHandler != nil { + end := &stats.End{ + Client: true, + BeginTime: a.cs.beginTime, + EndTime: time.Now(), + Error: err, + } + a.statsHandler.HandleRPC(a.cs.ctx, end) + } + if a.trInfo.tr != nil { + if err == nil { + a.trInfo.tr.LazyPrintf("RPC: [OK]") + } else { + a.trInfo.tr.LazyPrintf("RPC: [%v]", err) + a.trInfo.tr.SetError() + } + a.trInfo.tr.Finish() + a.trInfo.tr = nil + } + a.mu.Unlock() +} + +func (ac *addrConn) newClientStream(ctx context.Context, desc *StreamDesc, method string, t transport.ClientTransport, opts ...CallOption) (_ ClientStream, err error) { + ac.mu.Lock() + if ac.transport != t { + ac.mu.Unlock() + return nil, status.Error(codes.Canceled, "the provided transport is no longer valid to use") + } + // transition to CONNECTING state when an attempt starts + if ac.state != connectivity.Connecting { + ac.updateConnectivityState(connectivity.Connecting) + ac.cc.handleSubConnStateChange(ac.acbw, ac.state) + } + ac.mu.Unlock() + + if t == nil { + // TODO: return RPC error here? + return nil, errors.New("transport provided is nil") + } + // defaultCallInfo contains unnecessary info(i.e. failfast, maxRetryRPCBufferSize), so we just initialize an empty struct. + c := &callInfo{} + + for _, o := range opts { + if err := o.before(c); err != nil { + return nil, toRPCErr(err) + } + } + c.maxReceiveMessageSize = getMaxSize(nil, c.maxReceiveMessageSize, defaultClientMaxReceiveMessageSize) + c.maxSendMessageSize = getMaxSize(nil, c.maxSendMessageSize, defaultServerMaxSendMessageSize) + + // Possible context leak: + // The cancel function for the child context we create will only be called + // when RecvMsg returns a non-nil error, if the ClientConn is closed, or if + // an error is generated by SendMsg. + // https://github.com/grpc/grpc-go/issues/1818. + ctx, cancel := context.WithCancel(ctx) + defer func() { + if err != nil { + cancel() + } + }() + + if err := setCallInfoCodec(c); err != nil { + return nil, err + } + + callHdr := &transport.CallHdr{ + Host: ac.cc.authority, + Method: method, + ContentSubtype: c.contentSubtype, + } + + // Set our outgoing compression according to the UseCompressor CallOption, if + // set. In that case, also find the compressor from the encoding package. + // Otherwise, use the compressor configured by the WithCompressor DialOption, + // if set. + var cp Compressor + var comp encoding.Compressor + if ct := c.compressorType; ct != "" { + callHdr.SendCompress = ct + if ct != encoding.Identity { + comp = encoding.GetCompressor(ct) + if comp == nil { + return nil, status.Errorf(codes.Internal, "grpc: Compressor is not installed for requested grpc-encoding %q", ct) + } + } + } else if ac.cc.dopts.cp != nil { + callHdr.SendCompress = ac.cc.dopts.cp.Type() + cp = ac.cc.dopts.cp + } + if c.creds != nil { + callHdr.Creds = c.creds + } + + as := &addrConnStream{ + callHdr: callHdr, + ac: ac, + ctx: ctx, + cancel: cancel, + opts: opts, + callInfo: c, + desc: desc, + codec: c.codec, + cp: cp, + comp: comp, + t: t, + } + + as.callInfo.stream = as + s, err := as.t.NewStream(as.ctx, as.callHdr) + if err != nil { + err = toRPCErr(err) + return nil, err + } + as.s = s + as.p = &parser{r: s} + ac.incrCallsStarted() + if desc != unaryStreamDesc { + // Listen on cc and stream contexts to cleanup when the user closes the + // ClientConn or cancels the stream context. In all other cases, an error + // should already be injected into the recv buffer by the transport, which + // the client will eventually receive, and then we will cancel the stream's + // context in clientStream.finish. + go func() { + select { + case <-ac.ctx.Done(): + as.finish(status.Error(codes.Canceled, "grpc: the SubConn is closing")) + case <-ctx.Done(): + as.finish(toRPCErr(ctx.Err())) + } + }() + } + return as, nil +} + +type addrConnStream struct { + s *transport.Stream + ac *addrConn + callHdr *transport.CallHdr + cancel context.CancelFunc + opts []CallOption + callInfo *callInfo + t transport.ClientTransport + ctx context.Context + sentLast bool + desc *StreamDesc + codec baseCodec + cp Compressor + comp encoding.Compressor + decompSet bool + dc Decompressor + decomp encoding.Compressor + p *parser + done func(balancer.DoneInfo) + mu sync.Mutex + finished bool +} + +func (as *addrConnStream) Header() (metadata.MD, error) { + m, err := as.s.Header() + if err != nil { + as.finish(toRPCErr(err)) + } + return m, err +} + +func (as *addrConnStream) Trailer() metadata.MD { + return as.s.Trailer() +} + +func (as *addrConnStream) CloseSend() error { + if as.sentLast { + // TODO: return an error and finish the stream instead, due to API misuse? + return nil + } + as.sentLast = true + + as.t.Write(as.s, nil, nil, &transport.Options{Last: true}) + // Always return nil; io.EOF is the only error that might make sense + // instead, but there is no need to signal the client to call RecvMsg + // as the only use left for the stream after CloseSend is to call + // RecvMsg. This also matches historical behavior. + return nil +} + +func (as *addrConnStream) Context() context.Context { + return as.s.Context() +} + +func (as *addrConnStream) SendMsg(m interface{}) (err error) { + defer func() { + if err != nil && err != io.EOF { + // Call finish on the client stream for errors generated by this SendMsg + // call, as these indicate problems created by this client. (Transport + // errors are converted to an io.EOF error in csAttempt.sendMsg; the real + // error will be returned from RecvMsg eventually in that case, or be + // retried.) + as.finish(err) + } + }() + if as.sentLast { + return status.Errorf(codes.Internal, "SendMsg called after CloseSend") + } + if !as.desc.ClientStreams { + as.sentLast = true + } + data, err := encode(as.codec, m) + if err != nil { + return err + } + compData, err := compress(data, as.cp, as.comp) + if err != nil { + return err + } + hdr, payld := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payld) > *as.callInfo.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payld), *as.callInfo.maxSendMessageSize) + } + + if err := as.t.Write(as.s, hdr, payld, &transport.Options{Last: !as.desc.ClientStreams}); err != nil { + if !as.desc.ClientStreams { + // For non-client-streaming RPCs, we return nil instead of EOF on error + // because the generated code requires it. finish is not called; RecvMsg() + // will call it with the stream's status independently. + return nil + } + return io.EOF + } + + if channelz.IsOn() { + as.t.IncrMsgSent() + } + return nil +} + +func (as *addrConnStream) RecvMsg(m interface{}) (err error) { + defer func() { + if err != nil || !as.desc.ServerStreams { + // err != nil or non-server-streaming indicates end of stream. + as.finish(err) + } + }() + + if !as.decompSet { + // Block until we receive headers containing received message encoding. + if ct := as.s.RecvCompress(); ct != "" && ct != encoding.Identity { + if as.dc == nil || as.dc.Type() != ct { + // No configured decompressor, or it does not match the incoming + // message encoding; attempt to find a registered compressor that does. + as.dc = nil + as.decomp = encoding.GetCompressor(ct) + } + } else { + // No compression is used; disable our decompressor. + as.dc = nil + } + // Only initialize this state once per stream. + as.decompSet = true + } + err = recv(as.p, as.codec, as.s, as.dc, m, *as.callInfo.maxReceiveMessageSize, nil, as.decomp) + if err != nil { + if err == io.EOF { + if statusErr := as.s.Status().Err(); statusErr != nil { + return statusErr + } + return io.EOF // indicates successful end of stream. + } + return toRPCErr(err) + } + + if channelz.IsOn() { + as.t.IncrMsgRecv() + } + if as.desc.ServerStreams { + // Subsequent messages should be received by subsequent RecvMsg calls. + return nil + } + + // Special handling for non-server-stream rpcs. + // This recv expects EOF or errors, so we don't collect inPayload. + err = recv(as.p, as.codec, as.s, as.dc, m, *as.callInfo.maxReceiveMessageSize, nil, as.decomp) + if err == nil { + return toRPCErr(errors.New("grpc: client streaming protocol violation: get , want ")) + } + if err == io.EOF { + return as.s.Status().Err() // non-server streaming Recv returns nil on success + } + return toRPCErr(err) +} + +func (as *addrConnStream) finish(err error) { + as.mu.Lock() + if as.finished { + as.mu.Unlock() + return + } + as.finished = true + if err == io.EOF { + // Ending a stream with EOF indicates a success. + err = nil + } + if as.s != nil { + as.t.CloseStream(as.s, err) + } + + if err != nil { + as.ac.incrCallsFailed() + } else { + as.ac.incrCallsSucceeded() + } + as.cancel() + as.mu.Unlock() +} + +// ServerStream defines the server-side behavior of a streaming RPC. +// +// All errors returned from ServerStream methods are compatible with the +// status package. +type ServerStream interface { + // SetHeader sets the header metadata. It may be called multiple times. + // When call multiple times, all the provided metadata will be merged. + // All the metadata will be sent out when one of the following happens: + // - ServerStream.SendHeader() is called; + // - The first response is sent out; + // - An RPC status is sent out (error or success). + SetHeader(metadata.MD) error + // SendHeader sends the header metadata. + // The provided md and headers set by SetHeader() will be sent. + // It fails if called multiple times. + SendHeader(metadata.MD) error + // SetTrailer sets the trailer metadata which will be sent with the RPC status. + // When called more than once, all the provided metadata will be merged. + SetTrailer(metadata.MD) + // Context returns the context for this stream. + Context() context.Context + // SendMsg sends a message. On error, SendMsg aborts the stream and the + // error is returned directly. + // + // SendMsg blocks until: + // - There is sufficient flow control to schedule m with the transport, or + // - The stream is done, or + // - The stream breaks. + // + // SendMsg does not wait until the message is received by the client. An + // untimely stream closure may result in lost messages. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not safe + // to call SendMsg on the same stream in different goroutines. + SendMsg(m interface{}) error + // RecvMsg blocks until it receives a message into m or the stream is + // done. It returns io.EOF when the client has performed a CloseSend. On + // any non-EOF error, the stream is aborted and the error contains the + // RPC status. + // + // It is safe to have a goroutine calling SendMsg and another goroutine + // calling RecvMsg on the same stream at the same time, but it is not + // safe to call RecvMsg on the same stream in different goroutines. + RecvMsg(m interface{}) error +} + +// serverStream implements a server side Stream. +type serverStream struct { + ctx context.Context + t transport.ServerTransport + s *transport.Stream + p *parser + codec baseCodec + + cp Compressor + dc Decompressor + comp encoding.Compressor + decomp encoding.Compressor + + maxReceiveMessageSize int + maxSendMessageSize int + trInfo *traceInfo + + statsHandler stats.Handler + + binlog *binarylog.MethodLogger + // serverHeaderBinlogged indicates whether server header has been logged. It + // will happen when one of the following two happens: stream.SendHeader(), + // stream.Send(). + // + // It's only checked in send and sendHeader, doesn't need to be + // synchronized. + serverHeaderBinlogged bool + + mu sync.Mutex // protects trInfo.tr after the service handler runs. +} + +func (ss *serverStream) Context() context.Context { + return ss.ctx +} + +func (ss *serverStream) SetHeader(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + return ss.s.SetHeader(md) +} + +func (ss *serverStream) SendHeader(md metadata.MD) error { + err := ss.t.WriteHeader(ss.s, md) + if ss.binlog != nil && !ss.serverHeaderBinlogged { + h, _ := ss.s.Header() + ss.binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + ss.serverHeaderBinlogged = true + } + return err +} + +func (ss *serverStream) SetTrailer(md metadata.MD) { + if md.Len() == 0 { + return + } + ss.s.SetTrailer(md) +} + +func (ss *serverStream) SendMsg(m interface{}) (err error) { + defer func() { + if ss.trInfo != nil { + ss.mu.Lock() + if ss.trInfo.tr != nil { + if err == nil { + ss.trInfo.tr.LazyLog(&payload{sent: true, msg: m}, true) + } else { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + } + ss.mu.Unlock() + } + if err != nil && err != io.EOF { + st, _ := status.FromError(toRPCErr(err)) + ss.t.WriteStatus(ss.s, st) + // Non-user specified status was sent out. This should be an error + // case (as a server side Cancel maybe). + // + // This is not handled specifically now. User will return a final + // status from the service handler, we will log that error instead. + // This behavior is similar to an interceptor. + } + if channelz.IsOn() && err == nil { + ss.t.IncrMsgSent() + } + }() + data, err := encode(ss.codec, m) + if err != nil { + return err + } + compData, err := compress(data, ss.cp, ss.comp) + if err != nil { + return err + } + hdr, payload := msgHeader(data, compData) + // TODO(dfawley): should we be checking len(data) instead? + if len(payload) > ss.maxSendMessageSize { + return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(payload), ss.maxSendMessageSize) + } + if err := ss.t.Write(ss.s, hdr, payload, &transport.Options{Last: false}); err != nil { + return toRPCErr(err) + } + if ss.binlog != nil { + if !ss.serverHeaderBinlogged { + h, _ := ss.s.Header() + ss.binlog.Log(&binarylog.ServerHeader{ + Header: h, + }) + ss.serverHeaderBinlogged = true + } + ss.binlog.Log(&binarylog.ServerMessage{ + Message: data, + }) + } + if ss.statsHandler != nil { + ss.statsHandler.HandleRPC(ss.s.Context(), outPayload(false, m, data, payload, time.Now())) + } + return nil +} + +func (ss *serverStream) RecvMsg(m interface{}) (err error) { + defer func() { + if ss.trInfo != nil { + ss.mu.Lock() + if ss.trInfo.tr != nil { + if err == nil { + ss.trInfo.tr.LazyLog(&payload{sent: false, msg: m}, true) + } else if err != io.EOF { + ss.trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true) + ss.trInfo.tr.SetError() + } + } + ss.mu.Unlock() + } + if err != nil && err != io.EOF { + st, _ := status.FromError(toRPCErr(err)) + ss.t.WriteStatus(ss.s, st) + // Non-user specified status was sent out. This should be an error + // case (as a server side Cancel maybe). + // + // This is not handled specifically now. User will return a final + // status from the service handler, we will log that error instead. + // This behavior is similar to an interceptor. + } + if channelz.IsOn() && err == nil { + ss.t.IncrMsgRecv() + } + }() + var payInfo *payloadInfo + if ss.statsHandler != nil || ss.binlog != nil { + payInfo = &payloadInfo{} + } + if err := recv(ss.p, ss.codec, ss.s, ss.dc, m, ss.maxReceiveMessageSize, payInfo, ss.decomp); err != nil { + if err == io.EOF { + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ClientHalfClose{}) + } + return err + } + if err == io.ErrUnexpectedEOF { + err = status.Errorf(codes.Internal, io.ErrUnexpectedEOF.Error()) + } + return toRPCErr(err) + } + if ss.statsHandler != nil { + ss.statsHandler.HandleRPC(ss.s.Context(), &stats.InPayload{ + RecvTime: time.Now(), + Payload: m, + // TODO truncate large payload. + Data: payInfo.uncompressedBytes, + Length: len(payInfo.uncompressedBytes), + }) + } + if ss.binlog != nil { + ss.binlog.Log(&binarylog.ClientMessage{ + Message: payInfo.uncompressedBytes, + }) + } + return nil +} + +// MethodFromServerStream returns the method string for the input stream. +// The returned string is in the format of "/service/method". +func MethodFromServerStream(stream ServerStream) (string, bool) { + return Method(stream.Context()) +} diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go new file mode 100644 index 00000000..584360f6 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/tap/tap.go @@ -0,0 +1,51 @@ +/* + * + * Copyright 2016 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 tap defines the function handles which are executed on the transport +// layer of gRPC-Go and related information. Everything here is EXPERIMENTAL. +package tap + +import ( + "context" +) + +// Info defines the relevant information needed by the handles. +type Info struct { + // FullMethodName is the string of grpc method (in the format of + // /package.service/method). + FullMethodName string + // TODO: More to be added. +} + +// ServerInHandle defines the function which runs before a new stream is created +// on the server side. If it returns a non-nil error, the stream will not be +// created and a RST_STREAM will be sent back to the client with REFUSED_STREAM. +// The client will receive an RPC error "code = Unavailable, desc = stream +// terminated by RST_STREAM with error code: REFUSED_STREAM". +// +// It's intended to be used in situations where you don't want to waste the +// resources to accept the new stream (e.g. rate-limiting). And the content of +// the error will be ignored and won't be sent back to the client. For other +// general usages, please use interceptors. +// +// Note that it is executed in the per-connection I/O goroutine(s) instead of +// per-RPC goroutine. Therefore, users should NOT have any +// blocking/time-consuming work in this handle. Otherwise all the RPCs would +// slow down. Also, for the same reason, this handle won't be called +// concurrently by gRPC. +type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/trace.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/trace.go similarity index 100% rename from functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/github.com/v3io/frames/vendor/google.golang.org/grpc/trace.go rename to functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/trace.go diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go new file mode 100644 index 00000000..260f27c8 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/version.go @@ -0,0 +1,22 @@ +/* + * + * 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 grpc + +// Version is the current grpc version. +const Version = "1.17.0" diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh new file mode 100644 index 00000000..94d3d54e --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/google.golang.org/grpc/vet.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +if [[ `uname -a` = *"Darwin"* ]]; then + echo "It seems you are running on Mac. This script does not work on Mac. See https://github.com/grpc/grpc-go/issues/2047" + exit 1 +fi + +set -ex # Exit on error; debugging enabled. +set -o pipefail # Fail a pipe if any sub-command fails. + +die() { + echo "$@" >&2 + exit 1 +} + +# Check to make sure it's safe to modify the user's git repo. +if git status --porcelain | read; then + die "Uncommitted or untracked files found; commit changes first" +fi + +if [[ -d "${GOPATH}/src" ]]; then + die "\${GOPATH}/src (${GOPATH}/src) exists; this script will delete it." +fi + +# Undo any edits made by this script. +cleanup() { + rm -rf "${GOPATH}/src" + git reset --hard HEAD +} +trap cleanup EXIT + +fail_on_output() { + tee /dev/stderr | (! read) +} + +PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}" + +if [[ "$1" = "-install" ]]; then + # Check for module support + if go help mod >& /dev/null; then + go install \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/goimports \ + honnef.co/go/tools/cmd/staticcheck \ + github.com/client9/misspell/cmd/misspell \ + github.com/golang/protobuf/protoc-gen-go + else + # Ye olde `go get` incantation. + # Note: this gets the latest version of all tools (vs. the pinned versions + # with Go modules). + go get -u \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/goimports \ + honnef.co/go/tools/cmd/staticcheck \ + github.com/client9/misspell/cmd/misspell \ + github.com/golang/protobuf/protoc-gen-go + fi + if [[ -z "${VET_SKIP_PROTO}" ]]; then + if [[ "${TRAVIS}" = "true" ]]; then + PROTOBUF_VERSION=3.3.0 + PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip + pushd /home/travis + wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} + unzip ${PROTOC_FILENAME} + bin/protoc --version + popd + elif ! which protoc > /dev/null; then + die "Please install protoc into your path" + fi + fi + exit 0 +elif [[ "$#" -ne 0 ]]; then + die "Unknown argument(s): $*" +fi + +# - Ensure all source files contain a copyright message. +git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | fail_on_output + +# - Do not import math/rand for real library code. Use internal/grpcrand for +# thread safety. +git ls-files "*.go" | xargs grep -l '"math/rand"' 2>&1 | (! grep -v '^examples\|^stress\|grpcrand') + +# - Ensure all ptypes proto packages are renamed when importing. +git ls-files "*.go" | (! xargs grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/") + +# - Check imports that are illegal in appengine (until Go 1.11). +# TODO: Remove when we drop Go 1.10 support +go list -f {{.Dir}} ./... | xargs go run test/go_vet/vet.go + +# - gofmt, goimports, golint (with exceptions for generated code), go vet. +gofmt -s -d -l . 2>&1 | fail_on_output +goimports -l . 2>&1 | fail_on_output +golint ./... 2>&1 | (! grep -vE "(_mock|\.pb)\.go:") +go tool vet -all . + +# - Check that generated proto files are up to date. +if [[ -z "${VET_SKIP_PROTO}" ]]; then + PATH="/home/travis/bin:${PATH}" make proto && \ + git status --porcelain 2>&1 | fail_on_output || \ + (git status; git --no-pager diff; exit 1) +fi + +# - Check that our module is tidy. +if go help mod >& /dev/null; then + go mod tidy && \ + git status --porcelain 2>&1 | fail_on_output || \ + (git status; git --no-pager diff; exit 1) +fi + +# - Collection of static analysis checks +### HACK HACK HACK: Remove once staticcheck works with modules. +# Make a symlink in ${GOPATH}/src to its ${GOPATH}/pkg/mod equivalent for every package we use. +for x in $(find "${GOPATH}/pkg/mod" -name '*@*' | grep -v \/mod\/cache\/); do + pkg="$(echo ${x#"${GOPATH}/pkg/mod/"} | cut -f1 -d@)"; + # If multiple versions exist, just use the existing one. + if [[ -L "${GOPATH}/src/${pkg}" ]]; then continue; fi + mkdir -p "$(dirname "${GOPATH}/src/${pkg}")"; + ln -s $x "${GOPATH}/src/${pkg}"; +done +### END HACK HACK HACK + +# TODO(menghanl): fix errors in transport_test. +staticcheck -ignore ' +balancer.go:SA1019 +balancer_test.go:SA1019 +clientconn_test.go:SA1019 +balancer/roundrobin/roundrobin_test.go:SA1019 +benchmark/benchmain/main.go:SA1019 +internal/transport/handler_server.go:SA1019 +internal/transport/handler_server_test.go:SA1019 +internal/transport/transport_test.go:SA2002 +stats/stats_test.go:SA1019 +test/channelz_test.go:SA1019 +test/end2end_test.go:SA1019 +' ./... +misspell -error . diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml new file mode 100644 index 00000000..9f556934 --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/.travis.yml @@ -0,0 +1,12 @@ +language: go + +go: + - 1.4 + - 1.5 + - 1.6 + - 1.7 + - 1.8 + - 1.9 + - tip + +go_import_path: gopkg.in/yaml.v2 diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go index a14435e8..0ee738e1 100644 --- a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/gopkg.in/yaml.v2/encode.go @@ -13,6 +13,19 @@ import ( "unicode/utf8" ) +// jsonNumber is the interface of the encoding/json.Number datatype. +// Repeating the interface here avoids a dependency on encoding/json, and also +// supports other libraries like jsoniter, which use a similar datatype with +// the same interface. Detecting this interface is useful when dealing with +// structures containing json.Number, which is a string under the hood. The +// encoder should prefer the use of Int64(), Float64() and string(), in that +// order, when encoding this type. +type jsonNumber interface { + Float64() (float64, error) + Int64() (int64, error) + String() string +} + type encoder struct { emitter yaml_emitter_t event yaml_event_t @@ -89,6 +102,21 @@ func (e *encoder) marshal(tag string, in reflect.Value) { } iface := in.Interface() switch m := iface.(type) { + case jsonNumber: + integer, err := m.Int64() + if err == nil { + // In this case the json.Number is a valid int64 + in = reflect.ValueOf(integer) + break + } + float, err := m.Float64() + if err == nil { + // In this case the json.Number is a valid float64 + in = reflect.ValueOf(float) + break + } + // fallback case - no number could be obtained + in = reflect.ValueOf(m.String()) case time.Time, *time.Time: // Although time.Time implements TextMarshaler, // we don't want to treat it as a string for YAML diff --git a/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt new file mode 100644 index 00000000..4e4e1ddb --- /dev/null +++ b/functions/query/vendor/github.com/v3io/v3io-tsdb/vendor/modules.txt @@ -0,0 +1,134 @@ +# github.com/cespare/xxhash v1.1.0 +github.com/cespare/xxhash +# github.com/cpuguy83/go-md2man v1.0.8 +github.com/cpuguy83/go-md2man/md2man +# github.com/davecgh/go-spew v1.1.1 +github.com/davecgh/go-spew/spew +# github.com/ghodss/yaml v1.0.0 +github.com/ghodss/yaml +# github.com/golang/protobuf v1.2.0 +github.com/golang/protobuf/proto +github.com/golang/protobuf/ptypes +github.com/golang/protobuf/ptypes/any +github.com/golang/protobuf/ptypes/duration +github.com/golang/protobuf/ptypes/timestamp +# github.com/imdario/mergo v0.3.7 +github.com/imdario/mergo +# github.com/inconshreveable/mousetrap v1.0.0 +github.com/inconshreveable/mousetrap +# github.com/klauspost/compress v1.4.0 +github.com/klauspost/compress/flate +github.com/klauspost/compress/gzip +github.com/klauspost/compress/zlib +# github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e +github.com/klauspost/cpuid +# github.com/mattn/go-colorable v0.0.9 +github.com/mattn/go-colorable +# github.com/mattn/go-isatty v0.0.4 +github.com/mattn/go-isatty +# github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b +github.com/mgutz/ansi +# github.com/nuclio/logger v0.0.1 +github.com/nuclio/logger +# github.com/nuclio/nuclio-sdk-go v0.0.0-20190205170814-3b507fbd0324 +github.com/nuclio/nuclio-sdk-go +# github.com/nuclio/nuclio-test-go v0.0.0-20180704132150-0ce6587f8e37 +github.com/nuclio/nuclio-test-go +# github.com/nuclio/zap v0.0.2 +github.com/nuclio/zap +# github.com/pavius/zap v0.0.0-20180228181622-8d52692529b8 +github.com/pavius/zap +github.com/pavius/zap/zapcore +github.com/pavius/zap/internal/bufferpool +github.com/pavius/zap/buffer +github.com/pavius/zap/internal/color +github.com/pavius/zap/internal/exit +# github.com/pkg/errors v0.8.1 +github.com/pkg/errors +# github.com/pmezard/go-difflib v1.0.0 +github.com/pmezard/go-difflib/difflib +# github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a +github.com/rcrowley/go-metrics +# github.com/russross/blackfriday v1.5.2+incompatible +github.com/russross/blackfriday +# github.com/spf13/cobra v0.0.3 +github.com/spf13/cobra +github.com/spf13/cobra/doc +# github.com/spf13/pflag v1.0.3 +github.com/spf13/pflag +# github.com/stretchr/testify v1.3.0 +github.com/stretchr/testify/assert +github.com/stretchr/testify/suite +github.com/stretchr/testify/require +# github.com/v3io/frames v0.0.0-20190328123118-1dad1ff610509e7b087d9cd390ed1b452caecf15 +github.com/v3io/frames +github.com/v3io/frames/pb +# github.com/v3io/v3io-go-http v0.0.0-20190221115935-53e2b487c9a2 +github.com/v3io/v3io-go-http +# github.com/valyala/bytebufferpool v1.0.0 +github.com/valyala/bytebufferpool +# github.com/valyala/fasthttp v1.0.0 +github.com/valyala/fasthttp +github.com/valyala/fasthttp/fasthttputil +github.com/valyala/fasthttp/stackless +# github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 => github.com/v3io/sqlparser v0.0.0-20190306105200-4d7273501871 +github.com/xwb1989/sqlparser +github.com/xwb1989/sqlparser/dependency/bytes2 +github.com/xwb1989/sqlparser/dependency/querypb +github.com/xwb1989/sqlparser/dependency/sqltypes +github.com/xwb1989/sqlparser/dependency/hack +# go.uber.org/atomic v1.3.2 +go.uber.org/atomic +# go.uber.org/multierr v1.1.0 +go.uber.org/multierr +# golang.org/x/net v0.0.0-20181114220301-adae6a3d119a +golang.org/x/net/context +golang.org/x/net/trace +golang.org/x/net/internal/timeseries +golang.org/x/net/http2 +golang.org/x/net/http2/hpack +golang.org/x/net/http/httpguts +golang.org/x/net/idna +# golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 +golang.org/x/sys/unix +# golang.org/x/text v0.3.0 +golang.org/x/text/secure/bidirule +golang.org/x/text/unicode/bidi +golang.org/x/text/unicode/norm +golang.org/x/text/transform +# google.golang.org/genproto v0.0.0-20181026194446-8b5d7a19e2d9 +google.golang.org/genproto/googleapis/rpc/status +# google.golang.org/grpc v1.17.0 +google.golang.org/grpc +google.golang.org/grpc/balancer +google.golang.org/grpc/balancer/roundrobin +google.golang.org/grpc/codes +google.golang.org/grpc/connectivity +google.golang.org/grpc/credentials +google.golang.org/grpc/encoding +google.golang.org/grpc/encoding/proto +google.golang.org/grpc/grpclog +google.golang.org/grpc/internal +google.golang.org/grpc/internal/backoff +google.golang.org/grpc/internal/binarylog +google.golang.org/grpc/internal/channelz +google.golang.org/grpc/internal/envconfig +google.golang.org/grpc/internal/grpcrand +google.golang.org/grpc/internal/grpcsync +google.golang.org/grpc/internal/transport +google.golang.org/grpc/keepalive +google.golang.org/grpc/metadata +google.golang.org/grpc/naming +google.golang.org/grpc/peer +google.golang.org/grpc/resolver +google.golang.org/grpc/resolver/dns +google.golang.org/grpc/resolver/passthrough +google.golang.org/grpc/stats +google.golang.org/grpc/status +google.golang.org/grpc/tap +google.golang.org/grpc/balancer/base +google.golang.org/grpc/credentials/internal +google.golang.org/grpc/binarylog/grpc_binarylog_v1 +google.golang.org/grpc/internal/syscall +# gopkg.in/yaml.v2 v2.2.2 +gopkg.in/yaml.v2