diff --git a/CHANGELOG.md b/CHANGELOG.md index 1630506e..4d72c801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The next release needs to be v0.3.0 because #217 & #219. ## [Unreleased] +- added metric for counting when caduceus re-encodes the wrp [#216](https://github.com/xmidt-org/caduceus/pull/216) - Made outgoing hostname validation configurable [#217](https://github.com/xmidt-org/caduceus/pull/217) - **Note:** To be backwards compatable, the configuration value of `allowInsecureTLS: true` will need to be defined, otherwise hostname validation is enabled by default. - removed contentTypeCounter [#218](https://github.com/xmidt-org/caduceus/pull/218) @@ -15,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - **Note:** This configuration change causes the existing retry logic to change. + ## [v0.2.8] ### Changed - cleaned up shutdown logic for outbound sender [#205](https://github.com/xmidt-org/caduceus/pull/205) diff --git a/http.go b/http.go index 10b03eb1..d4a7bfe7 100644 --- a/http.go +++ b/http.go @@ -37,6 +37,7 @@ type ServerHandler struct { emptyRequests metrics.Counter invalidCount metrics.Counter incomingQueueDepthMetric metrics.Gauge + modifiedWRPCount metrics.Counter incomingQueueDepth int64 maxOutstanding int64 } @@ -91,7 +92,7 @@ func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.R return } - sh.caduceusHandler.HandleRequest(0, fixWrp(msg)) + sh.caduceusHandler.HandleRequest(0, sh.fixWrp(msg)) // return a 202 response.WriteHeader(http.StatusAccepted) @@ -99,18 +100,29 @@ func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.R debugLog.Log(messageKey, "Request placed on to queue.") } -func fixWrp(msg *wrp.Message) *wrp.Message { +func (sh *ServerHandler) fixWrp(msg *wrp.Message) *wrp.Message { // "Fix" the WRP if needed. + var reason string // Default to "application/json" if there is no content type, otherwise // use the one the source specified. if "" == msg.ContentType { msg.ContentType = "application/json" + reason = emptyContentTypeReason } // Ensure there is a transaction id even if we make one up if "" == msg.TransactionUUID { msg.TransactionUUID = uuid.NewV4().String() + if reason == "" { + reason = emptyUUIDReason + } else { + reason = bothEmptyReason + } + } + + if reason != "" { + sh.modifiedWRPCount.With("reason", reason).Add(1.0) } return msg diff --git a/http_test.go b/http_test.go index 7b668bb2..7ca29423 100644 --- a/http_test.go +++ b/http_test.go @@ -118,12 +118,22 @@ func TestServerHandlerFixWrp(t *testing.T) { fakeQueueDepth := new(mockGauge) fakeQueueDepth.On("Add", mock.AnythingOfType("float64")).Return().Times(2) + fakeIncomingContentTypeCount := new(mockCounter) + fakeIncomingContentTypeCount.On("With", []string{"content_type", "application/msgpack"}).Return(fakeIncomingContentTypeCount) + fakeIncomingContentTypeCount.On("With", []string{"content_type", ""}).Return(fakeIncomingContentTypeCount) + fakeIncomingContentTypeCount.On("Add", 1.0).Return() + + fakeModifiedWRPCount := new(mockCounter) + fakeModifiedWRPCount.On("With", []string{"reason", bothEmptyReason}).Return(fakeIncomingContentTypeCount).Once() + fakeModifiedWRPCount.On("Add", 1.0).Return().Once() + serverWrapper := &ServerHandler{ Logger: logger, caduceusHandler: fakeHandler, errorRequests: fakeErrorRequests, emptyRequests: fakeEmptyRequests, invalidCount: fakeInvalidCount, + modifiedWRPCount: fakeModifiedWRPCount, incomingQueueDepthMetric: fakeQueueDepth, maxOutstanding: 1, } diff --git a/main.go b/main.go index be06add2..890cdb42 100644 --- a/main.go +++ b/main.go @@ -135,6 +135,7 @@ func caduceus(arguments []string) int { emptyRequests: metricsRegistry.NewCounter(EmptyRequestBodyCounter), invalidCount: metricsRegistry.NewCounter(DropsDueToInvalidPayload), incomingQueueDepthMetric: metricsRegistry.NewGauge(IncomingQueueDepth), + modifiedWRPCount: metricsRegistry.NewCounter(ModifiedWRPCounter), maxOutstanding: 0, } diff --git a/metrics.go b/metrics.go index b9d5e691..4a5e7a6e 100644 --- a/metrics.go +++ b/metrics.go @@ -7,6 +7,7 @@ import ( const ( ErrorRequestBodyCounter = "error_request_body_count" EmptyRequestBodyCounter = "empty_request_body_count" + ModifiedWRPCounter = "modified_wrp_count" DeliveryCounter = "delivery_count" DeliveryRetryCounter = "delivery_retry_count" DeliveryRetryMaxGauge = "delivery_retry_max" @@ -24,6 +25,12 @@ const ( ConsumerMaxDeliveryWorkersGauge = "consumer_delivery_workers_max" ) +const ( + emptyContentTypeReason = "empty_content_type" + emptyUUIDReason = "empty_uuid" + bothEmptyReason = "empty_uuid_and_content_type" +) + func Metrics() []xmetrics.Metric { return []xmetrics.Metric{ { @@ -46,6 +53,18 @@ func Metrics() []xmetrics.Metric { Help: "Dropped messages due to invalid payloads.", Type: "counter", }, + { + Name: ModifiedWRPCounter, + Help: "Number of times a WRP was modified by Caduceus", + Type: "counter", + LabelNames: []string{"reason"}, + }, + { + Name: IncomingContentTypeCounter, + Help: "Count of the content type processed.", + Type: "counter", + LabelNames: []string{"content_type"}, + }, { Name: DeliveryRetryCounter, Help: "Number of delivery retries made",