diff --git a/proxy/pkg/metrics/node_metrics.go b/proxy/pkg/metrics/node_metrics.go index 25c3273..cc73c11 100644 --- a/proxy/pkg/metrics/node_metrics.go +++ b/proxy/pkg/metrics/node_metrics.go @@ -280,7 +280,8 @@ type NodeMetricsInstance struct { UnavailableErrors Counter OtherErrors Counter - RequestDuration map[string]Histogram + ReadDurations Histogram + WriteDurations Histogram OpenConnections Gauge @@ -311,18 +312,6 @@ func CreateHistogramNodeMetric(metricFactory MetricFactory, nodeDescription stri return m, nil } -func CreateHistogramNodeRequestDurationMetrics(metricFactory MetricFactory, nodeDescription string, mn Metric, buckets []float64) (map[string]Histogram, error) { - requestDuration := make(map[string]Histogram) - for _, stmtCtg := range StatementCategories { - item, err := CreateHistogramNodeMetric(metricFactory, nodeDescription, mn, buckets, RequestDurationTypeLabel, stmtCtg) - if err != nil { - return nil, err - } - requestDuration[stmtCtg] = item - } - return requestDuration, nil -} - func CreateGaugeNodeMetric(metricFactory MetricFactory, nodeDescription string, mn Metric) (Gauge, error) { m, err := metricFactory.GetOrCreateGauge( mn.WithLabels(map[string]string{nodeLabel: nodeDescription})) diff --git a/proxy/pkg/metrics/proxy_metrics.go b/proxy/pkg/metrics/proxy_metrics.go index 2f5998f..9c3eb5f 100644 --- a/proxy/pkg/metrics/proxy_metrics.go +++ b/proxy/pkg/metrics/proxy_metrics.go @@ -27,10 +27,6 @@ const ( inFlightRequestsDescription = "Number of requests currently in flight in the proxy" ) -var ( - StatementCategories = []string{TypeWrites, TypeReads} -) - var ( FailedReadsOrigin = NewMetricWithLabels( failedReadsName, diff --git a/proxy/pkg/zdmproxy/proxy.go b/proxy/pkg/zdmproxy/proxy.go index 778178c..26b7d5c 100644 --- a/proxy/pkg/zdmproxy/proxy.go +++ b/proxy/pkg/zdmproxy/proxy.go @@ -826,7 +826,12 @@ func (p *ZdmProxy) CreateOriginNodeMetrics( return nil, err } - originRequestDuration, err := metrics.CreateHistogramNodeRequestDurationMetrics(metricFactory, originNodeDescription, metrics.OriginRequestDuration, originBuckets) + originReadRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, originNodeDescription, metrics.OriginRequestDuration, originBuckets, metrics.RequestDurationTypeLabel, metrics.TypeReads) + if err != nil { + return nil, err + } + + originWriteRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, originNodeDescription, metrics.OriginRequestDuration, originBuckets, metrics.RequestDurationTypeLabel, metrics.TypeWrites) if err != nil { return nil, err } @@ -857,7 +862,8 @@ func (p *ZdmProxy) CreateOriginNodeMetrics( OverloadedErrors: originOverloadedErrors, UnavailableErrors: originUnavailableErrors, OtherErrors: originOtherErrors, - RequestDuration: originRequestDuration, + ReadDurations: originReadRequestDuration, + WriteDurations: originWriteRequestDuration, OpenConnections: openOriginConnections, InFlightRequests: inflightRequests, UsedStreamIds: originUsedStreamIds, @@ -911,7 +917,12 @@ func (p *ZdmProxy) CreateAsyncNodeMetrics( return nil, err } - asyncRequestDuration, err := metrics.CreateHistogramNodeRequestDurationMetrics(metricFactory, asyncNodeDescription, metrics.AsyncRequestDuration, asyncBuckets) + asyncReadRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, asyncNodeDescription, metrics.AsyncRequestDuration, asyncBuckets, metrics.RequestDurationTypeLabel, metrics.TypeReads) + if err != nil { + return nil, err + } + + asyncWriteRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, asyncNodeDescription, metrics.AsyncRequestDuration, asyncBuckets, metrics.RequestDurationTypeLabel, metrics.TypeWrites) if err != nil { return nil, err } @@ -941,7 +952,8 @@ func (p *ZdmProxy) CreateAsyncNodeMetrics( OverloadedErrors: asyncOverloadedErrors, UnavailableErrors: asyncUnavailableErrors, OtherErrors: asyncOtherErrors, - RequestDuration: asyncRequestDuration, + ReadDurations: asyncReadRequestDuration, + WriteDurations: asyncWriteRequestDuration, OpenConnections: openAsyncConnections, InFlightRequests: inflightRequestsAsync, UsedStreamIds: asyncUsedStreamIds, @@ -995,7 +1007,12 @@ func (p *ZdmProxy) CreateTargetNodeMetrics( return nil, err } - targetRequestDuration, err := metrics.CreateHistogramNodeRequestDurationMetrics(metricFactory, targetNodeDescription, metrics.TargetRequestDuration, targetBuckets) + targetReadRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, targetNodeDescription, metrics.TargetRequestDuration, targetBuckets, metrics.RequestDurationTypeLabel, metrics.TypeReads) + if err != nil { + return nil, err + } + + targetWriteRequestDuration, err := metrics.CreateHistogramNodeMetric(metricFactory, targetNodeDescription, metrics.TargetRequestDuration, targetBuckets, metrics.RequestDurationTypeLabel, metrics.TypeWrites) if err != nil { return nil, err } @@ -1026,7 +1043,8 @@ func (p *ZdmProxy) CreateTargetNodeMetrics( OverloadedErrors: targetOverloadedErrors, UnavailableErrors: targetUnavailableErrors, OtherErrors: targetOtherErrors, - RequestDuration: targetRequestDuration, + ReadDurations: targetReadRequestDuration, + WriteDurations: targetWriteRequestDuration, OpenConnections: openTargetConnections, InFlightRequests: inflightRequests, UsedStreamIds: targetUsedStreamIds, diff --git a/proxy/pkg/zdmproxy/requestcontext.go b/proxy/pkg/zdmproxy/requestcontext.go index 2380fbf..aa5a849 100644 --- a/proxy/pkg/zdmproxy/requestcontext.go +++ b/proxy/pkg/zdmproxy/requestcontext.go @@ -193,11 +193,17 @@ func (recv *requestContextImpl) SetResponse(nodeMetrics *metrics.NodeMetrics, f if recv.GetRequestInfo().ShouldBeTrackedInMetrics() { switch connectorType { case ClusterConnectorTypeOrigin: - stmtCtg := getStatementCategory(recv.GetRequestInfo()) - nodeMetrics.OriginMetrics.RequestDuration[stmtCtg].Track(recv.startTime) + if isWriteStatement(recv.GetRequestInfo()) { + nodeMetrics.OriginMetrics.WriteDurations.Track(recv.startTime) + } else { + nodeMetrics.OriginMetrics.ReadDurations.Track(recv.startTime) + } case ClusterConnectorTypeTarget: - stmtCtg := getStatementCategory(recv.GetRequestInfo()) - nodeMetrics.TargetMetrics.RequestDuration[stmtCtg].Track(recv.startTime) + if isWriteStatement(recv.GetRequestInfo()) { + nodeMetrics.TargetMetrics.WriteDurations.Track(recv.startTime) + } else { + nodeMetrics.TargetMetrics.ReadDurations.Track(recv.startTime) + } case ClusterConnectorTypeAsync: default: log.Errorf("could not recognize connector type %v", connectorType) @@ -207,12 +213,8 @@ func (recv *requestContextImpl) SetResponse(nodeMetrics *metrics.NodeMetrics, f return finished } -func getStatementCategory(req RequestInfo) string { - switch req.GetForwardDecision() { - case forwardToBoth: - return metrics.TypeWrites - } - return metrics.TypeReads +func isWriteStatement(req RequestInfo) bool { + return req.GetForwardDecision() == forwardToBoth } func (recv *requestContextImpl) updateInternalState(f *frame.RawFrame, cluster common.ClusterType) (state int, updated bool) { @@ -341,8 +343,11 @@ func (recv *asyncRequestContextImpl) SetResponse( } if recv.GetRequestInfo().ShouldBeTrackedInMetrics() { - stmtCtg := getStatementCategory(recv.GetRequestInfo()) - nodeMetrics.AsyncMetrics.RequestDuration[stmtCtg].Track(recv.startTime) + if isWriteStatement(recv.GetRequestInfo()) { + nodeMetrics.AsyncMetrics.WriteDurations.Track(recv.startTime) + } else { + nodeMetrics.AsyncMetrics.ReadDurations.Track(recv.startTime) + } nodeMetrics.AsyncMetrics.InFlightRequests.Subtract(1) }