Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application. Validated with go test ./..., npm run build, and npm run lint.
97 lines
3.4 KiB
Go
97 lines
3.4 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type LokiDeployment struct {
|
|
ID uint `json:"id"`
|
|
UUID string `json:"uuid"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Version string `json:"version"`
|
|
Mode string `json:"mode"`
|
|
ClusterID *uint `json:"clusterID,omitempty"`
|
|
Cluster *Cluster `json:"cluster,omitempty"`
|
|
HostID *uint `json:"hostID,omitempty"`
|
|
Host *Host `json:"host,omitempty"`
|
|
ListenIP string `json:"listenIP,omitempty"`
|
|
ListenPort int `json:"listenPort,omitempty"`
|
|
Namespace string `json:"namespace"`
|
|
StorageConfigID uint `json:"storageConfigID"`
|
|
StorageConfig *StorageConfig `json:"storageConfig,omitempty"`
|
|
AuthEnabled bool `json:"authEnabled"`
|
|
RetentionDays int `json:"retentionDays"`
|
|
Replicas int `json:"replicas"`
|
|
ResourcesCPU string `json:"resourcesCPU"`
|
|
ResourcesMem string `json:"resourcesMem"`
|
|
StorageSize string `json:"storageSize"`
|
|
GrafanaEnabled bool `json:"grafanaEnabled"`
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
GrafanaPort int `json:"grafanaPort"`
|
|
GrafanaEndpoint string `json:"grafanaEndpoint"`
|
|
Status string `json:"status"`
|
|
StatusMessage string `json:"statusMessage"`
|
|
HelmValues string `json:"helmValues"`
|
|
Endpoint string `json:"endpoint"`
|
|
AdminUser string `json:"adminUser"`
|
|
AdminPassword string `json:"adminPassword"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
}
|
|
|
|
func (d *LokiDeployment) BeforeCreate() {
|
|
if d.UUID == "" {
|
|
d.UUID = uuid.New().String()
|
|
}
|
|
}
|
|
|
|
// Sanitized 返回去除敏感字段(AdminPassword)的部署视图,并对嵌套的
|
|
// Cluster/Host/StorageConfig 一并做脱敏,避免经部署接口泄漏各自凭证。
|
|
func (d *LokiDeployment) Sanitized() map[string]interface{} {
|
|
out := map[string]interface{}{
|
|
"id": d.ID,
|
|
"uuid": d.UUID,
|
|
"name": d.Name,
|
|
"description": d.Description,
|
|
"version": d.Version,
|
|
"mode": d.Mode,
|
|
"clusterID": d.ClusterID,
|
|
"hostID": d.HostID,
|
|
"listenIP": d.ListenIP,
|
|
"listenPort": d.ListenPort,
|
|
"namespace": d.Namespace,
|
|
"storageConfigID": d.StorageConfigID,
|
|
"authEnabled": d.AuthEnabled,
|
|
"retentionDays": d.RetentionDays,
|
|
"replicas": d.Replicas,
|
|
"resourcesCPU": d.ResourcesCPU,
|
|
"resourcesMem": d.ResourcesMem,
|
|
"storageSize": d.StorageSize,
|
|
"grafanaEnabled": d.GrafanaEnabled,
|
|
"grafanaVersion": d.GrafanaVersion,
|
|
"grafanaPort": d.GrafanaPort,
|
|
"grafanaEndpoint": d.GrafanaEndpoint,
|
|
"status": d.Status,
|
|
"statusMessage": d.StatusMessage,
|
|
"helmValues": d.HelmValues,
|
|
"endpoint": d.Endpoint,
|
|
"adminUser": d.AdminUser,
|
|
// AdminPassword 故意省略
|
|
"createdAt": d.CreatedAt,
|
|
"updatedAt": d.UpdatedAt,
|
|
}
|
|
if d.Cluster != nil {
|
|
out["cluster"] = d.Cluster.Sanitized()
|
|
}
|
|
if d.Host != nil {
|
|
out["host"] = d.Host.Sanitized()
|
|
}
|
|
if d.StorageConfig != nil {
|
|
out["storageConfig"] = d.StorageConfig.Sanitized()
|
|
}
|
|
return out
|
|
}
|