Files
LokiStack/backend/models/log_source.go
T
logan 2d73661dd1 feat: complete Loki query, insights, settings and deployment workflows
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.
2026-10-25 21:28:32 +08:00

58 lines
2.4 KiB
Go

package models
import "time"
// LogSource 日志查询数据源。
// cluster-svc: 经目标集群 kube-apiserver 的 service proxy 访问(无需直通 ClusterIP/DNS),
//
// 覆盖「本平台部署的 Loki」与「接入集群中已有的外部 Loki」两类场景;
//
// url: 直连地址(host-binary 部署或网络可达的 Loki)。
type LogSource struct {
ID uint `json:"id"`
Name string `json:"name"`
TargetType string `json:"targetType"` // cluster-svc | url
ClusterID *uint `json:"clusterID,omitempty"`
Namespace string `json:"namespace"`
Service string `json:"service"`
Port int `json:"port"`
URL string `json:"url"`
AuthType string `json:"authType"` // none | basic | bearer
BasicUser string `json:"basicUser"`
BasicPass string `json:"basicPass"` // ENC: 加密存储,不外发
BearerToken string `json:"bearerToken"`
Headers map[string]string `json:"headers,omitempty"`
SkipTLSVerify bool `json:"skipTLSVerify"`
IsDefault bool `json:"isDefault"`
Managed bool `json:"managed"` // 平台部署自动注册(固定不可编辑)
Access []LogSourceAccess `json:"access,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (s *LogSource) Sanitized() map[string]interface{} {
return map[string]interface{}{
"id": s.ID, "name": s.Name, "targetType": s.TargetType,
"clusterID": s.ClusterID, "namespace": s.Namespace, "service": s.Service, "port": s.Port,
"url": s.URL, "authType": s.AuthType, "basicUser": s.BasicUser,
"hasBasicPass": s.BasicPass != "", "isDefault": s.IsDefault, "managed": s.Managed,
"hasBearerToken": s.BearerToken != "", "headerNames": headerNames(s.Headers), "skipTLSVerify": s.SkipTLSVerify,
"access": s.Access,
"createdAt": s.CreatedAt, "updatedAt": s.UpdatedAt,
}
}
func headerNames(headers map[string]string) []string {
names := make([]string, 0, len(headers))
for name := range headers {
names = append(names, name)
}
return names
}
// LogSourceAccess grants one user access to a source, optionally restricted to exact stream labels.
type LogSourceAccess struct {
UserID uint `json:"userId"`
Labels map[string]string `json:"labels,omitempty"`
}