metricsmap: fix Prometheus exporter
metricsmap: fix Prometheus exporter

Fix the Prometheus exporter as it was not aggregating correctly the
multiple entries that make up a value.

This commit changes the logic from:

    func updatePrometheusMetrics(value) {
      updateMetric(value.Packets)
      updateMetric(value.Bytes)
    }

    func SyncMetrics() {
      for _, value := range values {
	updatePrometheusMetrics(value)
      }
    }

to:

    func updatePrometheusMetrics(values) {
      for _, value := range values {
	packets += value.Packets
	bytes   += value.Bytes
      }

      updateMetrics(packets)
      updateMetrics(bytes)
    }

    func SyncMetrics() {
      updatePrometheusMetrics(values)
    }

What updateMetric does is:

* diff the packets/bytes value it receive with the one stored in
  Prometheus
* increment the Prometheus counter by the delta it just calculated

Since the logic in updateMetric is not linear, it will work correctly
only if the packets/bytes counter it receives is the sum of all the
per-CPU values for a given key (rather than what we are doing now, which
is calling updateMetric() on every single per-CPU value for a given key)

Fixes: a59105352 ("pkg/maps/metricsmap: userspace aggregation of BPF_PER_CPU_HASH_MAP metrics map.")

Signed-off-by: 2ffe63ec4010b352e11700f96024edf13477699f@isovalent.com

cilium/cilium,tgraf/cilium,tklauser/cilium,tgraf/cilium,michi-covalent/cilium,tgraf/cilium,cilium/cilium,tklauser/cilium,cilium/cilium,michi-covalent/cilium,tgraf/cilium,tgraf/cilium,michi-covalent/cilium,michi-covalent/cilium,tgraf/cilium,cilium/cilium,tklauser/cilium,tklauser/cilium,michi-covalent/cilium,cilium/cilium,tklauser/cilium