/*
 * Copyright 2024 gRPC authors.
 *
 * Licensed 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 stats

import (
	

	estats 
	
)

// MetricsRecorderList forwards Record calls to all of its metricsRecorders.
//
// It eats any record calls where the label values provided do not match the
// number of label keys.
type MetricsRecorderList struct {
	// metricsRecorders are the metrics recorders this list will forward to.
	metricsRecorders []estats.MetricsRecorder
}

// NewMetricsRecorderList creates a new metric recorder list with all the stats
// handlers provided which implement the MetricsRecorder interface.
// If no stats handlers provided implement the MetricsRecorder interface,
// the MetricsRecorder list returned is a no-op.
func ( []stats.Handler) *MetricsRecorderList {
	var  []estats.MetricsRecorder
	for ,  := range  {
		if ,  := .(estats.MetricsRecorder);  {
			 = append(, )
		}
	}
	return &MetricsRecorderList{
		metricsRecorders: ,
	}
}

func verifyLabels( *estats.MetricDescriptor,  ...string) {
	if ,  := len(), len(.Labels)+len(.OptionalLabels);  !=  {
		panic(fmt.Sprintf("Received %d labels in call to record metric %q, but expected %d.", , .Name, ))
	}
}

// RecordInt64Count records the measurement alongside labels on the int
// count associated with the provided handle.
func ( *MetricsRecorderList) ( *estats.Int64CountHandle,  int64,  ...string) {
	verifyLabels(.Descriptor(), ...)

	for ,  := range .metricsRecorders {
		.RecordInt64Count(, , ...)
	}
}

// RecordFloat64Count records the measurement alongside labels on the float
// count associated with the provided handle.
func ( *MetricsRecorderList) ( *estats.Float64CountHandle,  float64,  ...string) {
	verifyLabels(.Descriptor(), ...)

	for ,  := range .metricsRecorders {
		.RecordFloat64Count(, , ...)
	}
}

// RecordInt64Histo records the measurement alongside labels on the int
// histo associated with the provided handle.
func ( *MetricsRecorderList) ( *estats.Int64HistoHandle,  int64,  ...string) {
	verifyLabels(.Descriptor(), ...)

	for ,  := range .metricsRecorders {
		.RecordInt64Histo(, , ...)
	}
}

// RecordFloat64Histo records the measurement alongside labels on the float
// histo associated with the provided handle.
func ( *MetricsRecorderList) ( *estats.Float64HistoHandle,  float64,  ...string) {
	verifyLabels(.Descriptor(), ...)

	for ,  := range .metricsRecorders {
		.RecordFloat64Histo(, , ...)
	}
}

// RecordInt64Gauge records the measurement alongside labels on the int
// gauge associated with the provided handle.
func ( *MetricsRecorderList) ( *estats.Int64GaugeHandle,  int64,  ...string) {
	verifyLabels(.Descriptor(), ...)

	for ,  := range .metricsRecorders {
		.RecordInt64Gauge(, , ...)
	}
}