-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Improve logging of metrics in the indexing job. * Add integrity checks to the metrics formatter * Clean up log messages * Add logging of metrics to reindex, merge in node store and total job time. * Improve logging * Add missing license header. Fix typo in class name. * Simplify logic. * Print elapsed time in hours:minutes instead of decimal minutes. * Do not call .name() on reference that is potentially null.
- Loading branch information
Showing
14 changed files
with
316 additions
and
89 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtils.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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.jackrabbit.oak.plugins.index; | ||
|
||
import org.apache.jackrabbit.guava.common.base.Stopwatch; | ||
|
||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FormattingUtils { | ||
public static String formatToSeconds(Stopwatch stopwatch) { | ||
LocalTime seconds = LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS)); | ||
return DateTimeFormatter.ISO_TIME.format(seconds); | ||
} | ||
|
||
public static String formatToMillis(Stopwatch stopwatch) { | ||
LocalTime nanoSeconds = LocalTime.ofNanoOfDay(stopwatch.elapsed(TimeUnit.MILLISECONDS)*1000000); | ||
return DateTimeFormatter.ISO_TIME.format(nanoSeconds); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/MetricsFormatter.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,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.jackrabbit.oak.plugins.index; | ||
|
||
import org.apache.jackrabbit.guava.common.base.Preconditions; | ||
import org.apache.jackrabbit.oak.commons.json.JsopBuilder; | ||
|
||
public class MetricsFormatter { | ||
private final JsopBuilder jsopBuilder = new JsopBuilder(); | ||
private boolean isWritable = true; | ||
public static MetricsFormatter newBuilder() { | ||
return new MetricsFormatter(); | ||
} | ||
|
||
private MetricsFormatter() { | ||
jsopBuilder.object(); | ||
} | ||
|
||
public MetricsFormatter add(String key, String value) { | ||
Preconditions.checkState(isWritable, "Formatter already built, in read-only mode"); | ||
jsopBuilder.key(key).value(value); | ||
return this; | ||
} | ||
|
||
public MetricsFormatter add(String key, int value) { | ||
Preconditions.checkState(isWritable, "Formatter already built, in read-only mode"); | ||
jsopBuilder.key(key).value(value); | ||
return this; | ||
} | ||
|
||
public MetricsFormatter add(String key, long value) { | ||
Preconditions.checkState(isWritable, "Formatter already built, in read-only mode"); | ||
jsopBuilder.key(key).value(value); | ||
return this; | ||
} | ||
|
||
public MetricsFormatter add(String key, boolean value) { | ||
Preconditions.checkState(isWritable, "Formatter already built, in read-only mode"); | ||
jsopBuilder.key(key).value(value); | ||
return this; | ||
} | ||
|
||
public String build() { | ||
if (isWritable){ | ||
jsopBuilder.endObject(); | ||
isWritable = false; | ||
} | ||
return jsopBuilder.toString(); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/MetricsFormatterTest.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,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.jackrabbit.oak.plugins.index; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class MetricsFormatterTest { | ||
|
||
@Test | ||
public void testAdd() { | ||
MetricsFormatter metricsFormatter = MetricsFormatter.newBuilder(); | ||
String result = metricsFormatter.add("key", "value") | ||
.add("key", 1) | ||
.add("key", 1L) | ||
.add("key", true) | ||
.build(); | ||
assertEquals("{\"key\":\"value\",\"key\":1,\"key\":1,\"key\":true}", result); | ||
assertThrows(IllegalStateException.class, () -> metricsFormatter.add("key", "value")); | ||
assertEquals("{\"key\":\"value\",\"key\":1,\"key\":1,\"key\":true}", metricsFormatter.build()); | ||
} | ||
} |
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
Oops, something went wrong.