changes added for live tail api

This commit is contained in:
nityanandagohain 2022-07-19 16:34:33 +05:30
parent 8e4fbbe770
commit b5c8764605
3 changed files with 7 additions and 7 deletions

View File

@ -2884,7 +2884,7 @@ func (r *ClickHouseReader) GetLogs(ctx context.Context, params *model.LogsFilter
}
func (r *ClickHouseReader) TailLogs(ctx context.Context, client *model.LogsTailClient) {
response := &[]model.GetLogsResponse{}
fields, apiErr := r.GetLogFields(ctx)
if apiErr != nil {
client.Error <- apiErr.Err
@ -2934,8 +2934,9 @@ func (r *ClickHouseReader) TailLogs(ctx context.Context, client *model.LogsTailC
if idStart != nil {
tmpQuery += fmt.Sprintf(" and id > '%s'", *idStart)
}
tmpQuery = fmt.Sprintf("%s order by timestamp asc limit 1000", tmpQuery)
tmpQuery = fmt.Sprintf("%s order by timestamp asc, id asc limit 1000", tmpQuery)
zap.S().Debug(tmpQuery)
response := &[]model.GetLogsResponse{}
err := r.db.Select(ctx, response, tmpQuery)
if err != nil {
zap.S().Debug(err)

View File

@ -1951,13 +1951,12 @@ func (aH *APIHandler) tailLogs(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(&buf)
enc.Encode(ev)
fmt.Fprintf(w, "data: %v\n\n", buf.String())
fmt.Printf("data: %v\n", buf.String())
flusher.Flush()
case <-client.Done:
fmt.Println("done!")
zap.S().Debug("done!")
return
case <-client.Error:
fmt.Println("error occured!")
zap.S().Debug("error occured!")
return
}
}

View File

@ -166,8 +166,8 @@ func (s *Server) createPublicServer(api *APIHandler) (*http.Server, error) {
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "cache-control"},
})
handler := c.Handler(r)