Conversation
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
|
Hey @vesari , just passing by to ask if there is anything we could do to unblock you 👋 |
@ArthurSens hello! I think I'm just using a Go version which is too new, I plan on fixing that later today. Thanks a lot for checking on me, much appreciated! :) |
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Thank you very much, I'm working on addressing your requests for changes and your observations. I'll get back to you once I'm done :) |
…t is given Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
…c argument in V2 NewDesc Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
|
This is now ready for review :) |
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
| for _, opt := range opts { | ||
| opt(d) | ||
| } | ||
| unit := d.unit |
| } | ||
| unitStr := "" | ||
| if d.unit != "" { | ||
| unitStr = fmt.Sprintf(", unit: %q", d.unit) |
There was a problem hiding this comment.
I'd add this inline and show unit is empty? We expanded the data structure so we can expand the error too
|
|
||
| func NewInfoVec(name, help string, labelNames []string) *InfoVec { | ||
| desc := prometheus.NewDesc(name, help, labelNames, nil) | ||
| func NewInfoVec(name, help string, labelNames []string, unit ...string) *InfoVec { |
There was a problem hiding this comment.
Info likely does not have unit?
| sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1] | ||
|
|
||
| // Extract unit from the runtime/metrics name (e.g., "/gc/heap/allocs:bytes" -> "bytes") | ||
| unit := d.Name[strings.IndexRune(d.Name, ':')+1:] |
There was a problem hiding this comment.
As found in https://gist.github.com/bwplotka/a38c33a74fad88a46c4623e924fa58c8#file-prometheusclient_golang1392-md, I think indeed we should handle the case of no unit here gracefully (-1 index response):
> Unsafe Substring Slice during Runtime Metric Unit Extraction
File with exact line number: prometheus/go_collector_latest.go:L213
Link to a file line on GitHub PR: https://github.com/prometheus/client_golang/pull/1392/files#diff-8360f0c0ae2f0d98fb9ecdf37119d6d333dc17ec23f0547055c1ddfdf4ed0759R213
Problem: The unit is extracted using d.Name[strings.IndexRune(d.Name, ':')+1:]. If a runtime metric is introduced without a :, strings.IndexRune evaluates to -1 resulting in -1+1 = 0. The unit silently turns into the entire metric name, bypassing obvious fault detection. (Note: this extraction assumption existed before the PR for histograms, but was generalized here).
Suggestion: Consider checking if strings.ContainsRune(d.Name, ':') before slicing to future-proof the collector against misconfigured runtime metrics.
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Arianna Vespri <36129782+vesari@users.noreply.github.com>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
|
Ready for review. |
bwplotka
left a comment
There was a problem hiding this comment.
It looks generally good, but some comments are not address. If you want to skip them, that's ok, just let us know what's the rationales
Thanks!
| var ( | ||
| enc expfmt.Encoder | ||
| encOpts []expfmt.EncoderOption | ||
| ) | ||
| if opts.EnableOpenMetricsTextCreatedSamples { | ||
| enc = expfmt.NewEncoder(w, contentType, expfmt.WithCreatedLines()) | ||
| } else { | ||
| enc = expfmt.NewEncoder(w, contentType) | ||
| encOpts = append(encOpts, expfmt.WithCreatedLines()) | ||
| } | ||
| enc = expfmt.NewEncoder(w, contentType, encOpts...) |
There was a problem hiding this comment.
Unrelated change, but if we want this we could simplify further:
| var ( | |
| enc expfmt.Encoder | |
| encOpts []expfmt.EncoderOption | |
| ) | |
| if opts.EnableOpenMetricsTextCreatedSamples { | |
| enc = expfmt.NewEncoder(w, contentType, expfmt.WithCreatedLines()) | |
| } else { | |
| enc = expfmt.NewEncoder(w, contentType) | |
| encOpts = append(encOpts, expfmt.WithCreatedLines()) | |
| } | |
| enc = expfmt.NewEncoder(w, contentType, encOpts...) | |
| var encOpts []expfmt.EncoderOption | |
| if opts.EnableOpenMetricsTextCreatedSamples { | |
| encOpts = append(encOpts, expfmt.WithCreatedLines()) | |
| } | |
| enc := expfmt.NewEncoder(w, contentType, encOpts...) |
vesari
left a comment
There was a problem hiding this comment.
I could not comment if not in the form a review as the GitHub UI is being whimsical for some reason and also doesn't allow me to accept your code suggestion
|
@bwplotka About your comment: "do you plan to address this?" |
|
@bwplotka about your "ping" comment: |
bwplotka
left a comment
There was a problem hiding this comment.
Thanks for catching my misunderstanding (error vs String). All good except one tiny nit!
This PR adds support for unit for Open Metrics. It is ready for review, but not ready to merge (see my long comment below). Fixes #684.