OpenTracing for Fission (#1079)
Added Opentracing integration using opencensus libraries for all Fission components.
This commit is contained in:
@@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -9,18 +10,25 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
"github.com/fission/fission"
|
||||
)
|
||||
|
||||
type (
|
||||
Client struct {
|
||||
url string
|
||||
url string
|
||||
httpClient *http.Client
|
||||
}
|
||||
)
|
||||
|
||||
func MakeClient(fetcherUrl string) *Client {
|
||||
return &Client{
|
||||
url: strings.TrimSuffix(fetcherUrl, "/"),
|
||||
httpClient: &http.Client{
|
||||
Transport: &ochttp.Transport{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +44,18 @@ func (c *Client) getUploadUrl() string {
|
||||
return c.url + "/upload"
|
||||
}
|
||||
|
||||
func (c *Client) Specialize(req *fission.FunctionSpecializeRequest) error {
|
||||
_, err := sendRequest(req, c.getSpecializeUrl())
|
||||
func (c *Client) Specialize(ctx context.Context, req *fission.FunctionSpecializeRequest) error {
|
||||
_, err := sendRequest(ctx, c.httpClient, req, c.getSpecializeUrl())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Fetch(fr *fission.FunctionFetchRequest) error {
|
||||
_, err := sendRequest(fr, c.getFetchUrl())
|
||||
func (c *Client) Fetch(ctx context.Context, fr *fission.FunctionFetchRequest) error {
|
||||
_, err := sendRequest(ctx, c.httpClient, fr, c.getFetchUrl())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Upload(fr *fission.ArchiveUploadRequest) (*fission.ArchiveUploadResponse, error) {
|
||||
body, err := sendRequest(fr, c.getUploadUrl())
|
||||
func (c *Client) Upload(ctx context.Context, fr *fission.ArchiveUploadRequest) (*fission.ArchiveUploadResponse, error) {
|
||||
body, err := sendRequest(ctx, c.httpClient, fr, c.getUploadUrl())
|
||||
|
||||
uploadResp := fission.ArchiveUploadResponse{}
|
||||
err = json.Unmarshal(body, &uploadResp)
|
||||
@@ -58,7 +66,7 @@ func (c *Client) Upload(fr *fission.ArchiveUploadRequest) (*fission.ArchiveUploa
|
||||
return &uploadResp, nil
|
||||
}
|
||||
|
||||
func sendRequest(req interface{}, url string) ([]byte, error) {
|
||||
func sendRequest(ctx context.Context, httpClient *http.Client, req interface{}, url string) ([]byte, error) {
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -68,7 +76,7 @@ func sendRequest(req interface{}, url string) ([]byte, error) {
|
||||
var resp *http.Response
|
||||
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
resp, err = http.Post(url, "application/json", bytes.NewReader(body))
|
||||
resp, err = ctxhttp.Post(ctx, httpClient, url, "application/json", bytes.NewReader(body))
|
||||
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
|
||||
Reference in New Issue
Block a user