diff --git a/search/document_store.go b/search/document_store.go index 380910ef4687e2e82eb193b224640f9d9253645c..07278e1b0eaee9c528c2502a3d926c0cad7a87e4 100644 --- a/search/document_store.go +++ b/search/document_store.go @@ -90,7 +90,7 @@ func (w *writer) DocumentStore(name string, tmpl interface{}) (DocumentStore, er if err != nil { return nil, errors.Wrapf(err, "failed to marshal index mappings") } - logs.Infof("%s Index Mappings: %s", structType, string(ds.jsonMappings)) + logs.Info("%s Index Mappings: %s", structType, string(ds.jsonMappings)) //define search response type //similar to SearchResponseBody @@ -164,7 +164,7 @@ func (ds *documentStore) Write(id string, data interface{}) error { if res, err := ds.w.Write(indexName, id, data); err != nil { return err } else { - logs.Debugf("IndexResponse: %+v", res) + logs.Info("IndexResponse: %+v", res) } return nil } @@ -217,17 +217,16 @@ func (ds *documentStore) Search(query Query, limit int64) (ids []string, totalCo } bodyData, _ := ioutil.ReadAll(searchResponse.Body) - logs.Debugf("Response Body: %s", string(bodyData)) + logs.Info("Response Body: %s", string(bodyData)) resBodyPtrValue := reflect.New(ds.searchResponseBodyType) // if err = json.NewDecoder(searchResponse.Body).Decode(resBodyPtrValue.Interface()); err != nil { if err = json.Unmarshal(bodyData, resBodyPtrValue.Interface()); err != nil { - logs.Errorf("search response body: %s", string(bodyData)) err = errors.Wrapf(err, "cannot decode search response body") return } - logs.Debugf("Response Parsed: %+v", resBodyPtrValue.Interface()) + logs.Info("Response Parsed: %+v", resBodyPtrValue.Interface()) hitsTotalValue, err := reflection.Get(resBodyPtrValue, ".hits.total.value") if err != nil { @@ -243,7 +242,7 @@ func (ds *documentStore) Search(query Query, limit int64) (ids []string, totalCo err = errors.Wrapf(err, "cannot get search response documents") return } - logs.Errorf("items: (%T) %+v", foundIDs.Interface(), foundIDs.Interface()) + //logs.Errorf("items: (%T) %+v", foundIDs.Interface(), foundIDs.Interface()) return foundIDs.Interface().([]string), hitsTotalValue.Interface().(int), nil } diff --git a/search/time_series.go b/search/time_series.go index 77fbd62c6fcf89ef712c02901a474e2cc006072a..e9f87dd5fc3a8bbbf45549a74b27e233ad2b9ae9 100644 --- a/search/time_series.go +++ b/search/time_series.go @@ -102,7 +102,7 @@ func (w *writer) TimeSeries(name string, tmpl interface{}) (TimeSeries, error) { if err != nil { return nil, errors.Wrapf(err, "failed to marshal index mappings") } - logs.Infof("%s Index Mappings: %s", structType, string(ts.jsonMappings)) + logs.Info("%s Index Mappings: %s", structType, string(ts.jsonMappings)) //define search response type //similar to SearchResponseBody @@ -141,7 +141,7 @@ func structMappingProperties(structType reflect.Type) (map[string]MappingPropert fieldName = jsonTags[0] } if fieldName == "" { - logs.Debugf("Skip %s unnamed field %+v", structType, structField) + logs.Info("Skip %s unnamed field %+v", structType, structField) continue } @@ -272,7 +272,7 @@ func (ts *timeSeries) Write(startTime, endTime time.Time, data interface{}) erro if res, err := ts.w.Write(indexName, "", x.Elem().Interface()); err != nil { return err } else { - logs.Debugf("IndexResponse: %+v", res) + logs.Info("IndexResponse: %+v", res) } return nil @@ -320,10 +320,10 @@ func (w *writer) DelOldTimeSeries(indexName string, olderThanDays int) ([]string for dailyIndexName, dailyIndexInfo := range indices { dateStr := dailyIndexName[len(indexName)+1:] if date, err := time.ParseInLocation("20060102", dateStr, t0.Location()); err != nil { - logs.Debugf("Ignore index(%s) with invalid date(%s)", dailyIndexName, dateStr) + logs.Info("Ignore index(%s) with invalid date(%s)", dailyIndexName, dateStr) } else { if date.Before(timeThreshold) { - logs.Debugf("Deleting index(%s).uuid(%s) older than %s days...", dailyIndexName, dailyIndexInfo.Settings.Index.UUID, timeThreshold) + logs.Info("Deleting index(%s).uuid(%s) older than %s days...", dailyIndexName, dailyIndexInfo.Settings.Index.UUID, timeThreshold) indicesToDelete = append(indicesToDelete, dailyIndexName) } } @@ -333,7 +333,7 @@ func (w *writer) DelOldTimeSeries(indexName string, olderThanDays int) ([]string if err != nil { return indicesToDelete, errors.Wrapf(err, "failed to delete indices(%s)", indicesToDelete) } - logs.Debugf("Deleted %d daily indices(%s) older than %d days", len(indicesToDelete), indicesToDelete, olderThanDays) + logs.Info("Deleted %d daily indices(%s) older than %d days", len(indicesToDelete), indicesToDelete, olderThanDays) } return indicesToDelete, nil } @@ -385,7 +385,7 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC } jsonBody, _ := json.Marshal(body) - logs.Debugf("Search: %s", string(jsonBody)) + logs.Info("Search: %s", string(jsonBody)) search := opensearchapi.SearchRequest{ Index: []string{ts.name + "-*"}, Body: bytes.NewReader(jsonBody), @@ -406,12 +406,12 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC } bodyData, _ := ioutil.ReadAll(searchResponse.Body) - logs.Debugf("Response Body: %s", string(bodyData)) + logs.Info("Response Body: %s", string(bodyData)) resBodyPtrValue := reflect.New(ts.searchResponseBodyType) //if err = json.NewDecoder(searchResponse.Body).Decode(resBodyPtrValue.Interface()); err != nil { if err = json.Unmarshal(bodyData, resBodyPtrValue.Interface()); err != nil { - logs.Errorf("search response body: %s", string(bodyData)) + logs.Info("search response body: %s", string(bodyData)) err = errors.Wrapf(err, "cannot decode search response body") return } diff --git a/search/writer.go b/search/writer.go index 44477cd5b6f50258da5589a43225074ab7bc2c64..46f406375a31607923d29439c8e19c866b654c45 100644 --- a/search/writer.go +++ b/search/writer.go @@ -43,7 +43,7 @@ func New(config Config) (Writer, error) { return nil, errors.Wrapf(err, "cannot initialize opensearch connection") } // Print OpenSearch version information on console. - logs.Debugf("Search client created with config: %+v", searchConfig) + logs.Info("Search client created with config: %+v", searchConfig) w.api = opensearchapi.New(w.client) return w, nil diff --git a/string_utils/string_utils.go b/string_utils/string_utils.go index 77bd2b76403103d346b930c809f5b973d697d68e..72e59ff6257770f19a7b02c083cc8dfb33b29c48 100644 --- a/string_utils/string_utils.go +++ b/string_utils/string_utils.go @@ -134,6 +134,9 @@ func Int64ToString(number int64) string { func IntToString(number int) string { return strconv.Itoa(number) } +func StringToInt(stringValue string) (int, error) { + return strconv.Atoi(stringValue) +} func Int64SliceToString(numbers []int64) string { numString := fmt.Sprint(numbers)