mirror of
https://github.com/ferdzo/fs.git
synced 2026-04-04 20:36:25 +00:00
Minimal fixes for metrics
This commit is contained in:
@@ -661,13 +661,12 @@ func (l *limitedListener) Accept() (net.Conn, error) {
|
||||
l.slots <- struct{}{}
|
||||
metrics.Default.DecRequestQueueLength()
|
||||
}
|
||||
metrics.Default.IncConnectionPoolActive()
|
||||
conn, err := l.Listener.Accept()
|
||||
if err != nil {
|
||||
<-l.slots
|
||||
metrics.Default.DecConnectionPoolActive()
|
||||
return nil, err
|
||||
}
|
||||
metrics.Default.IncConnectionPoolActive()
|
||||
return &limitedConn{
|
||||
Conn: conn,
|
||||
done: func() {
|
||||
|
||||
@@ -762,7 +762,7 @@ func trimFloat(v float64) string {
|
||||
}
|
||||
|
||||
func escapeLabelValue(value string) string {
|
||||
value = strings.ReplaceAll(value, `\\`, `\\\\`)
|
||||
value = strings.ReplaceAll(value, `\`, `\\`)
|
||||
value = strings.ReplaceAll(value, "\n", `\\n`)
|
||||
value = strings.ReplaceAll(value, `"`, `\\"`)
|
||||
return value
|
||||
|
||||
@@ -24,3 +24,11 @@ func TestRenderPrometheusHistogramNoEmptyLabelSet(t *testing.T) {
|
||||
t.Fatalf("unexpected empty label set for gc count metric")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscapeLabelValueEscapesSingleBackslash(t *testing.T) {
|
||||
got := escapeLabelValue(`a\b`)
|
||||
want := `a\\b`
|
||||
if got != want {
|
||||
t.Fatalf("escapeLabelValue returned %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,10 +106,6 @@ func (s *ObjectService) PutObject(bucket, key, contentType string, input io.Read
|
||||
|
||||
func (s *ObjectService) GetObject(bucket, key string) (io.ReadCloser, *models.ObjectManifest, error) {
|
||||
start := time.Now()
|
||||
success := false
|
||||
defer func() {
|
||||
metrics.Default.ObserveService("get_object", time.Since(start), success)
|
||||
}()
|
||||
|
||||
waitStart := time.Now()
|
||||
s.gcMu.RLock()
|
||||
@@ -120,20 +116,27 @@ func (s *ObjectService) GetObject(bucket, key string) (io.ReadCloser, *models.Ob
|
||||
if err != nil {
|
||||
metrics.Default.ObserveLockHold("gc_mu_read", time.Since(holdStart))
|
||||
s.gcMu.RUnlock()
|
||||
metrics.Default.ObserveService("get_object", time.Since(start), false)
|
||||
return nil, nil, err
|
||||
}
|
||||
pr, pw := io.Pipe()
|
||||
|
||||
go func() {
|
||||
streamOK := false
|
||||
defer func() {
|
||||
metrics.Default.ObserveService("get_object", time.Since(start), streamOK)
|
||||
}()
|
||||
defer metrics.Default.ObserveLockHold("gc_mu_read", time.Since(holdStart))
|
||||
defer s.gcMu.RUnlock()
|
||||
if err := s.blob.AssembleStream(manifest.Chunks, pw); err != nil {
|
||||
_ = pw.CloseWithError(err)
|
||||
return
|
||||
}
|
||||
_ = pw.Close()
|
||||
if err := pw.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
streamOK = true
|
||||
}()
|
||||
success = true
|
||||
return pr, manifest, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,9 @@ func (bs *BlobStore) IngestStream(stream io.Reader) ([]string, int64, string, er
|
||||
func (bs *BlobStore) saveBlob(chunkID string, data []byte) error {
|
||||
start := time.Now()
|
||||
success := false
|
||||
writtenBytes := int64(0)
|
||||
defer func() {
|
||||
metrics.Default.ObserveBlob("write_chunk", time.Since(start), int64(len(data)), success)
|
||||
metrics.Default.ObserveBlob("write_chunk", time.Since(start), writtenBytes, success)
|
||||
}()
|
||||
|
||||
if !isValidChunkID(chunkID) {
|
||||
@@ -144,6 +145,7 @@ func (bs *BlobStore) saveBlob(chunkID string, data []byte) error {
|
||||
if err := syncDir(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
writtenBytes = int64(len(data))
|
||||
success = true
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user