-
Notifications
You must be signed in to change notification settings - Fork 812
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
Add latency metrics for each visibility message to ES #2026
Changes from 3 commits
5f3204d
e4a6ac1
a39b179
ea1052c
192b9eb
81a2c99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package metrics | ||
|
||
import ( | ||
"github.com/uber-go/tally" | ||
"time" | ||
) | ||
|
||
type nopStopwatchRecorder struct{} | ||
|
||
// RecordStopwatch is a nop impl for replay mode | ||
func (n *nopStopwatchRecorder) RecordStopwatch(stopwatchStart time.Time) {} | ||
|
||
// NopStopwatch return a fake tally stop watch | ||
func NopStopwatch() tally.Stopwatch { | ||
return tally.NewStopwatch(time.Now(), &nopStopwatchRecorder{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ func (r *replayMetricsClient) AddCounter(scope int, counter int, delta int64) { | |
// StartTimer starts a timer for the given metric name. Time will be recorded when stopwatch is stopped. | ||
func (r *replayMetricsClient) StartTimer(scope int, timer int) tally.Stopwatch { | ||
if workflow.IsReplaying(r.ctx) { | ||
return nopStopwatch() | ||
return metrics.NopStopwatch() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI
|
||
} | ||
return r.client.StartTimer(scope, timer) | ||
} | ||
|
@@ -145,12 +145,3 @@ func (r *replayMetricsScope) UpdateGauge(gauge int, value float64) { | |
func (r *replayMetricsScope) Tagged(tags ...metrics.Tag) metrics.Scope { | ||
return NewReplayMetricsScope(r.scope.Tagged(tags...), r.ctx) | ||
} | ||
|
||
type nopStopwatchRecorder struct{} | ||
|
||
// RecordStopwatch is a nop impl for replay mode | ||
func (n *nopStopwatchRecorder) RecordStopwatch(stopwatchStart time.Time) {} | ||
|
||
func nopStopwatch() tally.Stopwatch { | ||
return tally.NewStopwatch(time.Now(), &nopStopwatchRecorder{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
"time" | ||
|
||
"github.com/olivere/elastic" | ||
"github.com/uber-go/tally" | ||
"github.com/uber/cadence/common" | ||
"github.com/uber/cadence/common/collection" | ||
es "github.com/uber/cadence/common/elasticsearch" | ||
|
@@ -64,6 +65,11 @@ type ( | |
logger log.Logger | ||
metricsClient metrics.Client | ||
} | ||
|
||
kafkaMessageWithMetrics struct { // value of esProcessorImpl.mapToKafkaMsg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can also make this struct implement messaging.Message and make the implemented ack / nack call stopwatch.stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated, I think your suggestion is cleaner |
||
message messaging.Message | ||
swFromAddToAck *tally.Stopwatch // metric from message add to process, to message ack/nack | ||
} | ||
) | ||
|
||
var _ ESProcessor = (*esProcessorImpl)(nil) | ||
|
@@ -115,7 +121,12 @@ func (p *esProcessorImpl) Add(request elastic.BulkableRequest, key string, kafka | |
kafkaMsg.Ack() | ||
return nil | ||
} | ||
_, isDup, _ := p.mapToKafkaMsg.PutOrDo(key, kafkaMsg, actionWhenFoundDuplicates) | ||
sw := p.metricsClient.StartTimer(metrics.ESProcessorScope, metrics.ESProcessorProcessMsgLatency) | ||
mapVal := &kafkaMessageWithMetrics{ | ||
message: kafkaMsg, | ||
swFromAddToAck: &sw, | ||
} | ||
_, isDup, _ := p.mapToKafkaMsg.PutOrDo(key, mapVal, actionWhenFoundDuplicates) | ||
if isDup { | ||
return | ||
} | ||
|
@@ -177,16 +188,21 @@ func (p *esProcessorImpl) ackKafkaMsgHelper(key string, nack bool) { | |
if !ok { | ||
return // duplicate kafka message | ||
} | ||
kafkaMsg, ok := msg.(messaging.Message) | ||
kafkaMsg, ok := msg.(*kafkaMessageWithMetrics) | ||
if !ok { // must be bug in code and bad deployment | ||
p.logger.Fatal("Message is not kafka message.", tag.ESKey(key)) | ||
} | ||
|
||
if nack { | ||
kafkaMsg.Nack() | ||
kafkaMsg.message.Nack() | ||
} else { | ||
kafkaMsg.Ack() | ||
kafkaMsg.message.Ack() | ||
} | ||
|
||
if kafkaMsg.swFromAddToAck != nil { | ||
kafkaMsg.swFromAddToAck.Stop() | ||
} | ||
|
||
p.mapToKafkaMsg.Remove(key) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you change this file name to noop.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed