func extractZoneNetworkErrorLogs()

in parsing.go [25:62]


func extractZoneNetworkErrorLogs(zone zoneResp, zoneNames map[string]string, scrapeBucket *TimeBucket) (int, error) {
	// NELs have different sampling rates.
	//
	// According to https://w3c.github.io/network-error-logging/#generate-a-network-error-report
	// "ok" is the only accepted code for a successful response, so only those would have a different
	// sampling rate compared to all others.
	//
	// Currently, Cloudflare uses:
	// - the default of 1 as a `failure_fraction`
	// - 0.01 as a `success_fraction`
	//
	// So for every single failure and 100 successful connections the browser is instructed to report a success.
	// Thus, we multiply successes by 100.
	// This *might* be a dynamic value, but it seems constant across zones and is not exposed with its value in the
	// API, so for now, this is hard-coded.
	const failureFraction float64 = 1
	const successFraction float64 = 0.01

	for _, nel := range zone.NetworkErrorLogs {
		var currentFraction float64 = failureFraction
		if nel.Dimensions.Type == "ok" {
			currentFraction = successFraction
		}

		networkErrorLogs.WithLabelValues(
			zoneNames[zone.ZoneTag],
			nel.Dimensions.ClientIPCountryCode,
			toString(nel.Dimensions.ClientIPVersion),
			nel.Dimensions.LastKnownGoodColoCode,
			nel.Dimensions.Protocol,
			nel.Dimensions.Phase,
			nel.Dimensions.Type,
		).
			Add(float64(nel.Count)/currentFraction, scrapeBucket.getEndTime())
	}

	return len(zone.NetworkErrorLogs), nil
}