-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Improve ES Sink: #1260
Improve ES Sink: #1260
Changes from 1 commit
df50dc0
9d05351
97869bf
8b28b5d
e6425d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ import ( | |
"time" | ||
|
||
"github.com/golang/glog" | ||
"github.com/olivere/elastic" | ||
"github.com/pborman/uuid" | ||
|
||
"gopkg.in/olivere/elastic.v3" | ||
"os" | ||
) | ||
|
||
const ( | ||
|
@@ -60,7 +62,7 @@ func SaveDataIntoES(esClient *elastic.Client, indexName string, typeName string, | |
_, err = esClient.Index(). | ||
Index(indexName). | ||
Type(typeName). | ||
Id(string(indexID)). | ||
Id(indexID.String()). | ||
BodyJson(sinkData). | ||
Do() | ||
if err != nil { | ||
|
@@ -76,7 +78,7 @@ func CreateElasticSearchConfig(uri *url.URL) (*ElasticSearchConfig, error) { | |
var esConfig ElasticSearchConfig | ||
opts, err := url.ParseQuery(uri.RawQuery) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parser url's query string: %s", err) | ||
return nil, fmt.Errorf("fFailed to parser url's query string: %s", err) | ||
} | ||
|
||
// set the index for es,the default value is "heapster" | ||
|
@@ -87,12 +89,15 @@ func CreateElasticSearchConfig(uri *url.URL) (*ElasticSearchConfig, error) { | |
|
||
// Set the URL endpoints of the ES's nodes. Notice that when sniffing is | ||
// enabled, these URLs are used to initially sniff the cluster on startup. | ||
if len(opts["nodes"]) < 1 { | ||
var startupFns []elastic.ClientOptionFunc | ||
if len(opts["nodes"]) > 0 { | ||
startupFns = append(startupFns, elastic.SetURL(opts["nodes"]...)) | ||
} else if uri.Opaque != "" { | ||
startupFns = append(startupFns, elastic.SetURL(uri.Opaque)) | ||
} else { | ||
return nil, fmt.Errorf("There is no node assigned for connecting ES cluster") | ||
} | ||
|
||
startupFns := []elastic.ClientOptionFunc{elastic.SetURL(opts["nodes"]...)} | ||
|
||
// If the ES cluster needs authentication, the username and secret | ||
// should be set in sink config.Else, set the Authenticate flag to false | ||
if len(opts["esUserName"]) > 0 && len(opts["esUserSecret"]) > 0 { | ||
|
@@ -115,14 +120,6 @@ func CreateElasticSearchConfig(uri *url.URL) (*ElasticSearchConfig, error) { | |
startupFns = append(startupFns, elastic.SetHealthcheck(healthCheck)) | ||
} | ||
|
||
if len(opts["sniff"]) > 0 { | ||
sniff, err := strconv.ParseBool(opts["sniff"][0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to parse URL's sniff value into a bool") | ||
} | ||
startupFns = append(startupFns, elastic.SetSniff(sniff)) | ||
} | ||
|
||
if len(opts["startupHealthcheckTimeout"]) > 0 { | ||
timeout, err := time.ParseDuration(opts["startupHealthcheckTimeout"][0] + "s") | ||
if err != nil { | ||
|
@@ -131,12 +128,34 @@ func CreateElasticSearchConfig(uri *url.URL) (*ElasticSearchConfig, error) { | |
startupFns = append(startupFns, elastic.SetHealthcheckTimeoutStartup(timeout)) | ||
} | ||
|
||
if os.Getenv("AWS_ACCESS_KEY_ID") != "" || os.Getenv("AWS_ACCESS_KEY") != "" || | ||
os.Getenv("AWS_SECRET_ACCESS_KEY") != "" || os.Getenv("AWS_SECRET_KEY") != "" { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the blank line here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
glog.Info("Configuring with AWS credentials..") | ||
|
||
awsClient, err := createAWSClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
startupFns = append(startupFns, elastic.SetHttpClient(awsClient)) | ||
startupFns = append(startupFns, elastic.SetSniff(false)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change startupFns = append(startupFns, elastic.SetHttpClient(awsClient))
startupFns = append(startupFns, elastic.SetSniff(false)) to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} else { | ||
if len(opts["sniff"]) > 0 { | ||
sniff, err := strconv.ParseBool(opts["sniff"][0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to parse URL's sniff value into a bool") | ||
} | ||
startupFns = append(startupFns, elastic.SetSniff(sniff)) | ||
} | ||
} | ||
|
||
esConfig.EsClient, err = elastic.NewClient(startupFns...) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create ElasticSearch client: %v", err) | ||
return nil, fmt.Errorf("Failed to create ElasticSearch client: %v", err) | ||
} | ||
|
||
glog.V(2).Infof("elasticsearch sink configure successfully") | ||
glog.V(2).Infof("ElasticSearch sink configure successfully") | ||
|
||
return &esConfig, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import ( | |
"encoding/json" | ||
|
||
"github.com/golang/glog" | ||
"github.com/olivere/elastic" | ||
"gopkg.in/olivere/elastic.v3" | ||
esCommon "k8s.io/heapster/common/elasticsearch" | ||
event_core "k8s.io/heapster/events/core" | ||
"k8s.io/heapster/metrics/core" | ||
|
@@ -84,9 +84,12 @@ func (sink *elasticSearchSink) ExportEvents(eventBatch *event_core.EventBatch) { | |
for _, event := range eventBatch.Events { | ||
point, err := eventToPoint(event) | ||
if err != nil { | ||
glog.Warningf("Failed to convert event to point: %v", err) | ||
glog.Info("Failed to convert event to point: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to warning.. It make more sense to me. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i agree, |
||
} | ||
err = sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
if err != nil { | ||
glog.V(3).Info("Failed to export data to ElasticSearch sink: ", err) | ||
} | ||
sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
} | ||
} | ||
|
||
|
@@ -102,12 +105,12 @@ func NewElasticSearchSink(uri *url.URL) (event_core.EventSink, error) { | |
var esSink elasticSearchSink | ||
elasticsearchConfig, err := esCommon.CreateElasticSearchConfig(uri) | ||
if err != nil { | ||
glog.V(2).Infof("failed to config elasticsearch") | ||
glog.V(2).Infof("Failed to config ElasticSearch") | ||
return nil, err | ||
} | ||
|
||
esSink.esConfig = *elasticsearchConfig | ||
esSink.saveDataFunc = esCommon.SaveDataIntoES | ||
glog.V(2).Infof("elasticsearch sink setup successfully") | ||
glog.V(2).Infof("ElasticSearch sink setup successfully") | ||
return &esSink, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import ( | |
"time" | ||
|
||
"github.com/golang/glog" | ||
"github.com/olivere/elastic" | ||
"gopkg.in/olivere/elastic.v3" | ||
esCommon "k8s.io/heapster/common/elasticsearch" | ||
"k8s.io/heapster/metrics/core" | ||
) | ||
|
@@ -58,7 +58,10 @@ func (sink *elasticSearchSink) ExportData(dataBatch *core.DataBatch) { | |
}, | ||
MetricsTimestamp: dataBatch.Timestamp.UTC(), | ||
} | ||
sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
err := sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
if err != nil { | ||
glog.V(3).Info("Failed to export data to ElasticSearch sink: ", err) | ||
} | ||
} | ||
for _, metric := range metricSet.LabeledMetrics { | ||
labels := make(map[string]string) | ||
|
@@ -76,7 +79,10 @@ func (sink *elasticSearchSink) ExportData(dataBatch *core.DataBatch) { | |
}, | ||
MetricsTimestamp: dataBatch.Timestamp.UTC(), | ||
} | ||
sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
err := sink.saveDataFunc(sink.esConfig.EsClient, sink.esConfig.Index, typeName, point) | ||
if err != nil { | ||
glog.V(3).Info("Failed to export data to ElasticSearch sink: ", err) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -93,12 +99,12 @@ func NewElasticSearchSink(uri *url.URL) (core.DataSink, error) { | |
var esSink elasticSearchSink | ||
elasticsearchConfig, err := esCommon.CreateElasticSearchConfig(uri) | ||
if err != nil { | ||
glog.V(2).Infof("failed to config elasticsearch") | ||
glog.V(2).Infof("Failed to config ElasticSearch") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unify the level of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to warning.. It make more sense to me. What do you think? |
||
return nil, err | ||
} | ||
|
||
esSink.esConfig = *elasticsearchConfig | ||
esSink.saveDataFunc = esCommon.SaveDataIntoES | ||
glog.V(2).Infof("elasticsearch sink setup successfully") | ||
glog.V(2).Infof("ElasticSearch sink setup successfully") | ||
return &esSink, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo error
fFailed
==>Failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done