Skip to content

Commit

Permalink
Добавил логи для запросов, исправил работу с часовыми индексами
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Nov 21, 2024
1 parent 12f7272 commit 5f318a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions modules/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ func (rt *Router) FrontHandler(w http.ResponseWriter, r *http.Request) {
return
}

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", r.UserAgent())
/* отправить его клиенту */
contentType := mime.TypeByExtension(path.Ext(cFile))
w.Header().Set("Content-Type", contentType)
Expand Down Expand Up @@ -256,16 +255,15 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {

if r.Method != http.MethodPost {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", http.StatusMethodNotAllowed, "\t", "Invalid request method ")
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusMethodNotAllowed, "\t", "Invalid request method ")
return
}
err := json.NewDecoder(r.Body).Decode(&request)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", http.StatusInternalServerError, "\t", err.Error())
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}

switch request.Action {
case "get_repositories":
{
Expand All @@ -275,6 +273,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(response)
}
case "get_nodes":
Expand All @@ -287,6 +286,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}

j, _ := json.Marshal(nresp)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(j)
}

Expand All @@ -298,7 +298,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(response)
}

Expand All @@ -316,7 +316,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(response)
}

Expand Down Expand Up @@ -388,7 +388,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}
rt.sl = snap_list
j, _ := json.Marshal(snap_list)

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(j)
}

Expand Down Expand Up @@ -421,10 +421,8 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {

}

log.Println("Get Snapshots from cache")

j, _ := json.Marshal(rt.sl)

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent(), "\t", "Get Snapshots from cache")
w.Write(j)
}

Expand All @@ -451,6 +449,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(status_response)
}

Expand Down Expand Up @@ -555,6 +554,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}

msg := fmt.Sprintf(`{"message":"Indices '%v' will be restored", "error":0}`, index_list_for_restore)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write([]byte(msg))

}
Expand All @@ -565,6 +565,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
cl = append(cl, Cluster{rt.conf.Snapshot.Name, rt.conf.Snapshot.Host, "Snapshot"})
cl = append(cl, Cluster{rt.conf.Search.Name, rt.conf.Search.Host, "Search"})
j, _ := json.Marshal(cl)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(j)
}
case "get_index_groups":
Expand All @@ -576,6 +577,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
return
}
j, _ := json.Marshal(response)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent())
w.Write(j)
}

Expand All @@ -593,7 +595,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
host = rt.conf.Search.Host
}
flatMap := make(map[string]string)
response, err := rt.doGet(host+request.Search.Index+t.Format("2006.01.02")+"/_mapping", "Search")
response, err := rt.doGet(host+request.Search.Index+t.Format("2006.01.02")+"*/_mapping", "Search")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
Expand All @@ -615,7 +617,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}

j, _ := json.Marshal(flatMap)

log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent(), "\t", host+request.Search.Index)
w.Write(j)
}

Expand Down Expand Up @@ -685,17 +687,18 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {

full_query = fmt.Sprintf(`{"size": 500, %s, %s, %s, %s }`, sort, use_source, fields, query)
if request.Search.Count {
log.Println("action: Count", "\tquery: ", "{"+query+"}")
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent(), "\t", host+request.Search.Index, "\t", "action: Count", "\tquery: ", "{"+query+"}")
_ = json.Unmarshal([]byte("{"+query+"}"), &req)
cresponse, err := rt.doPost(host+request.Search.Index+"/_count", req, "Search")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
return
}

w.Write(cresponse)
} else {
log.Println("action: Search", "\tquery: ", full_query)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent(), "\t", host+request.Search.Index, "\t", "action: Search", "\tquery: ", full_query)
_ = json.Unmarshal([]byte(full_query), &req)
sresponse, err := rt.doPost(host+request.Search.Index+"/_search", req, "Search")
if err != nil {
Expand Down Expand Up @@ -941,6 +944,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}

}
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", r.UserAgent(), "\t", host+request.Search.Index, "\t", "action: CSV", "\tquery: ", full_query, "\tfile: ", request.Search.Fname)
w.Write([]byte("Done"))

}
Expand Down
2 changes: 1 addition & 1 deletion modules/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

package version

var Version = "extractor/v0.2.16"
var Version = "extractor/v0.2.17"

0 comments on commit 5f318a2

Please sign in to comment.