@loghead/core 0.1.21 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/server.js +34 -6
- package/dist/cli_main.js +9 -12
- package/dist/public/assets/index-BSfBUhxd.js +107 -0
- package/dist/public/assets/index-Zf0dAxdt.css +1 -0
- package/dist/public/index.html +2 -2
- package/package.json +3 -2
- package/dist/public/assets/index-CEQopy59.css +0 -1
- package/dist/public/assets/index-JSs_QfLO.js +0 -95
package/dist/api/server.js
CHANGED
|
@@ -23,6 +23,7 @@ async function startApiServer(db) {
|
|
|
23
23
|
publicPath = path_1.default.join(__dirname, "../../dist/public");
|
|
24
24
|
}
|
|
25
25
|
if (require("fs").existsSync(publicPath)) {
|
|
26
|
+
console.log(chalk_1.default.blue(`Serving frontend from: ${publicPath}`));
|
|
26
27
|
app.use(express_1.default.static(publicPath));
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
@@ -58,24 +59,32 @@ async function startApiServer(db) {
|
|
|
58
59
|
}
|
|
59
60
|
return result;
|
|
60
61
|
};
|
|
61
|
-
// OTLP Logs Ingestion Endpoint
|
|
62
62
|
app.post("/v1/logs", async (req, res) => {
|
|
63
|
+
console.log(`[API] POST /v1/logs received`);
|
|
63
64
|
try {
|
|
64
65
|
const authHeader = req.headers.authorization;
|
|
65
66
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
67
|
+
console.warn("[API] /v1/logs Unauthorized: Missing token");
|
|
66
68
|
return res.status(401).json({ code: 16, message: "Unauthenticated" });
|
|
67
69
|
}
|
|
68
70
|
const token = authHeader.split(" ")[1];
|
|
69
71
|
const payload = await auth.verifyToken(token);
|
|
70
72
|
if (!payload || !payload.streamId) {
|
|
73
|
+
console.warn("[API] /v1/logs Unauthorized: Invalid token");
|
|
71
74
|
return res.status(401).json({ code: 16, message: "Invalid token" });
|
|
72
75
|
}
|
|
73
76
|
const streamId = payload.streamId;
|
|
77
|
+
console.log(`[API] Ingesting OTLP logs for stream: ${streamId}`);
|
|
74
78
|
const { resourceLogs } = req.body;
|
|
75
79
|
if (!resourceLogs || !Array.isArray(resourceLogs)) {
|
|
80
|
+
console.warn("[API] /v1/logs Invalid payload");
|
|
76
81
|
return res.status(400).json({ code: 3, message: "Invalid payload" });
|
|
77
82
|
}
|
|
83
|
+
// ... existing logic ...
|
|
78
84
|
let count = 0;
|
|
85
|
+
// ... loop ...
|
|
86
|
+
// (I will keep the existing loop logic but add a log at the end)
|
|
87
|
+
/* ... existing loop code ... */
|
|
79
88
|
for (const resourceLog of resourceLogs) {
|
|
80
89
|
const resourceAttrs = parseOtlpAttributes(resourceLog.resource?.attributes);
|
|
81
90
|
if (resourceLog.scopeLogs) {
|
|
@@ -108,6 +117,7 @@ async function startApiServer(db) {
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
}
|
|
120
|
+
console.log(`[API] /v1/logs Ingested ${count} logs`);
|
|
111
121
|
res.json({ partialSuccess: {}, logsIngested: count });
|
|
112
122
|
}
|
|
113
123
|
catch (e) {
|
|
@@ -116,24 +126,31 @@ async function startApiServer(db) {
|
|
|
116
126
|
}
|
|
117
127
|
});
|
|
118
128
|
app.post("/api/ingest", async (req, res) => {
|
|
129
|
+
console.log(`[API] POST /api/ingest received`);
|
|
119
130
|
try {
|
|
120
131
|
const authHeader = req.headers.authorization;
|
|
121
132
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
133
|
+
console.warn("[API] /api/ingest Unauthorized: Missing token");
|
|
122
134
|
return res.status(401).send("Unauthorized: Missing token");
|
|
123
135
|
}
|
|
124
136
|
const token = authHeader.split(" ")[1];
|
|
125
137
|
const payload = await auth.verifyToken(token);
|
|
126
138
|
if (!payload || !payload.streamId) {
|
|
139
|
+
console.warn("[API] /api/ingest Unauthorized: Invalid token");
|
|
127
140
|
return res.status(401).send("Unauthorized: Invalid token");
|
|
128
141
|
}
|
|
129
142
|
const { streamId, logs } = req.body;
|
|
143
|
+
console.log(`[API] Ingesting logs for stream: ${streamId}`);
|
|
130
144
|
if (streamId !== payload.streamId) {
|
|
145
|
+
console.warn(`[API] /api/ingest Forbidden: Token streamId ${payload.streamId} != body streamId ${streamId}`);
|
|
131
146
|
return res.status(403).send("Forbidden: Token does not match streamId");
|
|
132
147
|
}
|
|
133
148
|
if (!logs) {
|
|
149
|
+
console.warn("[API] /api/ingest Missing logs");
|
|
134
150
|
return res.status(400).send("Missing logs");
|
|
135
151
|
}
|
|
136
152
|
const logEntries = Array.isArray(logs) ? logs : [logs];
|
|
153
|
+
console.log(`[API] Processing ${logEntries.length} log entries`);
|
|
137
154
|
for (const log of logEntries) {
|
|
138
155
|
let content = "";
|
|
139
156
|
let metadata = {};
|
|
@@ -148,6 +165,7 @@ async function startApiServer(db) {
|
|
|
148
165
|
await db.addLog(streamId, content, metadata);
|
|
149
166
|
}
|
|
150
167
|
}
|
|
168
|
+
console.log(`[API] /api/ingest Successfully added ${logEntries.length} logs`);
|
|
151
169
|
res.json({ success: true, count: logEntries.length });
|
|
152
170
|
}
|
|
153
171
|
catch (e) {
|
|
@@ -155,6 +173,16 @@ async function startApiServer(db) {
|
|
|
155
173
|
res.status(500).json({ error: String(e) });
|
|
156
174
|
}
|
|
157
175
|
});
|
|
176
|
+
// Added this endpoint to fetch system token
|
|
177
|
+
app.get("/api/system/token", async (_req, res) => {
|
|
178
|
+
try {
|
|
179
|
+
const token = await auth.getOrCreateMcpToken();
|
|
180
|
+
res.json({ token });
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
res.status(500).json({ error: String(e) });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
158
186
|
app.get("/api/connection", async (req, res) => {
|
|
159
187
|
try {
|
|
160
188
|
const token = await auth.getOrCreateMcpToken();
|
|
@@ -171,10 +199,6 @@ async function startApiServer(db) {
|
|
|
171
199
|
const projects = db.listProjects();
|
|
172
200
|
res.json(projects);
|
|
173
201
|
});
|
|
174
|
-
app.get("/api/system/token", async (_req, res) => {
|
|
175
|
-
const token = await auth.getOrCreateMcpToken();
|
|
176
|
-
res.json({ token });
|
|
177
|
-
});
|
|
178
202
|
app.post("/api/projects", (req, res) => {
|
|
179
203
|
const { name } = req.body;
|
|
180
204
|
if (!name)
|
|
@@ -270,7 +294,11 @@ async function startApiServer(db) {
|
|
|
270
294
|
res.status(404).send("Dashboard not found. Please build the frontend.");
|
|
271
295
|
}
|
|
272
296
|
});
|
|
273
|
-
app.listen(port, () => {
|
|
297
|
+
const server = app.listen(port, () => {
|
|
274
298
|
// listening
|
|
275
299
|
});
|
|
300
|
+
server.on("error", (e) => {
|
|
301
|
+
console.error("Server error:", e);
|
|
302
|
+
process.exit(1);
|
|
303
|
+
});
|
|
276
304
|
}
|
package/dist/cli_main.js
CHANGED
|
@@ -12,24 +12,22 @@ const migrate_1 = require("./db/migrate");
|
|
|
12
12
|
// import { ensureInfrastructure } from "./utils/startup"; // Might need adjustment
|
|
13
13
|
const auth_1 = require("./services/auth");
|
|
14
14
|
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
-
const open_1 = __importDefault(require("open"));
|
|
16
15
|
const db = new db_1.DbService();
|
|
17
16
|
const auth = new auth_1.AuthService();
|
|
18
17
|
async function main() {
|
|
19
18
|
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
20
|
-
.command(["start", "$0"], "Start API Server", {}, async () => {
|
|
19
|
+
.command(["start", "$0"], "Start API Server", {}, async (argv) => {
|
|
21
20
|
// console.log("Ensuring database is initialized...");
|
|
22
21
|
await (0, migrate_1.migrate)(false); // Run migrations silently
|
|
23
22
|
const token = await auth.getOrCreateMcpToken();
|
|
24
23
|
// Start API Server (this sets up express listen)
|
|
25
24
|
await (0, server_1.startApiServer)(db);
|
|
26
|
-
console.clear();
|
|
25
|
+
// console.clear();
|
|
27
26
|
console.log(chalk_1.default.bold.green(`
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/___/
|
|
27
|
+
▌ ▌ ▌
|
|
28
|
+
▌ ▞▀▖▞▀▌▛▀▖▞▀▖▝▀▖▞▀▌
|
|
29
|
+
▌ ▌ ▌▚▄▌▌ ▌▛▀ ▞▀▌▌ ▌
|
|
30
|
+
▀▀▘▝▀ ▗▄▘▘ ▘▝▀▘▝▀▘▝▀▘
|
|
33
31
|
`));
|
|
34
32
|
console.log(chalk_1.default.gray("--------------------------------------------------"));
|
|
35
33
|
console.log(chalk_1.default.bold(" 🟢 Loghead is running"));
|
|
@@ -43,7 +41,6 @@ async function main() {
|
|
|
43
41
|
console.log("");
|
|
44
42
|
console.log(chalk_1.default.gray("--------------------------------------------------"));
|
|
45
43
|
console.log(chalk_1.default.gray(" Press Ctrl+C to stop"));
|
|
46
|
-
(0, open_1.default)("http://localhost:4567");
|
|
47
44
|
})
|
|
48
45
|
.command("projects <cmd> [name]", "Manage projects", (yargs) => {
|
|
49
46
|
yargs
|
|
@@ -63,14 +60,14 @@ async function main() {
|
|
|
63
60
|
.command("streams <cmd> [type] [name]", "Manage streams", (yargs) => {
|
|
64
61
|
yargs
|
|
65
62
|
.command("list", "List streams", {
|
|
66
|
-
project: { type: "string", demandOption: true }
|
|
63
|
+
project: { type: "string", demandOption: true },
|
|
67
64
|
}, (argv) => {
|
|
68
65
|
const streams = db.listStreams(argv.project);
|
|
69
66
|
console.table(streams);
|
|
70
67
|
})
|
|
71
68
|
.command("add <type> <name>", "Add stream", {
|
|
72
69
|
project: { type: "string", demandOption: true },
|
|
73
|
-
container: { type: "string" }
|
|
70
|
+
container: { type: "string" },
|
|
74
71
|
}, async (argv) => {
|
|
75
72
|
const config = {};
|
|
76
73
|
if (argv.type === "docker" && argv.container) {
|
|
@@ -94,7 +91,7 @@ async function main() {
|
|
|
94
91
|
.help()
|
|
95
92
|
.parse();
|
|
96
93
|
}
|
|
97
|
-
main().catch(err => {
|
|
94
|
+
main().catch((err) => {
|
|
98
95
|
console.error(err);
|
|
99
96
|
process.exit(1);
|
|
100
97
|
});
|