You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ps...@apache.org on 2007/08/09 01:11:10 UTC
svn commit: r564042 - in /labs/pinpoint/trunk:
pinpoint-cli/src/main/java/org/apache/logging/pinpoint/
pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/
pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/
Author: psmith
Date: Wed Aug 8 16:11:08 2007
New Revision: 564042
URL: http://svn.apache.org/viewvc?view=rev&rev=564042
Log:
* Added ReloadPolicy interface and basic implementation. Now IndexSearcher instances reload
on each query.
* Added 'info' command to display Context information and potential searchable content.
* Changed one logging event to trace.
* minor formatting.
Added:
labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicy.java
labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicyAlways.java
Modified:
labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java
labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java
labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/SimpleEventStore.java
labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java
Modified: labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java?view=diff&rev=564042&r1=564041&r2=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java (original)
+++ labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java Wed Aug 8 16:11:08 2007
@@ -87,46 +87,60 @@
* @param ctx
*/
private static void browseContext(PinpointContext ctx) {
- Collection<String> contextPoints = PinpointContextUtils.listContextPoints(ctx);
- System.out.format("Context: %s\n", ctx.getContextRoot().getAbsoluteFile());
+ // TODO proper browse!
+ showContextInfo(ctx);
+
+ }
+
+ private static void showContextInfo(PinpointContext ctx) {
+ Collection<String> contextPoints = PinpointContextUtils
+ .listContextPoints(ctx);
+ System.out.format("Context: %s\n", ctx.getContextRoot()
+ .getAbsoluteFile());
for (String contextPoint : contextPoints) {
System.out.format("%s: ", contextPoint);
- System.out.format("%s", PinpointContextUtils.listContexPointValues(ctx, contextPoint));
+ System.out.format("%s", PinpointContextUtils.listContexPointValues(
+ ctx, contextPoint));
System.out.println("");
}
-
}
- private static void searchContext(PinpointContext ctx) throws IOException, ParseException {
+ private static void searchContext(PinpointContext ctx) throws IOException,
+ ParseException {
ConsoleReader consoleReader = new ConsoleReader();
Completor fieldNameCompletor = new PinpointContextCompleter(ctx);
/*
- * this is one of the most confusing aspects of jLine....
+ * this is one of the most confusing aspects of jLine.... I think these
+ * names need to be in sorted order too...?
*/
consoleReader.addCompletor(new ArgumentCompletor(new Completor[] {
- new SimpleCompletor(new String[] { "exit", "search", "set", "quit" }),
- fieldNameCompletor, new NullCompletor() }));
+ new SimpleCompletor(new String[] { "exit", "info", "search",
+ "set", "quit" }), fieldNameCompletor,
+ new NullCompletor() }));
- consoleReader.setCompletionHandler(new CandidateListCompletionHandler());
+ consoleReader
+ .setCompletionHandler(new CandidateListCompletionHandler());
consoleReader.setDefaultPrompt("pinpoint>");
String input = "";
/*
- * IMPORTANT NOTE: jline 0.9.90 DOES NOT WORK properly with the command prompt so it's
- * important that at least jline 0.9.91 is used. I WASTED OVER AN HOUR tracking that down.
+ * IMPORTANT NOTE: jline 0.9.90 DOES NOT WORK properly with the command
+ * prompt so it's important that at least jline 0.9.91 is used. I WASTED
+ * OVER AN HOUR tracking that down.
*/
Analyzer analyzer = new StandardAnalyzer();
QueryParser queryParser = new QueryParser("message", analyzer);
queryParser.setDefaultOperator(Operator.AND);
- PinpointSearcher pinpointSearcher = new PinpointSearcher(ctx, new SimpleEventStore(ctx
- .getSerializationFile()));
+ PinpointSearcher pinpointSearcher = new PinpointSearcher(ctx,
+ new SimpleEventStore(ctx.getSerializationFile()));
try {
- while (!Arrays.asList("exit", "quit").contains((input = consoleReader.readLine()))) {
+ while (!Arrays.asList("exit", "quit").contains(
+ (input = consoleReader.readLine()))) {
try {
String[] cmd = StringUtils.split(input);
@@ -134,15 +148,18 @@
input = StringUtils.removeStart(input, cmd[0]);
Query query = queryParser.parse(input);
System.out.println(query);
- Iterable<LoggingEvent> iterable = pinpointSearcher.search(query);
+ Iterable<LoggingEvent> iterable = pinpointSearcher
+ .search(query);
displayEvents(iterable);
+ } else if (StringUtils.equalsIgnoreCase("info", cmd[0])) {
+ showContextInfo(ctx);
} else {
System.err.println("Unknown cmd: " + input);
}
} catch (Exception e) {
/*
- * This is deliberately not logged using log4j, designed to go staight to the
- * console unhindered.
+ * This is deliberately not logged using log4j, designed to
+ * go staight to the console unhindered.
*/
e.printStackTrace();
}
@@ -154,7 +171,8 @@
}
//
- // private static void browseContext(PinpointContext ctx) throws IOException {
+ // private static void browseContext(PinpointContext ctx) throws IOException
+ // {
// PinpointContextIterator iterator = new PinpointContextIterator(ctx);
//
// displayEvents(iterator);
@@ -165,7 +183,8 @@
if (!iterable.iterator().hasNext()) {
System.out.println("No results found");
}
- Layout layout = new PatternLayout("[%d{ISO8601} %-5p][%20.20c][%t] %m%n");
+ Layout layout = new PatternLayout(
+ "[%d{ISO8601} %-5p][%20.20c][%t] %m%n");
for (LoggingEvent loggingEvent : iterable) {
System.out.print(layout.format(loggingEvent));
@@ -182,9 +201,11 @@
Options options = PinpointUtils.getCommonCommandLineOptions();
OptionGroup actionGroup = new OptionGroup();
- Option browseOption = new Option("b", "browse", false, "Browse the context");
+ Option browseOption = new Option("b", "browse", false,
+ "Browse the context");
- Option searchOption = new Option("s", "search", false, "Search the contex");
+ Option searchOption = new Option("s", "search", false,
+ "Search the contex");
// TODO is this a standard Pinpoint option?
Option verboseLogging = new Option("v", "verbosity", true,
Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java?view=diff&rev=564042&r1=564041&r2=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java (original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java Wed Aug 8 16:11:08 2007
@@ -39,7 +39,8 @@
public class EventWriter {
- private static final Logger LOG = PinpointUtils.getLogger(EventWriter.class);
+ private static final Logger LOG = PinpointUtils
+ .getLogger(EventWriter.class);
private final File indexDirectory;
private final Analyzer analyser;
@@ -56,11 +57,12 @@
private boolean optimizeOnClose;
public EventWriter(EventStore eventStore, File indexDirectory,
- IndexWriterFactory indexWriterFactory, AnalyzerFactory analyserFactory)
- throws IOException {
+ IndexWriterFactory indexWriterFactory,
+ AnalyzerFactory analyserFactory) throws IOException {
if (!indexDirectory.exists()) {
- throw new IllegalArgumentException("Index directory does not exist: "
- + indexDirectory.getAbsolutePath());
+ throw new IllegalArgumentException(
+ "Index directory does not exist: " +
+ indexDirectory.getAbsolutePath());
}
if (analyserFactory == null) {
throw new IllegalArgumentException("analyserFactory cannot be null");
@@ -77,15 +79,18 @@
// TODO check that directories can be created
boolean createIndex = false;
- Collection luceneIndexFiles = FileUtils.listFiles(indexDirectory, FileFilterUtils
- .asFileFilter(new IndexFileNameFilter()), FileFilterUtils.trueFileFilter());
+ Collection luceneIndexFiles = FileUtils.listFiles(indexDirectory,
+ FileFilterUtils.asFileFilter(new IndexFileNameFilter()),
+ FileFilterUtils.trueFileFilter());
createIndex = luceneIndexFiles.size() == 0;
if (createIndex) {
- LOG.info("Creating new Lucene Index @ " + indexDirectory.getAbsolutePath());
+ LOG.info("Creating new Lucene Index @ " +
+ indexDirectory.getAbsolutePath());
}
- indexWriter = indexWriterFactory.create(indexDirectory, analyser, createIndex);
+ indexWriter = indexWriterFactory.create(indexDirectory, analyser,
+ createIndex);
LOG.debug("Initialized EventWriter: " + this.toString());
}
@@ -106,33 +111,36 @@
private Document convertDocument(LoggingEvent event, String loc) {
Document doc = new Document();
- doc.add(new Field("level", StringUtils.defaultString(event.getLevel().toString()
- .toLowerCase()), Store.NO, Index.UN_TOKENIZED));
+ doc.add(new Field("level", StringUtils.defaultString(event.getLevel()
+ .toString().toLowerCase()), Store.NO, Index.UN_TOKENIZED));
- doc.add(new Field("message", StringUtils.defaultString(event.getMessage().toString()),
+ doc.add(new Field("message", StringUtils.defaultString(event
+ .getMessage().toString()), Store.NO, Index.TOKENIZED));
+ doc.add(new Field("thread", StringUtils.defaultString(event
+ .getThreadName().toLowerCase()), Store.NO, Index.UN_TOKENIZED));
+ doc.add(new Field("logger", StringUtils.defaultString(event
+ .getLoggerName()), Store.NO, Index.TOKENIZED));
+ doc.add(new Field("ndc", StringUtils.defaultString(event.getNDC()),
Store.NO, Index.TOKENIZED));
- doc.add(new Field("thread", StringUtils.defaultString(event.getThreadName().toLowerCase()),
- Store.NO, Index.UN_TOKENIZED));
- doc.add(new Field("logger", StringUtils.defaultString(event.getLoggerName()), Store.NO,
- Index.TOKENIZED));
- doc.add(new Field("ndc", StringUtils.defaultString(event.getNDC()), Store.NO,
- Index.TOKENIZED));
LocationInfo info = event.getLocationInformation();
StringBuilder buf = new StringBuilder(128);
- buf.append(info.getClassName()).append(" ").append(info.getFileName()).append(" ").append(
- info.getMethodName()).append(" ").append(info.getLineNumber()).append(" ");
- doc.add(new Field("locationinfo", StringUtils.defaultString(buf.toString()), Store.NO,
- Index.TOKENIZED));
+ buf.append(info.getClassName()).append(" ").append(info.getFileName())
+ .append(" ").append(info.getMethodName()).append(" ").append(
+ info.getLineNumber()).append(" ");
+ doc.add(new Field("locationinfo", StringUtils.defaultString(buf
+ .toString()), Store.NO, Index.TOKENIZED));
addTimestamp(event, doc);
// TODO others
+
Map properties = event.getProperties();
- for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) {
+ for (Iterator iterator = properties.entrySet().iterator(); iterator
+ .hasNext();) {
Entry entry = (Map.Entry) iterator.next();
- doc.add(new Field(entry.getKey().toString(), entry.getValue().toString(), Store.NO,
- Index.TOKENIZED));
+ doc.add(new Field(entry.getKey().toString(), entry.getValue()
+ .toString(), Store.NO, Index.TOKENIZED));
}
// TODO add generic content field
@@ -159,7 +167,9 @@
LOG.info("Optimizing index");
indexWriter.optimize();
}
- LOG.info("Closing indexWriter: " + indexDirectory.getAbsolutePath());
+ LOG
+ .info("Closing indexWriter: " +
+ indexDirectory.getAbsolutePath());
indexWriter.close();
} catch (Exception e) {
@@ -168,9 +178,10 @@
}
public String toString() {
- return new ToStringBuilder(this).append("eventStore", eventStore).append("indexDirectory",
- indexDirectory.getAbsolutePath()).append("analyserClass",
- analyser.getClass().getName()).toString();
+ return new ToStringBuilder(this).append("eventStore", eventStore)
+ .append("indexDirectory", indexDirectory.getAbsolutePath())
+ .append("analyserClass", analyser.getClass().getName())
+ .toString();
}
Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/SimpleEventStore.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/SimpleEventStore.java?view=diff&rev=564042&r1=564041&r2=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/SimpleEventStore.java (original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/SimpleEventStore.java Wed Aug 8 16:11:08 2007
@@ -84,7 +84,9 @@
oos.writeObject(event);
oos.close();
loc.length = channel.write(ByteBuffer.wrap(baos.toByteArray()));
- LOG.debug("Written event at " + loc);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Written event at " + loc);
+ }
return loc.encodeAsString();
} catch (IOException e) {
throw new RuntimeException("Failure storing event", e);
Modified: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java?view=diff&rev=564042&r1=564041&r2=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java (original)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java Wed Aug 8 16:11:08 2007
@@ -34,28 +34,40 @@
public class PinpointSearcher {
private final PinpointContext ctx;
- private final IndexSearcher searcher;
+ private IndexSearcher searcher;
- private final Sort defaultSort = new Sort(new SortField[] { new SortField("eventdate"),
- new SortField("eventtime") });
+ private final Sort defaultSort = new Sort(new SortField[] {
+ new SortField("eventdate"), new SortField("eventtime") });
private Filter filter;
private EventStore eventStore;
- public PinpointSearcher(PinpointContext ctx, EventStore eventStore) throws IOException {
+ private ReloadPolicy reloadPolicy = new ReloadPolicyAlways();
+
+ public PinpointSearcher(PinpointContext ctx, EventStore eventStore)
+ throws IOException {
this.ctx = ctx;
- this.searcher = new IndexSearcher(ctx.getIndexDirectory().getAbsolutePath());
+ reload();
this.eventStore = eventStore;
- // TODO background thread to warm up the seaerches? Some sort of pre-filter sort by
+ }
+
+ private void reload() throws IOException {
+ this.searcher = new IndexSearcher(ctx.getIndexDirectory()
+ .getAbsolutePath());
+ // TODO background thread to warm up the seaerches? Some sort of
+ // pre-filter sort by
// date/time?
}
public Iterable<LoggingEvent> search(Query query) throws IOException {
-
+ if (reloadPolicy.shouldReload(query)) {
+ reload();
+ }
if (filter == null) {
Hits hits = searcher.search(query, defaultSort);
return new HitIteratable(hits);
} else {
- throw new UnsupportedOperationException("ahh, filters not yet supported");
+ throw new UnsupportedOperationException(
+ "ahh, filters not yet supported");
}
}
@@ -96,7 +108,8 @@
Hit hit = (Hit) internalHitIterator.next();
try {
Document document = hit.getDocument();
- String eventLocationKey = OffsetAndLength.resolveLocationFromDocument(document);
+ String eventLocationKey = OffsetAndLength
+ .resolveLocationFromDocument(document);
return eventStore.restore(eventLocationKey);
} catch (Exception e) {
throw new RuntimeException("Failed to navigate to next hit", e);
Added: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicy.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicy.java?view=auto&rev=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicy.java (added)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicy.java Wed Aug 8 16:11:08 2007
@@ -0,0 +1,29 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * 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 org.apache.logging.pinpoint.search;
+
+import org.apache.lucene.search.Query;
+
+/**
+ * Implementations decide when/if the underlying IndexSearcher instance should
+ * be thrown out
+ *
+ * @author psmith
+ */
+public interface ReloadPolicy {
+
+ public boolean shouldReload(Query query);
+}
Added: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicyAlways.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicyAlways.java?view=auto&rev=564042
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicyAlways.java (added)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ReloadPolicyAlways.java Wed Aug 8 16:11:08 2007
@@ -0,0 +1,32 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * 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 org.apache.logging.pinpoint.search;
+
+import org.apache.lucene.search.Query;
+
+/**
+ * Policy implementation that reloads the IndexSearcher on everq request
+ *
+ * @author psmith
+ *
+ */
+public class ReloadPolicyAlways implements ReloadPolicy {
+
+ public boolean shouldReload(Query query) {
+ return true;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org