-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b16e08e
commit 108fcd4
Showing
8 changed files
with
462 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cloud.cirrusup.publisher; | ||
|
||
import cloud.cirrusup.publisher.Publisher; | ||
import cloud.cirrusup.publisher.model.PublishedInfo; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static cloud.cirrusup.publisher.model.PublishedInfo.API_METHOD; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.ERROR_SUMMARY; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.HTTP_METHOD; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.REQUEST_ID; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.SERVICE_NAME; | ||
|
||
/** | ||
* Publisher that exports entries in JSON format. | ||
*/ | ||
public class JSONPublisher implements Publisher { | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
private static final Logger LOG = LoggerFactory.getLogger(LOG_NAME); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void publish(PublishedInfo info) { | ||
|
||
ObjectNode node = mapper.createObjectNode(); | ||
node.put("requestId", info.getInfo(REQUEST_ID)); | ||
node.put("serviceName", info.getInfo(SERVICE_NAME)); | ||
node.put("httpMethod", info.getInfo(HTTP_METHOD)); | ||
node.put("latency", info.getLatency()); | ||
node.put("statusCode", info.getStatusCode()); | ||
if (info.hasInfo(ERROR_SUMMARY)) { | ||
node.put("errorMessage", info.getInfo(ERROR_SUMMARY)); | ||
} | ||
if (info.hasInfo(API_METHOD)) { | ||
node.put("apiMethod", info.getInfo(API_METHOD)); | ||
} | ||
|
||
try { | ||
|
||
LOG.info(mapper.writeValueAsString(node)); | ||
} catch (JsonProcessingException e) { | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/cloud/cirrusup/publisher/PlainLogPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cloud.cirrusup.publisher; | ||
|
||
import cloud.cirrusup.publisher.Publisher; | ||
import cloud.cirrusup.publisher.model.PublishedInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static cloud.cirrusup.publisher.model.PublishedInfo.API_METHOD; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.ERROR_SUMMARY; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.HTTP_METHOD; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.REQUEST_ID; | ||
import static cloud.cirrusup.publisher.model.PublishedInfo.SERVICE_NAME; | ||
|
||
/** | ||
* Publisher that uses a text log file to add plain info. | ||
*/ | ||
public class PlainLogPublisher implements Publisher { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(LOG_NAME); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void publish(PublishedInfo info) { | ||
|
||
LOG.info("Request ID [{}] to [{}/{}] took [{}] milliseconds and returned the RESPONSE_CODE [{}]", | ||
info.getInfo(REQUEST_ID), info.getInfo(SERVICE_NAME), info.getInfo(HTTP_METHOD), info.getLatency(), info.getStatusCode()); | ||
|
||
if (info.hasInfo(ERROR_SUMMARY)) { | ||
LOG.warn("Request ID [{}], RESPONSE_CODE [{}], MESSAGE [{}]", info.getInfo(REQUEST_ID), info.getStatusCode(), info.getInfo(ERROR_SUMMARY)); | ||
} | ||
|
||
if(info.hasInfo(API_METHOD)){ | ||
LOG.info("Request ID [{}], API method [{}]", info.getInfo(REQUEST_ID), info.getInfo(API_METHOD)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cloud.cirrusup.publisher; | ||
|
||
import cloud.cirrusup.publisher.model.PublishedInfo; | ||
|
||
/** | ||
* Model for any publisher. | ||
*/ | ||
public interface Publisher { | ||
|
||
String LOG_NAME = "aws-latency-log"; | ||
|
||
/** | ||
* Publish info in the underlying destination. | ||
* | ||
* @param info information to be published | ||
*/ | ||
void publish(PublishedInfo info); | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/cloud/cirrusup/publisher/model/PublishedInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cloud.cirrusup.publisher.model; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* POJO class that holds all details about info published. | ||
*/ | ||
public class PublishedInfo { | ||
|
||
public static final String REQUEST_ID = "requestId"; | ||
public static final String SERVICE_NAME = "serviceName"; | ||
public static final String HTTP_METHOD = "httpMethod"; | ||
public static final String ERROR_SUMMARY = "errorInfo"; | ||
public static final String API_METHOD = "apiMethod"; | ||
|
||
|
||
private final Map<String, String> info = new HashMap<>(); | ||
private long latency = -1; | ||
private int statusCode = -1; | ||
|
||
|
||
public void addLatency(long latency) { | ||
|
||
this.latency = latency; | ||
} | ||
|
||
public void addInfo(String name, String value) { | ||
|
||
this.info.put(name, value); | ||
} | ||
|
||
public long getLatency() { | ||
|
||
return latency; | ||
} | ||
|
||
public String getInfo(String name) { | ||
|
||
return info.get(name); | ||
} | ||
|
||
public boolean hasInfo(String name) { | ||
|
||
return info.containsKey(name) && info.get(name) != null; | ||
} | ||
|
||
public void setStatusCode(int statusCode) { | ||
|
||
this.statusCode = statusCode; | ||
} | ||
|
||
public int getStatusCode() { | ||
|
||
return statusCode; | ||
} | ||
} |
Oops, something went wrong.