package models import "time" // Collector 日志采集器(部署客户端),关联一个已部署的 Loki 作为推送目标 type Collector struct { ID uint `json:"id"` Name string `json:"name"` Type string `json:"type"` // host-promtail | k8s-daemonset | k8s-fluentbit-sidecar LokiDeploymentID uint `json:"lokiDeploymentID"` LokiDeployment *LokiDeployment `json:"lokiDeployment,omitempty"` RefType string `json:"refType"` // host | cluster HostID *uint `json:"hostID,omitempty"` Host *Host `json:"host,omitempty"` ClusterID *uint `json:"clusterID,omitempty"` Cluster *Cluster `json:"cluster,omitempty"` TargetDeployment string `json:"targetDeployment"` // sidecar 专用:目标 deployment 名 Namespace string `json:"namespace"` // k8s 命名空间(默认 logging) LogPath string `json:"logPath"` // 采集日志路径 Labels string `json:"labels"` // 额外标签(JSON) Status string `json:"status"` // pending | active | error StatusMessage string `json:"statusMessage"` Config string `json:"config"` // 生成的配置快照 CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } func (c *Collector) Sanitized() map[string]interface{} { var loki map[string]interface{} if c.LokiDeployment != nil { loki = map[string]interface{}{ "id": c.LokiDeployment.ID, "name": c.LokiDeployment.Name, "endpoint": c.LokiDeployment.Endpoint, "status": c.LokiDeployment.Status, } } var host map[string]interface{} if c.Host != nil { host = c.Host.Sanitized() } var cluster map[string]interface{} if c.Cluster != nil { cluster = c.Cluster.Sanitized() } return map[string]interface{}{ "id": c.ID, "name": c.Name, "type": c.Type, "lokiDeploymentID": c.LokiDeploymentID, "lokiDeployment": loki, "refType": c.RefType, "hostID": c.HostID, "host": host, "clusterID": c.ClusterID, "cluster": cluster, "targetDeployment": c.TargetDeployment, "namespace": c.Namespace, "logPath": c.LogPath, "labels": c.Labels, "status": c.Status, "statusMessage": c.StatusMessage, "createdAt": c.CreatedAt, "updatedAt": c.UpdatedAt, } }