Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chore/unify-instr…
Browse files Browse the repository at this point in the history
…umentation
  • Loading branch information
XSAM committed Aug 27, 2020
2 parents e8eef93 + 1f7546c commit 864a47c
Show file tree
Hide file tree
Showing 27 changed files with 1,379 additions and 134 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Benchmark tests for the gRPC instrumentation. (#296)
- Integration testing for the gRPC instrumentation. (#297)

### Changed

- Unify instrumentation about provider options for `go.mongodb.org/mongo-driver`, `gin-gonic/gin`, `gorilla/mux`,
Expand Down
2 changes: 1 addition & 1 deletion detectors/aws/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.opentelemetry.io/contrib/detectors/aws
go 1.14

require (
github.com/aws/aws-sdk-go v1.34.9
github.com/aws/aws-sdk-go v1.34.10
go.opentelemetry.io/otel v0.11.0
go.opentelemetry.io/otel/sdk v0.11.0
)
4 changes: 2 additions & 2 deletions detectors/aws/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/sketches-go v0.0.1/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60=
github.com/aws/aws-sdk-go v1.34.9 h1:cUGBW9CVdi0mS7K1hDzxIqTpfeWhpoQiguq81M1tjK0=
github.com/aws/aws-sdk-go v1.34.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.10 h1:VU78gcf/3wA4HNEDCHidK738l7K0Bals4SJnfnvXOtY=
github.com/aws/aws-sdk-go v1.34.10/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
91 changes: 91 additions & 0 deletions exporters/metric/cortex/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
package cortex

import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"strconv"
"time"
)

// ErrFailedToReadFile occurs when a password / bearer token file exists, but could
Expand Down Expand Up @@ -88,3 +93,89 @@ func (e *Exporter) addBearerTokenAuth(req *http.Request) error {

return nil
}

// buildClient returns a http client that uses TLS and has the user-specified proxy and
// timeout.
func (e *Exporter) buildClient() (*http.Client, error) {
// Create a TLS Config struct for use in a custom HTTP Transport.
tlsConfig, err := e.buildTLSConfig()
if err != nil {
return nil, err
}

// Create a custom HTTP Transport for the client. This is the same as
// http.DefaultTransport other than the TLSClientConfig.
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: tlsConfig,
}

// Convert proxy url to proxy function for use in the created Transport.
if e.config.ProxyURL != nil {
proxy := http.ProxyURL(e.config.ProxyURL)
transport.Proxy = proxy
}

client := http.Client{
Transport: transport,
Timeout: e.config.RemoteTimeout,
}
return &client, nil
}

// buildTLSConfig creates a new TLS Config struct with the properties from the exporter's
// Config struct.
func (e *Exporter) buildTLSConfig() (*tls.Config, error) {
tlsConfig := &tls.Config{}
if e.config.TLSConfig == nil {
return tlsConfig, nil
}

// Set the server name if it exists.
if e.config.TLSConfig["server_name"] != "" {
tlsConfig.ServerName = e.config.TLSConfig["server_name"]
}

// Set InsecureSkipVerify. Viper reads the bool as a string since it is in a map.
if isv, ok := e.config.TLSConfig["insecure_skip_verify"]; ok {
var err error
if tlsConfig.InsecureSkipVerify, err = strconv.ParseBool(isv); err != nil {
return nil, err
}
}

// Load certificates from CA file if it exists.
caFile := e.config.TLSConfig["ca_file"]
if caFile != "" {
caFileData, err := ioutil.ReadFile(caFile)
if err != nil {
return nil, err
}
certPool := x509.NewCertPool()
certPool.AppendCertsFromPEM(caFileData)
tlsConfig.RootCAs = certPool
}

// Load the client certificate if it exists.
certFile := e.config.TLSConfig["cert_file"]
keyFile := e.config.TLSConfig["key_file"]
if certFile != "" && keyFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return nil, err
}
tlsConfig.Certificates = []tls.Certificate{cert}
}

return tlsConfig, nil
}
Loading

0 comments on commit 864a47c

Please sign in to comment.