Skip to content

Commit

Permalink
Fixes #4355: The apoc.metrics.get throws an URLAccessChecker error (#…
Browse files Browse the repository at this point in the history
…4358)

* Fixes #4355: The apoc.metrics.get throws an URLAccessChecker error

* restored reader creation
  • Loading branch information
vga91 authored Feb 25, 2025
1 parent 96b1bd1 commit c3d857c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 13 additions & 8 deletions extended-it/src/test/java/apoc/neo4j/docker/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.neo4j.driver.Record;
import org.neo4j.driver.Session;
Expand All @@ -29,8 +28,6 @@
* @author as
* @since 13.02.19
*/
// TODO Investigate why this test is not working. Possibly increase timeout for container
@Ignore
public class MetricsTest {

private static Neo4jContainerExtension neo4jContainer;
Expand Down Expand Up @@ -63,24 +60,32 @@ public void shouldNotGetFileOutsideMetricsDir() {
}
}

// TODO: Investigate broken test. It hangs for more than 30 seconds for no reason.
@Test
@Ignore
public void shouldGetMetrics() {
session.executeRead(tx -> tx.run("RETURN 1 AS num;").consume());
String metricKey = "neo4j.system.check_point.total_time";

List<String> metricsList = session.run("CALL apoc.metrics.list")
.list(i -> i.get("name").asString());

for (String metric: metricsList) {
metricsGetAssertion(metric);
}
}

private void metricsGetAssertion(String metric) {
assertEventually(() -> {
try {
return session.run("CALL apoc.metrics.get($metricKey)",
map("metricKey", metricKey))
map("metricKey", metric))
.list()
.get(0)
.asMap();
} catch (Exception e) {
System.out.println("e = " + e);
return Map.<String, Object>of();
}
},
map -> Set.of("timestamp", "metric", "map").equals(map.keySet()) && map.get("metric").equals(metricKey),
map -> Set.of("timestamp", "metric", "map").equals(map.keySet()) && map.get("metric").equals(metric),
30L, TimeUnit.SECONDS);
}

Expand Down
12 changes: 4 additions & 8 deletions extended/src/main/java/apoc/metrics/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import apoc.load.CSVResult;
import apoc.load.LoadCsv;
import apoc.load.util.LoadCsvConfig;
import apoc.util.CompressionAlgo;
import apoc.util.ExtendedFileUtils;
import apoc.util.FileUtils;
import apoc.util.SupportedProtocols;
import apoc.util.Util;
import apoc.util.*;
import org.neo4j.graphdb.security.URLAccessChecker;
import org.neo4j.logging.Log;
import org.neo4j.procedure.*;
Expand Down Expand Up @@ -118,7 +114,7 @@ public Neo4jMeasuredMetric(String name, long lastUpdated) {
}
}

@Procedure(mode=Mode.DBMS)
@Procedure
@Description("apoc.metrics.list() - get a list of available metrics")
public Stream<Neo4jMeasuredMetric> list() {
File metricsDir = ExtendedFileUtils.getMetricsDirectory();
Expand Down Expand Up @@ -204,7 +200,7 @@ public Stream<GenericMetric> loadCsvForMetric(String metricName, Map<String,Obje
}
}

@Procedure(mode=Mode.DBMS)
@Procedure
@Description("apoc.metrics.storage(directorySetting) - retrieve storage metrics about the devices Neo4j uses for data storage. " +
"directorySetting may be any valid neo4j directory setting name, such as 'server.directories.data'. If null is provided " +
"as a directorySetting, you will get back all available directory settings. For a list of available directory settings, " +
Expand Down Expand Up @@ -239,7 +235,7 @@ public Stream<StorageMetric> storage(@Name("directorySetting") String directoryS
.map(StorageMetric::fromStoragePair);
}

@Procedure(mode=Mode.DBMS)
@Procedure
@Description("apoc.metrics.get(metricName, {}) - retrieve a system metric by its metric name. Additional configuration options may be passed matching the options available for apoc.load.csv.")
/**
* This method is a specialization of apoc.load.csv, it just happens that the directory and file path
Expand Down

0 comments on commit c3d857c

Please sign in to comment.