Skip to content

Commit bb458c8

Browse files
committed
Fix issues in the code review
- Set the default values of Origin/Cache_SelfTestInterval - Move self-monitoring.go to xrootd pkg, avoid creating a new pkg - Use filepath.Join to construct the path - Other minor improvements
1 parent 1029bb4 commit bb458c8

5 files changed

Lines changed: 25 additions & 16 deletions

File tree

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ func SetServerDefaults(v *viper.Viper) error {
10421042
v.SetDefault(param.Registry_RequireKeyChaining.GetName(), true)
10431043
v.SetDefault(param.Origin_StorageType.GetName(), "posix")
10441044
v.SetDefault(param.Origin_SelfTest.GetName(), true)
1045+
v.SetDefault(param.Origin_SelfTestInterval.GetName(), 15*time.Second)
1046+
v.SetDefault(param.Cache_SelfTestInterval.GetName(), 15*time.Second)
10451047
v.SetDefault(param.Origin_DirectorTest.GetName(), true)
10461048
// Set up the default S3 URL style to be path-style here as opposed to in the defaults.yaml because
10471049
// we want to be able to check if this is user-provided (which we can't do for defaults.yaml)

launchers/cache_serve.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/pelicanplatform/pelican/lotman"
4141
"github.com/pelicanplatform/pelican/metrics"
4242
"github.com/pelicanplatform/pelican/param"
43-
"github.com/pelicanplatform/pelican/self_monitor"
4443
"github.com/pelicanplatform/pelican/server_structs"
4544
"github.com/pelicanplatform/pelican/server_utils"
4645
"github.com/pelicanplatform/pelican/web_ui"
@@ -109,12 +108,12 @@ func CacheServe(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group, m
109108
cache.LaunchFedTokManager(ctx, egrp, cacheServer)
110109

111110
if param.Cache_SelfTest.GetBool() {
112-
err = self_monitor.InitSelfTestDir()
111+
err = xrootd.InitSelfTestDir()
113112
if err != nil {
114113
return nil, err
115114
}
116115

117-
self_monitor.PeriodicSelfTest(ctx, egrp, false)
116+
xrootd.PeriodicSelfTest(ctx, egrp, false)
118117
}
119118

120119
// Director and origin also registers this metadata URL; avoid registering twice.

launchers/origin_serve.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"github.com/pelicanplatform/pelican/oa4mp"
4040
"github.com/pelicanplatform/pelican/origin"
4141
"github.com/pelicanplatform/pelican/param"
42-
"github.com/pelicanplatform/pelican/self_monitor"
4342
"github.com/pelicanplatform/pelican/server_structs"
4443
"github.com/pelicanplatform/pelican/server_utils"
4544
"github.com/pelicanplatform/pelican/web_ui"
@@ -110,7 +109,7 @@ func OriginServe(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group,
110109
}
111110

112111
if param.Origin_SelfTest.GetBool() {
113-
self_monitor.PeriodicSelfTest(ctx, egrp, true)
112+
xrootd.PeriodicSelfTest(ctx, egrp, true)
114113
}
115114

116115
privileged := param.Origin_Multiuser.GetBool()

xrootd/launch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/pelicanplatform/pelican/config"
4040
"github.com/pelicanplatform/pelican/daemon"
4141
"github.com/pelicanplatform/pelican/param"
42+
"github.com/pelicanplatform/pelican/server_utils"
4243
)
4344

4445
type (
@@ -159,9 +160,9 @@ func makeUnprivilegedXrootdLauncher(daemonName string, configPath string, isCach
159160
result.ExtraEnv = append(result.ExtraEnv, "XRDHTTP_PELICAN_CERT_FILE="+filepath.Join(xrootdRun, "copied-tls-creds.crt"))
160161
result.ExtraEnv = append(result.ExtraEnv, "XRDHTTP_PELICAN_INFO_FD="+strconv.Itoa(result.fds[1]))
161162

162-
basePath := param.Cache_NamespaceLocation.GetString() + "/pelican/monitoring/selfTest"
163-
testFileLocation := basePath + "/self-test-cache-server.txt"
164-
testFileCinfoLocation := basePath + "/self-test-cache-server.txt.cinfo"
163+
basePath := filepath.Join(param.Cache_NamespaceLocation.GetString(), server_utils.MonitoringBaseNs, "selfTest")
164+
testFileLocation := filepath.Join(basePath, "self-test-cache-server.txt")
165+
testFileCinfoLocation := filepath.Join(basePath, "self-test-cache-server.txt.cinfo")
165166
result.ExtraEnv = append(result.ExtraEnv, "XRDHTTP_PELICAN_CACHE_SELF_TEST_FILE="+testFileLocation)
166167
result.ExtraEnv = append(result.ExtraEnv, "XRDHTTP_PELICAN_CACHE_SELF_TEST_FILE_CINFO="+testFileCinfoLocation)
167168
}
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
***************************************************************/
1818

19-
package self_monitor
19+
package xrootd
2020

2121
import (
2222
"context"
@@ -41,7 +41,6 @@ import (
4141
"github.com/pelicanplatform/pelican/server_utils"
4242
"github.com/pelicanplatform/pelican/token"
4343
"github.com/pelicanplatform/pelican/token_scopes"
44-
"github.com/pelicanplatform/pelican/xrootd"
4544
)
4645

4746
const (
@@ -179,7 +178,7 @@ func generateTestFileViaPlugin() (string, error) {
179178
selfTestBirthplace := filepath.Join(param.Monitoring_DataLocation.GetString(), "selfTest")
180179
err = config.MkdirAll(selfTestBirthplace, 0750, user.Uid, user.Gid)
181180
if err != nil {
182-
return "", errors.Wrap(err, "failed to create selftest directory")
181+
return "", errors.Wrap(err, "failed to create self-test directory")
183182
}
184183

185184
// Create a test file and its cinfo in the birthplace
@@ -234,11 +233,15 @@ func generateTestFileViaPlugin() (string, error) {
234233
return "", errors.Wrap(err, "failed to seek to beginning of cinfo file")
235234
}
236235

237-
// Transplant the test file and cinfo from birthplace to the selfTestDir via xrdhttp-pelican plugin
238-
if err = xrootd.SelfTestFileCopy(4, file); err != nil {
236+
// Transplant the test file to selfTestDir using the xrdhttp-pelican plugin.
237+
// Command "4" instructs the plugin to put the test file into the designated location, which is specified in `xrootd/launch.go`.
238+
// Check `src/XrdHttpPelican.cc` in https://github.com/PelicanPlatform/xrdhttp-pelican for the counterpart in the plugin.
239+
if err = SelfTestFileCopy(4, file); err != nil {
239240
return "", errors.Wrap(err, "failed to copy the test file to the self-test directory")
240241
}
241-
if err = xrootd.SelfTestFileCopy(5, cinfoFile); err != nil {
242+
// Transplant the cinfo file to selfTestDir using the xrdhttp-pelican plugin.
243+
// Command "5" instructs the plugin to put the cinfo file into the designated location, which is specified in `xrootd/launch.go`.
244+
if err = SelfTestFileCopy(5, cinfoFile); err != nil {
242245
return "", errors.Wrap(err, "failed to copy the test cinfo file to the self-test directory")
243246
}
244247

@@ -418,9 +421,14 @@ func PeriodicSelfTest(ctx context.Context, ergp *errgroup.Group, isOrigin bool)
418421
customInterval = param.Origin_SelfTestInterval.GetDuration()
419422
}
420423

421-
if customInterval == 0 {
424+
// Fallback to a 15s interval, if the user sets a very small or negative interval
425+
if customInterval < 1*time.Second {
422426
customInterval = 15 * time.Second
423-
log.Error("Invalid config value: both Origin.SelfTestInterval and Cache.SelfTestInterval are 0. Fallback to 15s.")
427+
serverType := "Cache"
428+
if isOrigin {
429+
serverType = "Origin"
430+
}
431+
log.Warningf("Invalid config value: %s.SelfTestInterval. Fallback to 15s.", serverType)
424432
}
425433
ticker := time.NewTicker(customInterval)
426434
firstRound := time.After(5 * time.Second)

0 commit comments

Comments
 (0)