Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 0.4.3 #44

Merged
merged 9 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
.idea

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go

go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- 1.14.x

sudo: false

Expand Down
4 changes: 4 additions & 0 deletions appinsights/configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package appinsights

import (
"net/http"
"os"
"runtime"
"time"
Expand All @@ -21,6 +22,9 @@ type TelemetryConfiguration struct {

// Maximum time to wait before sending a batch of telemetry.
MaxBatchInterval time.Duration

// Customized http client if desired (will use http.DefaultClient otherwise)
Client *http.Client
}

// Creates a new TelemetryConfiguration object with the specified
Expand Down
4 changes: 4 additions & 0 deletions appinsights/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ func TestTelemetryConfiguration(t *testing.T) {
if config.EndpointUrl != defaultEndpoint {
t.Errorf("EndpointUrl is %s, want %s", config.EndpointUrl, defaultEndpoint)
}

if config.Client != nil {
t.Errorf("Client is not nil, want nil")
}
}
2 changes: 1 addition & 1 deletion appinsights/inmemorychannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewInMemoryChannel(config *TelemetryConfiguration) *InMemoryChannel {
batchSize: config.MaxBatchSize,
batchInterval: config.MaxBatchInterval,
throttle: newThrottleManager(),
transmitter: newTransmitter(config.EndpointUrl),
transmitter: newTransmitter(config.EndpointUrl, config.Client),
}

go channel.acceptLoop()
Expand Down
2 changes: 1 addition & 1 deletion appinsights/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package appinsights

const (
sdkName = "go"
Version = "0.4.2"
Version = "0.4.3"
)
11 changes: 7 additions & 4 deletions appinsights/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type transmitter interface {

type httpTransmitter struct {
endpoint string
client *http.Client
}

type transmissionResult struct {
Expand Down Expand Up @@ -50,8 +51,11 @@ const (
serviceUnavailableResponse = 503
)

func newTransmitter(endpointAddress string) transmitter {
return &httpTransmitter{endpointAddress}
func newTransmitter(endpointAddress string, client *http.Client) transmitter {
if client == nil {
client = http.DefaultClient
}
return &httpTransmitter{endpointAddress, client}
}

func (transmitter *httpTransmitter) Transmit(payload []byte, items telemetryBufferItems) (*transmissionResult, error) {
Expand All @@ -78,8 +82,7 @@ func (transmitter *httpTransmitter) Transmit(payload []byte, items telemetryBuff
req.Header.Set("Content-Type", "application/x-json-stream")
req.Header.Set("Accept-Encoding", "gzip, deflate")

client := http.DefaultClient
resp, err := client.Do(req)
resp, err := transmitter.client.Do(req)
if err != nil {
diagnosticsWriter.Printf("Failed to transmit telemetry: %s", err.Error())
return nil, err
Expand Down
29 changes: 28 additions & 1 deletion appinsights/transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,45 @@ func newTestClientServer() (transmitter, *testServer) {
server.responseData = make([]byte, 0)
server.responseHeaders = make(map[string]string)

client := newTransmitter(fmt.Sprintf("http://%s/v2/track", server.server.Listener.Addr().String()))
client := newTransmitter(fmt.Sprintf("http://%s/v2/track", server.server.Listener.Addr().String()), nil)

return client, server
}

func newTestTlsClientServer(t *testing.T) (transmitter, *testServer) {
server := &testServer{}
server.server = httptest.NewTLSServer(server)
server.notify = make(chan *testRequest, 1)
server.responseCode = 200
server.responseData = make([]byte, 0)
server.responseHeaders = make(map[string]string)

client := newTransmitter(fmt.Sprintf("https://%s/v2/track", server.server.Listener.Addr().String()), server.server.Client())

return client, server
}

func TestBasicTransitTls(t *testing.T) {
client, server := newTestTlsClientServer(t)

doBasicTransmit(client, server, t)
}

func TestBasicTransmit(t *testing.T) {
client, server := newTestClientServer()

doBasicTransmit(client, server, t)
}

func doBasicTransmit(client transmitter, server *testServer, t *testing.T) {
defer server.Close()

server.responseData = []byte(`{"itemsReceived":3, "itemsAccepted":5, "errors":[]}`)
server.responseHeaders["Content-type"] = "application/json"
result, err := client.Transmit([]byte("foobar"), make(telemetryBufferItems, 0))
if err != nil {
fmt.Println(err.Error())
}
req := server.waitForRequest(t)

if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/microsoft/ApplicationInsights-Go

go 1.12

require (
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c
github.com/kr/pretty v0.1.0 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/satori/go.uuid v1.2.0
github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
39 changes: 39 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c h1:5eeuG0BHx1+DHeT3AP+ISKZ2ht1UjGhm581ljqYpVeQ=
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc h1:LUUe4cdABGrIJAhl1P1ZpWY76AwukVszFdwkVFVLwIk=
github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
1 change: 0 additions & 1 deletion vendor/code.cloudfoundry.org/clock
Submodule clock deleted from 226916
1 change: 0 additions & 1 deletion vendor/github.com/satori/go.uuid
Submodule go.uuid deleted from 36e9d2