mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-06-03 13:59:34 +00:00
remove unnecessary clone methods
Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
parent
3673e56e85
commit
9cd6e54279
|
@ -56,33 +56,10 @@ type SummaryOptions struct {
|
|||
BufCap uint32 `yaml:"buf_cap"`
|
||||
}
|
||||
|
||||
// Clone returns a copy of SummaryOptions
|
||||
func (s *SummaryOptions) Clone() SummaryOptions {
|
||||
r := SummaryOptions{
|
||||
Quantiles: make([]metricObjective, len(s.Quantiles)),
|
||||
}
|
||||
copy(r.Quantiles, s.Quantiles)
|
||||
r.MaxAge = s.MaxAge
|
||||
r.AgeBuckets = s.AgeBuckets
|
||||
r.BufCap = s.BufCap
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
type HistogramOptions struct {
|
||||
Buckets []float64 `yaml:"buckets"`
|
||||
}
|
||||
|
||||
// Clone returns a copy of HistogramOptions
|
||||
func (h *HistogramOptions) Clone() HistogramOptions {
|
||||
r := HistogramOptions{
|
||||
Buckets: make([]float64, len(h.Buckets)),
|
||||
}
|
||||
copy(r.Buckets, h.Buckets)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
type metricObjective struct {
|
||||
Quantile float64 `yaml:"quantile"`
|
||||
Error float64 `yaml:"error"`
|
||||
|
@ -94,24 +71,22 @@ var defaultQuantiles = []metricObjective{
|
|||
{Quantile: 0.99, Error: 0.001},
|
||||
}
|
||||
|
||||
// GetDefaultHistogramOptions returns a copy of the default HistogramOptions
|
||||
// GetDefaultHistogramOptions returns the default HistogramOptions with default buckets if none are present
|
||||
func (m *MetricMapper) GetDefaultHistogramOptions() HistogramOptions {
|
||||
r := m.Defaults.HistogramOptions.Clone()
|
||||
if len(m.Defaults.HistogramOptions.Buckets) == 0 {
|
||||
r.Buckets = prometheus.DefBuckets
|
||||
m.Defaults.HistogramOptions.Buckets = prometheus.DefBuckets
|
||||
}
|
||||
|
||||
return r
|
||||
return m.Defaults.HistogramOptions
|
||||
}
|
||||
|
||||
// GetDefaultSummaryOptions returns a copy of the default SummaryOptions
|
||||
// GetDefaultSummaryOptions returns the default SummaryOptions with default quantiles if none are present
|
||||
func (m *MetricMapper) GetDefaultSummaryOptions() SummaryOptions {
|
||||
r := m.Defaults.SummaryOptions.Clone()
|
||||
if len(m.Defaults.SummaryOptions.Quantiles) == 0 {
|
||||
r.Quantiles = defaultQuantiles
|
||||
m.Defaults.SummaryOptions.Quantiles = defaultQuantiles
|
||||
}
|
||||
|
||||
return r
|
||||
return m.Defaults.SummaryOptions
|
||||
}
|
||||
|
||||
func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, options ...CacheOption) error {
|
||||
|
@ -228,7 +203,7 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op
|
|||
return fmt.Errorf("cannot use histogram observer and summary options at the same time")
|
||||
}
|
||||
if currentMapping.HistogramOptions == nil {
|
||||
c := n.Defaults.HistogramOptions.Clone()
|
||||
c := n.GetDefaultHistogramOptions()
|
||||
currentMapping.HistogramOptions = &c
|
||||
}
|
||||
if currentMapping.LegacyBuckets != nil && len(currentMapping.LegacyBuckets) != 0 {
|
||||
|
@ -241,7 +216,7 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op
|
|||
return fmt.Errorf("cannot use summary observer and histogram options at the same time")
|
||||
}
|
||||
if currentMapping.SummaryOptions == nil {
|
||||
c := n.Defaults.SummaryOptions.Clone()
|
||||
c := n.GetDefaultSummaryOptions()
|
||||
currentMapping.SummaryOptions = &c
|
||||
}
|
||||
if currentMapping.LegacyQuantiles != nil && len(currentMapping.LegacyQuantiles) != 0 {
|
||||
|
|
|
@ -251,8 +251,8 @@ func (r *Registry) GetHistogram(metricName string, labels prometheus.Labels, hel
|
|||
metricsCount.WithLabelValues("histogram").Inc()
|
||||
histogramOptions := r.Mapper.GetDefaultHistogramOptions()
|
||||
|
||||
if mapping != nil {
|
||||
if mapping.HistogramOptions != nil && len(mapping.HistogramOptions.Buckets) > 0 {
|
||||
if mapping != nil && mapping.HistogramOptions != nil {
|
||||
if len(mapping.HistogramOptions.Buckets) > 0 {
|
||||
histogramOptions.Buckets = mapping.HistogramOptions.Buckets
|
||||
}
|
||||
}
|
||||
|
@ -301,18 +301,17 @@ func (r *Registry) GetSummary(metricName string, labels prometheus.Labels, help
|
|||
metricsCount.WithLabelValues("summary").Inc()
|
||||
summaryOptions := r.Mapper.GetDefaultSummaryOptions()
|
||||
if mapping != nil && mapping.SummaryOptions != nil {
|
||||
tmp := mapping.SummaryOptions.Clone()
|
||||
if len(tmp.Quantiles) > 0 {
|
||||
summaryOptions.Quantiles = tmp.Quantiles
|
||||
if len(mapping.SummaryOptions.Quantiles) > 0 {
|
||||
summaryOptions.Quantiles = mapping.SummaryOptions.Quantiles
|
||||
}
|
||||
if tmp.BufCap != 0 {
|
||||
summaryOptions.BufCap = tmp.BufCap
|
||||
if mapping.SummaryOptions.BufCap != 0 {
|
||||
summaryOptions.BufCap = mapping.SummaryOptions.BufCap
|
||||
}
|
||||
if tmp.AgeBuckets != 0 {
|
||||
summaryOptions.AgeBuckets = tmp.AgeBuckets
|
||||
if mapping.SummaryOptions.AgeBuckets != 0 {
|
||||
summaryOptions.AgeBuckets = mapping.SummaryOptions.AgeBuckets
|
||||
}
|
||||
if tmp.MaxAge != 0 {
|
||||
summaryOptions.MaxAge = tmp.MaxAge
|
||||
if mapping.SummaryOptions.MaxAge != 0 {
|
||||
summaryOptions.MaxAge = mapping.SummaryOptions.MaxAge
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue