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: add es #1959

Merged
merged 38 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
834b67d
feat: add es
DokiDoki1103 Jun 20, 2024
fe641c2
fix: import cycle not allowed
DokiDoki1103 Jun 20, 2024
f9fd975
fix: import cycle not allowed
DokiDoki1103 Jun 20, 2024
6e6716a
fix: undefined: time.DateTime
DokiDoki1103 Jun 20, 2024
9f62f86
feat: add SetBasicAuth
DokiDoki1103 Jun 22, 2024
c57c3df
feat: add SetBasicAuth
DokiDoki1103 Jun 22, 2024
ba71c58
feat: add SetBasicAuth
DokiDoki1103 Jun 22, 2024
895ffbd
feat: id sort desc
DokiDoki1103 Jun 22, 2024
9f07f85
feat: create_time sort desc
DokiDoki1103 Jun 23, 2024
0df2988
fix: count not support limit
DokiDoki1103 Jun 24, 2024
79b8981
fix: count not support limit
DokiDoki1103 Jun 24, 2024
4b42be5
fix: time format error
DokiDoki1103 Jun 24, 2024
7f5de63
fix: time format error
DokiDoki1103 Jun 24, 2024
61853c8
fix: time format error
DokiDoki1103 Jun 24, 2024
6989a7f
fix: field
DokiDoki1103 Jun 24, 2024
21f4862
fix: format date
DokiDoki1103 Jun 24, 2024
bae930d
fix: format date
DokiDoki1103 Jun 24, 2024
d63d4bd
fix: format date
DokiDoki1103 Jun 24, 2024
3a73494
fix: format array
DokiDoki1103 Jun 25, 2024
44c254f
fix: format array
DokiDoki1103 Jun 25, 2024
6ee92d6
feat: add es
DokiDoki1103 Jun 25, 2024
80615ca
fix: all link es
DokiDoki1103 Jun 25, 2024
fa6b7d9
feat: add es
ZhangSetSail Jun 26, 2024
28a9ee0
perf: delete es log
ZhangSetSail Jun 27, 2024
12a10f5
fix: show build use time
DokiDoki1103 Jul 21, 2024
22e3eb5
fix: show build use time
DokiDoki1103 Jul 21, 2024
4f2b43a
fix: show build use time
DokiDoki1103 Jul 21, 2024
eeceacd
feat: es logrus
DokiDoki1103 Jul 22, 2024
7a30f8f
feat: es logrus
DokiDoki1103 Jul 22, 2024
0ac8cf5
perf: support es connect reuse
yangkaa Jul 24, 2024
8319633
fix: es connect reuse error
yangkaa Jul 24, 2024
47f8782
feat: download chart defer wg.Done()
DokiDoki1103 Jul 24, 2024
4bf94da
perf: support configrue es and http connections
yangkaa Jul 25, 2024
6de0699
feat: add es
DokiDoki1103 Jul 26, 2024
b09a72c
feat: add es
DokiDoki1103 Jul 26, 2024
da4b425
feat: add es
DokiDoki1103 Jul 26, 2024
23ac7ac
feat: add es
DokiDoki1103 Jul 26, 2024
30fbdb4
feat: args es-enable
DokiDoki1103 Jul 26, 2024
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
16 changes: 8 additions & 8 deletions api/handler/service_batch_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/sirupsen/logrus"
)

