我尝试通过发出获取请求从 kibana 服务器获取 csv 数据。在此服务器向我发送带有数据的响应后,我编写csv文件并保存在某个地方。每次 csv 文件都有一行“挂起”。Kibana日志显示状态代码503但是如果我把网址放在浏览器中,我可以得到带有正确数据的csv文件。可能我需要等待更多来自基巴纳的回应。从我的角度来看,问题就在下一个:服务器可以向我发送带有单行“待处理”的响应,这意味着它需要更多时间来准备正确的响应。我试图增加客户时间,但它不起作用client := http.Client{ Timeout: 10 * time.Second,}接下来是带有go例程和通道/等待组的想法:他们强制Get请求等待获取正确的数据,而不是“待定”和503状态代码import ( "encoding/json" "errors" "fmt" "io/ioutil" "log" "net/http" "sync")type KibanaReportResponse struct { Path string `json:"path"`}var urlKibanaBase = "http://localhost:5601"var urlKibanaPost = urlKibanaBase + "/api/reporting/generate/csv_searchsource?"var urlParameters = "jobParams=%28browserTimezone%3AEurope%2FBerlin%2Ccolumns%3A%21%28%29%2CobjectType%3Asearch%2CsearchSource%3A%28fields%3A%21%28%28field%3A%27%2A%27%2Cinclude_unmapped%3Atrue%29%29%2Cindex%3Aec074c00-1f62-11ec-8056-8d208a1f6e77%2Cparent%3A%28filter%3A%21%28%29%2Cindex%3Aec074c00-1f62-11ec-8056-8d208a1f6e77%2Cquery%3A%28language%3Akuery%2Cquery%3A%27%27%29%29%2Csort%3A%21%28%28_score%3Adesc%29%29%2CtrackTotalHits%3A%21t%2Cversion%3A%21t%29%2Ctitle%3A%27Discover%20search%20%5B2021-09-27T09%3A19%3A44.977%2B02%3A00%5D%27%29"var urlWithParam = urlKibanaPost + urlParametersfunc main() { var wg sync.WaitGroup wg.Add(1) pathCsvFile := getCsvPathFromKibana(urlWithParam) go getCsvFile(urlKibanaBase, pathCsvFile, &wg) defer wg.Wait()}func getCsvPathFromKibana(urlKib string) string { resKibana := KibanaReportResponse{} client := &http.Client{} if req, err := http.NewRequest("POST", urlKib, nil); err != nil { log.Println("Given a method, URL, andoptional body are wrong", err) }
1 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
Kibana 服务器需要一些时间来准备响应。我添加了一些代码,用于向通道发出信号,以等待一段时间,并在等待向客户端重复请求后再等待
if res.StatusCode != 200 { time.Sleep(30 * time.Second) }
- 1 回答
- 0 关注
- 588 浏览
添加回答
举报
0/150
提交
取消