public abstract class AuditLoggerPlugin extends Object implements Closeable, Runnable, SolrInfoBean, SolrMetricProducer
Modifier and Type | Class and Description |
---|---|
static interface |
AuditLoggerPlugin.AuditEventFormatter
Interface for formatting the event
|
static class |
AuditLoggerPlugin.JSONAuditEventFormatter
Event formatter that returns event as JSON string
|
static interface |
AuditLoggerPlugin.MuteRule |
SolrInfoBean.Category, SolrInfoBean.Group
Modifier and Type | Field and Description |
---|---|
protected List<String> |
eventTypes |
protected AuditLoggerPlugin.AuditEventFormatter |
formatter |
protected com.codahale.metrics.Meter |
numErrors |
protected com.codahale.metrics.Meter |
numLogged |
protected com.codahale.metrics.Meter |
numLost |
protected com.codahale.metrics.Timer |
queuedTime |
protected com.codahale.metrics.Timer |
requestTimes |
protected SolrMetricsContext |
solrMetricsContext |
protected com.codahale.metrics.Counter |
totalTime |
Constructor and Description |
---|
AuditLoggerPlugin() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
audit(AuditEvent event)
This is the method that each Audit plugin has to implement to do the actual logging.
|
protected void |
auditAsync(AuditEvent event)
Enqueues an
AuditEvent to a queue and returns immediately. |
void |
close()
Waits 30s for async queue to drain, then closes executor threads.
|
void |
doAudit(AuditEvent event)
Called by the framework, and takes care of metrics tracking and to dispatch
to either synchronous or async logging.
|
SolrInfoBean.Category |
getCategory()
Category of this component
|
String |
getDescription()
Simple one or two line description
|
Set<String> |
getMetricNames()
Modifiable set of metric names that this component reports (default is null,
which means none).
|
String |
getName()
Simple common usage name, e.g.
|
SolrMetricsContext |
getSolrMetricsContext()
Implementing classes should override this method to provide the context obtained in
SolrMetricProducer.initializeMetrics(SolrMetricsContext, String) to ensure proper cleanup of metrics
at the end of the life-cycle of this component. |
void |
init(Map<String,Object> pluginConfig)
Initialize the plugin from security.json.
|
void |
initializeMetrics(SolrMetricsContext parentContext,
String scope)
Initialize metrics specific to this producer.
|
void |
run()
Pick next event from async queue and call
audit(AuditEvent) |
void |
setFormatter(AuditLoggerPlugin.AuditEventFormatter formatter) |
boolean |
shouldLog(AuditEvent.EventType eventType)
Checks whether this event type should be logged based on "eventTypes" config parameter.
|
protected boolean |
shouldMute(AuditEvent event)
Returns true if any of the configured mute rules matches.
|
protected void |
waitForQueueToDrain(int timeoutSeconds)
Blocks until the async event queue is drained
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMetricRegistry, getMetricsSnapshot, registerMetricName
getUniqueMetricTag, initializeMetrics
protected AuditLoggerPlugin.AuditEventFormatter formatter
protected SolrMetricsContext solrMetricsContext
protected com.codahale.metrics.Meter numErrors
protected com.codahale.metrics.Meter numLost
protected com.codahale.metrics.Meter numLogged
protected com.codahale.metrics.Timer requestTimes
protected com.codahale.metrics.Timer queuedTime
protected com.codahale.metrics.Counter totalTime
public void init(Map<String,Object> pluginConfig)
pluginConfig
- the config for the pluginprotected abstract void audit(AuditEvent event)
event
- the audit eventpublic final void doAudit(AuditEvent event)
protected boolean shouldMute(AuditEvent event)
event
- the audit eventprotected final void auditAsync(AuditEvent event)
AuditEvent
to a queue and returns immediately.
A background thread will pull events from this queue and call audit(AuditEvent)
event
- the audit eventpublic void run()
audit(AuditEvent)
public boolean shouldLog(AuditEvent.EventType eventType)
eventType
- the event type to considerpublic void setFormatter(AuditLoggerPlugin.AuditEventFormatter formatter)
public void initializeMetrics(SolrMetricsContext parentContext, String scope)
SolrMetricProducer
initializeMetrics
in interface SolrMetricProducer
parentContext
- parent metrics context. If this component has the same life-cycle as the parent
it can simply use the parent context, otherwise it should obtain a child context
using SolrMetricsContext.getChildContext(Object)
passing this
as the child.scope
- component scopepublic String getName()
SolrInfoBean
getName
in interface SolrInfoBean
public String getDescription()
SolrInfoBean
getDescription
in interface SolrInfoBean
public SolrInfoBean.Category getCategory()
SolrInfoBean
getCategory
in interface SolrInfoBean
public Set<String> getMetricNames()
SolrInfoBean
SolrInfoBean.registerMetricName(String)
to capture what metrics names are reported from this component.
NOTE: this set has to allow iteration under modifications.
getMetricNames
in interface SolrInfoBean
public SolrMetricsContext getSolrMetricsContext()
SolrMetricProducer
SolrMetricProducer.initializeMetrics(SolrMetricsContext, String)
to ensure proper cleanup of metrics
at the end of the life-cycle of this component.getSolrMetricsContext
in interface SolrMetricProducer
public void close() throws IOException
super.close()
or waitForQueueToDrain(int)
before shutting itself down to make sure they can complete logging events in the queue.close
in interface Closeable
close
in interface AutoCloseable
close
in interface SolrMetricProducer
IOException
protected void waitForQueueToDrain(int timeoutSeconds)
timeoutSeconds
- number of seconds to wait for queue to drainCopyright © 2000-2021 Apache Software Foundation. All Rights Reserved.