@@ -3,16 +3,50 @@ package skywalking
33import (
44 "context"
55 "fmt"
6+ "io/ioutil"
67 "net/http"
8+ "sync"
79 "testing"
810
911 "github.com/OpenFunction/functions-framework-go/framework"
1012 "github.com/OpenFunction/functions-framework-go/plugin"
13+ "github.com/SkyAPM/go2sky"
14+ httpP "github.com/SkyAPM/go2sky/plugins/http"
15+ "k8s.io/klog/v2"
1116)
1217
18+ var (
19+ initHttpClientOnce sync.Once
20+ client * http.Client
21+ )
22+
23+ func initHTTPClient () {
24+ initHttpClientOnce .Do (func () {
25+ client , _ = httpP .NewClient (go2sky .GetGlobalTracer ())
26+ })
27+ }
28+
1329// HelloWorld writes "Hello, World!" to the HTTP response.
1430func HelloWorldWithHttp (w http.ResponseWriter , r * http.Request ) error {
15- fmt .Fprint (w , "Hello, World!\n " )
31+ initHTTPClient ()
32+ // call end service
33+ request , err := http .NewRequest ("POST" , fmt .Sprintf ("%s/correlation" , "http://127.0.0.1:9090" ), nil )
34+ if err != nil {
35+ klog .Errorf ("unable to create http request: %+v\n " , err )
36+ return err
37+ }
38+
39+ request = request .WithContext (r .Context ())
40+ res , err := client .Do (request )
41+ if err != nil {
42+ return err
43+ }
44+ body , err := ioutil .ReadAll (res .Body )
45+ if err != nil {
46+ return err
47+ }
48+ defer res .Body .Close ()
49+ fmt .Fprint (w , string (body ))
1650 return nil
1751}
1852
@@ -37,14 +71,15 @@ func TestHTTP(t *testing.T) {
3771 "tag2": "value2"
3872 },
3973 "baggage": {
40- "key": "sw8-correlation ",
41- "value": "base64(string key):base64(string value),base64(string key2):base64(string value2) "
74+ "key": "CONSUMER_KEY ",
75+ "value": "test "
4276 }
4377 }
4478}
4579` )
46- t .Setenv ("POD_NAME" , "prometheus-node-exporter -vhct4" )
80+ t .Setenv ("POD_NAME" , "function-test -vhct4" )
4781 t .Setenv ("POD_NAMESPACE" , "test" )
82+ t .Setenv ("SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL" , "-1" )
4883 ctx := context .Background ()
4984 fwk , err := framework .NewFramework ()
5085 if err != nil {
0 commit comments