Skip to content

Commit

Permalink
Changed the format of status code metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-s-del committed Apr 21, 2017
1 parent 7e0787c commit 1180e1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion api/src/main/java/com/flipkart/poseidon/api/APILegoSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.flipkart.poseidon.core.RequestContext;
import com.flipkart.poseidon.ds.trie.KeyWrapper;
import com.flipkart.poseidon.ds.trie.Trie;
import com.flipkart.poseidon.helpers.MetricsHelper;
import com.flipkart.poseidon.legoset.PoseidonLegoSet;
import com.flipkart.poseidon.metrics.Metrics;
import com.flipkart.poseidon.pojos.EndpointPOJO;
Expand Down Expand Up @@ -106,7 +107,7 @@ public Buildable getBuildable(Request request) throws LegoSetException, ElementN

String name = pojo.getName();
if (name != null && !name.isEmpty()) {
poseidonRequest.setAttribute(TIMER_CONTEXT, Metrics.getRegistry().timer("poseidon.api." + name + "." + httpMethod).time());
poseidonRequest.setAttribute(TIMER_CONTEXT, Metrics.getRegistry().timer(MetricsHelper.getApiTimerMetricsName(name, httpMethod)).time());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.flipkart.poseidon.constants.RequestConstants;
import com.flipkart.poseidon.core.RequestContext;
import com.flipkart.poseidon.handlers.http.utils.StringUtils;
import com.flipkart.poseidon.helpers.MetricsHelper;
import com.flipkart.poseidon.metrics.Metrics;
import com.flipkart.poseidon.serviceclients.ServiceClientConstants;
import com.flipkart.poseidon.serviceclients.ServiceContext;
Expand Down Expand Up @@ -72,7 +73,7 @@ private void ingestResponseBasedMetrics(ServletResponse response) {
if (response instanceof HttpServletResponse && !StringUtils.isNullOrEmpty(RequestContext.get(ENDPOINT_NAME))) {
String status = (((HttpServletResponse) response).getStatus() / 100) + "XX";
Metrics.getRegistry()
.counter("poseidon.api." + RequestContext.get(ENDPOINT_NAME) + "_" + RequestContext.get(RequestConstants.METHOD) + "." + status)
.counter(MetricsHelper.getStatusCodeMetricsName(RequestContext.get(ENDPOINT_NAME), RequestContext.get(RequestConstants.METHOD), status))
.inc();
}
}
Expand Down Expand Up @@ -126,11 +127,11 @@ public void destroy() {
* A command might not have been executed (say threadpool/semaphore rejected,
* short circuited). Command might have been executed but failed (say timed out,
* command execution failed).
*
* <p>
* This is required as Phantom's RequestLogger logs failures of sync command
* executions alone (and not async command executions) and doesn't provide request
* level view of all commands.
*
* <p>
* We log global headers here as it typically contains request id
*/
private void logFailedHystrixCommands(ServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.flipkart.poseidon.helpers;

/**
* Created by shubham.srivastava on 19/04/17.
*/
public class MetricsHelper {

private static String BASE_METRICS_NAME = "poseidon.api.";
private static String DEFAULT_DELIMITER = ".";

public static String getStatusCodeMetricsName(String endpoint, String method, String status) {
return new StringBuilder(BASE_METRICS_NAME)
.append(endpoint)
.append(method)
.append(DEFAULT_DELIMITER)
.append(status)
.toString();
}

public static String getApiTimerMetricsName(String endpoint, String method) {
return new StringBuilder(BASE_METRICS_NAME)
.append(endpoint)
.append(DEFAULT_DELIMITER)
.append(method)
.toString();
}

}

0 comments on commit 1180e1d

Please sign in to comment.