Implement time for parameter usage

This commit is contained in:
Zoltán Papp
2025-11-17 15:47:27 +01:00
parent 39bec2dd74
commit 938554fb0f
3 changed files with 29 additions and 3 deletions

View File

@@ -1060,7 +1060,9 @@ func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobR
LogFileCount: uint32(params.LogFileCount),
}
uploadKey, err := e.jobExecutor.BundleJob(e.ctx, bundleDeps, bundleJobParams, e.config.ProfileConfig.ManagementURL.String())
waitFor := time.Duration(params.BundleForTime) * time.Minute
uploadKey, err := e.jobExecutor.BundleJob(e.ctx, bundleDeps, bundleJobParams, waitFor, e.config.ProfileConfig.ManagementURL.String())
if err != nil {
return nil, err
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"time"
log "github.com/sirupsen/logrus"
@@ -11,6 +12,10 @@ import (
"github.com/netbirdio/netbird/upload-server/types"
)
const (
MaxBundleWaitTime = 60 * time.Minute // maximum wait time for bundle generation (1 hour)
)
var (
ErrJobNotImplemented = errors.New("job not implemented")
)
@@ -22,8 +27,18 @@ func NewExecutor() *Executor {
return &Executor{}
}
func (e *Executor) BundleJob(ctx context.Context, debugBundleDependencies debug.GeneratorDependencies, params debug.BundleConfig, mgmURL string) (string, error) {
func (e *Executor) BundleJob(ctx context.Context, debugBundleDependencies debug.GeneratorDependencies, params debug.BundleConfig, waitForDuration time.Duration, mgmURL string) (string, error) {
if waitForDuration > MaxBundleWaitTime {
log.Warnf("bundle wait time %v exceeds maximum %v, capping to maximum", waitFor, MaxBundleWaitTime)
waitForDuration = MaxBundleWaitTime
}
if waitForDuration > 0 {
waitFor(ctx, waitForDuration)
}
log.Infof("execute debug bundle generation")
bundleGenerator := debug.NewBundleGenerator(debugBundleDependencies, params)
path, err := bundleGenerator.Generate()
@@ -40,3 +55,12 @@ func (e *Executor) BundleJob(ctx context.Context, debugBundleDependencies debug.
log.Infof("debug bundle has been generated well")
return key, nil
}
func waitFor(ctx context.Context, duration time.Duration) {
log.Infof("wait for %v minutes before executing debug bundle", duration.Minutes())
select {
case <-time.After(duration):
case <-ctx.Done():
log.Infof("wait cancelled: %v", ctx.Err())
}
}

View File

@@ -204,7 +204,7 @@ func (c *GrpcClient) handleJobStream(
continue
}
log.WithContext(ctx).Infof("Received a new job from the management server (ID: %s)", jobReq.ID)
log.WithContext(ctx).Infof("received a new job from the management server (ID: %s)", jobReq.ID)
jobResp := c.processJobRequest(ctx, jobReq, msgHandler)
if err := c.sendJobResponse(ctx, stream, serverPubKey, jobResp); err != nil {
return err