Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
<properties>
<java.version>1.8</java.version>
<slf4j-api.version>1.7.28</slf4j-api.version>
<jackson.version>2.9.9</jackson.version>
<jackson-databind.version>2.9.10.5</jackson-databind.version>
<httpclient.version>4.5.9</httpclient.version>
<jackson.version>2.12.7</jackson.version>
<jackson-databind.version>2.12.6.1</jackson-databind.version>
<httpclient.version>4.5.13</httpclient.version>
<junixsocket.version>2.2.0</junixsocket.version>
<failsafe.version>2.3.0</failsafe.version>
<protobuf.version>3.9.1</protobuf.version>
<protobuf.version>3.16.3</protobuf.version>
<lombok.version>1.18.8</lombok.version>
<junit.version>4.11</junit.version>
<mockito.version>1.9.5</mockito.version>
<powermock.version>1.5.6</powermock.version>
<junit.version>4.13.1</junit.version>
<mockito.version>2.8.9</mockito.version>
<powermock.version>1.7.4</powermock.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -167,7 +167,7 @@

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
Expand Down
48 changes: 31 additions & 17 deletions src/main/java/com/stackify/api/common/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
*/
package com.stackify.api.common.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.stackify.api.common.ApiConfiguration;
import com.stackify.api.common.util.CharStreams;
import com.stackify.api.common.util.Preconditions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
Expand All @@ -32,6 +36,7 @@

