Skip to content

Commit

Permalink
Merge branch 'feature/analytics'
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Dec 7, 2020
2 parents 902866f + f8657ca commit 1cc3bec
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 1 deletion.
51 changes: 51 additions & 0 deletions DISCLAIMER.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
== Data

This product uses Google Analytics, a web analytics service provided by Google, Inc.("Google").

This product sends usage data and platform information via a secure connection to Google Analytics.

This product stores a small file with a random client id (UUID) in the user's home directory. Because it is random, it does not contain any personal information.

== Conveyed Properties
Properties are conveyed over a secure (https) connection and includes the following:

* Event name (e.g. "started")
* Version of the library (e.g. "5.20.146")
* The three top-most external package names (e.g. "org.apache.commons")
* A random client id (UUID) (e.g. "c38175c7-e822-40ef-a2ff-73a2e888b47c")
* The following System Properties:
- java.runtime.name (e.g "Java(TM) SE Runtime Environment")
- java.runtime.version (e.g. "1.8.0_191-b12")
- os.name (e.g. "Mac OS X")
- os.arch (e.g. "x86_64")
- os.version (e.g. "10.16")
- timezone.default (e.g. "Europe/London")
- available.processors (e.g. "16")
- max.memory.gib (e.g "14")
- java.major.version (e.g. "8")
- max.direct.memory.gib (e.g. "14")

The following library-specific properties are also conveyed:

* Key type (e.g. `java.lang.Long`)
* Value type (e.g. `java.lang.CharSequence`)
* Entries (e.g. 10000)

== Why is Data Collected?
Knowing how our products are used allows us to focus our resources more efficiently in our effort to improve our libraries and
provide better and more widely adopted solutions for the community.

== Open Data Pledge
Chronicle pledges to make aggregated data reports (using collected data) available to the general public at no cost.
Contact info@chronicle.software to obtain a link to these reports.

== Consent
By using this product, you consent to the collection, storage and processing of data (sent by this library) by Google and Chronicle in the manner and for the purposes set out above.

If you do not consent you can do either of the following:

A) Refrain from using this product

OR

