Skip to content

Commit

Permalink
add mutex to TimeStart and TimeEnd functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Jan 13, 2018
1 parent e893f2a commit 6948ab1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* 0.6.1
* Bugfix: Add mutex for time monitoring map
* 0.6.0
* Feature: Add prometheus reporter
* Bugfix: Fix race condition when notifying waiting clients about response
Expand Down
4 changes: 2 additions & 2 deletions cmd/mort/mort.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
// Version of mort
Version = "0.6.0"
Version = "0.6.1"
// BANNER just fancy command line banner
BANNER = `
/\/\ ___ _ __| |_
Expand Down Expand Up @@ -130,7 +130,7 @@ func configureMonitoring(mortConfig *config.Config) {

p.RegisterHistogramVec("response_time", prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "mort_response_time",
Help: "mort reponse times",
Help: "mort response times",
Buckets: []float64{10, 50, 100, 200, 300, 400, 500, 1000, 2000, 3000, 4000, 5000, 6000, 10000, 30000, 60000},
},
[]string{"method"},
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func GetInstance() *Config {
return instance
}

// RegisterTransformKind register new transformation in config validator
func RegisterTransformKind(kind string) {
for _, k := range transformKinds {
if k == kind {
Expand Down
7 changes: 6 additions & 1 deletion pkg/monitoring/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"strings"
"time"
"sync"
)

// PrometheusReporter is a reporter that allow you to "send" metrics to
Expand All @@ -18,6 +19,7 @@ type PrometheusReporter struct {
histograms map[string]prometheus.Histogram
histogramsVec map[string]*prometheus.HistogramVec
timers map[string]time.Time
timersLock sync.RWMutex
}

// NewPrometheusReporter create instance of reporter that allow you to report stats to prometheus
Expand Down Expand Up @@ -99,14 +101,17 @@ func (p *PrometheusReporter) Histogram(metric string, val float64) {
// Result will be histogram of time
// metric schema: metric_name;label:value,label1:value2
func (p *PrometheusReporter) TimeStart(metric string) {
p.timersLock.Lock()
p.timers[metric] = time.Now()
p.timersLock.Unlock()
}

// TimeEnd - end time measure for given metric
func (p *PrometheusReporter) TimeEnd(metric string) {
p.timersLock.RLock()
delta := time.Since(p.timers[metric])
p.timersLock.RUnlock()
p.Histogram(metric, float64(delta.Nanoseconds()/1000))
delete(p.timers, metric)
}

// RegisterCounter register counter in prometheus default registry
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var bufPool = sync.Pool{
},
}

// ParserFnc is a function that create object from request url
// ParseFnc is a function that create object from request url
type ParseFnc func(url *url.URL, bucketConfig config.Bucket, obj *FileObject) (string, error)

// parser list of available decoder function
Expand Down

0 comments on commit 6948ab1

Please sign in to comment.