<commit_before>package main

import (
	"log"

	"github.com/nsqio/go-nsq"
	"github.com/raintank/raintank-metric/msg"
)

type Handler struct {
	metrics Metrics
}

func NewHandler(metrics Metrics) *Handler {
	return &Handler{
		metrics: metrics,
	}
}

func (h *Handler) HandleMessage(m *nsq.Message) error {
	ms, err := msg.MetricDataFromMsg(m.Body)
	if err != nil {
		log.Println("ERROR:", err, "skipping message")
		return nil
	}
	//	msgsAge.Value(time.Now().Sub(ms.Produced).Nanoseconds() / 1000)

	err = ms.DecodeMetricData()
	if err != nil {
		log.Println("ERROR:", err, "skipping message")
		return nil
	}
	//	metricsPerMessage.Value(int64(len(ms.Metrics)))

	for _, metric := range ms.Metrics {
		m := h.metrics.Get(metric.Name)
		m.Add(uint32(metric.Time), metric.Value)
	}

	return nil
}
<commit_msg>use metric.Id() as key instead of name.<commit_after>package main

import (
	"log"

	"github.com/nsqio/go-nsq"
	"github.com/raintank/raintank-metric/msg"
)

type Handler struct {
	metrics Metrics
}

func NewHandler(metrics Metrics) *Handler {
	return &Handler{
		metrics: metrics,
	}
}

func (h *Handler) HandleMessage(m *nsq.Message) error {
	ms, err := msg.MetricDataFromMsg(m.Body)
	if err != nil {
		log.Println("ERROR:", err, "skipping message")
		return nil
	}
	//	msgsAge.Value(time.Now().Sub(ms.Produced).Nanoseconds() / 1000)

	err = ms.DecodeMetricData()
	if err != nil {
		log.Println("ERROR:", err, "skipping message")
		return nil
	}
	//	metricsPerMessage.Value(int64(len(ms.Metrics)))

	for _, metric := range ms.Metrics {
		m := h.metrics.Get(metric.Id())
		m.Add(uint32(metric.Time), metric.Value)
	}

	return nil
}

{'fraction_non_alphanumeric': 0.15873015873015872, 'fraction_numerical': 0.009768009768009768, 'mean_word_length': 4.01223241590214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2459678', 'n_tokens_mistral': 662, 'n_tokens_neox': 615, 'n_words': 128}