16
16
package io .micrometer .core .instrument .binder .jetty ;
17
17
18
18
import io .micrometer .core .instrument .Tag ;
19
+ import io .micrometer .core .instrument .binder .http .Outcome ;
19
20
import io .micrometer .core .instrument .util .StringUtils ;
20
21
import org .eclipse .jetty .client .api .Request ;
21
22
import org .eclipse .jetty .client .api .Response ;
@@ -42,20 +43,6 @@ public final class JettyClientTags {
42
43
43
44
private static final Tag EXCEPTION_NONE = Tag .of ("exception" , "None" );
44
45
45
- private static final Tag STATUS_SERVER_ERROR = Tag .of ("status" , String .valueOf (HttpStatus .INTERNAL_SERVER_ERROR_500 ));
46
-
47
- private static final Tag OUTCOME_UNKNOWN = Tag .of ("outcome" , "UNKNOWN" );
48
-
49
- private static final Tag OUTCOME_INFORMATIONAL = Tag .of ("outcome" , "INFORMATIONAL" );
50
-
51
- private static final Tag OUTCOME_SUCCESS = Tag .of ("outcome" , "SUCCESS" );
52
-
53
- private static final Tag OUTCOME_REDIRECTION = Tag .of ("outcome" , "REDIRECTION" );
54
-
55
- private static final Tag OUTCOME_CLIENT_ERROR = Tag .of ("outcome" , "CLIENT_ERROR" );
56
-
57
- private static final Tag OUTCOME_SERVER_ERROR = Tag .of ("outcome" , "SERVER_ERROR" );
58
-
59
46
private static final Tag METHOD_UNKNOWN = Tag .of ("method" , "UNKNOWN" );
60
47
61
48
private static final Pattern TRAILING_SLASH_PATTERN = Pattern .compile ("/$" );
@@ -69,7 +56,7 @@ private JettyClientTags() {
69
56
* Creates a {@code method} tag based on the {@link Request#getMethod()
70
57
* method} of the given {@code request}.
71
58
*
72
- * @param request the container request
59
+ * @param request the request
73
60
* @return the method tag whose value is a capitalized method (e.g. GET).
74
61
*/
75
62
public static Tag method (Request request ) {
@@ -107,20 +94,16 @@ public static Tag uri(Result result, Function<Result, String> successfulUriPatte
107
94
}
108
95
109
96
String matchingPattern = successfulUriPattern .apply (result );
97
+ matchingPattern = MULTIPLE_SLASH_PATTERN .matcher (matchingPattern ).replaceAll ("/" );
110
98
if (matchingPattern .equals ("/" )) {
111
99
return URI_ROOT ;
112
100
}
113
-
114
- matchingPattern = MULTIPLE_SLASH_PATTERN .matcher (matchingPattern ).replaceAll ("/" );
115
- if (!matchingPattern .equals ("/" )) {
116
- matchingPattern = TRAILING_SLASH_PATTERN .matcher (matchingPattern ).replaceAll ("" );
117
- }
118
-
101
+ matchingPattern = TRAILING_SLASH_PATTERN .matcher (matchingPattern ).replaceAll ("" );
119
102
return Tag .of ("uri" , matchingPattern );
120
103
}
121
104
122
105
/**
123
- * Creates a {@code exception} tag based on the {@link Class#getSimpleName() simple
106
+ * Creates an {@code exception} tag based on the {@link Class#getSimpleName() simple
124
107
* name} of the class of the given {@code exception}.
125
108
*
126
109
* @param result the request result
@@ -152,19 +135,7 @@ public static Tag exception(Result result) {
152
135
* @return the outcome tag derived from the status of the response
153
136
*/
154
137
public static Tag outcome (Result result ) {
155
- int status = result .getResponse ().getStatus ();
156
- if (HttpStatus .isInformational (status )) {
157
- return OUTCOME_INFORMATIONAL ;
158
- } else if (HttpStatus .isSuccess (status )) {
159
- return OUTCOME_SUCCESS ;
160
- } else if (HttpStatus .isRedirection (status )) {
161
- return OUTCOME_REDIRECTION ;
162
- } else if (HttpStatus .isClientError (status )) {
163
- return OUTCOME_CLIENT_ERROR ;
164
- } else if (HttpStatus .isServerError (status )) {
165
- return OUTCOME_SERVER_ERROR ;
166
- }
167
- return OUTCOME_UNKNOWN ;
138
+ return Outcome .forStatus (result .getResponse ().getStatus ()).asTag ();
168
139
}
169
140
170
141
}
0 commit comments