28
28
import com .google .common .collect .ImmutableMultimap ;
29
29
import com .google .common .io .Resources ;
30
30
import org .junit .Assert ;
31
+ import org .junit .Ignore ;
31
32
import org .junit .Test ;
32
33
33
34
import java .io .IOException ;
34
35
import java .time .Instant ;
35
36
import java .time .ZoneOffset ;
36
37
import java .time .ZonedDateTime ;
37
- import java .util .Arrays ;
38
38
import java .util .List ;
39
39
import java .util .Optional ;
40
- import java . util . stream . Collectors ;
40
+ import javax . annotation . Nullable ;
41
41
42
42
/**
43
43
* Tests for the prometheus parser.
@@ -53,7 +53,8 @@ public void testParseEmpty() throws ParsingException, IOException {
53
53
Assert .assertEquals (0 , records .size ());
54
54
}
55
55
56
- @ Test
56
+ @ Test ()
57
+ @ Ignore ("Currently dropping aggregates" )
57
58
public void testParseSingleRecord () throws ParsingException , IOException {
58
59
final ZonedDateTime time = ZonedDateTime .ofInstant (Instant .ofEpochMilli (1542330080682L ), ZoneOffset .UTC );
59
60
final List <Record > records = parseRecords ("PrometheusParserTest/testSingleRecord" );
@@ -86,17 +87,17 @@ public void testParseSingleRecord() throws ParsingException, IOException {
86
87
87
88
@ Test
88
89
public void testParseSingleRecordWithoutUnitInterpreter () throws ParsingException , IOException {
89
- final List <Record > records = parseRecords ("PrometheusParserTest/testSingleRecord " , createParserWithoutInterpreter ());
90
- final Record record = records .get (0 );
90
+ final List <Record > records = parseRecords ("PrometheusParserTest/testLivePrometheus2 " , createParserWithoutInterpreter ());
91
+ final Record record = records .get (57 );
91
92
final ImmutableMap <String , ? extends Metric > metrics = record .getMetrics ();
92
93
Assert .assertEquals (1 , metrics .size ());
93
- final Metric gauge = metrics .get ("rpc_durations_histogram_seconds_count " );
94
+ final Metric gauge = metrics .get ("container_spec_memory_limit_bytes " );
94
95
Assert .assertNotNull (gauge );
95
96
Assert .assertEquals (MetricType .GAUGE , gauge .getType ());
96
97
Assert .assertEquals (1 , gauge .getValues ().size ());
97
98
final Quantity gaugeQuantity = gauge .getValues ().get (0 );
98
99
Assert .assertEquals (Optional .empty (), gaugeQuantity .getUnit ());
99
- Assert .assertEquals (493.0 , gaugeQuantity .getValue (), 0.001 );
100
+ Assert .assertEquals (1.3500524544e11 , gaugeQuantity .getValue (), 0.001 );
100
101
}
101
102
102
103
@ Test (expected = ParsingException .class )
@@ -129,10 +130,12 @@ public void testUnitParserNoUnit() {
129
130
testUnitParserNoUnitHelper ("foo_bar" );
130
131
testUnitParserNoUnitHelper ("foo_seconds_bar" );
131
132
testUnitParserNoUnitHelper ("seconds_bar" );
133
+ testUnitParserNoUnitHelper ("foo_seconds_total_" );
134
+ testUnitParserNoUnitHelper ("foo_seconds_" );
132
135
}
133
136
private void testUnitParserNoUnitHelper (final String name ) {
134
137
final PrometheusToRecordParser .ParseResult expectedResult
135
- = new PrometheusToRecordParser .ParseResult (name , Optional .empty ());
138
+ = new PrometheusToRecordParser .ParseResult (name , Optional .empty (), Optional . empty () );
136
139
Assert .assertEquals (expectedResult , createParser ().parseNameAndUnit (name ));
137
140
}
138
141
@@ -160,28 +163,30 @@ public void testUnitParserBits() {
160
163
public void testLive1 () throws ParsingException , IOException {
161
164
final List <Record > records = parseRecords ("PrometheusParserTest/testLivePrometheus1" );
162
165
163
- Assert .assertEquals (500 , records .size ());
166
+ Assert .assertEquals (294 , records .size ());
164
167
}
165
168
166
169
private static void testUnitParsing (final String prometheusUnit , final Unit expected ) {
167
- assertUnitNewName (prometheusUnit , prometheusUnit , expected );
168
- assertUnitNewName ("foo_" + prometheusUnit , prometheusUnit , expected );
169
- assertUnitNewName (prometheusUnit + "_total" , prometheusUnit , expected );
170
- assertUnitNewName (prometheusUnit + "_bucket" , prometheusUnit , expected );
171
- assertUnitNewName (prometheusUnit + "_sum" , prometheusUnit , expected );
172
- assertUnitNewName (prometheusUnit + "_avg" , prometheusUnit , expected );
173
- assertUnitNewName (prometheusUnit + "_count" , prometheusUnit , expected );
174
- assertUnitNewName (prometheusUnit + "_total_count" , prometheusUnit , expected );
175
- assertUnitNewName ("foo_" + prometheusUnit + "_total_count" , prometheusUnit , expected );
176
- }
177
- private static void assertUnitNewName (final String fullName , final String prometheusUnit , final Unit expectedUnit ) {
170
+ assertUnitNewName (prometheusUnit , expected , null );
171
+ assertUnitNewName ("foo_" + prometheusUnit , expected , null );
172
+ assertUnitNewName ("foo_" + prometheusUnit + "_total" , expected , "total" );
173
+ assertUnitNewName ("foo_" + prometheusUnit + "_bucket" , expected , "bucket" );
174
+ assertUnitNewName ("foo_" + prometheusUnit + "_sum" , expected , "sum" );
175
+ assertUnitNewName ("foo_" + prometheusUnit + "_avg" , expected , "avg" );
176
+ assertUnitNewName ("foo_" + prometheusUnit + "_count" , expected , "count" );
177
+ assertUnitNewName (prometheusUnit + "_total_count" , null , "count" );
178
+ assertUnitNewName ("foo_" + prometheusUnit + "_total_count" , null , "count" );
179
+ assertUnitNewName ("foo_" + prometheusUnit + "_total" , expected , "total" );
180
+ assertUnitNewName ("foo_" + prometheusUnit + "_sum" , expected , "sum" );
181
+ }
182
+ private static void assertUnitNewName (
183
+ final String fullName ,
184
+ @ Nullable final Unit expectedUnit ,
185
+ @ Nullable final String expectedAggregation ) {
178
186
final PrometheusToRecordParser parser = createParser ();
179
- final String newName
180
- = Arrays .stream (fullName .split ("_" ))
181
- .filter (x -> !prometheusUnit .equals (x ))
182
- .collect (Collectors .joining ("_" ));
183
187
final PrometheusToRecordParser .ParseResult expectedResult
184
- = new PrometheusToRecordParser .ParseResult (newName , Optional .of (expectedUnit ));
188
+ = new PrometheusToRecordParser .ParseResult (
189
+ fullName , Optional .ofNullable (expectedAggregation ), Optional .ofNullable (expectedUnit ));
185
190
Assert .assertEquals (expectedResult , parser .parseNameAndUnit (fullName ));
186
191
}
187
192
0 commit comments