log: cleanup es client options

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2019-09-29 16:18:47 +08:00
parent d2b1bf4ba0
commit 11854e3320
3 changed files with 15 additions and 37 deletions

View File

@@ -91,12 +91,9 @@ func newTestConfig() *Config {
SecondaryEndpoint: "http://prometheus.kubesphere-monitoring-system.svc", SecondaryEndpoint: "http://prometheus.kubesphere-monitoring-system.svc",
}, },
LoggingOptions: &esclient.ElasticSearchOptions{ LoggingOptions: &esclient.ElasticSearchOptions{
Host: "http://elasticsearch-logging.kubesphere-logging-system.svc:9200", Host: "http://elasticsearch-logging.kubesphere-logging-system.svc:9200",
LogstashFormat: false, IndexPrefix: "elk",
Index: "", Version: "6",
LogstashPrefix: "elk",
Match: "kube.*",
Version: "6",
}, },
KubeSphereOptions: &kubesphere.KubeSphereOptions{ KubeSphereOptions: &kubesphere.KubeSphereOptions{
APIServer: "http://ks-apiserver.kubesphere-system.svc", APIServer: "http://ks-apiserver.kubesphere-system.svc",

View File

@@ -73,12 +73,10 @@ func NewLoggingClient(options *ElasticSearchOptions) (*ElasticSearchClient, erro
version = options.Version version = options.Version
} }
if options.LogstashFormat { if options.IndexPrefix != "" {
if options.LogstashPrefix != "" { index = options.IndexPrefix
index = options.LogstashPrefix } else {
} else { index = "logstash"
index = "logstash"
}
} }
switch version { switch version {

View File

@@ -6,22 +6,16 @@ import (
) )
type ElasticSearchOptions struct { type ElasticSearchOptions struct {
Host string `json:"host" yaml:"host"` Host string `json:"host" yaml:"host"`
LogstashFormat bool `json:"logstashFormat" yaml:"logstashFormat"` IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"`
Index string `json:"index" yaml:"index"` Version string `json:"version" yaml:"version"`
LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix"`
Match string `json:"match" yaml:"match"`
Version string `json:"version" yaml:"version"`
} }
func NewElasticSearchOptions() *ElasticSearchOptions { func NewElasticSearchOptions() *ElasticSearchOptions {
return &ElasticSearchOptions{ return &ElasticSearchOptions{
Host: "", Host: "",
LogstashFormat: false, IndexPrefix: "fluentbit",
Index: "fluentbit", Version: "",
LogstashPrefix: "",
Match: "kube.*",
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"+ "if this filed left blank, KubeSphere will use kubernetes builtin log API instead, and"+
" the following elastic search options will be ignored.") " the following elastic search options will be ignored.")
fs.BoolVar(&s.LogstashFormat, "logstash-format", s.LogstashFormat, ""+ fs.StringVar(&s.IndexPrefix, "index-prefix", s.IndexPrefix, ""+
"Whether to toggle logstash format compatibility.") "Index name prefix. KubeSphere will retrieve logs against indices matching the prefix.")
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.Version, "elasticsearch-version", s.Version, ""+ fs.StringVar(&s.Version, "elasticsearch-version", s.Version, ""+
"ElasticSearch major version, e.g. 5/6/7, if left blank, will detect automatically."+ "ElasticSearch major version, e.g. 5/6/7, if left blank, will detect automatically."+