func readStatsJSON()

in opentelemetry_collector/receiver/nginxreceiver/nginx_stats_collector.go [121:145]


func readStatsJSON(statsJSON []byte) (*NginxStats, error) {
	// Setting the default int value to -1 makes it possible to tell when a value is missing from the json
	// since the regular default is 0, which is a valid value for the stats.
	stats := NginxStats{
		RequestLatency: LatencyStats{
			RequestCount: -1,
			LatencySum:   -1,
			SumSquares:   -1,
		},
		UpstreamLatency: LatencyStats{
			RequestCount: -1,
			LatencySum:   -1,
			SumSquares:   -1,
		},
		WebsocketLatency: LatencyStats{
			RequestCount: -1,
			LatencySum:   -1,
			SumSquares:   -1,
		},
	}
	if err := json.Unmarshal(statsJSON, &stats); err != nil {
		return nil, err
	}
	return &stats, nil
}