B) Contact info@chronicle.software to have this feature removed
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>AnalyticsMain</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>net.openhft.chronicle.map.internal.AnalyticsMain</mainClass>
<classpathScope>compile</classpathScope>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
<profiles>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/openhft/chronicle/internal/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This package and any and all sub-packages contains strictly internal classes for this Chronicle library.
* Internal classes shall <em>never</em> be used directly.
* <p>
* Specifically, the following actions (including, but not limited to) are not allowed
* on internal classes and packages:
* <ul>
* <li>Casting to</li>
* <li>Reflection of any kind</li>
* <li>Explicit Serialize/deserialize</li>
* </ul>
* <p>
* The classes in this package and any sub-package are subject to
* changes at any time for any reason.
*/
package net.openhft.chronicle.internal;
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.openhft.chronicle.hash.serialization.impl.MarshallableReaderWriter;
import net.openhft.chronicle.hash.serialization.impl.SerializationBuilder;
import net.openhft.chronicle.hash.serialization.impl.TypedMarshallableReaderWriter;
import net.openhft.chronicle.map.internal.AnalyticsHolder;
import net.openhft.chronicle.map.replication.MapRemoteOperations;
import net.openhft.chronicle.set.ChronicleSetBuilder;
import net.openhft.chronicle.values.ValueModel;
Expand Down Expand Up @@ -1012,7 +1013,7 @@ public ChronicleMapBuilder<K, V> entries(final long entries) {
long entries() {
if (entries < 0) {
throw new IllegalStateException("If in-memory Chronicle Map is created or persisted\n" +
"to a file for the first time (i. e. not accessing existing file),\n" +
"to a file for the first time (i. e. not accessing an existing file),\n" +
"ChronicleMapBuilder.entries() must be configured.\n" +
"See Chronicle Map 3 tutorial and javadocs for more information");
}
Expand Down Expand Up @@ -1626,6 +1627,7 @@ public ChronicleMap<K, V> recoverPersistedTo(@NotNull final File file, final boo
public ChronicleMap<K, V> recoverPersistedTo(@NotNull final File file,
final boolean sameBuilderConfigAndLibraryVersion,
@Nullable final ChronicleHashCorruption.Listener corruptionListener) throws IOException {
AnalyticsHolder.instance().sendEvent("recover");
return clone().createWithFile(file, true, sameBuilderConfigAndLibraryVersion, corruptionListener);
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.PointerBytesStore;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.analytics.AnalyticsFacade;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.hash.ChronicleHashClosedException;
import net.openhft.chronicle.hash.ChronicleHashCorruption;
Expand All @@ -36,6 +37,7 @@
import net.openhft.chronicle.hash.serialization.impl.SerializationBuilder;
import net.openhft.chronicle.map.impl.*;
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
import net.openhft.chronicle.map.internal.AnalyticsHolder;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
Expand All @@ -45,6 +47,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -109,6 +113,17 @@ public VanillaChronicleMap(@NotNull final ChronicleMapBuilder<K, V> builder) {

initTransientsFromBuilder(builder);
initTransients();

final Map<String, String> additionalEventParameters = AnalyticsFacade.standardAdditionalProperties();
additionalEventParameters.put("key_type", keyClass.getTypeName());
additionalEventParameters.put("value_type", valueClass.getTypeName());
try {
additionalEventParameters.put("entries", Long.toString(builder.entries()));
} catch (RuntimeException ignored) {
// The ChronicleMapBuilder::entries may throw an Exception. If so, just ignore this parameter
}

AnalyticsHolder.instance().sendEvent("started", additionalEventParameters);
}

public static long alignAddr(final long addr, final long alignment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.openhft.chronicle.map.internal;

import net.openhft.chronicle.core.analytics.AnalyticsFacade;
import net.openhft.chronicle.core.pom.PomProperties;

public enum AnalyticsHolder {;

static {
System.setProperty("chronicle.analytics.enable","true");
}

// Todo: VERSION is "unknown" for some reason
private static final String VERSION = PomProperties.version("net.openhft", "chronicle-map");

private static final AnalyticsFacade ANALYTICS = AnalyticsFacade.standardBuilder("G-TDTJG5CT6G", "J8qsWGHgQP6CLs43mQ10KQ", VERSION)
//.withReportDespiteJUnit()
.withDebugLogger(System.out::println)
//.withUrl("https://www.google-analytics.com/debug/mp/collect")
.build();

public static AnalyticsFacade instance() {
return ANALYTICS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.openhft.chronicle.map.internal;

import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;

public final class AnalyticsMain {

public static final String BASE_MAP_NAME = "analytics_test_map";
public static final String MAP_NAME1 = BASE_MAP_NAME + "1";
public static final String MAP_NAME2 = BASE_MAP_NAME + "2";

public static void main(String[] args) {
System.out.println("Creating two maps and sending analytics...");
System.out.println("Currently, there is a limit of four messages per h per JVM instance so only some analytics messages might be sent upstream.");

try (ChronicleMap<CharSequence, CharSequence> m1 = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.name(MAP_NAME1)
.averageKeySize(32)
.averageValueSize(32)
.entries(1_000)
.create()) {
try (ChronicleMap<Long, CharSequence> m2 = ChronicleMapBuilder.of(Long.class, CharSequence.class)
.name(MAP_NAME2)
.averageValueSize(32)
.entries(100)
.create()) {

m1.put("A", "1");
m2.put(2L, "Two");
}
}
Jvm.pause(2_000);
System.out.println("Completed successfully");
System.exit(0);
}

private static <K, V> ChronicleMap<K, V> createMap(Class<K> keyType, Class<V> valueType, String name) {
return ChronicleMapBuilder.of(keyType, valueType)
.name(name)
.averageKeySize(32)
.averageValueSize(32)
.entries(1_000)
.create();
}

}

0 comments on commit 1cc3bec

Please sign in to comment.