Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c29cddcca0 |
No files matched your search
@@ -1,10 +0,0 @@
|
||||
Bugfix: Remove keyboard focus from open file name in top bar
|
||||
|
||||
When opening a file such as a text or markdown document, the file name shown
|
||||
in the top bar could be reached via keyboard tabbing even though it was not
|
||||
clickable and triggered no action. This made keyboard navigation confusing.
|
||||
|
||||
The file name is no longer part of the tab order, since it is a purely
|
||||
informational, non-interactive element.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12752
|
||||
@@ -1,14 +0,0 @@
|
||||
Bugfix: Truncate long resource names instead of overlapping the next column
|
||||
|
||||
In resource tables, a name that was too long for its column was not truncated.
|
||||
Instead it kept its full width and was painted over the value of the adjacent
|
||||
column, making both unreadable. This was most visible in the Spaces overview,
|
||||
where a long space name overlapped the "Manager" column, but it affected every
|
||||
resource table using the name column, including the files list and search
|
||||
results, as well as the parent folder path shown below a search result.
|
||||
|
||||
The name is now truncated with an ellipsis at the column boundary, and the
|
||||
rename button stays inside the name column. The full name remains available via
|
||||
the title tooltip on hover.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12754
|
||||
@@ -1,21 +0,0 @@
|
||||
Enhancement: Add a command to recalculate the treesize of a space
|
||||
|
||||
The reported quota usage of a space can drift from the data actually stored on
|
||||
disk. The treesize of a directory is maintained as a running counter that is
|
||||
updated on every change, so a failed or incomplete update leaves the counter
|
||||
wrong. Removing a node without propagating the size change, for example, leaves
|
||||
its size counted against the quota forever, with no way to reclaim it.
|
||||
|
||||
The new command walks a space bottom up, recalculates the treesize of every
|
||||
directory from the actual size of its children and corrects the stored values:
|
||||
|
||||
```
|
||||
ocis storage-users spaces recalculate-treesize --space-id <id>
|
||||
ocis storage-users spaces recalculate-treesize --space-id <id> --dry-run=false
|
||||
```
|
||||
|
||||
Omit `--space-id` to process all spaces. As with the other maintenance commands,
|
||||
`--dry-run` defaults to true, so the command reports what it would change until
|
||||
it is explicitly told to write.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12746
|
||||
@@ -1,17 +0,0 @@
|
||||
Bugfix: Open files whose name contains a hash or question mark
|
||||
|
||||
Cmd+Clicking or middle-clicking a file with a `#` or `?` in its name opened the
|
||||
space root instead of the file, and the top bar showed the space name rather than
|
||||
the file name. The file's path is carried in a route parameter which the router
|
||||
percent-encodes when it builds the URL, but the editor route was resolved twice
|
||||
and resolving twice does not encode twice: the second pass rebuilt the URL from
|
||||
the still-decoded parameter with the encoding step skipped. The browser then read
|
||||
everything from the `#` onward as a fragment, discarding the query string along
|
||||
with the `fileId` needed to identify the file. Left clicks were unaffected because
|
||||
they never leave the app.
|
||||
|
||||
Editor routes are now handed to links unresolved, so the file name is encoded
|
||||
exactly once and survives both a new tab and an in-app navigation. Hash and
|
||||
question mark remain valid characters in file names.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12740
|
||||
@@ -45,7 +45,7 @@ require (
|
||||
github.com/gookit/config/v2 v2.2.9
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0
|
||||
github.com/invopop/validation v0.8.0
|
||||
github.com/jellydator/ttlcache/v2 v2.11.1
|
||||
github.com/jellydator/ttlcache/v3 v3.4.1
|
||||
@@ -67,7 +67,7 @@ require (
|
||||
github.com/open-policy-agent/opa v1.19.0
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/xattr v0.4.12
|
||||
github.com/prometheus/client_golang v1.24.1
|
||||
@@ -89,14 +89,14 @@ require (
|
||||
github.com/xhit/go-simple-mail/v2 v2.16.0
|
||||
go-micro.dev/v4 v4.11.0
|
||||
go.etcd.io/bbolt v1.5.0
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0
|
||||
go.opentelemetry.io/contrib/zpages v0.70.0
|
||||
go.opentelemetry.io/otel v1.45.0
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.69.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0
|
||||
go.opentelemetry.io/contrib/zpages v0.69.0
|
||||
go.opentelemetry.io/otel v1.44.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0
|
||||
go.opentelemetry.io/otel/sdk v1.45.0
|
||||
go.opentelemetry.io/otel/trace v1.45.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0
|
||||
go.opentelemetry.io/otel/sdk v1.44.0
|
||||
go.opentelemetry.io/otel/trace v1.44.0
|
||||
golang.org/x/crypto v0.54.0
|
||||
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f
|
||||
golang.org/x/image v0.44.0
|
||||
@@ -105,7 +105,7 @@ require (
|
||||
golang.org/x/sync v0.22.0
|
||||
golang.org/x/term v0.45.0
|
||||
golang.org/x/text v0.40.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa
|
||||
google.golang.org/grpc v1.83.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
@@ -182,14 +182,14 @@ require (
|
||||
github.com/emvi/iso-639-1 v1.1.1 // indirect
|
||||
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
|
||||
github.com/fatih/color v1.19.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.1.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.10.1 // indirect
|
||||
github.com/gdexlab/go-render v1.0.1 // indirect
|
||||
github.com/go-acme/lego/v4 v4.34.0 // indirect
|
||||
github.com/go-asn1-ber/asn1-ber v1.5.8 // indirect
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.9.0 // indirect
|
||||
github.com/go-git/go-git/v5 v5.19.2 // indirect
|
||||
github.com/go-git/go-git/v5 v5.19.1 // indirect
|
||||
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
||||
github.com/go-kit/log v0.2.1 // indirect
|
||||
@@ -333,19 +333,19 @@ require (
|
||||
go.etcd.io/etcd/client/v3 v3.7.1 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.45.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.44.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.1 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.4 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/mod v0.37.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
golang.org/x/time v0.15.0 // indirect
|
||||
golang.org/x/tools v0.47.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.3 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
|
||||
@@ -256,8 +256,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF
|
||||
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
|
||||
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
|
||||
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
|
||||
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/foxcpp/go-mockdns v1.2.0 h1:omK3OrHRD1IWJz1FuFBCFquhXslXoF17OvBS6JPzZF0=
|
||||
@@ -298,8 +298,8 @@ github.com/go-git/go-billy/v5 v5.9.0 h1:jItGXszUDRtR/AlferWPTMN4j38BQ88XnXKbilmm
|
||||
github.com/go-git/go-billy/v5 v5.9.0/go.mod h1:jCnQMLj9eUgGU7+ludSTYoZL/GGmii14RxKFj7ROgHw=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
|
||||
github.com/go-git/go-git/v5 v5.19.2 h1:wkfn7vOlUBu8ivAWKBWisTiwJK4jYHzTF8Ndv1LyGqY=
|
||||
github.com/go-git/go-git/v5 v5.19.2/go.mod h1:QqCBE1EFN5ddFmrliLQ3/ntRCUjZU3EJuwuB/jWEHjk=
|
||||
github.com/go-git/go-git/v5 v5.19.1 h1:nX27AnaU43/K5bKktKwgBmR9lawoYVe1Ckg0rgzzN00=
|
||||
github.com/go-git/go-git/v5 v5.19.1/go.mod h1:Pb1v0c7/g8aGQJwx9Us09W85yGoyvSwuhEGMH7zjDKQ=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
@@ -499,8 +499,8 @@ github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
|
||||
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
|
||||
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
|
||||
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-plugin v1.8.0 h1:ie8S6RRY8RvB2usYZv+AAZ/wBvx2AU5p5QeP5j/FORs=
|
||||
@@ -736,8 +736,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
|
||||
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4 h1:Cnq24qhteHD30DfTG8o0bf3cnVL/2b+afz//0qGjAeU=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4/go.mod h1:XBnHPPDOGYq+Uf/PD1wGXne3xTvoghBxXPUULcSZjlc=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e h1:VyezYtf9tz6COz9sIk2i2szESueBPTI79KEOSR8I8Ug=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e/go.mod h1:XBnHPPDOGYq+Uf/PD1wGXne3xTvoghBxXPUULcSZjlc=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M=
|
||||
@@ -965,30 +965,30 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0 h1:oECp5f+hN7nkwjU/8BxQ/q23bGPb8FIrD839owX222E=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0/go.mod h1:DqEFwLumhzMBDQv9PcWbyoDxHI/4lAk6CM4nJBH39sc=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0 h1:LMuyCAyfalSjDyjdC65nK6N0zoTT63+E/u95X0JovZI=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0/go.mod h1:085m8qbm4hgc8rZWGDEa4vmyyo2c3nPxUslYUKUIU04=
|
||||
go.opentelemetry.io/contrib/zpages v0.70.0 h1:uBcclHekIrCRLO4KZfXiebDcWB52QQXaHGgvhUJ1K5I=
|
||||
go.opentelemetry.io/contrib/zpages v0.70.0/go.mod h1:Nz9A1+68HVoJrk+cg92zJbcbHFAa+Jbl1uINwAlcK94=
|
||||
go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU=
|
||||
go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.69.0 h1:2yEATaop1/a1I4psnSLgWVPLWwCzkqWakgJy7xTDVy0=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.69.0/go.mod h1:D7J12YRapIekYyPWgGPlA/23pRmpSEZC5xJC/TTLI9U=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0 h1:8tvICD4vSTOOsNrsI4Ljf6C+6UKvpTEH5XY3JMoyPoo=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0/go.mod h1:z9+yiacE0IHRqM4qFfkbt/JYlmYXgss8GY/jXoNuPJI=
|
||||
go.opentelemetry.io/contrib/zpages v0.69.0 h1:YQC1PumJq6lUGQNrLW14ID9a0dXSBcbC/aC6VRSIARU=
|
||||
go.opentelemetry.io/contrib/zpages v0.69.0/go.mod h1:FGvUcMGN5atRzUIgUsqOi+MiMvlQsfbuYATBHPP4cGs=
|
||||
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
|
||||
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 h1:QRefszxJmfPdjXUUm3j6iDzY03mTPXMjqErFqQ67vUg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0/go.mod h1:Tiz03lTBVBrm7eWZBOidzEaYaJa8tjwGUGv6d8mlTyk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0 h1:fG5MCxGz8+2VtrN/WgqSpJFctVz24gpxj8CxkKmc8Ww=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0/go.mod h1:BmAYTn+3ysbRe+IU2msxmf5Rx3g6DHvex+tWI3LdhYI=
|
||||
go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M=
|
||||
go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s=
|
||||
go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw=
|
||||
go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA=
|
||||
go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag=
|
||||
go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 h1:4YsVu3B8+3qtWYYrsUYgn0OG78pN0rnNPRGX4SbokQI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0/go.mod h1:+wnlSn0mD1ADVMe3v9Z/WIaiz6q6gL2J/ejaAmdmv80=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0 h1:qazEJlUOQzhCpzQpFETGby7EdqjI1wsd0W+6Gg1SCTU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0/go.mod h1:fOD2Yefuxixkx3ahVNf0O/PERb6r4OlbxfATVnYvzCo=
|
||||
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
|
||||
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
|
||||
go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
|
||||
go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
|
||||
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
|
||||
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
@@ -1001,9 +1001,8 @@ go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
|
||||
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
|
||||
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@@ -1326,10 +1325,10 @@ google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6D
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 h1:XzmzkmB14QhVhgnawEVsOn6OFsnpyxNPRY9QV01dNB0=
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:L43LFes82YgSonw6iTXTxXUX1OlULt4AQtkik4ULL/I=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d h1:FarXi840EJWSHYTN3ERkADbPWjl307+FGrA22KAVjjc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d/go.mod h1:K/+WGbmBY7aNW1HDw1fJnKYo10i0DkAX6pows00dLig=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d h1:IL4hdHzcUv2l/gcg98/Rj3FbtE6axwqslOW8SW0C+S0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
|
||||
@@ -181,45 +181,6 @@ OPTIONS:
|
||||
--help, -h show help
|
||||
```
|
||||
|
||||
Note that removing a stale node does not reclaim the quota it consumed. Use the
|
||||
Recalculate Treesize command afterwards to correct the reported quota usage of the space.
|
||||
|
||||
#### Recalculate Treesize command
|
||||
|
||||
The treesize of a directory is maintained as a running counter that is updated on every
|
||||
change, so a failed or incomplete update leaves the counter wrong and the reported quota
|
||||
usage of a space drifts from the data actually stored on disk. This command walks a space
|
||||
bottom up, recalculates the treesize of every directory from the actual size of its
|
||||
children and corrects the stored values.
|
||||
|
||||
```bash
|
||||
~/ocis storage-users spaces recalculate-treesize <commandoptions>
|
||||
```
|
||||
```
|
||||
NAME:
|
||||
ocis storage-users spaces recalculate-treesize - Recalculate the treesize of all directories in a space from the actual size of their children. Use this to repair a space whose reported quota usage drifted from the data on disk
|
||||
|
||||
USAGE:
|
||||
ocis storage-users spaces recalculate-treesize [command options]
|
||||
|
||||
OPTIONS:
|
||||
--space-id value, -s value Space ID to recalculate (omit to process all spaces)
|
||||
--dry-run Only show which treesizes would be corrected without writing them (default: true)
|
||||
--verbose, -v Enable verbose logging (default: false)
|
||||
--help, -h show help
|
||||
```
|
||||
|
||||
```bash
|
||||
# report incorrect treesizes of a single space without changing anything
|
||||
ocis storage-users spaces recalculate-treesize --space-id 43972c79-f7ce-441b-9fe0-cf5170e4d61e
|
||||
|
||||
# correct them
|
||||
ocis storage-users spaces recalculate-treesize --space-id 43972c79-f7ce-441b-9fe0-cf5170e4d61e --dry-run=false
|
||||
```
|
||||
|
||||
Note: the command reads the metadata of every node in the space, so it is I/O intensive on
|
||||
large spaces. Prefer targeting a single space with `--space-id` over processing all spaces.
|
||||
|
||||
#### Command Examples
|
||||
|
||||
Dry run to see what would be deleted (recommended first step)
|
||||
|
||||
@@ -33,7 +33,6 @@ func Spaces(cfg *config.Config) *cli.Command {
|
||||
Usage: "manage spaces",
|
||||
Subcommands: []*cli.Command{
|
||||
PurgeDisabledSpaces(cfg),
|
||||
RecalculateTreesize(cfg),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,222 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config/parser"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/lookup"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
|
||||
"github.com/shamaton/msgpack/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// metadataExtension is the suffix of the messagepack metadata file of a node
|
||||
const metadataExtension = ".mpk"
|
||||
|
||||
// RecalculateTreesize is the entry point for the recalculate-treesize command
|
||||
func RecalculateTreesize(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "recalculate-treesize",
|
||||
Usage: "Recalculate the treesize of all directories in a space from the actual size of their children. " +
|
||||
"Use this to repair a space whose reported quota usage drifted from the data on disk",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "space-id",
|
||||
Usage: "Space ID to recalculate (omit to process all spaces)",
|
||||
Required: false,
|
||||
Aliases: []string{"s"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "Only show which treesizes would be corrected without writing them",
|
||||
Value: true, // default must be true to avoid accidental writes!
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "verbose",
|
||||
Usage: "Enable verbose logging",
|
||||
Value: false,
|
||||
Aliases: []string{"v"},
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
dryRun := c.Bool("dry-run")
|
||||
verbose := c.Bool("verbose")
|
||||
|
||||
spaceIDs := []string{}
|
||||
if c.IsSet("space-id") {
|
||||
spaceIDs = append(spaceIDs, c.String("space-id"))
|
||||
} else {
|
||||
fmt.Println("Scanning all spaces for incorrect treesizes...")
|
||||
spaceIDs = globSpaceIDs(cfg)
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
fmt.Print("Dry run mode enabled, no treesize will be written\n\n")
|
||||
}
|
||||
|
||||
var (
|
||||
table *tablewriter.Table
|
||||
corrected int
|
||||
)
|
||||
table = tablewriter.NewTable(os.Stdout)
|
||||
table.Header("Space", "Node", "Stored", "Calculated", "Difference")
|
||||
|
||||
for _, spaceID := range spaceIDs {
|
||||
if verbose {
|
||||
fmt.Printf("Recalculating treesizes for space: %s\n", spaceID)
|
||||
}
|
||||
root := filepath.Join(cfg.Drivers.OCIS.Root, "spaces", lookup.Pathify(spaceID, 1, 2), "nodes", lookup.Pathify(spaceID, 4, 2))
|
||||
_, n, err := recalculateNode(cfg, spaceID, root, dryRun, verbose, table)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error recalculating space %s: %s\n", spaceID, err)
|
||||
continue
|
||||
}
|
||||
corrected += n
|
||||
}
|
||||
|
||||
if corrected > 0 {
|
||||
table.Render()
|
||||
}
|
||||
|
||||
switch {
|
||||
case corrected == 0:
|
||||
fmt.Println("All treesizes are correct")
|
||||
case dryRun:
|
||||
fmt.Printf("Would correct %d treesizes. Run with --dry-run=false to apply\n", corrected)
|
||||
default:
|
||||
fmt.Printf("Corrected %d treesizes\n", corrected)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// recalculateNode calculates the size of the node at the given path. For directories it
|
||||
// recurses into the children first, so the whole subtree is corrected bottom up, and
|
||||
// compares the sum against the stored treesize. It returns the calculated size of the
|
||||
// node and the number of corrected treesizes in the subtree.
|
||||
func recalculateNode(cfg *config.Config, spaceID, path string, dryRun, verbose bool, table *tablewriter.Table) (uint64, int, error) {
|
||||
attribs, err := readAttributes(path)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
// Files simply report their blobsize, there is nothing to recalculate. Only an
|
||||
// explicit file type is treated as a file, everything else is walked as a
|
||||
// directory: a space root for example carries no type attribute at all. This
|
||||
// matches how the propagator classifies children.
|
||||
if string(attribs[prefixes.TypeAttr]) == strconv.FormatUint(uint64(provider.ResourceType_RESOURCE_TYPE_FILE), 10) {
|
||||
size, err := strconv.ParseUint(string(attribs[prefixes.BlobsizeAttr]), 10, 64)
|
||||
if err != nil {
|
||||
// a node without a blobsize contributes nothing, but it is worth reporting
|
||||
if verbose {
|
||||
fmt.Fprintf(os.Stderr, " Could not read blobsize of %s: %s\n", path, err)
|
||||
}
|
||||
return 0, 0, nil
|
||||
}
|
||||
return size, 0, nil
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
var (
|
||||
calculated uint64
|
||||
corrected int
|
||||
)
|
||||
for _, entry := range entries {
|
||||
child, err := filepath.EvalSymlinks(filepath.Join(path, entry.Name()))
|
||||
if err != nil {
|
||||
// dangling child entry, it contributes nothing
|
||||
if verbose {
|
||||
fmt.Fprintf(os.Stderr, " Could not resolve child %s: %s\n", entry.Name(), err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
size, n, err := recalculateNode(cfg, spaceID, child, dryRun, verbose, table)
|
||||
if err != nil {
|
||||
if verbose {
|
||||
fmt.Fprintf(os.Stderr, " Could not recalculate child %s: %s\n", child, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
calculated += size
|
||||
corrected += n
|
||||
}
|
||||
|
||||
stored, storedErr := strconv.ParseUint(string(attribs[prefixes.TreesizeAttr]), 10, 64)
|
||||
if storedErr == nil && stored == calculated {
|
||||
return calculated, corrected, nil
|
||||
}
|
||||
|
||||
storedStr := string(attribs[prefixes.TreesizeAttr])
|
||||
if storedStr == "" {
|
||||
storedStr = "unset"
|
||||
}
|
||||
diff := "n/a"
|
||||
if storedErr == nil {
|
||||
diff = fmt.Sprintf("%+d", int64(calculated)-int64(stored))
|
||||
}
|
||||
table.Append([]string{spaceID, nodeIDFromPath(path), storedStr, strconv.FormatUint(calculated, 10), diff})
|
||||
corrected++
|
||||
|
||||
if !dryRun {
|
||||
if err := writeTreesize(path, attribs, calculated); err != nil {
|
||||
return calculated, corrected, fmt.Errorf("could not write treesize of %s: %w", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
return calculated, corrected, nil
|
||||
}
|
||||
|
||||
// readAttributes reads the messagepack metadata of the node at the given path
|
||||
func readAttributes(path string) (map[string][]byte, error) {
|
||||
b, err := os.ReadFile(path + metadataExtension)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
attribs := map[string][]byte{}
|
||||
if err := msgpack.Unmarshal(b, &attribs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return attribs, nil
|
||||
}
|
||||
|
||||
// writeTreesize sets the treesize attribute of the node at the given path
|
||||
func writeTreesize(path string, attribs map[string][]byte, size uint64) error {
|
||||
attribs[prefixes.TreesizeAttr] = []byte(strconv.FormatUint(size, 10))
|
||||
b, err := msgpack.Marshal(attribs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path+metadataExtension, b, 0600)
|
||||
}
|
||||
|
||||
// nodeIDFromPath rebuilds the node id from a pathified node path, i.e.
|
||||
// .../nodes/5b/ba/1e/a7/-f185-4f31-8342-ed4b5743f096 -> 5bba1ea7-f185-4f31-8342-ed4b5743f096
|
||||
func nodeIDFromPath(path string) string {
|
||||
parts := strings.Split(path, string(filepath.Separator))
|
||||
if len(parts) < 5 {
|
||||
return path
|
||||
}
|
||||
return strings.Join(parts[len(parts)-5:], "")
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
|
||||
"github.com/shamaton/msgpack/v2"
|
||||
"github.com/test-go/testify/require"
|
||||
)
|
||||
|
||||
// writeNode creates a node file with the given attributes on disk
|
||||
func writeNode(t *testing.T, path string, attribs map[string][]byte) {
|
||||
t.Helper()
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0700))
|
||||
b, err := msgpack.Marshal(attribs)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(path+metadataExtension, b, 0600))
|
||||
}
|
||||
|
||||
// writeFileNode creates a file node with the given blobsize. The node file itself
|
||||
// has to exist as well, decomposedfs resolves children through it.
|
||||
func writeFileNode(t *testing.T, path string, blobsize int) {
|
||||
t.Helper()
|
||||
writeNode(t, path, map[string][]byte{
|
||||
prefixes.TypeAttr: []byte(strconv.FormatUint(uint64(provider.ResourceType_RESOURCE_TYPE_FILE), 10)),
|
||||
prefixes.BlobsizeAttr: []byte(strconv.Itoa(blobsize)),
|
||||
})
|
||||
require.NoError(t, os.WriteFile(path, []byte{}, 0600))
|
||||
}
|
||||
|
||||
// writeDirNode creates a directory node with the given stored treesize
|
||||
func writeDirNode(t *testing.T, path string, treesize int) {
|
||||
t.Helper()
|
||||
require.NoError(t, os.MkdirAll(path, 0700))
|
||||
writeNode(t, path, map[string][]byte{
|
||||
prefixes.TypeAttr: []byte(strconv.FormatUint(uint64(provider.ResourceType_RESOURCE_TYPE_CONTAINER), 10)),
|
||||
prefixes.TreesizeAttr: []byte(strconv.Itoa(treesize)),
|
||||
})
|
||||
}
|
||||
|
||||
// storedTreesize reads back the treesize attribute of a node
|
||||
func storedTreesize(t *testing.T, path string) string {
|
||||
t.Helper()
|
||||
attribs, err := readAttributes(path)
|
||||
require.NoError(t, err)
|
||||
return string(attribs[prefixes.TreesizeAttr])
|
||||
}
|
||||
|
||||
// linkChild links a child node into a parent directory, mirroring how decomposedfs
|
||||
// references children by symlink
|
||||
func linkChild(t *testing.T, parent, child, name string) {
|
||||
t.Helper()
|
||||
rel, err := filepath.Rel(parent, child)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.Symlink(rel, filepath.Join(parent, name)))
|
||||
}
|
||||
|
||||
func TestRecalculateNode(t *testing.T) {
|
||||
t.Run("corrects a wrong treesize", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "dir")
|
||||
writeDirNode(t, dir, 999)
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 100)
|
||||
linkChild(t, dir, f, "file")
|
||||
|
||||
size, corrected, err := recalculateNode(nil, "spaceid", dir, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(100), size)
|
||||
require.Equal(t, 1, corrected)
|
||||
require.Equal(t, "100", storedTreesize(t, dir))
|
||||
})
|
||||
|
||||
t.Run("leaves a correct treesize untouched", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "dir")
|
||||
writeDirNode(t, dir, 100)
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 100)
|
||||
linkChild(t, dir, f, "file")
|
||||
|
||||
size, corrected, err := recalculateNode(nil, "spaceid", dir, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(100), size)
|
||||
require.Equal(t, 0, corrected)
|
||||
})
|
||||
|
||||
t.Run("does not write in dry-run mode", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "dir")
|
||||
writeDirNode(t, dir, 999)
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 100)
|
||||
linkChild(t, dir, f, "file")
|
||||
|
||||
size, corrected, err := recalculateNode(nil, "spaceid", dir, true, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(100), size)
|
||||
require.Equal(t, 1, corrected)
|
||||
require.Equal(t, "999", storedTreesize(t, dir), "dry-run must not write the treesize")
|
||||
})
|
||||
|
||||
t.Run("sums nested directories bottom up", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
outer := filepath.Join(root, "outer")
|
||||
writeDirNode(t, outer, 0)
|
||||
inner := filepath.Join(root, "inner")
|
||||
writeDirNode(t, inner, 0)
|
||||
f1 := filepath.Join(root, "f1")
|
||||
writeFileNode(t, f1, 10)
|
||||
f2 := filepath.Join(root, "f2")
|
||||
writeFileNode(t, f2, 32)
|
||||
|
||||
linkChild(t, inner, f2, "f2")
|
||||
linkChild(t, outer, f1, "f1")
|
||||
linkChild(t, outer, inner, "inner")
|
||||
|
||||
size, corrected, err := recalculateNode(nil, "spaceid", outer, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(42), size)
|
||||
require.Equal(t, 2, corrected, "both the inner and the outer directory are corrected")
|
||||
require.Equal(t, "32", storedTreesize(t, inner))
|
||||
require.Equal(t, "42", storedTreesize(t, outer))
|
||||
})
|
||||
|
||||
t.Run("treats a node without a type attribute as a directory", func(t *testing.T) {
|
||||
// space roots carry no type attribute
|
||||
root := t.TempDir()
|
||||
spaceRoot := filepath.Join(root, "space")
|
||||
require.NoError(t, os.MkdirAll(spaceRoot, 0700))
|
||||
writeNode(t, spaceRoot, map[string][]byte{
|
||||
prefixes.TreesizeAttr: []byte("999"),
|
||||
})
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 64)
|
||||
linkChild(t, spaceRoot, f, "file")
|
||||
|
||||
size, corrected, err := recalculateNode(nil, "spaceid", spaceRoot, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(64), size)
|
||||
require.Equal(t, 1, corrected)
|
||||
require.Equal(t, "64", storedTreesize(t, spaceRoot))
|
||||
})
|
||||
|
||||
t.Run("skips dangling child links", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "dir")
|
||||
writeDirNode(t, dir, 0)
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 20)
|
||||
linkChild(t, dir, f, "file")
|
||||
require.NoError(t, os.Symlink("../gone", filepath.Join(dir, "gone")))
|
||||
|
||||
size, _, err := recalculateNode(nil, "spaceid", dir, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(20), size, "the dangling entry contributes nothing")
|
||||
})
|
||||
|
||||
t.Run("sets an unset treesize", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "dir")
|
||||
require.NoError(t, os.MkdirAll(dir, 0700))
|
||||
writeNode(t, dir, map[string][]byte{
|
||||
prefixes.TypeAttr: []byte(strconv.FormatUint(uint64(provider.ResourceType_RESOURCE_TYPE_CONTAINER), 10)),
|
||||
})
|
||||
f := filepath.Join(root, "file")
|
||||
writeFileNode(t, f, 7)
|
||||
linkChild(t, dir, f, "file")
|
||||
|
||||
_, corrected, err := recalculateNode(nil, "spaceid", dir, false, false, tablewriter.NewTable(os.Stdout))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, corrected)
|
||||
require.Equal(t, "7", storedTreesize(t, dir))
|
||||
})
|
||||
}
|
||||
@@ -137,17 +137,7 @@ class CollaborationContext implements Context {
|
||||
string $folder,
|
||||
string $space,
|
||||
): void {
|
||||
// getResourceId does a single PROPFIND; after a share invite the xattr grant
|
||||
// may not be visible yet, so retry until oc:fileid is non-empty.
|
||||
$retried = 0;
|
||||
do {
|
||||
$parentContainerId = $this->spacesContext->getResourceId($user, $space, $folder);
|
||||
$tryAgain = empty($parentContainerId) && $retried < HttpRequestHelper::maxHTTPRequestRetries();
|
||||
if ($tryAgain) {
|
||||
$retried += 1;
|
||||
\usleep(500 * 1000);
|
||||
}
|
||||
} while ($tryAgain);
|
||||
$parentContainerId = $this->spacesContext->getResourceId($user, $space, $folder);
|
||||
$this->featureContext->setResponse(
|
||||
CollaborationHelper::createFile(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
|
||||
@@ -1739,49 +1739,6 @@ class SharingNgContext implements Context {
|
||||
$this->waitAndCheckShareSyncStatus($user, $resource, "enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" has a share "([^"]*)" accessible via WebDAV$/
|
||||
*
|
||||
* Waits until the share mount point is reachable via WebDAV PROPFIND (HTTP 207).
|
||||
* This is a storage-layer readiness check that complements userHasShareSynced,
|
||||
* which only checks the JSON share-manager state. The xattr grant written by
|
||||
* AddGrant may still be propagating when the share-manager state already reads
|
||||
* ACCEPTED, so resolveAcceptedShare's Stat call can fail transiently without
|
||||
* this extra gate.
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $resource
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userHasShareAccessibleViaWebDAV(string $user, string $resource): void {
|
||||
$resource = \trim($resource, '/');
|
||||
$davPath = WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_NEW, $user);
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
$password = $this->featureContext->getPasswordForUser($user);
|
||||
|
||||
$retried = 0;
|
||||
do {
|
||||
$response = HttpRequestHelper::sendRequest(
|
||||
"$baseUrl/$davPath/Shares/$resource",
|
||||
'PROPFIND',
|
||||
$user,
|
||||
$password,
|
||||
['Depth' => '0'],
|
||||
);
|
||||
if ($response->getStatusCode() === 207) {
|
||||
return;
|
||||
}
|
||||
$tryAgain = $retried < HttpRequestHelper::maxHTTPRequestRetries();
|
||||
if ($tryAgain) {
|
||||
$retried += 1;
|
||||
\usleep(500 * 1000);
|
||||
}
|
||||
} while ($tryAgain);
|
||||
Assert::fail("[Timeout] Share '$resource' for user '$user' not accessible via WebDAV after retries");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^user "([^"]*)" should have sync (enabled|disabled) for share "([^"]*)"$/
|
||||
*
|
||||
|
||||
@@ -107,7 +107,6 @@ Feature: sharing
|
||||
| shareType | user |
|
||||
| permissionsRole | <permissions-role> |
|
||||
And user "Carol" has a share "sharefile.txt" synced
|
||||
And user "Carol" has a share "sharefile.txt" accessible via WebDAV
|
||||
When user "Carol" moves file "Shares/sharefile.txt" to "Shares/renamedsharefile.txt" using the WebDAV API
|
||||
Then the HTTP status code should be "201"
|
||||
And as "Carol" file "Shares/renamedsharefile.txt" should exist
|
||||
@@ -150,7 +149,6 @@ Feature: sharing
|
||||
| shareType | user |
|
||||
| permissionsRole | <permissions-role> |
|
||||
And user "Carol" has a share "sharefile.txt" synced
|
||||
And user "Carol" has a share "sharefile.txt" accessible via WebDAV
|
||||
When user "Carol" moves file "Shares/sharefile.txt" to "Shares/renamedsharefile.txt" using the WebDAV API
|
||||
Then the HTTP status code should be "201"
|
||||
And as "Carol" file "Shares/renamedsharefile.txt" should exist
|
||||
|
||||
+1
-36
@@ -69,16 +69,6 @@ func (m *Metrics) CaptureMetrics(w http.ResponseWriter, fn func(http.ResponseWri
|
||||
}
|
||||
},
|
||||
|
||||
WriteString: func(next WriteStringFunc) WriteStringFunc {
|
||||
return func(s string) (int, error) {
|
||||
n, err := next(s)
|
||||
|
||||
m.Written += int64(n)
|
||||
headerWritten = true
|
||||
return n, err
|
||||
}
|
||||
},
|
||||
|
||||
ReadFrom: func(next ReadFromFunc) ReadFromFunc {
|
||||
return func(src io.Reader) (int64, error) {
|
||||
n, err := next(src)
|
||||
@@ -91,31 +81,6 @@ func (m *Metrics) CaptureMetrics(w http.ResponseWriter, fn func(http.ResponseWri
|
||||
}
|
||||
)
|
||||
|
||||
// defer to ensure duration is updated even if the handler panics
|
||||
defer func() {
|
||||
m.Duration += time.Since(start)
|
||||
}()
|
||||
fn(Wrap(w, hooks))
|
||||
}
|
||||
|
||||
// deadliner defines two methods introduced in go 1.20. The standard library
|
||||
// seems not to provide an interface we can import, hence its definition here.
|
||||
type deadliner interface {
|
||||
SetReadDeadline(deadline time.Time) error
|
||||
SetWriteDeadline(deadline time.Time) error
|
||||
}
|
||||
|
||||
// fullDuplexEnabler defines a method introduced in go 1.21. The standard
|
||||
// library seems not to provide an interface we can import, hence its definition
|
||||
// here.
|
||||
type fullDuplexEnabler interface {
|
||||
EnableFullDuplex() error
|
||||
}
|
||||
|
||||
// httpFlushError defines a method introduced in go 1.20. The standard
|
||||
// library seems not to provide an interface we can import, hence its definition
|
||||
// here.
|
||||
// See https://github.com/golang/go/blob/go1.20/src/net/http/responsecontroller.go#L50
|
||||
type httpFlushError interface {
|
||||
FlushError() error
|
||||
m.Duration += time.Since(start)
|
||||
}
|
||||
-16179
File diff suppressed because it is too large.
Load diff
+436
@@ -0,0 +1,436 @@
|
||||
// +build go1.8
|
||||
// Code generated by "httpsnoop/codegen"; DO NOT EDIT.
|
||||
|
||||
package httpsnoop
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HeaderFunc is part of the http.ResponseWriter interface.
|
||||
type HeaderFunc func() http.Header
|
||||
|
||||
// WriteHeaderFunc is part of the http.ResponseWriter interface.
|
||||
type WriteHeaderFunc func(code int)
|
||||
|
||||
// WriteFunc is part of the http.ResponseWriter interface.
|
||||
type WriteFunc func(b []byte) (int, error)
|
||||
|
||||
// FlushFunc is part of the http.Flusher interface.
|
||||
type FlushFunc func()
|
||||
|
||||
// CloseNotifyFunc is part of the http.CloseNotifier interface.
|
||||
type CloseNotifyFunc func() <-chan bool
|
||||
|
||||
// HijackFunc is part of the http.Hijacker interface.
|
||||
type HijackFunc func() (net.Conn, *bufio.ReadWriter, error)
|
||||
|
||||
// ReadFromFunc is part of the io.ReaderFrom interface.
|
||||
type ReadFromFunc func(src io.Reader) (int64, error)
|
||||
|
||||
// PushFunc is part of the http.Pusher interface.
|
||||
type PushFunc func(target string, opts *http.PushOptions) error
|
||||
|
||||
// Hooks defines a set of method interceptors for methods included in
|
||||
// http.ResponseWriter as well as some others. You can think of them as
|
||||
// middleware for the function calls they target. See Wrap for more details.
|
||||
type Hooks struct {
|
||||
Header func(HeaderFunc) HeaderFunc
|
||||
WriteHeader func(WriteHeaderFunc) WriteHeaderFunc
|
||||
Write func(WriteFunc) WriteFunc
|
||||
Flush func(FlushFunc) FlushFunc
|
||||
CloseNotify func(CloseNotifyFunc) CloseNotifyFunc
|
||||
Hijack func(HijackFunc) HijackFunc
|
||||
ReadFrom func(ReadFromFunc) ReadFromFunc
|
||||
Push func(PushFunc) PushFunc
|
||||
}
|
||||
|
||||
// Wrap returns a wrapped version of w that provides the exact same interface
|
||||
// as w. Specifically if w implements any combination of:
|
||||
//
|
||||
// - http.Flusher
|
||||
// - http.CloseNotifier
|
||||
// - http.Hijacker
|
||||
// - io.ReaderFrom
|
||||
// - http.Pusher
|
||||
//
|
||||
// The wrapped version will implement the exact same combination. If no hooks
|
||||
// are set, the wrapped version also behaves exactly as w. Hooks targeting
|
||||
// methods not supported by w are ignored. Any other hooks will intercept the
|
||||
// method they target and may modify the call's arguments and/or return values.
|
||||
// The CaptureMetrics implementation serves as a working example for how the
|
||||
// hooks can be used.
|
||||
func Wrap(w http.ResponseWriter, hooks Hooks) http.ResponseWriter {
|
||||
rw := &rw{w: w, h: hooks}
|
||||
_, i0 := w.(http.Flusher)
|
||||
_, i1 := w.(http.CloseNotifier)
|
||||
_, i2 := w.(http.Hijacker)
|
||||
_, i3 := w.(io.ReaderFrom)
|
||||
_, i4 := w.(http.Pusher)
|
||||
switch {
|
||||
// combination 1/32
|
||||
case !i0 && !i1 && !i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
}{rw, rw}
|
||||
// combination 2/32
|
||||
case !i0 && !i1 && !i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Pusher
|
||||
}{rw, rw, rw}
|
||||
// combination 3/32
|
||||
case !i0 && !i1 && !i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw}
|
||||
// combination 4/32
|
||||
case !i0 && !i1 && !i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 5/32
|
||||
case !i0 && !i1 && i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
}{rw, rw, rw}
|
||||
// combination 6/32
|
||||
case !i0 && !i1 && i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 7/32
|
||||
case !i0 && !i1 && i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 8/32
|
||||
case !i0 && !i1 && i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 9/32
|
||||
case !i0 && i1 && !i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
}{rw, rw, rw}
|
||||
// combination 10/32
|
||||
case !i0 && i1 && !i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 11/32
|
||||
case !i0 && i1 && !i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 12/32
|
||||
case !i0 && i1 && !i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 13/32
|
||||
case !i0 && i1 && i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 14/32
|
||||
case !i0 && i1 && i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 15/32
|
||||
case !i0 && i1 && i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 16/32
|
||||
case !i0 && i1 && i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
// combination 17/32
|
||||
case i0 && !i1 && !i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
}{rw, rw, rw}
|
||||
// combination 18/32
|
||||
case i0 && !i1 && !i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 19/32
|
||||
case i0 && !i1 && !i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 20/32
|
||||
case i0 && !i1 && !i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 21/32
|
||||
case i0 && !i1 && i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 22/32
|
||||
case i0 && !i1 && i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 23/32
|
||||
case i0 && !i1 && i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 24/32
|
||||
case i0 && !i1 && i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
// combination 25/32
|
||||
case i0 && i1 && !i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 26/32
|
||||
case i0 && i1 && !i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 27/32
|
||||
case i0 && i1 && !i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 28/32
|
||||
case i0 && i1 && !i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
// combination 29/32
|
||||
case i0 && i1 && i2 && !i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 30/32
|
||||
case i0 && i1 && i2 && !i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
// combination 31/32
|
||||
case i0 && i1 && i2 && i3 && !i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
// combination 32/32
|
||||
case i0 && i1 && i2 && i3 && i4:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
http.Pusher
|
||||
}{rw, rw, rw, rw, rw, rw, rw}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
type rw struct {
|
||||
w http.ResponseWriter
|
||||
h Hooks
|
||||
}
|
||||
|
||||
func (w *rw) Unwrap() http.ResponseWriter {
|
||||
return w.w
|
||||
}
|
||||
|
||||
func (w *rw) Header() http.Header {
|
||||
f := w.w.(http.ResponseWriter).Header
|
||||
if w.h.Header != nil {
|
||||
f = w.h.Header(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) WriteHeader(code int) {
|
||||
f := w.w.(http.ResponseWriter).WriteHeader
|
||||
if w.h.WriteHeader != nil {
|
||||
f = w.h.WriteHeader(f)
|
||||
}
|
||||
f(code)
|
||||
}
|
||||
|
||||
func (w *rw) Write(b []byte) (int, error) {
|
||||
f := w.w.(http.ResponseWriter).Write
|
||||
if w.h.Write != nil {
|
||||
f = w.h.Write(f)
|
||||
}
|
||||
return f(b)
|
||||
}
|
||||
|
||||
func (w *rw) Flush() {
|
||||
f := w.w.(http.Flusher).Flush
|
||||
if w.h.Flush != nil {
|
||||
f = w.h.Flush(f)
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
func (w *rw) CloseNotify() <-chan bool {
|
||||
f := w.w.(http.CloseNotifier).CloseNotify
|
||||
if w.h.CloseNotify != nil {
|
||||
f = w.h.CloseNotify(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
f := w.w.(http.Hijacker).Hijack
|
||||
if w.h.Hijack != nil {
|
||||
f = w.h.Hijack(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) ReadFrom(src io.Reader) (int64, error) {
|
||||
f := w.w.(io.ReaderFrom).ReadFrom
|
||||
if w.h.ReadFrom != nil {
|
||||
f = w.h.ReadFrom(f)
|
||||
}
|
||||
return f(src)
|
||||
}
|
||||
|
||||
func (w *rw) Push(target string, opts *http.PushOptions) error {
|
||||
f := w.w.(http.Pusher).Push
|
||||
if w.h.Push != nil {
|
||||
f = w.h.Push(f)
|
||||
}
|
||||
return f(target, opts)
|
||||
}
|
||||
|
||||
type Unwrapper interface {
|
||||
Unwrap() http.ResponseWriter
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying http.ResponseWriter from within zero or more
|
||||
// layers of httpsnoop wrappers.
|
||||
func Unwrap(w http.ResponseWriter) http.ResponseWriter {
|
||||
if rw, ok := w.(Unwrapper); ok {
|
||||
// recurse until rw.Unwrap() returns a non-Unwrapper
|
||||
return Unwrap(rw.Unwrap())
|
||||
} else {
|
||||
return w
|
||||
}
|
||||
}
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
// +build !go1.8
|
||||
// Code generated by "httpsnoop/codegen"; DO NOT EDIT.
|
||||
|
||||
package httpsnoop
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HeaderFunc is part of the http.ResponseWriter interface.
|
||||
type HeaderFunc func() http.Header
|
||||
|
||||
// WriteHeaderFunc is part of the http.ResponseWriter interface.
|
||||
type WriteHeaderFunc func(code int)
|
||||
|
||||
// WriteFunc is part of the http.ResponseWriter interface.
|
||||
type WriteFunc func(b []byte) (int, error)
|
||||
|
||||
// FlushFunc is part of the http.Flusher interface.
|
||||
type FlushFunc func()
|
||||
|
||||
// CloseNotifyFunc is part of the http.CloseNotifier interface.
|
||||
type CloseNotifyFunc func() <-chan bool
|
||||
|
||||
// HijackFunc is part of the http.Hijacker interface.
|
||||
type HijackFunc func() (net.Conn, *bufio.ReadWriter, error)
|
||||
|
||||
// ReadFromFunc is part of the io.ReaderFrom interface.
|
||||
type ReadFromFunc func(src io.Reader) (int64, error)
|
||||
|
||||
// Hooks defines a set of method interceptors for methods included in
|
||||
// http.ResponseWriter as well as some others. You can think of them as
|
||||
// middleware for the function calls they target. See Wrap for more details.
|
||||
type Hooks struct {
|
||||
Header func(HeaderFunc) HeaderFunc
|
||||
WriteHeader func(WriteHeaderFunc) WriteHeaderFunc
|
||||
Write func(WriteFunc) WriteFunc
|
||||
Flush func(FlushFunc) FlushFunc
|
||||
CloseNotify func(CloseNotifyFunc) CloseNotifyFunc
|
||||
Hijack func(HijackFunc) HijackFunc
|
||||
ReadFrom func(ReadFromFunc) ReadFromFunc
|
||||
}
|
||||
|
||||
// Wrap returns a wrapped version of w that provides the exact same interface
|
||||
// as w. Specifically if w implements any combination of:
|
||||
//
|
||||
// - http.Flusher
|
||||
// - http.CloseNotifier
|
||||
// - http.Hijacker
|
||||
// - io.ReaderFrom
|
||||
//
|
||||
// The wrapped version will implement the exact same combination. If no hooks
|
||||
// are set, the wrapped version also behaves exactly as w. Hooks targeting
|
||||
// methods not supported by w are ignored. Any other hooks will intercept the
|
||||
// method they target and may modify the call's arguments and/or return values.
|
||||
// The CaptureMetrics implementation serves as a working example for how the
|
||||
// hooks can be used.
|
||||
func Wrap(w http.ResponseWriter, hooks Hooks) http.ResponseWriter {
|
||||
rw := &rw{w: w, h: hooks}
|
||||
_, i0 := w.(http.Flusher)
|
||||
_, i1 := w.(http.CloseNotifier)
|
||||
_, i2 := w.(http.Hijacker)
|
||||
_, i3 := w.(io.ReaderFrom)
|
||||
switch {
|
||||
// combination 1/16
|
||||
case !i0 && !i1 && !i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
}{rw, rw}
|
||||
// combination 2/16
|
||||
case !i0 && !i1 && !i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw}
|
||||
// combination 3/16
|
||||
case !i0 && !i1 && i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
}{rw, rw, rw}
|
||||
// combination 4/16
|
||||
case !i0 && !i1 && i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 5/16
|
||||
case !i0 && i1 && !i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
}{rw, rw, rw}
|
||||
// combination 6/16
|
||||
case !i0 && i1 && !i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 7/16
|
||||
case !i0 && i1 && i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 8/16
|
||||
case !i0 && i1 && i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 9/16
|
||||
case i0 && !i1 && !i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
}{rw, rw, rw}
|
||||
// combination 10/16
|
||||
case i0 && !i1 && !i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 11/16
|
||||
case i0 && !i1 && i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 12/16
|
||||
case i0 && !i1 && i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 13/16
|
||||
case i0 && i1 && !i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
}{rw, rw, rw, rw}
|
||||
// combination 14/16
|
||||
case i0 && i1 && !i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 15/16
|
||||
case i0 && i1 && i2 && !i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
}{rw, rw, rw, rw, rw}
|
||||
// combination 16/16
|
||||
case i0 && i1 && i2 && i3:
|
||||
return struct {
|
||||
Unwrapper
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.CloseNotifier
|
||||
http.Hijacker
|
||||
io.ReaderFrom
|
||||
}{rw, rw, rw, rw, rw, rw}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
type rw struct {
|
||||
w http.ResponseWriter
|
||||
h Hooks
|
||||
}
|
||||
|
||||
func (w *rw) Unwrap() http.ResponseWriter {
|
||||
return w.w
|
||||
}
|
||||
|
||||
func (w *rw) Header() http.Header {
|
||||
f := w.w.(http.ResponseWriter).Header
|
||||
if w.h.Header != nil {
|
||||
f = w.h.Header(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) WriteHeader(code int) {
|
||||
f := w.w.(http.ResponseWriter).WriteHeader
|
||||
if w.h.WriteHeader != nil {
|
||||
f = w.h.WriteHeader(f)
|
||||
}
|
||||
f(code)
|
||||
}
|
||||
|
||||
func (w *rw) Write(b []byte) (int, error) {
|
||||
f := w.w.(http.ResponseWriter).Write
|
||||
if w.h.Write != nil {
|
||||
f = w.h.Write(f)
|
||||
}
|
||||
return f(b)
|
||||
}
|
||||
|
||||
func (w *rw) Flush() {
|
||||
f := w.w.(http.Flusher).Flush
|
||||
if w.h.Flush != nil {
|
||||
f = w.h.Flush(f)
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
func (w *rw) CloseNotify() <-chan bool {
|
||||
f := w.w.(http.CloseNotifier).CloseNotify
|
||||
if w.h.CloseNotify != nil {
|
||||
f = w.h.CloseNotify(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
f := w.w.(http.Hijacker).Hijack
|
||||
if w.h.Hijack != nil {
|
||||
f = w.h.Hijack(f)
|
||||
}
|
||||
return f()
|
||||
}
|
||||
|
||||
func (w *rw) ReadFrom(src io.Reader) (int64, error) {
|
||||
f := w.w.(io.ReaderFrom).ReadFrom
|
||||
if w.h.ReadFrom != nil {
|
||||
f = w.h.ReadFrom(f)
|
||||
}
|
||||
return f(src)
|
||||
}
|
||||
|
||||
type Unwrapper interface {
|
||||
Unwrap() http.ResponseWriter
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying http.ResponseWriter from within zero or more
|
||||
// layers of httpsnoop wrappers.
|
||||
func Unwrap(w http.ResponseWriter) http.ResponseWriter {
|
||||
if rw, ok := w.(Unwrapper); ok {
|
||||
// recurse until rw.Unwrap() returns a non-Unwrapper
|
||||
return Unwrap(rw.Unwrap())
|
||||
} else {
|
||||
return w
|
||||
}
|
||||
}
|
||||
-1
@@ -5,4 +5,3 @@ profile.out
|
||||
.tmp/
|
||||
.git-dist/
|
||||
.vscode
|
||||
build/tools/
|
||||
-42
@@ -110,48 +110,6 @@ func (r ReferenceName) IsTag() bool {
|
||||
return strings.HasPrefix(string(r), refTagPrefix)
|
||||
}
|
||||
|
||||
// IsSafe reports whether the reference name can be safely turned into a path
|
||||
// under the .git directory, mirroring Git's refname_is_safe (refs.c). A name
|
||||
// is safe when it is either:
|
||||
//
|
||||
// - under "refs/", non-empty after the prefix, containing no backslash and
|
||||
// no empty, "." or ".." path component (so it cannot escape the refs/
|
||||
// sub-tree, or alias another name, once turned into a path); or
|
||||
// - a one-level pseudo-ref whose spelling is restricted to [A-Z_]
|
||||
// (e.g. HEAD, ORIG_HEAD, FETCH_HEAD).
|
||||
//
|
||||
// Everything else — a lowercase or mixed one-level name such as "config" or
|
||||
// "index", an absolute or drive-prefixed name, or a refs/ name that escapes —
|
||||
// is unsafe, because it could resolve onto unrelated repository metadata.
|
||||
func (r ReferenceName) IsSafe() bool {
|
||||
s := string(r)
|
||||
if s == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if rest, ok := strings.CutPrefix(s, refPrefix); ok {
|
||||
// '\' is a path separator on Windows, so a refs/ name containing one
|
||||
// could escape the sub-tree or alias another name once turned into a
|
||||
// path; reject it outright (check_refname_format forbids '\' too).
|
||||
if rest == "" || strings.Contains(rest, "\\") {
|
||||
return false
|
||||
}
|
||||
for part := range strings.SplitSeq(rest, "/") {
|
||||
if part == "" || part == "." || part == ".." {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
for i := 0; i < len(s); i++ {
|
||||
if (s[i] < 'A' || s[i] > 'Z') && s[i] != '_' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r ReferenceName) String() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
-57
@@ -16,7 +16,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/internal/pathutil"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/hash"
|
||||
"github.com/go-git/go-git/v5/storage"
|
||||
@@ -80,52 +79,8 @@ var (
|
||||
// resolve outside the modules/ subtree, mirroring canonical Git's
|
||||
// "ignoring suspicious submodule name" defence.
|
||||
ErrModuleNameEscape = errors.New("submodule name escapes modules/ directory")
|
||||
// ErrReferenceNameEscape is returned when a reference name would
|
||||
// resolve outside its reference sub-tree once turned into a path
|
||||
// under the .git directory (e.g. a name with a ".." component).
|
||||
ErrReferenceNameEscape = errors.New("reference name escapes the reference storage")
|
||||
)
|
||||
|
||||
// isPathSep reports whether r is a path separator in reference names.
|
||||
// It treats both '/' and '\\' as separators to harden against cross-OS paths.
|
||||
func isPathSep(r rune) bool { return r == '/' || r == '\\' }
|
||||
|
||||
// validReferenceName rejects reference names that cannot be safely turned into
|
||||
// a path under the .git directory. A loose reference is stored verbatim at
|
||||
// ".git/<name>", so a crafted name — for instance one advertised by a malicious
|
||||
// remote — could climb out of its reference sub-tree and read, overwrite, or
|
||||
// delete unrelated metadata such as .git/config.
|
||||
//
|
||||
// The storage-safety gate is plumbing.ReferenceName.IsSafe, mirroring Git's
|
||||
// refname_is_safe: a name must be under refs/ without escaping it, or be a
|
||||
// [A-Z_] pseudo-ref. This alone rejects absolute, drive-prefixed, escaping and
|
||||
// single-level metadata names. On top of it, this adds filesystem-specific
|
||||
// hardening that IsSafe's literal check does not cover: control characters, and
|
||||
// components a case-insensitive/NTFS/HFS+ filesystem would fold back to "." or
|
||||
// ".." (trailing dots/spaces, Alternate Data Streams, ignorable Unicode code
|
||||
// points), delegated to pathutil.IsHFSDot and pathutil.IsNTFSDot with "." as
|
||||
// the needle — as validSubmoduleName does — and run regardless of host OS.
|
||||
func validReferenceName(name plumbing.ReferenceName) error {
|
||||
if !name.IsSafe() {
|
||||
return fmt.Errorf("%w: %q is not under refs/ nor a valid pseudo-ref", ErrReferenceNameEscape, string(name))
|
||||
}
|
||||
|
||||
s := string(name)
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] < 0x20 || s[i] == 0x7f {
|
||||
return fmt.Errorf("%w: %q", ErrReferenceNameEscape, s)
|
||||
}
|
||||
}
|
||||
for _, part := range strings.FieldsFunc(s, isPathSep) {
|
||||
// IsNTFSDot/IsHFSDot with a "." needle match ".." and its disguises
|
||||
// but not a bare ".", so reject that component explicitly too.
|
||||
if part == "." || pathutil.IsHFSDot(part, ".") || pathutil.IsNTFSDot(part, ".", "") {
|
||||
return fmt.Errorf("%w: %q", ErrReferenceNameEscape, s)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Options holds configuration for the storage.
|
||||
type Options struct {
|
||||
// ExclusiveAccess means that the filesystem is not modified externally
|
||||
@@ -751,10 +706,6 @@ func (d *DotGit) checkReferenceAndTruncate(f billy.File, old *plumbing.Reference
|
||||
}
|
||||
|
||||
func (d *DotGit) SetRef(r, old *plumbing.Reference) error {
|
||||
if err := validReferenceName(r.Name()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var content string
|
||||
switch r.Type() {
|
||||
case plumbing.SymbolicReference:
|
||||
@@ -790,10 +741,6 @@ func (d *DotGit) Refs() ([]*plumbing.Reference, error) {
|
||||
|
||||
// Ref returns the reference for a given reference name.
|
||||
func (d *DotGit) Ref(name plumbing.ReferenceName) (*plumbing.Reference, error) {
|
||||
if err := validReferenceName(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ref, err := d.readReferenceFile(".", name.String())
|
||||
if err == nil {
|
||||
return ref, nil
|
||||
@@ -857,10 +804,6 @@ func (d *DotGit) packedRef(name plumbing.ReferenceName) (*plumbing.Reference, er
|
||||
|
||||
// RemoveRef removes a reference by name.
|
||||
func (d *DotGit) RemoveRef(name plumbing.ReferenceName) error {
|
||||
if err := validReferenceName(name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path := d.fs.Join(".", name.String())
|
||||
_, err := d.fs.Stat(path)
|
||||
if err == nil {
|
||||
|
||||
-67
@@ -583,10 +583,6 @@ func (w *Worktree) checkoutChangeSubmodule(name string,
|
||||
return err
|
||||
}
|
||||
|
||||
if err := w.clearBlockingSymlinks(name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := w.Filesystem.MkdirAll(name, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -630,70 +626,7 @@ func (w *Worktree) checkoutChangeRegularFile(name string,
|
||||
return nil
|
||||
}
|
||||
|
||||
// clearBlockingSymlinks removes a symlink that is in the way of
|
||||
// materialising name, so the checkout writes a real entry in its place
|
||||
// instead of following the link out of the worktree. Two cases:
|
||||
//
|
||||
// - a leading directory component that is a symlink (e.g. "s" while
|
||||
// writing "s/config", where "s" links to ".git"): OpenFile/MkdirAll
|
||||
// would traverse it, so the write would land under the link's target.
|
||||
// - the final component itself being a symlink (e.g. writing "s" while
|
||||
// "s" links to ".git/config"): OpenFile with O_TRUNC, or Symlink,
|
||||
// would follow/replace through it and clobber the target.
|
||||
//
|
||||
// A symlink can never be a legitimate parent of, or the destination for,
|
||||
// a tracked entry, so removing it is always correct. This mirrors upstream
|
||||
// Git's forced checkout, which unlinks a blocking symlink in the leading
|
||||
// path (create_directories) and unlinks an existing entry before
|
||||
// write_entry.
|
||||
// https://github.com/git/git/blob/v2.54.0/entry.c#L50
|
||||
func (w *Worktree) clearBlockingSymlinks(name string) error {
|
||||
var dirs []string
|
||||
for dir := filepath.Dir(name); dir != "." && dir != "" && dir != string(filepath.Separator); dir = filepath.Dir(dir) {
|
||||
dirs = append(dirs, dir)
|
||||
}
|
||||
// Leading components, shallowest-first: removing the shallowest symlink
|
||||
// invalidates every component beneath it, so a single removal is enough.
|
||||
for i := len(dirs) - 1; i >= 0; i-- {
|
||||
fi, err := w.Filesystem.Lstat(dirs[i])
|
||||
if err != nil {
|
||||
// A missing component is created as a real directory by the
|
||||
// checkout. Any other error means we cannot tell whether it is
|
||||
// a symlink, so surface it instead of leaving a blocking link in
|
||||
// place and failing later in a harder-to-diagnose way.
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
if fi.Mode()&os.ModeSymlink != 0 {
|
||||
return w.Filesystem.Remove(dirs[i])
|
||||
}
|
||||
}
|
||||
// Final component: an existing symlink here would be followed by the
|
||||
// subsequent OpenFile/Symlink/MkdirAll, so replace it.
|
||||
fi, err := w.Filesystem.Lstat(name)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if fi.Mode()&os.ModeSymlink != 0 {
|
||||
return w.Filesystem.Remove(name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Worktree) checkoutFile(f *object.File) (err error) {
|
||||
// checkoutFile is the materialisation boundary for tracked entries.
|
||||
// Remove any blocking symlink first so the subsequent OpenFile or
|
||||
// Symlink call writes the entry itself instead of following a planted
|
||||
// final-component link in the underlying filesystem.
|
||||
if err := w.clearBlockingSymlinks(f.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode, err := f.Mode.ToOSFileMode()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
+15
-100
@@ -35,25 +35,10 @@ func defaultProtectNTFS() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// worktreeFilesystem wraps a billy.Filesystem and validates every path it
|
||||
// is handed, so worktree operations cannot use dangerous paths at the
|
||||
// boundary. Two layers apply:
|
||||
//
|
||||
// - validPath rejects dangerous path *strings*: .git and its HFS+/NTFS
|
||||
// variants, "..", control characters, volume names.
|
||||
// - validNoLeadingSymlink rejects paths whose leading directories
|
||||
// already exist on disk as symlinks, so a write or delete cannot
|
||||
// follow a planted link out of the tree.
|
||||
//
|
||||
// Both layers run on every mutating operation (validWritePath) and every
|
||||
// read (validReadPath). Chroot additionally refuses a symlink as the final
|
||||
// component, so a sub-filesystem such as a submodule worktree cannot be
|
||||
// scoped to a redirected target.
|
||||
//
|
||||
// The wrapper intentionally stops at leading-component traversal. Callers
|
||||
// that need final-component no-follow semantics for materialisation
|
||||
// (checkoutFile) enforce that directly by removing the blocking symlink
|
||||
// before opening the destination path.
|
||||
// worktreeFilesystem wraps a billy.Filesystem and validates every path passed
|
||||
// to a mutating operation. This prevents writing to, or deleting from,
|
||||
// dangerous locations (e.g. .git/*, ../) regardless of which worktree
|
||||
// code path triggers the operation.
|
||||
type worktreeFilesystem struct {
|
||||
billy.Filesystem
|
||||
protectNTFS bool
|
||||
@@ -65,7 +50,7 @@ func newWorktreeFilesystem(fs billy.Filesystem, protectNTFS, protectHFS bool) *w
|
||||
}
|
||||
|
||||
func (sfs *worktreeFilesystem) Create(filename string) (billy.File, error) {
|
||||
if err := sfs.validWritePath(filename); err != nil {
|
||||
if err := sfs.validPath(filename); err != nil {
|
||||
return nil, fmt.Errorf("create: %w", err)
|
||||
}
|
||||
return sfs.Filesystem.Create(filename)
|
||||
@@ -79,7 +64,7 @@ func (sfs *worktreeFilesystem) Open(filename string) (billy.File, error) {
|
||||
}
|
||||
|
||||
func (sfs *worktreeFilesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) {
|
||||
if err := sfs.validWritePath(filename); err != nil {
|
||||
if err := sfs.validPath(filename); err != nil {
|
||||
return nil, fmt.Errorf("openfile: %w", err)
|
||||
}
|
||||
return sfs.Filesystem.OpenFile(filename, flag, perm)
|
||||
@@ -93,14 +78,14 @@ func (sfs *worktreeFilesystem) Stat(filename string) (os.FileInfo, error) {
|
||||
}
|
||||
|
||||
func (sfs *worktreeFilesystem) Remove(filename string) error {
|
||||
if err := sfs.validWritePath(filename); err != nil {
|
||||
if err := sfs.validPath(filename); err != nil {
|
||||
return fmt.Errorf("remove: %w", err)
|
||||
}
|
||||
return sfs.Filesystem.Remove(filename)
|
||||
}
|
||||
|
||||
func (sfs *worktreeFilesystem) Rename(from, to string) error {
|
||||
if err := sfs.validWritePath(from, to); err != nil {
|
||||
if err := sfs.validPath(from, to); err != nil {
|
||||
return fmt.Errorf("rename: %w", err)
|
||||
}
|
||||
return sfs.Filesystem.Rename(from, to)
|
||||
@@ -121,7 +106,7 @@ func (sfs *worktreeFilesystem) Lstat(filename string) (os.FileInfo, error) {
|
||||
}
|
||||
|
||||
func (sfs *worktreeFilesystem) Symlink(target, link string) error {
|
||||
if err := sfs.validWritePath(link); err != nil {
|
||||
if err := sfs.validPath(link); err != nil {
|
||||
return fmt.Errorf("symlink: %w", err)
|
||||
}
|
||||
if err := sfs.validSymlinkName(link); err != nil {
|
||||
@@ -146,7 +131,7 @@ func (sfs *worktreeFilesystem) MkdirAll(path string, perm os.FileMode) error {
|
||||
if path == "" || path == "." || path == "/" {
|
||||
return nil
|
||||
}
|
||||
if err := sfs.validWritePath(path); err != nil {
|
||||
if err := sfs.validPath(path); err != nil {
|
||||
return fmt.Errorf("mkdirall: %w", err)
|
||||
}
|
||||
return sfs.Filesystem.MkdirAll(path, perm)
|
||||
@@ -160,39 +145,18 @@ func (sfs *worktreeFilesystem) Chroot(path string) (billy.Filesystem, error) {
|
||||
if err := sfs.validReadPath(path); err != nil {
|
||||
return nil, fmt.Errorf("chroot: %w", err)
|
||||
}
|
||||
// Chroot scopes a sub-filesystem to path, so the final component must
|
||||
// be a real directory too: a symlink there would silently redirect the
|
||||
// scope (e.g. a submodule worktree) to a target outside the tree. This
|
||||
// is the "valid path, wrong target" case that validNoLeadingSymlink,
|
||||
// which only inspects leading components, does not cover.
|
||||
//
|
||||
// A non-existent target is fine: Chroot creates it as a real
|
||||
// directory. Any other Lstat error means we cannot prove the target
|
||||
// is not a symlink, so fail closed rather than scope through it.
|
||||
if fi, err := sfs.Filesystem.Lstat(path); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("chroot: cannot stat %q: %w", path, err)
|
||||
}
|
||||
} else if fi.Mode()&os.ModeSymlink != 0 {
|
||||
return nil, fmt.Errorf("chroot: invalid path %q: is a symlink", path)
|
||||
}
|
||||
return sfs.Filesystem.Chroot(path)
|
||||
}
|
||||
|
||||
// validReadPath is like validWritePath but treats the empty string and "."
|
||||
// as valid references to the worktree root. Read-side operations on the
|
||||
// root (e.g. ReadDir(""), Lstat(".")) are legitimate. Mutating the root
|
||||
// itself is not, so write-side operations reject it via validPath. Reads
|
||||
// are still refused through a leading symlink, so the wrapper never
|
||||
// follows a planted link even on the read surface.
|
||||
// validReadPath is like validPath but treats the empty string and "." as
|
||||
// valid references to the worktree root. Read-side operations on the root
|
||||
// (e.g. ReadDir(""), Lstat(".")) are legitimate; mutating the root itself
|
||||
// is not, so write-side operations continue to use validPath directly.
|
||||
func (sfs *worktreeFilesystem) validReadPath(p string) error {
|
||||
if p == "" || p == "." || p == "/" {
|
||||
return nil
|
||||
}
|
||||
if err := sfs.validPath(p); err != nil {
|
||||
return err
|
||||
}
|
||||
return sfs.validNoLeadingSymlink(p)
|
||||
return sfs.validPath(p)
|
||||
}
|
||||
|
||||
var errUnsupportedOperation = errors.New("unsupported operation")
|
||||
@@ -268,55 +232,6 @@ func (sfs *worktreeFilesystem) validPath(paths ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// validWritePath validates paths for mutating operations. It layers the
|
||||
// filesystem-state check validNoLeadingSymlink on top of the string-only
|
||||
// checks in validPath, so a write can neither name a dangerous path nor
|
||||
// reach one by traversing an existing symlink. Every mutating method on
|
||||
// the wrapper funnels through here, so the leading-symlink invariant holds
|
||||
// for all worktree writers without each call site having to remember it.
|
||||
func (sfs *worktreeFilesystem) validWritePath(paths ...string) error {
|
||||
if err := sfs.validPath(paths...); err != nil {
|
||||
return err
|
||||
}
|
||||
return sfs.validNoLeadingSymlink(paths...)
|
||||
}
|
||||
|
||||
// validNoLeadingSymlink rejects paths whose leading directory components
|
||||
// resolve through a symlink that already exists on the underlying
|
||||
// filesystem. validPath guards the path string. This guards the on-disk
|
||||
// state, so a write or delete cannot reach outside the worktree by
|
||||
// traversing a symlink that a tree or an earlier step left in place.
|
||||
//
|
||||
// This is the fail-closed backstop for the whole class. Callers that want
|
||||
// upstream's replace-and-continue behaviour (checkout) remove the blocking
|
||||
// symlink first via clearBlockingSymlinks, so no symlink remains when the
|
||||
// write reaches the wrapper. Callers that do not get a safe error,
|
||||
// matching upstream Git refusing rather than following the link. See
|
||||
// has_symlink_leading_path (symlinks.c) and the check_leading_path guard
|
||||
// in unlink_entry (entry.c).
|
||||
func (sfs *worktreeFilesystem) validNoLeadingSymlink(paths ...string) error {
|
||||
for _, p := range paths {
|
||||
for dir := filepath.Dir(p); dir != "." && dir != "" && dir != string(filepath.Separator); dir = filepath.Dir(dir) {
|
||||
fi, err := sfs.Filesystem.Lstat(dir)
|
||||
if err != nil {
|
||||
// A missing ancestor is materialised as a real directory,
|
||||
// so it cannot be a symlink and is safe to skip. Any other
|
||||
// error (permission, I/O) means we cannot prove the
|
||||
// component is not a symlink, so fail closed rather than
|
||||
// let the operation traverse an unverified component.
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("invalid path %q: cannot stat leading component %q: %w", p, dir, err)
|
||||
}
|
||||
if fi.Mode()&os.ModeSymlink != 0 {
|
||||
return fmt.Errorf("invalid path %q: leading component %q is a symlink", p, dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validSymlinkName checks the per-component name of a symlink for
|
||||
// dotfile names that attackers can use to trick a checkout into
|
||||
// writing a dangerous symlink. Each path component is compared
|
||||
|
||||
+1
-1
@@ -371,7 +371,7 @@ func (w *Worktree) doAdd(path string, ignorePattern []gitignore.Pattern, skipSta
|
||||
}
|
||||
}
|
||||
|
||||
path = filepath.ToSlash(filepath.Clean(path))
|
||||
path = filepath.Clean(path)
|
||||
|
||||
if err != nil || !fi.IsDir() {
|
||||
added, h, err = w.doAddFile(idx, s, path, ignorePattern)
|
||||
|
||||
+57
-5
@@ -253,7 +253,7 @@ func (d *driver) CreateDir(ctx context.Context, ref *provider.Reference) (*stora
|
||||
}
|
||||
|
||||
func (d *driver) Delete(ctx context.Context, ref *provider.Reference) (*storage.DeleteResult, error) {
|
||||
client, _, rel, err := d.webdavClient(ctx, nil, ref)
|
||||
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -264,14 +264,24 @@ func (d *driver) Delete(ctx context.Context, ref *provider.Reference) (*storage.
|
||||
}
|
||||
|
||||
func (d *driver) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) (*storage.TouchFileResult, error) {
|
||||
client, _, rel, err := d.webdavClient(ctx, nil, ref)
|
||||
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := client.Write(rel, []byte{}, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &storage.TouchFileResult{}, nil
|
||||
// callers address the touched file by the ids returned here, so encode them the
|
||||
// same way a stat does (convertStatToResourceInfo)
|
||||
shareID, _ := shareInfoFromReference(ref)
|
||||
return &storage.TouchFileResult{
|
||||
SpaceID: shareID.GetOpaqueId(),
|
||||
ResourceID: &provider.ResourceId{
|
||||
StorageId: utils.OCMStorageProviderID,
|
||||
SpaceId: shareID.GetOpaqueId(),
|
||||
OpaqueId: base64.StdEncoding.EncodeToString([]byte(filepath.Join("/", rel))),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *driver) Move(ctx context.Context, oldRef, newRef *provider.Reference) (*storage.MoveResult, error) {
|
||||
@@ -347,6 +357,36 @@ func convertStatToResourceInfo(ref *provider.Reference, f fs.FileInfo, share *oc
|
||||
return &ri, nil
|
||||
}
|
||||
|
||||
// extractLock returns the active lock, or nil if there is none. Props.GetString
|
||||
// renders a missing key as "<nil>", so require a parseable activelock with a token.
|
||||
func extractLock(props gowebdav.Props) *provider.Lock {
|
||||
raw := props.GetString(xml.Name{Space: "DAV:", Local: "lockdiscovery"})
|
||||
|
||||
// local names only: raw is innerxml, so the d: prefix is unbound and
|
||||
// namespaced tags ("DAV: lockscope") would match nothing.
|
||||
var al struct {
|
||||
LockScope struct {
|
||||
Exclusive *struct{} `xml:"exclusive"`
|
||||
Shared *struct{} `xml:"shared"`
|
||||
} `xml:"lockscope"`
|
||||
LockToken struct {
|
||||
Href string `xml:"href"`
|
||||
} `xml:"locktoken"`
|
||||
}
|
||||
if err := xml.Unmarshal([]byte(raw), &al); err != nil {
|
||||
return nil
|
||||
}
|
||||
if al.LockToken.Href == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
lockType := provider.LockType_LOCK_TYPE_EXCL
|
||||
if al.LockScope.Shared != nil && al.LockScope.Exclusive == nil {
|
||||
lockType = provider.LockType_LOCK_TYPE_SHARED
|
||||
}
|
||||
return &provider.Lock{LockId: al.LockToken.Href, Type: lockType}
|
||||
}
|
||||
|
||||
func extractChecksum(props gowebdav.Props) *provider.ResourceChecksum {
|
||||
checksums := props.GetString(xml.Name{Space: "http://owncloud.org/ns", Local: "checksums"})
|
||||
if checksums == "" {
|
||||
@@ -534,12 +574,24 @@ func (d *driver) GetLock(ctx context.Context, ref *provider.Reference) (*provide
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token, err := client.GetLock(rel)
|
||||
// gowebdav's GetLock stats with a fixed property set that omits lockdiscovery.
|
||||
// getetag keeps the 200 propstat non-empty — unlocked resources report
|
||||
// lockdiscovery in a 404 propstat, which gowebdav discards.
|
||||
info, err := client.StatWithProps(rel, []string{"lockdiscovery", "getetag"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &provider.Lock{LockId: token, Type: provider.LockType_LOCK_TYPE_EXCL}, nil
|
||||
props, ok := info.Sys().(gowebdav.Props)
|
||||
if !ok {
|
||||
return nil, errtypes.InternalError("ocm: unexpected stat result for " + ref.GetPath())
|
||||
}
|
||||
|
||||
lock := extractLock(props)
|
||||
if lock == nil {
|
||||
return nil, errtypes.NotFound("no lock found")
|
||||
}
|
||||
return lock, nil
|
||||
}
|
||||
|
||||
func (d *driver) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
|
||||
|
||||
+44
-3
@@ -35,9 +35,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/studio-b12/gowebdav"
|
||||
tusd "github.com/tus/tusd/v2/pkg/handler"
|
||||
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
ocmpb "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/owncloud/reva/v2/pkg/appctx"
|
||||
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
@@ -76,12 +78,51 @@ func (d *driver) InitiateUpload(ctx context.Context, ref *provider.Reference, up
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MarkProcessing is a no-op: the file lives on the remote instance, so there is no
|
||||
// local node to flag while postprocessing runs.
|
||||
func (d *driver) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
|
||||
return errtypes.NotSupported("op not supported")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *driver) CommitUpload(_ context.Context, _ *provider.Reference, _ string, _ storage.UploadSource) error {
|
||||
return errtypes.NotSupported("op not supported")
|
||||
// CommitUpload streams the staged bytes to the remote instance.
|
||||
func (d *driver) CommitUpload(ctx context.Context, ref *provider.Reference, sessionID string, source storage.UploadSource) error {
|
||||
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client.SetInterceptor(func(method string, rq *http.Request) {
|
||||
// Set the content length on the request struct directly instead of the header.
|
||||
// The content-length header gets reset by the golang http library before
|
||||
// sending out the request, resulting in chunked encoding to be used which
|
||||
// breaks the quota checks in ocdav.
|
||||
if method == "PUT" {
|
||||
rq.ContentLength = source.Length
|
||||
}
|
||||
})
|
||||
|
||||
// the coordinator owns source.Body and closes it after this returns
|
||||
lockToken, _ := ctxpkg.ContextGetLockID(ctx)
|
||||
return client.WriteStream(rel, source.Body, 0, lockToken)
|
||||
}
|
||||
|
||||
// serviceWebdavClient builds a webdav client without needing a request auth token:
|
||||
// it authenticates as the service account and looks up the share on behalf of the
|
||||
// upload's executant.
|
||||
func (d *driver) serviceWebdavClient(ctx context.Context, ref *provider.Reference) (*gowebdav.Client, *ocmpb.ReceivedShare, string, error) {
|
||||
gwc, err := d.gateway.Next()
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
serviceUserCtx, err := utils.GetServiceUserContext(d.c.ServiceAccountID, gwc, d.c.ServiceAccountSecret)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
executant, ok := ctxpkg.ContextGetUser(ctx)
|
||||
if !ok {
|
||||
return nil, nil, "", errtypes.BadRequest("ocm: no executant in context")
|
||||
}
|
||||
return d.webdavClient(serviceUserCtx, executant.GetId(), ref)
|
||||
}
|
||||
|
||||
func (d *driver) Upload(ctx context.Context, req storage.UploadRequest, _ storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
|
||||
|
||||
+39
-12
@@ -413,6 +413,13 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
|
||||
return errors.Wrap(err, "Decomposedfs: failed to write blob")
|
||||
}
|
||||
|
||||
// on the node, not the session: the session is deleted when the upload finishes
|
||||
if !source.ScanDate.IsZero() {
|
||||
if err := n.SetScanData(ctx, source.ScanResult, source.ScanDate); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not set scan results")
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if p, err := n.Parent(ctx); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not read parent for etag propagation")
|
||||
@@ -491,24 +498,38 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
|
||||
}
|
||||
}
|
||||
if info.NodeExisted && oldAttrs != nil {
|
||||
// mtime goes in the same batch: we still hold the metadata lock and
|
||||
// SetMTime would deadlock trying to retake it
|
||||
if err := fs.lu.TimeManager().OverrideMtime(ctx, n, &oldAttrs, oldMtime); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node mtime during rollback")
|
||||
}
|
||||
if err := n.SetXattrsWithContext(ctx, oldAttrs, false); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node xattrs during rollback")
|
||||
}
|
||||
if err := fs.lu.TimeManager().SetMTime(ctx, n, &oldMtime); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node mtime during rollback")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
var (
|
||||
old *node.Node
|
||||
overwrite bool
|
||||
oldBlobsize int64
|
||||
)
|
||||
if info.NodeExisted {
|
||||
old, err := node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, false, nil, false)
|
||||
old, err = node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, false, nil, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "PrepareUpload: failed to read existing node")
|
||||
}
|
||||
if _, err := node.CheckQuota(ctx, n.SpaceRoot, old.BlobID != "", uint64(old.Blobsize), uint64(info.Size)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
overwrite = old.BlobID != ""
|
||||
oldBlobsize = old.Blobsize
|
||||
}
|
||||
|
||||
// also for new files: the coordinator's check fails open without GetQuota
|
||||
// permission, and CheckQuota guards disk space too
|
||||
if _, err := node.CheckQuota(ctx, n.SpaceRoot, overwrite, uint64(oldBlobsize), uint64(info.Size)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if info.NodeExisted {
|
||||
oldMtime, err = old.GetMTime(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -633,7 +654,7 @@ func (fs *Decomposedfs) RollbackUpload(ctx context.Context, ref *provider.Refere
|
||||
return fmt.Errorf("RollbackUpload: node lookup failed: %w", err)
|
||||
}
|
||||
if !n.Exists {
|
||||
return nil // new node; coordinator calls Delete separately
|
||||
return nil // nothing was written yet
|
||||
}
|
||||
n.SpaceRoot, err = node.ReadNode(ctx, fs.lu, n.SpaceID, n.SpaceID, false, nil, false)
|
||||
if err != nil {
|
||||
@@ -652,13 +673,19 @@ func (fs *Decomposedfs) RollbackUpload(ctx context.Context, ref *provider.Refere
|
||||
if err := n.RevertCurrentRevision(ctx, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if sizeDiff != 0 {
|
||||
if err := fs.tp.Propagate(ctx, n, -sizeDiff); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Msg("RollbackUpload: could not revert propagate")
|
||||
}
|
||||
} else {
|
||||
// the upload created this node, so undo it. Purge, not trash: the file never
|
||||
// became visible, and Purge needs no Delete permission
|
||||
if err := n.Purge(ctx); err != nil {
|
||||
return fmt.Errorf("RollbackUpload: could not purge node: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if sizeDiff != 0 {
|
||||
if err := fs.tp.Propagate(ctx, n, -sizeDiff); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Msg("RollbackUpload: could not revert propagate")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -8,4 +8,4 @@ Use [NewClientHandler] with [grpc.WithStatsHandler] to instrument a gRPC client.
|
||||
|
||||
Use [NewServerHandler] with [grpc.StatsHandler] to instrument a gRPC server.
|
||||
*/
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
Generated
Vendored
+2
-43
@@ -1,62 +1,21 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
// gRPC tracing middleware
|
||||
// https://opentelemetry.io/docs/specs/semconv/rpc/
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
grpc_codes "google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// serverAddrAttrsFromCanonicalTarget extracts server address attributes from a
|
||||
// canonical gRPC target as returned by [google.golang.org/grpc.ClientConn.CanonicalTarget].
|
||||
// Canonical targets always have the form "scheme://[authority]/endpoint", e.g.:
|
||||
//
|
||||
// passthrough:///127.0.0.1:7777 → ServerAddress("127.0.0.1"), ServerPort(7777)
|
||||
// dns:///example.com:443 → ServerAddress("example.com"), ServerPort(443)
|
||||
// dns://authority/example.com:443 → ServerAddress("example.com"), ServerPort(443)
|
||||
// unix:///tmp/grpc.sock → ServerAddress("/tmp/grpc.sock")
|
||||
func serverAddrAttrsFromCanonicalTarget(target string) []attribute.KeyValue {
|
||||
// Fast path: confirmed host:port with numeric port, no scheme involved.
|
||||
if h, pStr, err := net.SplitHostPort(target); err == nil {
|
||||
if p, err := strconv.Atoi(pStr); err == nil {
|
||||
return []attribute.KeyValue{
|
||||
semconv.ServerAddress(h),
|
||||
semconv.ServerPort(p),
|
||||
}
|
||||
}
|
||||
}
|
||||
// gRPC URI: scheme://authority/endpoint → endpoint in Path
|
||||
// scheme:endpoint → endpoint in Opaque
|
||||
u, err := url.Parse(target)
|
||||
if err != nil {
|
||||
return []attribute.KeyValue{semconv.ServerAddress(target)}
|
||||
}
|
||||
ep := u.Path
|
||||
if u.Scheme != "unix" && u.Scheme != "unix-abstract" {
|
||||
// Strip the leading "/" added by url.Parse for hierarchical URIs;
|
||||
// preserve it for unix socket paths where the slash is meaningful.
|
||||
ep = strings.TrimPrefix(ep, "/")
|
||||
}
|
||||
if ep == "" {
|
||||
ep = u.Opaque
|
||||
}
|
||||
if ep != "" {
|
||||
return serverAddrAttrs(ep)
|
||||
}
|
||||
return []attribute.KeyValue{semconv.ServerAddress(target)}
|
||||
}
|
||||
|
||||
// serverAddrAttrs returns the server address attributes for the hostport.
|
||||
func serverAddrAttrs(hostport string) []attribute.KeyValue {
|
||||
h, pStr, err := net.SplitHostPort(hostport)
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go
Generated
Vendored
+2
-2
@@ -2,14 +2,14 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package internal provides internal functionality for the otelgrpc package.
|
||||
package internal
|
||||
package internal // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal"
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
oldsemconv "go.opentelemetry.io/otel/semconv/v1.37.0" //nolint:depguard // Use of v1.37.0 is required for backward compatibility stability opt-in.
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
)
|
||||
|
||||
// ParseFullMethod returns a span name following the OpenTelemetry semantic
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
Generated
Vendored
+9
-33
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
oldrpcconv "go.opentelemetry.io/otel/semconv/v1.37.0/rpcconv" //nolint:depguard // Use of v1.37.0 is required for backward compatibility stability opt-in.
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.43.0/rpcconv"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0/rpcconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
grpc_codes "google.golang.org/grpc/codes"
|
||||
@@ -26,11 +26,6 @@ import (
|
||||
|
||||
type gRPCContextKey struct{}
|
||||
|
||||
// dialTargetContextKey carries the dial target seeded by client interceptors
|
||||
// so the stats handler can use the hostname for server.address instead of the
|
||||
// post-DNS IP from RemoteAddr.
|
||||
type dialTargetContextKey struct{}
|
||||
|
||||
type gRPCContext struct {
|
||||
metricAttrs []attribute.KeyValue
|
||||
record bool
|
||||
@@ -333,20 +328,6 @@ func (*config) handleRPC(
|
||||
|
||||
switch rs := rs.(type) {
|
||||
case *stats.Begin:
|
||||
// Set server.address early from the dial target when available (upcoming
|
||||
// interceptors will seed this). Covers both success and failure paths since Begin
|
||||
// fires on every RPC regardless of outcome.
|
||||
if rs.Client {
|
||||
if target, ok := ctx.Value(dialTargetContextKey{}).(string); ok && target != "" {
|
||||
attrs := serverAddrAttrsFromCanonicalTarget(target)
|
||||
if span.IsRecording() {
|
||||
span.SetAttributes(attrs...)
|
||||
}
|
||||
if gctx != nil {
|
||||
gctx.metricAttrs = append(gctx.metricAttrs, attrs...)
|
||||
}
|
||||
}
|
||||
}
|
||||
case *stats.InPayload:
|
||||
case *stats.InHeader:
|
||||
if !rs.Client && rs.LocalAddr != nil {
|
||||
@@ -358,18 +339,13 @@ func (*config) handleRPC(
|
||||
case *stats.OutPayload:
|
||||
case *stats.OutTrailer:
|
||||
case *stats.OutHeader:
|
||||
// Only use the resolved IP from RemoteAddr when no dial target was seeded
|
||||
// (i.e. NewClientHandler callers without interceptors). When dialTargetContextKey
|
||||
// is present, Begin already set server.address to the hostname.
|
||||
if rs.Client && rs.RemoteAddr != nil && (span.IsRecording() || gctx != nil) {
|
||||
if target, ok := ctx.Value(dialTargetContextKey{}).(string); !ok || target == "" {
|
||||
attrs := serverAddrAttrs(rs.RemoteAddr.String())
|
||||
if span.IsRecording() {
|
||||
span.SetAttributes(attrs...)
|
||||
}
|
||||
if gctx != nil {
|
||||
gctx.metricAttrs = append(gctx.metricAttrs, attrs...)
|
||||
}
|
||||
attrs := serverAddrAttrs(rs.RemoteAddr.String())
|
||||
if span.IsRecording() {
|
||||
span.SetAttributes(attrs...)
|
||||
}
|
||||
if gctx != nil {
|
||||
gctx.metricAttrs = append(gctx.metricAttrs, attrs...)
|
||||
}
|
||||
}
|
||||
case *stats.End:
|
||||
|
||||
Generated
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelgrpc
|
||||
package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
|
||||
// Version is the current release version of the gRPC instrumentation.
|
||||
const Version = "0.70.0"
|
||||
const Version = "0.69.0"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@
|
||||
|
||||
// Package otelhttp provides an http.Handler and functions that are intended
|
||||
// to be used to add tracing by wrapping existing handlers.
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -1,12 +1,12 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/request/body_wrapper.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/request/body_wrapper.go.tmpl
|
||||
|
||||
// Package request provides types and functionality to handle HTTP request
|
||||
// handling.
|
||||
package request
|
||||
package request // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package request
|
||||
package request // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
|
||||
// Generate request package:
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/request/body_wrapper.go.tmpl "--data={}" --out=body_wrapper.go
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -1,10 +1,10 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/request/resp_writer_wrapper.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/request/resp_writer_wrapper.go.tmpl
|
||||
|
||||
package request
|
||||
package request // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
Generated
Vendored
+20
-50
@@ -1,12 +1,12 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/client.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/semconv/client.go.tmpl
|
||||
|
||||
// Package semconv provides OpenTelemetry semantic convention types and
|
||||
// functionality.
|
||||
package semconv
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.43.0/httpconv"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0/httpconv"
|
||||
)
|
||||
|
||||
type HTTPClient struct {
|
||||
@@ -45,7 +45,7 @@ func NewHTTPClient(meter metric.Meter) HTTPClient {
|
||||
return client
|
||||
}
|
||||
|
||||
func (HTTPClient) Status(code int) (codes.Code, string) {
|
||||
func (n HTTPClient) Status(code int) (codes.Code, string) {
|
||||
if code < 100 || code >= 600 {
|
||||
return codes.Error, fmt.Sprintf("Invalid HTTP status code %d", code)
|
||||
}
|
||||
@@ -120,7 +120,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue {
|
||||
// Restore any username/password info that was removed.
|
||||
req.URL.User = userinfo
|
||||
}
|
||||
attrs = append(attrs, semconv.URLFull(u), semconv.ServerAddress(requestHost))
|
||||
attrs = append(attrs, semconv.URLFull(u))
|
||||
|
||||
attrs = append(attrs, semconv.ServerAddress(requestHost))
|
||||
if eligiblePort > 0 {
|
||||
attrs = append(attrs, semconv.ServerPort(eligiblePort))
|
||||
}
|
||||
@@ -136,13 +138,11 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue {
|
||||
}
|
||||
|
||||
// ResponseTraceAttrs returns trace attributes for an HTTP response made by a client.
|
||||
func (HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue {
|
||||
func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue {
|
||||
/*
|
||||
below attributes are returned:
|
||||
- http.response.status_code
|
||||
- error.type
|
||||
- network.protocol.name (only when it is not "http")
|
||||
- network.protocol.version
|
||||
*/
|
||||
var count int
|
||||
if resp.StatusCode > 0 {
|
||||
@@ -153,21 +153,6 @@ func (HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue {
|
||||
count++
|
||||
}
|
||||
|
||||
// The protocol version is only known for certain once the response
|
||||
// arrives: req.Proto reflects what the caller asked for, but the
|
||||
// transport may negotiate a different version (for example HTTP/2 via
|
||||
// ALPN). Report resp.Proto here so it overrides the request-time value
|
||||
// on the span. As in RequestTraceAttrs, network.protocol.name is omitted
|
||||
// when it is "http": the spec only requires it when the name differs from
|
||||
// the protocol implied by http.request.method.
|
||||
protoName, protoVersion := netProtocol(resp.Proto)
|
||||
if protoName != "" && protoName != "http" {
|
||||
count++
|
||||
}
|
||||
if protoVersion != "" {
|
||||
count++
|
||||
}
|
||||
|
||||
attrs := make([]attribute.KeyValue, 0, count)
|
||||
if resp.StatusCode > 0 {
|
||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(resp.StatusCode))
|
||||
@@ -177,17 +162,10 @@ func (HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue {
|
||||
errorType := strconv.Itoa(resp.StatusCode)
|
||||
attrs = append(attrs, semconv.ErrorTypeKey.String(errorType))
|
||||
}
|
||||
|
||||
if protoName != "" && protoName != "http" {
|
||||
attrs = append(attrs, semconv.NetworkProtocolName(protoName))
|
||||
}
|
||||
if protoVersion != "" {
|
||||
attrs = append(attrs, semconv.NetworkProtocolVersion(protoVersion))
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
func (HTTPClient) method(method string) (attribute.KeyValue, attribute.KeyValue) {
|
||||
func (n HTTPClient) method(method string) (attribute.KeyValue, attribute.KeyValue) {
|
||||
if method == "" {
|
||||
return semconv.HTTPRequestMethodOther, attribute.KeyValue{}
|
||||
}
|
||||
@@ -202,7 +180,7 @@ func (HTTPClient) method(method string) (attribute.KeyValue, attribute.KeyValue)
|
||||
return semconv.HTTPRequestMethodOther, orig
|
||||
}
|
||||
|
||||
func (n HTTPClient) MetricAttributes(req *http.Request, resp *http.Response, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
func (n HTTPClient) MetricAttributes(req *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
num := len(additionalAttributes) + 2
|
||||
var h string
|
||||
if req.URL != nil {
|
||||
@@ -222,14 +200,7 @@ func (n HTTPClient) MetricAttributes(req *http.Request, resp *http.Response, sta
|
||||
num++
|
||||
}
|
||||
|
||||
// Prefer the negotiated protocol reported on the response: req.Proto is
|
||||
// only what the caller asked for, and the transport may have upgraded
|
||||
// the connection (for example HTTP/2 via ALPN).
|
||||
proto := req.Proto
|
||||
if resp != nil && resp.Proto != "" {
|
||||
proto = resp.Proto
|
||||
}
|
||||
protoName, protoVersion := netProtocol(proto)
|
||||
protoName, protoVersion := netProtocol(req.Proto)
|
||||
if protoName != "" {
|
||||
num++
|
||||
}
|
||||
@@ -242,8 +213,7 @@ func (n HTTPClient) MetricAttributes(req *http.Request, resp *http.Response, sta
|
||||
}
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, num)
|
||||
attributes = append(
|
||||
attributes,
|
||||
attributes = append(attributes,
|
||||
semconv.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)),
|
||||
semconv.ServerAddress(requestHost),
|
||||
n.scheme(req),
|
||||
@@ -279,7 +249,7 @@ func (o MetricOpts) AddOptions() metric.AddOption {
|
||||
}
|
||||
|
||||
func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts {
|
||||
attributes := n.MetricAttributes(ma.Req, ma.Resp, ma.StatusCode, ma.AdditionalAttributes)
|
||||
attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes)
|
||||
if ma.StatusCode == 0 && ma.Err != nil {
|
||||
attributes = append(attributes, n.ErrorType(ma.Err))
|
||||
}
|
||||
@@ -299,12 +269,12 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts {
|
||||
// type per failure keeps attribute cardinality bounded, as required by the
|
||||
// OTel spec (error.type SHOULD have low cardinality). Callers that need
|
||||
// finer-grained error distinctions should inspect the error themselves.
|
||||
func (HTTPClient) ErrorType(err error) attribute.KeyValue {
|
||||
func (n HTTPClient) ErrorType(err error) attribute.KeyValue {
|
||||
t := reflect.TypeOf(err)
|
||||
if t == nil {
|
||||
return semconv.ErrorTypeOther
|
||||
}
|
||||
if t.Kind() == reflect.Pointer {
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
var value string
|
||||
@@ -337,13 +307,13 @@ func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts Metri
|
||||
}
|
||||
|
||||
// TraceAttributes returns attributes for httptrace.
|
||||
func (HTTPClient) TraceAttributes(host string) []attribute.KeyValue {
|
||||
func (n HTTPClient) TraceAttributes(host string) []attribute.KeyValue {
|
||||
return []attribute.KeyValue{
|
||||
semconv.ServerAddress(host),
|
||||
}
|
||||
}
|
||||
|
||||
func (HTTPClient) scheme(req *http.Request) attribute.KeyValue {
|
||||
func (n HTTPClient) scheme(req *http.Request) attribute.KeyValue {
|
||||
if req.URL != nil && req.URL.Scheme != "" {
|
||||
return semconv.URLScheme(req.URL.Scheme)
|
||||
}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package semconv
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
// Generate semconv package:
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/bench_test.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=bench_test.go
|
||||
|
||||
Generated
Vendored
+17
-25
@@ -1,12 +1,12 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/server.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/semconv/server.go.tmpl
|
||||
|
||||
// Package semconv provides OpenTelemetry semantic convention types and
|
||||
// functionality.
|
||||
package semconv
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.43.0/httpconv"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0/httpconv"
|
||||
)
|
||||
|
||||
type RequestTraceAttrsOpts struct {
|
||||
@@ -67,7 +67,7 @@ func NewHTTPServer(meter metric.Meter) HTTPServer {
|
||||
// Status returns a span status code and message for an HTTP status code
|
||||
// value returned by a server. Status codes in the 400-499 range are not
|
||||
// returned as errors.
|
||||
func (HTTPServer) Status(code int) (codes.Code, string) {
|
||||
func (n HTTPServer) Status(code int) (codes.Code, string) {
|
||||
if code < 100 || code >= 600 {
|
||||
return codes.Error, fmt.Sprintf("Invalid HTTP status code %d", code)
|
||||
}
|
||||
@@ -168,8 +168,7 @@ func (n HTTPServer) RequestTraceAttrs(server string, req *http.Request, opts Req
|
||||
}
|
||||
|
||||
attrs := make([]attribute.KeyValue, 0, count)
|
||||
attrs = append(
|
||||
attrs,
|
||||
attrs = append(attrs,
|
||||
semconv.ServerAddress(host),
|
||||
method,
|
||||
scheme,
|
||||
@@ -217,7 +216,7 @@ func (n HTTPServer) RequestTraceAttrs(server string, req *http.Request, opts Req
|
||||
return attrs
|
||||
}
|
||||
|
||||
func (HTTPServer) NetworkTransportAttr(network string) []attribute.KeyValue {
|
||||
func (s HTTPServer) NetworkTransportAttr(network string) []attribute.KeyValue {
|
||||
attr := semconv.NetworkTransportPipe
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
@@ -240,11 +239,7 @@ type ServerMetricData struct {
|
||||
}
|
||||
|
||||
type MetricAttributes struct {
|
||||
Req *http.Request
|
||||
// Resp is the client response, if any. It is only consulted by
|
||||
// HTTPClient.MetricAttributes to source the negotiated protocol version;
|
||||
// server-side metric recording ignores it.
|
||||
Resp *http.Response
|
||||
Req *http.Request
|
||||
StatusCode int
|
||||
Route string
|
||||
AdditionalAttributes []attribute.KeyValue
|
||||
@@ -279,7 +274,7 @@ func (n HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData) {
|
||||
// It returns "{method} {route}" when the request has a pattern,
|
||||
// or just "{method}" when no route is available.
|
||||
// Non-standard HTTP methods are replaced by "HTTP".
|
||||
func (HTTPServer) SpanName(r *http.Request) string {
|
||||
func (n HTTPServer) SpanName(r *http.Request) string {
|
||||
method := strings.ToUpper(r.Method)
|
||||
if _, ok := methodLookup[method]; !ok {
|
||||
method = "HTTP"
|
||||
@@ -292,7 +287,7 @@ func (HTTPServer) SpanName(r *http.Request) string {
|
||||
return method
|
||||
}
|
||||
|
||||
func (HTTPServer) method(method string) (attribute.KeyValue, attribute.KeyValue) {
|
||||
func (n HTTPServer) method(method string) (attribute.KeyValue, attribute.KeyValue) {
|
||||
if method == "" {
|
||||
return semconv.HTTPRequestMethodOther, attribute.KeyValue{}
|
||||
}
|
||||
@@ -319,7 +314,7 @@ func (n HTTPServer) scheme(https bool) attribute.KeyValue { //nolint:revive // i
|
||||
//
|
||||
// If any of the fields in the ResponseTelemetry are not set the attribute will
|
||||
// be omitted.
|
||||
func (HTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValue {
|
||||
func (n HTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValue {
|
||||
var count int
|
||||
|
||||
if resp.ReadBytes > 0 {
|
||||
@@ -335,20 +330,17 @@ func (HTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValu
|
||||
attributes := make([]attribute.KeyValue, 0, count)
|
||||
|
||||
if resp.ReadBytes > 0 {
|
||||
attributes = append(
|
||||
attributes,
|
||||
attributes = append(attributes,
|
||||
semconv.HTTPRequestBodySize(int(resp.ReadBytes)),
|
||||
)
|
||||
}
|
||||
if resp.WriteBytes > 0 {
|
||||
attributes = append(
|
||||
attributes,
|
||||
attributes = append(attributes,
|
||||
semconv.HTTPResponseBodySize(int(resp.WriteBytes)),
|
||||
)
|
||||
}
|
||||
if resp.StatusCode > 0 {
|
||||
attributes = append(
|
||||
attributes,
|
||||
attributes = append(attributes,
|
||||
semconv.HTTPResponseStatusCode(resp.StatusCode),
|
||||
)
|
||||
}
|
||||
@@ -357,7 +349,7 @@ func (HTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValu
|
||||
}
|
||||
|
||||
// Route returns the attribute for the route.
|
||||
func (HTTPServer) Route(route string) attribute.KeyValue {
|
||||
func (n HTTPServer) Route(route string) attribute.KeyValue {
|
||||
return semconv.HTTPRoute(route)
|
||||
}
|
||||
|
||||
|
||||
Generated
Vendored
+12
-12
@@ -1,10 +1,10 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/util.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/semconv/util.go.tmpl
|
||||
|
||||
package semconv
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconvNew "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
semconvNew "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
)
|
||||
|
||||
// SplitHostPort splits a network address hostport of the form "host",
|
||||
@@ -32,29 +32,29 @@ func SplitHostPort(hostport string) (host string, port int) {
|
||||
addrEnd := strings.LastIndexByte(hostport, ']')
|
||||
if addrEnd < 0 {
|
||||
// Invalid hostport.
|
||||
return host, port
|
||||
return
|
||||
}
|
||||
if i := strings.LastIndexByte(hostport[addrEnd:], ':'); i < 0 {
|
||||
host = hostport[1:addrEnd]
|
||||
return host, port
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if i := strings.LastIndexByte(hostport, ':'); i < 0 {
|
||||
host = hostport
|
||||
return host, port
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
host, pStr, err := net.SplitHostPort(hostport)
|
||||
if err != nil {
|
||||
return host, port
|
||||
return
|
||||
}
|
||||
|
||||
p, err := strconv.ParseUint(pStr, 10, 16)
|
||||
if err != nil {
|
||||
return host, port
|
||||
return
|
||||
}
|
||||
return host, int(p)
|
||||
return host, int(p) //nolint:gosec // Byte size checked 16 above.
|
||||
}
|
||||
|
||||
func requiredHTTPPort(https bool, port int) int { //nolint:revive // ignore linter
|
||||
@@ -84,7 +84,7 @@ func httpRoute(pattern string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func netProtocol(proto string) (name, version string) {
|
||||
func netProtocol(proto string) (name string, version string) {
|
||||
name, version, _ = strings.Cut(proto, "/")
|
||||
switch name {
|
||||
case "HTTP":
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
Generated
Vendored
+2
-21
@@ -1,11 +1,10 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
otelsemconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
otelsemconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
@@ -143,9 +142,6 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
t.propagators.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||
|
||||
res, err := t.rt.RoundTrip(r)
|
||||
if err == nil {
|
||||
res, err = ensureResponseBody(t.rt, r, res)
|
||||
}
|
||||
|
||||
// Record the metrics on error or no error.
|
||||
statusCode := 0
|
||||
@@ -164,7 +160,6 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
},
|
||||
t.semconv.MetricOptions(semconv.MetricAttributes{
|
||||
Req: r,
|
||||
Resp: res,
|
||||
StatusCode: statusCode,
|
||||
Err: err,
|
||||
AdditionalAttributes: append(labeler.Get(), t.metricAttributesFromRequest(r)...),
|
||||
@@ -188,20 +183,6 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func ensureResponseBody(rt http.RoundTripper, r *http.Request, res *http.Response) (*http.Response, error) {
|
||||
switch {
|
||||
case res == nil:
|
||||
return nil, fmt.Errorf("http: RoundTripper implementation (%T) returned a nil *Response with a nil error", rt)
|
||||
case res.Body != nil:
|
||||
return res, nil
|
||||
case res.ContentLength > 0 && r.Method != http.MethodHead:
|
||||
return nil, fmt.Errorf("http: RoundTripper implementation (%T) returned a *Response with content length %d but a nil Body", rt, res.ContentLength)
|
||||
default:
|
||||
res.Body = http.NoBody
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transport) metricAttributesFromRequest(r *http.Request) []attribute.KeyValue {
|
||||
var attributeForRequest []attribute.KeyValue
|
||||
if t.metricAttributesFn != nil {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otelhttp
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
// Version is the current release version of the otelhttp instrumentation.
|
||||
const Version = "0.70.0"
|
||||
const Version = "0.69.0"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@
|
||||
|
||||
// Package zpages implements a collection of HTML pages that display
|
||||
// telemetry stats.
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package internal provides non-public types for the zpages package.
|
||||
package internal
|
||||
package internal // import "go.opentelemetry.io/contrib/zpages/internal"
|
||||
|
||||
import "embed"
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package zpages
|
||||
package zpages // import "go.opentelemetry.io/contrib/zpages"
|
||||
|
||||
// Version is the current release version of the zpages span processor.
|
||||
const Version = "0.70.0"
|
||||
const Version = "0.69.0"
|
||||
+2
-2
@@ -96,9 +96,9 @@ linters:
|
||||
- "!**/exporters/zipkin/**"
|
||||
deny:
|
||||
- pkg: go.opentelemetry.io/otel/semconv
|
||||
desc: "Use go.opentelemetry.io/otel/semconv/v1.43.0 instead. If a newer semconv version has been released, update the depguard rule."
|
||||
desc: "Use go.opentelemetry.io/otel/semconv/v1.41.0 instead. If a newer semconv version has been released, update the depguard rule."
|
||||
allow:
|
||||
- go.opentelemetry.io/otel/semconv/v1.43.0
|
||||
- go.opentelemetry.io/otel/semconv/v1.41.0
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- appendAssign
|
||||
|
||||
-14
@@ -11,17 +11,3 @@ http://4.3.2.1:78/user/123
|
||||
file:///home/runner/work/opentelemetry-go/opentelemetry-go/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/dns:/:4317
|
||||
# URL works, but it has blocked link checkers.
|
||||
https://dl.acm.org/doi/10.1145/198429.198435
|
||||
https://pkg.go.dev/google.golang.org/grpc.*internal/resolver
|
||||
https://golang.org/src/crypto/tls/generate_cert.go
|
||||
https://github.com/grpc/grpc/blob/.*/doc/naming.md
|
||||
https://github.com/open-telemetry/opentelemetry-specification/blob/.*
|
||||
# Fake domains used in otlp options_test.go tests
|
||||
https?://env\.endpoint.*
|
||||
https?://env\.metrics\.endpoint.*
|
||||
https?://env_metrics_endpoint.*
|
||||
https?://env\.traces\.endpoint.*
|
||||
https?://env_traces_endpoint.*
|
||||
https?://someendpoint.*
|
||||
https?://overrode\.by\.signal\.specific.*
|
||||
https?://overrode_by_signal_specific.*
|
||||
https?://proxy\.com.*
|
||||
-3
@@ -47,9 +47,6 @@ For docs-only, test-only, or review-only tasks, still start with the required re
|
||||
- Prefer examples over long code snippets in GoDoc when practical.
|
||||
- Keep docs aligned with actual behavior. Do not leave stale comments, stale examples, or stale package documentation behind.
|
||||
- For user-visible changes, update `CHANGELOG.md` under the appropriate `Added`, `Changed`, `Deprecated`, `Fixed`, or `Removed` section within `## [Unreleased]`.
|
||||
- Always put the PR number at the end of the line (e.g., `(#1234)`), NOT the issue number.
|
||||
- If the PR number is not yet known, omit it until the PR is created, then update the changelog entry before merging.
|
||||
- Always use references to the go module that is updated (e.g., `go.opentelemetry.io/otel/sdk/metric`), instead of just the path (e.g., `sdk/metric`).
|
||||
|
||||
## Repository habits
|
||||
|
||||
|
||||
+4
-74
@@ -11,75 +11,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
## [1.45.0/0.67.0/0.21.0/0.0.18] - 2026-08-03
|
||||
|
||||
### Added
|
||||
|
||||
- Add experimental observability metrics to `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log`. (#7124)
|
||||
- Add the experimental `WithUnsafeAttributes` no-copy attribute option to `go.opentelemetry.io/otel/metric/x` for future performance improvements. This API is a work in progress. (#8251)
|
||||
- Add `Map` and `MapValue` functions for the new `MAP` attribute type in `go.opentelemetry.io/otel/attribute`. (#8445)
|
||||
- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlptrace`. (#8453)
|
||||
- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlplog`. (#8453)
|
||||
- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric`. (#8453)
|
||||
- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/zipkin`. (#8453)
|
||||
- Apply `AttributeValueLengthLimit` recursively to values contained in `attribute.MAP` attributes in `go.opentelemetry.io/otel/sdk/trace`. (#8454)
|
||||
- Remove duplicate keys from `attribute.MAP` values in `go.opentelemetry.io/otel/sdk/resource` using last-value-wins semantics. (#8471)
|
||||
- Remove duplicate keys by default from `attribute.MAP` values in instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/log` using last-value-wins semantics. (#8471)
|
||||
- Remove duplicate keys by default from `attribute.MAP` values in span, event, link, and instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/trace` using last-value-wins semantics. (#8471)
|
||||
- Remove duplicate keys by default from `attribute.MAP` values in measurement and instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/metric` using last-value-wins semantics. (#8471)
|
||||
- Extend `WithAllowKeyDuplication` in `go.opentelemetry.io/otel/sdk/log` to disable duplicate-key removal in `attribute.MAP` values for instrumentation scope attributes. (#8471)
|
||||
- Add the `go.opentelemetry.io/otel/semconv/v1.42.0` package.
|
||||
The package contains semantic conventions from the `v1.42.0` version of the OpenTelemetry Semantic Conventions.
|
||||
See the [migration documentation](./semconv/v1.42.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.41.0`. (#8484)
|
||||
- Add `WithoutPanicRecording` as a `TracerProviderOption` in `go.opentelemetry.io/otel/sdk/trace` to disable exception event recording for panics. (#8532)
|
||||
- Add the `go.opentelemetry.io/otel/semconv/v1.43.0` package.
|
||||
The package contains semantic conventions from the `v1.43.0` version of the OpenTelemetry Semantic Conventions.
|
||||
See the [migration documentation](./semconv/v1.43.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.42.0`. (#8628)
|
||||
|
||||
### Changed
|
||||
|
||||
- `HistogramReservoir` in `go.opentelemetry.io/otel/sdk/metric/exemplar` now uses a time-unbiased sampling algorithm for exemplars. (#8306)
|
||||
- ⚠️ **Breaking Change:** Use `go.opentelemetry.io/otel/attribute.Value` and `go.opentelemetry.io/otel/attribute.KeyValue` for log bodies and attributes in `go.opentelemetry.io/otel/log`, `go.opentelemetry.io/otel/log/logtest`, `go.opentelemetry.io/otel/sdk/log`, and `go.opentelemetry.io/otel/sdk/log/logtest`. (#8490)
|
||||
- Encode log bodies and attributes as `go.opentelemetry.io/otel/attribute.Value` JSON in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#8490)
|
||||
- Improve the performance of hashing `BOOLSLICE`, `INT64SLICE`, `FLOAT64SLICE`, and `STRINGSLICE` attribute values by avoiding reflection for short slices in `go.opentelemetry.io/otel/attribute`. (#8511)
|
||||
- ⚠️ **Breaking Change:** `WithEndpointURL` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` no longer appends the default signal path when an endpoint URL has no path, making the behavior consistent with `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` and with setting the endpoint through `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`. If the URL has no path component, the root path (`/`) is used. Use `WithEndpointURL(url.JoinPath(endpoint, "/v1/metrics"))` to preserve the previous behavior. (#8538)
|
||||
- ⚠️ **Breaking Change:** `WithEndpointURL` in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` no longer appends the default signal path when an endpoint URL has no path, making the behavior consistent with `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` and with setting the endpoint through `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. If the URL has no path component, the root path (`/`) is used. Use `WithEndpointURL(url.JoinPath(endpoint, "/v1/traces"))` to preserve the previous behavior. (#8538)
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Deprecate `WithExportBufferSize` in `go.opentelemetry.io/otel/sdk/log`. The option remains available for source compatibility but no longer affects behavior; `BatchProcessor` no longer maintains a separate export-request buffer. (#8620)
|
||||
|
||||
### Removed
|
||||
|
||||
- ⚠️ **Breaking Change:** Remove `Kind`, `Value`, `KeyValue`, their constructors, and attribute conversion helpers from `go.opentelemetry.io/otel/log`. (#8490)
|
||||
- ⚠️ **Breaking Change:** Remove the `AttributeValueLengthLimit` and `AttributeCountLimit` fields from `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`; records produced by the factory now keep attribute limits disabled so test code can append exact attributes. (#8556)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Apply TLS certificates configured through environment variables to gRPC connections in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`.
|
||||
- Prevent panics in `go.opentelemetry.io/otel/bridge/opentracing` when OpenTracing baggage is propagated concurrently with `Span.SetBaggageItem`.
|
||||
- Fix an off-by-one error in `FixedSizeReservoir` in `go.opentelemetry.io/otel/sdk/metric/exemplar` that prevented the first exemplar from being sampled after the reservoir was filled. (#8309)
|
||||
- Interpret HTTP `Retry-After` header values as seconds instead of nanoseconds when retrying OTLP HTTP exports in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`, and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8383)
|
||||
- Fix a memory leak in the `Reservoir` implementation in `go.opentelemetry.io/otel/sdk/metric/exemplar`, where storing the full `context.Context` pinned large objects such as gRPC transport buffers. (#8389)
|
||||
- Prevent a non-empty attribute set whose computed hash is zero from collapsing to an empty set in `go.opentelemetry.io/otel/attribute`. (#8402)
|
||||
- Fix histogram data point reuse in `go.opentelemetry.io/otel/sdk/metric` aggregation to avoid leaking stale sum, minimum, and maximum values when they are disabled in subsequent collections. (#8403)
|
||||
- Avoid preallocating scope attributes when they are disabled in `go.opentelemetry.io/otel/exporters/prometheus`. (#8404)
|
||||
- Support HTTP-date values in the HTTP `Retry-After` header when retrying OTLP HTTP exports in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`, and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8417)
|
||||
- Reduce histogram heap allocations by reusing `BucketCounts` and `Exemplars` slices across `Collect` cycles in the cumulative histogram aggregation in `go.opentelemetry.io/otel/sdk/metric`. (#8428)
|
||||
- Fix `go.opentelemetry.io/otel/exporters/stdout/stdouttrace` self-observability to record `error.type` on the operation-duration histogram when the `exportedSpans` metric is disabled. (#8432)
|
||||
- Stop including trace exporter endpoint configuration in internal logs from `go.opentelemetry.io/otel/sdk/trace`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, and `go.opentelemetry.io/otel/exporters/zipkin`. (#8438)
|
||||
- Fix invalid error formatting for out-of-range JSON code values in `go.opentelemetry.io/otel/codes`. (#8497)
|
||||
- Clarify in `go.opentelemetry.io/otel/log` that `Logger.Enabled` should be checked for every log emission because its result may change over time. (#8565)
|
||||
- Preserve user-provided exception attributes while independently deriving missing exception message and type attributes in `go.opentelemetry.io/otel/sdk/log`. (#8566)
|
||||
- Make `WithAttributeCountLimit(0)` and `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT=0` discard all log record attributes in `go.opentelemetry.io/otel/sdk/log`. (#8570)
|
||||
- Clarify that the `Record` methods of `Float64Histogram` and `Int64Histogram` in `go.opentelemetry.io/otel/metric` expect non-negative values. (#8574)
|
||||
- Clarify in `go.opentelemetry.io/otel/log` that `LoggerProvider` implementations should retain an empty `Logger` name instead of replacing it with a default. (#8587)
|
||||
- Ensure that the built-in processors in `go.opentelemetry.io/otel/sdk/log` call exporter `ForceFlush` during `Shutdown`. (#8599)
|
||||
- Prevent processor operations in `go.opentelemetry.io/otel/sdk/log` from overlapping with processor shutdown or running after `LoggerProvider` shutdown. (#8608)
|
||||
- Prevent `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log` from busy-spinning under exporter backpressure and serialize dequeue, export, force-flush, and shutdown work in one worker. (#8620)
|
||||
- Make `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log` return errors encountered while draining records during `ForceFlush` and `Shutdown`, while continuing to attempt later batches as long as the request context remains valid. (#8620)
|
||||
- Keep the default `BatchProcessor` maximum export batch size in `go.opentelemetry.io/otel/sdk/log` at or below the configured maximum queue size. (#8620)
|
||||
|
||||
## [1.44.0/0.66.0/0.20.0/0.0.17] 2026-05-27
|
||||
|
||||
### Added
|
||||
@@ -111,13 +42,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
Set `OTEL_GO_X_METRIC_EXPORT_BATCH_SIZE=<max_size>` to enable for all periodic readers.
|
||||
See `go.opentelemetry.io/otel/sdk/metric/internal/x` for feature documentation. (#8071)
|
||||
- Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`.
|
||||
Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable.
|
||||
Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable.
|
||||
See `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x` for feature documentation. (#8192)
|
||||
- Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`.
|
||||
Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable.
|
||||
Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable.
|
||||
See `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x` for feature documentation. (#8194)
|
||||
- Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
|
||||
Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable.
|
||||
Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable.
|
||||
See `go.opentelemetry.io/otel/stdout/stdoutlog/internal/x` for feature documentation. (#8263)
|
||||
- Add `WithDefaultAttributes` to `go.opentelemetry.io/otel/metric/x` to support setting default attributes on instruments. (#8135)
|
||||
- Add `go.opentelemetry.io/otel/semconv/v1.41.0` package.
|
||||
@@ -3782,8 +3713,7 @@ It contains api and sdk for trace and meter.
|
||||
- CircleCI build CI manifest files.
|
||||
- CODEOWNERS file to track owners of this project.
|
||||
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.45.0...HEAD
|
||||
[1.45.0/0.67.0/0.21.0/0.0.18]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.45.0
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.44.0...HEAD
|
||||
[1.44.0/0.66.0/0.20.0/0.0.17]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.44.0
|
||||
[1.43.0/0.65.0/0.19.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.43.0
|
||||
[1.42.0/0.64.0/0.18.0/0.0.16]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.42.0
|
||||
|
||||
+5
-7
@@ -8,10 +8,8 @@ repo for information on this and other language SIGs.
|
||||
See the [public meeting
|
||||
notes](https://docs.google.com/document/d/1E5e7Ld0NuU1iVvf-42tOBpu2VBBLYnh73GJuITGJTTU/edit)
|
||||
for a summary description of past meetings. To request edit access,
|
||||
join the meeting or get in touch on the
|
||||
[#otel-go](https://cloud-native.slack.com/archives/C01NPAXACKT)
|
||||
channel on CNCF Slack. If you are new to the CNCF Slack community,
|
||||
you can [create an account](https://slack.cncf.io/).
|
||||
join the meeting or get in touch on
|
||||
[Slack](https://cloud-native.slack.com/archives/C01NPAXACKT).
|
||||
|
||||
The meeting is open for all to join. We invite everyone to join our
|
||||
meeting, regardless of your experience level. Whether you're a
|
||||
@@ -754,8 +752,8 @@ Encapsulate setup in constructor functions, ensuring clear ownership and scope:
|
||||
import (
|
||||
"errors"
|
||||
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.43.0/otelconv"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0/otelconv"
|
||||
)
|
||||
|
||||
type SDKComponent struct {
|
||||
@@ -1056,7 +1054,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
|
||||
|
||||
All observability metrics should follow the [OpenTelemetry Semantic Conventions for SDK metrics](https://github.com/open-telemetry/semantic-conventions/blob/1cf2476ae5e518225a766990a28a6d5602bd5a30/docs/otel/sdk-metrics.md).
|
||||
|
||||
Use the metric semantic conventions convenience package [otelconv](./semconv/v1.43.0/otelconv/metric.go).
|
||||
Use the metric semantic conventions convenience package [otelconv](./semconv/v1.41.0/otelconv/metric.go).
|
||||
|
||||
##### Component Identification
|
||||
|
||||
|
||||
+15
-5
@@ -10,7 +10,6 @@ ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {}
|
||||
|
||||
GO = go
|
||||
TIMEOUT = 60
|
||||
GO_VERSION := $(shell awk '/^go [0-9]/ {print $$2; exit}' go.mod)
|
||||
|
||||
# User to run as in docker images.
|
||||
DOCKER_USER=$(shell id -u):$(shell id -g)
|
||||
@@ -20,7 +19,7 @@ DEPENDENCIES_DOCKERFILE=./dependencies.Dockerfile
|
||||
|
||||
.PHONY: precommit ci
|
||||
precommit: generate toolchain-check license-check misspell go-mod-tidy golangci-lint-fix verify-readmes verify-mods test-default
|
||||
ci: generate toolchain-check license-check lint verify-readmes verify-mods build test-default check-clean-work-tree test-coverage
|
||||
ci: generate toolchain-check license-check lint vanity-import-check verify-readmes verify-mods build test-default check-clean-work-tree test-coverage
|
||||
|
||||
# Tools
|
||||
|
||||
@@ -60,6 +59,9 @@ $(TOOLS)/gocovmerge: PACKAGE=github.com/wadey/gocovmerge
|
||||
STRINGER = $(TOOLS)/stringer
|
||||
$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer
|
||||
|
||||
PORTO = $(TOOLS)/porto
|
||||
$(TOOLS)/porto: PACKAGE=github.com/jcchavezs/porto/cmd/porto
|
||||
|
||||
GOTMPL = $(TOOLS)/gotmpl
|
||||
$(GOTMPL): PACKAGE=go.opentelemetry.io/build-tools/gotmpl
|
||||
|
||||
@@ -70,7 +72,7 @@ GOVULNCHECK = $(TOOLS)/govulncheck
|
||||
$(TOOLS)/govulncheck: PACKAGE=golang.org/x/vuln/cmd/govulncheck
|
||||
|
||||
.PHONY: tools
|
||||
tools: $(CROSSLINK) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(VERIFYREADMES) $(MULTIMOD) $(SEMCONVKIT) $(GOTMPL) $(GORELEASE)
|
||||
tools: $(CROSSLINK) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(VERIFYREADMES) $(MULTIMOD) $(SEMCONVKIT) $(GOTMPL) $(GORELEASE)
|
||||
|
||||
# Virtualized python tools via docker
|
||||
|
||||
@@ -108,7 +110,7 @@ $(CODESPELL): PACKAGE=codespell
|
||||
# Generate
|
||||
|
||||
.PHONY: generate
|
||||
generate: go-generate
|
||||
generate: go-generate vanity-import-fix
|
||||
|
||||
.PHONY: go-generate
|
||||
go-generate: $(OTEL_GO_MOD_DIRS:%=go-generate/%)
|
||||
@@ -118,10 +120,14 @@ go-generate/%: $(STRINGER) $(GOTMPL)
|
||||
&& cd $(DIR) \
|
||||
&& PATH="$(TOOLS):$${PATH}" $(GO) generate ./...
|
||||
|
||||
.PHONY: vanity-import-fix
|
||||
vanity-import-fix: $(PORTO)
|
||||
@$(PORTO) --include-internal -w .
|
||||
|
||||
# Generate go.work file for local development.
|
||||
.PHONY: go-work
|
||||
go-work: $(CROSSLINK)
|
||||
$(CROSSLINK) work --root=$(shell pwd) --go=$(GO_VERSION)
|
||||
$(CROSSLINK) work --root=$(shell pwd) --go=1.22.7
|
||||
|
||||
# Build
|
||||
|
||||
@@ -222,6 +228,10 @@ go-mod-tidy/%: crosslink
|
||||
.PHONY: lint
|
||||
lint: misspell go-mod-tidy golangci-lint
|
||||
|
||||
.PHONY: vanity-import-check
|
||||
vanity-import-check: $(PORTO)
|
||||
@$(PORTO) --include-internal -l . || ( echo "(run: make vanity-import-fix)"; exit 1 )
|
||||
|
||||
.PHONY: misspell
|
||||
misspell: $(MISSPELL)
|
||||
@$(MISSPELL) -w $(ALL_DOCS)
|
||||
|
||||
-7
@@ -113,10 +113,3 @@ All officially supported exporters for the OpenTelemetry project are contained i
|
||||
## Contributing
|
||||
|
||||
See the [contributing documentation](CONTRIBUTING.md).
|
||||
|
||||
### Emeritus
|
||||
|
||||
- [Alex Kats](https://github.com/akats7), Triager
|
||||
|
||||
For more information about the emeritus role, see the
|
||||
[community repository](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#emeritus-maintainerapprovertriager).
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package attribute provides key and value attributes.
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// Filter supports removing certain attributes from attribute sets. When
|
||||
// the filter returns true, the attribute will be kept in the filtered
|
||||
|
||||
+26
-136
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -29,7 +29,6 @@ const (
|
||||
stringSliceID uint64 = 7453010373645655387 // "[]string" (little endian)
|
||||
byteSliceID uint64 = 6874028470941080415 // "_[]byte_" (little endian)
|
||||
sliceID uint64 = 7883494272577650031 // "__slice_" (little endian)
|
||||
mapID uint64 = 6872316492666199903 // "__map___" (little endian)
|
||||
emptyID uint64 = 7305809155345288421 // "__empty_" (little endian)
|
||||
)
|
||||
|
||||
@@ -39,13 +38,7 @@ func hashKVs(kvs []KeyValue) uint64 {
|
||||
for _, kv := range kvs {
|
||||
h = hashKV(h, kv)
|
||||
}
|
||||
sum := h.Sum64()
|
||||
// Remap 0 to a non-zero value for non-empty input because hash == 0 is a reserved sentinel (treated as empty/invalid).
|
||||
const remappedZeroHash uint64 = 1
|
||||
if sum == 0 && len(kvs) > 0 {
|
||||
return remappedZeroHash
|
||||
}
|
||||
return sum
|
||||
return h.Sum64()
|
||||
}
|
||||
|
||||
// hashKV returns the xxHash64 hash of kv with h as the base.
|
||||
@@ -71,79 +64,27 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash {
|
||||
h = h.String(v.stringly)
|
||||
case BOOLSLICE:
|
||||
h = h.Uint64(boolSliceID)
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]bool:
|
||||
case [1]bool:
|
||||
h = h.Bool(vals[0])
|
||||
case [2]bool:
|
||||
h = h.Bool(vals[0])
|
||||
h = h.Bool(vals[1])
|
||||
case [3]bool:
|
||||
h = h.Bool(vals[0])
|
||||
h = h.Bool(vals[1])
|
||||
h = h.Bool(vals[2])
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Bool(rv.Index(i).Bool())
|
||||
}
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Bool(rv.Index(i).Bool())
|
||||
}
|
||||
case INT64SLICE:
|
||||
h = h.Uint64(int64SliceID)
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]int64:
|
||||
case [1]int64:
|
||||
h = h.Int64(vals[0])
|
||||
case [2]int64:
|
||||
h = h.Int64(vals[0])
|
||||
h = h.Int64(vals[1])
|
||||
case [3]int64:
|
||||
h = h.Int64(vals[0])
|
||||
h = h.Int64(vals[1])
|
||||
h = h.Int64(vals[2])
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Int64(rv.Index(i).Int())
|
||||
}
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Int64(rv.Index(i).Int())
|
||||
}
|
||||
case FLOAT64SLICE:
|
||||
h = h.Uint64(float64SliceID)
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]float64:
|
||||
case [1]float64:
|
||||
h = h.Float64(vals[0])
|
||||
case [2]float64:
|
||||
h = h.Float64(vals[0])
|
||||
h = h.Float64(vals[1])
|
||||
case [3]float64:
|
||||
h = h.Float64(vals[0])
|
||||
h = h.Float64(vals[1])
|
||||
h = h.Float64(vals[2])
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Float64(rv.Index(i).Float())
|
||||
}
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.Float64(rv.Index(i).Float())
|
||||
}
|
||||
case STRINGSLICE:
|
||||
h = h.Uint64(stringSliceID)
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]string:
|
||||
case [1]string:
|
||||
h = h.String(vals[0])
|
||||
case [2]string:
|
||||
h = h.String(vals[0])
|
||||
h = h.String(vals[1])
|
||||
case [3]string:
|
||||
h = h.String(vals[0])
|
||||
h = h.String(vals[1])
|
||||
h = h.String(vals[2])
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.String(rv.Index(i).String())
|
||||
}
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = h.String(rv.Index(i).String())
|
||||
}
|
||||
case BYTESLICE:
|
||||
h = h.Uint64(byteSliceID)
|
||||
@@ -154,79 +95,21 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash {
|
||||
case [0]Value:
|
||||
// No values to hash, but the type identifier is still hashed above.
|
||||
case [1]Value:
|
||||
h = hashValue(h, vals[0])
|
||||
h = hashValueSlice(h, vals[:])
|
||||
case [2]Value:
|
||||
h = hashValue(h, vals[0])
|
||||
h = hashValue(h, vals[1])
|
||||
h = hashValueSlice(h, vals[:])
|
||||
case [3]Value:
|
||||
h = hashValue(h, vals[0])
|
||||
h = hashValue(h, vals[1])
|
||||
h = hashValue(h, vals[2])
|
||||
h = hashValueSlice(h, vals[:])
|
||||
case [4]Value:
|
||||
h = hashValue(h, vals[0])
|
||||
h = hashValue(h, vals[1])
|
||||
h = hashValue(h, vals[2])
|
||||
h = hashValue(h, vals[3])
|
||||
h = hashValueSlice(h, vals[:])
|
||||
case [5]Value:
|
||||
h = hashValue(h, vals[0])
|
||||
h = hashValue(h, vals[1])
|
||||
h = hashValue(h, vals[2])
|
||||
h = hashValue(h, vals[3])
|
||||
h = hashValue(h, vals[4])
|
||||
h = hashValueSlice(h, vals[:])
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
h = hashValue(h, rv.Index(i).Interface().(Value))
|
||||
}
|
||||
}
|
||||
case MAP:
|
||||
h = h.Uint64(mapID)
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]KeyValue:
|
||||
// No values to hash, but the type identifier is still hashed above.
|
||||
case [1]KeyValue:
|
||||
h = h.String(string(vals[0].Key))
|
||||
h = hashValue(h, vals[0].Value)
|
||||
case [2]KeyValue:
|
||||
h = h.String(string(vals[0].Key))
|
||||
h = hashValue(h, vals[0].Value)
|
||||
h = h.String(string(vals[1].Key))
|
||||
h = hashValue(h, vals[1].Value)
|
||||
case [3]KeyValue:
|
||||
h = h.String(string(vals[0].Key))
|
||||
h = hashValue(h, vals[0].Value)
|
||||
h = h.String(string(vals[1].Key))
|
||||
h = hashValue(h, vals[1].Value)
|
||||
h = h.String(string(vals[2].Key))
|
||||
h = hashValue(h, vals[2].Value)
|
||||
case [4]KeyValue:
|
||||
h = h.String(string(vals[0].Key))
|
||||
h = hashValue(h, vals[0].Value)
|
||||
h = h.String(string(vals[1].Key))
|
||||
h = hashValue(h, vals[1].Value)
|
||||
h = h.String(string(vals[2].Key))
|
||||
h = hashValue(h, vals[2].Value)
|
||||
h = h.String(string(vals[3].Key))
|
||||
h = hashValue(h, vals[3].Value)
|
||||
case [5]KeyValue:
|
||||
h = h.String(string(vals[0].Key))
|
||||
h = hashValue(h, vals[0].Value)
|
||||
h = h.String(string(vals[1].Key))
|
||||
h = hashValue(h, vals[1].Value)
|
||||
h = h.String(string(vals[2].Key))
|
||||
h = hashValue(h, vals[2].Value)
|
||||
h = h.String(string(vals[3].Key))
|
||||
h = hashValue(h, vals[3].Value)
|
||||
h = h.String(string(vals[4].Key))
|
||||
h = hashValue(h, vals[4].Value)
|
||||
default:
|
||||
rv := reflect.ValueOf(v.slice)
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
kv := rv.Index(i).Interface().(KeyValue)
|
||||
h = h.String(string(kv.Key))
|
||||
h = hashValue(h, kv.Value)
|
||||
}
|
||||
}
|
||||
case EMPTY:
|
||||
h = h.Uint64(emptyID)
|
||||
default:
|
||||
@@ -238,3 +121,10 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash {
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func hashValueSlice(h xxhash.Hash, vals []Value) xxhash.Hash {
|
||||
for _, v := range vals {
|
||||
h = hashValue(h, v)
|
||||
}
|
||||
return h
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
Package attribute provide several helper functions for some commonly used
|
||||
logic of processing attributes.
|
||||
*/
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute/internal"
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package xxhash provides a wrapper around the xxhash library for attribute hashing.
|
||||
package xxhash
|
||||
package xxhash // import "go.opentelemetry.io/otel/attribute/internal/xxhash"
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// Iterator allows iterating over the set of attributes in order, sorted by
|
||||
// key.
|
||||
|
||||
+37
-97
@@ -1,16 +1,16 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// Key represents the key part in key-value pairs. It's a string. The
|
||||
// allowed character set in the key depends on the use of the key.
|
||||
type Key string
|
||||
|
||||
// Bool returns a [KeyValue] for a bool value.
|
||||
// Bool creates a KeyValue instance with a BOOL Value.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Bool] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Bool(name, value).
|
||||
func (k Key) Bool(v bool) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -18,15 +18,10 @@ func (k Key) Bool(v bool) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// BoolSlice returns a [KeyValue] for a []bool value.
|
||||
// BoolSlice creates a KeyValue instance with a BOOLSLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [BoolSlice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- BoolSlice(name, value).
|
||||
func (k Key) BoolSlice(v []bool) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -34,12 +29,10 @@ func (k Key) BoolSlice(v []bool) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Int returns a [KeyValue] for an int value.
|
||||
// Int creates a KeyValue instance with an INT64 Value.
|
||||
//
|
||||
// It is provided as a convenience for [Key.Int64].
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level [Int]
|
||||
// function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Int(name, value).
|
||||
func (k Key) Int(v int) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -47,17 +40,10 @@ func (k Key) Int(v int) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// IntSlice returns a [KeyValue] for a []int value.
|
||||
// IntSlice creates a KeyValue instance with an INT64SLICE Value.
|
||||
//
|
||||
// It is provided as a convenience for [Key.Int64Slice].
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [IntSlice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- IntSlice(name, value).
|
||||
func (k Key) IntSlice(v []int) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -65,10 +51,10 @@ func (k Key) IntSlice(v []int) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Int64 returns a [KeyValue] for an int64 value.
|
||||
// Int64 creates a KeyValue instance with an INT64 Value.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Int64] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Int64(name, value).
|
||||
func (k Key) Int64(v int64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -76,15 +62,10 @@ func (k Key) Int64(v int64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Int64Slice returns a [KeyValue] for a []int64 value.
|
||||
// Int64Slice creates a KeyValue instance with an INT64SLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Int64Slice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Int64Slice(name, value).
|
||||
func (k Key) Int64Slice(v []int64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -92,10 +73,10 @@ func (k Key) Int64Slice(v []int64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Float64 returns a [KeyValue] for a float64 value.
|
||||
// Float64 creates a KeyValue instance with a FLOAT64 Value.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Float64] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Float64(name, value).
|
||||
func (k Key) Float64(v float64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -103,15 +84,10 @@ func (k Key) Float64(v float64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Float64Slice returns a [KeyValue] for a []float64 value.
|
||||
// Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Float64Slice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Float64(name, value).
|
||||
func (k Key) Float64Slice(v []float64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -119,10 +95,10 @@ func (k Key) Float64Slice(v []float64) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a [KeyValue] for a string value.
|
||||
// String creates a KeyValue instance with a STRING Value.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [String] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- String(name, value).
|
||||
func (k Key) String(v string) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -130,15 +106,10 @@ func (k Key) String(v string) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// StringSlice returns a [KeyValue] for a []string value.
|
||||
// StringSlice creates a KeyValue instance with a STRINGSLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [StringSlice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- StringSlice(name, value).
|
||||
func (k Key) StringSlice(v []string) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -146,15 +117,10 @@ func (k Key) StringSlice(v []string) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// ByteSlice returns a [KeyValue] for a []byte value.
|
||||
// ByteSlice creates a KeyValue instance with a BYTESLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [ByteSlice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- ByteSlice(name, value).
|
||||
func (k Key) ByteSlice(v []byte) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -162,15 +128,10 @@ func (k Key) ByteSlice(v []byte) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Slice returns a [KeyValue] for a []Value value.
|
||||
// Slice creates a KeyValue instance with a SLICE Value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level
|
||||
// [Slice] function.
|
||||
// If creating both a key and value at the same time, use the provided
|
||||
// convenience function instead -- Slice(name, values...).
|
||||
func (k Key) Slice(v ...Value) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
@@ -178,27 +139,6 @@ func (k Key) Slice(v ...Value) KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Map returns a [KeyValue] for a []KeyValue value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// Users should avoid providing duplicate keys; many receivers handle maps
|
||||
// containing duplicate keys unpredictably.
|
||||
//
|
||||
// The order of v is not preserved.
|
||||
//
|
||||
// If creating both a key and value at the same time, use the package-level [Map]
|
||||
// function.
|
||||
func (k Key) Map(v ...KeyValue) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: MapValue(v...),
|
||||
}
|
||||
}
|
||||
|
||||
// Defined reports whether the key is not empty.
|
||||
func (k Key) Defined() bool {
|
||||
return len(k) != 0
|
||||
|
||||
+13
-67
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -18,120 +18,66 @@ func (kv KeyValue) Valid() bool {
|
||||
return kv.Key.Defined()
|
||||
}
|
||||
|
||||
// Bool returns a [KeyValue] for a bool value.
|
||||
// Bool creates a KeyValue with a BOOL Value type.
|
||||
func Bool(k string, v bool) KeyValue {
|
||||
return Key(k).Bool(v)
|
||||
}
|
||||
|
||||
// BoolSlice returns a [KeyValue] for a []bool value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// BoolSlice creates a KeyValue with a BOOLSLICE Value type.
|
||||
func BoolSlice(k string, v []bool) KeyValue {
|
||||
return Key(k).BoolSlice(v)
|
||||
}
|
||||
|
||||
// Int returns a [KeyValue] for an int value.
|
||||
//
|
||||
// It is provided as a convenience for [Int64].
|
||||
// Int creates a KeyValue with an INT64 Value type.
|
||||
func Int(k string, v int) KeyValue {
|
||||
return Key(k).Int(v)
|
||||
}
|
||||
|
||||
// IntSlice returns a [KeyValue] for a []int value.
|
||||
//
|
||||
// It is provided as a convenience for [Int64Slice].
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// IntSlice creates a KeyValue with an INT64SLICE Value type.
|
||||
func IntSlice(k string, v []int) KeyValue {
|
||||
return Key(k).IntSlice(v)
|
||||
}
|
||||
|
||||
// Int64 returns a [KeyValue] for an int64 value.
|
||||
// Int64 creates a KeyValue with an INT64 Value type.
|
||||
func Int64(k string, v int64) KeyValue {
|
||||
return Key(k).Int64(v)
|
||||
}
|
||||
|
||||
// Int64Slice returns a [KeyValue] for a []int64 value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// Int64Slice creates a KeyValue with an INT64SLICE Value type.
|
||||
func Int64Slice(k string, v []int64) KeyValue {
|
||||
return Key(k).Int64Slice(v)
|
||||
}
|
||||
|
||||
// Float64 returns a [KeyValue] for a float64 value.
|
||||
// Float64 creates a KeyValue with a FLOAT64 Value type.
|
||||
func Float64(k string, v float64) KeyValue {
|
||||
return Key(k).Float64(v)
|
||||
}
|
||||
|
||||
// Float64Slice returns a [KeyValue] for a []float64 value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// Float64Slice creates a KeyValue with a FLOAT64SLICE Value type.
|
||||
func Float64Slice(k string, v []float64) KeyValue {
|
||||
return Key(k).Float64Slice(v)
|
||||
}
|
||||
|
||||
// String returns a [KeyValue] for a string value.
|
||||
// String creates a KeyValue with a STRING Value type.
|
||||
func String(k, v string) KeyValue {
|
||||
return Key(k).String(v)
|
||||
}
|
||||
|
||||
// StringSlice returns a [KeyValue] for a []string value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// StringSlice creates a KeyValue with a STRINGSLICE Value type.
|
||||
func StringSlice(k string, v []string) KeyValue {
|
||||
return Key(k).StringSlice(v)
|
||||
}
|
||||
|
||||
// ByteSlice returns a [KeyValue] for a []byte value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// ByteSlice creates a KeyValue with a BYTESLICE Value type.
|
||||
func ByteSlice(k string, v []byte) KeyValue {
|
||||
return Key(k).ByteSlice(v)
|
||||
}
|
||||
|
||||
// Slice returns a [KeyValue] for a []Value value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// Slice creates a KeyValue with a SLICE Value type.
|
||||
func Slice(k string, v ...Value) KeyValue {
|
||||
return Key(k).Slice(v...)
|
||||
}
|
||||
|
||||
// Map returns a [KeyValue] for a []KeyValue value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// Users should avoid providing duplicate keys; many receivers handle maps
|
||||
// containing duplicate keys unpredictably.
|
||||
//
|
||||
// The order of v is not preserved.
|
||||
func Map(k string, v ...KeyValue) KeyValue {
|
||||
return Key(k).Map(v...)
|
||||
}
|
||||
|
||||
// Stringer creates a new key-value pair with a passed name and a string
|
||||
// value generated by the passed Stringer interface.
|
||||
func Stringer(k string, v fmt.Stringer) KeyValue {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
|
||||
+2
-3
@@ -19,12 +19,11 @@ func _() {
|
||||
_ = x[STRINGSLICE-8]
|
||||
_ = x[BYTESLICE-9]
|
||||
_ = x[SLICE-10]
|
||||
_ = x[MAP-11]
|
||||
}
|
||||
|
||||
const _Type_name = "EMPTYBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICEBYTESLICESLICEMAP"
|
||||
const _Type_name = "EMPTYBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICEBYTESLICESLICE"
|
||||
|
||||
var _Type_index = [...]uint8{0, 5, 9, 14, 21, 27, 36, 46, 58, 69, 78, 83, 86}
|
||||
var _Type_index = [...]uint8{0, 5, 9, 14, 21, 27, 36, 46, 58, 69, 78, 83}
|
||||
|
||||
func (i Type) String() string {
|
||||
idx := int(i) - 0
|
||||
|
||||
+31
-281
@@ -1,16 +1,14 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package attribute
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
@@ -20,10 +18,10 @@ import (
|
||||
|
||||
//go:generate stringer -type=Type
|
||||
|
||||
// Type describes the kind of data a [Value] holds.
|
||||
// Type describes the type of the data Value holds.
|
||||
type Type int // nolint: revive // redefines builtin Type.
|
||||
|
||||
// Value represents the value in key-value pairs.
|
||||
// Value represents the value part in key-value pairs.
|
||||
//
|
||||
// Note that the zero value is a valid empty value.
|
||||
type Value struct {
|
||||
@@ -34,40 +32,35 @@ type Value struct {
|
||||
}
|
||||
|
||||
const (
|
||||
// EMPTY identifies a Value with no data.
|
||||
// EMPTY is used for a Value with no value set.
|
||||
EMPTY Type = iota
|
||||
// BOOL identifies a Value containing a bool.
|
||||
// BOOL is a boolean Type Value.
|
||||
BOOL
|
||||
// INT64 identifies a Value containing an int64.
|
||||
// INT64 is a 64-bit signed integral Type Value.
|
||||
INT64
|
||||
// FLOAT64 identifies a Value containing a float64.
|
||||
// FLOAT64 is a 64-bit floating point Type Value.
|
||||
FLOAT64
|
||||
// STRING identifies a Value containing a string.
|
||||
// STRING is a string Type Value.
|
||||
STRING
|
||||
// BOOLSLICE identifies a Value containing a []bool.
|
||||
// BOOLSLICE is a slice of booleans Type Value.
|
||||
BOOLSLICE
|
||||
// INT64SLICE identifies a Value containing a []int64.
|
||||
// INT64SLICE is a slice of 64-bit signed integral numbers Type Value.
|
||||
INT64SLICE
|
||||
// FLOAT64SLICE identifies a Value containing a []float64.
|
||||
// FLOAT64SLICE is a slice of 64-bit floating point numbers Type Value.
|
||||
FLOAT64SLICE
|
||||
// STRINGSLICE identifies a Value containing a []string.
|
||||
// STRINGSLICE is a slice of strings Type Value.
|
||||
STRINGSLICE
|
||||
// BYTESLICE identifies a Value containing a []byte.
|
||||
// BYTESLICE is a slice of bytes Type Value.
|
||||
BYTESLICE
|
||||
// SLICE identifies a Value containing a []Value.
|
||||
// SLICE is a slice of Value Type values.
|
||||
SLICE
|
||||
// MAP identifies a Value containing a []KeyValue representation of a map.
|
||||
//
|
||||
// Note that MAP values may contain duplicate keys if duplicate keys are
|
||||
// provided when creating the value.
|
||||
MAP
|
||||
// INVALID is used for a Value with no value set.
|
||||
//
|
||||
// Deprecated: Use EMPTY instead as an empty value is a valid value.
|
||||
INVALID = EMPTY
|
||||
)
|
||||
|
||||
// BoolValue returns a [Value] for a bool value.
|
||||
// BoolValue creates a BOOL Value.
|
||||
func BoolValue(v bool) Value {
|
||||
return Value{
|
||||
vtype: BOOL,
|
||||
@@ -75,31 +68,17 @@ func BoolValue(v bool) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// BoolSliceValue returns a [Value] for a []bool value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// BoolSliceValue creates a BOOLSLICE Value.
|
||||
func BoolSliceValue(v []bool) Value {
|
||||
return Value{vtype: BOOLSLICE, slice: attribute.SliceValue(v)}
|
||||
}
|
||||
|
||||
// IntValue returns a [Value] for an int value.
|
||||
//
|
||||
// It is provided as a convenience for [Int64Value].
|
||||
// IntValue creates an INT64 Value.
|
||||
func IntValue(v int) Value {
|
||||
return Int64Value(int64(v))
|
||||
}
|
||||
|
||||
// IntSliceValue returns a [Value] for a []int value.
|
||||
//
|
||||
// It is provided as a convenience for [Int64SliceValue].
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// IntSliceValue creates an INT64SLICE Value.
|
||||
func IntSliceValue(v []int) Value {
|
||||
val := Value{vtype: INT64SLICE}
|
||||
|
||||
@@ -125,7 +104,7 @@ func IntSliceValue(v []int) Value {
|
||||
return val
|
||||
}
|
||||
|
||||
// Int64Value returns a [Value] for an int64 value.
|
||||
// Int64Value creates an INT64 Value.
|
||||
func Int64Value(v int64) Value {
|
||||
return Value{
|
||||
vtype: INT64,
|
||||
@@ -133,17 +112,12 @@ func Int64Value(v int64) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// Int64SliceValue returns a [Value] for a []int64 value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// Int64SliceValue creates an INT64SLICE Value.
|
||||
func Int64SliceValue(v []int64) Value {
|
||||
return Value{vtype: INT64SLICE, slice: attribute.SliceValue(v)}
|
||||
}
|
||||
|
||||
// Float64Value returns a [Value] for a float64 value.
|
||||
// Float64Value creates a FLOAT64 Value.
|
||||
func Float64Value(v float64) Value {
|
||||
return Value{
|
||||
vtype: FLOAT64,
|
||||
@@ -151,17 +125,12 @@ func Float64Value(v float64) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// Float64SliceValue returns a [Value] for a []float64 value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// Float64SliceValue creates a FLOAT64SLICE Value.
|
||||
func Float64SliceValue(v []float64) Value {
|
||||
return Value{vtype: FLOAT64SLICE, slice: attribute.SliceValue(v)}
|
||||
}
|
||||
|
||||
// StringValue returns a [Value] for a string value.
|
||||
// StringValue creates a STRING Value.
|
||||
func StringValue(v string) Value {
|
||||
return Value{
|
||||
vtype: STRING,
|
||||
@@ -169,22 +138,12 @@ func StringValue(v string) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// StringSliceValue returns a [Value] for a []string value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// StringSliceValue creates a STRINGSLICE Value.
|
||||
func StringSliceValue(v []string) Value {
|
||||
return Value{vtype: STRINGSLICE, slice: attribute.SliceValue(v)}
|
||||
}
|
||||
|
||||
// ByteSliceValue returns a [Value] for a []byte value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// ByteSliceValue creates a BYTESLICE Value.
|
||||
func ByteSliceValue(v []byte) Value {
|
||||
return Value{
|
||||
vtype: BYTESLICE,
|
||||
@@ -192,32 +151,12 @@ func ByteSliceValue(v []byte) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// SliceValue returns a [Value] for a []Value value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
// SliceValue creates a SLICE Value.
|
||||
func SliceValue(v ...Value) Value {
|
||||
return Value{vtype: SLICE, slice: sliceValue(v)}
|
||||
}
|
||||
|
||||
// MapValue returns a [Value] for a []KeyValue value.
|
||||
//
|
||||
// Note that many observability backends are not optimized to query, index, or
|
||||
// aggregate complex attribute values. Complex values may also carry
|
||||
// additional performance overhead. Prefer primitive values when
|
||||
// possible.
|
||||
//
|
||||
// Users should avoid providing duplicate keys; many receivers handle maps
|
||||
// containing duplicate keys unpredictably.
|
||||
//
|
||||
// The order of v is not preserved.
|
||||
func MapValue(v ...KeyValue) Value {
|
||||
return Value{vtype: MAP, slice: mapValue(v)}
|
||||
}
|
||||
|
||||
// Type returns v's type.
|
||||
// Type returns a type of the Value.
|
||||
func (v Value) Type() Type {
|
||||
return v.vtype
|
||||
}
|
||||
@@ -338,53 +277,6 @@ func asValueSliceReflect(v any) []Value {
|
||||
return cpy
|
||||
}
|
||||
|
||||
// AsMap returns the []KeyValue value. Make sure that the Value's type is
|
||||
// MAP.
|
||||
//
|
||||
// The returned slice is sorted by key and may differ from the order
|
||||
// provided when creating the map value.
|
||||
//
|
||||
// The returned slice may contain duplicate keys if duplicate keys were
|
||||
// provided when creating the map value. Callers should not assume the returned
|
||||
// keys are unique.
|
||||
func (v Value) AsMap() []KeyValue {
|
||||
if v.vtype != MAP {
|
||||
return nil
|
||||
}
|
||||
return v.asMap()
|
||||
}
|
||||
|
||||
func (v Value) asMap() []KeyValue {
|
||||
switch vals := v.slice.(type) {
|
||||
case [0]KeyValue:
|
||||
return []KeyValue{}
|
||||
case [1]KeyValue:
|
||||
return []KeyValue{vals[0]}
|
||||
case [2]KeyValue:
|
||||
return []KeyValue{vals[0], vals[1]}
|
||||
case [3]KeyValue:
|
||||
return []KeyValue{vals[0], vals[1], vals[2]}
|
||||
case [4]KeyValue:
|
||||
return []KeyValue{vals[0], vals[1], vals[2], vals[3]}
|
||||
case [5]KeyValue:
|
||||
return []KeyValue{vals[0], vals[1], vals[2], vals[3], vals[4]}
|
||||
default:
|
||||
return asKeyValueSliceReflect(v.slice)
|
||||
}
|
||||
}
|
||||
|
||||
func asKeyValueSliceReflect(v any) []KeyValue {
|
||||
rv := reflect.ValueOf(v)
|
||||
if !rv.IsValid() || rv.Kind() != reflect.Array || rv.Type().Elem() != reflect.TypeFor[KeyValue]() {
|
||||
return nil
|
||||
}
|
||||
cpy := make([]KeyValue, rv.Len())
|
||||
if len(cpy) > 0 {
|
||||
_ = reflect.Copy(reflect.ValueOf(cpy), rv)
|
||||
}
|
||||
return cpy
|
||||
}
|
||||
|
||||
// AsByteSlice returns the bytes value. Make sure that the Value's type
|
||||
// is BYTESLICE.
|
||||
func (v Value) AsByteSlice() []byte {
|
||||
@@ -423,8 +315,6 @@ func (v Value) AsInterface() any {
|
||||
return v.asByteSlice()
|
||||
case SLICE:
|
||||
return v.asSlice()
|
||||
case MAP:
|
||||
return v.asMap()
|
||||
case EMPTY:
|
||||
return nil
|
||||
}
|
||||
@@ -437,10 +327,10 @@ func (v Value) AsInterface() any {
|
||||
// Strings are returned as-is without JSON quoting, booleans and integers use
|
||||
// JSON literals, floating-point values use JSON numbers except that NaN and
|
||||
// ±Inf are rendered as NaN, Infinity, and -Infinity, byte slices are
|
||||
// base64-encoded, empty values are the empty string, slices are encoded as JSON
|
||||
// arrays, and maps are encoded as JSON objects. String, byte, and special
|
||||
// floating-point values inside arrays and maps are encoded as JSON strings, and
|
||||
// empty values inside arrays and maps are encoded as null.
|
||||
// base64-encoded, empty values are the empty string, and slices are encoded as
|
||||
// JSON arrays. String, byte, and special floating-point values inside arrays
|
||||
// are encoded as JSON strings, and empty values inside arrays are encoded as
|
||||
// null.
|
||||
//
|
||||
// [OpenTelemetry AnyValue representation for non-OTLP protocols]: https://opentelemetry.io/docs/specs/otel/common/#anyvalue-representation-for-non-otlp-protocols
|
||||
func (v Value) String() string {
|
||||
@@ -465,8 +355,6 @@ func (v Value) String() string {
|
||||
return formatByteSlice(v.stringly)
|
||||
case SLICE:
|
||||
return formatValueSliceValue(v.slice)
|
||||
case MAP:
|
||||
return formatMapValue(v.slice)
|
||||
case EMPTY:
|
||||
return ""
|
||||
default:
|
||||
@@ -511,8 +399,6 @@ func (v Value) Emit() string {
|
||||
return formatByteSlice(v.stringly)
|
||||
case SLICE:
|
||||
return formatValueSliceValue(v.slice)
|
||||
case MAP:
|
||||
return formatMapValue(v.slice)
|
||||
case EMPTY:
|
||||
return ""
|
||||
default:
|
||||
@@ -553,47 +439,6 @@ func sliceValueReflect(v []Value) any {
|
||||
return cp.Interface()
|
||||
}
|
||||
|
||||
func mapValue(v []KeyValue) any {
|
||||
switch len(v) {
|
||||
case 0:
|
||||
return [0]KeyValue{}
|
||||
case 1:
|
||||
return [1]KeyValue{v[0]}
|
||||
case 2:
|
||||
vals := [2]KeyValue{v[0], v[1]}
|
||||
sortKeyValues(vals[:])
|
||||
return vals
|
||||
case 3:
|
||||
vals := [3]KeyValue{v[0], v[1], v[2]}
|
||||
sortKeyValues(vals[:])
|
||||
return vals
|
||||
case 4:
|
||||
vals := [4]KeyValue{v[0], v[1], v[2], v[3]}
|
||||
sortKeyValues(vals[:])
|
||||
return vals
|
||||
case 5:
|
||||
vals := [5]KeyValue{v[0], v[1], v[2], v[3], v[4]}
|
||||
sortKeyValues(vals[:])
|
||||
return vals
|
||||
default:
|
||||
return mapValueReflect(v)
|
||||
}
|
||||
}
|
||||
|
||||
func mapValueReflect(v []KeyValue) any {
|
||||
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeFor[KeyValue]())).Elem()
|
||||
reflect.Copy(cp, reflect.ValueOf(v))
|
||||
vals := cp.Slice(0, len(v)).Interface().([]KeyValue)
|
||||
sortKeyValues(vals)
|
||||
return cp.Interface()
|
||||
}
|
||||
|
||||
func sortKeyValues(vals []KeyValue) {
|
||||
slices.SortStableFunc(vals, func(a, b KeyValue) int {
|
||||
return cmp.Compare(a.Key, b.Key)
|
||||
})
|
||||
}
|
||||
|
||||
func formatBoolSliceValue(v any) string {
|
||||
switch vals := v.(type) {
|
||||
case [0]bool:
|
||||
@@ -962,37 +807,6 @@ func formatValueSliceReflect(v any) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func formatMapValue(v any) string {
|
||||
switch vals := v.(type) {
|
||||
case [0]KeyValue:
|
||||
return "{}"
|
||||
case [1]KeyValue:
|
||||
return formatMap(vals[:])
|
||||
case [2]KeyValue:
|
||||
return formatMap(vals[:])
|
||||
case [3]KeyValue:
|
||||
return formatMap(vals[:])
|
||||
case [4]KeyValue:
|
||||
return formatMap(vals[:])
|
||||
case [5]KeyValue:
|
||||
return formatMap(vals[:])
|
||||
default:
|
||||
return formatMapReflect(v)
|
||||
}
|
||||
}
|
||||
|
||||
func formatMap(vals []KeyValue) string {
|
||||
var b strings.Builder
|
||||
appendMap(&b, vals)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func formatMapReflect(v any) string {
|
||||
var b strings.Builder
|
||||
appendMapReflect(&b, reflect.ValueOf(v))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func appendValueSliceValue(dst *strings.Builder, v any) {
|
||||
switch vals := v.(type) {
|
||||
case [0]Value:
|
||||
@@ -1038,68 +852,6 @@ func appendValueSliceReflect(dst *strings.Builder, rv reflect.Value) {
|
||||
_ = dst.WriteByte(']')
|
||||
}
|
||||
|
||||
func appendMapValue(dst *strings.Builder, v any) {
|
||||
switch vals := v.(type) {
|
||||
case [0]KeyValue:
|
||||
_, _ = dst.WriteString("{}")
|
||||
case [1]KeyValue:
|
||||
appendMap(dst, vals[:])
|
||||
case [2]KeyValue:
|
||||
appendMap(dst, vals[:])
|
||||
case [3]KeyValue:
|
||||
appendMap(dst, vals[:])
|
||||
case [4]KeyValue:
|
||||
appendMap(dst, vals[:])
|
||||
case [5]KeyValue:
|
||||
appendMap(dst, vals[:])
|
||||
default:
|
||||
appendMapReflect(dst, reflect.ValueOf(v))
|
||||
}
|
||||
}
|
||||
|
||||
func appendMap(dst *strings.Builder, vals []KeyValue) {
|
||||
// Estimate 32 bytes per value for small values, plus key quotes, colon,
|
||||
// and commas. Escaped keys and larger values grow the builder as needed.
|
||||
size := len("{}") + len(vals)*commaLen + len(vals)*32
|
||||
for _, val := range vals {
|
||||
size += len(val.Key) + len(`"":`)
|
||||
}
|
||||
|
||||
dst.Grow(size)
|
||||
_ = dst.WriteByte('{')
|
||||
for i, val := range vals {
|
||||
if i > 0 {
|
||||
_ = dst.WriteByte(',')
|
||||
}
|
||||
appendJSONString(dst, string(val.Key))
|
||||
_ = dst.WriteByte(':')
|
||||
appendJSONValue(dst, val.Value)
|
||||
}
|
||||
_ = dst.WriteByte('}')
|
||||
}
|
||||
|
||||
func appendMapReflect(dst *strings.Builder, rv reflect.Value) {
|
||||
// Estimate 32 bytes per value for small values, plus key quotes, colon,
|
||||
// and commas. Escaped keys and larger values grow the builder as needed.
|
||||
size := len("{}") + rv.Len()*commaLen + rv.Len()*32
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
size += len(rv.Index(i).Field(0).String()) + len(`"":`)
|
||||
}
|
||||
|
||||
dst.Grow(size)
|
||||
_ = dst.WriteByte('{')
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
if i > 0 {
|
||||
_ = dst.WriteByte(',')
|
||||
}
|
||||
val := rv.Index(i).Interface().(KeyValue)
|
||||
appendJSONString(dst, string(val.Key))
|
||||
_ = dst.WriteByte(':')
|
||||
appendJSONValue(dst, val.Value)
|
||||
}
|
||||
_ = dst.WriteByte('}')
|
||||
}
|
||||
|
||||
func appendJSONValue(dst *strings.Builder, v Value) {
|
||||
switch v.Type() {
|
||||
case BOOL:
|
||||
@@ -1142,8 +894,6 @@ func appendJSONValue(dst *strings.Builder, v Value) {
|
||||
_ = dst.WriteByte('"')
|
||||
case SLICE:
|
||||
appendValueSliceValue(dst, v.slice)
|
||||
case MAP:
|
||||
appendMapValue(dst, v.slice)
|
||||
case EMPTY:
|
||||
_, _ = dst.WriteString("null")
|
||||
default:
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package baggage
|
||||
package baggage // import "go.opentelemetry.io/otel/baggage"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package baggage
|
||||
package baggage // import "go.opentelemetry.io/otel/baggage"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ Package baggage provides functionality for storing and retrieving
|
||||
baggage items in Go context. For propagating the baggage, see the
|
||||
go.opentelemetry.io/otel/propagation package.
|
||||
*/
|
||||
package baggage
|
||||
package baggage // import "go.opentelemetry.io/otel/baggage"
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package codes
|
||||
package codes // import "go.opentelemetry.io/otel/codes"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -81,7 +81,7 @@ func (c *Code) UnmarshalJSON(b []byte) error {
|
||||
case float64:
|
||||
if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil {
|
||||
if ci >= maxCode {
|
||||
return fmt.Errorf("invalid code: %d", ci)
|
||||
return fmt.Errorf("invalid code: %q", ci)
|
||||
}
|
||||
|
||||
*c = Code(ci) // nolint: gosec // Bit size of 32 check above.
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ Package codes defines the canonical error codes used by OpenTelemetry.
|
||||
It conforms to [the OpenTelemetry
|
||||
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/api.md#set-status).
|
||||
*/
|
||||
package codes
|
||||
package codes // import "go.opentelemetry.io/otel/codes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
# This is a renovate-friendly source of Docker images.
|
||||
FROM python:3.13.6-slim-bullseye@sha256:e98b521460ee75bca92175c16247bdf7275637a8faaeb2bcfa19d879ae5c4b9a AS python
|
||||
FROM otel/weaver:v0.25.1@sha256:9ad46ca9cd4fa5974b121f886aa3e9946a8ef8ea905001a96c018d21f9db87ca AS weaver
|
||||
FROM otel/weaver:v0.23.0@sha256:7984ecb55b859eb3034ae9d836c4eeda137e2bdd0873b7ba2bb6c3d24d6ff457 AS weaver
|
||||
FROM avtodev/markdown-lint:v1@sha256:6aeedc2f49138ce7a1cd0adffc1b1c0321b841dc2102408967d9301c031949ee AS markdown
|
||||
+1
-1
@@ -22,4 +22,4 @@ To read more about logs, see go.opentelemetry.io/otel/log.
|
||||
To read more about propagation, see go.opentelemetry.io/otel/propagation and
|
||||
go.opentelemetry.io/otel/baggage.
|
||||
*/
|
||||
package otel
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otel
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
// ErrorHandler handles irremediable events.
|
||||
type ErrorHandler interface {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otlptrace
|
||||
package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ See the official OTLP span exporter implementations:
|
||||
- [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc],
|
||||
- [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp].
|
||||
*/
|
||||
package otlptrace
|
||||
package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otlptrace
|
||||
package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -97,9 +97,9 @@ func NewUnstarted(client Client) *Exporter {
|
||||
func (e *Exporter) MarshalLog() any {
|
||||
return struct {
|
||||
Type string
|
||||
Client string
|
||||
Client Client
|
||||
}{
|
||||
Type: "otlptrace",
|
||||
Client: fmt.Sprintf("%T", e.client),
|
||||
Client: e.client,
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+1
-7
@@ -3,7 +3,7 @@
|
||||
|
||||
// Package tracetransform provides conversion functionality for the otlptrace
|
||||
// exporters.
|
||||
package tracetransform
|
||||
package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
|
||||
|
||||
import (
|
||||
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
@@ -97,12 +97,6 @@ func Value(v attribute.Value) *commonpb.AnyValue {
|
||||
Values: values(v.AsSlice()),
|
||||
},
|
||||
}
|
||||
case attribute.MAP:
|
||||
av.Value = &commonpb.AnyValue_KvlistValue{
|
||||
KvlistValue: &commonpb.KeyValueList{
|
||||
Values: KeyValues(v.AsMap()),
|
||||
},
|
||||
}
|
||||
case attribute.STRINGSLICE:
|
||||
av.Value = &commonpb.AnyValue_ArrayValue{
|
||||
ArrayValue: &commonpb.ArrayValue{
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package tracetransform
|
||||
package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
|
||||
|
||||
import (
|
||||
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package tracetransform
|
||||
package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
|
||||
|
||||
import (
|
||||
resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
|
||||
|
||||
Generated
Vendored
+11
-15
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package tracetransform
|
||||
package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
|
||||
|
||||
import (
|
||||
"math"
|
||||
@@ -37,22 +37,21 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans {
|
||||
}
|
||||
|
||||
rKey := sd.Resource().Equivalent()
|
||||
scope := sd.InstrumentationScope()
|
||||
k := key{
|
||||
r: rKey,
|
||||
is: scope,
|
||||
is: sd.InstrumentationScope(),
|
||||
}
|
||||
scopeSpan, iOk := ssm[k]
|
||||
if !iOk {
|
||||
// Either the resource or instrumentation scope were unknown.
|
||||
scopeSpan = &tracepb.ScopeSpans{
|
||||
Scope: InstrumentationScope(scope),
|
||||
Scope: InstrumentationScope(sd.InstrumentationScope()),
|
||||
Spans: []*tracepb.Span{},
|
||||
SchemaUrl: scope.SchemaURL,
|
||||
SchemaUrl: sd.InstrumentationScope().SchemaURL,
|
||||
}
|
||||
ssm[k] = scopeSpan
|
||||
}
|
||||
scopeSpan.Spans = append(scopeSpan.Spans, span(sd))
|
||||
ssm[k] = scopeSpan
|
||||
|
||||
rs, rOk := rsm[rKey]
|
||||
if !rOk {
|
||||
@@ -91,16 +90,14 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span {
|
||||
return nil
|
||||
}
|
||||
|
||||
spanContext := sd.SpanContext()
|
||||
tid := spanContext.TraceID()
|
||||
sid := spanContext.SpanID()
|
||||
tid := sd.SpanContext().TraceID()
|
||||
sid := sd.SpanContext().SpanID()
|
||||
|
||||
sdStatus := sd.Status()
|
||||
s := &tracepb.Span{
|
||||
TraceId: tid[:],
|
||||
SpanId: sid[:],
|
||||
TraceState: spanContext.TraceState().String(),
|
||||
Status: status(sdStatus.Code, sdStatus.Description),
|
||||
TraceState: sd.SpanContext().TraceState().String(),
|
||||
Status: status(sd.Status().Code, sd.Status().Description),
|
||||
StartTimeUnixNano: uint64(max(0, sd.StartTime().UnixNano())), // nolint:gosec // Overflow checked.
|
||||
EndTimeUnixNano: uint64(max(0, sd.EndTime().UnixNano())), // nolint:gosec // Overflow checked.
|
||||
Links: links(sd.Links()),
|
||||
@@ -113,11 +110,10 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span {
|
||||
DroppedLinksCount: clampUint32(sd.DroppedLinks()),
|
||||
}
|
||||
|
||||
sdParent := sd.Parent()
|
||||
if psid := sdParent.SpanID(); psid.IsValid() {
|
||||
if psid := sd.Parent().SpanID(); psid.IsValid() {
|
||||
s.ParentSpanId = psid[:]
|
||||
}
|
||||
s.Flags = buildSpanFlagsWith(spanContext.TraceFlags(), sdParent)
|
||||
s.Flags = buildSpanFlagsWith(sd.SpanContext().TraceFlags(), sd.Parent())
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otlptracegrpc
|
||||
package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -328,10 +328,12 @@ func throttleDelay(s *status.Status) (bool, time.Duration) {
|
||||
}
|
||||
|
||||
// MarshalLog is the marshaling function used by the logging system to represent this Client.
|
||||
func (*client) MarshalLog() any {
|
||||
func (c *client) MarshalLog() any {
|
||||
return struct {
|
||||
Type string
|
||||
Type string
|
||||
Endpoint string
|
||||
}{
|
||||
Type: "otlptracegrpc",
|
||||
Type: "otlptracegrpc",
|
||||
Endpoint: c.endpoint,
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -62,4 +62,4 @@ The configuration can be overridden by [WithTLSCredentials], [WithGRPCConn] opti
|
||||
|
||||
[W3C Baggage HTTP Header Content Format]: https://www.w3.org/TR/baggage/#header-content
|
||||
*/
|
||||
package otlptracegrpc
|
||||
package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
Generated
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package otlptracegrpc
|
||||
package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -1,14 +1,14 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/counter/counter.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/counter/counter.go.tmpl
|
||||
|
||||
// Package counter provides a simple counter for generating unique IDs.
|
||||
//
|
||||
// This package is used to generate unique IDs while allowing testing packages
|
||||
// to reset the counter.
|
||||
package counter
|
||||
package counter // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter"
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
|
||||
Generated
Vendored
+5
-5
@@ -1,12 +1,12 @@
|
||||
// Code generated by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/otlp/envconfig/envconfig.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// DO NOT MODIFY. Generated by gotmpl.
|
||||
// source: internal/shared/otlp/envconfig/envconfig.go.tmpl
|
||||
|
||||
// Package envconfig provides functionality to parse configuration from
|
||||
// environment variables.
|
||||
package envconfig
|
||||
package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig"
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
@@ -60,7 +60,7 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) {
|
||||
func WithBool(n string, fn func(bool)) ConfigFn {
|
||||
return func(e *EnvOptionsReader) {
|
||||
if v, ok := e.GetEnvValue(n); ok {
|
||||
b := strings.EqualFold(v, "true")
|
||||
b := strings.ToLower(v) == "true"
|
||||
fn(b)
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+3
-3
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package internal provides internal functionally for the otlptracegrpc package.
|
||||
package internal
|
||||
package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal"
|
||||
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go
|
||||
@@ -27,8 +27,8 @@ package internal
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc\" }" --out=x/x.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go
|
||||
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\", \"pkg_path\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ\" }" --out=observ/target.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target_test.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target_test.go
|
||||
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={}" --out=counter/counter.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter\" }" --out=counter/counter.go
|
||||
//go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go
|
||||
Generated
Vendored
+1
-1
@@ -3,4 +3,4 @@
|
||||
|
||||
// Package observ provides experimental observability instrumentation for the
|
||||
// otlptracegrpc exporter.
|
||||
package observ
|
||||
package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ"
|
||||
Generated
Vendored
+3
-3
@@ -1,7 +1,7 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package observ
|
||||
package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x"
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.43.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.43.0/otelconv"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.41.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.41.0/otelconv"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Loaded 100 of 298 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user