Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Remove metrics from loggregator_client
Browse files Browse the repository at this point in the history
[#82084598]

Signed-off-by: John Tuley <jtuley@pivotal.io>
  • Loading branch information
geapi authored and John Tuley committed Nov 6, 2014
1 parent f59ef77 commit c9192c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
33 changes: 13 additions & 20 deletions loggregatorclient/loggregator_client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package loggregatorclient

import (
"github.com/cloudfoundry/dropsonde/metrics"
"github.com/cloudfoundry/loggregatorlib/cfcomponent/generic_logger"
"github.com/cloudfoundry/loggregatorlib/cfcomponent/instrumentation"
"net"
Expand Down Expand Up @@ -45,25 +44,22 @@ func NewLoggregatorClient(loggregatorAddress string, logger generic_logger.Gener

go func() {
for dataToSend := range loggregatorClient.sendChannel {
metrics.SendValue("currentBufferCount", float64(len(loggregatorClient.sendChannel)), "Msg")

if len(dataToSend) > 0 {
writeCount, err := connection.WriteTo(dataToSend, la)
if err != nil {
logger.Errorf("Writing to loggregator %s failed %s", loggregatorAddress, err)
continue
}
logger.Debugf("Wrote %d bytes to %s", writeCount, loggregatorAddress)

atomic.AddUint64(&loggregatorClient.sentMessageCount, 1)
atomic.AddUint64(&loggregatorClient.sentByteCount, uint64(writeCount))

metrics.IncrementCounter("sentMessageCount")
metrics.AddToCounter("sentByteCount", uint64(writeCount))
} else {
if len(dataToSend) == 0 {
logger.Debugf("Skipped writing of 0 byte message to %s", loggregatorAddress)
continue
}

writeCount, err := connection.WriteTo(dataToSend, la)
if err != nil {
logger.Errorf("Writing to loggregator %s failed %s", loggregatorAddress, err)
continue
}
logger.Debugf("Wrote %d bytes to %s", writeCount, loggregatorAddress)

atomic.AddUint64(&loggregatorClient.sentMessageCount, 1)
atomic.AddUint64(&loggregatorClient.sentByteCount, uint64(writeCount))
}

close(loggregatorClient.doneChannel)
}()

Expand All @@ -80,10 +76,7 @@ func (loggregatorClient *udpLoggregatorClient) Send(data []byte) {
atomic.AddUint64(&loggregatorClient.receivedMessageCount, 1)
atomic.AddUint64(&loggregatorClient.receivedByteCount, uint64(len(data)))

metrics.IncrementCounter("receivedMessageCount")
metrics.AddToCounter("receivedByteCount", uint64(len(data)))
loggregatorClient.sendChannel <- data
metrics.SendValue("currentBufferCount", float64(len(loggregatorClient.sendChannel)), "Msg")
}

func (loggregatorClient *udpLoggregatorClient) metrics() []instrumentation.Metric {
Expand Down
14 changes: 0 additions & 14 deletions loggregatorclient/loggregator_client_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package loggregatorclient_test

import (
"github.com/cloudfoundry/dropsonde/metrics"
"github.com/cloudfoundry/gosteno"
"github.com/cloudfoundry/loggregatorlib/loggregatorclient"
"net"

"github.com/cloudfoundry/dropsonde/metric_sender/fake"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("loggregatorclient", func() {
var (
fakeMetricSender *fake.FakeMetricSender
loggregatorClient loggregatorclient.LoggregatorClient
udpListener *net.UDPConn
)

BeforeEach(func() {
fakeMetricSender = fake.NewFakeMetricSender()
metrics.Initialize(fakeMetricSender)

loggregatorClient = loggregatorclient.NewLoggregatorClient("localhost:9875", gosteno.NewLogger("TestLogger"), 0)

udpAddr, _ := net.ResolveUDPAddr("udp", "localhost:9875")
Expand Down Expand Up @@ -79,14 +73,6 @@ var _ = Describe("loggregatorclient", func() {
}
}
})

It("sends metrics using dropsonde", func() {
Expect(fakeMetricSender.GetValue("currentBufferCount")).To(Equal(fake.Metric{Value: 0, Unit: "Msg"}))
Expect(fakeMetricSender.GetCounter("sentMessageCount")).To(BeEquivalentTo(1))
Expect(fakeMetricSender.GetCounter("sentByteCount")).To(BeEquivalentTo(21))
Expect(fakeMetricSender.GetCounter("receivedMessageCount")).To(BeEquivalentTo(1))
Expect(fakeMetricSender.GetCounter("receivedByteCount")).To(BeEquivalentTo(21))
})
})

It("doesn't send empty data", func() {
Expand Down

0 comments on commit c9192c7

Please sign in to comment.