Files
payouts/internal/service/monitoring/config/metrics.go

56 lines
1.2 KiB
Go

package config
import (
"reflect"
"strconv"
"strings"
"github.com/go-viper/mapstructure/v2"
)
type CommaSeparatedFloat64Slice []float64
func CommaSeparatedFloat64SliceHookFunc() mapstructure.DecodeHookFuncType {
return func(
f reflect.Type,
t reflect.Type,
data interface{},
) (interface{}, error) {
// Check that the data is string
if f.Kind() != reflect.String {
return data, nil
}
// Check that the target type is our custom type
if t != reflect.TypeOf(CommaSeparatedFloat64Slice{}) {
return data, nil
}
stringSlice := strings.Split(data.(string), ",")
floatSlice := make([]float64, 0)
for _, str := range stringSlice {
val, err := strconv.ParseFloat(strings.TrimSpace(str), 64)
if err != nil {
return nil, err
}
floatSlice = append(floatSlice, val)
}
// Return the parsed value
return CommaSeparatedFloat64Slice(floatSlice), nil
}
}
// HttpMetrics configuration properties for http monitoring
type HttpMetrics struct {
HistogramEnabled bool
Buckets CommaSeparatedFloat64Slice
}
// Metrics configuration properties for monitoring
type Metrics struct {
Endpoint string
HistogramBuckets CommaSeparatedFloat64Slice
Http HttpMetrics
}