From 11854e33207339c68bb176e36d1ada4ecef62e7d Mon Sep 17 00:00:00 2001 From: huanggze Date: Sun, 29 Sep 2019 16:18:47 +0800 Subject: [PATCH] log: cleanup es client options Signed-off-by: huanggze --- pkg/server/config/config_test.go | 9 ++---- pkg/simple/client/elasticsearch/esclient.go | 10 +++---- pkg/simple/client/elasticsearch/options.go | 33 +++++---------------- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/pkg/server/config/config_test.go b/pkg/server/config/config_test.go index 611236b78..e2c310367 100644 --- a/pkg/server/config/config_test.go +++ b/pkg/server/config/config_test.go @@ -91,12 +91,9 @@ func newTestConfig() *Config { SecondaryEndpoint: "http://prometheus.kubesphere-monitoring-system.svc", }, LoggingOptions: &esclient.ElasticSearchOptions{ - Host: "http://elasticsearch-logging.kubesphere-logging-system.svc:9200", - LogstashFormat: false, - Index: "", - LogstashPrefix: "elk", - Match: "kube.*", - Version: "6", + Host: "http://elasticsearch-logging.kubesphere-logging-system.svc:9200", + IndexPrefix: "elk", + Version: "6", }, KubeSphereOptions: &kubesphere.KubeSphereOptions{ APIServer: "http://ks-apiserver.kubesphere-system.svc", diff --git a/pkg/simple/client/elasticsearch/esclient.go b/pkg/simple/client/elasticsearch/esclient.go index 6c19fb542..9ff1663cf 100644 --- a/pkg/simple/client/elasticsearch/esclient.go +++ b/pkg/simple/client/elasticsearch/esclient.go @@ -73,12 +73,10 @@ func NewLoggingClient(options *ElasticSearchOptions) (*ElasticSearchClient, erro version = options.Version } - if options.LogstashFormat { - if options.LogstashPrefix != "" { - index = options.LogstashPrefix - } else { - index = "logstash" - } + if options.IndexPrefix != "" { + index = options.IndexPrefix + } else { + index = "logstash" } switch version { diff --git a/pkg/simple/client/elasticsearch/options.go b/pkg/simple/client/elasticsearch/options.go index 2ac7bb31b..0ae93442d 100644 --- a/pkg/simple/client/elasticsearch/options.go +++ b/pkg/simple/client/elasticsearch/options.go @@ -6,22 +6,16 @@ import ( ) type ElasticSearchOptions struct { - Host string `json:"host" yaml:"host"` - LogstashFormat bool `json:"logstashFormat" yaml:"logstashFormat"` - Index string `json:"index" yaml:"index"` - LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix"` - Match string `json:"match" yaml:"match"` - Version string `json:"version" yaml:"version"` + Host string `json:"host" yaml:"host"` + IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"` + Version string `json:"version" yaml:"version"` } func NewElasticSearchOptions() *ElasticSearchOptions { return &ElasticSearchOptions{ - Host: "", - LogstashFormat: false, - Index: "fluentbit", - LogstashPrefix: "", - Match: "kube.*", - Version: "", + Host: "", + IndexPrefix: "fluentbit", + Version: "", } } @@ -43,19 +37,8 @@ func (s *ElasticSearchOptions) AddFlags(fs *pflag.FlagSet) { "if this filed left blank, KubeSphere will use kubernetes builtin log API instead, and"+ " the following elastic search options will be ignored.") - fs.BoolVar(&s.LogstashFormat, "logstash-format", s.LogstashFormat, ""+ - "Whether to toggle logstash format compatibility.") - - fs.StringVar(&s.LogstashPrefix, "logstash-prefix", s.LogstashPrefix, ""+ - "If logstash-format is enabled, the Index name is composed using a prefix and the date,"+ - "e.g: If logstash-prefix is equals to 'mydata' your index will become 'mydata-YYYY.MM.DD'."+ - "The last string appended belongs to the date when the data is being generated.") - - fs.StringVar(&s.Match, "elasticsearch-match", s.Match, ""+ - "The regex match for index, eg. kube.*") - - fs.StringVar(&s.Index, "elasticsearch-index", s.Index, ""+ - "Index name.") + fs.StringVar(&s.IndexPrefix, "index-prefix", s.IndexPrefix, ""+ + "Index name prefix. KubeSphere will retrieve logs against indices matching the prefix.") fs.StringVar(&s.Version, "elasticsearch-version", s.Version, ""+ "ElasticSearch major version, e.g. 5/6/7, if left blank, will detect automatically."+