Compare commits
11 Commits
10c1032bba
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcf78d3d69 | ||
|
|
34fee32155 | ||
|
|
b3e0b205ba | ||
|
|
31776603b2 | ||
|
|
35579f2803 | ||
|
|
a8a5df8a53 | ||
|
|
d616d7289a | ||
|
|
e79e2d1931 | ||
|
|
b2bbd079bc | ||
|
|
510a702ec8 | ||
|
|
59e5148a47 |
12
go.mod
12
go.mod
@@ -11,11 +11,11 @@ require (
|
|||||||
github.com/kubernetes-csi/csi-lib-utils v0.17.0
|
github.com/kubernetes-csi/csi-lib-utils v0.17.0
|
||||||
github.com/kubernetes-csi/csi-test/v5 v5.2.0
|
github.com/kubernetes-csi/csi-test/v5 v5.2.0
|
||||||
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0
|
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0
|
||||||
github.com/prometheus/client_golang v1.18.0
|
github.com/prometheus/client_golang v1.19.0
|
||||||
github.com/prometheus/client_model v0.5.0
|
github.com/prometheus/client_model v0.6.0
|
||||||
github.com/prometheus/common v0.46.0
|
github.com/prometheus/common v0.48.0
|
||||||
github.com/spf13/cobra v1.8.0
|
github.com/spf13/cobra v1.8.0
|
||||||
google.golang.org/grpc v1.61.1
|
google.golang.org/grpc v1.62.1
|
||||||
google.golang.org/protobuf v1.32.0
|
google.golang.org/protobuf v1.32.0
|
||||||
k8s.io/api v0.29.0
|
k8s.io/api v0.29.0
|
||||||
k8s.io/apimachinery v0.29.0
|
k8s.io/apimachinery v0.29.0
|
||||||
@@ -41,7 +41,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.4.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/imdario/mergo v0.3.13 // indirect
|
github.com/imdario/mergo v0.3.13 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
@@ -64,7 +64,7 @@ require (
|
|||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
golang.org/x/time v0.3.0 // indirect
|
golang.org/x/time v0.3.0 // indirect
|
||||||
google.golang.org/appengine v1.6.8 // indirect
|
google.golang.org/appengine v1.6.8 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
|||||||
32
go.sum
32
go.sum
@@ -8,8 +8,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
|
|||||||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 h1:7To3pQ+pZo0i3dsWEbinPNFs5gPSBOsJtx3wTT94VBY=
|
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ=
|
||||||
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
|
||||||
github.com/container-storage-interface/spec v1.9.0 h1:zKtX4STsq31Knz3gciCYCi1SXtO2HJDecIjDVboYavY=
|
github.com/container-storage-interface/spec v1.9.0 h1:zKtX4STsq31Knz3gciCYCi1SXtO2HJDecIjDVboYavY=
|
||||||
github.com/container-storage-interface/spec v1.9.0/go.mod h1:ZfDu+3ZRyeVqxZM0Ds19MVLkN2d1XJ5MAfi1L3VjlT0=
|
github.com/container-storage-interface/spec v1.9.0/go.mod h1:ZfDu+3ZRyeVqxZM0Ds19MVLkN2d1XJ5MAfi1L3VjlT0=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
@@ -19,8 +19,8 @@ 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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||||
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
|
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
|
||||||
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
|
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
|
||||||
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
|
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
|
||||||
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
@@ -59,8 +59,8 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
|||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
@@ -99,12 +99,12 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
|
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||||
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
|
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||||
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
|
||||||
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
|
||||||
github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y=
|
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||||
github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ=
|
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
||||||
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||||
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
@@ -196,10 +196,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
|||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
|
||||||
google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY=
|
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
|
||||||
google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
|
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import (
|
|||||||
groupsnapshotlisters "github.com/kubernetes-csi/external-snapshotter/client/v7/listers/volumegroupsnapshot/v1alpha1"
|
groupsnapshotlisters "github.com/kubernetes-csi/external-snapshotter/client/v7/listers/volumegroupsnapshot/v1alpha1"
|
||||||
snapshotlisters "github.com/kubernetes-csi/external-snapshotter/client/v7/listers/volumesnapshot/v1"
|
snapshotlisters "github.com/kubernetes-csi/external-snapshotter/client/v7/listers/volumesnapshot/v1"
|
||||||
"github.com/kubernetes-csi/external-snapshotter/v7/pkg/snapshotter"
|
"github.com/kubernetes-csi/external-snapshotter/v7/pkg/snapshotter"
|
||||||
|
"github.com/kubernetes-csi/external-snapshotter/v7/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type csiSnapshotSideCarController struct {
|
type csiSnapshotSideCarController struct {
|
||||||
@@ -116,14 +117,11 @@ func NewCSISnapshotSideCarController(
|
|||||||
cache.ResourceEventHandlerFuncs{
|
cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(obj interface{}) { ctrl.enqueueContentWork(obj) },
|
AddFunc: func(obj interface{}) { ctrl.enqueueContentWork(obj) },
|
||||||
UpdateFunc: func(oldObj, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
// Considering the object is modified more than once during the workflow we are not relying on the
|
// Only enqueue updated VolumeSnapshotContent object if it contains a change that may need resync
|
||||||
// "AnnVolumeSnapshotBeingCreated" annotation. Instead we will just check if newobj status has error
|
// Ignore changes that cannot necessitate a sync and/or are caused by the sidecar itself
|
||||||
// and avoid the immediate re-queue. This allows the retry to happen with exponential backoff.
|
if utils.ShouldEnqueueContentChange(oldObj.(*crdv1.VolumeSnapshotContent), newObj.(*crdv1.VolumeSnapshotContent)) {
|
||||||
newSnapContent := newObj.(*crdv1.VolumeSnapshotContent)
|
ctrl.enqueueContentWork(newObj)
|
||||||
if newSnapContent.Status != nil && newSnapContent.Status.Error != nil {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
ctrl.enqueueContentWork(newObj)
|
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) { ctrl.enqueueContentWork(obj) },
|
DeleteFunc: func(obj interface{}) { ctrl.enqueueContentWork(obj) },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/equality"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
@@ -156,6 +157,14 @@ var SnapshotterListSecretParams = secretParamsMap{
|
|||||||
secretNamespaceKey: PrefixedSnapshotterListSecretNamespaceKey,
|
secretNamespaceKey: PrefixedSnapshotterListSecretNamespaceKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Annotations on VolumeSnapshotContent objects entirely controlled by csi-snapshotter
|
||||||
|
// Changes to these annotations will be ignored for determining whether to sync changes to content objects
|
||||||
|
// AnnVolumeSnapshotBeingCreated is managed entirely by the csi-snapshotter sidecar
|
||||||
|
// AnnVolumeSnapshotBeingDeleted is applied by the snapshot-controller and thus is not sidecar-owned
|
||||||
|
var sidecarControlledContentAnnotations = map[string]struct{}{
|
||||||
|
AnnVolumeSnapshotBeingCreated: {},
|
||||||
|
}
|
||||||
|
|
||||||
// MapContainsKey checks if a given map of string to string contains the provided string.
|
// MapContainsKey checks if a given map of string to string contains the provided string.
|
||||||
func MapContainsKey(m map[string]string, s string) bool {
|
func MapContainsKey(m map[string]string, s string) bool {
|
||||||
_, r := m[s]
|
_, r := m[s]
|
||||||
@@ -593,3 +602,52 @@ func IsGroupSnapshotCreated(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool
|
|||||||
func GetDynamicSnapshotContentNameForGroupSnapshot(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) string {
|
func GetDynamicSnapshotContentNameForGroupSnapshot(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) string {
|
||||||
return "groupsnapcontent-" + string(groupSnapshot.UID)
|
return "groupsnapcontent-" + string(groupSnapshot.UID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShouldEnqueueContentChange indicated whether or not a change to a VolumeSnapshotContent object
|
||||||
|
// is a change that should be enqueued for sync
|
||||||
|
//
|
||||||
|
// The following changes are sanitized (and thus, not considered for determining whether to sync)
|
||||||
|
// - Resource Version (always changed between objects)
|
||||||
|
// - Status (owned and updated only by the sidecar)
|
||||||
|
// - Managed Fields (updated by sidecar, and will not change the sync status)
|
||||||
|
// - Finalizers (updated by sidecar, and will not change the sync status)
|
||||||
|
// - Sidecar-Owned Annotations (annotations that are owned and updated only by the sidecar)
|
||||||
|
// (some annotations, such as AnnVolumeSnapshotBeingDeleted, are applied by the controller - so
|
||||||
|
// only annotatinons entirely controlled by the sidecar are ignored)
|
||||||
|
//
|
||||||
|
// If the VolumeSnapshotContent object still contains other changes after this sanitization, the changes
|
||||||
|
// are potentially meaningful and the object is enqueued to be considered for syncing
|
||||||
|
func ShouldEnqueueContentChange(old *crdv1.VolumeSnapshotContent, new *crdv1.VolumeSnapshotContent) bool {
|
||||||
|
sanitized := new.DeepCopy()
|
||||||
|
// ResourceVersion always changes between revisions
|
||||||
|
sanitized.ResourceVersion = old.ResourceVersion
|
||||||
|
// Fields that should not result in a sync
|
||||||
|
sanitized.Status = old.Status
|
||||||
|
sanitized.ManagedFields = old.ManagedFields
|
||||||
|
sanitized.Finalizers = old.Finalizers
|
||||||
|
// Annotations should cause a sync, except for annotations that csi-snapshotter controls
|
||||||
|
if old.Annotations != nil {
|
||||||
|
// This can happen if the new version has all annotations removed
|
||||||
|
if sanitized.Annotations == nil {
|
||||||
|
sanitized.Annotations = map[string]string{}
|
||||||
|
}
|
||||||
|
for annotation, _ := range sidecarControlledContentAnnotations {
|
||||||
|
if value, ok := old.Annotations[annotation]; ok {
|
||||||
|
sanitized.Annotations[annotation] = value
|
||||||
|
} else {
|
||||||
|
delete(sanitized.Annotations, annotation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Old content has no annotations, so delete any sidecar-controlled annotations present on the new content
|
||||||
|
for annotation, _ := range sidecarControlledContentAnnotations {
|
||||||
|
delete(sanitized.Annotations, annotation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if equality.Semantic.DeepEqual(old, sanitized) {
|
||||||
|
// The only changes are in the fields we don't care about, so don't enqueue for sync
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -302,3 +302,220 @@ func TestIsDefaultAnnotation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShouldEnqueueContentChange(t *testing.T) {
|
||||||
|
oldValue := "old"
|
||||||
|
newValue := "new"
|
||||||
|
|
||||||
|
testcases := []struct {
|
||||||
|
name string
|
||||||
|
old *crdv1.VolumeSnapshotContent
|
||||||
|
new *crdv1.VolumeSnapshotContent
|
||||||
|
expectedResult bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic no change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "basic change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
Spec: crdv1.VolumeSnapshotContentSpec{
|
||||||
|
VolumeSnapshotClassName: &oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
Spec: crdv1.VolumeSnapshotContentSpec{
|
||||||
|
VolumeSnapshotClassName: &newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "status change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
Status: &crdv1.VolumeSnapshotContentStatus{
|
||||||
|
Error: &crdv1.VolumeSnapshotError{
|
||||||
|
Message: &oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
Status: &crdv1.VolumeSnapshotContentStatus{
|
||||||
|
Error: &crdv1.VolumeSnapshotError{
|
||||||
|
Message: &newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "finalizers change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Finalizers: []string{
|
||||||
|
oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Finalizers: []string{
|
||||||
|
newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "managed fields change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
ManagedFields: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
ManagedFields: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-managed annotation change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingCreated: oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingCreated: newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-unmanaged annotation change",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"test-annotation": oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"test-annotation": newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-managed annotation created",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingCreated: newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-unmanaged annotation created",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"test-annotation": newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-managed annotation deleted",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingCreated: oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-unmanaged annotation deleted",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"test-annotation": oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sidecar-unmanaged annotation change (AnnVolumeSnapshotBeingDeleted)",
|
||||||
|
old: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingDeleted: oldValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
new: &crdv1.VolumeSnapshotContent{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Annotations: map[string]string{
|
||||||
|
AnnVolumeSnapshotBeingDeleted: newValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testcases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
result := ShouldEnqueueContentChange(tc.old, tc.new)
|
||||||
|
if result != tc.expectedResult {
|
||||||
|
t.Fatalf("Incorrect result: Expected %v received %v", tc.expectedResult, result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -564,7 +564,15 @@ go_version_for_kubernetes () (
|
|||||||
local version="$2"
|
local version="$2"
|
||||||
local go_version
|
local go_version
|
||||||
|
|
||||||
# We use the minimal Go version specified for each K8S release (= minimum_go_version in hack/lib/golang.sh).
|
# Try to get the version for .go-version
|
||||||
|
go_version="$( cat "$path/.go-version" )"
|
||||||
|
if [ "$go_version" ]; then
|
||||||
|
echo "$go_version"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fall back to hack/lib/golang.sh parsing.
|
||||||
|
# This is necessary in v1.26.0 and older Kubernetes releases that do not have .go-version.
|
||||||
# More recent versions might also work, but we don't want to count on that.
|
# More recent versions might also work, but we don't want to count on that.
|
||||||
go_version="$(grep minimum_go_version= "$path/hack/lib/golang.sh" | sed -e 's/.*=go//')"
|
go_version="$(grep minimum_go_version= "$path/hack/lib/golang.sh" | sed -e 's/.*=go//')"
|
||||||
if ! [ "$go_version" ]; then
|
if ! [ "$go_version" ]; then
|
||||||
|
|||||||
530
vendor/github.com/golang/protobuf/jsonpb/decode.go
generated
vendored
530
vendor/github.com/golang/protobuf/jsonpb/decode.go
generated
vendored
@@ -1,530 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package jsonpb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wrapJSONUnmarshalV2 = false
|
|
||||||
|
|
||||||
// UnmarshalNext unmarshals the next JSON object from d into m.
|
|
||||||
func UnmarshalNext(d *json.Decoder, m proto.Message) error {
|
|
||||||
return new(Unmarshaler).UnmarshalNext(d, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal unmarshals a JSON object from r into m.
|
|
||||||
func Unmarshal(r io.Reader, m proto.Message) error {
|
|
||||||
return new(Unmarshaler).Unmarshal(r, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalString unmarshals a JSON object from s into m.
|
|
||||||
func UnmarshalString(s string, m proto.Message) error {
|
|
||||||
return new(Unmarshaler).Unmarshal(strings.NewReader(s), m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshaler is a configurable object for converting from a JSON
|
|
||||||
// representation to a protocol buffer object.
|
|
||||||
type Unmarshaler struct {
|
|
||||||
// AllowUnknownFields specifies whether to allow messages to contain
|
|
||||||
// unknown JSON fields, as opposed to failing to unmarshal.
|
|
||||||
AllowUnknownFields bool
|
|
||||||
|
|
||||||
// AnyResolver is used to resolve the google.protobuf.Any well-known type.
|
|
||||||
// If unset, the global registry is used by default.
|
|
||||||
AnyResolver AnyResolver
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONPBUnmarshaler is implemented by protobuf messages that customize the way
|
|
||||||
// they are unmarshaled from JSON. Messages that implement this should also
|
|
||||||
// implement JSONPBMarshaler so that the custom format can be produced.
|
|
||||||
//
|
|
||||||
// The JSON unmarshaling must follow the JSON to proto specification:
|
|
||||||
// https://developers.google.com/protocol-buffers/docs/proto3#json
|
|
||||||
//
|
|
||||||
// Deprecated: Custom types should implement protobuf reflection instead.
|
|
||||||
type JSONPBUnmarshaler interface {
|
|
||||||
UnmarshalJSONPB(*Unmarshaler, []byte) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal unmarshals a JSON object from r into m.
|
|
||||||
func (u *Unmarshaler) Unmarshal(r io.Reader, m proto.Message) error {
|
|
||||||
return u.UnmarshalNext(json.NewDecoder(r), m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalNext unmarshals the next JSON object from d into m.
|
|
||||||
func (u *Unmarshaler) UnmarshalNext(d *json.Decoder, m proto.Message) error {
|
|
||||||
if m == nil {
|
|
||||||
return errors.New("invalid nil message")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the next JSON object from the stream.
|
|
||||||
raw := json.RawMessage{}
|
|
||||||
if err := d.Decode(&raw); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for custom unmarshalers first since they may not properly
|
|
||||||
// implement protobuf reflection that the logic below relies on.
|
|
||||||
if jsu, ok := m.(JSONPBUnmarshaler); ok {
|
|
||||||
return jsu.UnmarshalJSONPB(u, raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
mr := proto.MessageReflect(m)
|
|
||||||
|
|
||||||
// NOTE: For historical reasons, a top-level null is treated as a noop.
|
|
||||||
// This is incorrect, but kept for compatibility.
|
|
||||||
if string(raw) == "null" && mr.Descriptor().FullName() != "google.protobuf.Value" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if wrapJSONUnmarshalV2 {
|
|
||||||
// NOTE: If input message is non-empty, we need to preserve merge semantics
|
|
||||||
// of the old jsonpb implementation. These semantics are not supported by
|
|
||||||
// the protobuf JSON specification.
|
|
||||||
isEmpty := true
|
|
||||||
mr.Range(func(protoreflect.FieldDescriptor, protoreflect.Value) bool {
|
|
||||||
isEmpty = false // at least one iteration implies non-empty
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
if !isEmpty {
|
|
||||||
// Perform unmarshaling into a newly allocated, empty message.
|
|
||||||
mr = mr.New()
|
|
||||||
|
|
||||||
// Use a defer to copy all unmarshaled fields into the original message.
|
|
||||||
dst := proto.MessageReflect(m)
|
|
||||||
defer mr.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
|
||||||
dst.Set(fd, v)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal using the v2 JSON unmarshaler.
|
|
||||||
opts := protojson.UnmarshalOptions{
|
|
||||||
DiscardUnknown: u.AllowUnknownFields,
|
|
||||||
}
|
|
||||||
if u.AnyResolver != nil {
|
|
||||||
opts.Resolver = anyResolver{u.AnyResolver}
|
|
||||||
}
|
|
||||||
return opts.Unmarshal(raw, mr.Interface())
|
|
||||||
} else {
|
|
||||||
if err := u.unmarshalMessage(mr, raw); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return protoV2.CheckInitialized(mr.Interface())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshalMessage(m protoreflect.Message, in []byte) error {
|
|
||||||
md := m.Descriptor()
|
|
||||||
fds := md.Fields()
|
|
||||||
|
|
||||||
if jsu, ok := proto.MessageV1(m.Interface()).(JSONPBUnmarshaler); ok {
|
|
||||||
return jsu.UnmarshalJSONPB(u, in)
|
|
||||||
}
|
|
||||||
|
|
||||||
if string(in) == "null" && md.FullName() != "google.protobuf.Value" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch wellKnownType(md.FullName()) {
|
|
||||||
case "Any":
|
|
||||||
var jsonObject map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonObject); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rawTypeURL, ok := jsonObject["@type"]
|
|
||||||
if !ok {
|
|
||||||
return errors.New("Any JSON doesn't have '@type'")
|
|
||||||
}
|
|
||||||
typeURL, err := unquoteString(string(rawTypeURL))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't unmarshal Any's '@type': %q", rawTypeURL)
|
|
||||||
}
|
|
||||||
m.Set(fds.ByNumber(1), protoreflect.ValueOfString(typeURL))
|
|
||||||
|
|
||||||
var m2 protoreflect.Message
|
|
||||||
if u.AnyResolver != nil {
|
|
||||||
mi, err := u.AnyResolver.Resolve(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m2 = proto.MessageReflect(mi)
|
|
||||||
} else {
|
|
||||||
mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
if err == protoregistry.NotFound {
|
|
||||||
return fmt.Errorf("could not resolve Any message type: %v", typeURL)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m2 = mt.New()
|
|
||||||
}
|
|
||||||
|
|
||||||
if wellKnownType(m2.Descriptor().FullName()) != "" {
|
|
||||||
rawValue, ok := jsonObject["value"]
|
|
||||||
if !ok {
|
|
||||||
return errors.New("Any JSON doesn't have 'value'")
|
|
||||||
}
|
|
||||||
if err := u.unmarshalMessage(m2, rawValue); err != nil {
|
|
||||||
return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete(jsonObject, "@type")
|
|
||||||
rawJSON, err := json.Marshal(jsonObject)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't generate JSON for Any's nested proto to be unmarshaled: %v", err)
|
|
||||||
}
|
|
||||||
if err = u.unmarshalMessage(m2, rawJSON); err != nil {
|
|
||||||
return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rawWire, err := protoV2.Marshal(m2.Interface())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't marshal proto %v into Any.Value: %v", typeURL, err)
|
|
||||||
}
|
|
||||||
m.Set(fds.ByNumber(2), protoreflect.ValueOfBytes(rawWire))
|
|
||||||
return nil
|
|
||||||
case "BoolValue", "BytesValue", "StringValue",
|
|
||||||
"Int32Value", "UInt32Value", "FloatValue",
|
|
||||||
"Int64Value", "UInt64Value", "DoubleValue":
|
|
||||||
fd := fds.ByNumber(1)
|
|
||||||
v, err := u.unmarshalValue(m.NewField(fd), in, fd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
return nil
|
|
||||||
case "Duration":
|
|
||||||
v, err := unquoteString(string(in))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
d, err := time.ParseDuration(v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("bad Duration: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sec := d.Nanoseconds() / 1e9
|
|
||||||
nsec := d.Nanoseconds() % 1e9
|
|
||||||
m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec)))
|
|
||||||
m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec)))
|
|
||||||
return nil
|
|
||||||
case "Timestamp":
|
|
||||||
v, err := unquoteString(string(in))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t, err := time.Parse(time.RFC3339Nano, v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("bad Timestamp: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sec := t.Unix()
|
|
||||||
nsec := t.Nanosecond()
|
|
||||||
m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec)))
|
|
||||||
m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec)))
|
|
||||||
return nil
|
|
||||||
case "Value":
|
|
||||||
switch {
|
|
||||||
case string(in) == "null":
|
|
||||||
m.Set(fds.ByNumber(1), protoreflect.ValueOfEnum(0))
|
|
||||||
case string(in) == "true":
|
|
||||||
m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(true))
|
|
||||||
case string(in) == "false":
|
|
||||||
m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(false))
|
|
||||||
case hasPrefixAndSuffix('"', in, '"'):
|
|
||||||
s, err := unquoteString(string(in))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unrecognized type for Value %q", in)
|
|
||||||
}
|
|
||||||
m.Set(fds.ByNumber(3), protoreflect.ValueOfString(s))
|
|
||||||
case hasPrefixAndSuffix('[', in, ']'):
|
|
||||||
v := m.Mutable(fds.ByNumber(6))
|
|
||||||
return u.unmarshalMessage(v.Message(), in)
|
|
||||||
case hasPrefixAndSuffix('{', in, '}'):
|
|
||||||
v := m.Mutable(fds.ByNumber(5))
|
|
||||||
return u.unmarshalMessage(v.Message(), in)
|
|
||||||
default:
|
|
||||||
f, err := strconv.ParseFloat(string(in), 0)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unrecognized type for Value %q", in)
|
|
||||||
}
|
|
||||||
m.Set(fds.ByNumber(2), protoreflect.ValueOfFloat64(f))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case "ListValue":
|
|
||||||
var jsonArray []json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonArray); err != nil {
|
|
||||||
return fmt.Errorf("bad ListValue: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
lv := m.Mutable(fds.ByNumber(1)).List()
|
|
||||||
for _, raw := range jsonArray {
|
|
||||||
ve := lv.NewElement()
|
|
||||||
if err := u.unmarshalMessage(ve.Message(), raw); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lv.Append(ve)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case "Struct":
|
|
||||||
var jsonObject map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonObject); err != nil {
|
|
||||||
return fmt.Errorf("bad StructValue: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mv := m.Mutable(fds.ByNumber(1)).Map()
|
|
||||||
for key, raw := range jsonObject {
|
|
||||||
kv := protoreflect.ValueOf(key).MapKey()
|
|
||||||
vv := mv.NewValue()
|
|
||||||
if err := u.unmarshalMessage(vv.Message(), raw); err != nil {
|
|
||||||
return fmt.Errorf("bad value in StructValue for key %q: %v", key, err)
|
|
||||||
}
|
|
||||||
mv.Set(kv, vv)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var jsonObject map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonObject); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle known fields.
|
|
||||||
for i := 0; i < fds.Len(); i++ {
|
|
||||||
fd := fds.Get(i)
|
|
||||||
if fd.IsWeak() && fd.Message().IsPlaceholder() {
|
|
||||||
continue // weak reference is not linked in
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search for any raw JSON value associated with this field.
|
|
||||||
var raw json.RawMessage
|
|
||||||
name := string(fd.Name())
|
|
||||||
if fd.Kind() == protoreflect.GroupKind {
|
|
||||||
name = string(fd.Message().Name())
|
|
||||||
}
|
|
||||||
if v, ok := jsonObject[name]; ok {
|
|
||||||
delete(jsonObject, name)
|
|
||||||
raw = v
|
|
||||||
}
|
|
||||||
name = string(fd.JSONName())
|
|
||||||
if v, ok := jsonObject[name]; ok {
|
|
||||||
delete(jsonObject, name)
|
|
||||||
raw = v
|
|
||||||
}
|
|
||||||
|
|
||||||
field := m.NewField(fd)
|
|
||||||
// Unmarshal the field value.
|
|
||||||
if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
v, err := u.unmarshalValue(field, raw, fd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle extension fields.
|
|
||||||
for name, raw := range jsonObject {
|
|
||||||
if !strings.HasPrefix(name, "[") || !strings.HasSuffix(name, "]") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve the extension field by name.
|
|
||||||
xname := protoreflect.FullName(name[len("[") : len(name)-len("]")])
|
|
||||||
xt, _ := protoregistry.GlobalTypes.FindExtensionByName(xname)
|
|
||||||
if xt == nil && isMessageSet(md) {
|
|
||||||
xt, _ = protoregistry.GlobalTypes.FindExtensionByName(xname.Append("message_set_extension"))
|
|
||||||
}
|
|
||||||
if xt == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
delete(jsonObject, name)
|
|
||||||
fd := xt.TypeDescriptor()
|
|
||||||
if fd.ContainingMessage().FullName() != m.Descriptor().FullName() {
|
|
||||||
return fmt.Errorf("extension field %q does not extend message %q", xname, m.Descriptor().FullName())
|
|
||||||
}
|
|
||||||
|
|
||||||
field := m.NewField(fd)
|
|
||||||
// Unmarshal the field value.
|
|
||||||
if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
v, err := u.unmarshalValue(field, raw, fd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !u.AllowUnknownFields && len(jsonObject) > 0 {
|
|
||||||
for name := range jsonObject {
|
|
||||||
return fmt.Errorf("unknown field %q in %v", name, md.FullName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSingularWellKnownValue(fd protoreflect.FieldDescriptor) bool {
|
|
||||||
if fd.Cardinality() == protoreflect.Repeated {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if md := fd.Message(); md != nil {
|
|
||||||
return md.FullName() == "google.protobuf.Value"
|
|
||||||
}
|
|
||||||
if ed := fd.Enum(); ed != nil {
|
|
||||||
return ed.FullName() == "google.protobuf.NullValue"
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSingularJSONPBUnmarshaler(v protoreflect.Value, fd protoreflect.FieldDescriptor) bool {
|
|
||||||
if fd.Message() != nil && fd.Cardinality() != protoreflect.Repeated {
|
|
||||||
_, ok := proto.MessageV1(v.Interface()).(JSONPBUnmarshaler)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshalValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
|
|
||||||
switch {
|
|
||||||
case fd.IsList():
|
|
||||||
var jsonArray []json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonArray); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
lv := v.List()
|
|
||||||
for _, raw := range jsonArray {
|
|
||||||
ve, err := u.unmarshalSingularValue(lv.NewElement(), raw, fd)
|
|
||||||
if err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
lv.Append(ve)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
case fd.IsMap():
|
|
||||||
var jsonObject map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(in, &jsonObject); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
kfd := fd.MapKey()
|
|
||||||
vfd := fd.MapValue()
|
|
||||||
mv := v.Map()
|
|
||||||
for key, raw := range jsonObject {
|
|
||||||
var kv protoreflect.MapKey
|
|
||||||
if kfd.Kind() == protoreflect.StringKind {
|
|
||||||
kv = protoreflect.ValueOf(key).MapKey()
|
|
||||||
} else {
|
|
||||||
v, err := u.unmarshalSingularValue(kfd.Default(), []byte(key), kfd)
|
|
||||||
if err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
kv = v.MapKey()
|
|
||||||
}
|
|
||||||
|
|
||||||
vv, err := u.unmarshalSingularValue(mv.NewValue(), raw, vfd)
|
|
||||||
if err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
mv.Set(kv, vv)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
default:
|
|
||||||
return u.unmarshalSingularValue(v, in, fd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var nonFinite = map[string]float64{
|
|
||||||
`"NaN"`: math.NaN(),
|
|
||||||
`"Infinity"`: math.Inf(+1),
|
|
||||||
`"-Infinity"`: math.Inf(-1),
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshalSingularValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
|
|
||||||
switch fd.Kind() {
|
|
||||||
case protoreflect.BoolKind:
|
|
||||||
return unmarshalValue(in, new(bool))
|
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
|
||||||
return unmarshalValue(trimQuote(in), new(int32))
|
|
||||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
|
||||||
return unmarshalValue(trimQuote(in), new(int64))
|
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
|
||||||
return unmarshalValue(trimQuote(in), new(uint32))
|
|
||||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
|
||||||
return unmarshalValue(trimQuote(in), new(uint64))
|
|
||||||
case protoreflect.FloatKind:
|
|
||||||
if f, ok := nonFinite[string(in)]; ok {
|
|
||||||
return protoreflect.ValueOfFloat32(float32(f)), nil
|
|
||||||
}
|
|
||||||
return unmarshalValue(trimQuote(in), new(float32))
|
|
||||||
case protoreflect.DoubleKind:
|
|
||||||
if f, ok := nonFinite[string(in)]; ok {
|
|
||||||
return protoreflect.ValueOfFloat64(float64(f)), nil
|
|
||||||
}
|
|
||||||
return unmarshalValue(trimQuote(in), new(float64))
|
|
||||||
case protoreflect.StringKind:
|
|
||||||
return unmarshalValue(in, new(string))
|
|
||||||
case protoreflect.BytesKind:
|
|
||||||
return unmarshalValue(in, new([]byte))
|
|
||||||
case protoreflect.EnumKind:
|
|
||||||
if hasPrefixAndSuffix('"', in, '"') {
|
|
||||||
vd := fd.Enum().Values().ByName(protoreflect.Name(trimQuote(in)))
|
|
||||||
if vd == nil {
|
|
||||||
return v, fmt.Errorf("unknown value %q for enum %s", in, fd.Enum().FullName())
|
|
||||||
}
|
|
||||||
return protoreflect.ValueOfEnum(vd.Number()), nil
|
|
||||||
}
|
|
||||||
return unmarshalValue(in, new(protoreflect.EnumNumber))
|
|
||||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
|
||||||
err := u.unmarshalMessage(v.Message(), in)
|
|
||||||
return v, err
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("invalid kind %v", fd.Kind()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func unmarshalValue(in []byte, v interface{}) (protoreflect.Value, error) {
|
|
||||||
err := json.Unmarshal(in, v)
|
|
||||||
return protoreflect.ValueOf(reflect.ValueOf(v).Elem().Interface()), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func unquoteString(in string) (out string, err error) {
|
|
||||||
err = json.Unmarshal([]byte(in), &out)
|
|
||||||
return out, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasPrefixAndSuffix(prefix byte, in []byte, suffix byte) bool {
|
|
||||||
if len(in) >= 2 && in[0] == prefix && in[len(in)-1] == suffix {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// trimQuote is like unquoteString but simply strips surrounding quotes.
|
|
||||||
// This is incorrect, but is behavior done by the legacy implementation.
|
|
||||||
func trimQuote(in []byte) []byte {
|
|
||||||
if len(in) >= 2 && in[0] == '"' && in[len(in)-1] == '"' {
|
|
||||||
in = in[1 : len(in)-1]
|
|
||||||
}
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
559
vendor/github.com/golang/protobuf/jsonpb/encode.go
generated
vendored
559
vendor/github.com/golang/protobuf/jsonpb/encode.go
generated
vendored
@@ -1,559 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package jsonpb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wrapJSONMarshalV2 = false
|
|
||||||
|
|
||||||
// Marshaler is a configurable object for marshaling protocol buffer messages
|
|
||||||
// to the specified JSON representation.
|
|
||||||
type Marshaler struct {
|
|
||||||
// OrigName specifies whether to use the original protobuf name for fields.
|
|
||||||
OrigName bool
|
|
||||||
|
|
||||||
// EnumsAsInts specifies whether to render enum values as integers,
|
|
||||||
// as opposed to string values.
|
|
||||||
EnumsAsInts bool
|
|
||||||
|
|
||||||
// EmitDefaults specifies whether to render fields with zero values.
|
|
||||||
EmitDefaults bool
|
|
||||||
|
|
||||||
// Indent controls whether the output is compact or not.
|
|
||||||
// If empty, the output is compact JSON. Otherwise, every JSON object
|
|
||||||
// entry and JSON array value will be on its own line.
|
|
||||||
// Each line will be preceded by repeated copies of Indent, where the
|
|
||||||
// number of copies is the current indentation depth.
|
|
||||||
Indent string
|
|
||||||
|
|
||||||
// AnyResolver is used to resolve the google.protobuf.Any well-known type.
|
|
||||||
// If unset, the global registry is used by default.
|
|
||||||
AnyResolver AnyResolver
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONPBMarshaler is implemented by protobuf messages that customize the
|
|
||||||
// way they are marshaled to JSON. Messages that implement this should also
|
|
||||||
// implement JSONPBUnmarshaler so that the custom format can be parsed.
|
|
||||||
//
|
|
||||||
// The JSON marshaling must follow the proto to JSON specification:
|
|
||||||
// https://developers.google.com/protocol-buffers/docs/proto3#json
|
|
||||||
//
|
|
||||||
// Deprecated: Custom types should implement protobuf reflection instead.
|
|
||||||
type JSONPBMarshaler interface {
|
|
||||||
MarshalJSONPB(*Marshaler) ([]byte, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal serializes a protobuf message as JSON into w.
|
|
||||||
func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error {
|
|
||||||
b, err := jm.marshal(m)
|
|
||||||
if len(b) > 0 {
|
|
||||||
if _, err := w.Write(b); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalToString serializes a protobuf message as JSON in string form.
|
|
||||||
func (jm *Marshaler) MarshalToString(m proto.Message) (string, error) {
|
|
||||||
b, err := jm.marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(b), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (jm *Marshaler) marshal(m proto.Message) ([]byte, error) {
|
|
||||||
v := reflect.ValueOf(m)
|
|
||||||
if m == nil || (v.Kind() == reflect.Ptr && v.IsNil()) {
|
|
||||||
return nil, errors.New("Marshal called with nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for custom marshalers first since they may not properly
|
|
||||||
// implement protobuf reflection that the logic below relies on.
|
|
||||||
if jsm, ok := m.(JSONPBMarshaler); ok {
|
|
||||||
return jsm.MarshalJSONPB(jm)
|
|
||||||
}
|
|
||||||
|
|
||||||
if wrapJSONMarshalV2 {
|
|
||||||
opts := protojson.MarshalOptions{
|
|
||||||
UseProtoNames: jm.OrigName,
|
|
||||||
UseEnumNumbers: jm.EnumsAsInts,
|
|
||||||
EmitUnpopulated: jm.EmitDefaults,
|
|
||||||
Indent: jm.Indent,
|
|
||||||
}
|
|
||||||
if jm.AnyResolver != nil {
|
|
||||||
opts.Resolver = anyResolver{jm.AnyResolver}
|
|
||||||
}
|
|
||||||
return opts.Marshal(proto.MessageReflect(m).Interface())
|
|
||||||
} else {
|
|
||||||
// Check for unpopulated required fields first.
|
|
||||||
m2 := proto.MessageReflect(m)
|
|
||||||
if err := protoV2.CheckInitialized(m2.Interface()); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
w := jsonWriter{Marshaler: jm}
|
|
||||||
err := w.marshalMessage(m2, "", "")
|
|
||||||
return w.buf, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type jsonWriter struct {
|
|
||||||
*Marshaler
|
|
||||||
buf []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) write(s string) {
|
|
||||||
w.buf = append(w.buf, s...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) marshalMessage(m protoreflect.Message, indent, typeURL string) error {
|
|
||||||
if jsm, ok := proto.MessageV1(m.Interface()).(JSONPBMarshaler); ok {
|
|
||||||
b, err := jsm.MarshalJSONPB(w.Marshaler)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if typeURL != "" {
|
|
||||||
// we are marshaling this object to an Any type
|
|
||||||
var js map[string]*json.RawMessage
|
|
||||||
if err = json.Unmarshal(b, &js); err != nil {
|
|
||||||
return fmt.Errorf("type %T produced invalid JSON: %v", m.Interface(), err)
|
|
||||||
}
|
|
||||||
turl, err := json.Marshal(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to marshal type URL %q to JSON: %v", typeURL, err)
|
|
||||||
}
|
|
||||||
js["@type"] = (*json.RawMessage)(&turl)
|
|
||||||
if b, err = json.Marshal(js); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.write(string(b))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
md := m.Descriptor()
|
|
||||||
fds := md.Fields()
|
|
||||||
|
|
||||||
// Handle well-known types.
|
|
||||||
const secondInNanos = int64(time.Second / time.Nanosecond)
|
|
||||||
switch wellKnownType(md.FullName()) {
|
|
||||||
case "Any":
|
|
||||||
return w.marshalAny(m, indent)
|
|
||||||
case "BoolValue", "BytesValue", "StringValue",
|
|
||||||
"Int32Value", "UInt32Value", "FloatValue",
|
|
||||||
"Int64Value", "UInt64Value", "DoubleValue":
|
|
||||||
fd := fds.ByNumber(1)
|
|
||||||
return w.marshalValue(fd, m.Get(fd), indent)
|
|
||||||
case "Duration":
|
|
||||||
const maxSecondsInDuration = 315576000000
|
|
||||||
// "Generated output always contains 0, 3, 6, or 9 fractional digits,
|
|
||||||
// depending on required precision."
|
|
||||||
s := m.Get(fds.ByNumber(1)).Int()
|
|
||||||
ns := m.Get(fds.ByNumber(2)).Int()
|
|
||||||
if s < -maxSecondsInDuration || s > maxSecondsInDuration {
|
|
||||||
return fmt.Errorf("seconds out of range %v", s)
|
|
||||||
}
|
|
||||||
if ns <= -secondInNanos || ns >= secondInNanos {
|
|
||||||
return fmt.Errorf("ns out of range (%v, %v)", -secondInNanos, secondInNanos)
|
|
||||||
}
|
|
||||||
if (s > 0 && ns < 0) || (s < 0 && ns > 0) {
|
|
||||||
return errors.New("signs of seconds and nanos do not match")
|
|
||||||
}
|
|
||||||
var sign string
|
|
||||||
if s < 0 || ns < 0 {
|
|
||||||
sign, s, ns = "-", -1*s, -1*ns
|
|
||||||
}
|
|
||||||
x := fmt.Sprintf("%s%d.%09d", sign, s, ns)
|
|
||||||
x = strings.TrimSuffix(x, "000")
|
|
||||||
x = strings.TrimSuffix(x, "000")
|
|
||||||
x = strings.TrimSuffix(x, ".000")
|
|
||||||
w.write(fmt.Sprintf(`"%vs"`, x))
|
|
||||||
return nil
|
|
||||||
case "Timestamp":
|
|
||||||
// "RFC 3339, where generated output will always be Z-normalized
|
|
||||||
// and uses 0, 3, 6 or 9 fractional digits."
|
|
||||||
s := m.Get(fds.ByNumber(1)).Int()
|
|
||||||
ns := m.Get(fds.ByNumber(2)).Int()
|
|
||||||
if ns < 0 || ns >= secondInNanos {
|
|
||||||
return fmt.Errorf("ns out of range [0, %v)", secondInNanos)
|
|
||||||
}
|
|
||||||
t := time.Unix(s, ns).UTC()
|
|
||||||
// time.RFC3339Nano isn't exactly right (we need to get 3/6/9 fractional digits).
|
|
||||||
x := t.Format("2006-01-02T15:04:05.000000000")
|
|
||||||
x = strings.TrimSuffix(x, "000")
|
|
||||||
x = strings.TrimSuffix(x, "000")
|
|
||||||
x = strings.TrimSuffix(x, ".000")
|
|
||||||
w.write(fmt.Sprintf(`"%vZ"`, x))
|
|
||||||
return nil
|
|
||||||
case "Value":
|
|
||||||
// JSON value; which is a null, number, string, bool, object, or array.
|
|
||||||
od := md.Oneofs().Get(0)
|
|
||||||
fd := m.WhichOneof(od)
|
|
||||||
if fd == nil {
|
|
||||||
return errors.New("nil Value")
|
|
||||||
}
|
|
||||||
return w.marshalValue(fd, m.Get(fd), indent)
|
|
||||||
case "Struct", "ListValue":
|
|
||||||
// JSON object or array.
|
|
||||||
fd := fds.ByNumber(1)
|
|
||||||
return w.marshalValue(fd, m.Get(fd), indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
w.write("{")
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
firstField := true
|
|
||||||
if typeURL != "" {
|
|
||||||
if err := w.marshalTypeURL(indent, typeURL); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
firstField = false
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < fds.Len(); {
|
|
||||||
fd := fds.Get(i)
|
|
||||||
if od := fd.ContainingOneof(); od != nil {
|
|
||||||
fd = m.WhichOneof(od)
|
|
||||||
i += od.Fields().Len()
|
|
||||||
if fd == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
v := m.Get(fd)
|
|
||||||
|
|
||||||
if !m.Has(fd) {
|
|
||||||
if !w.EmitDefaults || fd.ContainingOneof() != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fd.Cardinality() != protoreflect.Repeated && (fd.Message() != nil || fd.Syntax() == protoreflect.Proto2) {
|
|
||||||
v = protoreflect.Value{} // use "null" for singular messages or proto2 scalars
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !firstField {
|
|
||||||
w.writeComma()
|
|
||||||
}
|
|
||||||
if err := w.marshalField(fd, v, indent); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
firstField = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle proto2 extensions.
|
|
||||||
if md.ExtensionRanges().Len() > 0 {
|
|
||||||
// Collect a sorted list of all extension descriptor and values.
|
|
||||||
type ext struct {
|
|
||||||
desc protoreflect.FieldDescriptor
|
|
||||||
val protoreflect.Value
|
|
||||||
}
|
|
||||||
var exts []ext
|
|
||||||
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
|
||||||
if fd.IsExtension() {
|
|
||||||
exts = append(exts, ext{fd, v})
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
sort.Slice(exts, func(i, j int) bool {
|
|
||||||
return exts[i].desc.Number() < exts[j].desc.Number()
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, ext := range exts {
|
|
||||||
if !firstField {
|
|
||||||
w.writeComma()
|
|
||||||
}
|
|
||||||
if err := w.marshalField(ext.desc, ext.val, indent); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
firstField = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
}
|
|
||||||
w.write("}")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) writeComma() {
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(",\n")
|
|
||||||
} else {
|
|
||||||
w.write(",")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) marshalAny(m protoreflect.Message, indent string) error {
|
|
||||||
// "If the Any contains a value that has a special JSON mapping,
|
|
||||||
// it will be converted as follows: {"@type": xxx, "value": yyy}.
|
|
||||||
// Otherwise, the value will be converted into a JSON object,
|
|
||||||
// and the "@type" field will be inserted to indicate the actual data type."
|
|
||||||
md := m.Descriptor()
|
|
||||||
typeURL := m.Get(md.Fields().ByNumber(1)).String()
|
|
||||||
rawVal := m.Get(md.Fields().ByNumber(2)).Bytes()
|
|
||||||
|
|
||||||
var m2 protoreflect.Message
|
|
||||||
if w.AnyResolver != nil {
|
|
||||||
mi, err := w.AnyResolver.Resolve(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m2 = proto.MessageReflect(mi)
|
|
||||||
} else {
|
|
||||||
mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m2 = mt.New()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := protoV2.Unmarshal(rawVal, m2.Interface()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if wellKnownType(m2.Descriptor().FullName()) == "" {
|
|
||||||
return w.marshalMessage(m2, indent, typeURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
w.write("{")
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
}
|
|
||||||
if err := w.marshalTypeURL(indent, typeURL); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.writeComma()
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
w.write(`"value": `)
|
|
||||||
} else {
|
|
||||||
w.write(`"value":`)
|
|
||||||
}
|
|
||||||
if err := w.marshalMessage(m2, indent+w.Indent, ""); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
}
|
|
||||||
w.write("}")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) marshalTypeURL(indent, typeURL string) error {
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
w.write(`"@type":`)
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(" ")
|
|
||||||
}
|
|
||||||
b, err := json.Marshal(typeURL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.write(string(b))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshalField writes field description and value to the Writer.
|
|
||||||
func (w *jsonWriter) marshalField(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error {
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
w.write(`"`)
|
|
||||||
switch {
|
|
||||||
case fd.IsExtension():
|
|
||||||
// For message set, use the fname of the message as the extension name.
|
|
||||||
name := string(fd.FullName())
|
|
||||||
if isMessageSet(fd.ContainingMessage()) {
|
|
||||||
name = strings.TrimSuffix(name, ".message_set_extension")
|
|
||||||
}
|
|
||||||
|
|
||||||
w.write("[" + name + "]")
|
|
||||||
case w.OrigName:
|
|
||||||
name := string(fd.Name())
|
|
||||||
if fd.Kind() == protoreflect.GroupKind {
|
|
||||||
name = string(fd.Message().Name())
|
|
||||||
}
|
|
||||||
w.write(name)
|
|
||||||
default:
|
|
||||||
w.write(string(fd.JSONName()))
|
|
||||||
}
|
|
||||||
w.write(`":`)
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(" ")
|
|
||||||
}
|
|
||||||
return w.marshalValue(fd, v, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) marshalValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error {
|
|
||||||
switch {
|
|
||||||
case fd.IsList():
|
|
||||||
w.write("[")
|
|
||||||
comma := ""
|
|
||||||
lv := v.List()
|
|
||||||
for i := 0; i < lv.Len(); i++ {
|
|
||||||
w.write(comma)
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
if err := w.marshalSingularValue(fd, lv.Get(i), indent+w.Indent); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
comma = ","
|
|
||||||
}
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
w.write("]")
|
|
||||||
return nil
|
|
||||||
case fd.IsMap():
|
|
||||||
kfd := fd.MapKey()
|
|
||||||
vfd := fd.MapValue()
|
|
||||||
mv := v.Map()
|
|
||||||
|
|
||||||
// Collect a sorted list of all map keys and values.
|
|
||||||
type entry struct{ key, val protoreflect.Value }
|
|
||||||
var entries []entry
|
|
||||||
mv.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
|
|
||||||
entries = append(entries, entry{k.Value(), v})
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
sort.Slice(entries, func(i, j int) bool {
|
|
||||||
switch kfd.Kind() {
|
|
||||||
case protoreflect.BoolKind:
|
|
||||||
return !entries[i].key.Bool() && entries[j].key.Bool()
|
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
|
||||||
return entries[i].key.Int() < entries[j].key.Int()
|
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
|
||||||
return entries[i].key.Uint() < entries[j].key.Uint()
|
|
||||||
case protoreflect.StringKind:
|
|
||||||
return entries[i].key.String() < entries[j].key.String()
|
|
||||||
default:
|
|
||||||
panic("invalid kind")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
w.write(`{`)
|
|
||||||
comma := ""
|
|
||||||
for _, entry := range entries {
|
|
||||||
w.write(comma)
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
s := fmt.Sprint(entry.key.Interface())
|
|
||||||
b, err := json.Marshal(s)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.write(string(b))
|
|
||||||
|
|
||||||
w.write(`:`)
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write(` `)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := w.marshalSingularValue(vfd, entry.val, indent+w.Indent); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
comma = ","
|
|
||||||
}
|
|
||||||
if w.Indent != "" {
|
|
||||||
w.write("\n")
|
|
||||||
w.write(indent)
|
|
||||||
w.write(w.Indent)
|
|
||||||
}
|
|
||||||
w.write(`}`)
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return w.marshalSingularValue(fd, v, indent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *jsonWriter) marshalSingularValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error {
|
|
||||||
switch {
|
|
||||||
case !v.IsValid():
|
|
||||||
w.write("null")
|
|
||||||
return nil
|
|
||||||
case fd.Message() != nil:
|
|
||||||
return w.marshalMessage(v.Message(), indent+w.Indent, "")
|
|
||||||
case fd.Enum() != nil:
|
|
||||||
if fd.Enum().FullName() == "google.protobuf.NullValue" {
|
|
||||||
w.write("null")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
vd := fd.Enum().Values().ByNumber(v.Enum())
|
|
||||||
if vd == nil || w.EnumsAsInts {
|
|
||||||
w.write(strconv.Itoa(int(v.Enum())))
|
|
||||||
} else {
|
|
||||||
w.write(`"` + string(vd.Name()) + `"`)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
switch v.Interface().(type) {
|
|
||||||
case float32, float64:
|
|
||||||
switch {
|
|
||||||
case math.IsInf(v.Float(), +1):
|
|
||||||
w.write(`"Infinity"`)
|
|
||||||
return nil
|
|
||||||
case math.IsInf(v.Float(), -1):
|
|
||||||
w.write(`"-Infinity"`)
|
|
||||||
return nil
|
|
||||||
case math.IsNaN(v.Float()):
|
|
||||||
w.write(`"NaN"`)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
case int64, uint64:
|
|
||||||
w.write(fmt.Sprintf(`"%d"`, v.Interface()))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := json.Marshal(v.Interface())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.write(string(b))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
69
vendor/github.com/golang/protobuf/jsonpb/json.go
generated
vendored
69
vendor/github.com/golang/protobuf/jsonpb/json.go
generated
vendored
@@ -1,69 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package jsonpb provides functionality to marshal and unmarshal between a
|
|
||||||
// protocol buffer message and JSON. It follows the specification at
|
|
||||||
// https://developers.google.com/protocol-buffers/docs/proto3#json.
|
|
||||||
//
|
|
||||||
// Do not rely on the default behavior of the standard encoding/json package
|
|
||||||
// when called on generated message types as it does not operate correctly.
|
|
||||||
//
|
|
||||||
// Deprecated: Use the "google.golang.org/protobuf/encoding/protojson"
|
|
||||||
// package instead.
|
|
||||||
package jsonpb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AnyResolver takes a type URL, present in an Any message,
|
|
||||||
// and resolves it into an instance of the associated message.
|
|
||||||
type AnyResolver interface {
|
|
||||||
Resolve(typeURL string) (proto.Message, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type anyResolver struct{ AnyResolver }
|
|
||||||
|
|
||||||
func (r anyResolver) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error) {
|
|
||||||
return r.FindMessageByURL(string(message))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r anyResolver) FindMessageByURL(url string) (protoreflect.MessageType, error) {
|
|
||||||
m, err := r.Resolve(url)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return protoimpl.X.MessageTypeOf(m), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r anyResolver) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) {
|
|
||||||
return protoregistry.GlobalTypes.FindExtensionByName(field)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r anyResolver) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
|
|
||||||
return protoregistry.GlobalTypes.FindExtensionByNumber(message, field)
|
|
||||||
}
|
|
||||||
|
|
||||||
func wellKnownType(s protoreflect.FullName) string {
|
|
||||||
if s.Parent() == "google.protobuf" {
|
|
||||||
switch s.Name() {
|
|
||||||
case "Empty", "Any",
|
|
||||||
"BoolValue", "BytesValue", "StringValue",
|
|
||||||
"Int32Value", "UInt32Value", "FloatValue",
|
|
||||||
"Int64Value", "UInt64Value", "DoubleValue",
|
|
||||||
"Duration", "Timestamp",
|
|
||||||
"NullValue", "Struct", "Value", "ListValue":
|
|
||||||
return string(s.Name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func isMessageSet(md protoreflect.MessageDescriptor) bool {
|
|
||||||
ms, ok := md.(interface{ IsMessageSet() bool })
|
|
||||||
return ok && ms.IsMessageSet()
|
|
||||||
}
|
|
||||||
20
vendor/github.com/google/uuid/CHANGELOG.md
generated
vendored
20
vendor/github.com/google/uuid/CHANGELOG.md
generated
vendored
@@ -1,5 +1,25 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.6.0](https://github.com/google/uuid/compare/v1.5.0...v1.6.0) (2024-01-16)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add Max UUID constant ([#149](https://github.com/google/uuid/issues/149)) ([c58770e](https://github.com/google/uuid/commit/c58770eb495f55fe2ced6284f93c5158a62e53e3))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix typo in version 7 uuid documentation ([#153](https://github.com/google/uuid/issues/153)) ([016b199](https://github.com/google/uuid/commit/016b199544692f745ffc8867b914129ecb47ef06))
|
||||||
|
* Monotonicity in UUIDv7 ([#150](https://github.com/google/uuid/issues/150)) ([a2b2b32](https://github.com/google/uuid/commit/a2b2b32373ff0b1a312b7fdf6d38a977099698a6))
|
||||||
|
|
||||||
|
## [1.5.0](https://github.com/google/uuid/compare/v1.4.0...v1.5.0) (2023-12-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Validate UUID without creating new UUID ([#141](https://github.com/google/uuid/issues/141)) ([9ee7366](https://github.com/google/uuid/commit/9ee7366e66c9ad96bab89139418a713dc584ae29))
|
||||||
|
|
||||||
## [1.4.0](https://github.com/google/uuid/compare/v1.3.1...v1.4.0) (2023-10-26)
|
## [1.4.0](https://github.com/google/uuid/compare/v1.3.1...v1.4.0) (2023-10-26)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
vendor/github.com/google/uuid/hash.go
generated
vendored
6
vendor/github.com/google/uuid/hash.go
generated
vendored
@@ -17,6 +17,12 @@ var (
|
|||||||
NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
|
NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
|
NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
Nil UUID // empty UUID, all zeros
|
Nil UUID // empty UUID, all zeros
|
||||||
|
|
||||||
|
// The Max UUID is special form of UUID that is specified to have all 128 bits set to 1.
|
||||||
|
Max = UUID{
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHash returns a new UUID derived from the hash of space concatenated with
|
// NewHash returns a new UUID derived from the hash of space concatenated with
|
||||||
|
|||||||
21
vendor/github.com/google/uuid/time.go
generated
vendored
21
vendor/github.com/google/uuid/time.go
generated
vendored
@@ -108,12 +108,23 @@ func setClockSequence(seq int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
|
// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
|
||||||
// uuid. The time is only defined for version 1 and 2 UUIDs.
|
// uuid. The time is only defined for version 1, 2, 6 and 7 UUIDs.
|
||||||
func (uuid UUID) Time() Time {
|
func (uuid UUID) Time() Time {
|
||||||
time := int64(binary.BigEndian.Uint32(uuid[0:4]))
|
var t Time
|
||||||
time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
|
switch uuid.Version() {
|
||||||
time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
|
case 6:
|
||||||
return Time(time)
|
time := binary.BigEndian.Uint64(uuid[:8]) // Ignore uuid[6] version b0110
|
||||||
|
t = Time(time)
|
||||||
|
case 7:
|
||||||
|
time := binary.BigEndian.Uint64(uuid[:8])
|
||||||
|
t = Time((time>>16)*10000 + g1582ns100)
|
||||||
|
default: // forward compatible
|
||||||
|
time := int64(binary.BigEndian.Uint32(uuid[0:4]))
|
||||||
|
time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
|
||||||
|
time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
|
||||||
|
t = Time(time)
|
||||||
|
}
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClockSequence returns the clock sequence encoded in uuid.
|
// ClockSequence returns the clock sequence encoded in uuid.
|
||||||
|
|||||||
53
vendor/github.com/google/uuid/uuid.go
generated
vendored
53
vendor/github.com/google/uuid/uuid.go
generated
vendored
@@ -186,6 +186,59 @@ func Must(uuid UUID, err error) UUID {
|
|||||||
return uuid
|
return uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate returns an error if s is not a properly formatted UUID in one of the following formats:
|
||||||
|
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||||
|
// It returns an error if the format is invalid, otherwise nil.
|
||||||
|
func Validate(s string) error {
|
||||||
|
switch len(s) {
|
||||||
|
// Standard UUID format
|
||||||
|
case 36:
|
||||||
|
|
||||||
|
// UUID with "urn:uuid:" prefix
|
||||||
|
case 36 + 9:
|
||||||
|
if !strings.EqualFold(s[:9], "urn:uuid:") {
|
||||||
|
return fmt.Errorf("invalid urn prefix: %q", s[:9])
|
||||||
|
}
|
||||||
|
s = s[9:]
|
||||||
|
|
||||||
|
// UUID enclosed in braces
|
||||||
|
case 36 + 2:
|
||||||
|
if s[0] != '{' || s[len(s)-1] != '}' {
|
||||||
|
return fmt.Errorf("invalid bracketed UUID format")
|
||||||
|
}
|
||||||
|
s = s[1 : len(s)-1]
|
||||||
|
|
||||||
|
// UUID without hyphens
|
||||||
|
case 32:
|
||||||
|
for i := 0; i < len(s); i += 2 {
|
||||||
|
_, ok := xtob(s[i], s[i+1])
|
||||||
|
if !ok {
|
||||||
|
return errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return invalidLengthError{len(s)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for standard UUID format
|
||||||
|
if len(s) == 36 {
|
||||||
|
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
|
||||||
|
return errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} {
|
||||||
|
if _, ok := xtob(s[x], s[x+1]); !ok {
|
||||||
|
return errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
// , or "" if uuid is invalid.
|
// , or "" if uuid is invalid.
|
||||||
func (uuid UUID) String() string {
|
func (uuid UUID) String() string {
|
||||||
|
|||||||
56
vendor/github.com/google/uuid/version6.go
generated
vendored
Normal file
56
vendor/github.com/google/uuid/version6.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import "encoding/binary"
|
||||||
|
|
||||||
|
// UUID version 6 is a field-compatible version of UUIDv1, reordered for improved DB locality.
|
||||||
|
// It is expected that UUIDv6 will primarily be used in contexts where there are existing v1 UUIDs.
|
||||||
|
// Systems that do not involve legacy UUIDv1 SHOULD consider using UUIDv7 instead.
|
||||||
|
//
|
||||||
|
// see https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#uuidv6
|
||||||
|
//
|
||||||
|
// NewV6 returns a Version 6 UUID based on the current NodeID and clock
|
||||||
|
// sequence, and the current time. If the NodeID has not been set by SetNodeID
|
||||||
|
// or SetNodeInterface then it will be set automatically. If the NodeID cannot
|
||||||
|
// be set NewV6 set NodeID is random bits automatically . If clock sequence has not been set by
|
||||||
|
// SetClockSequence then it will be set automatically. If GetTime fails to
|
||||||
|
// return the current NewV6 returns Nil and an error.
|
||||||
|
func NewV6() (UUID, error) {
|
||||||
|
var uuid UUID
|
||||||
|
now, seq, err := GetTime()
|
||||||
|
if err != nil {
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
0 1 2 3
|
||||||
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| time_high |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| time_mid | time_low_and_version |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|clk_seq_hi_res | clk_seq_low | node (0-1) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| node (2-5) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
|
||||||
|
binary.BigEndian.PutUint64(uuid[0:], uint64(now))
|
||||||
|
binary.BigEndian.PutUint16(uuid[8:], seq)
|
||||||
|
|
||||||
|
uuid[6] = 0x60 | (uuid[6] & 0x0F)
|
||||||
|
uuid[8] = 0x80 | (uuid[8] & 0x3F)
|
||||||
|
|
||||||
|
nodeMu.Lock()
|
||||||
|
if nodeID == zeroID {
|
||||||
|
setNodeInterface("")
|
||||||
|
}
|
||||||
|
copy(uuid[10:], nodeID[:])
|
||||||
|
nodeMu.Unlock()
|
||||||
|
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
104
vendor/github.com/google/uuid/version7.go
generated
vendored
Normal file
104
vendor/github.com/google/uuid/version7.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UUID version 7 features a time-ordered value field derived from the widely
|
||||||
|
// implemented and well known Unix Epoch timestamp source,
|
||||||
|
// the number of milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded.
|
||||||
|
// As well as improved entropy characteristics over versions 1 or 6.
|
||||||
|
//
|
||||||
|
// see https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#name-uuid-version-7
|
||||||
|
//
|
||||||
|
// Implementations SHOULD utilize UUID version 7 over UUID version 1 and 6 if possible.
|
||||||
|
//
|
||||||
|
// NewV7 returns a Version 7 UUID based on the current time(Unix Epoch).
|
||||||
|
// Uses the randomness pool if it was enabled with EnableRandPool.
|
||||||
|
// On error, NewV7 returns Nil and an error
|
||||||
|
func NewV7() (UUID, error) {
|
||||||
|
uuid, err := NewRandom()
|
||||||
|
if err != nil {
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
makeV7(uuid[:])
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewV7FromReader returns a Version 7 UUID based on the current time(Unix Epoch).
|
||||||
|
// it use NewRandomFromReader fill random bits.
|
||||||
|
// On error, NewV7FromReader returns Nil and an error.
|
||||||
|
func NewV7FromReader(r io.Reader) (UUID, error) {
|
||||||
|
uuid, err := NewRandomFromReader(r)
|
||||||
|
if err != nil {
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
makeV7(uuid[:])
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// makeV7 fill 48 bits time (uuid[0] - uuid[5]), set version b0111 (uuid[6])
|
||||||
|
// uuid[8] already has the right version number (Variant is 10)
|
||||||
|
// see function NewV7 and NewV7FromReader
|
||||||
|
func makeV7(uuid []byte) {
|
||||||
|
/*
|
||||||
|
0 1 2 3
|
||||||
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| unix_ts_ms |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| unix_ts_ms | ver | rand_a (12 bit seq) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|var| rand_b |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| rand_b |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
_ = uuid[15] // bounds check
|
||||||
|
|
||||||
|
t, s := getV7Time()
|
||||||
|
|
||||||
|
uuid[0] = byte(t >> 40)
|
||||||
|
uuid[1] = byte(t >> 32)
|
||||||
|
uuid[2] = byte(t >> 24)
|
||||||
|
uuid[3] = byte(t >> 16)
|
||||||
|
uuid[4] = byte(t >> 8)
|
||||||
|
uuid[5] = byte(t)
|
||||||
|
|
||||||
|
uuid[6] = 0x70 | (0x0F & byte(s>>8))
|
||||||
|
uuid[7] = byte(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// lastV7time is the last time we returned stored as:
|
||||||
|
//
|
||||||
|
// 52 bits of time in milliseconds since epoch
|
||||||
|
// 12 bits of (fractional nanoseconds) >> 8
|
||||||
|
var lastV7time int64
|
||||||
|
|
||||||
|
const nanoPerMilli = 1000000
|
||||||
|
|
||||||
|
// getV7Time returns the time in milliseconds and nanoseconds / 256.
|
||||||
|
// The returned (milli << 12 + seq) is guarenteed to be greater than
|
||||||
|
// (milli << 12 + seq) returned by any previous call to getV7Time.
|
||||||
|
func getV7Time() (milli, seq int64) {
|
||||||
|
timeMu.Lock()
|
||||||
|
defer timeMu.Unlock()
|
||||||
|
|
||||||
|
nano := timeNow().UnixNano()
|
||||||
|
milli = nano / nanoPerMilli
|
||||||
|
// Sequence number is between 0 and 3906 (nanoPerMilli>>8)
|
||||||
|
seq = (nano - milli*nanoPerMilli) >> 8
|
||||||
|
now := milli<<12 + seq
|
||||||
|
if now <= lastV7time {
|
||||||
|
now = lastV7time + 1
|
||||||
|
milli = now >> 12
|
||||||
|
seq = now & 0xfff
|
||||||
|
}
|
||||||
|
lastV7time = now
|
||||||
|
return milli, seq
|
||||||
|
}
|
||||||
195
vendor/github.com/prometheus/client_model/go/metrics.pb.go
generated
vendored
195
vendor/github.com/prometheus/client_model/go/metrics.pb.go
generated
vendored
@@ -483,6 +483,8 @@ type Histogram struct {
|
|||||||
// histograms.
|
// histograms.
|
||||||
PositiveDelta []int64 `protobuf:"zigzag64,13,rep,name=positive_delta,json=positiveDelta" json:"positive_delta,omitempty"` // Count delta of each bucket compared to previous one (or to zero for 1st bucket).
|
PositiveDelta []int64 `protobuf:"zigzag64,13,rep,name=positive_delta,json=positiveDelta" json:"positive_delta,omitempty"` // Count delta of each bucket compared to previous one (or to zero for 1st bucket).
|
||||||
PositiveCount []float64 `protobuf:"fixed64,14,rep,name=positive_count,json=positiveCount" json:"positive_count,omitempty"` // Absolute count of each bucket.
|
PositiveCount []float64 `protobuf:"fixed64,14,rep,name=positive_count,json=positiveCount" json:"positive_count,omitempty"` // Absolute count of each bucket.
|
||||||
|
// Only used for native histograms. These exemplars MUST have a timestamp.
|
||||||
|
Exemplars []*Exemplar `protobuf:"bytes,16,rep,name=exemplars" json:"exemplars,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Histogram) Reset() {
|
func (x *Histogram) Reset() {
|
||||||
@@ -622,6 +624,13 @@ func (x *Histogram) GetPositiveCount() []float64 {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Histogram) GetExemplars() []*Exemplar {
|
||||||
|
if x != nil {
|
||||||
|
return x.Exemplars
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// A Bucket of a conventional histogram, each of which is treated as
|
// A Bucket of a conventional histogram, each of which is treated as
|
||||||
// an individual counter-like time series by Prometheus.
|
// an individual counter-like time series by Prometheus.
|
||||||
type Bucket struct {
|
type Bucket struct {
|
||||||
@@ -923,6 +932,7 @@ type MetricFamily struct {
|
|||||||
Help *string `protobuf:"bytes,2,opt,name=help" json:"help,omitempty"`
|
Help *string `protobuf:"bytes,2,opt,name=help" json:"help,omitempty"`
|
||||||
Type *MetricType `protobuf:"varint,3,opt,name=type,enum=io.prometheus.client.MetricType" json:"type,omitempty"`
|
Type *MetricType `protobuf:"varint,3,opt,name=type,enum=io.prometheus.client.MetricType" json:"type,omitempty"`
|
||||||
Metric []*Metric `protobuf:"bytes,4,rep,name=metric" json:"metric,omitempty"`
|
Metric []*Metric `protobuf:"bytes,4,rep,name=metric" json:"metric,omitempty"`
|
||||||
|
Unit *string `protobuf:"bytes,5,opt,name=unit" json:"unit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *MetricFamily) Reset() {
|
func (x *MetricFamily) Reset() {
|
||||||
@@ -985,6 +995,13 @@ func (x *MetricFamily) GetMetric() []*Metric {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *MetricFamily) GetUnit() string {
|
||||||
|
if x != nil && x.Unit != nil {
|
||||||
|
return *x.Unit
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
var File_io_prometheus_client_metrics_proto protoreflect.FileDescriptor
|
var File_io_prometheus_client_metrics_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_io_prometheus_client_metrics_proto_rawDesc = []byte{
|
var file_io_prometheus_client_metrics_proto_rawDesc = []byte{
|
||||||
@@ -1028,7 +1045,7 @@ var file_io_prometheus_client_metrics_proto_rawDesc = []byte{
|
|||||||
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
||||||
0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x1f, 0x0a, 0x07, 0x55, 0x6e, 0x74,
|
0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x1f, 0x0a, 0x07, 0x55, 0x6e, 0x74,
|
||||||
0x79, 0x70, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20,
|
0x79, 0x70, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20,
|
||||||
0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xac, 0x05, 0x0a, 0x09, 0x48,
|
0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xea, 0x05, 0x0a, 0x09, 0x48,
|
||||||
0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x61, 0x6d, 0x70,
|
0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x61, 0x6d, 0x70,
|
||||||
0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b,
|
0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b,
|
||||||
0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2c, 0x0a, 0x12, 0x73,
|
0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2c, 0x0a, 0x12, 0x73,
|
||||||
@@ -1071,79 +1088,84 @@ var file_io_prometheus_client_metrics_proto_rawDesc = []byte{
|
|||||||
0x03, 0x28, 0x12, 0x52, 0x0d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x44, 0x65, 0x6c,
|
0x03, 0x28, 0x12, 0x52, 0x0d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x44, 0x65, 0x6c,
|
||||||
0x74, 0x61, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x63,
|
0x74, 0x61, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x63,
|
||||||
0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0e, 0x20, 0x03, 0x28, 0x01, 0x52, 0x0d, 0x70, 0x6f, 0x73, 0x69,
|
0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0e, 0x20, 0x03, 0x28, 0x01, 0x52, 0x0d, 0x70, 0x6f, 0x73, 0x69,
|
||||||
0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xc6, 0x01, 0x0a, 0x06, 0x42, 0x75,
|
0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x3c, 0x0a, 0x09, 0x65, 0x78, 0x65,
|
||||||
0x63, 0x6b, 0x65, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69,
|
0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x18, 0x10, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x69,
|
||||||
0x76, 0x65, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f,
|
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69,
|
||||||
0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12,
|
0x65, 0x6e, 0x74, 0x2e, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x09, 0x65, 0x78,
|
||||||
0x34, 0x0a, 0x16, 0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x63, 0x6f,
|
0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x22, 0xc6, 0x01, 0x0a, 0x06, 0x42, 0x75, 0x63, 0x6b,
|
||||||
0x75, 0x6e, 0x74, 0x5f, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x01, 0x52,
|
0x65, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65,
|
||||||
0x14, 0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74,
|
0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x63, 0x75,
|
||||||
0x46, 0x6c, 0x6f, 0x61, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x75, 0x70, 0x70, 0x65, 0x72, 0x5f, 0x62,
|
0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a,
|
||||||
0x6f, 0x75, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0a, 0x75, 0x70, 0x70, 0x65,
|
0x16, 0x63, 0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x63, 0x6f, 0x75, 0x6e,
|
||||||
0x72, 0x42, 0x6f, 0x75, 0x6e, 0x64, 0x12, 0x3a, 0x0a, 0x08, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c,
|
0x74, 0x5f, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x01, 0x52, 0x14, 0x63,
|
||||||
0x61, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72,
|
0x75, 0x6d, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x46, 0x6c,
|
||||||
0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e,
|
0x6f, 0x61, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x75, 0x70, 0x70, 0x65, 0x72, 0x5f, 0x62, 0x6f, 0x75,
|
||||||
0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x08, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c,
|
0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0a, 0x75, 0x70, 0x70, 0x65, 0x72, 0x42,
|
||||||
0x61, 0x72, 0x22, 0x3c, 0x0a, 0x0a, 0x42, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x70, 0x61, 0x6e,
|
0x6f, 0x75, 0x6e, 0x64, 0x12, 0x3a, 0x0a, 0x08, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72,
|
||||||
0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x11,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d,
|
||||||
0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67,
|
0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x45, 0x78,
|
||||||
0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,
|
0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x08, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72,
|
||||||
0x22, 0x91, 0x01, 0x0a, 0x08, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x12, 0x35, 0x0a,
|
0x22, 0x3c, 0x0a, 0x0a, 0x42, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x16,
|
||||||
|
0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x11, 0x52, 0x06,
|
||||||
|
0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,
|
||||||
|
0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x91,
|
||||||
|
0x01, 0x0a, 0x08, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x12, 0x35, 0x0a, 0x05, 0x6c,
|
||||||
|
0x61, 0x62, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6f, 0x2e,
|
||||||
|
0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||||
|
0x74, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, 0x6c, 0x61, 0x62,
|
||||||
|
0x65, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
|
0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65,
|
||||||
|
0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f,
|
||||||
|
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69,
|
||||||
|
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
|
||||||
|
0x6d, 0x70, 0x22, 0xff, 0x02, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x35, 0x0a,
|
||||||
0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69,
|
0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69,
|
||||||
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69,
|
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69,
|
||||||
0x65, 0x6e, 0x74, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, 0x6c,
|
0x65, 0x6e, 0x74, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, 0x6c,
|
||||||
0x61, 0x62, 0x65, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
|
0x61, 0x62, 0x65, 0x6c, 0x12, 0x31, 0x0a, 0x05, 0x67, 0x61, 0x75, 0x67, 0x65, 0x18, 0x02, 0x20,
|
||||||
0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69,
|
0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68,
|
||||||
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e,
|
0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x47, 0x61, 0x75, 0x67, 0x65,
|
||||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
0x52, 0x05, 0x67, 0x61, 0x75, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74,
|
||||||
0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73,
|
0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72,
|
||||||
0x74, 0x61, 0x6d, 0x70, 0x22, 0xff, 0x02, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12,
|
0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e,
|
||||||
0x35, 0x0a, 0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f,
|
0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72,
|
||||||
0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63,
|
0x12, 0x37, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x50, 0x61, 0x69, 0x72, 0x52,
|
0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75,
|
||||||
0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x12, 0x31, 0x0a, 0x05, 0x67, 0x61, 0x75, 0x67, 0x65, 0x18,
|
0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79,
|
||||||
0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65,
|
0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x37, 0x0a, 0x07, 0x75, 0x6e, 0x74,
|
||||||
0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x47, 0x61, 0x75,
|
0x79, 0x70, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6f, 0x2e,
|
||||||
0x67, 0x65, 0x52, 0x05, 0x67, 0x61, 0x75, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x07, 0x63, 0x6f, 0x75,
|
|
||||||
0x6e, 0x74, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6f, 0x2e,
|
|
||||||
0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||||
0x74, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74,
|
0x74, 0x2e, 0x55, 0x6e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x52, 0x07, 0x75, 0x6e, 0x74, 0x79, 0x70,
|
||||||
0x65, 0x72, 0x12, 0x37, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x04, 0x20,
|
0x65, 0x64, 0x12, 0x3d, 0x0a, 0x09, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x18,
|
||||||
0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68,
|
0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65,
|
||||||
0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61,
|
0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x48, 0x69, 0x73,
|
||||||
0x72, 0x79, 0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x37, 0x0a, 0x07, 0x75,
|
0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x52, 0x09, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61,
|
||||||
0x6e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69,
|
0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x5f, 0x6d,
|
||||||
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69,
|
0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
|
||||||
0x65, 0x6e, 0x74, 0x2e, 0x55, 0x6e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x52, 0x07, 0x75, 0x6e, 0x74,
|
0x6d, 0x70, 0x4d, 0x73, 0x22, 0xb6, 0x01, 0x0a, 0x0c, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x46,
|
||||||
0x79, 0x70, 0x65, 0x64, 0x12, 0x3d, 0x0a, 0x09, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61,
|
0x61, 0x6d, 0x69, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
|
||||||
0x6d, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f,
|
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x65, 0x6c,
|
||||||
0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x48,
|
0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x65, 0x6c, 0x70, 0x12, 0x34, 0x0a,
|
||||||
0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x52, 0x09, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67,
|
0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x20, 0x2e, 0x69, 0x6f,
|
||||||
0x72, 0x61, 0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
|
0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65,
|
||||||
0x5f, 0x6d, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x74, 0x69, 0x6d, 0x65, 0x73,
|
0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74,
|
||||||
0x74, 0x61, 0x6d, 0x70, 0x4d, 0x73, 0x22, 0xa2, 0x01, 0x0a, 0x0c, 0x4d, 0x65, 0x74, 0x72, 0x69,
|
0x79, 0x70, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x04, 0x20,
|
||||||
0x63, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
|
0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68,
|
||||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68,
|
0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69,
|
||||||
0x65, 0x6c, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x65, 0x6c, 0x70, 0x12,
|
0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69,
|
||||||
0x34, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x20, 0x2e,
|
0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x2a, 0x62, 0x0a,
|
||||||
0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c,
|
0x0a, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x43,
|
||||||
0x69, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x52,
|
0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x41, 0x55, 0x47,
|
||||||
0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18,
|
0x45, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x4d, 0x4d, 0x41, 0x52, 0x59, 0x10, 0x02,
|
||||||
0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65,
|
0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x54, 0x59, 0x50, 0x45, 0x44, 0x10, 0x03, 0x12, 0x0d, 0x0a,
|
||||||
0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74,
|
0x09, 0x48, 0x49, 0x53, 0x54, 0x4f, 0x47, 0x52, 0x41, 0x4d, 0x10, 0x04, 0x12, 0x13, 0x0a, 0x0f,
|
||||||
0x72, 0x69, 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x2a, 0x62, 0x0a, 0x0a, 0x4d,
|
0x47, 0x41, 0x55, 0x47, 0x45, 0x5f, 0x48, 0x49, 0x53, 0x54, 0x4f, 0x47, 0x52, 0x41, 0x4d, 0x10,
|
||||||
0x65, 0x74, 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x4f, 0x55,
|
0x05, 0x42, 0x52, 0x0a, 0x14, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65,
|
||||||
0x4e, 0x54, 0x45, 0x52, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x41, 0x55, 0x47, 0x45, 0x10,
|
0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75,
|
||||||
0x01, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x4d, 0x4d, 0x41, 0x52, 0x59, 0x10, 0x02, 0x12, 0x0b,
|
0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73,
|
||||||
0x0a, 0x07, 0x55, 0x4e, 0x54, 0x59, 0x50, 0x45, 0x44, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x48,
|
0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x67, 0x6f,
|
||||||
0x49, 0x53, 0x54, 0x4f, 0x47, 0x52, 0x41, 0x4d, 0x10, 0x04, 0x12, 0x13, 0x0a, 0x0f, 0x47, 0x41,
|
0x3b, 0x69, 0x6f, 0x5f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x5f, 0x63,
|
||||||
0x55, 0x47, 0x45, 0x5f, 0x48, 0x49, 0x53, 0x54, 0x4f, 0x47, 0x52, 0x41, 0x4d, 0x10, 0x05, 0x42,
|
0x6c, 0x69, 0x65, 0x6e, 0x74,
|
||||||
0x52, 0x0a, 0x14, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73,
|
|
||||||
0x2e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
|
||||||
0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2f, 0x63,
|
|
||||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x67, 0x6f, 0x3b, 0x69,
|
|
||||||
0x6f, 0x5f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x5f, 0x63, 0x6c, 0x69,
|
|
||||||
0x65, 0x6e, 0x74,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -1185,22 +1207,23 @@ var file_io_prometheus_client_metrics_proto_depIdxs = []int32{
|
|||||||
13, // 5: io.prometheus.client.Histogram.created_timestamp:type_name -> google.protobuf.Timestamp
|
13, // 5: io.prometheus.client.Histogram.created_timestamp:type_name -> google.protobuf.Timestamp
|
||||||
9, // 6: io.prometheus.client.Histogram.negative_span:type_name -> io.prometheus.client.BucketSpan
|
9, // 6: io.prometheus.client.Histogram.negative_span:type_name -> io.prometheus.client.BucketSpan
|
||||||
9, // 7: io.prometheus.client.Histogram.positive_span:type_name -> io.prometheus.client.BucketSpan
|
9, // 7: io.prometheus.client.Histogram.positive_span:type_name -> io.prometheus.client.BucketSpan
|
||||||
10, // 8: io.prometheus.client.Bucket.exemplar:type_name -> io.prometheus.client.Exemplar
|
10, // 8: io.prometheus.client.Histogram.exemplars:type_name -> io.prometheus.client.Exemplar
|
||||||
1, // 9: io.prometheus.client.Exemplar.label:type_name -> io.prometheus.client.LabelPair
|
10, // 9: io.prometheus.client.Bucket.exemplar:type_name -> io.prometheus.client.Exemplar
|
||||||
13, // 10: io.prometheus.client.Exemplar.timestamp:type_name -> google.protobuf.Timestamp
|
1, // 10: io.prometheus.client.Exemplar.label:type_name -> io.prometheus.client.LabelPair
|
||||||
1, // 11: io.prometheus.client.Metric.label:type_name -> io.prometheus.client.LabelPair
|
13, // 11: io.prometheus.client.Exemplar.timestamp:type_name -> google.protobuf.Timestamp
|
||||||
2, // 12: io.prometheus.client.Metric.gauge:type_name -> io.prometheus.client.Gauge
|
1, // 12: io.prometheus.client.Metric.label:type_name -> io.prometheus.client.LabelPair
|
||||||
3, // 13: io.prometheus.client.Metric.counter:type_name -> io.prometheus.client.Counter
|
2, // 13: io.prometheus.client.Metric.gauge:type_name -> io.prometheus.client.Gauge
|
||||||
5, // 14: io.prometheus.client.Metric.summary:type_name -> io.prometheus.client.Summary
|
3, // 14: io.prometheus.client.Metric.counter:type_name -> io.prometheus.client.Counter
|
||||||
6, // 15: io.prometheus.client.Metric.untyped:type_name -> io.prometheus.client.Untyped
|
5, // 15: io.prometheus.client.Metric.summary:type_name -> io.prometheus.client.Summary
|
||||||
7, // 16: io.prometheus.client.Metric.histogram:type_name -> io.prometheus.client.Histogram
|
6, // 16: io.prometheus.client.Metric.untyped:type_name -> io.prometheus.client.Untyped
|
||||||
0, // 17: io.prometheus.client.MetricFamily.type:type_name -> io.prometheus.client.MetricType
|
7, // 17: io.prometheus.client.Metric.histogram:type_name -> io.prometheus.client.Histogram
|
||||||
11, // 18: io.prometheus.client.MetricFamily.metric:type_name -> io.prometheus.client.Metric
|
0, // 18: io.prometheus.client.MetricFamily.type:type_name -> io.prometheus.client.MetricType
|
||||||
19, // [19:19] is the sub-list for method output_type
|
11, // 19: io.prometheus.client.MetricFamily.metric:type_name -> io.prometheus.client.Metric
|
||||||
19, // [19:19] is the sub-list for method input_type
|
20, // [20:20] is the sub-list for method output_type
|
||||||
19, // [19:19] is the sub-list for extension type_name
|
20, // [20:20] is the sub-list for method input_type
|
||||||
19, // [19:19] is the sub-list for extension extendee
|
20, // [20:20] is the sub-list for extension type_name
|
||||||
0, // [0:19] is the sub-list for field type_name
|
20, // [20:20] is the sub-list for extension extendee
|
||||||
|
0, // [0:20] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_io_prometheus_client_metrics_proto_init() }
|
func init() { file_io_prometheus_client_metrics_proto_init() }
|
||||||
|
|||||||
18
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
18
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
@@ -45,7 +45,7 @@ func ResponseFormat(h http.Header) Format {
|
|||||||
|
|
||||||
mediatype, params, err := mime.ParseMediaType(ct)
|
mediatype, params, err := mime.ParseMediaType(ct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return FmtUnknown
|
return fmtUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
const textType = "text/plain"
|
const textType = "text/plain"
|
||||||
@@ -53,28 +53,28 @@ func ResponseFormat(h http.Header) Format {
|
|||||||
switch mediatype {
|
switch mediatype {
|
||||||
case ProtoType:
|
case ProtoType:
|
||||||
if p, ok := params["proto"]; ok && p != ProtoProtocol {
|
if p, ok := params["proto"]; ok && p != ProtoProtocol {
|
||||||
return FmtUnknown
|
return fmtUnknown
|
||||||
}
|
}
|
||||||
if e, ok := params["encoding"]; ok && e != "delimited" {
|
if e, ok := params["encoding"]; ok && e != "delimited" {
|
||||||
return FmtUnknown
|
return fmtUnknown
|
||||||
}
|
}
|
||||||
return FmtProtoDelim
|
return fmtProtoDelim
|
||||||
|
|
||||||
case textType:
|
case textType:
|
||||||
if v, ok := params["version"]; ok && v != TextVersion {
|
if v, ok := params["version"]; ok && v != TextVersion {
|
||||||
return FmtUnknown
|
return fmtUnknown
|
||||||
}
|
}
|
||||||
return FmtText
|
return fmtText
|
||||||
}
|
}
|
||||||
|
|
||||||
return FmtUnknown
|
return fmtUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDecoder returns a new decoder based on the given input format.
|
// NewDecoder returns a new decoder based on the given input format.
|
||||||
// If the input format does not imply otherwise, a text format decoder is returned.
|
// If the input format does not imply otherwise, a text format decoder is returned.
|
||||||
func NewDecoder(r io.Reader, format Format) Decoder {
|
func NewDecoder(r io.Reader, format Format) Decoder {
|
||||||
switch format {
|
switch format.FormatType() {
|
||||||
case FmtProtoDelim:
|
case TypeProtoDelim:
|
||||||
return &protoDecoder{r: r}
|
return &protoDecoder{r: r}
|
||||||
}
|
}
|
||||||
return &textDecoder{r: r}
|
return &textDecoder{r: r}
|
||||||
|
|||||||
71
vendor/github.com/prometheus/common/expfmt/encode.go
generated
vendored
71
vendor/github.com/prometheus/common/expfmt/encode.go
generated
vendored
@@ -22,6 +22,7 @@ import (
|
|||||||
"google.golang.org/protobuf/encoding/prototext"
|
"google.golang.org/protobuf/encoding/prototext"
|
||||||
|
|
||||||
"github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg"
|
"github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg"
|
||||||
|
"github.com/prometheus/common/model"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
@@ -61,23 +62,32 @@ func (ec encoderCloser) Close() error {
|
|||||||
// as the support is still experimental. To include the option to negotiate
|
// as the support is still experimental. To include the option to negotiate
|
||||||
// FmtOpenMetrics, use NegotiateOpenMetrics.
|
// FmtOpenMetrics, use NegotiateOpenMetrics.
|
||||||
func Negotiate(h http.Header) Format {
|
func Negotiate(h http.Header) Format {
|
||||||
|
escapingScheme := Format(fmt.Sprintf("; escaping=%s", Format(model.NameEscapingScheme.String())))
|
||||||
for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) {
|
for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) {
|
||||||
|
if escapeParam := ac.Params[model.EscapingKey]; escapeParam != "" {
|
||||||
|
switch Format(escapeParam) {
|
||||||
|
case model.AllowUTF8, model.EscapeUnderscores, model.EscapeDots, model.EscapeValues:
|
||||||
|
escapingScheme = Format(fmt.Sprintf("; escaping=%s", escapeParam))
|
||||||
|
default:
|
||||||
|
// If the escaping parameter is unknown, ignore it.
|
||||||
|
}
|
||||||
|
}
|
||||||
ver := ac.Params["version"]
|
ver := ac.Params["version"]
|
||||||
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
|
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
|
||||||
switch ac.Params["encoding"] {
|
switch ac.Params["encoding"] {
|
||||||
case "delimited":
|
case "delimited":
|
||||||
return FmtProtoDelim
|
return fmtProtoDelim + escapingScheme
|
||||||
case "text":
|
case "text":
|
||||||
return FmtProtoText
|
return fmtProtoText + escapingScheme
|
||||||
case "compact-text":
|
case "compact-text":
|
||||||
return FmtProtoCompact
|
return fmtProtoCompact + escapingScheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
|
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
|
||||||
return FmtText
|
return fmtText + escapingScheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FmtText
|
return fmtText + escapingScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
// NegotiateIncludingOpenMetrics works like Negotiate but includes
|
// NegotiateIncludingOpenMetrics works like Negotiate but includes
|
||||||
@@ -85,29 +95,40 @@ func Negotiate(h http.Header) Format {
|
|||||||
// temporary and will disappear once FmtOpenMetrics is fully supported and as
|
// temporary and will disappear once FmtOpenMetrics is fully supported and as
|
||||||
// such may be negotiated by the normal Negotiate function.
|
// such may be negotiated by the normal Negotiate function.
|
||||||
func NegotiateIncludingOpenMetrics(h http.Header) Format {
|
func NegotiateIncludingOpenMetrics(h http.Header) Format {
|
||||||
|
escapingScheme := Format(fmt.Sprintf("; escaping=%s", Format(model.NameEscapingScheme.String())))
|
||||||
for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) {
|
for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) {
|
||||||
|
if escapeParam := ac.Params[model.EscapingKey]; escapeParam != "" {
|
||||||
|
switch Format(escapeParam) {
|
||||||
|
case model.AllowUTF8, model.EscapeUnderscores, model.EscapeDots, model.EscapeValues:
|
||||||
|
escapingScheme = Format(fmt.Sprintf("; escaping=%s", escapeParam))
|
||||||
|
default:
|
||||||
|
// If the escaping parameter is unknown, ignore it.
|
||||||
|
}
|
||||||
|
}
|
||||||
ver := ac.Params["version"]
|
ver := ac.Params["version"]
|
||||||
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
|
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
|
||||||
switch ac.Params["encoding"] {
|
switch ac.Params["encoding"] {
|
||||||
case "delimited":
|
case "delimited":
|
||||||
return FmtProtoDelim
|
return fmtProtoDelim + escapingScheme
|
||||||
case "text":
|
case "text":
|
||||||
return FmtProtoText
|
return fmtProtoText + escapingScheme
|
||||||
case "compact-text":
|
case "compact-text":
|
||||||
return FmtProtoCompact
|
return fmtProtoCompact + escapingScheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
|
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
|
||||||
return FmtText
|
return fmtText + escapingScheme
|
||||||
}
|
}
|
||||||
if ac.Type+"/"+ac.SubType == OpenMetricsType && (ver == OpenMetricsVersion_0_0_1 || ver == OpenMetricsVersion_1_0_0 || ver == "") {
|
if ac.Type+"/"+ac.SubType == OpenMetricsType && (ver == OpenMetricsVersion_0_0_1 || ver == OpenMetricsVersion_1_0_0 || ver == "") {
|
||||||
if ver == OpenMetricsVersion_1_0_0 {
|
switch ver {
|
||||||
return FmtOpenMetrics_1_0_0
|
case OpenMetricsVersion_1_0_0:
|
||||||
|
return fmtOpenMetrics_1_0_0 + escapingScheme
|
||||||
|
default:
|
||||||
|
return fmtOpenMetrics_0_0_1 + escapingScheme
|
||||||
}
|
}
|
||||||
return FmtOpenMetrics_0_0_1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FmtText
|
return fmtText + escapingScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder returns a new encoder based on content type negotiation. All
|
// NewEncoder returns a new encoder based on content type negotiation. All
|
||||||
@@ -116,9 +137,13 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
|
|||||||
// for FmtOpenMetrics, but a future (breaking) release will add the Close method
|
// for FmtOpenMetrics, but a future (breaking) release will add the Close method
|
||||||
// to the Encoder interface directly. The current version of the Encoder
|
// to the Encoder interface directly. The current version of the Encoder
|
||||||
// interface is kept for backwards compatibility.
|
// interface is kept for backwards compatibility.
|
||||||
|
// In cases where the Format does not allow for UTF-8 names, the global
|
||||||
|
// NameEscapingScheme will be applied.
|
||||||
func NewEncoder(w io.Writer, format Format) Encoder {
|
func NewEncoder(w io.Writer, format Format) Encoder {
|
||||||
switch format {
|
escapingScheme := format.ToEscapingScheme()
|
||||||
case FmtProtoDelim:
|
|
||||||
|
switch format.FormatType() {
|
||||||
|
case TypeProtoDelim:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := protodelim.MarshalTo(w, v)
|
_, err := protodelim.MarshalTo(w, v)
|
||||||
@@ -126,34 +151,34 @@ func NewEncoder(w io.Writer, format Format) Encoder {
|
|||||||
},
|
},
|
||||||
close: func() error { return nil },
|
close: func() error { return nil },
|
||||||
}
|
}
|
||||||
case FmtProtoCompact:
|
case TypeProtoCompact:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := fmt.Fprintln(w, v.String())
|
_, err := fmt.Fprintln(w, model.EscapeMetricFamily(v, escapingScheme).String())
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
close: func() error { return nil },
|
close: func() error { return nil },
|
||||||
}
|
}
|
||||||
case FmtProtoText:
|
case TypeProtoText:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := fmt.Fprintln(w, prototext.Format(v))
|
_, err := fmt.Fprintln(w, prototext.Format(model.EscapeMetricFamily(v, escapingScheme)))
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
close: func() error { return nil },
|
close: func() error { return nil },
|
||||||
}
|
}
|
||||||
case FmtText:
|
case TypeTextPlain:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := MetricFamilyToText(w, v)
|
_, err := MetricFamilyToText(w, model.EscapeMetricFamily(v, escapingScheme))
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
close: func() error { return nil },
|
close: func() error { return nil },
|
||||||
}
|
}
|
||||||
case FmtOpenMetrics_0_0_1, FmtOpenMetrics_1_0_0:
|
case TypeOpenMetrics:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := MetricFamilyToOpenMetrics(w, v)
|
_, err := MetricFamilyToOpenMetrics(w, model.EscapeMetricFamily(v, escapingScheme))
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
close: func() error {
|
close: func() error {
|
||||||
|
|||||||
144
vendor/github.com/prometheus/common/expfmt/expfmt.go
generated
vendored
144
vendor/github.com/prometheus/common/expfmt/expfmt.go
generated
vendored
@@ -14,30 +14,154 @@
|
|||||||
// Package expfmt contains tools for reading and writing Prometheus metrics.
|
// Package expfmt contains tools for reading and writing Prometheus metrics.
|
||||||
package expfmt
|
package expfmt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/prometheus/common/model"
|
||||||
|
)
|
||||||
|
|
||||||
// Format specifies the HTTP content type of the different wire protocols.
|
// Format specifies the HTTP content type of the different wire protocols.
|
||||||
type Format string
|
type Format string
|
||||||
|
|
||||||
// Constants to assemble the Content-Type values for the different wire protocols.
|
// Constants to assemble the Content-Type values for the different wire
|
||||||
|
// protocols. The Content-Type strings here are all for the legacy exposition
|
||||||
|
// formats, where valid characters for metric names and label names are limited.
|
||||||
|
// Support for arbitrary UTF-8 characters in those names is already partially
|
||||||
|
// implemented in this module (see model.ValidationScheme), but to actually use
|
||||||
|
// it on the wire, new content-type strings will have to be agreed upon and
|
||||||
|
// added here.
|
||||||
const (
|
const (
|
||||||
TextVersion = "0.0.4"
|
TextVersion = "0.0.4"
|
||||||
ProtoType = `application/vnd.google.protobuf`
|
ProtoType = `application/vnd.google.protobuf`
|
||||||
ProtoProtocol = `io.prometheus.client.MetricFamily`
|
ProtoProtocol = `io.prometheus.client.MetricFamily`
|
||||||
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
|
protoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
|
||||||
OpenMetricsType = `application/openmetrics-text`
|
OpenMetricsType = `application/openmetrics-text`
|
||||||
OpenMetricsVersion_0_0_1 = "0.0.1"
|
OpenMetricsVersion_0_0_1 = "0.0.1"
|
||||||
OpenMetricsVersion_1_0_0 = "1.0.0"
|
OpenMetricsVersion_1_0_0 = "1.0.0"
|
||||||
|
|
||||||
// The Content-Type values for the different wire protocols.
|
// The Content-Type values for the different wire protocols. Note that these
|
||||||
FmtUnknown Format = `<unknown>`
|
// values are now unexported. If code was relying on comparisons to these
|
||||||
FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
|
// constants, instead use FormatType().
|
||||||
FmtProtoDelim Format = ProtoFmt + ` encoding=delimited`
|
fmtUnknown Format = `<unknown>`
|
||||||
FmtProtoText Format = ProtoFmt + ` encoding=text`
|
fmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
|
||||||
FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text`
|
fmtProtoDelim Format = protoFmt + ` encoding=delimited`
|
||||||
FmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
|
fmtProtoText Format = protoFmt + ` encoding=text`
|
||||||
FmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
|
fmtProtoCompact Format = protoFmt + ` encoding=compact-text`
|
||||||
|
fmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
|
||||||
|
fmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hdrContentType = "Content-Type"
|
hdrContentType = "Content-Type"
|
||||||
hdrAccept = "Accept"
|
hdrAccept = "Accept"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FormatType is a Go enum representing the overall category for the given
|
||||||
|
// Format. As the number of Format permutations increases, doing basic string
|
||||||
|
// comparisons are not feasible, so this enum captures the most useful
|
||||||
|
// high-level attribute of the Format string.
|
||||||
|
type FormatType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TypeUnknown = iota
|
||||||
|
TypeProtoCompact
|
||||||
|
TypeProtoDelim
|
||||||
|
TypeProtoText
|
||||||
|
TypeTextPlain
|
||||||
|
TypeOpenMetrics
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewFormat generates a new Format from the type provided. Mostly used for
|
||||||
|
// tests, most Formats should be generated as part of content negotiation in
|
||||||
|
// encode.go.
|
||||||
|
func NewFormat(t FormatType) Format {
|
||||||
|
switch t {
|
||||||
|
case TypeProtoCompact:
|
||||||
|
return fmtProtoCompact
|
||||||
|
case TypeProtoDelim:
|
||||||
|
return fmtProtoDelim
|
||||||
|
case TypeProtoText:
|
||||||
|
return fmtProtoText
|
||||||
|
case TypeTextPlain:
|
||||||
|
return fmtText
|
||||||
|
case TypeOpenMetrics:
|
||||||
|
return fmtOpenMetrics_1_0_0
|
||||||
|
default:
|
||||||
|
return fmtUnknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatType deduces an overall FormatType for the given format.
|
||||||
|
func (f Format) FormatType() FormatType {
|
||||||
|
toks := strings.Split(string(f), ";")
|
||||||
|
if len(toks) < 2 {
|
||||||
|
return TypeUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
params := make(map[string]string)
|
||||||
|
for i, t := range toks {
|
||||||
|
if i == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
args := strings.Split(t, "=")
|
||||||
|
if len(args) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
params[strings.TrimSpace(args[0])] = strings.TrimSpace(args[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.TrimSpace(toks[0]) {
|
||||||
|
case ProtoType:
|
||||||
|
if params["proto"] != ProtoProtocol {
|
||||||
|
return TypeUnknown
|
||||||
|
}
|
||||||
|
switch params["encoding"] {
|
||||||
|
case "delimited":
|
||||||
|
return TypeProtoDelim
|
||||||
|
case "text":
|
||||||
|
return TypeProtoText
|
||||||
|
case "compact-text":
|
||||||
|
return TypeProtoCompact
|
||||||
|
default:
|
||||||
|
return TypeUnknown
|
||||||
|
}
|
||||||
|
case OpenMetricsType:
|
||||||
|
if params["charset"] != "utf-8" {
|
||||||
|
return TypeUnknown
|
||||||
|
}
|
||||||
|
return TypeOpenMetrics
|
||||||
|
case "text/plain":
|
||||||
|
v, ok := params["version"]
|
||||||
|
if !ok {
|
||||||
|
return TypeTextPlain
|
||||||
|
}
|
||||||
|
if v == TextVersion {
|
||||||
|
return TypeTextPlain
|
||||||
|
}
|
||||||
|
return TypeUnknown
|
||||||
|
default:
|
||||||
|
return TypeUnknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToEscapingScheme returns an EscapingScheme depending on the Format. Iff the
|
||||||
|
// Format contains a escaping=allow-utf-8 term, it will select NoEscaping. If a valid
|
||||||
|
// "escaping" term exists, that will be used. Otherwise, the global default will
|
||||||
|
// be returned.
|
||||||
|
func (format Format) ToEscapingScheme() model.EscapingScheme {
|
||||||
|
for _, p := range strings.Split(string(format), ";") {
|
||||||
|
toks := strings.Split(p, "=")
|
||||||
|
if len(toks) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key, value := strings.TrimSpace(toks[0]), strings.TrimSpace(toks[1])
|
||||||
|
if key == model.EscapingKey {
|
||||||
|
scheme, err := model.ToEscapingScheme(value)
|
||||||
|
if err != nil {
|
||||||
|
return model.NameEscapingScheme
|
||||||
|
}
|
||||||
|
return scheme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model.NameEscapingScheme
|
||||||
|
}
|
||||||
|
|||||||
85
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
85
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
@@ -35,6 +35,18 @@ import (
|
|||||||
// sanity checks. If the input contains duplicate metrics or invalid metric or
|
// sanity checks. If the input contains duplicate metrics or invalid metric or
|
||||||
// label names, the conversion will result in invalid text format output.
|
// label names, the conversion will result in invalid text format output.
|
||||||
//
|
//
|
||||||
|
// If metric names conform to the legacy validation pattern, they will be placed
|
||||||
|
// outside the brackets in the traditional way, like `foo{}`. If the metric name
|
||||||
|
// fails the legacy validation check, it will be placed quoted inside the
|
||||||
|
// brackets: `{"foo"}`. As stated above, the input is assumed to be santized and
|
||||||
|
// no error will be thrown in this case.
|
||||||
|
//
|
||||||
|
// Similar to metric names, if label names conform to the legacy validation
|
||||||
|
// pattern, they will be unquoted as normal, like `foo{bar="baz"}`. If the label
|
||||||
|
// name fails the legacy validation check, it will be quoted:
|
||||||
|
// `foo{"bar"="baz"}`. As stated above, the input is assumed to be santized and
|
||||||
|
// no error will be thrown in this case.
|
||||||
|
//
|
||||||
// This function fulfills the type 'expfmt.encoder'.
|
// This function fulfills the type 'expfmt.encoder'.
|
||||||
//
|
//
|
||||||
// Note that OpenMetrics requires a final `# EOF` line. Since this function acts
|
// Note that OpenMetrics requires a final `# EOF` line. Since this function acts
|
||||||
@@ -98,7 +110,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = w.WriteString(shortName)
|
n, err = writeName(w, shortName)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -124,7 +136,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = w.WriteString(shortName)
|
n, err = writeName(w, shortName)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -303,21 +315,9 @@ func writeOpenMetricsSample(
|
|||||||
floatValue float64, intValue uint64, useIntValue bool,
|
floatValue float64, intValue uint64, useIntValue bool,
|
||||||
exemplar *dto.Exemplar,
|
exemplar *dto.Exemplar,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
var written int
|
written := 0
|
||||||
n, err := w.WriteString(name)
|
n, err := writeOpenMetricsNameAndLabelPairs(
|
||||||
written += n
|
w, name+suffix, metric.Label, additionalLabelName, additionalLabelValue,
|
||||||
if err != nil {
|
|
||||||
return written, err
|
|
||||||
}
|
|
||||||
if suffix != "" {
|
|
||||||
n, err = w.WriteString(suffix)
|
|
||||||
written += n
|
|
||||||
if err != nil {
|
|
||||||
return written, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n, err = writeOpenMetricsLabelPairs(
|
|
||||||
w, metric.Label, additionalLabelName, additionalLabelValue,
|
|
||||||
)
|
)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -365,27 +365,58 @@ func writeOpenMetricsSample(
|
|||||||
return written, nil
|
return written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeOpenMetricsLabelPairs works like writeOpenMetrics but formats the float
|
// writeOpenMetricsNameAndLabelPairs works like writeOpenMetricsSample but
|
||||||
// in OpenMetrics style.
|
// formats the float in OpenMetrics style.
|
||||||
func writeOpenMetricsLabelPairs(
|
func writeOpenMetricsNameAndLabelPairs(
|
||||||
w enhancedWriter,
|
w enhancedWriter,
|
||||||
|
name string,
|
||||||
in []*dto.LabelPair,
|
in []*dto.LabelPair,
|
||||||
additionalLabelName string, additionalLabelValue float64,
|
additionalLabelName string, additionalLabelValue float64,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
if len(in) == 0 && additionalLabelName == "" {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
written int
|
written int
|
||||||
separator byte = '{'
|
separator byte = '{'
|
||||||
|
metricInsideBraces = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
// If the name does not pass the legacy validity check, we must put the
|
||||||
|
// metric name inside the braces, quoted.
|
||||||
|
if !model.IsValidLegacyMetricName(model.LabelValue(name)) {
|
||||||
|
metricInsideBraces = true
|
||||||
|
err := w.WriteByte(separator)
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
separator = ','
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := writeName(w, name)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(in) == 0 && additionalLabelName == "" {
|
||||||
|
if metricInsideBraces {
|
||||||
|
err := w.WriteByte('}')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return written, nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, lp := range in {
|
for _, lp := range in {
|
||||||
err := w.WriteByte(separator)
|
err := w.WriteByte(separator)
|
||||||
written++
|
written++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
}
|
}
|
||||||
n, err := w.WriteString(lp.GetName())
|
n, err := writeName(w, lp.GetName())
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
@@ -451,7 +482,7 @@ func writeExemplar(w enhancedWriter, e *dto.Exemplar) (int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsLabelPairs(w, e.Label, "", 0)
|
n, err = writeOpenMetricsNameAndLabelPairs(w, "", e.Label, "", 0)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
|
|||||||
118
vendor/github.com/prometheus/common/expfmt/text_create.go
generated
vendored
118
vendor/github.com/prometheus/common/expfmt/text_create.go
generated
vendored
@@ -62,6 +62,18 @@ var (
|
|||||||
// contains duplicate metrics or invalid metric or label names, the conversion
|
// contains duplicate metrics or invalid metric or label names, the conversion
|
||||||
// will result in invalid text format output.
|
// will result in invalid text format output.
|
||||||
//
|
//
|
||||||
|
// If metric names conform to the legacy validation pattern, they will be placed
|
||||||
|
// outside the brackets in the traditional way, like `foo{}`. If the metric name
|
||||||
|
// fails the legacy validation check, it will be placed quoted inside the
|
||||||
|
// brackets: `{"foo"}`. As stated above, the input is assumed to be santized and
|
||||||
|
// no error will be thrown in this case.
|
||||||
|
//
|
||||||
|
// Similar to metric names, if label names conform to the legacy validation
|
||||||
|
// pattern, they will be unquoted as normal, like `foo{bar="baz"}`. If the label
|
||||||
|
// name fails the legacy validation check, it will be quoted:
|
||||||
|
// `foo{"bar"="baz"}`. As stated above, the input is assumed to be santized and
|
||||||
|
// no error will be thrown in this case.
|
||||||
|
//
|
||||||
// This method fulfills the type 'prometheus.encoder'.
|
// This method fulfills the type 'prometheus.encoder'.
|
||||||
func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err error) {
|
func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err error) {
|
||||||
// Fail-fast checks.
|
// Fail-fast checks.
|
||||||
@@ -98,7 +110,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = w.WriteString(name)
|
n, err = writeName(w, name)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -124,7 +136,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = w.WriteString(name)
|
n, err = writeName(w, name)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -280,21 +292,9 @@ func writeSample(
|
|||||||
additionalLabelName string, additionalLabelValue float64,
|
additionalLabelName string, additionalLabelValue float64,
|
||||||
value float64,
|
value float64,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
var written int
|
written := 0
|
||||||
n, err := w.WriteString(name)
|
n, err := writeNameAndLabelPairs(
|
||||||
written += n
|
w, name+suffix, metric.Label, additionalLabelName, additionalLabelValue,
|
||||||
if err != nil {
|
|
||||||
return written, err
|
|
||||||
}
|
|
||||||
if suffix != "" {
|
|
||||||
n, err = w.WriteString(suffix)
|
|
||||||
written += n
|
|
||||||
if err != nil {
|
|
||||||
return written, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n, err = writeLabelPairs(
|
|
||||||
w, metric.Label, additionalLabelName, additionalLabelValue,
|
|
||||||
)
|
)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -330,32 +330,64 @@ func writeSample(
|
|||||||
return written, nil
|
return written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeLabelPairs converts a slice of LabelPair proto messages plus the
|
// writeNameAndLabelPairs converts a slice of LabelPair proto messages plus the
|
||||||
// explicitly given additional label pair into text formatted as required by the
|
// explicitly given metric name and additional label pair into text formatted as
|
||||||
// text format and writes it to 'w'. An empty slice in combination with an empty
|
// required by the text format and writes it to 'w'. An empty slice in
|
||||||
// string 'additionalLabelName' results in nothing being written. Otherwise, the
|
// combination with an empty string 'additionalLabelName' results in nothing
|
||||||
// label pairs are written, escaped as required by the text format, and enclosed
|
// being written. Otherwise, the label pairs are written, escaped as required by
|
||||||
// in '{...}'. The function returns the number of bytes written and any error
|
// the text format, and enclosed in '{...}'. The function returns the number of
|
||||||
// encountered.
|
// bytes written and any error encountered. If the metric name is not
|
||||||
func writeLabelPairs(
|
// legacy-valid, it will be put inside the brackets as well. Legacy-invalid
|
||||||
|
// label names will also be quoted.
|
||||||
|
func writeNameAndLabelPairs(
|
||||||
w enhancedWriter,
|
w enhancedWriter,
|
||||||
|
name string,
|
||||||
in []*dto.LabelPair,
|
in []*dto.LabelPair,
|
||||||
additionalLabelName string, additionalLabelValue float64,
|
additionalLabelName string, additionalLabelValue float64,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
if len(in) == 0 && additionalLabelName == "" {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
written int
|
written int
|
||||||
separator byte = '{'
|
separator byte = '{'
|
||||||
|
metricInsideBraces = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
// If the name does not pass the legacy validity check, we must put the
|
||||||
|
// metric name inside the braces.
|
||||||
|
if !model.IsValidLegacyMetricName(model.LabelValue(name)) {
|
||||||
|
metricInsideBraces = true
|
||||||
|
err := w.WriteByte(separator)
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
separator = ','
|
||||||
|
}
|
||||||
|
n, err := writeName(w, name)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(in) == 0 && additionalLabelName == "" {
|
||||||
|
if metricInsideBraces {
|
||||||
|
err := w.WriteByte('}')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return written, nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, lp := range in {
|
for _, lp := range in {
|
||||||
err := w.WriteByte(separator)
|
err := w.WriteByte(separator)
|
||||||
written++
|
written++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
}
|
}
|
||||||
n, err := w.WriteString(lp.GetName())
|
n, err := writeName(w, lp.GetName())
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, err
|
return written, err
|
||||||
@@ -462,3 +494,27 @@ func writeInt(w enhancedWriter, i int64) (int, error) {
|
|||||||
numBufPool.Put(bp)
|
numBufPool.Put(bp)
|
||||||
return written, err
|
return written, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeName writes a string as-is if it complies with the legacy naming
|
||||||
|
// scheme, or escapes it in double quotes if not.
|
||||||
|
func writeName(w enhancedWriter, name string) (int, error) {
|
||||||
|
if model.IsValidLegacyMetricName(model.LabelValue(name)) {
|
||||||
|
return w.WriteString(name)
|
||||||
|
}
|
||||||
|
var written int
|
||||||
|
var err error
|
||||||
|
err = w.WriteByte('"')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
var n int
|
||||||
|
n, err = writeEscapedString(w, name, true)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
err = w.WriteByte('"')
|
||||||
|
written++
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
|||||||
22
vendor/github.com/prometheus/common/model/labels.go
generated
vendored
22
vendor/github.com/prometheus/common/model/labels.go
generated
vendored
@@ -97,17 +97,25 @@ var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
|
|||||||
// therewith.
|
// therewith.
|
||||||
type LabelName string
|
type LabelName string
|
||||||
|
|
||||||
// IsValid is true iff the label name matches the pattern of LabelNameRE. This
|
// IsValid returns true iff name matches the pattern of LabelNameRE for legacy
|
||||||
// method, however, does not use LabelNameRE for the check but a much faster
|
// names, and iff it's valid UTF-8 if NameValidationScheme is set to
|
||||||
// hardcoded implementation.
|
// UTF8Validation. For the legacy matching, it does not use LabelNameRE for the
|
||||||
|
// check but a much faster hardcoded implementation.
|
||||||
func (ln LabelName) IsValid() bool {
|
func (ln LabelName) IsValid() bool {
|
||||||
if len(ln) == 0 {
|
if len(ln) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i, b := range ln {
|
switch NameValidationScheme {
|
||||||
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
|
case LegacyValidation:
|
||||||
return false
|
for i, b := range ln {
|
||||||
|
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
case UTF8Validation:
|
||||||
|
return utf8.ValidString(string(ln))
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Invalid name validation scheme requested: %d", NameValidationScheme))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -164,7 +172,7 @@ func (l LabelNames) String() string {
|
|||||||
// A LabelValue is an associated value for a LabelName.
|
// A LabelValue is an associated value for a LabelName.
|
||||||
type LabelValue string
|
type LabelValue string
|
||||||
|
|
||||||
// IsValid returns true iff the string is a valid UTF8.
|
// IsValid returns true iff the string is a valid UTF-8.
|
||||||
func (lv LabelValue) IsValid() bool {
|
func (lv LabelValue) IsValid() bool {
|
||||||
return utf8.ValidString(string(lv))
|
return utf8.ValidString(string(lv))
|
||||||
}
|
}
|
||||||
|
|||||||
362
vendor/github.com/prometheus/common/model/metric.go
generated
vendored
362
vendor/github.com/prometheus/common/model/metric.go
generated
vendored
@@ -18,6 +18,77 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// NameValidationScheme determines the method of name validation to be used by
|
||||||
|
// all calls to IsValidMetricName() and LabelName IsValid(). Setting UTF-8 mode
|
||||||
|
// in isolation from other components that don't support UTF-8 may result in
|
||||||
|
// bugs or other undefined behavior. This value is intended to be set by
|
||||||
|
// UTF-8-aware binaries as part of their startup. To avoid need for locking,
|
||||||
|
// this value should be set once, ideally in an init(), before multiple
|
||||||
|
// goroutines are started.
|
||||||
|
NameValidationScheme = LegacyValidation
|
||||||
|
|
||||||
|
// NameEscapingScheme defines the default way that names will be
|
||||||
|
// escaped when presented to systems that do not support UTF-8 names. If the
|
||||||
|
// Content-Type "escaping" term is specified, that will override this value.
|
||||||
|
NameEscapingScheme = ValueEncodingEscaping
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidationScheme is a Go enum for determining how metric and label names will
|
||||||
|
// be validated by this library.
|
||||||
|
type ValidationScheme int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// LegacyValidation is a setting that requirets that metric and label names
|
||||||
|
// conform to the original Prometheus character requirements described by
|
||||||
|
// MetricNameRE and LabelNameRE.
|
||||||
|
LegacyValidation ValidationScheme = iota
|
||||||
|
|
||||||
|
// UTF8Validation only requires that metric and label names be valid UTF-8
|
||||||
|
// strings.
|
||||||
|
UTF8Validation
|
||||||
|
)
|
||||||
|
|
||||||
|
type EscapingScheme int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// NoEscaping indicates that a name will not be escaped. Unescaped names that
|
||||||
|
// do not conform to the legacy validity check will use a new exposition
|
||||||
|
// format syntax that will be officially standardized in future versions.
|
||||||
|
NoEscaping EscapingScheme = iota
|
||||||
|
|
||||||
|
// UnderscoreEscaping replaces all legacy-invalid characters with underscores.
|
||||||
|
UnderscoreEscaping
|
||||||
|
|
||||||
|
// DotsEscaping is similar to UnderscoreEscaping, except that dots are
|
||||||
|
// converted to `_dot_` and pre-existing underscores are converted to `__`.
|
||||||
|
DotsEscaping
|
||||||
|
|
||||||
|
// ValueEncodingEscaping prepends the name with `U__` and replaces all invalid
|
||||||
|
// characters with the unicode value, surrounded by underscores. Single
|
||||||
|
// underscores are replaced with double underscores.
|
||||||
|
ValueEncodingEscaping
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// EscapingKey is the key in an Accept or Content-Type header that defines how
|
||||||
|
// metric and label names that do not conform to the legacy character
|
||||||
|
// requirements should be escaped when being scraped by a legacy prometheus
|
||||||
|
// system. If a system does not explicitly pass an escaping parameter in the
|
||||||
|
// Accept header, the default NameEscapingScheme will be used.
|
||||||
|
EscapingKey = "escaping"
|
||||||
|
|
||||||
|
// Possible values for Escaping Key:
|
||||||
|
AllowUTF8 = "allow-utf-8" // No escaping required.
|
||||||
|
EscapeUnderscores = "underscores"
|
||||||
|
EscapeDots = "dots"
|
||||||
|
EscapeValues = "values"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MetricNameRE is a regular expression matching valid metric
|
// MetricNameRE is a regular expression matching valid metric
|
||||||
@@ -84,17 +155,302 @@ func (m Metric) FastFingerprint() Fingerprint {
|
|||||||
return LabelSet(m).FastFingerprint()
|
return LabelSet(m).FastFingerprint()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValidMetricName returns true iff name matches the pattern of MetricNameRE.
|
// IsValidMetricName returns true iff name matches the pattern of MetricNameRE
|
||||||
|
// for legacy names, and iff it's valid UTF-8 if the UTF8Validation scheme is
|
||||||
|
// selected.
|
||||||
|
func IsValidMetricName(n LabelValue) bool {
|
||||||
|
switch NameValidationScheme {
|
||||||
|
case LegacyValidation:
|
||||||
|
return IsValidLegacyMetricName(n)
|
||||||
|
case UTF8Validation:
|
||||||
|
if len(n) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return utf8.ValidString(string(n))
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Invalid name validation scheme requested: %d", NameValidationScheme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidLegacyMetricName is similar to IsValidMetricName but always uses the
|
||||||
|
// legacy validation scheme regardless of the value of NameValidationScheme.
|
||||||
// This function, however, does not use MetricNameRE for the check but a much
|
// This function, however, does not use MetricNameRE for the check but a much
|
||||||
// faster hardcoded implementation.
|
// faster hardcoded implementation.
|
||||||
func IsValidMetricName(n LabelValue) bool {
|
func IsValidLegacyMetricName(n LabelValue) bool {
|
||||||
if len(n) == 0 {
|
if len(n) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i, b := range n {
|
for i, b := range n {
|
||||||
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) {
|
if !isValidLegacyRune(b, i) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EscapeMetricFamily escapes the given metric names and labels with the given
|
||||||
|
// escaping scheme. Returns a new object that uses the same pointers to fields
|
||||||
|
// when possible and creates new escaped versions so as not to mutate the
|
||||||
|
// input.
|
||||||
|
func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricFamily {
|
||||||
|
if v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if scheme == NoEscaping {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
out := &dto.MetricFamily{
|
||||||
|
Help: v.Help,
|
||||||
|
Type: v.Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the name is nil, copy as-is, don't try to escape.
|
||||||
|
if v.Name == nil || IsValidLegacyMetricName(LabelValue(v.GetName())) {
|
||||||
|
out.Name = v.Name
|
||||||
|
} else {
|
||||||
|
out.Name = proto.String(EscapeName(v.GetName(), scheme))
|
||||||
|
}
|
||||||
|
for _, m := range v.Metric {
|
||||||
|
if !metricNeedsEscaping(m) {
|
||||||
|
out.Metric = append(out.Metric, m)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
escaped := &dto.Metric{
|
||||||
|
Gauge: m.Gauge,
|
||||||
|
Counter: m.Counter,
|
||||||
|
Summary: m.Summary,
|
||||||
|
Untyped: m.Untyped,
|
||||||
|
Histogram: m.Histogram,
|
||||||
|
TimestampMs: m.TimestampMs,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range m.Label {
|
||||||
|
if l.GetName() == MetricNameLabel {
|
||||||
|
if l.Value == nil || IsValidLegacyMetricName(LabelValue(l.GetValue())) {
|
||||||
|
escaped.Label = append(escaped.Label, l)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
escaped.Label = append(escaped.Label, &dto.LabelPair{
|
||||||
|
Name: proto.String(MetricNameLabel),
|
||||||
|
Value: proto.String(EscapeName(l.GetValue(), scheme)),
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if l.Name == nil || IsValidLegacyMetricName(LabelValue(l.GetName())) {
|
||||||
|
escaped.Label = append(escaped.Label, l)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
escaped.Label = append(escaped.Label, &dto.LabelPair{
|
||||||
|
Name: proto.String(EscapeName(l.GetName(), scheme)),
|
||||||
|
Value: l.Value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
out.Metric = append(out.Metric, escaped)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func metricNeedsEscaping(m *dto.Metric) bool {
|
||||||
|
for _, l := range m.Label {
|
||||||
|
if l.GetName() == MetricNameLabel && !IsValidLegacyMetricName(LabelValue(l.GetValue())) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if !IsValidLegacyMetricName(LabelValue(l.GetName())) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
lowerhex = "0123456789abcdef"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EscapeName escapes the incoming name according to the provided escaping
|
||||||
|
// scheme. Depending on the rules of escaping, this may cause no change in the
|
||||||
|
// string that is returned. (Especially NoEscaping, which by definition is a
|
||||||
|
// noop). This function does not do any validation of the name.
|
||||||
|
func EscapeName(name string, scheme EscapingScheme) string {
|
||||||
|
if len(name) == 0 {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
var escaped strings.Builder
|
||||||
|
switch scheme {
|
||||||
|
case NoEscaping:
|
||||||
|
return name
|
||||||
|
case UnderscoreEscaping:
|
||||||
|
if IsValidLegacyMetricName(LabelValue(name)) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
for i, b := range name {
|
||||||
|
if isValidLegacyRune(b, i) {
|
||||||
|
escaped.WriteRune(b)
|
||||||
|
} else {
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped.String()
|
||||||
|
case DotsEscaping:
|
||||||
|
// Do not early return for legacy valid names, we still escape underscores.
|
||||||
|
for i, b := range name {
|
||||||
|
if b == '_' {
|
||||||
|
escaped.WriteString("__")
|
||||||
|
} else if b == '.' {
|
||||||
|
escaped.WriteString("_dot_")
|
||||||
|
} else if isValidLegacyRune(b, i) {
|
||||||
|
escaped.WriteRune(b)
|
||||||
|
} else {
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped.String()
|
||||||
|
case ValueEncodingEscaping:
|
||||||
|
if IsValidLegacyMetricName(LabelValue(name)) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
escaped.WriteString("U__")
|
||||||
|
for i, b := range name {
|
||||||
|
if isValidLegacyRune(b, i) {
|
||||||
|
escaped.WriteRune(b)
|
||||||
|
} else if !utf8.ValidRune(b) {
|
||||||
|
escaped.WriteString("_FFFD_")
|
||||||
|
} else if b < 0x100 {
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
for s := 4; s >= 0; s -= 4 {
|
||||||
|
escaped.WriteByte(lowerhex[b>>uint(s)&0xF])
|
||||||
|
}
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
} else if b < 0x10000 {
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
for s := 12; s >= 0; s -= 4 {
|
||||||
|
escaped.WriteByte(lowerhex[b>>uint(s)&0xF])
|
||||||
|
}
|
||||||
|
escaped.WriteRune('_')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped.String()
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid escaping scheme %d", scheme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// lower function taken from strconv.atoi
|
||||||
|
func lower(c byte) byte {
|
||||||
|
return c | ('x' - 'X')
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnescapeName unescapes the incoming name according to the provided escaping
|
||||||
|
// scheme if possible. Some schemes are partially or totally non-roundtripable.
|
||||||
|
// If any error is enountered, returns the original input.
|
||||||
|
func UnescapeName(name string, scheme EscapingScheme) string {
|
||||||
|
if len(name) == 0 {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
switch scheme {
|
||||||
|
case NoEscaping:
|
||||||
|
return name
|
||||||
|
case UnderscoreEscaping:
|
||||||
|
// It is not possible to unescape from underscore replacement.
|
||||||
|
return name
|
||||||
|
case DotsEscaping:
|
||||||
|
name = strings.ReplaceAll(name, "_dot_", ".")
|
||||||
|
name = strings.ReplaceAll(name, "__", "_")
|
||||||
|
return name
|
||||||
|
case ValueEncodingEscaping:
|
||||||
|
escapedName, found := strings.CutPrefix(name, "U__")
|
||||||
|
if !found {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
var unescaped strings.Builder
|
||||||
|
TOP:
|
||||||
|
for i := 0; i < len(escapedName); i++ {
|
||||||
|
// All non-underscores are treated normally.
|
||||||
|
if escapedName[i] != '_' {
|
||||||
|
unescaped.WriteByte(escapedName[i])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
if i >= len(escapedName) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
// A double underscore is a single underscore.
|
||||||
|
if escapedName[i] == '_' {
|
||||||
|
unescaped.WriteByte('_')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// We think we are in a UTF-8 code, process it.
|
||||||
|
var utf8Val uint
|
||||||
|
for j := 0; i < len(escapedName); j++ {
|
||||||
|
// This is too many characters for a utf8 value.
|
||||||
|
if j > 4 {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
// Found a closing underscore, convert to a rune, check validity, and append.
|
||||||
|
if escapedName[i] == '_' {
|
||||||
|
utf8Rune := rune(utf8Val)
|
||||||
|
if !utf8.ValidRune(utf8Rune) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
unescaped.WriteRune(utf8Rune)
|
||||||
|
continue TOP
|
||||||
|
}
|
||||||
|
r := lower(escapedName[i])
|
||||||
|
utf8Val *= 16
|
||||||
|
if r >= '0' && r <= '9' {
|
||||||
|
utf8Val += uint(r) - '0'
|
||||||
|
} else if r >= 'a' && r <= 'f' {
|
||||||
|
utf8Val += uint(r) - 'a' + 10
|
||||||
|
} else {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
// Didn't find closing underscore, invalid.
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
return unescaped.String()
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid escaping scheme %d", scheme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isValidLegacyRune(b rune, i int) bool {
|
||||||
|
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EscapingScheme) String() string {
|
||||||
|
switch e {
|
||||||
|
case NoEscaping:
|
||||||
|
return AllowUTF8
|
||||||
|
case UnderscoreEscaping:
|
||||||
|
return EscapeUnderscores
|
||||||
|
case DotsEscaping:
|
||||||
|
return EscapeDots
|
||||||
|
case ValueEncodingEscaping:
|
||||||
|
return EscapeValues
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unknown format scheme %d", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToEscapingScheme(s string) (EscapingScheme, error) {
|
||||||
|
if s == "" {
|
||||||
|
return NoEscaping, fmt.Errorf("got empty string instead of escaping scheme")
|
||||||
|
}
|
||||||
|
switch s {
|
||||||
|
case AllowUTF8:
|
||||||
|
return NoEscaping, nil
|
||||||
|
case EscapeUnderscores:
|
||||||
|
return UnderscoreEscaping, nil
|
||||||
|
case EscapeDots:
|
||||||
|
return DotsEscaping, nil
|
||||||
|
case EscapeValues:
|
||||||
|
return ValueEncodingEscaping, nil
|
||||||
|
default:
|
||||||
|
return NoEscaping, fmt.Errorf("unknown format scheme " + s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
4
vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go
generated
vendored
4
vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go
generated
vendored
@@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.32.0
|
||||||
// protoc v4.22.0
|
// protoc v4.25.2
|
||||||
// source: grpc/binlog/v1/binarylog.proto
|
// source: grpc/binlog/v1/binarylog.proto
|
||||||
|
|
||||||
package grpc_binarylog_v1
|
package grpc_binarylog_v1
|
||||||
|
|||||||
2
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
2
vendor/google.golang.org/grpc/clientconn.go
generated
vendored
@@ -1772,6 +1772,8 @@ func parseTarget(target string) (resolver.Target, error) {
|
|||||||
return resolver.Target{URL: *u}, nil
|
return resolver.Target{URL: *u}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// encodeAuthority escapes the authority string based on valid chars defined in
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.
|
||||||
func encodeAuthority(authority string) string {
|
func encodeAuthority(authority string) string {
|
||||||
const upperhex = "0123456789ABCDEF"
|
const upperhex = "0123456789ABCDEF"
|
||||||
|
|
||||||
|
|||||||
24
vendor/google.golang.org/grpc/encoding/proto/proto.go
generated
vendored
24
vendor/google.golang.org/grpc/encoding/proto/proto.go
generated
vendored
@@ -23,8 +23,9 @@ package proto
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
"google.golang.org/protobuf/protoadapt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Name is the name registered for the proto compressor.
|
// Name is the name registered for the proto compressor.
|
||||||
@@ -38,21 +39,34 @@ func init() {
|
|||||||
type codec struct{}
|
type codec struct{}
|
||||||
|
|
||||||
func (codec) Marshal(v any) ([]byte, error) {
|
func (codec) Marshal(v any) ([]byte, error) {
|
||||||
vv, ok := v.(proto.Message)
|
vv := messageV2Of(v)
|
||||||
if !ok {
|
if vv == nil {
|
||||||
return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
|
return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return proto.Marshal(vv)
|
return proto.Marshal(vv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (codec) Unmarshal(data []byte, v any) error {
|
func (codec) Unmarshal(data []byte, v any) error {
|
||||||
vv, ok := v.(proto.Message)
|
vv := messageV2Of(v)
|
||||||
if !ok {
|
if vv == nil {
|
||||||
return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
|
return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return proto.Unmarshal(data, vv)
|
return proto.Unmarshal(data, vv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func messageV2Of(v any) proto.Message {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case protoadapt.MessageV1:
|
||||||
|
return protoadapt.MessageV2Of(v)
|
||||||
|
case protoadapt.MessageV2:
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (codec) Name() string {
|
func (codec) Name() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|||||||
9
vendor/google.golang.org/grpc/internal/binarylog/method_logger.go
generated
vendored
9
vendor/google.golang.org/grpc/internal/binarylog/method_logger.go
generated
vendored
@@ -25,11 +25,12 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes"
|
|
||||||
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
|
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
"google.golang.org/protobuf/types/known/durationpb"
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type callIDGenerator struct {
|
type callIDGenerator struct {
|
||||||
@@ -88,7 +89,7 @@ func NewTruncatingMethodLogger(h, m uint64) *TruncatingMethodLogger {
|
|||||||
// in TruncatingMethodLogger as possible.
|
// in TruncatingMethodLogger as possible.
|
||||||
func (ml *TruncatingMethodLogger) Build(c LogEntryConfig) *binlogpb.GrpcLogEntry {
|
func (ml *TruncatingMethodLogger) Build(c LogEntryConfig) *binlogpb.GrpcLogEntry {
|
||||||
m := c.toProto()
|
m := c.toProto()
|
||||||
timestamp, _ := ptypes.TimestampProto(time.Now())
|
timestamp := timestamppb.Now()
|
||||||
m.Timestamp = timestamp
|
m.Timestamp = timestamp
|
||||||
m.CallId = ml.callID
|
m.CallId = ml.callID
|
||||||
m.SequenceIdWithinCall = ml.idWithinCallGen.next()
|
m.SequenceIdWithinCall = ml.idWithinCallGen.next()
|
||||||
@@ -178,7 +179,7 @@ func (c *ClientHeader) toProto() *binlogpb.GrpcLogEntry {
|
|||||||
Authority: c.Authority,
|
Authority: c.Authority,
|
||||||
}
|
}
|
||||||
if c.Timeout > 0 {
|
if c.Timeout > 0 {
|
||||||
clientHeader.Timeout = ptypes.DurationProto(c.Timeout)
|
clientHeader.Timeout = durationpb.New(c.Timeout)
|
||||||
}
|
}
|
||||||
ret := &binlogpb.GrpcLogEntry{
|
ret := &binlogpb.GrpcLogEntry{
|
||||||
Type: binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER,
|
Type: binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER,
|
||||||
|
|||||||
2
vendor/google.golang.org/grpc/internal/binarylog/sink.go
generated
vendored
2
vendor/google.golang.org/grpc/internal/binarylog/sink.go
generated
vendored
@@ -25,8 +25,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
|
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
5
vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go
generated
vendored
5
vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go
generated
vendored
@@ -1,3 +1,8 @@
|
|||||||
|
//go:build !go1.21
|
||||||
|
|
||||||
|
// TODO: when this file is deleted (after Go 1.20 support is dropped), delete
|
||||||
|
// all of grpcrand and call the rand package directly.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Copyright 2018 gRPC authors.
|
* Copyright 2018 gRPC authors.
|
||||||
|
|||||||
73
vendor/google.golang.org/grpc/internal/grpcrand/grpcrand_go1.21.go
generated
vendored
Normal file
73
vendor/google.golang.org/grpc/internal/grpcrand/grpcrand_go1.21.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
//go:build go1.21
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2024 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 grpcrand implements math/rand functions in a concurrent-safe way
|
||||||
|
// with a global random source, independent of math/rand's global source.
|
||||||
|
package grpcrand
|
||||||
|
|
||||||
|
import "math/rand"
|
||||||
|
|
||||||
|
// This implementation will be used for Go version 1.21 or newer.
|
||||||
|
// For older versions, the original implementation with mutex will be used.
|
||||||
|
|
||||||
|
// Int implements rand.Int on the grpcrand global source.
|
||||||
|
func Int() int {
|
||||||
|
return rand.Int()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int63n implements rand.Int63n on the grpcrand global source.
|
||||||
|
func Int63n(n int64) int64 {
|
||||||
|
return rand.Int63n(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intn implements rand.Intn on the grpcrand global source.
|
||||||
|
func Intn(n int) int {
|
||||||
|
return rand.Intn(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int31n implements rand.Int31n on the grpcrand global source.
|
||||||
|
func Int31n(n int32) int32 {
|
||||||
|
return rand.Int31n(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 implements rand.Float64 on the grpcrand global source.
|
||||||
|
func Float64() float64 {
|
||||||
|
return rand.Float64()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64 implements rand.Uint64 on the grpcrand global source.
|
||||||
|
func Uint64() uint64 {
|
||||||
|
return rand.Uint64()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint32 implements rand.Uint32 on the grpcrand global source.
|
||||||
|
func Uint32() uint32 {
|
||||||
|
return rand.Uint32()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpFloat64 implements rand.ExpFloat64 on the grpcrand global source.
|
||||||
|
func ExpFloat64() float64 {
|
||||||
|
return rand.ExpFloat64()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffle implements rand.Shuffle on the grpcrand global source.
|
||||||
|
var Shuffle = func(n int, f func(int, int)) {
|
||||||
|
rand.Shuffle(n, f)
|
||||||
|
}
|
||||||
7
vendor/google.golang.org/grpc/internal/pretty/pretty.go
generated
vendored
7
vendor/google.golang.org/grpc/internal/pretty/pretty.go
generated
vendored
@@ -24,7 +24,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/golang/protobuf/jsonpb"
|
|
||||||
protov1 "github.com/golang/protobuf/proto"
|
protov1 "github.com/golang/protobuf/proto"
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
protov2 "google.golang.org/protobuf/proto"
|
protov2 "google.golang.org/protobuf/proto"
|
||||||
@@ -38,15 +37,15 @@ const jsonIndent = " "
|
|||||||
func ToJSON(e any) string {
|
func ToJSON(e any) string {
|
||||||
switch ee := e.(type) {
|
switch ee := e.(type) {
|
||||||
case protov1.Message:
|
case protov1.Message:
|
||||||
mm := jsonpb.Marshaler{Indent: jsonIndent}
|
mm := protojson.MarshalOptions{Indent: jsonIndent}
|
||||||
ret, err := mm.MarshalToString(ee)
|
ret, err := mm.Marshal(protov1.MessageV2(ee))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This may fail for proto.Anys, e.g. for xDS v2, LDS, the v2
|
// This may fail for proto.Anys, e.g. for xDS v2, LDS, the v2
|
||||||
// messages are not imported, and this will fail because the message
|
// messages are not imported, and this will fail because the message
|
||||||
// is not found.
|
// is not found.
|
||||||
return fmt.Sprintf("%+v", ee)
|
return fmt.Sprintf("%+v", ee)
|
||||||
}
|
}
|
||||||
return ret
|
return string(ret)
|
||||||
case protov2.Message:
|
case protov2.Message:
|
||||||
mm := protojson.MarshalOptions{
|
mm := protojson.MarshalOptions{
|
||||||
Multiline: true,
|
Multiline: true,
|
||||||
|
|||||||
15
vendor/google.golang.org/grpc/internal/status/status.go
generated
vendored
15
vendor/google.golang.org/grpc/internal/status/status.go
generated
vendored
@@ -31,10 +31,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/ptypes"
|
|
||||||
spb "google.golang.org/genproto/googleapis/rpc/status"
|
spb "google.golang.org/genproto/googleapis/rpc/status"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
"google.golang.org/protobuf/protoadapt"
|
||||||
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status represents an RPC status code, message, and details. It is immutable
|
// Status represents an RPC status code, message, and details. It is immutable
|
||||||
@@ -130,14 +131,14 @@ func (s *Status) Err() error {
|
|||||||
|
|
||||||
// WithDetails returns a new status with the provided details messages appended to the status.
|
// 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.
|
// If any errors are encountered, it returns nil and the first error encountered.
|
||||||
func (s *Status) WithDetails(details ...proto.Message) (*Status, error) {
|
func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) {
|
||||||
if s.Code() == codes.OK {
|
if s.Code() == codes.OK {
|
||||||
return nil, errors.New("no error details for status with code OK")
|
return nil, errors.New("no error details for status with code OK")
|
||||||
}
|
}
|
||||||
// s.Code() != OK implies that s.Proto() != nil.
|
// s.Code() != OK implies that s.Proto() != nil.
|
||||||
p := s.Proto()
|
p := s.Proto()
|
||||||
for _, detail := range details {
|
for _, detail := range details {
|
||||||
any, err := ptypes.MarshalAny(detail)
|
any, err := anypb.New(protoadapt.MessageV2Of(detail))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -154,12 +155,12 @@ func (s *Status) Details() []any {
|
|||||||
}
|
}
|
||||||
details := make([]any, 0, len(s.s.Details))
|
details := make([]any, 0, len(s.s.Details))
|
||||||
for _, any := range s.s.Details {
|
for _, any := range s.s.Details {
|
||||||
detail := &ptypes.DynamicAny{}
|
detail, err := any.UnmarshalNew()
|
||||||
if err := ptypes.UnmarshalAny(any, detail); err != nil {
|
if err != nil {
|
||||||
details = append(details, err)
|
details = append(details, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
details = append(details, detail.Message)
|
details = append(details, detail)
|
||||||
}
|
}
|
||||||
return details
|
return details
|
||||||
}
|
}
|
||||||
|
|||||||
2
vendor/google.golang.org/grpc/internal/transport/handler_server.go
generated
vendored
2
vendor/google.golang.org/grpc/internal/transport/handler_server.go
generated
vendored
@@ -35,7 +35,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
@@ -45,6 +44,7 @@ import (
|
|||||||
"google.golang.org/grpc/peer"
|
"google.golang.org/grpc/peer"
|
||||||
"google.golang.org/grpc/stats"
|
"google.golang.org/grpc/stats"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewServerHandlerTransport returns a ServerTransport handling gRPC from
|
// NewServerHandlerTransport returns a ServerTransport handling gRPC from
|
||||||
|
|||||||
6
vendor/google.golang.org/grpc/internal/transport/http2_server.go
generated
vendored
6
vendor/google.golang.org/grpc/internal/transport/http2_server.go
generated
vendored
@@ -32,13 +32,13 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
"google.golang.org/grpc/internal/grpclog"
|
"google.golang.org/grpc/internal/grpclog"
|
||||||
"google.golang.org/grpc/internal/grpcutil"
|
"google.golang.org/grpc/internal/grpcutil"
|
||||||
"google.golang.org/grpc/internal/pretty"
|
"google.golang.org/grpc/internal/pretty"
|
||||||
"google.golang.org/grpc/internal/syscall"
|
"google.golang.org/grpc/internal/syscall"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
@@ -652,10 +652,6 @@ func (t *http2Server) HandleStreams(ctx context.Context, handle func(*Stream)) {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err == io.EOF || err == io.ErrUnexpectedEOF {
|
|
||||||
t.Close(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t.Close(err)
|
t.Close(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
9
vendor/google.golang.org/grpc/internal/transport/transport.go
generated
vendored
9
vendor/google.golang.org/grpc/internal/transport/transport.go
generated
vendored
@@ -28,6 +28,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@@ -362,8 +363,12 @@ func (s *Stream) SendCompress() string {
|
|||||||
|
|
||||||
// ClientAdvertisedCompressors returns the compressor names advertised by the
|
// ClientAdvertisedCompressors returns the compressor names advertised by the
|
||||||
// client via grpc-accept-encoding header.
|
// client via grpc-accept-encoding header.
|
||||||
func (s *Stream) ClientAdvertisedCompressors() string {
|
func (s *Stream) ClientAdvertisedCompressors() []string {
|
||||||
return s.clientAdvertisedCompressors
|
values := strings.Split(s.clientAdvertisedCompressors, ",")
|
||||||
|
for i, v := range values {
|
||||||
|
values[i] = strings.TrimSpace(v)
|
||||||
|
}
|
||||||
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done returns a channel which is closed when it receives the final status
|
// Done returns a channel which is closed when it receives the final status
|
||||||
|
|||||||
4
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection.pb.go
generated
vendored
4
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection.pb.go
generated
vendored
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.32.0
|
||||||
// protoc v4.22.0
|
// protoc v4.25.2
|
||||||
// source: grpc/reflection/v1/reflection.proto
|
// source: grpc/reflection/v1/reflection.proto
|
||||||
|
|
||||||
package grpc_reflection_v1
|
package grpc_reflection_v1
|
||||||
|
|||||||
2
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go
generated
vendored
2
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go
generated
vendored
@@ -22,7 +22,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.3.0
|
// - protoc-gen-go-grpc v1.3.0
|
||||||
// - protoc v4.22.0
|
// - protoc v4.25.2
|
||||||
// source: grpc/reflection/v1/reflection.proto
|
// source: grpc/reflection/v1/reflection.proto
|
||||||
|
|
||||||
package grpc_reflection_v1
|
package grpc_reflection_v1
|
||||||
|
|||||||
4
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go
generated
vendored
4
vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go
generated
vendored
@@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.32.0
|
||||||
// protoc v4.22.0
|
// protoc v4.25.2
|
||||||
// grpc/reflection/v1alpha/reflection.proto is a deprecated file.
|
// grpc/reflection/v1alpha/reflection.proto is a deprecated file.
|
||||||
|
|
||||||
package grpc_reflection_v1alpha
|
package grpc_reflection_v1alpha
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.3.0
|
// - protoc-gen-go-grpc v1.3.0
|
||||||
// - protoc v4.22.0
|
// - protoc v4.25.2
|
||||||
// grpc/reflection/v1alpha/reflection.proto is a deprecated file.
|
// grpc/reflection/v1alpha/reflection.proto is a deprecated file.
|
||||||
|
|
||||||
package grpc_reflection_v1alpha
|
package grpc_reflection_v1alpha
|
||||||
|
|||||||
3
vendor/google.golang.org/grpc/resolver/resolver.go
generated
vendored
3
vendor/google.golang.org/grpc/resolver/resolver.go
generated
vendored
@@ -168,6 +168,9 @@ type BuildOptions struct {
|
|||||||
// field. In most cases though, it is not appropriate, and this field may
|
// field. In most cases though, it is not appropriate, and this field may
|
||||||
// be ignored.
|
// be ignored.
|
||||||
Dialer func(context.Context, string) (net.Conn, error)
|
Dialer func(context.Context, string) (net.Conn, error)
|
||||||
|
// Authority is the effective authority of the clientconn for which the
|
||||||
|
// resolver is built.
|
||||||
|
Authority string
|
||||||
}
|
}
|
||||||
|
|
||||||
// An Endpoint is one network endpoint, or server, which may have multiple
|
// An Endpoint is one network endpoint, or server, which may have multiple
|
||||||
|
|||||||
1
vendor/google.golang.org/grpc/resolver_wrapper.go
generated
vendored
1
vendor/google.golang.org/grpc/resolver_wrapper.go
generated
vendored
@@ -75,6 +75,7 @@ func (ccr *ccResolverWrapper) start() error {
|
|||||||
DialCreds: ccr.cc.dopts.copts.TransportCredentials,
|
DialCreds: ccr.cc.dopts.copts.TransportCredentials,
|
||||||
CredsBundle: ccr.cc.dopts.copts.CredsBundle,
|
CredsBundle: ccr.cc.dopts.copts.CredsBundle,
|
||||||
Dialer: ccr.cc.dopts.copts.Dialer,
|
Dialer: ccr.cc.dopts.copts.Dialer,
|
||||||
|
Authority: ccr.cc.authority,
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
ccr.resolver, err = ccr.cc.resolverBuilder.Build(ccr.cc.parsedTarget, ccr, opts)
|
ccr.resolver, err = ccr.cc.resolverBuilder.Build(ccr.cc.parsedTarget, ccr, opts)
|
||||||
|
|||||||
69
vendor/google.golang.org/grpc/rpc_util.go
generated
vendored
69
vendor/google.golang.org/grpc/rpc_util.go
generated
vendored
@@ -189,6 +189,20 @@ type EmptyCallOption struct{}
|
|||||||
func (EmptyCallOption) before(*callInfo) error { return nil }
|
func (EmptyCallOption) before(*callInfo) error { return nil }
|
||||||
func (EmptyCallOption) after(*callInfo, *csAttempt) {}
|
func (EmptyCallOption) after(*callInfo, *csAttempt) {}
|
||||||
|
|
||||||
|
// StaticMethod returns a CallOption which specifies that a call is being made
|
||||||
|
// to a method that is static, which means the method is known at compile time
|
||||||
|
// and doesn't change at runtime. This can be used as a signal to stats plugins
|
||||||
|
// that this method is safe to include as a key to a measurement.
|
||||||
|
func StaticMethod() CallOption {
|
||||||
|
return StaticMethodCallOption{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticMethodCallOption is a CallOption that specifies that a call comes
|
||||||
|
// from a static method.
|
||||||
|
type StaticMethodCallOption struct {
|
||||||
|
EmptyCallOption
|
||||||
|
}
|
||||||
|
|
||||||
// Header returns a CallOptions that retrieves the header metadata
|
// Header returns a CallOptions that retrieves the header metadata
|
||||||
// for a unary RPC.
|
// for a unary RPC.
|
||||||
func Header(md *metadata.MD) CallOption {
|
func Header(md *metadata.MD) CallOption {
|
||||||
@@ -730,17 +744,19 @@ type payloadInfo struct {
|
|||||||
uncompressedBytes []byte
|
uncompressedBytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) ([]byte, error) {
|
// recvAndDecompress reads a message from the stream, decompressing it if necessary.
|
||||||
pf, buf, err := p.recvMsg(maxReceiveMessageSize)
|
//
|
||||||
|
// Cancelling the returned cancel function releases the buffer back to the pool. So the caller should cancel as soon as
|
||||||
|
// the buffer is no longer needed.
|
||||||
|
func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor,
|
||||||
|
) (uncompressedBuf []byte, cancel func(), err error) {
|
||||||
|
pf, compressedBuf, err := p.recvMsg(maxReceiveMessageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
|
||||||
if payInfo != nil {
|
|
||||||
payInfo.compressedLength = len(buf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if st := checkRecvPayload(pf, s.RecvCompress(), compressor != nil || dc != nil); st != nil {
|
if st := checkRecvPayload(pf, s.RecvCompress(), compressor != nil || dc != nil); st != nil {
|
||||||
return nil, st.Err()
|
return nil, nil, st.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
var size int
|
var size int
|
||||||
@@ -748,21 +764,35 @@ func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxRecei
|
|||||||
// To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor,
|
// To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor,
|
||||||
// use this decompressor as the default.
|
// use this decompressor as the default.
|
||||||
if dc != nil {
|
if dc != nil {
|
||||||
buf, err = dc.Do(bytes.NewReader(buf))
|
uncompressedBuf, err = dc.Do(bytes.NewReader(compressedBuf))
|
||||||
size = len(buf)
|
size = len(uncompressedBuf)
|
||||||
} else {
|
} else {
|
||||||
buf, size, err = decompress(compressor, buf, maxReceiveMessageSize)
|
uncompressedBuf, size, err = decompress(compressor, compressedBuf, maxReceiveMessageSize)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message: %v", err)
|
return nil, nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message: %v", err)
|
||||||
}
|
}
|
||||||
if size > maxReceiveMessageSize {
|
if size > maxReceiveMessageSize {
|
||||||
// TODO: Revisit the error code. Currently keep it consistent with java
|
// TODO: Revisit the error code. Currently keep it consistent with java
|
||||||
// implementation.
|
// implementation.
|
||||||
return nil, status.Errorf(codes.ResourceExhausted, "grpc: received message after decompression larger than max (%d vs. %d)", size, maxReceiveMessageSize)
|
return nil, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message after decompression larger than max (%d vs. %d)", size, maxReceiveMessageSize)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uncompressedBuf = compressedBuf
|
||||||
|
}
|
||||||
|
|
||||||
|
if payInfo != nil {
|
||||||
|
payInfo.compressedLength = len(compressedBuf)
|
||||||
|
payInfo.uncompressedBytes = uncompressedBuf
|
||||||
|
|
||||||
|
cancel = func() {}
|
||||||
|
} else {
|
||||||
|
cancel = func() {
|
||||||
|
p.recvBufferPool.Put(&compressedBuf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf, nil
|
|
||||||
|
return uncompressedBuf, cancel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using compressor, decompress d, returning data and size.
|
// Using compressor, decompress d, returning data and size.
|
||||||
@@ -782,6 +812,9 @@ func decompress(compressor encoding.Compressor, d []byte, maxReceiveMessageSize
|
|||||||
// size is used as an estimate to size the buffer, but we
|
// size is used as an estimate to size the buffer, but we
|
||||||
// will read more data if available.
|
// will read more data if available.
|
||||||
// +MinRead so ReadFrom will not reallocate if size is correct.
|
// +MinRead so ReadFrom will not reallocate if size is correct.
|
||||||
|
//
|
||||||
|
// TODO: If we ensure that the buffer size is the same as the DecompressedSize,
|
||||||
|
// we can also utilize the recv buffer pool here.
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, size+bytes.MinRead))
|
buf := bytes.NewBuffer(make([]byte, 0, size+bytes.MinRead))
|
||||||
bytesRead, err := buf.ReadFrom(io.LimitReader(dcReader, int64(maxReceiveMessageSize)+1))
|
bytesRead, err := buf.ReadFrom(io.LimitReader(dcReader, int64(maxReceiveMessageSize)+1))
|
||||||
return buf.Bytes(), int(bytesRead), err
|
return buf.Bytes(), int(bytesRead), err
|
||||||
@@ -797,18 +830,15 @@ func decompress(compressor encoding.Compressor, d []byte, maxReceiveMessageSize
|
|||||||
// dc takes precedence over compressor.
|
// dc takes precedence over compressor.
|
||||||
// TODO(dfawley): wrap the old compressor/decompressor using the new API?
|
// TODO(dfawley): wrap the old compressor/decompressor using the new API?
|
||||||
func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m any, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) error {
|
func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m any, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor) error {
|
||||||
buf, err := recvAndDecompress(p, s, dc, maxReceiveMessageSize, payInfo, compressor)
|
buf, cancel, err := recvAndDecompress(p, s, dc, maxReceiveMessageSize, payInfo, compressor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
if err := c.Unmarshal(buf, m); err != nil {
|
if err := c.Unmarshal(buf, m); err != nil {
|
||||||
return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message: %v", err)
|
return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message: %v", err)
|
||||||
}
|
}
|
||||||
if payInfo != nil {
|
|
||||||
payInfo.uncompressedBytes = buf
|
|
||||||
} else {
|
|
||||||
p.recvBufferPool.Put(&buf)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -958,6 +988,7 @@ const (
|
|||||||
SupportPackageIsVersion5 = true
|
SupportPackageIsVersion5 = true
|
||||||
SupportPackageIsVersion6 = true
|
SupportPackageIsVersion6 = true
|
||||||
SupportPackageIsVersion7 = true
|
SupportPackageIsVersion7 = true
|
||||||
|
SupportPackageIsVersion8 = true
|
||||||
)
|
)
|
||||||
|
|
||||||
const grpcUA = "grpc-go/" + Version
|
const grpcUA = "grpc-go/" + Version
|
||||||
|
|||||||
21
vendor/google.golang.org/grpc/server.go
generated
vendored
21
vendor/google.golang.org/grpc/server.go
generated
vendored
@@ -33,8 +33,6 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/trace"
|
|
||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
@@ -131,7 +129,7 @@ type Server struct {
|
|||||||
drain bool
|
drain bool
|
||||||
cv *sync.Cond // signaled when connections close for GracefulStop
|
cv *sync.Cond // signaled when connections close for GracefulStop
|
||||||
services map[string]*serviceInfo // service name -> service info
|
services map[string]*serviceInfo // service name -> service info
|
||||||
events trace.EventLog
|
events traceEventLog
|
||||||
|
|
||||||
quit *grpcsync.Event
|
quit *grpcsync.Event
|
||||||
done *grpcsync.Event
|
done *grpcsync.Event
|
||||||
@@ -670,7 +668,7 @@ func NewServer(opt ...ServerOption) *Server {
|
|||||||
s.cv = sync.NewCond(&s.mu)
|
s.cv = sync.NewCond(&s.mu)
|
||||||
if EnableTracing {
|
if EnableTracing {
|
||||||
_, file, line, _ := runtime.Caller(1)
|
_, file, line, _ := runtime.Caller(1)
|
||||||
s.events = trace.NewEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line))
|
s.events = newTraceEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line))
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.opts.numServerWorkers > 0 {
|
if s.opts.numServerWorkers > 0 {
|
||||||
@@ -1344,7 +1342,8 @@ func (s *Server) processUnaryRPC(ctx context.Context, t transport.ServerTranspor
|
|||||||
if len(shs) != 0 || len(binlogs) != 0 {
|
if len(shs) != 0 || len(binlogs) != 0 {
|
||||||
payInfo = &payloadInfo{}
|
payInfo = &payloadInfo{}
|
||||||
}
|
}
|
||||||
d, err := recvAndDecompress(&parser{r: stream, recvBufferPool: s.opts.recvBufferPool}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp)
|
|
||||||
|
d, cancel, err := recvAndDecompress(&parser{r: stream, recvBufferPool: s.opts.recvBufferPool}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if e := t.WriteStatus(stream, status.Convert(err)); e != nil {
|
if e := t.WriteStatus(stream, status.Convert(err)); e != nil {
|
||||||
channelz.Warningf(logger, s.channelzID, "grpc: Server.processUnaryRPC failed to write status: %v", e)
|
channelz.Warningf(logger, s.channelzID, "grpc: Server.processUnaryRPC failed to write status: %v", e)
|
||||||
@@ -1355,6 +1354,8 @@ func (s *Server) processUnaryRPC(ctx context.Context, t transport.ServerTranspor
|
|||||||
t.IncrMsgRecv()
|
t.IncrMsgRecv()
|
||||||
}
|
}
|
||||||
df := func(v any) error {
|
df := func(v any) error {
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
if err := s.getCodec(stream.ContentSubtype()).Unmarshal(d, v); err != nil {
|
if err := s.getCodec(stream.ContentSubtype()).Unmarshal(d, v); err != nil {
|
||||||
return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err)
|
return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1734,8 +1735,8 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str
|
|||||||
ctx = contextWithServer(ctx, s)
|
ctx = contextWithServer(ctx, s)
|
||||||
var ti *traceInfo
|
var ti *traceInfo
|
||||||
if EnableTracing {
|
if EnableTracing {
|
||||||
tr := trace.New("grpc.Recv."+methodFamily(stream.Method()), stream.Method())
|
tr := newTrace("grpc.Recv."+methodFamily(stream.Method()), stream.Method())
|
||||||
ctx = trace.NewContext(ctx, tr)
|
ctx = newTraceContext(ctx, tr)
|
||||||
ti = &traceInfo{
|
ti = &traceInfo{
|
||||||
tr: tr,
|
tr: tr,
|
||||||
firstLine: firstLine{
|
firstLine: firstLine{
|
||||||
@@ -2119,7 +2120,7 @@ func ClientSupportedCompressors(ctx context.Context) ([]string, error) {
|
|||||||
return nil, fmt.Errorf("failed to fetch the stream from the given context %v", ctx)
|
return nil, fmt.Errorf("failed to fetch the stream from the given context %v", ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Split(stream.ClientAdvertisedCompressors(), ","), nil
|
return stream.ClientAdvertisedCompressors(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTrailer sets the trailer metadata that will be sent when an RPC returns.
|
// SetTrailer sets the trailer metadata that will be sent when an RPC returns.
|
||||||
@@ -2159,7 +2160,7 @@ func (c *channelzServer) ChannelzMetric() *channelz.ServerInternalMetric {
|
|||||||
|
|
||||||
// validateSendCompressor returns an error when given compressor name cannot be
|
// validateSendCompressor returns an error when given compressor name cannot be
|
||||||
// handled by the server or the client based on the advertised compressors.
|
// handled by the server or the client based on the advertised compressors.
|
||||||
func validateSendCompressor(name, clientCompressors string) error {
|
func validateSendCompressor(name string, clientCompressors []string) error {
|
||||||
if name == encoding.Identity {
|
if name == encoding.Identity {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -2168,7 +2169,7 @@ func validateSendCompressor(name, clientCompressors string) error {
|
|||||||
return fmt.Errorf("compressor not registered %q", name)
|
return fmt.Errorf("compressor not registered %q", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range strings.Split(clientCompressors, ",") {
|
for _, c := range clientCompressors {
|
||||||
if c == name {
|
if c == name {
|
||||||
return nil // found match
|
return nil // found match
|
||||||
}
|
}
|
||||||
|
|||||||
5
vendor/google.golang.org/grpc/stream.go
generated
vendored
5
vendor/google.golang.org/grpc/stream.go
generated
vendored
@@ -27,7 +27,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/trace"
|
|
||||||
"google.golang.org/grpc/balancer"
|
"google.golang.org/grpc/balancer"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
@@ -431,7 +430,7 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error)
|
|||||||
var trInfo *traceInfo
|
var trInfo *traceInfo
|
||||||
if EnableTracing {
|
if EnableTracing {
|
||||||
trInfo = &traceInfo{
|
trInfo = &traceInfo{
|
||||||
tr: trace.New("grpc.Sent."+methodFamily(method), method),
|
tr: newTrace("grpc.Sent."+methodFamily(method), method),
|
||||||
firstLine: firstLine{
|
firstLine: firstLine{
|
||||||
client: true,
|
client: true,
|
||||||
},
|
},
|
||||||
@@ -440,7 +439,7 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error)
|
|||||||
trInfo.firstLine.deadline = time.Until(deadline)
|
trInfo.firstLine.deadline = time.Until(deadline)
|
||||||
}
|
}
|
||||||
trInfo.tr.LazyLog(&trInfo.firstLine, false)
|
trInfo.tr.LazyLog(&trInfo.firstLine, false)
|
||||||
ctx = trace.NewContext(ctx, trInfo.tr)
|
ctx = newTraceContext(ctx, trInfo.tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cs.cc.parsedTarget.URL.Scheme == internal.GRPCResolverSchemeExtraMetadata {
|
if cs.cc.parsedTarget.URL.Scheme == internal.GRPCResolverSchemeExtraMetadata {
|
||||||
|
|||||||
26
vendor/google.golang.org/grpc/trace.go
generated
vendored
26
vendor/google.golang.org/grpc/trace.go
generated
vendored
@@ -26,8 +26,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/trace"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package.
|
// EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package.
|
||||||
@@ -44,9 +42,31 @@ func methodFamily(m string) string {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// traceEventLog mirrors golang.org/x/net/trace.EventLog.
|
||||||
|
//
|
||||||
|
// It exists in order to avoid importing x/net/trace on grpcnotrace builds.
|
||||||
|
type traceEventLog interface {
|
||||||
|
Printf(format string, a ...any)
|
||||||
|
Errorf(format string, a ...any)
|
||||||
|
Finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
// traceLog mirrors golang.org/x/net/trace.Trace.
|
||||||
|
//
|
||||||
|
// It exists in order to avoid importing x/net/trace on grpcnotrace builds.
|
||||||
|
type traceLog interface {
|
||||||
|
LazyLog(x fmt.Stringer, sensitive bool)
|
||||||
|
LazyPrintf(format string, a ...any)
|
||||||
|
SetError()
|
||||||
|
SetRecycler(f func(any))
|
||||||
|
SetTraceInfo(traceID, spanID uint64)
|
||||||
|
SetMaxEvents(m int)
|
||||||
|
Finish()
|
||||||
|
}
|
||||||
|
|
||||||
// traceInfo contains tracing information for an RPC.
|
// traceInfo contains tracing information for an RPC.
|
||||||
type traceInfo struct {
|
type traceInfo struct {
|
||||||
tr trace.Trace
|
tr traceLog
|
||||||
firstLine firstLine
|
firstLine firstLine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
vendor/google.golang.org/grpc/trace_notrace.go
generated
vendored
Normal file
52
vendor/google.golang.org/grpc/trace_notrace.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//go:build grpcnotrace
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2024 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
|
||||||
|
|
||||||
|
// grpcnotrace can be used to avoid importing golang.org/x/net/trace, which in
|
||||||
|
// turn enables binaries using gRPC-Go for dead code elimination, which can
|
||||||
|
// yield 10-15% improvements in binary size when tracing is not needed.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type notrace struct{}
|
||||||
|
|
||||||
|
func (notrace) LazyLog(x fmt.Stringer, sensitive bool) {}
|
||||||
|
func (notrace) LazyPrintf(format string, a ...any) {}
|
||||||
|
func (notrace) SetError() {}
|
||||||
|
func (notrace) SetRecycler(f func(any)) {}
|
||||||
|
func (notrace) SetTraceInfo(traceID, spanID uint64) {}
|
||||||
|
func (notrace) SetMaxEvents(m int) {}
|
||||||
|
func (notrace) Finish() {}
|
||||||
|
|
||||||
|
func newTrace(family, title string) traceLog {
|
||||||
|
return notrace{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTraceContext(ctx context.Context, tr traceLog) context.Context {
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTraceEventLog(family, title string) traceEventLog {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
39
vendor/google.golang.org/grpc/trace_withtrace.go
generated
vendored
Normal file
39
vendor/google.golang.org/grpc/trace_withtrace.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//go:build !grpcnotrace
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2024 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"
|
||||||
|
|
||||||
|
t "golang.org/x/net/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newTrace(family, title string) traceLog {
|
||||||
|
return t.New(family, title)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTraceContext(ctx context.Context, tr traceLog) context.Context {
|
||||||
|
return t.NewContext(ctx, tr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTraceEventLog(family, title string) traceEventLog {
|
||||||
|
return t.NewEventLog(family, title)
|
||||||
|
}
|
||||||
2
vendor/google.golang.org/grpc/version.go
generated
vendored
2
vendor/google.golang.org/grpc/version.go
generated
vendored
@@ -19,4 +19,4 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
// Version is the current grpc version.
|
// Version is the current grpc version.
|
||||||
const Version = "1.61.1"
|
const Version = "1.62.1"
|
||||||
|
|||||||
2
vendor/google.golang.org/grpc/vet.sh
generated
vendored
2
vendor/google.golang.org/grpc/vet.sh
generated
vendored
@@ -41,7 +41,7 @@ if [[ "$1" = "-install" ]]; then
|
|||||||
popd
|
popd
|
||||||
if [[ -z "${VET_SKIP_PROTO}" ]]; then
|
if [[ -z "${VET_SKIP_PROTO}" ]]; then
|
||||||
if [[ "${GITHUB_ACTIONS}" = "true" ]]; then
|
if [[ "${GITHUB_ACTIONS}" = "true" ]]; then
|
||||||
PROTOBUF_VERSION=22.0 # a.k.a v4.22.0 in pb.go files.
|
PROTOBUF_VERSION=25.2 # a.k.a. v4.22.0 in pb.go files.
|
||||||
PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
|
PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
|
||||||
pushd /home/runner/go
|
pushd /home/runner/go
|
||||||
wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME}
|
wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME}
|
||||||
|
|||||||
31
vendor/google.golang.org/protobuf/protoadapt/convert.go
generated
vendored
Normal file
31
vendor/google.golang.org/protobuf/protoadapt/convert.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2023 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package protoadapt bridges the original and new proto APIs.
|
||||||
|
package protoadapt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
"google.golang.org/protobuf/runtime/protoiface"
|
||||||
|
"google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MessageV1 is the original [github.com/golang/protobuf/proto.Message] type.
|
||||||
|
type MessageV1 = protoiface.MessageV1
|
||||||
|
|
||||||
|
// MessageV2 is the [google.golang.org/protobuf/proto.Message] type used by the
|
||||||
|
// current [google.golang.org/protobuf] module, adding support for reflection.
|
||||||
|
type MessageV2 = proto.Message
|
||||||
|
|
||||||
|
// MessageV1Of converts a v2 message to a v1 message.
|
||||||
|
// It returns nil if m is nil.
|
||||||
|
func MessageV1Of(m MessageV2) MessageV1 {
|
||||||
|
return protoimpl.X.ProtoMessageV1Of(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageV2Of converts a v1 message to a v2 message.
|
||||||
|
// It returns nil if m is nil.
|
||||||
|
func MessageV2Of(m MessageV1) MessageV2 {
|
||||||
|
return protoimpl.X.ProtoMessageV2Of(m)
|
||||||
|
}
|
||||||
16
vendor/modules.txt
vendored
16
vendor/modules.txt
vendored
@@ -54,7 +54,6 @@ github.com/golang/mock/mockgen/model
|
|||||||
# github.com/golang/protobuf v1.5.3
|
# github.com/golang/protobuf v1.5.3
|
||||||
## explicit; go 1.9
|
## explicit; go 1.9
|
||||||
github.com/golang/protobuf/descriptor
|
github.com/golang/protobuf/descriptor
|
||||||
github.com/golang/protobuf/jsonpb
|
|
||||||
github.com/golang/protobuf/proto
|
github.com/golang/protobuf/proto
|
||||||
github.com/golang/protobuf/protoc-gen-go/descriptor
|
github.com/golang/protobuf/protoc-gen-go/descriptor
|
||||||
github.com/golang/protobuf/ptypes
|
github.com/golang/protobuf/ptypes
|
||||||
@@ -80,7 +79,7 @@ github.com/google/go-cmp/cmp/internal/value
|
|||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
github.com/google/gofuzz
|
github.com/google/gofuzz
|
||||||
github.com/google/gofuzz/bytesource
|
github.com/google/gofuzz/bytesource
|
||||||
# github.com/google/uuid v1.4.0
|
# github.com/google/uuid v1.6.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/google/uuid
|
github.com/google/uuid
|
||||||
# github.com/imdario/mergo v0.3.13
|
# github.com/imdario/mergo v0.3.13
|
||||||
@@ -142,15 +141,15 @@ github.com/munnerz/goautoneg
|
|||||||
# github.com/pkg/errors v0.9.1
|
# github.com/pkg/errors v0.9.1
|
||||||
## explicit
|
## explicit
|
||||||
github.com/pkg/errors
|
github.com/pkg/errors
|
||||||
# github.com/prometheus/client_golang v1.18.0
|
# github.com/prometheus/client_golang v1.19.0
|
||||||
## explicit; go 1.19
|
## explicit; go 1.20
|
||||||
github.com/prometheus/client_golang/prometheus
|
github.com/prometheus/client_golang/prometheus
|
||||||
github.com/prometheus/client_golang/prometheus/internal
|
github.com/prometheus/client_golang/prometheus/internal
|
||||||
github.com/prometheus/client_golang/prometheus/promhttp
|
github.com/prometheus/client_golang/prometheus/promhttp
|
||||||
# github.com/prometheus/client_model v0.5.0
|
# github.com/prometheus/client_model v0.6.0
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
github.com/prometheus/client_model/go
|
github.com/prometheus/client_model/go
|
||||||
# github.com/prometheus/common v0.46.0
|
# github.com/prometheus/common v0.48.0
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
github.com/prometheus/common/expfmt
|
github.com/prometheus/common/expfmt
|
||||||
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
|
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
|
||||||
@@ -228,10 +227,10 @@ google.golang.org/appengine/internal/log
|
|||||||
google.golang.org/appengine/internal/remote_api
|
google.golang.org/appengine/internal/remote_api
|
||||||
google.golang.org/appengine/internal/urlfetch
|
google.golang.org/appengine/internal/urlfetch
|
||||||
google.golang.org/appengine/urlfetch
|
google.golang.org/appengine/urlfetch
|
||||||
# google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17
|
# google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
google.golang.org/genproto/googleapis/rpc/status
|
google.golang.org/genproto/googleapis/rpc/status
|
||||||
# google.golang.org/grpc v1.61.1
|
# google.golang.org/grpc v1.62.1
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
google.golang.org/grpc
|
google.golang.org/grpc
|
||||||
google.golang.org/grpc/attributes
|
google.golang.org/grpc/attributes
|
||||||
@@ -313,6 +312,7 @@ google.golang.org/protobuf/internal/set
|
|||||||
google.golang.org/protobuf/internal/strs
|
google.golang.org/protobuf/internal/strs
|
||||||
google.golang.org/protobuf/internal/version
|
google.golang.org/protobuf/internal/version
|
||||||
google.golang.org/protobuf/proto
|
google.golang.org/protobuf/proto
|
||||||
|
google.golang.org/protobuf/protoadapt
|
||||||
google.golang.org/protobuf/reflect/protodesc
|
google.golang.org/protobuf/reflect/protodesc
|
||||||
google.golang.org/protobuf/reflect/protoreflect
|
google.golang.org/protobuf/reflect/protoreflect
|
||||||
google.golang.org/protobuf/reflect/protoregistry
|
google.golang.org/protobuf/reflect/protoregistry
|
||||||
|
|||||||
Reference in New Issue
Block a user