mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-22 03:00:12 +00:00
test(agentcompat): define integration contracts
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ResourceWarmupRuns = 1
|
||||
ResourceSampleCount = 5
|
||||
ResourceSampleInterval = 250 * time.Millisecond
|
||||
ResourceExpectedCountDrift = 0
|
||||
DashboardRSSDeltaBytes uint64 = 64 * 1024 * 1024
|
||||
AgentRSSDeltaBytes uint64 = 32 * 1024 * 1024
|
||||
TransferHeapBytes uint64 = 16 * 1024 * 1024
|
||||
)
|
||||
|
||||
type ResourceBudgetInput struct {
|
||||
WarmupRuns int
|
||||
SampleCount int
|
||||
SampleInterval time.Duration
|
||||
ChildProcessCountDrift int
|
||||
ListenerCountDrift int
|
||||
NonStdioFDCountDrift int
|
||||
DashboardRSSDeltaBytes uint64
|
||||
AgentRSSDeltaBytes uint64
|
||||
TransferHeapBytes uint64
|
||||
}
|
||||
|
||||
type ResourceBudget struct{ input ResourceBudgetInput }
|
||||
|
||||
func NewResourceBudget(input ResourceBudgetInput) (ResourceBudget, error) {
|
||||
if input.WarmupRuns < 1 || input.SampleCount < 1 || input.SampleInterval <= 0 || input.ChildProcessCountDrift < 0 || input.ListenerCountDrift < 0 || input.NonStdioFDCountDrift < 0 || input.DashboardRSSDeltaBytes == 0 || input.AgentRSSDeltaBytes == 0 || input.TransferHeapBytes == 0 {
|
||||
return ResourceBudget{}, errors.New("invalid resource budget")
|
||||
}
|
||||
return ResourceBudget{input: input}, nil
|
||||
}
|
||||
|
||||
func (b ResourceBudget) WarmupRuns() int { return b.input.WarmupRuns }
|
||||
func (b ResourceBudget) SampleCount() int { return b.input.SampleCount }
|
||||
func (b ResourceBudget) SampleInterval() time.Duration { return b.input.SampleInterval }
|
||||
func (b ResourceBudget) ChildProcessCountDrift() int { return b.input.ChildProcessCountDrift }
|
||||
func (b ResourceBudget) ListenerCountDrift() int { return b.input.ListenerCountDrift }
|
||||
func (b ResourceBudget) NonStdioFDCountDrift() int { return b.input.NonStdioFDCountDrift }
|
||||
func (b ResourceBudget) DashboardRSSDeltaBytes() uint64 { return b.input.DashboardRSSDeltaBytes }
|
||||
func (b ResourceBudget) AgentRSSDeltaBytes() uint64 { return b.input.AgentRSSDeltaBytes }
|
||||
func (b ResourceBudget) TransferHeapBytes() uint64 { return b.input.TransferHeapBytes }
|
||||
|
||||
func DefaultResourceBudget() ResourceBudget {
|
||||
return ResourceBudget{input: ResourceBudgetInput{WarmupRuns: ResourceWarmupRuns, SampleCount: ResourceSampleCount, SampleInterval: ResourceSampleInterval, ChildProcessCountDrift: ResourceExpectedCountDrift, ListenerCountDrift: ResourceExpectedCountDrift, NonStdioFDCountDrift: ResourceExpectedCountDrift, DashboardRSSDeltaBytes: DashboardRSSDeltaBytes, AgentRSSDeltaBytes: AgentRSSDeltaBytes, TransferHeapBytes: TransferHeapBytes}}
|
||||
}
|
||||
Reference in New Issue
Block a user