• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 28113618611

24 Jun 2026 04:28PM UTC coverage: 31.926% (-0.2%) from 32.089%
28113618611

Pull #116

github

web-flow
Merge d931f8afc into eebd16ba4
Pull Request #116: Enhance and standardize logging across multiple components

313 of 1106 branches covered (28.3%)

Branch coverage included in aggregate %.

1048 of 3157 relevant lines covered (33.2%)

5.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/registry/DebugPage.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import com.mongodb.client.MongoCursor;
5
import io.vertx.ext.web.RoutingContext;
6
import org.bson.Document;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import java.io.IOException;
11

12
import static com.knowledgepixels.registry.RegistryDB.collection;
13
import static com.mongodb.client.model.Indexes.ascending;
14

15
public class DebugPage extends Page {
16

17
    private static final Logger logger = LoggerFactory.getLogger(DebugPage.class);
×
18

19
    public static void show(RoutingContext context) {
20
        DebugPage page;
21
        logger.info("Received debug request: {}", context.request().path());
×
22
        try (ClientSession s = RegistryDB.getClient().startSession()) {
×
23
            s.startTransaction();
×
24
            page = new DebugPage(s, context);
×
25
            page.show();
×
26
        } catch (IOException ex) {
×
27
            logger.warn("Failed to show debug page for request {}: {} ({})", context.request().path(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
×
28
        } finally {
29
            logger.debug("Ending response for debug request: {}", context.request().path());
×
30
            context.response().end();
×
31
            // TODO Clean-up here?
32
        }
33
    }
×
34

35
    private DebugPage(ClientSession mongoSession, RoutingContext context) {
36
        super(mongoSession, context);
×
37
    }
×
38

39
    protected void show() throws IOException {
40
        RoutingContext c = getContext();
×
41
        logger.debug("Preparing debug response for {}", getFullRequest());
×
42

43
        if (getRequestString().matches("/debug/trustPaths")) {
×
44
            String counterString = c.request().getParam("trustStateCounter");
×
45
            if (counterString == null) {
×
46
                logger.info("Serving current trustPaths for {}", getFullRequest());
×
47
                print(getTrustPathsTxt(mongoSession));
×
48
            } else {
49
                Long counter = Long.parseLong(counterString);
×
50
                logger.info("Serving trustPaths for trustStateCounter={} request={}", counter, getFullRequest());
×
51
                print(RegistryDB.getOne(mongoSession, "debug_trustPaths", new Document("trustStateCounter", counter)).getString("trustStateTxt"));
×
52
            }
53
            setRespContentType("text/plain");
×
54
        } else if (getRequestString().matches("/debug/endorsements")) {
×
55
            MongoCursor<Document> tp = collection("endorsements").find(mongoSession).cursor();
×
56
            int count = 0;
×
57
            while (tp.hasNext()) {
×
58
                Document d = tp.next();
×
59
                println(d.get("agent") + ">" + d.get("pubkey") + " " + d.get("endorsedNanopub") + " " + d.get("source") + " (" + d.get("status") + ")");
×
60
                count++;
×
61
            }
×
62
            setRespContentType("text/plain");
×
63
            logger.info("Listed {} endorsements for {}", count, getFullRequest());
×
64
        } else if (getRequestString().matches("/debug/accounts")) {
×
65
            MongoCursor<Document> tp = collection("accounts").find(mongoSession).cursor();
×
66
            int count = 0;
×
67
            while (tp.hasNext()) {
×
68
                Document d = tp.next();
×
69
                println(d.getString("agent") + ">" + d.get("pubkey") + " " + d.get("depth") + " (" + d.get("status") + ")");
×
70
                count++;
×
71
            }
×
72
            logger.info("Listed {} accounts for {}", count, getFullRequest());
×
73
        } else if (getRequestString().matches("/debug/tasks")) {
×
74
            setRespContentType("text/plain");
×
75
            try {
76
                String currentTask = Task.getCurrentTaskName();
×
77
                if (currentTask != null) {
×
78
                    long elapsed = System.currentTimeMillis() - Task.getCurrentTaskStartTime();
×
79
                    println("Currently running: " + currentTask + " (for " + elapsed + "ms)");
×
80
                } else {
×
81
                    println("Currently running: (none)");
×
82
                }
83
                println("");
×
84
                MongoCursor<Document> tasks = collection(Collection.TASKS.toString()).find(mongoSession)
×
85
                        .sort(ascending("not-before")).cursor();
×
86
                int count = 0;
×
87
                while (tasks.hasNext()) {
×
88
                    println(tasks.next().toJson());
×
89
                    count++;
×
90
                }
91
                println("Total queued tasks: " + count);
×
92
                logger.info("Listed {} queued tasks for {}", count, getFullRequest());
×
93
            } catch (Exception ex) {
×
94
                logger.warn("Failed while listing tasks for {}: {} ({})", getFullRequest(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
×
95
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
96
            }
×
97
        } else if (getRequestString().matches("/debug/peerState")) {
×
98
            setRespContentType("text/plain");
×
99
            try {
100
                long count = collection(Collection.PEER_STATE.toString()).countDocuments(mongoSession);
×
101
                println("peerState documents: " + count);
×
102
                MongoCursor<Document> ps = collection(Collection.PEER_STATE.toString()).find(mongoSession).cursor();
×
103
                int listed = 0;
×
104
                while (ps.hasNext()) {
×
105
                    println(ps.next().toJson());
×
106
                    listed++;
×
107
                }
108
                logger.info("Listed {} peerState documents for {}", listed, getFullRequest());
×
109
            } catch (Exception ex) {
×
110
                logger.warn("Failed while listing peerState for {}: {} ({})", getFullRequest(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
×
111
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
112
            }
×
113
        } else {
114
            logger.warn("Invalid debug request path: {}", getFullRequest());
×
115
            c.response().setStatusCode(400).setStatusMessage("Invalid request: " + getFullRequest());
×
116
        }
117
    }
×
118

119
    public static String getTrustPathsTxt(ClientSession mongoSession) {
120
        String s = "";
×
121
        MongoCursor<Document> tp = collection("trustPaths").find(mongoSession).sort(ascending("_id")).cursor();
×
122
        while (tp.hasNext()) {
×
123
            Document d = tp.next();
×
124
            String path = d.getString("_id");
×
125
            path = path.replace(" ", " > ");
×
126
            if (d.getString("type").equals("extended")) {
×
127
                path = path.replaceFirst(" > ([^ ]+)$", " ~ $1");
×
128
            }
129
            s += path + "\n";
×
130
        }
×
131
        return s;
×
132
    }
133

134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc