Added optional "timestamp" value as part of metric sample#337
Added optional "timestamp" value as part of metric sample#337brian-brazil merged 19 commits intoprometheus:masterfrom
Conversation
|
This is breaking tests, and there should be unittests added for this. It's be better to take a unboxed value. |
| return false; | ||
| } | ||
| Sample other = (Sample) obj; | ||
| boolean timestampEquals = true; |
There was a problem hiding this comment.
This is the Java 7 java.utils.Objects.equals. This project maintains Java 6 compatibility but it might be tidier to paste in this method and use it compare all the member objects using this method.
static boolean equals(Object a, Object b) { return (a == b) || (a != null && a.equals(b)); }
There was a problem hiding this comment.
I don't totally understand what you say:
boolean timestampEquals = true;
if ((timestamp != null && other.timestamp == null) || (timestamp == null && other.timestamp != null)) {
timestampEquals = false;
}
if (timestamp != null && other.timestamp != null) {
timestampEquals = other.timestamp.equals(timestamp);
}
The equals() used here is the same used in other parts of previously existing code, such as:
return other.name.equals(name) && other.labelNames.equals(labelNames)
&& other.labelValues.equals(labelValues) && other.value == value;
There was a problem hiding this comment.
My suggestion is to based on readability - but it's just a suggestion.
| hash = 37 * hash + labelValues.hashCode(); | ||
| long d = Double.doubleToLongBits(value); | ||
| hash = 37 * hash + (int)(d ^ (d >>> 32)); | ||
| hash = 37 * hash + timestamp.hashCode(); |
There was a problem hiding this comment.
this needs to be wrapped in an if (timestamp != null) check
There was a problem hiding this comment.
Thank you, I have changed it, but still not pushed.
| writer.write(' '); | ||
| writer.write(Collector.doubleToGoString(sample.value)); | ||
| if (sample.timestamp != null){ | ||
| writer.write(' '); |
There was a problem hiding this comment.
could you remove the tab and use spaces for indents?
There was a problem hiding this comment.
Sorry, I didn't realize about it, I have changed it, but still not pushed.
| long d = Double.doubleToLongBits(value); | ||
| hash = 37 * hash + (int)(d ^ (d >>> 32)); | ||
| if (timestamp != null) | ||
| hash = 37 * hash + timestamp.hashCode(); |
There was a problem hiding this comment.
could you remove the tab here?
There was a problem hiding this comment.
Sorry, now my Eclipse IDE is configured for use "spaces" (2) instead of "tabs".
| return other.name.equals(name) && other.labelNames.equals(labelNames) | ||
| && other.labelValues.equals(labelValues) && other.value == value; | ||
| && other.labelValues.equals(labelValues) && other.value == value | ||
| && timestampEquals; |
There was a problem hiding this comment.
also appears to be a tab here
There was a problem hiding this comment.
Sorry, now my Eclipse IDE is configured for use "spaces" (2) instead of "tabs".
|
@efelcon would you have time to add the unit tests that Brian asked for? |
|
I have the unit tests creation pending, now I have no time to complete it, but I expect to complete before weekend. |
|
I'm at FOSDEM and unlikely to give this a proper look until Tuesday.
…On 2 Feb 2018 14:08, "Felipe Conde" ***@***.***> wrote:
I have the unit tests creation pending, now I have no time to complete it,
but I expect to complete before weekend.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#337 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGyTdgOnNb2LVkYcqSiaizXLW5DplvZHks5tQwi1gaJpZM4R1-ju>
.
|
|
|
||
| @Test | ||
| public void testCollectWithTimestamp() { | ||
| Long now = System.currentTimeMillis(); |
| public final List<String> labelNames; | ||
| public final List<String> labelValues; // Must have same length as labelNames. | ||
| public final double value; | ||
| public final Long timestamp; |
There was a problem hiding this comment.
timestampMs would be clearer.
Can you also add a note that this field is subject to change?
There was a problem hiding this comment.
I'm agree, this has been changed.
| } | ||
| Sample other = (Sample) obj; | ||
|
|
||
| boolean timestampEquals = true; |
There was a problem hiding this comment.
This is a bit long, I think you can simplify a bit.
There was a problem hiding this comment.
Done. Now has been reduced to one line.
| /** | ||
| * Set the optional value for time stamp in epoch format. | ||
| */ | ||
| public void setTimestamp(Long timestamp) { |
There was a problem hiding this comment.
Direct instrumentation has no need for timestamps, these need to be removed.
There was a problem hiding this comment.
If I remove this, the Unit Tests for Counter called testCollectWithTimestamp must be removed, because there will be no way for setting the timestamp property (also happen the same for Gauge)). For me there is no problem so, are you agree to remove also the both Unit Tests called testCollectWithTimestamp?
There was a problem hiding this comment.
Timestamps only work via custom collectors, so tests need to implement one of those.
There was a problem hiding this comment.
Ok, now I think I understand what you mean. But I'm afraid I have commited several changes. Tomorrow I will work on this.
| writer.write(Collector.doubleToGoString(sample.value)); | ||
| if (sample.timestamp != null){ | ||
| writer.write(' '); | ||
| writer.write(sample.timestamp.toString()); |
Refactoring of some code in equals method.
…to "value" functions, such as get()/set()
…ture used by "value". This is needed for Unit Tests code.
…he new functions added (covering both cases: "labels" and "nolabels").
|
I have added a Unit Test for TextFormat java class (I'm not totally sure if it's all what you want). Please confirm me if you want me to remove the methods and Unit Tests added in |
brian-brazil
left a comment
There was a problem hiding this comment.
Yes, those should be removed.
| } | ||
|
|
||
| @Test | ||
| public void testMetricOutputWithTimetamp() throws IOException { |
|
@brian-brazil I have removed all code you request to remove, so I think that all is ready for your check. |
| TextFormat.write004(writer, registry.metricFamilySamples()); | ||
| assertEquals("# HELP nolabels help\n" | ||
| + "# TYPE nolabels untyped\n" | ||
| + "nolabels 1.0 "+ now +"\n", writer.toString()); |
There was a problem hiding this comment.
I'd prefer this was a literal string rather than dynamic, as the output here depends on Java's implicit conversion to string.
|
Thanks! |
I'm using an exporter based on this code and it's working fine.
To be honest I'm not using
equals()andhashCode()methods, so I haven't test it.One more thing, about
hashCode(): I'm not totally sure if code is totally agree with the current structure, so please check.