-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple samples within same metric 'NewMetricWithTimestamp' #1137
Comments
Hey, I think his is not desired functionality, I am afraid. ): Prometheus clients are optimized to present the current state (or last known state) of data to a potential collector/scraper/Prometheus. Even if we somewhat hack it to put multiple samples of the same series, Prometheus and other scrapers will most likely fail. In other words, you would need to propose a such a change to the https://github.com/OpenObservability/OpenMetrics standard. Only if it's there, will we implement it such extension (which I doubt will be accepted). Perhaps you might need to look in Otel Go SDK and push the metric paradigm to have functionality like this, but you need to understand the huge impact of buffering multiple samples in your clients. Hope that makes sense. I will close this issue to avoid confusion but feel free to discuss - maybe I missed something. We can always reopen. Thanks! |
@bwplotka I was just checking the OpenMetrics standard specification. In the
|
By the way, just tested this with the Python client, and it supports what I suggested import time
import random
import datetime
from prometheus_client.core import GaugeMetricFamily, REGISTRY
from prometheus_client import start_http_server
class RandomNumberCollector(object):
def __init__(self):
pass
def collect(self):
gauge = GaugeMetricFamily("random_number", "A random number generator, I have no better idea", labels=["randomNum"])
gauge.add_metric(['random_num'], random.randint(1, 20), int(datetime.datetime.utcnow().timestamp()))
time.sleep(1)
gauge.add_metric(['random_num'], random.randint(1, 20), int(datetime.datetime.utcnow().timestamp()))
yield gauge
if __name__ == "__main__":
port = 9000
frequency = 1
start_http_server(port)
REGISTRY.register(RandomNumberCollector())
while True:
time.sleep(frequency)
|
Client supports, but how do you want to consume it? Do you plan to use Prometheus or Prometheus-like scraper? |
You got me with OM statement: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#metric-types-1 I don't understand yet, why this is there, but you are right, OM supports it. Trying to get more information about it. BTW Again, what's your use case? Why do you want this done? (: |
I was planning to use Prometheus. |
Please check how this is consumed by Prometheus. It's likely Prometheus just drops other samples, but let's see. Maybe there is some work to be done there. For 2-4 samples it's ok, but more than that on scale, the scrape will be simply too large. Given OM supports it I think I might change my mind towards implementation here (: |
They are func (s *httpServer) handleMetricReq(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
now := time.Now()
w.Write([]byte("# HELP random_number A random number generator, I have no better idea\n"))
w.Write([]byte("# TYPE random_number gauge\n"))
w.Write([]byte("random_number{randomNum=\"random_num\"} 100.0 " + strconv.FormatInt(now.Add(-60*time.Minute).Unix(), 10) + "000\n"))
w.Write([]byte("random_number{randomNum=\"random_num\"} 180.0 " + strconv.FormatInt(now.Add(-20*time.Minute).Unix(), 10) + "000\n"))
w.Write([]byte("random_number{randomNum=\"random_num\"} 120.0 " + strconv.FormatInt(now.Add(-10*time.Minute).Unix(), 10) + "000\n"))
w.Write([]byte("random_number{randomNum=\"random_num\"} 140.0 " + strconv.FormatInt(now.Add(-5*time.Minute).Unix(), 10) + "000\n"))
} |
I don't know if @Elecon-rou wants to proceed with it, if not I can open a new PR |
@bwplotka @machadovilaca I'll try to add the test, sure |
@bwplotka I created a new PR with the fix and a unit test for the metric consistency check |
This might not even be considered a bug, but I think this is a very annoying behavior.
When using
NewMetricWithTimestamp
in a Collector as in:The client is running checkMetricConsistency for each of the pushed metrics which is throwing the following error
I think the validation should be aware of the metrics timestamps and not throw an error in this case because the metrics belong to different point in times, and there are use cases where it makes sense to allow multiple ones to be pushed in the same scrape call.
The text was updated successfully, but these errors were encountered: