Skip to content

object: add User-Agent to all storage backends - #6925

Closed
heardbefore wants to merge 2 commits into
juicedata:mainfrom
heardbefore:add-user-agent-to-backends
Closed

object: add User-Agent to all storage backends#6925
heardbefore wants to merge 2 commits into
juicedata:mainfrom
heardbefore:add-user-agent-to-backends

Conversation

@heardbefore

Copy link
Copy Markdown
Contributor

Summary

  • Wire the existing UserAgent variable into all storage backends that were missing it: S3, Qiniu, WebDAV, UFile, TOS (Volcengine), IBM COS, Google Cloud Storage, and Azure Blob Storage
  • Uses each SDK's idiomatic mechanism: aws-sdk-go-v2 middleware, Azure telemetry options, GCS client options, TOS product name option, and direct User-Agent header setting for HTTP-based backends
  • The native B2 backend cannot be covered yet because kothar/go-backblaze does not expose http.Client injection — a TODO comment is added, and an upstream PR has been submitted to unblock this

Motivation

Several backends (BOS, COS, OSS, Storj) already set UserAgent, but the majority — including the S3 backend that covers Backblaze B2's S3-compatible endpoint — did not. This means cloud storage providers cannot identify JuiceFS traffic in access logs.

Setting a User-Agent follows conventions established by rclone, minio-go, and aws-sdk-go, and aligns with Backblaze's integration checklist guidance for integrators. It gives operators version visibility for support and issue triage.

Test plan

  • Build with make juicefs
  • For S3-compatible backends: format and mount a JuiceFS volume against MinIO (docker run -p 9000:9000 minio/minio server /data), perform reads/writes, and verify JuiceFS-<version> appears in mc admin trace output's User-Agent field
  • For other backends: run existing integration tests in pkg/object/*_test.go
  • Verify no regressions in backends that already set UserAgent (BOS, COS, OSS, Storj)

🤖 Generated with Claude Code

Set the JuiceFS UserAgent string on HTTP requests for backends that
were missing it: S3 (covers B2 S3-compatible endpoint), Qiniu, WebDAV,
UFile, TOS, IBM COS, Google Cloud Storage, and Azure Blob Storage.

This allows cloud storage providers to identify JuiceFS traffic in
access logs, following conventions established by rclone, minio-go,
and aws-sdk-go. Uses each SDK's idiomatic mechanism where available
(aws middleware, Azure telemetry options, GCS client options, etc.)
and falls back to direct header setting for HTTP-based backends.

The native B2 backend (kothar/go-backblaze) cannot be covered yet
because the library does not expose http.Client injection — tracked
with a TODO comment for a future follow-up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Apr 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR wires the existing global object.UserAgent string into additional object storage backends so that outbound SDK/HTTP requests consistently include a JuiceFS-identifying User-Agent across providers.

Changes:

  • Add User-Agent injection to AWS SDK v2-based backends (S3, Qiniu) via aws-sdk-go-v2 middleware.
  • Add User-Agent injection to provider SDK clients (Azure Blob telemetry options, GCS client option, TOS SDK option, IBM COS aws-sdk-go-v1 handler).
  • Add User-Agent header to HTTP-based backends (WebDAV, UFile bucket creation request, RestfulStorage requests); add a TODO for B2 native backend.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/object/webdav.go Sets a default User-Agent header on the gowebdav client.
pkg/object/ufile.go Adds User-Agent header to the UFile CreateBucket HTTP request.
pkg/object/tos.go Configures TOS SDK client with UserAgent product name.
pkg/object/s3.go Appends aws-sdk-go-v2 User-Agent middleware to S3 client API options.
pkg/object/restful.go Sets User-Agent header on all requests made through RestfulStorage.
pkg/object/qiniu.go Appends aws-sdk-go-v2 User-Agent middleware to Qiniu’s S3-compatible client options.
pkg/object/ibmcos.go Adds IBM COS (aws-sdk-go-v1) User-Agent handler to the session.
pkg/object/gs.go Creates GCS clients with option.WithUserAgent(UserAgent).
pkg/object/b2.go Documents TODO for native B2 backend pending upstream http.Client injection support.
pkg/object/azure.go Adds shared azblob client options that set telemetry ApplicationID from UserAgent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/object/ufile.go
Comment thread pkg/object/restful.go
Comment on lines +225 to 226
req.Header.Set("User-Agent", UserAgent)
now := time.Now().UTC().Format(http.TimeFormat)

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a global User-Agent header on all requests made via RestfulStorage.request, but there are currently no tests asserting the header is actually sent. Consider adding a unit test (e.g., via httptest.Server) that inspects incoming requests and verifies the User-Agent equals object.UserAgent.

Copilot uses AI. Check for mistakes.
@jiefenghuang

Copy link
Copy Markdown
Contributor

missing some backends like swift\obs

Wire UserAgent into the Swift (OpenStack) and OBS (Huawei) backends
using each SDK's native option: swift.Connection.UserAgent and
obs.WithUserAgent respectively.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jiefenghuang

Copy link
Copy Markdown
Contributor

hi @heardbefore, please resolve conflicts

@zhijian-pro

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

@zhijian-pro

Copy link
Copy Markdown
Contributor

ref #7393

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants