Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bcs-monitor rest 泛型优化 #3681

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions bcs-services/bcs-monitor/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Tencent/bk-bcs/bcs-services/bcs-monitor

go 1.23
go 1.23.0

require (
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20241225073847-71cfc38de294
Expand All @@ -9,10 +9,10 @@ require (
github.com/chonla/format v0.0.0-20220105105701-1119f4a3f36f
github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.6.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/requestid v0.0.4
github.com/ggicci/httpin v0.19.0
github.com/gin-contrib/sse v0.1.0
github.com/gin-gonic/gin v1.9.1
github.com/go-chi/chi/v5 v5.0.11
github.com/go-chi/render v1.0.3
github.com/go-kit/log v0.2.1
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-redis/redis/v8 v8.11.5
Expand All @@ -36,14 +36,14 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2
github.com/swaggo/gin-swagger v1.4.3
github.com/swaggo/http-swagger v1.3.4
github.com/swaggo/swag v1.8.1
github.com/thanos-io/thanos v0.26.0
go-micro.dev/v4 v4.10.2
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.44.0
go.opentelemetry.io/otel/metric v1.18.0
go.uber.org/automaxprocs v1.5.1
golang.org/x/sync v0.6.0
golang.org/x/sync v0.11.0
google.golang.org/grpc v1.62.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -59,20 +59,18 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.6 // indirect
github.com/TencentBlueKing/gopkg v1.1.0 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.0 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/frankban/quicktest v1.14.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/ggicci/owl v0.8.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-migrate/migrate/v4 v4.17.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
Expand All @@ -81,16 +79,20 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/labstack/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/openzipkin/zipkin-go v0.3.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand All @@ -101,9 +103,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.3.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/arch v0.6.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
Expand Down Expand Up @@ -185,7 +185,6 @@ require (
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743 // indirect
github.com/lightstep/lightstep-tracer-go v0.18.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -212,7 +211,7 @@ require (
github.com/subosito/gotenv v1.4.1 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/vimeo/galaxycache v0.0.0-20210323154928-b7e5d71c067a // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
Expand All @@ -232,18 +231,18 @@ require (
go.opentelemetry.io/otel/trace v1.18.0
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.2.1 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/api v0.150.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -266,10 +265,10 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/go-playground/validator/v10 v10.25.0
github.com/mailru/easyjson v0.7.7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/urfave/cli/v2 v2.8.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
Expand All @@ -287,4 +286,5 @@ replace (
github.com/vimeo/galaxycache => github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e
// from github.com/thanos-io/thanos
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0
go.opentelemetry.io/otel/metric => go.opentelemetry.io/otel/metric v0.38.0
)
35 changes: 32 additions & 3 deletions bcs-services/bcs-monitor/pkg/api/logrule/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
"encoding/json"
"fmt"
"net/url"
"regexp"
"strings"

"github.com/Tencent/bk-bcs/bcs-common/common/blog"
"github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator"
"github.com/pkg/errors"

bklog "github.com/Tencent/bk-bcs/bcs-services/bcs-monitor/pkg/component/bk_log"
"github.com/Tencent/bk-bcs/bcs-services/bcs-monitor/pkg/config"
Expand All @@ -36,6 +38,19 @@ const (
bkLogPrefix = "bklog|"
)

// ListLogCollectorsReq list log collectors request
type ListLogCollectorsReq struct {
ProjectId string `json:"projectId" in:"path=projectId" validate:"required"`
ClusterId string `json:"clusterId" in:"path=clusterId" validate:"required"`
}

// GetLogRuleReq get log rule request
type GetLogRuleReq struct {
ProjectId string `json:"projectId" in:"path=projectId" validate:"required"`
ClusterId string `json:"clusterId" in:"path=clusterId" validate:"required"`
ID string `json:"id" in:"path=id" validate:"required"`
}

// GetLogRuleResp log rule resp
type GetLogRuleResp struct {
ID string `json:"id"`
Expand Down Expand Up @@ -104,14 +119,25 @@ func (l GetLogRuleRespSortByStatus) Swap(i, j int) { l[i], l[j] = l[j], l[i] }

// CreateLogRuleReq req
type CreateLogRuleReq struct {
ProjectId string `json:"projectId" in:"path=projectId" validate:"required"`
ClusterId string `json:"clusterId" in:"path=clusterId" validate:"required"`
DisplayName string `json:"display_name" form:"display_name"`
Name string `json:"name" form:"name" binding:"required" validate:"max=30,min=5,regexp=^[A-Za-z0-9_]+$"`
Name string `json:"name" form:"name" binding:"required" validate:"required,max=30,min=5"`
RuleName string `json:"-" form:"-"`
Description string `json:"description"`
Rule bklog.LogRule `json:"rule"`
FromRule string `json:"from_rule"`
}

// Validate CreateLogRuleReq validate
func (req *CreateLogRuleReq) Validate() error {
nameRegexp := regexp.MustCompile(`^[A-Za-z0-9_]+$`)
if !nameRegexp.MatchString(req.Name) {
return errors.New("name is invalid: " + req.Name)
}
return nil
}

// toEntity convert to entity.LogRule
func (req *CreateLogRuleReq) toEntity(c *rest.Context) *entity.LogRule {
if req.DisplayName == "" {
Expand Down Expand Up @@ -158,6 +184,9 @@ func (req *CreateLogRuleReq) toBKLog(c *rest.Context) *bklog.CreateBCSCollectorR

// UpdateLogRuleReq req
type UpdateLogRuleReq struct {
ProjectId string `json:"projectId" in:"path=projectId" validate:"required"`
ClusterId string `json:"clusterId" in:"path=clusterId" validate:"required"`
ID string `json:"id" in:"path=id" validate:"required"`
DisplayName string `json:"display_name" form:"display_name"`
Description string `json:"description"`
Rule bklog.LogRule `json:"rule"`
Expand Down Expand Up @@ -356,7 +385,7 @@ func getBkLogDeleteMessage(isFileDeleted, isSTDDeleted bool, originMessage strin
}

// getContainerQueryLogLinks get container query log links
func getContainerQueryLogLinks(containerIDs []string, projectCode, clusterID string) map[string]Entrypoint {
func getContainerQueryLogLinks(containerIDs []string, projectCode, clusterID string) *map[string]Entrypoint {
result := make(map[string]Entrypoint, 0)
type addition struct {
Field string `json:"field"`
Expand All @@ -377,7 +406,7 @@ func getContainerQueryLogLinks(containerIDs []string, projectCode, clusterID str
FileLogURL: fmt.Sprintf("%s/#/retrieve/?%s", config.G.BKLog.Entrypoint, query.Encode()),
}
}
return result
return &result
}

// getRuleIDByNames get rule id by names
Expand Down
Loading
Loading