Skip to content
Snippets Groups Projects
Commit d25f8523 authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Cleanup in search

parent ea83f988
Branches
Tags
1 merge request!8More cleanup, remove clutter, add to api-logs, sqs-logs possible, action list in api-logs, runtime control possible
......@@ -258,7 +258,7 @@ func (ts *timeSeries) Write(startTime, endTime time.Time, data interface{}) erro
x.Elem().Field(0).Set(reflect.ValueOf(TimeSeriesHeader{
StartTime: startTime,
EndTime: endTime,
DurationMs: int64(endTime.Sub(startTime) / time.Millisecond),
DurationMs: endTime.Sub(startTime).Milliseconds(),
}))
return ts.w.Write(indexName, x.Elem().Interface())
}
......
......@@ -10,6 +10,7 @@ import (
opensearch "github.com/opensearch-project/opensearch-go"
opensearchapi "github.com/opensearch-project/opensearch-go/opensearchapi"
"gitlab.com/uafrica/go-utils/errors"
"gitlab.com/uafrica/go-utils/logger"
)
type Writer interface {
......@@ -26,21 +27,22 @@ func New(config Config) (Writer, error) {
timeSeriesByName: map[string]TimeSeries{},
}
// Initialize the client with SSL/TLS enabled.
var err error
w.client, err = opensearch.NewClient(opensearch.Config{
searchConfig := opensearch.Config{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Addresses: config.Addresses,
Username: config.Username,
Password: config.Password,
})
}
// Initialize the client with SSL/TLS enabled.
var err error
w.client, err = opensearch.NewClient(searchConfig)
if err != nil {
return nil, errors.Wrapf(err, "cannot initialize opensearch connection")
}
// Print OpenSearch version information on console.
//fmt.Println(client.Info())
logger.Debugf("Search client created with config: %+v", searchConfig)
w.api = opensearchapi.New(w.client)
return w, nil
......@@ -58,13 +60,17 @@ func (writer writer) Write(indexName string, doc interface{}) error {
if writer.client == nil {
return errors.Errorf("writer closed")
}
jsonDocStr, ok := doc.(string)
if !ok {
jsonDoc, err := json.Marshal(doc)
if err != nil {
return errors.Wrapf(err, "failed to JSON encode document")
}
jsonDocStr = string(jsonDoc)
}
indexResponse, err := writer.api.Index(
indexName,
strings.NewReader(string(jsonDoc)),
strings.NewReader(jsonDocStr),
)
if err != nil {
return errors.Wrapf(err, "failed to index document")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment