Update go dependencies (#4322)
This commit is contained in:
parent
28cc3bb5e2
commit
a54ab3341e
507 changed files with 50566 additions and 40414 deletions
17
vendor/github.com/Azure/go-autorest/autorest/adal/token.go
generated
vendored
17
vendor/github.com/Azure/go-autorest/autorest/adal/token.go
generated
vendored
|
|
@ -34,7 +34,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Azure/go-autorest/autorest/date"
|
||||
"github.com/Azure/go-autorest/tracing"
|
||||
"github.com/Azure/go-autorest/version"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
|
|
@ -385,13 +385,8 @@ func (spt *ServicePrincipalToken) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Don't override the refreshLock or the sender if those have been already set.
|
||||
if spt.refreshLock == nil {
|
||||
spt.refreshLock = &sync.RWMutex{}
|
||||
}
|
||||
if spt.sender == nil {
|
||||
spt.sender = &http.Client{Transport: tracing.Transport}
|
||||
}
|
||||
spt.refreshLock = &sync.RWMutex{}
|
||||
spt.sender = &http.Client{}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +433,7 @@ func NewServicePrincipalTokenWithSecret(oauthConfig OAuthConfig, id string, reso
|
|||
RefreshWithin: defaultRefresh,
|
||||
},
|
||||
refreshLock: &sync.RWMutex{},
|
||||
sender: &http.Client{Transport: tracing.Transport},
|
||||
sender: &http.Client{},
|
||||
refreshCallbacks: callbacks,
|
||||
}
|
||||
return spt, nil
|
||||
|
|
@ -679,7 +674,7 @@ func newServicePrincipalTokenFromMSI(msiEndpoint, resource string, userAssignedI
|
|||
RefreshWithin: defaultRefresh,
|
||||
},
|
||||
refreshLock: &sync.RWMutex{},
|
||||
sender: &http.Client{Transport: tracing.Transport},
|
||||
sender: &http.Client{},
|
||||
refreshCallbacks: callbacks,
|
||||
MaxMSIRefreshAttempts: defaultMaxMSIRefreshAttempts,
|
||||
}
|
||||
|
|
@ -796,7 +791,7 @@ func (spt *ServicePrincipalToken) refreshInternal(ctx context.Context, resource
|
|||
if err != nil {
|
||||
return fmt.Errorf("adal: Failed to build the refresh request. Error = '%v'", err)
|
||||
}
|
||||
req.Header.Add("User-Agent", UserAgent())
|
||||
req.Header.Add("User-Agent", version.UserAgent())
|
||||
req = req.WithContext(ctx)
|
||||
if !isIMDS(spt.inner.OauthConfig.TokenEndpoint) {
|
||||
v := url.Values{}
|
||||
|
|
|
|||
32
vendor/github.com/Azure/go-autorest/autorest/authorization.go
generated
vendored
32
vendor/github.com/Azure/go-autorest/autorest/authorization.go
generated
vendored
|
|
@ -15,14 +15,12 @@ package autorest
|
|||
// limitations under the License.
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/go-autorest/autorest/adal"
|
||||
"github.com/Azure/go-autorest/tracing"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -32,8 +30,6 @@ const (
|
|||
apiKeyAuthorizerHeader = "Ocp-Apim-Subscription-Key"
|
||||
bingAPISdkHeader = "X-BingApis-SDK-Client"
|
||||
golangBingAPISdkHeaderValue = "Go-SDK"
|
||||
authorization = "Authorization"
|
||||
basic = "Basic"
|
||||
)
|
||||
|
||||
// Authorizer is the interface that provides a PrepareDecorator used to supply request
|
||||
|
|
@ -72,7 +68,7 @@ func NewAPIKeyAuthorizer(headers map[string]interface{}, queryParameters map[str
|
|||
return &APIKeyAuthorizer{headers: headers, queryParameters: queryParameters}
|
||||
}
|
||||
|
||||
// WithAuthorization returns a PrepareDecorator that adds an HTTP headers and Query Parameters.
|
||||
// WithAuthorization returns a PrepareDecorator that adds an HTTP headers and Query Paramaters
|
||||
func (aka *APIKeyAuthorizer) WithAuthorization() PrepareDecorator {
|
||||
return func(p Preparer) Preparer {
|
||||
return DecoratePreparer(p, WithHeaders(aka.headers), WithQueryParameters(aka.queryParameters))
|
||||
|
|
@ -151,7 +147,7 @@ type BearerAuthorizerCallback struct {
|
|||
// is invoked when the HTTP request is submitted.
|
||||
func NewBearerAuthorizerCallback(sender Sender, callback BearerAuthorizerCallbackFunc) *BearerAuthorizerCallback {
|
||||
if sender == nil {
|
||||
sender = &http.Client{Transport: tracing.Transport}
|
||||
sender = &http.Client{}
|
||||
}
|
||||
return &BearerAuthorizerCallback{sender: sender, callback: callback}
|
||||
}
|
||||
|
|
@ -261,27 +257,3 @@ func (egta EventGridKeyAuthorizer) WithAuthorization() PrepareDecorator {
|
|||
}
|
||||
return NewAPIKeyAuthorizerWithHeaders(headers).WithAuthorization()
|
||||
}
|
||||
|
||||
// BasicAuthorizer implements basic HTTP authorization by adding the Authorization HTTP header
|
||||
// with the value "Basic <TOKEN>" where <TOKEN> is a base64-encoded username:password tuple.
|
||||
type BasicAuthorizer struct {
|
||||
userName string
|
||||
password string
|
||||
}
|
||||
|
||||
// NewBasicAuthorizer creates a new BasicAuthorizer with the specified username and password.
|
||||
func NewBasicAuthorizer(userName, password string) *BasicAuthorizer {
|
||||
return &BasicAuthorizer{
|
||||
userName: userName,
|
||||
password: password,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose
|
||||
// value is "Basic " followed by the base64-encoded username:password tuple.
|
||||
func (ba *BasicAuthorizer) WithAuthorization() PrepareDecorator {
|
||||
headers := make(map[string]interface{})
|
||||
headers[authorization] = basic + " " + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", ba.userName, ba.password)))
|
||||
|
||||
return NewAPIKeyAuthorizerWithHeaders(headers).WithAuthorization()
|
||||
}
|
||||
|
|
|
|||
20
vendor/github.com/Azure/go-autorest/autorest/azure/async.go
generated
vendored
20
vendor/github.com/Azure/go-autorest/autorest/azure/async.go
generated
vendored
|
|
@ -26,7 +26,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Azure/go-autorest/autorest"
|
||||
"github.com/Azure/go-autorest/tracing"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -94,16 +93,6 @@ func (f *Future) Done(sender autorest.Sender) (bool, error) {
|
|||
|
||||
// DoneWithContext queries the service to see if the operation has completed.
|
||||
func (f *Future) DoneWithContext(ctx context.Context, sender autorest.Sender) (done bool, err error) {
|
||||
ctx = tracing.StartSpan(ctx, "github.com/Azure/go-autorest/autorest/azure/async.DoneWithContext")
|
||||
defer func() {
|
||||
sc := -1
|
||||
resp := f.Response()
|
||||
if resp != nil {
|
||||
sc = resp.StatusCode
|
||||
}
|
||||
tracing.EndSpan(ctx, sc, err)
|
||||
}()
|
||||
|
||||
// support for legacy Future implementation
|
||||
if f.req != nil {
|
||||
resp, err := sender.Do(f.req)
|
||||
|
|
@ -186,15 +175,6 @@ func (f Future) WaitForCompletion(ctx context.Context, client autorest.Client) e
|
|||
// If PollingDuration is greater than zero the value will be used as the context's timeout.
|
||||
// If PollingDuration is zero then no default deadline will be used.
|
||||
func (f *Future) WaitForCompletionRef(ctx context.Context, client autorest.Client) (err error) {
|
||||
ctx = tracing.StartSpan(ctx, "github.com/Azure/go-autorest/autorest/azure/async.WaitForCompletionRef")
|
||||
defer func() {
|
||||
sc := -1
|
||||
resp := f.Response()
|
||||
if resp != nil {
|
||||
sc = resp.StatusCode
|
||||
}
|
||||
tracing.EndSpan(ctx, sc, err)
|
||||
}()
|
||||
cancelCtx := ctx
|
||||
// if the provided context already has a deadline don't override it
|
||||
_, hasDeadline := ctx.Deadline()
|
||||
|
|
|
|||
13
vendor/github.com/Azure/go-autorest/autorest/azure/environments.go
generated
vendored
13
vendor/github.com/Azure/go-autorest/autorest/azure/environments.go
generated
vendored
|
|
@ -54,7 +54,6 @@ type Environment struct {
|
|||
ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"`
|
||||
ResourceManagerVMDNSSuffix string `json:"resourceManagerVMDNSSuffix"`
|
||||
ContainerRegistryDNSSuffix string `json:"containerRegistryDNSSuffix"`
|
||||
CosmosDBDNSSuffix string `json:"cosmosDBDNSSuffix"`
|
||||
TokenAudience string `json:"tokenAudience"`
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +79,6 @@ var (
|
|||
ServiceManagementVMDNSSuffix: "cloudapp.net",
|
||||
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
|
||||
ContainerRegistryDNSSuffix: "azurecr.io",
|
||||
CosmosDBDNSSuffix: "documents.azure.com",
|
||||
TokenAudience: "https://management.azure.com/",
|
||||
}
|
||||
|
||||
|
|
@ -104,8 +102,7 @@ var (
|
|||
ServiceBusEndpointSuffix: "servicebus.usgovcloudapi.net",
|
||||
ServiceManagementVMDNSSuffix: "usgovcloudapp.net",
|
||||
ResourceManagerVMDNSSuffix: "cloudapp.windowsazure.us",
|
||||
ContainerRegistryDNSSuffix: "azurecr.us",
|
||||
CosmosDBDNSSuffix: "documents.azure.us",
|
||||
ContainerRegistryDNSSuffix: "azurecr.io",
|
||||
TokenAudience: "https://management.usgovcloudapi.net/",
|
||||
}
|
||||
|
||||
|
|
@ -129,8 +126,7 @@ var (
|
|||
ServiceBusEndpointSuffix: "servicebus.chinacloudapi.cn",
|
||||
ServiceManagementVMDNSSuffix: "chinacloudapp.cn",
|
||||
ResourceManagerVMDNSSuffix: "cloudapp.azure.cn",
|
||||
ContainerRegistryDNSSuffix: "azurecr.cn",
|
||||
CosmosDBDNSSuffix: "documents.azure.cn",
|
||||
ContainerRegistryDNSSuffix: "azurecr.io",
|
||||
TokenAudience: "https://management.chinacloudapi.cn/",
|
||||
}
|
||||
|
||||
|
|
@ -154,9 +150,8 @@ var (
|
|||
ServiceBusEndpointSuffix: "servicebus.cloudapi.de",
|
||||
ServiceManagementVMDNSSuffix: "azurecloudapp.de",
|
||||
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
|
||||
// ContainerRegistryDNSSuffix: "", ACR not present yet in the German Cloud
|
||||
CosmosDBDNSSuffix: "documents.microsoftazure.de",
|
||||
TokenAudience: "https://management.microsoftazure.de/",
|
||||
ContainerRegistryDNSSuffix: "azurecr.io",
|
||||
TokenAudience: "https://management.microsoftazure.de/",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
23
vendor/github.com/Azure/go-autorest/autorest/client.go
generated
vendored
23
vendor/github.com/Azure/go-autorest/autorest/client.go
generated
vendored
|
|
@ -16,7 +16,6 @@ package autorest
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
@ -27,7 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Azure/go-autorest/logger"
|
||||
"github.com/Azure/go-autorest/tracing"
|
||||
"github.com/Azure/go-autorest/version"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -175,7 +174,7 @@ func NewClientWithUserAgent(ua string) Client {
|
|||
PollingDuration: DefaultPollingDuration,
|
||||
RetryAttempts: DefaultRetryAttempts,
|
||||
RetryDuration: DefaultRetryDuration,
|
||||
UserAgent: UserAgent(),
|
||||
UserAgent: version.UserAgent(),
|
||||
}
|
||||
c.Sender = c.sender()
|
||||
c.AddToUserAgent(ua)
|
||||
|
|
@ -230,25 +229,9 @@ func (c Client) Do(r *http.Request) (*http.Response, error) {
|
|||
// sender returns the Sender to which to send requests.
|
||||
func (c Client) sender() Sender {
|
||||
if c.Sender == nil {
|
||||
// Use behaviour compatible with DefaultTransport, but require TLS minimum version.
|
||||
var defaultTransport = http.DefaultTransport.(*http.Transport)
|
||||
|
||||
tracing.Transport.Base = &http.Transport{
|
||||
Proxy: defaultTransport.Proxy,
|
||||
DialContext: defaultTransport.DialContext,
|
||||
MaxIdleConns: defaultTransport.MaxIdleConns,
|
||||
IdleConnTimeout: defaultTransport.IdleConnTimeout,
|
||||
TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout,
|
||||
ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout,
|
||||
TLSClientConfig: &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
},
|
||||
}
|
||||
|
||||
j, _ := cookiejar.New(nil)
|
||||
return &http.Client{Jar: j, Transport: tracing.Transport}
|
||||
return &http.Client{Jar: j}
|
||||
}
|
||||
|
||||
return c.Sender
|
||||
}
|
||||
|
||||
|
|
|
|||
9
vendor/github.com/Azure/go-autorest/autorest/sender.go
generated
vendored
9
vendor/github.com/Azure/go-autorest/autorest/sender.go
generated
vendored
|
|
@ -21,8 +21,6 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-autorest/tracing"
|
||||
)
|
||||
|
||||
// Sender is the interface that wraps the Do method to send HTTP requests.
|
||||
|
|
@ -40,7 +38,7 @@ func (sf SenderFunc) Do(r *http.Request) (*http.Response, error) {
|
|||
return sf(r)
|
||||
}
|
||||
|
||||
// SendDecorator takes and possibly decorates, by wrapping, a Sender. Decorators may affect the
|
||||
// SendDecorator takes and possibily decorates, by wrapping, a Sender. Decorators may affect the
|
||||
// http.Request and pass it along or, first, pass the http.Request along then react to the
|
||||
// http.Response result.
|
||||
type SendDecorator func(Sender) Sender
|
||||
|
|
@ -70,7 +68,7 @@ func DecorateSender(s Sender, decorators ...SendDecorator) Sender {
|
|||
//
|
||||
// Send will not poll or retry requests.
|
||||
func Send(r *http.Request, decorators ...SendDecorator) (*http.Response, error) {
|
||||
return SendWithSender(&http.Client{Transport: tracing.Transport}, r, decorators...)
|
||||
return SendWithSender(&http.Client{}, r, decorators...)
|
||||
}
|
||||
|
||||
// SendWithSender sends the passed http.Request, through the provided Sender, returning the
|
||||
|
|
@ -218,7 +216,8 @@ func DoRetryForStatusCodes(attempts int, backoff time.Duration, codes ...int) Se
|
|||
return SenderFunc(func(r *http.Request) (resp *http.Response, err error) {
|
||||
rr := NewRetriableRequest(r)
|
||||
// Increment to add the first call (attempts denotes number of retries)
|
||||
for attempt := 0; attempt < attempts+1; {
|
||||
attempts++
|
||||
for attempt := 0; attempt < attempts; {
|
||||
err = rr.Prepare()
|
||||
if err != nil {
|
||||
return resp, err
|
||||
|
|
|
|||
2
vendor/github.com/Azure/go-autorest/autorest/utility.go
generated
vendored
2
vendor/github.com/Azure/go-autorest/autorest/utility.go
generated
vendored
|
|
@ -157,7 +157,7 @@ func AsStringSlice(s interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
// String method converts interface v to string. If interface is a list, it
|
||||
// joins list elements using the separator. Note that only sep[0] will be used for
|
||||
// joins list elements using the seperator. Note that only sep[0] will be used for
|
||||
// joining if any separator is specified.
|
||||
func String(v interface{}, sep ...string) string {
|
||||
if len(sep) == 0 {
|
||||
|
|
|
|||
25
vendor/github.com/Azure/go-autorest/autorest/version.go
generated
vendored
25
vendor/github.com/Azure/go-autorest/autorest/version.go
generated
vendored
|
|
@ -1,5 +1,7 @@
|
|||
package autorest
|
||||
|
||||
import "github.com/Azure/go-autorest/version"
|
||||
|
||||
// Copyright 2017 Microsoft Corporation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,28 +16,7 @@ package autorest
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const number = "v11.7.1"
|
||||
|
||||
var (
|
||||
userAgent = fmt.Sprintf("Go/%s (%s-%s) go-autorest/%s",
|
||||
runtime.Version(),
|
||||
runtime.GOARCH,
|
||||
runtime.GOOS,
|
||||
number,
|
||||
)
|
||||
)
|
||||
|
||||
// UserAgent returns a string containing the Go version, system architecture and OS, and the go-autorest version.
|
||||
func UserAgent() string {
|
||||
return userAgent
|
||||
}
|
||||
|
||||
// Version returns the semantic version (see http://semver.org).
|
||||
func Version() string {
|
||||
return number
|
||||
return version.Number
|
||||
}
|
||||
|
|
|
|||
4
vendor/github.com/Azure/go-autorest/logger/logger.go
generated
vendored
4
vendor/github.com/Azure/go-autorest/logger/logger.go
generated
vendored
|
|
@ -162,7 +162,7 @@ type Writer interface {
|
|||
// WriteResponse writes the specified HTTP response to the logger if the log level is greater than
|
||||
// or equal to LogInfo. The response body, if set, is logged at level LogDebug or higher.
|
||||
// Custom filters can be specified to exclude URL, header, and/or body content from the log.
|
||||
// By default no response content is excluded.
|
||||
// By default no respone content is excluded.
|
||||
WriteResponse(resp *http.Response, filter Filter)
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ func (fl fileLogger) WriteResponse(resp *http.Response, filter Filter) {
|
|||
// returns true if the provided body should be included in the log
|
||||
func (fl fileLogger) shouldLogBody(header http.Header, body io.ReadCloser) bool {
|
||||
ct := header.Get("Content-Type")
|
||||
return fl.logLevel >= LogDebug && body != nil && !strings.Contains(ct, "application/octet-stream")
|
||||
return fl.logLevel >= LogDebug && body != nil && strings.Index(ct, "application/octet-stream") == -1
|
||||
}
|
||||
|
||||
// creates standard header for log entries, it contains a timestamp and the log level
|
||||
|
|
|
|||
190
vendor/github.com/Azure/go-autorest/tracing/tracing.go
generated
vendored
190
vendor/github.com/Azure/go-autorest/tracing/tracing.go
generated
vendored
|
|
@ -1,190 +0,0 @@
|
|||
package tracing
|
||||
|
||||
// Copyright 2018 Microsoft Corporation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"contrib.go.opencensus.io/exporter/ocagent"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.opencensus.io/plugin/ochttp/propagation/tracecontext"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// Transport is the default tracing RoundTripper. The custom options setter will control
|
||||
// if traces are being emitted or not.
|
||||
Transport = &ochttp.Transport{
|
||||
Propagation: &tracecontext.HTTPFormat{},
|
||||
GetStartOptions: getStartOptions,
|
||||
}
|
||||
|
||||
// enabled is the flag for marking if tracing is enabled.
|
||||
enabled = false
|
||||
|
||||
// Sampler is the tracing sampler. If tracing is disabled it will never sample. Otherwise
|
||||
// it will be using the parent sampler or the default.
|
||||
sampler = trace.NeverSample()
|
||||
|
||||
// Views for metric instrumentation.
|
||||
views = map[string]*view.View{}
|
||||
|
||||
// the trace exporter
|
||||
traceExporter trace.Exporter
|
||||
)
|
||||
|
||||
func init() {
|
||||
enableFromEnv()
|
||||
}
|
||||
|
||||
func enableFromEnv() {
|
||||
_, ok := os.LookupEnv("AZURE_SDK_TRACING_ENABLED")
|
||||
_, legacyOk := os.LookupEnv("AZURE_SDK_TRACING_ENABELD")
|
||||
if ok || legacyOk {
|
||||
agentEndpoint, ok := os.LookupEnv("OCAGENT_TRACE_EXPORTER_ENDPOINT")
|
||||
|
||||
if ok {
|
||||
EnableWithAIForwarding(agentEndpoint)
|
||||
} else {
|
||||
Enable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsEnabled returns true if monitoring is enabled for the sdk.
|
||||
func IsEnabled() bool {
|
||||
return enabled
|
||||
}
|
||||
|
||||
// Enable will start instrumentation for metrics and traces.
|
||||
func Enable() error {
|
||||
enabled = true
|
||||
sampler = nil
|
||||
|
||||
err := initStats()
|
||||
return err
|
||||
}
|
||||
|
||||
// Disable will disable instrumentation for metrics and traces.
|
||||
func Disable() {
|
||||
disableStats()
|
||||
sampler = trace.NeverSample()
|
||||
if traceExporter != nil {
|
||||
trace.UnregisterExporter(traceExporter)
|
||||
}
|
||||
enabled = false
|
||||
}
|
||||
|
||||
// EnableWithAIForwarding will start instrumentation and will connect to app insights forwarder
|
||||
// exporter making the metrics and traces available in app insights.
|
||||
func EnableWithAIForwarding(agentEndpoint string) (err error) {
|
||||
err = Enable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
traceExporter, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithAddress(agentEndpoint))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
trace.RegisterExporter(traceExporter)
|
||||
return
|
||||
}
|
||||
|
||||
// getStartOptions is the custom options setter for the ochttp package.
|
||||
func getStartOptions(*http.Request) trace.StartOptions {
|
||||
return trace.StartOptions{
|
||||
Sampler: sampler,
|
||||
}
|
||||
}
|
||||
|
||||
// initStats registers the views for the http metrics
|
||||
func initStats() (err error) {
|
||||
clientViews := []*view.View{
|
||||
ochttp.ClientCompletedCount,
|
||||
ochttp.ClientRoundtripLatencyDistribution,
|
||||
ochttp.ClientReceivedBytesDistribution,
|
||||
ochttp.ClientSentBytesDistribution,
|
||||
}
|
||||
for _, cv := range clientViews {
|
||||
vn := fmt.Sprintf("Azure/go-autorest/tracing-%s", cv.Name)
|
||||
views[vn] = cv.WithName(vn)
|
||||
err = view.Register(views[vn])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// disableStats will unregister the previously registered metrics
|
||||
func disableStats() {
|
||||
for _, v := range views {
|
||||
view.Unregister(v)
|
||||
}
|
||||
}
|
||||
|
||||
// StartSpan starts a trace span
|
||||
func StartSpan(ctx context.Context, name string) context.Context {
|
||||
ctx, _ = trace.StartSpan(ctx, name, trace.WithSampler(sampler))
|
||||
return ctx
|
||||
}
|
||||
|
||||
// EndSpan ends a previously started span stored in the context
|
||||
func EndSpan(ctx context.Context, httpStatusCode int, err error) {
|
||||
span := trace.FromContext(ctx)
|
||||
|
||||
if span == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
span.SetStatus(trace.Status{Message: err.Error(), Code: toTraceStatusCode(httpStatusCode)})
|
||||
}
|
||||
span.End()
|
||||
}
|
||||
|
||||
// toTraceStatusCode converts HTTP Codes to OpenCensus codes as defined
|
||||
// at https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#status
|
||||
func toTraceStatusCode(httpStatusCode int) int32 {
|
||||
switch {
|
||||
case http.StatusOK <= httpStatusCode && httpStatusCode < http.StatusBadRequest:
|
||||
return trace.StatusCodeOK
|
||||
case httpStatusCode == http.StatusBadRequest:
|
||||
return trace.StatusCodeInvalidArgument
|
||||
case httpStatusCode == http.StatusUnauthorized: // 401 is actually unauthenticated.
|
||||
return trace.StatusCodeUnauthenticated
|
||||
case httpStatusCode == http.StatusForbidden:
|
||||
return trace.StatusCodePermissionDenied
|
||||
case httpStatusCode == http.StatusNotFound:
|
||||
return trace.StatusCodeNotFound
|
||||
case httpStatusCode == http.StatusTooManyRequests:
|
||||
return trace.StatusCodeResourceExhausted
|
||||
case httpStatusCode == 499:
|
||||
return trace.StatusCodeCancelled
|
||||
case httpStatusCode == http.StatusNotImplemented:
|
||||
return trace.StatusCodeUnimplemented
|
||||
case httpStatusCode == http.StatusServiceUnavailable:
|
||||
return trace.StatusCodeUnavailable
|
||||
case httpStatusCode == http.StatusGatewayTimeout:
|
||||
return trace.StatusCodeDeadlineExceeded
|
||||
default:
|
||||
return trace.StatusCodeUnknown
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,4 @@
|
|||
package adal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
package version
|
||||
|
||||
// Copyright 2017 Microsoft Corporation
|
||||
//
|
||||
|
|
@ -19,27 +14,24 @@ import (
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
const number = "v1.0.0"
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// Number contains the semantic version of this SDK.
|
||||
const Number = "v11.1.2"
|
||||
|
||||
var (
|
||||
ua = fmt.Sprintf("Go/%s (%s-%s) go-autorest/adal/%s",
|
||||
userAgent = fmt.Sprintf("Go/%s (%s-%s) go-autorest/%s",
|
||||
runtime.Version(),
|
||||
runtime.GOARCH,
|
||||
runtime.GOOS,
|
||||
number,
|
||||
Number,
|
||||
)
|
||||
)
|
||||
|
||||
// UserAgent returns a string containing the Go version, system architecture and OS, and the adal version.
|
||||
// UserAgent returns a string containing the Go version, system archityecture and OS, and the go-autorest version.
|
||||
func UserAgent() string {
|
||||
return ua
|
||||
}
|
||||
|
||||
// AddToUserAgent adds an extension to the current user agent
|
||||
func AddToUserAgent(extension string) error {
|
||||
if extension != "" {
|
||||
ua = fmt.Sprintf("%s %s", ua, extension)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Extension was empty, User Agent remained as '%s'", ua)
|
||||
return userAgent
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue