本文整理汇总了Golang中github.com/cloudfoundry/dropsonde/metric_sender/fake.FakeMetricSender.GetCounter方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeMetricSender.GetCounter方法的具体用法?Golang FakeMetricSender.GetCounter怎么用?Golang FakeMetricSender.GetCounter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/dropsonde/metric_sender/fake.FakeMetricSender
的用法示例。
在下文中一共展示了FakeMetricSender.GetCounter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
})
Describe("ConvergeTasks", func() {
const (
taskGuid = "some-guid"
taskGuid2 = "some-other-guid"
domain = "some-domain"
cellId = "cell-id"
)
JustBeforeEach(func() {
etcdDB.ConvergeTasks(logger, kickTasksDuration, expirePendingTaskDuration, expireCompletedTaskDuration)
})
It("bumps the convergence counter", func() {
Expect(sender.GetCounter("ConvergenceTaskRuns")).To(Equal(uint64(1)))
})
It("reports the duration that it took to converge", func() {
reportedDuration := sender.GetValue("ConvergenceTaskDuration")
Expect(reportedDuration.Unit).To(Equal("nanos"))
Expect(reportedDuration.Value).NotTo(BeZero())
})
It("emits -1 metrics", func() {
Expect(sender.GetValue("TasksPending").Value).To(Equal(float64(-1)))
Expect(sender.GetValue("TasksRunning").Value).To(Equal(float64(-1)))
Expect(sender.GetValue("TasksCompleted").Value).To(Equal(float64(-1)))
Expect(sender.GetValue("TasksResolving").Value).To(Equal(float64(-1)))
})
示例2:
EventType: events.Envelope_LogMessage.Enum(),
LogMessage: &events.LogMessage{
Message: []byte{4, 5, 6},
MessageType: events.LogMessage_OUT.Enum(),
Timestamp: proto.Int64(123),
AppId: proto.String("fake-app-id"),
},
}))
})
It("does not put an envelope on the output channel if there is unmarshal error", func() {
unmarshaller.Write([]byte{1, 2, 3})
Expect(writer.Events).To(BeEmpty())
})
})
Context("metrics", func() {
BeforeEach(func() {
unmarshaller = legacyunmarshaller.New(&writer, loggertesthelper.Logger())
fakeSender = fake.NewFakeMetricSender()
batcher := metricbatcher.New(fakeSender, time.Millisecond)
metrics.Initialize(fakeSender, batcher)
})
It("emits an unmarshal error counter", func() {
unmarshaller.Write([]byte{1, 2, 3})
Eventually(func() uint64 { return fakeSender.GetCounter("legacyUnmarshaller.unmarshalErrors") }).Should(BeEquivalentTo(1))
})
})
})
示例3:
BeforeEach(func() {
fakeMetricSender = fake.NewFakeMetricSender()
metrics.Initialize(fakeMetricSender)
})
It("delegates SendValue", func() {
metrics.SendValue("metric", 42.42, "answers")
Expect(fakeMetricSender.GetValue("metric").Value).To(Equal(42.42))
Expect(fakeMetricSender.GetValue("metric").Unit).To(Equal("answers"))
})
It("delegates IncrementCounter", func() {
metrics.IncrementCounter("count")
Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(1))
metrics.IncrementCounter("count")
Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(2))
})
It("delegates AddToCounter", func() {
metrics.AddToCounter("count", 5)
Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(5))
metrics.AddToCounter("count", 10)
Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(15))
})
示例4:
It("responds with 202", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusAccepted))
})
It("logs with the correct session nesting", func() {
Expect(logger.TestSink.LogMessages()).To(Equal([]string{
"test.request.serving",
"test.request.task-auction-handler.create.submitted",
"test.request.done",
}))
})
It("sends the correct metrics", func() {
Expect(sender.GetValue("RequestLatency").Value).To(BeNumerically(">", 0))
Expect(sender.GetCounter("RequestCount")).To(BeEquivalentTo(1))
})
})
})
Describe("LRP Handler", func() {
Context("with a valid LRPStart", func() {
BeforeEach(func() {
starts := []auctioneer.LRPStartRequest{{
Indices: []int{2},
Domain: "tests",
ProcessGuid: "some-guid",
Resource: rep.Resource{
RootFs: "docker:///docker.com/docker",
示例5:
reportedDuration := sender.GetValue("VolmanMountDuration")
Expect(reportedDuration.Unit).To(Equal("nanos"))
Expect(reportedDuration.Value).NotTo(BeZero())
reportedDuration = sender.GetValue("VolmanMountDurationForfakedriver")
Expect(reportedDuration.Unit).To(Equal("nanos"))
Expect(reportedDuration.Value).NotTo(BeZero())
})
It("should increment error count on mount failure", func() {
mountResponse := voldriver.MountResponse{Err: "an error"}
fakeDriver.MountReturns(mountResponse)
volumeId := "fake-volume"
client.Mount(logger, "fakedriver", volumeId, map[string]interface{}{"volume_id": volumeId})
Expect(sender.GetCounter("VolmanMountErrors")).To(Equal(uint64(1)))
})
})
})
Context("umount", func() {
It("should be able to unmount", func() {
volumeId := "fake-volume"
err := client.Unmount(logger, "fakedriver", volumeId)
Expect(err).NotTo(HaveOccurred())
Expect(fakeDriver.UnmountCallCount()).To(Equal(1))
Expect(fakeDriver.RemoveCallCount()).To(Equal(0))
})
示例6:
Context("when a staging request is received for a registered backend", func() {
var stagingRequest cc_messages.StagingRequestFromCC
BeforeEach(func() {
stagingRequest = cc_messages.StagingRequestFromCC{
AppId: "myapp",
Lifecycle: "fake-backend",
}
var err error
stagingRequestJson, err = json.Marshal(stagingRequest)
Expect(err).NotTo(HaveOccurred())
})
It("increments the counter to track arriving staging messages", func() {
Expect(fakeMetricSender.GetCounter("StagingStartRequestsReceived")).To(Equal(uint64(1)))
})
It("returns an Accepted response", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusAccepted))
})
It("builds a staging recipe", func() {
Expect(fakeBackend.BuildRecipeCallCount()).To(Equal(1))
guid, request := fakeBackend.BuildRecipeArgsForCall(0)
Expect(guid).To(Equal("a-staging-guid"))
Expect(request).To(Equal(stagingRequest))
})
Context("when the recipe was built successfully", func() {
示例7:
table.SetRoutesReturns(dummyMessagesToEmit)
nextEvent.Store(EventHolder{models.NewDesiredLRPCreatedEvent(desiredLRP)})
})
It("should set the routes on the table", func() {
Eventually(table.SetRoutesCallCount).Should(Equal(1))
key, routes := table.SetRoutesArgsForCall(0)
Expect(key).To(Equal(expectedRoutingKey))
Expect(routes).To(Equal(routing_table.Routes{Hostnames: expectedRoutes, LogGuid: logGuid, RouteServiceUrl: expectedRouteServiceUrl}))
})
It("sends a 'routes registered' metric", func() {
Eventually(func() uint64 {
return fakeMetricSender.GetCounter("RoutesRegistered")
}).Should(BeEquivalentTo(2))
})
It("sends a 'routes unregistered' metric", func() {
Eventually(func() uint64 {
return fakeMetricSender.GetCounter("RoutesUnRegistered")
}).Should(BeEquivalentTo(0))
})
It("should emit whatever the table tells it to emit", func() {
Eventually(emitter.EmitCallCount).Should(Equal(2))
messagesToEmit := emitter.EmitArgsForCall(1)
Expect(messagesToEmit).To(Equal(dummyMessagesToEmit))
})
示例8:
It("writes message to client", func() {
byteWriter.WriteOutput.sentLength <- len(prefixedMessage)
bytesWritten, err := batcher.Write(messageBytes)
Expect(err).ToNot(HaveOccurred())
Expect(bytesWritten).To(Equal(len(messageBytes)))
Expect(byteWriter.WriteInput.message).To(Receive(Equal(prefixedMessage)))
})
It("sends a sentMessages metric", func() {
close(byteWriter.WriteOutput.sentLength)
_, err := batcher.Write(messageBytes)
Expect(err).ToNot(HaveOccurred())
Eventually(byteWriter.WriteInput.message).Should(Receive(Equal(prefixedMessage)))
Eventually(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(1))
})
Context("the weighted writer errors once", func() {
BeforeEach(func() {
byteWriter.WriteOutput.sentLength <- 0
byteWriter.WriteOutput.err = make(chan error, 1)
byteWriter.WriteOutput.err <- errors.New("boom")
})
JustBeforeEach(func() {
byteWriter.WriteOutput.sentLength <- len(prefixedMessage)
close(byteWriter.WriteOutput.err)
})
It("retries", func() {
示例9:
})
Context("udp client", func() {
BeforeEach(func() {
client.SchemeReturns("udp")
})
It("marshals, signs, writes and emits metrics", func() {
bytes, err := proto.Marshal(envelope)
Expect(err).NotTo(HaveOccurred())
bytes = signature.SignMessage(bytes, sharedSecret)
forwarder.Write(envelope)
Expect(client.WriteArgsForCall(0)).To(Equal(bytes))
Eventually(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(1))
Expect(sender.GetCounter("dropsondeMarshaller.logMessageMarshalled")).To(BeEquivalentTo(1))
})
Context("when writes fail", func() {
BeforeEach(func() {
client.WriteReturns(0, errors.New("boom"))
})
It("does not increment message count or sentMessages", func() {
forwarder.Write(envelope)
Consistently(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeZero())
Expect(sender.GetCounter("dropsondeMarshaller.LogMessageMarshalled")).To(BeZero())
})
})
示例10:
Origin: proto.String("fake-origin-1"),
EventType: events.Envelope_LogMessage.Enum(),
LogMessage: factories.NewLogMessage(events.LogMessage_OUT, "message", "appid", "sourceType"),
}
message, _ = proto.Marshal(envelope)
marshaller.Write(envelope)
})
It("marshals envelopes into bytes", func() {
Expect(writer.Data()).Should(HaveLen(1))
outputMessage := writer.Data()[0]
Expect(outputMessage).To(Equal(message))
})
It("emits a metric", func() {
Eventually(func() uint64 { return fakeMetricSender.GetCounter("dropsondeMarshaller.logMessageMarshalled") }).Should(BeEquivalentTo(1))
})
})
Context("invalid envelope", func() {
It("emits a dropsonde marshal error counter", func() {
envelope := &events.Envelope{}
marshaller.Write(envelope)
Eventually(func() uint64 { return fakeMetricSender.GetCounter("dropsondeMarshaller.marshalErrors") }).Should(BeEquivalentTo(1))
})
})
})
示例11:
Expect(metric.Value).To(Equal(uint64(1)))
case "sentByteCount":
Expect(metric.Value).To(Equal(uint64(21)))
case "receivedMessageCount":
Expect(metric.Value).To(Equal(uint64(1)))
case "receivedByteCount":
Expect(metric.Value).To(Equal(uint64(21)))
default:
Fail("Got an invalid metric name: " + metric.Name)
}
}
})
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() {
bufferSize := 4096
firstMessage := []byte("")
secondMessage := []byte("hi")
loggregatorClient.Send(firstMessage)
loggregatorClient.Send(secondMessage)
buffer := make([]byte, bufferSize)
示例12:
protocol = "tcp"
})
It("counts the number of bytes sent", func() {
// subtract a magic number three from the message length to make sure
// we report the bytes sent by the client, not just the len of the
// message given to it
sentLength := len(message) - 3
client.WriteOutput.sentLength <- sentLength
client.WriteOutput.err <- nil
err := wrapper.Write(client, message)
Expect(err).NotTo(HaveOccurred())
Eventually(func() uint64 {
return sender.GetCounter("tcp.sentByteCount")
}).Should(BeEquivalentTo(sentLength))
})
It("counts the number of messages sent", func() {
client.WriteOutput.sentLength <- len(message)
client.WriteOutput.err <- nil
err := wrapper.Write(client, message)
Expect(err).NotTo(HaveOccurred())
Eventually(func() uint64 {
return sender.GetCounter("tcp.sentMessageCount")
}).Should(BeEquivalentTo(1))
client.WriteOutput.sentLength <- len(message)
client.WriteOutput.err <- nil
示例13:
}
})
JustBeforeEach(func() {
marshaller.SetWriter(nil)
})
It("does not panic", func() {
Expect(func() {
marshaller.Write(envelope)
}).ToNot(Panic())
})
It("counts messages written while byteWriter was nil", func() {
marshaller.Write(envelope)
Eventually(func() uint64 { return sender.GetCounter("dropsondeMarshaller.nilByteWriterWrites") }).Should(BeEquivalentTo(1))
})
})
Context("with an invalid envelope", func() {
BeforeEach(func() {
envelope = &events.Envelope{}
close(writer.WriteOutput.SentLength)
close(writer.WriteOutput.Err)
})
It("counts marshal errors", func() {
marshaller.Write(envelope)
Eventually(func() uint64 { return sender.GetCounter("dropsondeMarshaller.marshalErrors") }).Should(BeEquivalentTo(1))
})
示例14:
BeforeEach(func() {
close(byteWriter.WriteOutput.SentLength)
// close enough
infinity := 10
byteWriter.WriteOutput.Err = make(chan error, infinity)
for i := 0; i < infinity; i++ {
byteWriter.WriteOutput.Err <- errors.New("To INFINITY (but not beyond)")
}
})
It("increments the dropped message counter", func() {
batcher.Write(messageBytes)
Eventually(droppedCounter.DropInput.Count).Should(Receive(BeNumerically("==", 1)))
Consistently(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(0))
})
})
})
Context("message smaller than buffer size", func() {
var twoMessageOutput []byte
BeforeEach(func() {
for uint64(len(messageBytes)) < bufferSize/2 {
messageBytes = append(messageBytes, messageBytes...)
}
})
JustBeforeEach(func() {
twoMessageOutput = append(prefixedMessage, prefixedMessage...)
示例15:
Consistently(func() int { return len(mockWriter.Events) }).Should(Equal(0))
})
})
Context("metrics", func() {
var fakeSender *fake.FakeMetricSender
BeforeEach(func() {
fakeSender = fake.NewFakeMetricSender()
batcher := metricbatcher.New(fakeSender, time.Millisecond)
metrics.Initialize(fakeSender, batcher)
})
var eventuallyExpectMetric = func(name string, value uint64) {
Eventually(func() uint64 {
return fakeSender.GetCounter("MessageAggregator." + name)
}).Should(Equal(value), fmt.Sprintf("Metric %s was incorrect", name))
}
It("emits a HTTP start counter", func() {
messageAggregator.Write(createStartMessage(123, events.PeerType_Client))
eventuallyExpectMetric("httpStartReceived", 1)
})
It("emits a HTTP stop counter", func() {
messageAggregator.Write(createStopMessage(123, events.PeerType_Client))
eventuallyExpectMetric("httpStopReceived", 1)
})
It("emits a HTTP StartStop counter", func() {
messageAggregator.Write(createStartMessage(123, events.PeerType_Client))