-/* metric_create allocates and initializes a new metric. */
-static Io__Prometheus__Client__Metric *metric_create(value_list_t const *vl) {
- Io__Prometheus__Client__Metric *msg = calloc(1, sizeof(*msg));
- if (msg == NULL)
+#define METRIC_INIT \
+ &(Io__Prometheus__Client__Metric) { \
+ .label = \
+ (Io__Prometheus__Client__LabelPair *[]){ \
+ &(Io__Prometheus__Client__LabelPair){ \
+ .name = NULL, \
+ }, \
+ &(Io__Prometheus__Client__LabelPair){ \
+ .name = NULL, \
+ }, \
+ &(Io__Prometheus__Client__LabelPair){ \
+ .name = NULL, \
+ }, \
+ }, \
+ .n_label = 0, \
+ }
+
+#define METRIC_ADD_LABELS(m, vl) \
+ do { \
+ if (strlen((vl)->plugin_instance) != 0) { \
+ (m)->label[(m)->n_label]->name = (char *)(vl)->plugin; \
+ (m)->label[(m)->n_label]->value = (char *)(vl)->plugin_instance; \
+ (m)->n_label++; \
+ } \
+ \
+ if (strlen((vl)->type_instance) != 0) { \
+ (m)->label[(m)->n_label]->name = "type"; \
+ if (strlen((vl)->plugin_instance) == 0) \
+ (m)->label[(m)->n_label]->name = (char *)(vl)->plugin; \
+ (m)->label[(m)->n_label]->value = (char *)(vl)->type_instance; \
+ (m)->n_label++; \
+ } \
+ \
+ (m)->label[(m)->n_label]->name = "instance"; \
+ (m)->label[(m)->n_label]->value = (char *)(vl)->host; \
+ (m)->n_label++; \
+ } while (0)
+
+/* metric_clone allocates and initializes a new metric based on orig. */
+static Io__Prometheus__Client__Metric *
+metric_clone(Io__Prometheus__Client__Metric const *orig) {
+ Io__Prometheus__Client__Metric *copy = calloc(1, sizeof(*copy));
+ if (copy == NULL)