/**
* HttpClient
*
* @author Eric Martin
*/
public class HttpClient {
Expand All @@ -56,27 +61,29 @@ public class HttpClient {
*/
private final Proxy proxy;

private static final Logger LOGGER = LoggerFactory.getLogger(HttpClient.class);

/**
* Constructor
*
* @param apiConfig API configuration
*/
public HttpClient(final ApiConfiguration apiConfig) {
Preconditions.checkNotNull(apiConfig);
this.apiConfig = apiConfig;

if (apiConfig.getHttpProxyHost() != null &&
!apiConfig.getHttpProxyHost().isEmpty() &&
apiConfig.getHttpProxyPort() != null &&
!apiConfig.getHttpProxyPort().isEmpty()) {
this.proxy = HttpProxy.build(apiConfig.getHttpProxyHost(), apiConfig.getHttpProxyPort());
} else {
this.proxy = HttpProxy.fromSystemProperties();
}
}
public HttpClient(final ApiConfiguration apiConfig) {
Preconditions.checkNotNull(apiConfig);
this.apiConfig = apiConfig;

if (apiConfig.getHttpProxyHost() != null && !apiConfig.getHttpProxyHost().isEmpty()
&& apiConfig.getHttpProxyPort() != null && !apiConfig.getHttpProxyPort().isEmpty()) {
this.proxy = HttpProxy.build(apiConfig.getHttpProxyHost(), apiConfig.getHttpProxyPort());
} else {
this.proxy = HttpProxy.fromSystemProperties();
}
}

/**
* Posts data to stackify
* @param path REST path
*
* @param path REST path
* @param jsonBytes JSON bytes
* @return Response string
* @throws IOException
Expand All @@ -88,14 +95,16 @@ public String post(final String path, final byte[] jsonBytes) throws IOException

/**
* Posts data to stackify
* @param path REST path
*
* @param path REST path
* @param jsonBytes JSON bytes
* @param gzip True if the post should be gzipped, false otherwise
* @param gzip True if the post should be gzipped, false otherwise
* @return Response string
* @throws IOException
* @throws HttpException
*/
public String post(final String path, final byte[] jsonBytes, final boolean gzip) throws IOException, HttpException {
public String post(final String path, final byte[] jsonBytes, final boolean gzip)
throws IOException, HttpException {
Preconditions.checkNotNull(path);
Preconditions.checkArgument(!path.isEmpty());
Preconditions.checkNotNull(jsonBytes);
Expand All @@ -107,6 +116,10 @@ public String post(final String path, final byte[] jsonBytes, final boolean gzip
URL url = new URL(apiConfig.getApiUrl() + path);

// request properties
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("#HttpClient #Post Sending request to {}/{} - Body: {}", apiConfig.getApiUrl(), path,
(new ObjectMapper()).writeValueAsString(jsonBytes));
}

connection = (HttpURLConnection) url.openConnection(proxy);
connection.setDoInput(true);
Expand Down Expand Up @@ -172,6 +185,7 @@ public String post(final String path, final byte[] jsonBytes, final boolean gzip

/**
* Reads all remaining contents from the stream and closes it
*
* @param stream The stream
* @return The contents of the stream
* @throws IOException
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/stackify/api/common/log/LogAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import com.stackify.api.common.error.ErrorGovernor;
import com.stackify.api.common.mask.Masker;
import com.stackify.api.common.util.Preconditions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.NonNull;

import java.io.Closeable;
Expand All @@ -35,6 +39,11 @@
*/
public class LogAppender<T> implements Closeable {

/**
* The appender logger
*/
private static final Logger LOGGER = LoggerFactory.getLogger(LogAppender.class);

/**
* Internal package prefix
*/
Expand Down Expand Up @@ -79,10 +88,8 @@ public class LogAppender<T> implements Closeable {
*
* @param logger Logger project name
*/
public LogAppender(@NonNull final String logger,
@NonNull final EventAdapter<T> eventAdapter,
final Masker masker,
final boolean skipJson) {
public LogAppender(@NonNull final String logger, @NonNull final EventAdapter<T> eventAdapter, final Masker masker,
final boolean skipJson) {
this.logger = logger;
this.eventAdapter = eventAdapter;
this.masker = masker;
Expand All @@ -94,9 +101,7 @@ public LogAppender(@NonNull final String logger,
*
* @param logger Logger project name
*/
public LogAppender(@NonNull final String logger,
@NonNull final EventAdapter<T> eventAdapter,
final Masker masker) {
public LogAppender(@NonNull final String logger, @NonNull final EventAdapter<T> eventAdapter, final Masker masker) {
this(logger, eventAdapter, masker, false);
}

Expand Down Expand Up @@ -203,6 +208,10 @@ public void append(final T event) {

LogMsg logMsg = eventAdapter.getLogMsg(event, error);

if (LOGGER.isDebugEnabled()) {
LOGGER.info("#Log #Appender #Template Logging mesage: {}", event);
}

collector.addLogMsg(logMsg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.stackify.api.common.log;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.stackify.api.LogMsgGroup;
import com.stackify.api.common.ApiConfiguration;
import com.stackify.api.common.mask.Masker;
Expand All @@ -25,10 +26,12 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Log Transport - Agent Socket
* Send log messages to Stackify Agent via Domain Socket
* Log Transport - Agent Socket Send log messages to Stackify Agent via Domain
* Socket
*
* @author Darin Howard
*/
Expand All @@ -46,9 +49,12 @@ public class LogTransportAgentSocket implements LogTransport {

private final HttpSocketClient httpSocketClient;

public LogTransportAgentSocket(@NonNull final ApiConfiguration apiConfig,
Masker masker,
boolean skipJson) {
/**
* The transport logger
*/
private static final Logger LOGGER = LoggerFactory.getLogger(LogTransportAgentSocket.class);

public LogTransportAgentSocket(@NonNull final ApiConfiguration apiConfig, Masker masker, boolean skipJson) {
this.apiConfig = apiConfig;
this.logTransportPreProcessor = new LogTransportPreProcessor(masker, skipJson);
this.httpSocketClient = new HttpSocketClient(apiConfig.getAgentSocketPath());
Expand All @@ -73,6 +79,12 @@ public void send(@NonNull final LogMsgGroup group) throws Exception {
HttpPost httpPost = new HttpPost(URI_PREFIX + "/log");
httpPost.setHeader("Content-Type", "application/x-protobuf");
httpPost.setEntity(new ByteArrayEntity(logGroup.toByteArray()));

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("#Log #Transport #Socket Sending request to {} - Body: {}", httpPost.getURI(),
(new ObjectMapper()).writeValueAsString(group));
}

httpSocketClient.send(httpPost);
} catch (Throwable e) {
log.info("Queueing logs for retransmission due to Exception");
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/stackify/api/common/log/LogTransportDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import com.stackify.api.common.ApiConfiguration;
import com.stackify.api.common.http.HttpClient;
import com.stackify.api.common.mask.Masker;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

/**
* Log Transport - Direct
* Send log messages directly to Stackify
* Log Transport - Direct Send log messages directly to Stackify
*
* @author Eric Martin
*/
Expand All @@ -49,16 +52,19 @@ public class LogTransportDirect implements LogTransport {

private final LogTransportPreProcessor logTransportPreProcessor;

/**
* The transport logger
*/
private static final Logger LOGGER = LoggerFactory.getLogger(LogTransportAgentSocket.class);

/**
* Default constructor
*
* @param apiConfig API configuration
* @param objectMapper JSON object mapper
*/
public LogTransportDirect(@NonNull final ApiConfiguration apiConfig,
@NonNull final ObjectMapper objectMapper,
Masker masker,
boolean skipJson) {
public LogTransportDirect(@NonNull final ApiConfiguration apiConfig, @NonNull final ObjectMapper objectMapper,
Masker masker, boolean skipJson) {
this.apiConfig = apiConfig;
this.objectMapper = objectMapper;
this.logTransportPreProcessor = new LogTransportPreProcessor(masker, skipJson);
Expand All @@ -84,6 +90,10 @@ public void send(@NonNull final LogMsgGroup group) throws Exception {
// post to stackify

try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("#Log #Transport #Direct Sending request to {} - Body: {}", LOG_SAVE_PATH,
objectMapper.writeValueAsString(group));
}
httpClient.post(LOG_SAVE_PATH, jsonBytes, true);
} catch (Exception e) {
log.info("Queueing logs for retransmission due to Exception");
Expand Down
Loading