Merge pull request #1215 from metamx/log-audit-IP-Address

Add remote ip address in audit log.
This commit is contained in:
Xavier Léauté 2015-03-17 13:59:31 -07:00
commit 9d6b728054
6 changed files with 44 additions and 11 deletions

View File

@ -24,15 +24,18 @@ public class AuditInfo
{
private final String author;
private final String comment;
private final String ip;
@JsonCreator
public AuditInfo(
@JsonProperty("author") String author,
@JsonProperty("comment") String comment
@JsonProperty("comment") String comment,
@JsonProperty("ip") String ip
)
{
this.author = author;
this.comment = comment;
this.ip = ip;
}
@JsonProperty
@ -47,6 +50,12 @@ public class AuditInfo
return comment;
}
@JsonProperty
public String getIp()
{
return ip;
}
@Override
public boolean equals(Object o)
{
@ -65,6 +74,9 @@ public class AuditInfo
if (!comment.equals(that.comment)) {
return false;
}
if (!ip.equals(that.ip)) {
return false;
}
return true;
}
@ -74,6 +86,7 @@ public class AuditInfo
{
int result = author.hashCode();
result = 31 * result + comment.hashCode();
result = 31 * result + ip.hashCode();
return result;
}
}

View File

@ -49,6 +49,7 @@ import io.druid.timeline.DataSegment;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
@ -58,6 +59,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
@ -196,10 +198,15 @@ public class OverlordResource
public Response setWorkerConfig(
final WorkerBehaviorConfig workerBehaviorConfig,
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment,
@Context HttpServletRequest req
)
{
if (!configManager.set(WorkerBehaviorConfig.CONFIG_KEY, workerBehaviorConfig, new AuditInfo(author, comment))) {
if (!configManager.set(
WorkerBehaviorConfig.CONFIG_KEY,
workerBehaviorConfig,
new AuditInfo(author, comment, req.getRemoteAddr())
)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}

View File

@ -24,6 +24,7 @@ import io.druid.server.coordinator.CoordinatorDynamicConfig;
import org.joda.time.Interval;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
@ -32,6 +33,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -70,10 +72,15 @@ public class CoordinatorDynamicConfigsResource
@Consumes(MediaType.APPLICATION_JSON)
public Response setDynamicConfigs(final CoordinatorDynamicConfig dynamicConfig,
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment,
@Context HttpServletRequest req
)
{
if (!manager.set(CoordinatorDynamicConfig.CONFIG_KEY, dynamicConfig, new AuditInfo(author, comment))) {
if (!manager.set(
CoordinatorDynamicConfig.CONFIG_KEY,
dynamicConfig,
new AuditInfo(author, comment, req.getRemoteAddr())
)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().build();

View File

@ -24,6 +24,7 @@ import io.druid.metadata.MetadataRuleManager;
import io.druid.server.coordinator.rules.Rule;
import org.joda.time.Interval;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
@ -33,6 +34,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@ -85,13 +87,14 @@ public class RulesResource
@PathParam("dataSourceName") final String dataSourceName,
final List<Rule> rules,
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment
@HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment,
@Context HttpServletRequest req
)
{
if (databaseRuleManager.overrideRule(
dataSourceName,
rules,
new AuditInfo(author, comment)
new AuditInfo(author, comment, req.getRemoteAddr())
)) {
return Response.ok().build();
}

View File

@ -94,7 +94,7 @@ public class SQLMetadataRuleManagerTest
)
)
);
AuditInfo auditInfo = new AuditInfo("test_author", "test_comment");
AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1");
ruleManager.overrideRule(
"test_dataSource",
rules,

View File

@ -73,7 +73,8 @@ public class SQLAuditManagerTest
"testType",
new AuditInfo(
"testAuthor",
"testComment"
"testComment",
"127.0.0.1"
),
"testPayload",
new DateTime("2013-01-01T00:00:00Z")
@ -91,7 +92,8 @@ public class SQLAuditManagerTest
"testType",
new AuditInfo(
"testAuthor",
"testComment"
"testComment",
"127.0.0.1"
),
"testPayload",
new DateTime("2013-01-01T00:00:00Z")
@ -111,7 +113,8 @@ public class SQLAuditManagerTest
"testType",
new AuditInfo(
"testAuthor",
"testComment"
"testComment",
"127.0.0.1"
),
"testPayload",
new DateTime("2013-01-01T00:00:00Z")