Skip to content

Commit cb552f3

Browse files
committed
Review param usage in client_agent
1 parent e03808a commit cb552f3

9 files changed

Lines changed: 49 additions & 50 deletions

File tree

client_agent/apiclient/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"testing"
3030
"time"
3131

32-
"github.com/spf13/viper"
3332
"github.com/stretchr/testify/assert"
3433
"github.com/stretchr/testify/require"
3534

@@ -72,7 +71,8 @@ func setupTestEnvironment(t *testing.T) (apiClient *apiclient.APIClient, fed *fe
7271

7372
// Create token for authenticated operations
7473
t.Log("setupTestEnvironment: Creating token")
75-
viper.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
74+
err := param.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
75+
require.NoError(t, err)
7676
issuer, err := config.GetServerIssuerURL()
7777
require.NoError(t, err)
7878

client_agent/cli_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"time"
3535

3636
log "github.com/sirupsen/logrus"
37-
"github.com/spf13/viper"
3837
"github.com/stretchr/testify/assert"
3938
"github.com/stretchr/testify/require"
4039

@@ -98,7 +97,8 @@ func TestCLIAsyncGet(t *testing.T) {
9897
tempDir := t.TempDir()
9998

10099
// Create token
101-
viper.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
100+
err := param.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
101+
require.NoError(t, err)
102102
issuer, err := config.GetServerIssuerURL()
103103
require.NoError(t, err)
104104

@@ -234,7 +234,8 @@ func TestCLIAsyncPut(t *testing.T) {
234234

235235
// Create token
236236
tokenStart := time.Now()
237-
viper.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
237+
err := param.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
238+
require.NoError(t, err)
238239
issuer, err := config.GetServerIssuerURL()
239240
require.NoError(t, err)
240241

@@ -348,7 +349,8 @@ func TestCLIJobCommands(t *testing.T) {
348349
tempDir := t.TempDir()
349350

350351
// Create token
351-
viper.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
352+
err := param.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
353+
require.NoError(t, err)
352354
issuer, err := config.GetServerIssuerURL()
353355
require.NoError(t, err)
354356

client_agent/integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"testing"
3636
"time"
3737

38-
"github.com/spf13/viper"
3938
"github.com/stretchr/testify/assert"
4039
"github.com/stretchr/testify/require"
4140

@@ -115,7 +114,8 @@ func TestClientAPIIntegration(t *testing.T) {
115114
require.NoError(t, err)
116115

117116
// Create token for authenticated operations
118-
viper.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
117+
err = param.Set(param.IssuerKeysDirectory.GetName(), t.TempDir())
118+
require.NoError(t, err)
119119
issuer, err := config.GetServerIssuerURL()
120120
require.NoError(t, err)
121121

client_agent/server.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import (
3030
"github.com/gin-gonic/gin"
3131
"github.com/pkg/errors"
3232
log "github.com/sirupsen/logrus"
33+
34+
"github.com/pelicanplatform/pelican/param"
3335
)
3436

3537
const (
36-
DefaultSocketPath = "~/.pelican/client-api.sock"
37-
DefaultPidFile = "~/.pelican/client-api.pid"
38-
DefaultMaxConcurrentJobs = 5
39-
DefaultShutdownTimeout = 30 * time.Second
38+
DefaultSocketPath = "~/.pelican/client-api.sock"
39+
DefaultPidFile = "~/.pelican/client-api.pid"
40+
DefaultShutdownTimeout = 30 * time.Second
4041
)
4142

4243
// Server represents the client API server
@@ -126,9 +127,15 @@ func NewServer(config ServerConfig) (*Server, error) {
126127
}
127128

128129
// Create transfer manager
130+
// Use config value if provided, otherwise fall back to parameter
129131
maxJobs := config.MaxConcurrentJobs
130132
if maxJobs <= 0 {
131-
maxJobs = DefaultMaxConcurrentJobs
133+
providedValue := maxJobs
134+
maxJobs = param.ClientAgent_MaxConcurrentJobs.GetInt()
135+
if maxJobs <= 0 {
136+
log.Warnf("Invalid max concurrent jobs configuration (provided=%d, param=%d), using default value of 5", providedValue, maxJobs)
137+
maxJobs = 5 // Final fallback
138+
}
132139
}
133140
transferManager := NewTransferManager(ctx, maxJobs, storeInstance)
134141

client_agent/transfer_manager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
log "github.com/sirupsen/logrus"
2929

3030
"github.com/pelicanplatform/pelican/client"
31+
"github.com/pelicanplatform/pelican/param"
3132
)
3233

3334
// Transfer represents an individual file transfer
@@ -81,6 +82,16 @@ type TransferManager struct {
8182
func NewTransferManager(ctx context.Context, maxConcurrentJobs int, store StoreInterface) *TransferManager {
8283
managerCtx, cancel := context.WithCancel(ctx)
8384

85+
// Use parameter value if maxConcurrentJobs is not positive
86+
if maxConcurrentJobs <= 0 {
87+
providedValue := maxConcurrentJobs
88+
maxConcurrentJobs = param.ClientAgent_MaxConcurrentJobs.GetInt()
89+
if maxConcurrentJobs <= 0 {
90+
log.Warnf("Invalid max concurrent jobs configuration (provided=%d, param=%d), using default value of 5", providedValue, maxConcurrentJobs)
91+
maxConcurrentJobs = 5 // Final fallback
92+
}
93+
}
94+
8495
tm := &TransferManager{
8596
jobs: make(map[string]*TransferJob),
8697
transfers: make(map[string]*Transfer),

cmd/client_agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ func init() {
233233
"Path to the PID file")
234234

235235
// Serve-specific flags
236-
clientAgentServeCmd.Flags().IntVar(&clientAgentMaxJobs, "max-jobs", client_agent.DefaultMaxConcurrentJobs,
237-
"Maximum number of concurrent transfer jobs")
236+
clientAgentServeCmd.Flags().IntVar(&clientAgentMaxJobs, "max-jobs", 0,
237+
"Maximum number of concurrent transfer jobs (default: uses ClientAgent.MaxConcurrentJobs parameter, or 5)")
238238
clientAgentServeCmd.Flags().StringVar(&clientAgentDbPath, "database", "",
239239
"Path to the SQLite database file for persistence (default: ~/.pelican/client-api.db)")
240240

docs/parameters.yaml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,6 @@ type: filename
693693
default: $ConfigBase/client-api.db
694694
components: ["client"]
695695
---
696-
name: ClientAgent.EnableAutoRecovery
697-
description: |+
698-
A boolean indicating whether the client API server should automatically attempt
699-
to recover incomplete jobs from the database on startup. When enabled, interrupted
700-
jobs will be marked as failed and archived to history.
701-
702-
Disabling this may be useful for debugging or when manual recovery is preferred.
703-
type: bool
704-
default: true
705-
components: ["client"]
706-
---
707696
name: ClientAgent.HistoryRetentionDays
708697
description: |+
709698
The number of days to retain completed job history in the database before
@@ -715,16 +704,15 @@ type: int
715704
default: 30
716705
components: ["client"]
717706
---
718-
name: ClientAgent.MaxConnections
707+
name: ClientAgent.MaxConcurrentJobs
719708
description: |+
720-
The maximum number of concurrent database connections allowed by the client API
721-
server's SQLite connection pool. This limits resource usage but may impact
722-
performance under high load.
709+
The maximum number of concurrent transfer jobs that the client API server
710+
can process simultaneously. This limits resource usage and prevents overwhelming
711+
the system with too many parallel transfers.
723712
724-
Increase this value if you experience database lock contention or timeouts
725-
with many concurrent API requests.
713+
Set to 0 or negative to use the default value (5).
726714
type: int
727-
default: 10
715+
default: 5
728716
components: ["client"]
729717
---
730718
name: ClientAgent.Socket
@@ -733,9 +721,7 @@ description: |+
733721
inter-process communication. Clients connect to this socket to submit transfer
734722
jobs and query their status.
735723
736-
If not specified, the default location is used based on the platform and user
737-
permissions. This parameter allows overriding the default location for testing
738-
or custom deployment scenarios.
724+
If not specified, the default location is `~/.pelican/client-api.db`.
739725
type: filename
740726
default: ""
741727
components: ["client"]

param/parameters.go

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

param/parameters_struct.go

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)