Datasource: Shared HTTP client provider for core backend data sources and any data source using the data source proxy (#33439)
Uses new httpclient package from grafana-plugin-sdk-go introduced via grafana/grafana-plugin-sdk-go#328. Replaces the GetHTTPClient, GetTransport, GetTLSConfig methods defined on DataSource model. Longer-term the goal is to migrate core HTTP backend data sources to use the SDK contracts and using httpclient.Provider for creating HTTP clients and such. Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
co-authored by
Arve Knudsen
parent
7a83d1f9ff
commit
348e76fc8e
@@ -0,0 +1,2 @@
|
||||
ORIGIN_SERVER=http://localhost:9090/
|
||||
SLEEP_DURATION=60s
|
||||
@@ -4,4 +4,5 @@
|
||||
ports:
|
||||
- "3011:3011"
|
||||
environment:
|
||||
ORIGIN_SERVER: "http://localhost:9090/"
|
||||
ORIGIN_SERVER: ${ORIGIN_SERVER}
|
||||
SLEEP_DURATION: ${SLEEP_DURATION}
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -16,13 +15,21 @@ func main() {
|
||||
origin = "http://localhost:9090/"
|
||||
}
|
||||
|
||||
sleep := time.Minute
|
||||
sleepDurationStr := os.Getenv("SLEEP_DURATION")
|
||||
if sleepDurationStr == "" {
|
||||
sleepDurationStr = "60s"
|
||||
}
|
||||
|
||||
sleep, err := time.ParseDuration(sleepDurationStr)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to parse SLEEP_DURATION: %v", err)
|
||||
}
|
||||
|
||||
originURL, _ := url.Parse(origin)
|
||||
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("sleeping for %s then proxying request: %s", sleep.String(), r.RequestURI)
|
||||
log.Printf("sleeping for %s then proxying request: url '%s', headers: '%v'", sleep.String(), r.RequestURI, r.Header)
|
||||
<-time.After(sleep)
|
||||
proxy.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user