Skip to content

Commit

Permalink
Send (aggregated) server.document.open events at fixed periods.
Browse files Browse the repository at this point in the history
- Send server.document.open approximately every other hour

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
  • Loading branch information
rgrunber authored and datho7561 committed Mar 6, 2023
1 parent d764495 commit fb9eabd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions USAGE_DATA.md
Expand Up @@ -15,10 +15,10 @@ When telemetry events are enabled, the following information is emitted when the
* The server version number
* Text Document Information
* When a document is opened :
* The file extension (eg. `xml`, `xsd`, `dtd`)
* The file extension (eg. `xml`, `xsd`, `dtd`, `rng`)
* The associated grammar types (eg. `none`, `doctype`, `xml-model`, `xsi:schemaLocation`, `xsi:noNamespaceSchemaLocation`)
* The grammar identifiers for an XML document (eg. `http://maven.apache.org/xsd/maven-4.0.0.xsd`)
* The resolver used to resolve the grammar identifier (eg. `catalog`, `file association`, `embedded catalog.xsd`, `embedded xml.xsd`, `embedded xslt.xsd`)
* The resolver used to resolve the grammar identifier (eg. `catalog`, `file association`, `embedded catalog.xsd`, `embedded xml.xsd`, `embedded xslt.xsd`, `relaxng.rng`)
* Note: Does NOT include the `JAVA_HOME` environment variable for privacy reasons

Currently, the startup event is the only telemetry event that is emitted.
Expand Up @@ -238,7 +238,6 @@ public CompletableFuture<Object> shutdown() {
if (capabilityManager.getClientCapabilities().shouldLanguageServerExitOnShutdown()) {
delayer.schedule(() -> exit(0), 1, TimeUnit.SECONDS);
}
getTelemetryManager().shutdown();
return computeAsync(cc -> new Object());
}

Expand Down
Expand Up @@ -29,4 +29,12 @@ public Map<String, Integer> getProperties() {
return cache;
}

public boolean isEmpty () {
return cache.isEmpty();
}

public void clear () {
cache.clear();
}

}
Expand Up @@ -9,6 +9,11 @@
*******************************************************************************/
package org.eclipse.lemminx.telemetry;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.extensions.contentmodel.model.ContentModelManager;
import org.eclipse.lsp4j.InitializedParams;
Expand All @@ -25,20 +30,21 @@ public class TelemetryManager {
* "startup" telemetry event name
*/
private static final String STARTUP_EVENT_NAME = "server.initialized";
private static final String SHUTDOWN_EVENT_NAME = "server.shutdown";

@SuppressWarnings("unused")
private static final String DOC_OPEN_EVENT_NAME = "server.document.open";

private final LanguageClient languageClient;

private final TelemetryCache telemetryCache;

private final ScheduledExecutorService executor;

private boolean enabled;

public TelemetryManager(LanguageClient languageClient) {
this.languageClient = languageClient;
this.telemetryCache = new TelemetryCache();
this.executor = Executors.newSingleThreadScheduledExecutor();
}

public boolean isEnabled() {
Expand All @@ -58,6 +64,16 @@ public void onInitialized(InitializedParams params) {
if (isEnabled()) {
telemetryEvent(STARTUP_EVENT_NAME, InitializationTelemetryInfo.getInitializationTelemetryInfo());
}

executor.scheduleAtFixedRate(() -> {
int hour = LocalDateTime.now().getHour();
if (hour % 2 == 0) {
if (isEnabled() && !telemetryCache.isEmpty()) {
telemetryEvent(DOC_OPEN_EVENT_NAME, telemetryCache.getProperties());
telemetryCache.clear();
}
}
}, 30, 60, TimeUnit.MINUTES);
}

public void onDidOpen(DOMDocument document, ContentModelManager manager) {
Expand All @@ -76,10 +92,4 @@ private void telemetryEvent(String eventName, Object object) {
}
}

public void shutdown() {
if (isEnabled()) {
telemetryEvent(SHUTDOWN_EVENT_NAME, telemetryCache.getProperties());
}
}

}

0 comments on commit fb9eabd

Please sign in to comment.