ev1lQuark commented on code in PR #2362:
URL: https://github.com/apache/dubbo-go/pull/2362#discussion_r1269148124


##########
metrics/prometheus/model.go:
##########
@@ -298,3 +298,91 @@ func (gv *quantileGaugeVec) updateQuantile(labels 
*prometheus.Labels, curValue i
                updateFunc(cur)
        }
 }
+
+type qpsGaugeVec struct {
+       gaugeVec *prometheus.GaugeVec
+       syncMap  *sync.Map // key: labels string, value: TimeWindowCounter
+}
+
+func newQpsGaugeVec(name, namespace string, labels []string) *qpsGaugeVec {
+       return &qpsGaugeVec{
+               gaugeVec: newAutoGaugeVec(name, namespace, labels),
+               syncMap:  &sync.Map{},
+       }
+}
+
+func (gv *qpsGaugeVec) updateQps(labels *prometheus.Labels) {
+       key := convertLabelsToMapKey(*labels)
+       cur := aggregate.NewTimeWindowCounter(10, 120)
+       cur.Inc()
+
+       if actual, loaded := gv.syncMap.LoadOrStore(key, cur); loaded {
+               store := actual.(*aggregate.TimeWindowCounter)
+               store.Inc()
+               gv.gaugeVec.With(*labels).Set(store.Count() / 
float64(store.LivedSeconds()))
+       } else {
+               gv.gaugeVec.With(*labels).Set(cur.Count() / 
float64(cur.LivedSeconds()))
+       }
+}
+
+type aggregateCounterGaugeVec struct {
+       gaugeVec *prometheus.GaugeVec
+       syncMap  *sync.Map // key: labels string, value: TimeWindowCounter
+}
+
+func newAggregateCounterGaugeVec(name, namespace string, labels []string) 
*aggregateCounterGaugeVec {
+       return &aggregateCounterGaugeVec{
+               gaugeVec: newAutoGaugeVec(name, namespace, labels),
+               syncMap:  &sync.Map{},
+       }
+}
+
+func (gv *aggregateCounterGaugeVec) inc(labels *prometheus.Labels) {
+       key := convertLabelsToMapKey(*labels)
+       cur := aggregate.NewTimeWindowCounter(10, 120)
+       cur.Inc()
+
+       if actual, loaded := gv.syncMap.LoadOrStore(key, cur); loaded {
+               store := actual.(*aggregate.TimeWindowCounter)
+               store.Inc()
+               gv.gaugeVec.With(*labels).Set(store.Count())
+       } else {
+               gv.gaugeVec.With(*labels).Set(cur.Count())
+       }
+}
+
+type aggregateFunctionsGaugeVec struct {
+       min     *prometheus.GaugeVec
+       max     *prometheus.GaugeVec
+       avg     *prometheus.GaugeVec
+       syncMap *sync.Map // key: labels string, value: TimeWindowAggregator
+}
+
+func newAggregateFunctionsGaugeVec(minName, maxName, avgName, namespace 
string, labels []string) *aggregateFunctionsGaugeVec {
+       return &aggregateFunctionsGaugeVec{
+               min:     newAutoGaugeVec(minName, namespace, labels),
+               max:     newAutoGaugeVec(maxName, namespace, labels),
+               avg:     newAutoGaugeVec(avgName, namespace, labels),
+               syncMap: &sync.Map{},
+       }
+}
+
+func (gv *aggregateFunctionsGaugeVec) update(labels *prometheus.Labels, 
curValue int64) {
+       key := convertLabelsToMapKey(*labels)
+       cur := aggregate.NewTimeWindowAggregator(10, 120)
+       cur.Add(float64(curValue))
+
+       updateFunc := func(aggregator *aggregate.TimeWindowAggregator) {
+               gv.min.With(*labels).Set(aggregator.Result().Min)
+               gv.max.With(*labels).Set(aggregator.Result().Max)
+               gv.avg.With(*labels).Set(aggregator.Result().Avg)

Review Comment:
   Thanks!



-- 
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: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to