2525import java .util .Map ;
2626
2727import static org .elasticsearch .inference .telemetry .InferenceStats .create ;
28- import static org .elasticsearch .inference .telemetry .InferenceStats .modelAttributes ;
2928import static org .elasticsearch .inference .telemetry .InferenceStats .responseAttributes ;
29+ import static org .elasticsearch .inference .telemetry .InferenceStats .serviceAttributes ;
3030import static org .hamcrest .Matchers .is ;
3131import static org .hamcrest .Matchers .nullValue ;
3232import static org .mockito .ArgumentMatchers .assertArg ;
@@ -41,23 +41,20 @@ public static InferenceStats mockInferenceStats() {
4141 return new InferenceStats (mock (), mock (), mock ());
4242 }
4343
44- public void testRecordWithModel () {
44+ public void testRecordWithService () {
4545 var longCounter = mock (LongCounter .class );
4646 var stats = new InferenceStats (longCounter , mock (), mock ());
4747
48- stats .requestCount ().incrementBy (1 , modelAttributes (model ("service" , TaskType .ANY , "modelId" )));
48+ stats .requestCount ().incrementBy (1 , serviceAttributes (model ("service" , TaskType .ANY , "modelId" )));
4949
50- verify (longCounter ).incrementBy (
51- eq (1L ),
52- eq (Map .of ("service" , "service" , "task_type" , TaskType .ANY .toString (), "model_id" , "modelId" ))
53- );
50+ verify (longCounter ).incrementBy (eq (1L ), eq (Map .of ("service" , "service" , "task_type" , TaskType .ANY .toString ())));
5451 }
5552
5653 public void testRecordWithoutModel () {
5754 var longCounter = mock (LongCounter .class );
5855 var stats = new InferenceStats (longCounter , mock (), mock ());
5956
60- stats .requestCount ().incrementBy (1 , modelAttributes (model ("service" , TaskType .ANY , null )));
57+ stats .requestCount ().incrementBy (1 , serviceAttributes (model ("service" , TaskType .ANY , null )));
6158
6259 verify (longCounter ).incrementBy (eq (1L ), eq (Map .of ("service" , "service" , "task_type" , TaskType .ANY .toString ())));
6360 }
@@ -72,15 +69,14 @@ public void testRecordDurationWithoutError() {
7269 var stats = new InferenceStats (mock (), histogramCounter , mock ());
7370
7471 Map <String , Object > metricAttributes = new HashMap <>();
75- metricAttributes .putAll (modelAttributes (model ("service" , TaskType .ANY , "modelId" )));
72+ metricAttributes .putAll (serviceAttributes (model ("service" , TaskType .ANY , "modelId" )));
7673 metricAttributes .putAll (responseAttributes (null ));
7774
7875 stats .inferenceDuration ().record (expectedLong , metricAttributes );
7976
8077 verify (histogramCounter ).record (eq (expectedLong ), assertArg (attributes -> {
8178 assertThat (attributes .get ("service" ), is ("service" ));
8279 assertThat (attributes .get ("task_type" ), is (TaskType .ANY .toString ()));
83- assertThat (attributes .get ("model_id" ), is ("modelId" ));
8480 assertThat (attributes .get ("status_code" ), is (200 ));
8581 assertThat (attributes .get ("error.type" ), nullValue ());
8682 }));
@@ -100,15 +96,14 @@ public void testRecordDurationWithElasticsearchStatusException() {
10096 var expectedError = String .valueOf (statusCode .getStatus ());
10197
10298 Map <String , Object > metricAttributes = new HashMap <>();
103- metricAttributes .putAll (modelAttributes (model ("service" , TaskType .ANY , "modelId" )));
99+ metricAttributes .putAll (serviceAttributes (model ("service" , TaskType .ANY , "modelId" )));
104100 metricAttributes .putAll (responseAttributes (exception ));
105101
106102 stats .inferenceDuration ().record (expectedLong , metricAttributes );
107103
108104 verify (histogramCounter ).record (eq (expectedLong ), assertArg (attributes -> {
109105 assertThat (attributes .get ("service" ), is ("service" ));
110106 assertThat (attributes .get ("task_type" ), is (TaskType .ANY .toString ()));
111- assertThat (attributes .get ("model_id" ), is ("modelId" ));
112107 assertThat (attributes .get ("status_code" ), is (statusCode .getStatus ()));
113108 assertThat (attributes .get ("error.type" ), is (expectedError ));
114109 }));
@@ -127,15 +122,14 @@ public void testRecordDurationWithOtherException() {
127122 var expectedError = exception .getClass ().getSimpleName ();
128123
129124 Map <String , Object > metricAttributes = new HashMap <>();
130- metricAttributes .putAll (modelAttributes (model ("service" , TaskType .ANY , "modelId" )));
125+ metricAttributes .putAll (serviceAttributes (model ("service" , TaskType .ANY , "modelId" )));
131126 metricAttributes .putAll (responseAttributes (exception ));
132127
133128 stats .inferenceDuration ().record (expectedLong , metricAttributes );
134129
135130 verify (histogramCounter ).record (eq (expectedLong ), assertArg (attributes -> {
136131 assertThat (attributes .get ("service" ), is ("service" ));
137132 assertThat (attributes .get ("task_type" ), is (TaskType .ANY .toString ()));
138- assertThat (attributes .get ("model_id" ), is ("modelId" ));
139133 assertThat (attributes .get ("status_code" ), nullValue ());
140134 assertThat (attributes .get ("error.type" ), is (expectedError ));
141135 }));
@@ -152,7 +146,7 @@ public void testRecordDurationWithUnparsedModelAndElasticsearchStatusException()
152146 var unparsedModel = new UnparsedModel ("inferenceEntityId" , TaskType .ANY , "service" , Map .of (), Map .of ());
153147
154148 Map <String , Object > metricAttributes = new HashMap <>();
155- metricAttributes .putAll (modelAttributes (unparsedModel ));
149+ metricAttributes .putAll (serviceAttributes (unparsedModel ));
156150 metricAttributes .putAll (responseAttributes (exception ));
157151
158152 stats .inferenceDuration ().record (expectedLong , metricAttributes );
@@ -176,7 +170,7 @@ public void testRecordDurationWithUnparsedModelAndOtherException() {
176170 var unparsedModel = new UnparsedModel ("inferenceEntityId" , TaskType .ANY , "service" , Map .of (), Map .of ());
177171
178172 Map <String , Object > metricAttributes = new HashMap <>();
179- metricAttributes .putAll (modelAttributes (unparsedModel ));
173+ metricAttributes .putAll (serviceAttributes (unparsedModel ));
180174 metricAttributes .putAll (responseAttributes (exception ));
181175
182176 stats .inferenceDuration ().record (expectedLong , metricAttributes );
0 commit comments