Skip to content

Commit

Permalink
Do not record number of file.identifier, file.extension instances.
Browse files Browse the repository at this point in the history
- Add support for RelaxNG grammar detection in telemetry manager

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
  • Loading branch information
rgrunber authored and datho7561 committed Mar 10, 2023
1 parent 7feb246 commit f1e5297
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Expand Up @@ -31,6 +31,7 @@ public class DocumentTelemetryInfo {
private static final String DOC_PROP_GRAMMAR_NONE = "file.grammar.none";
private static final String DOC_PROP_GRAMMAR_DOCTYPE = "file.grammar.doctype";
private static final String DOC_PROP_GRAMMAR_XMLMODEL = "file.grammar.xmlmodel";
private static final String DOC_PROP_GRAMMAR_RELAXNG = "file.grammar.relaxng";
private static final String DOC_PROP_GRAMMAR_SCHEMALOC = "file.grammar.schemalocation";
private static final String DOC_PROP_GRAMMAR_NONSSCHEMALOC = "file.grammar.nonsschemalocation";

Expand All @@ -40,7 +41,7 @@ public static void collectDocumentTelemetryInfo (DOMDocument doc, ContentModelMa
String fileExtension = uri.substring(index + 1, uri.length()).toLowerCase();
boolean isXML = !DOMUtils.isXSD(doc) && !DOMUtils.isDTD(uri);
Set<ReferencedGrammarInfo> referencedGrammarInfos = manager.getReferencedGrammarInfos(doc);
cache.put(String.join(".", DOC_PROP_EXT, fileExtension));
cache.put(DOC_PROP_EXT, fileExtension);

if (referencedGrammarInfos.isEmpty()) {
if (isXML) {
Expand All @@ -60,7 +61,11 @@ public static void collectDocumentTelemetryInfo (DOMDocument doc, ContentModelMa
cache.put(DOC_PROP_GRAMMAR_DOCTYPE);
break;
case "xml-model":
cache.put(DOC_PROP_GRAMMAR_XMLMODEL);
if (DOMUtils.isRelaxNGUri(info.getIdentifierURI())) {
cache.put(DOC_PROP_GRAMMAR_RELAXNG);
} else {
cache.put(DOC_PROP_GRAMMAR_XMLMODEL);
}
break;
case "xsi:schemaLocation":
cache.put(DOC_PROP_GRAMMAR_SCHEMALOC);
Expand All @@ -76,7 +81,7 @@ public static void collectDocumentTelemetryInfo (DOMDocument doc, ContentModelMa
if (new URI(identifier).getScheme() != null && !URIUtils.isFileResource(identifier)) {
int limit = Math.min(identifier.length(), 200); // 200 char limit
String shortId = identifier.substring(0, limit);
cache.put(String.join(".", DOC_PROP_IDENTIFIER, shortId));
cache.put(DOC_PROP_IDENTIFIER, shortId);
}
} catch (URISyntaxException e) {
// continue
Expand Down
Expand Up @@ -12,20 +12,33 @@
package org.eclipse.lemminx.telemetry;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Store telemetry data for transmission at a later time
*/
public class TelemetryCache {

private Map<String, Integer> cache = new HashMap<>();
private Map<String, Object> cache = new HashMap<>();

public void put (String key) {
cache.put(key, cache.getOrDefault(key, 0) + 1);
public void put(String key) {
cache.put(key, ((Integer)cache.getOrDefault(key, 0)) + 1);
}

public Map<String, Integer> getProperties() {
public void put(String key, String value) {
Set<String> tmp = new HashSet<>();
Object val = cache.get(key);
if (val == null) {
tmp.add(value);
cache.put(key, tmp);
} else {
((Set<String>) cache.get(key)).add(value);
}
}

public Map<String, Object> getProperties() {
return cache;
}

Expand Down

0 comments on commit f1e5297

Please sign in to comment.