Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pmohankumar authored Apr 25, 2017
2 parents e16dd17 + 71217c1 commit a7be96d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 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 @@ -18,8 +18,10 @@

import com.flipkart.poseidon.api.Configuration;
import com.flipkart.poseidon.api.HeaderConfiguration;
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 @@ -70,7 +72,9 @@ private void ingestResponseBasedMetrics(ServletResponse response) {
// Ingest API response status codes for HttpServletResponse
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) + "." + status).inc();
Metrics.getRegistry()
.counter(MetricsHelper.getStatusCodeMetricsName(RequestContext.get(ENDPOINT_NAME), RequestContext.get(RequestConstants.METHOD), status))
.inc();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015 Flipkart Internet, pvt ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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(DEFAULT_DELIMITER)
.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 a7be96d

Please sign in to comment.