acelyc111 commented on code in PR #2285:
URL: 
https://github.com/apache/incubator-pegasus/pull/2285#discussion_r2346771181


##########
go-client/pegasus/table_connector.go:
##########
@@ -715,8 +719,44 @@ func (p *pegasusTableConnector) Incr(ctx context.Context, 
hashKey []byte, sortKe
 }
 
 func (p *pegasusTableConnector) runPartitionOp(ctx context.Context, hashKey 
[]byte, req op.Request, optype OpType) (interface{}, error) {
+       start := time.Now()
+       var errResult error
+       if p.enableMetrics {
+               defer func() {
+                       elapsed := time.Since(start).Nanoseconds()

Review Comment:
   move it to line 752 to reduce the cost if this function early returned.



##########
go-client/metrics/prometheus.go:
##########
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package metrics
+
+import (
+       "fmt"
+       "net/http"
+       "os"
+       "sort"
+       "strings"
+       "sync"
+       "time"
+
+       "github.com/apache/incubator-pegasus/go-client/config"
+       "github.com/apache/incubator-pegasus/go-client/pegalog"
+       "github.com/prometheus/client_golang/prometheus"
+       "github.com/prometheus/client_golang/prometheus/promauto"
+       "github.com/prometheus/client_golang/prometheus/promhttp"
+)
+
+// PrometheusMetrics is the metrics implementation for Prometheus.
+type PrometheusMetrics struct {
+       registry    prometheus.Registerer
+       counterMap  sync.Map

Review Comment:
   What the purpose of manual maintain the metrics? The go-client prometheus 
seems have the ability to maintain the metrics with different labels.



##########
go-client/pegasus/table_connector.go:
##########
@@ -715,8 +719,44 @@ func (p *pegasusTableConnector) Incr(ctx context.Context, 
hashKey []byte, sortKe
 }
 
 func (p *pegasusTableConnector) runPartitionOp(ctx context.Context, hashKey 
[]byte, req op.Request, optype OpType) (interface{}, error) {
+       start := time.Now()
+       var errResult error
+       if p.enableMetrics {
+               defer func() {
+                       elapsed := time.Since(start).Nanoseconds()
+                       pm := metrics.GetPrometheusMetrics()
+                       status := "success"
+                       if errResult != nil {
+                               if errors.Is(ctx.Err(), 
context.DeadlineExceeded) {
+                                       status = "timeout"
+                               } else {
+                                       status = "fail"
+                               }
+                       }
+                       labels := map[string]string{
+                               "table":  p.tableName,
+                               "op":     optype.String(),
+                               "status": status,
+                               "meta":   strings.Join(p.meta.GetMetaIPAddrs(), 
","),
+                       }
+                       counter, err := 
pm.GetOrCreateCounter("pegasus_client_operations_total", labels)

Review Comment:
   The summary metric bellow has record the "total count" of the metric, is it 
necessary to use an independent metric to monitor the count?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to