//BatchOperationHandler batch operation handler
// BatchOperationHandler batch operation handler
type BatchOperationHandler struct {
mqCli gclient.MQClient
operationHandler *OperationHandler
Expand All @@ -48,12 +48,12 @@ type BatchOperationHandler struct {
EventIDs []string
}

//BatchOperationResult batch operation result
// BatchOperationResult batch operation result
type BatchOperationResult struct {
BatchResult []OperationResult `json:"batche_result"`
}

//CreateBatchOperationHandler create batch operation handler
// CreateBatchOperationHandler create batch operation handler
func CreateBatchOperationHandler(mqCli gclient.MQClient, statusCli *client.AppRuntimeSyncClient, operationHandler *OperationHandler) *BatchOperationHandler {
return &BatchOperationHandler{
mqCli: mqCli,
Expand All @@ -72,7 +72,7 @@ func (b *BatchOperationHandler) serviceStartupSequence(serviceIDs []string) map[
return startupSeqConfigs
}

//Build build
// Build build
func (b *BatchOperationHandler) Build(ctx context.Context, tenant *dbmodel.Tenants, operator string, batchOpReqs model.BatchOpRequesters) (model.BatchOpResult, error) {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
defer util.Elapsed("[BatchOperationHandler] build components")()
Expand Down Expand Up @@ -118,7 +118,7 @@ func (b *BatchOperationHandler) Build(ctx context.Context, tenant *dbmodel.Tenan
return batchOpResult, nil
}

//Start batch start
// Start batch start
func (b *BatchOperationHandler) Start(ctx context.Context, tenant *dbmodel.Tenants, operator string, batchOpReqs model.BatchOpRequesters) (model.BatchOpResult, error) {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
defer util.Elapsed("[BatchOperationHandler] start components")()
Expand Down Expand Up @@ -165,7 +165,7 @@ func (b *BatchOperationHandler) Start(ctx context.Context, tenant *dbmodel.Tenan
return batchOpResult, nil
}

//Stop batch stop
// Stop batch stop
func (b *BatchOperationHandler) Stop(ctx context.Context, tenant *dbmodel.Tenants, operator string, batchOpReqs model.BatchOpRequesters) (model.BatchOpResult, error) {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
defer util.Elapsed("[BatchOperationHandler] stop components")()
Expand Down Expand Up @@ -197,7 +197,7 @@ func (b *BatchOperationHandler) Stop(ctx context.Context, tenant *dbmodel.Tenant
return batchOpResult, nil
}

//Upgrade batch upgrade
// Upgrade batch upgrade
func (b *BatchOperationHandler) Upgrade(ctx context.Context, tenant *dbmodel.Tenants, operator string, batchOpReqs model.BatchOpRequesters) (model.BatchOpResult, error) {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
defer util.Elapsed("[BatchOperationHandler] upgrade components")()
Expand Down Expand Up @@ -280,7 +280,7 @@ func (b *BatchOperationHandler) createEvents(tenantID, operator string, batchOpR
Target: dbmodel.TargetTypeService,
TargetID: req.GetComponentID(),
UserName: operator,
StartTime: time.Now().Format(time.RFC3339),
StartTime: time.Now().Format("2006-01-02 15:04:05"),
SynType: dbmodel.ASYNEVENTTYPE,
OptType: req.OpType(),
}
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/exector.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (e *exectorManager) sendAction(tenantID, serviceID, eventID, newVersion, ac
EventID: util.NewUUID(),
TenantID: tenantID,
ServiceID: serviceID,
StartTime: time.Now().Format(time.RFC3339),
StartTime: time.Now().Format("2006-01-02 15:04:05"),
OptType: "upgrade",
Target: "service",
TargetID: serviceID,
Expand Down
6 changes: 6 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"github.com/goodrain/rainbond/config/configs"
"github.com/goodrain/rainbond/pkg/component"
"github.com/goodrain/rainbond/pkg/component/es"
"github.com/goodrain/rainbond/pkg/rainbond"
"github.com/sirupsen/logrus"
"os"
Expand All @@ -46,6 +47,11 @@ func main() {
AppName: "rbd-api",
APIConfig: s.Config,
})

if s.Config.ElasticEnable {
es.New().SingleStart(s.Config.ElasticSearchURL, s.Config.ElasticSearchUsername, s.Config.ElasticSearchPassword)
}

// 启动 rbd-api
err := rainbond.New(context.Background(), configs.Default()).
Registry(component.Database()).
Expand Down
11 changes: 11 additions & 0 deletions cmd/api/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ type Config struct {
GrctlImage string
RbdHub string
RbdWorker string
RegionName string
RegionSN string

ElasticSearchURL string
ElasticSearchUsername string
ElasticSearchPassword string
ElasticEnable bool
}

// APIServer apiserver server
Expand Down Expand Up @@ -121,6 +128,10 @@ func (a *APIServer) AddFlags(fs *pflag.FlagSet) {
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"rbd-eventlog:6366"}, "event log server address")
fs.StringSliceVar(&a.EventLogEndpoints, "event-log", []string{"local=>rbd-eventlog:6363"}, "event log websocket address")

fs.StringVar(&a.ElasticSearchURL, "es-url", "http://47.92.106.114:9200", "es url")
fs.StringVar(&a.ElasticSearchUsername, "es-username", "", "es username")
fs.StringVar(&a.ElasticSearchPassword, "es-password", "", "es pwd")
fs.BoolVar(&a.ElasticEnable, "es-enable", false, "enable es")
}

// SetLog 设置log
Expand Down
10 changes: 10 additions & 0 deletions cmd/builder/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type Config struct {
KeepCount int
CleanInterval int
BRVersion string

ElasticSearchURL string
ElasticSearchUsername string
ElasticSearchPassword string
ElasticEnable bool
}

// Builder builder server
Expand Down Expand Up @@ -106,6 +111,11 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"rbd-eventlog:6366"}, "event log server address. simple lb")
fs.StringVar(&a.MQAPI, "mq-api", "rbd-mq:6300", "acp_mq api")

fs.StringVar(&a.ElasticSearchURL, "es-url", "http://47.92.106.114:9200", "es url")
fs.StringVar(&a.ElasticSearchUsername, "es-username", "", "es username")
fs.StringVar(&a.ElasticSearchPassword, "es-password", "", "es pwd")
fs.BoolVar(&a.ElasticEnable, "es-enable", false, "enable es")

}

// SetLog 设置log
Expand Down
5 changes: 5 additions & 0 deletions cmd/builder/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/goodrain/rainbond/db/config"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/mq/client"
"github.com/goodrain/rainbond/pkg/component/es"
"github.com/goodrain/rainbond/pkg/gogo"
k8sutil "github.com/goodrain/rainbond/util/k8s"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -51,6 +52,10 @@ func Run(s *option.Builder) error {
MysqlConnectionInfo: s.Config.MysqlConnectionInfo,
}

if s.ElasticEnable {
es.New().SingleStart(s.Config.ElasticSearchURL, s.Config.ElasticSearchUsername, s.Config.ElasticSearchPassword)
}

if err := db.CreateManager(dbconfig); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/eventlog/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package server

import (
"fmt"
"github.com/goodrain/rainbond/pkg/component/es"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -101,6 +102,11 @@ func (s *LogServer) AddFlags(fs *pflag.FlagSet) {
fs.IntVar(&s.Conf.Entry.NewMonitorMessageServerConf.ListenerPort, "monitor.udp.port", 6166, "receive new monitor udp server port")
fs.StringVar(&s.Conf.Cluster.Discover.NodeID, "node-id", "", "the unique ID for this node.")
fs.DurationVar(&s.Conf.Cluster.PubSub.PollingTimeout, "zmq4-polling-timeout", 200*time.Millisecond, "The timeout determines the time-out on the polling of sockets")

fs.StringVar(&s.Conf.ElasticSearchURL, "es-url", "http://47.92.106.114:9200", "es url")
fs.StringVar(&s.Conf.ElasticSearchUsername, "es-username", "", "es username")
fs.StringVar(&s.Conf.ElasticSearchPassword, "es-password", "", "es pwd")
fs.BoolVar(&s.Conf.ElasticEnable, "es-enable", false, "enable es")
}

// InitLog 初始化log
Expand Down Expand Up @@ -161,6 +167,10 @@ func (s *LogServer) Run() error {
s.Logger.Debug("Start run server.")
log := s.Logger

if s.Conf.ElasticEnable {
es.New().SingleStart(s.Conf.ElasticSearchURL, s.Conf.ElasticSearchUsername, s.Conf.ElasticSearchPassword)
}

//init new db
if err := db.CreateDBManager(s.Conf.EventStore.DB); err != nil {
logrus.Infof("create db manager error, %v", err)
Expand Down
10 changes: 10 additions & 0 deletions cmd/worker/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type Config struct {
RBDNamespace string
GrdataPVCName string
Helm Helm

ElasticSearchURL string
ElasticSearchUsername string
ElasticSearchPassword string
ElasticEnable bool
}

// Helm helm configuration.
Expand Down Expand Up @@ -104,6 +109,11 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
a.Helm.RepoFile = path.Join(a.Helm.DataDir, "repo/repositories.yaml")
a.Helm.RepoCache = path.Join(a.Helm.DataDir, "cache")
a.Helm.ChartCache = path.Join(a.Helm.DataDir, "chart")

fs.StringVar(&a.ElasticSearchURL, "es-url", "http://47.92.106.114:9200", "es url")
fs.StringVar(&a.ElasticSearchUsername, "es-username", "", "es username")
fs.StringVar(&a.ElasticSearchPassword, "es-password", "", "es pwd")
fs.BoolVar(&a.ElasticEnable, "es-enable", false, "enable es")
}

// SetLog 设置log
Expand Down
6 changes: 6 additions & 0 deletions cmd/worker/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package server
import (
apisixversioned "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned"
"github.com/goodrain/rainbond/otherclient"
"github.com/goodrain/rainbond/pkg/component/es"
"k8s.io/client-go/restmapper"
"kubevirt.io/client-go/kubecli"
"os"
Expand Down Expand Up @@ -56,6 +57,11 @@ func Run(s *option.Worker) error {
DBType: s.Config.DBType,
MysqlConnectionInfo: s.Config.MysqlConnectionInfo,
}
if s.Config.ElasticEnable {
es.New().SingleStart(s.Config.ElasticSearchURL, s.Config.ElasticSearchUsername, s.Config.ElasticSearchPassword)

}

//step 1:db manager init ,event log client init
if err := db.CreateManager(dbconfig); err != nil {
return err
Expand Down
41 changes: 21 additions & 20 deletions db/model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,33 @@ var EventStatusSuccess EventStatus = "success"
// EventStatusFailure -
var EventStatusFailure EventStatus = "failure"

//ServiceEvent event struct
// ServiceEvent event struct
type ServiceEvent struct {
Model
EventID string `gorm:"column:event_id;size:40;index:event_id"`
TenantID string `gorm:"column:tenant_id;size:40;index:tenant_id"`
ServiceID string `gorm:"column:service_id;size:40;index:service_id"`
Target string `gorm:"column:target;size:40"`
TargetID string `gorm:"column:target_id;size:255;index:target_id"`
RequestBody string `gorm:"column:request_body;size:1024"`
UserName string `gorm:"column:user_name;size:40"`
StartTime string `gorm:"column:start_time;size:40"`
EndTime string `gorm:"column:end_time;size:40"`
OptType string `gorm:"column:opt_type;size:40"`
SynType int `gorm:"column:syn_type;size:1"`
Status string `gorm:"column:status;size:40"`
FinalStatus string `gorm:"column:final_status;size:40"`
Message string `gorm:"column:message"`
Reason string `gorm:"column:reason"`
ID uint `gorm:"column:ID;primary_key" json:"-"`
CreatedAt string `gorm:"column:create_time" json:"create_time"`
EventID string `gorm:"column:event_id;size:40;index:event_id" json:"event_id"`
TenantID string `gorm:"column:tenant_id;size:40;index:tenant_id" json:"tenant_id"`
ServiceID string `gorm:"column:service_id;size:40;index:service_id" json:"service_id"`
Target string `gorm:"column:target;size:40" json:"target"`
TargetID string `gorm:"column:target_id;size:255;index:target_id" json:"target_id"`
RequestBody string `gorm:"column:request_body;size:1024" json:"request_body"`
UserName string `gorm:"column:user_name;size:40" json:"user_name"`
StartTime string `gorm:"column:start_time;size:40" json:"start_time"`
EndTime string `gorm:"column:end_time;size:40" json:"end_time"`
OptType string `gorm:"column:opt_type;size:40" json:"opt_type"`
SynType int `gorm:"column:syn_type;size:1" json:"syn_type"`
Status string `gorm:"column:status;size:40" json:"status"`
FinalStatus string `gorm:"column:final_status;size:40" json:"final_status"`
Message string `gorm:"column:message" json:"message"`
Reason string `gorm:"column:reason" json:"reason"`
}

//TableName 表名
// TableName 表名
func (t *ServiceEvent) TableName() string {
return "tenant_services_event"
}

//NotificationEvent NotificationEvent
// NotificationEvent NotificationEvent
type NotificationEvent struct {
Model
//Kind could be service, tenant, cluster, node
Expand All @@ -121,7 +122,7 @@ type NotificationEvent struct {
TenantName string `gorm:"column:tenant_name;size:40"`
}

//TableName table name
// TableName table name
func (n *NotificationEvent) TableName() string {
return "region_notification_event"
}
Expand Down
Loading
Loading