我嘗試通過(guò)發(fā)出獲取請(qǐng)求從 kibana 服務(wù)器獲取 csv 數(shù)據(jù)。在此服務(wù)器向我發(fā)送帶有數(shù)據(jù)的響應(yīng)后,我編寫csv文件并保存在某個(gè)地方。每次 csv 文件都有一行“掛起”。Kibana日志顯示狀態(tài)代碼503但是如果我把網(wǎng)址放在瀏覽器中,我可以得到帶有正確數(shù)據(jù)的csv文件。可能我需要等待更多來(lái)自基巴納的回應(yīng)。從我的角度來(lái)看,問(wèn)題就在下一個(gè):服務(wù)器可以向我發(fā)送帶有單行“待處理”的響應(yīng),這意味著它需要更多時(shí)間來(lái)準(zhǔn)備正確的響應(yīng)。我試圖增加客戶時(shí)間,但它不起作用client := http.Client{ Timeout: 10 * time.Second,}接下來(lái)是帶有g(shù)o例程和通道/等待組的想法:他們強(qiáng)制Get請(qǐng)求等待獲取正確的數(shù)據(jù),而不是“待定”和503狀態(tài)代碼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) }
發(fā)出 Get 請(qǐng)求后,Golang 程序返回 HTTP 狀態(tài)代碼 503 或掛起
長(zhǎng)風(fēng)秋雁
2022-10-04 17:05:51