Skip to content

Commit 5282cca

Browse files
jukkarnashif
authored andcommitted
net: prometheus: Use const pointer for string data
Instead of allocating space for description and label name + value, have a const pointer for it. The data is set typically statically when the metric is defined, so there should be no need to allocate separate buffer for those strings. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 90fb4b3 commit 5282cca

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

include/zephyr/net/prometheus/label.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
* @{
1717
*/
1818

19-
/* maximum length of label key */
20-
#define MAX_PROMETHEUS_LABEL_KEY_LENGTH 16
21-
/* maximum length of label value */
22-
#define MAX_PROMETHEUS_LABEL_VALUE_LENGTH 16
2319
/* maximum namber of labels per metric */
2420
#define MAX_PROMETHEUS_LABELS_PER_METRIC 5
2521

@@ -30,9 +26,9 @@
3026
*/
3127
struct prometheus_label {
3228
/** Prometheus metric label key */
33-
char key[MAX_PROMETHEUS_LABEL_KEY_LENGTH];
29+
const char *key;
3430
/** Prometheus metric label value */
35-
char value[MAX_PROMETHEUS_LABEL_VALUE_LENGTH];
31+
const char *value;
3632
};
3733

3834
/**

include/zephyr/net/prometheus/metric.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ enum prometheus_metric_type {
3737
PROMETHEUS_HISTOGRAM,
3838
};
3939

40-
#define MAX_METRIC_NAME_LENGTH 32
41-
#define MAX_METRIC_DESCRIPTION_LENGTH 64
42-
4340
/**
4441
* @brief Type used to represent a Prometheus metric base.
4542
*
@@ -52,9 +49,9 @@ struct prometheus_metric {
5249
/** Type of the Prometheus metric. */
5350
enum prometheus_metric_type type;
5451
/** Name of the Prometheus metric. */
55-
char name[MAX_METRIC_NAME_LENGTH];
52+
const char *name;
5653
/** Description of the Prometheus metric. */
57-
char description[MAX_METRIC_DESCRIPTION_LENGTH];
54+
const char *description;
5855
/** Labels associated with the Prometheus metric. */
5956
struct prometheus_label labels[MAX_PROMETHEUS_LABELS_PER_METRIC];
6057
/** Number of labels associated with the Prometheus metric. */

0 commit comments

Comments
 (0)