feat: 完整游戏运维功能
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
// MetricSample is a bounded, platform-owned observation for one server instance.
|
||||
type MetricSample struct {
|
||||
ID string
|
||||
ServerInstanceID string
|
||||
RunEndpointID string
|
||||
Online bool
|
||||
PlayerCount *int
|
||||
MaxPlayers *int
|
||||
TPS *float64
|
||||
LatencyMS *float64
|
||||
CPUPercent *float64
|
||||
MemoryPercent *float64
|
||||
DiskPercent *float64
|
||||
Source string
|
||||
CollectedAt time.Time
|
||||
}
|
||||
|
||||
type MetricSampleFilter struct {
|
||||
ServerInstanceID string
|
||||
After time.Time
|
||||
Before time.Time
|
||||
Limit int
|
||||
}
|
||||
|
||||
type MetricBatchIngest struct {
|
||||
RunEndpointID string
|
||||
SessionToken string
|
||||
Samples []MetricSample
|
||||
}
|
||||
|
||||
type MetricBatchIngestResult struct {
|
||||
Accepted bool
|
||||
AcceptedCount int
|
||||
LatestAt time.Time
|
||||
ServerTime time.Time
|
||||
}
|
||||
|
||||
type BackupState string
|
||||
|
||||
const (
|
||||
BackupStatePending BackupState = "pending"
|
||||
BackupStateAvailable BackupState = "available"
|
||||
BackupStateFailed BackupState = "failed"
|
||||
BackupStateExpired BackupState = "expired"
|
||||
)
|
||||
|
||||
type BackupRecord struct {
|
||||
ID string
|
||||
ServerInstanceID string
|
||||
ArtifactID string
|
||||
Checksum string
|
||||
SizeBytes int64
|
||||
State BackupState
|
||||
RecoveryStatus string
|
||||
RetentionUntil time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type BackupFilter struct {
|
||||
ServerInstanceID string
|
||||
State BackupState
|
||||
}
|
||||
|
||||
type RemoteAdapterKind string
|
||||
|
||||
const (
|
||||
RemoteAdapterFTP RemoteAdapterKind = "ftp"
|
||||
RemoteAdapterRsync RemoteAdapterKind = "rsync"
|
||||
RemoteAdapterRunFile RemoteAdapterKind = "run-file"
|
||||
RemoteAdapterRunProcess RemoteAdapterKind = "run-process"
|
||||
RemoteAdapterDatabase RemoteAdapterKind = "database"
|
||||
RemoteAdapterRCON RemoteAdapterKind = "rcon"
|
||||
)
|
||||
|
||||
type RemoteAdapterDeclaration struct {
|
||||
Key string
|
||||
Kind RemoteAdapterKind
|
||||
TargetKeys []string
|
||||
Capabilities []string
|
||||
TimeoutSeconds int
|
||||
MaxAttempts int
|
||||
}
|
||||
|
||||
type RemoteAdapterRequest struct {
|
||||
ServerInstanceID string
|
||||
DeclarationKey string
|
||||
TargetKey string
|
||||
Capability string
|
||||
TimeoutSeconds int
|
||||
MaxAttempts int
|
||||
IdempotencyKey string
|
||||
}
|
||||
|
||||
type RemoteAdapterResult struct {
|
||||
RequestID string
|
||||
ServerInstanceID string
|
||||
DeclarationKey string
|
||||
TargetKey string
|
||||
Kind RemoteAdapterKind
|
||||
Status string
|
||||
Retryable bool
|
||||
Message string
|
||||
ResultRef string
|
||||
AuditEventID string
|
||||
CompletedAt time.Time
|
||||
}
|
||||
|
||||
func CopyMetricSample(sample MetricSample) MetricSample {
|
||||
sample.PlayerCount = copyIntPtr(sample.PlayerCount)
|
||||
sample.MaxPlayers = copyIntPtr(sample.MaxPlayers)
|
||||
sample.TPS = copyFloatPtr(sample.TPS)
|
||||
sample.LatencyMS = copyFloatPtr(sample.LatencyMS)
|
||||
sample.CPUPercent = copyFloatPtr(sample.CPUPercent)
|
||||
sample.MemoryPercent = copyFloatPtr(sample.MemoryPercent)
|
||||
sample.DiskPercent = copyFloatPtr(sample.DiskPercent)
|
||||
return sample
|
||||
}
|
||||
|
||||
func copyIntPtr(value *int) *int {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
copy := *value
|
||||
return ©
|
||||
}
|
||||
|
||||
func copyFloatPtr(value *float64) *float64 {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
copy := *value
|
||||
return ©
|
||||
}
|
||||
|
||||
func CopyMetricSamples(samples []MetricSample) []MetricSample {
|
||||
if samples == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]MetricSample, len(samples))
|
||||
for i, sample := range samples {
|
||||
out[i] = CopyMetricSample(sample)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func CopyMetricBatchIngest(batch MetricBatchIngest) MetricBatchIngest {
|
||||
batch.Samples = CopyMetricSamples(batch.Samples)
|
||||
return batch
|
||||
}
|
||||
|
||||
func CopyBackupRecord(record BackupRecord) BackupRecord { return record }
|
||||
|
||||
func CopyBackupRecords(records []BackupRecord) []BackupRecord {
|
||||
if records == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]BackupRecord, len(records))
|
||||
copy(out, records)
|
||||
return out
|
||||
}
|
||||
|
||||
func CopyRemoteAdapterDeclaration(declaration RemoteAdapterDeclaration) RemoteAdapterDeclaration {
|
||||
declaration.TargetKeys = CopyStringSlice(declaration.TargetKeys)
|
||||
declaration.Capabilities = CopyStringSlice(declaration.Capabilities)
|
||||
return declaration
|
||||
}
|
||||
|
||||
func CopyRemoteAdapterDeclarations(declarations []RemoteAdapterDeclaration) []RemoteAdapterDeclaration {
|
||||
if declarations == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]RemoteAdapterDeclaration, len(declarations))
|
||||
for i, declaration := range declarations {
|
||||
out[i] = CopyRemoteAdapterDeclaration(declaration)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func CopyRemoteAdapterRequest(request RemoteAdapterRequest) RemoteAdapterRequest { return request }
|
||||
func CopyRemoteAdapterResult(result RemoteAdapterResult) RemoteAdapterResult { return result }
|
||||
Reference in New Issue
Block a user