mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-14 17:39:12 +02:00
Implement time for parameter usage
This commit is contained in:
@@ -1060,7 +1060,9 @@ func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobR
|
|||||||
LogFileCount: uint32(params.LogFileCount),
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -11,6 +12,10 @@ import (
|
|||||||
"github.com/netbirdio/netbird/upload-server/types"
|
"github.com/netbirdio/netbird/upload-server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxBundleWaitTime = 60 * time.Minute // maximum wait time for bundle generation (1 hour)
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrJobNotImplemented = errors.New("job not implemented")
|
ErrJobNotImplemented = errors.New("job not implemented")
|
||||||
)
|
)
|
||||||
@@ -22,8 +27,18 @@ func NewExecutor() *Executor {
|
|||||||
return &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")
|
log.Infof("execute debug bundle generation")
|
||||||
|
|
||||||
bundleGenerator := debug.NewBundleGenerator(debugBundleDependencies, params)
|
bundleGenerator := debug.NewBundleGenerator(debugBundleDependencies, params)
|
||||||
|
|
||||||
path, err := bundleGenerator.Generate()
|
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")
|
log.Infof("debug bundle has been generated well")
|
||||||
return key, nil
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ func (c *GrpcClient) handleJobStream(
|
|||||||
continue
|
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)
|
jobResp := c.processJobRequest(ctx, jobReq, msgHandler)
|
||||||
if err := c.sendJobResponse(ctx, stream, serverPubKey, jobResp); err != nil {
|
if err := c.sendJobResponse(ctx, stream, serverPubKey, jobResp); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user