// newInstrumentingAdapter returns an instance of an instrumenting Adapter.
newInstrumentingAdapter returns an instance of an instrumenting Adapter.
// newInstrumentingAdapter returns an instance of an instrumenting Adapter .
func newInstrumentingAdapter() *instrumentingAdapter {
	logger := log.New(os.Stdout, "Instrumenting ", log.LstdFlags)
	buildInfo := promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "build_info",
		Help:      "Number of logspout logdna adapter builds.",
	},
		[]string{"go_version", "adapter_version"},
	)
	requestCount := promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "request_total",
		Help:      "Number of stream requests received.",
	}, []string{actionLabel})
	requestLatency := promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "request_latency_seconds",
		Help:      "Total duration of stream requests in seconds.",
	}, []string{actionLabel})
	logDNARequestCount := promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "logdna_request_total",
		Help:      "Number of requests to LogDNA service while flushing message.",
	}, []string{actionLabel, statusLabel})
	streamMarshalDataErrorCount := promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "stream_marshal_data_error_total",
		Help:      "Number of errors when marshalling the received stream data.",
	}, []string{})
	flushBufferEncodeDataErrorCount := promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "flush_buffer_encode_data_error_total",
		Help:      "Number of errors when encoding the data while flushing message.",
	}, []string{})
	flushBufferLogDNACodeErrorCount := promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "logspout_logdna",
		Subsystem: "adapter",
		Name:      "flush_buffer_logdna_code_error_total",
		Help:      "Number of errors when posting the message to LogDNA because of a code error when performing the request while flushing message.",
	}, []string{})
	for _, action := range actionLabelsValues {
		if _, err := requestCount.GetMetricWith(prometheus.Labels{
			actionLabel: action,
		}); err != nil {
			logger.Println(fmt.Errorf("cannot initialize request counter metric: %s", err))
		}
	}
	for _, action := range actionLabelsValues {
		if _, err := requestLatency.GetMetricWith(prometheus.Labels{
			actionLabel: action,
		}); err != nil {
			logger.Println(fmt.Errorf("cannot initialize request latency metric: %s", err))
		}
	}
	for _, status := range logDNAStatusCodes {
		for _, action := range actionLabelsValues {
			if _, err := logDNARequestCount.GetMetricWith(prometheus.Labels{
				actionLabel: action,
				statusLabel: status,
			}); err != nil {
				logger.Println(fmt.Errorf("cannot initialize flush buffer logdna client error counter metric: %s", err))
			}
		}
	}
	return &instrumentingAdapter{
		buildInfo: buildInfo,
		requestCount:       requestCount,
		requestLatency:     requestLatency,
		logDNARequestCount: logDNARequestCount,
		streamMarshalDataErrorCount:     streamMarshalDataErrorCount,
		flushBufferEncodeDataErrorCount: flushBufferEncodeDataErrorCount,
		flushBufferLogDNACodeErrorCount: flushBufferLogDNACodeErrorCount,
		logger: logger,
	}
}
func newInstrumentingAdapter ( ) * instrumentingAdapter { logger := log . New ( os . Stdout , " " , log . LstdFlags ) buildInfo := promauto . NewGaugeVec ( prometheus . GaugeOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { " " , " " } , ) requestCount := promauto . NewCounterVec ( prometheus . CounterOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { actionLabel } ) requestLatency := promauto . NewHistogramVec ( prometheus . HistogramOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { actionLabel } ) logDNARequestCount := promauto . NewCounterVec ( prometheus . CounterOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { actionLabel , statusLabel } ) streamMarshalDataErrorCount := promauto . NewCounterVec ( prometheus . CounterOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { } ) flushBufferEncodeDataErrorCount := promauto . NewCounterVec ( prometheus . CounterOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { } ) flushBufferLogDNACodeErrorCount := promauto . NewCounterVec ( prometheus . CounterOpts { Namespace : " " , Subsystem : " " , Name : " " , Help : " " , } , [ ] string { } ) for _ , action := range actionLabelsValues { if _ , err := requestCount . GetMetricWith ( prometheus . Labels { actionLabel : action , } ) ; err != nil { logger . Println ( fmt . Errorf ( " " , err ) ) } } for _ , action := range actionLabelsValues { if _ , err := requestLatency . GetMetricWith ( prometheus . Labels { actionLabel : action , } ) ; err != nil { logger . Println ( fmt . Errorf ( " " , err ) ) } } for _ , status := range logDNAStatusCodes { for _ , action := range actionLabelsValues { if _ , err := logDNARequestCount . GetMetricWith ( prometheus . Labels { actionLabel : action , statusLabel : status , } ) ; err != nil { logger . Println ( fmt . Errorf ( " " , err ) ) } } } return & instrumentingAdapter { buildInfo : buildInfo , requestCount : requestCount , requestLatency : requestLatency , logDNARequestCount : logDNARequestCount , streamMarshalDataErrorCount : streamMarshalDataErrorCount , flushBufferEncodeDataErrorCount : flushBufferEncodeDataErrorCount , flushBufferLogDNACodeErrorCount : flushBufferLogDNACodeErrorCount , logger : logger , } }
newInstrumentingAdapter returns an instance of an instrumenting Adapter.
newInstrumentingAdapter returns an instance of an instrumenting Adapter .
// ## Define metrics // general metrics // performance metrics // error metrics // ## Initialize metrics: why? https://www.robustperception.io/existential-issues-with-metrics // performance metrics