@theotherwillembotha/node-red-loki 0.0.55 → 0.1.0

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/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # @theotherwillembotha/node-red-loki
2
2
 
3
- Grafana Loki logger config node for Node-RED. Extends the logging infrastructure provided by [@theotherwillembotha/node-red-plugincore](https://github.com/theotherwillembotha/nodered_plugincore) with a Loki transport, so any node built with the `@Logger` decorator can ship structured log entries directly to a Loki instance.
3
+ Grafana Loki integration for Node-RED. Built on [@theotherwillembotha/node-red-plugincore](https://github.com/theotherwillembotha/nodered_plugincore).
4
4
 
5
- ---
5
+ Provides three nodes:
6
+ - **Loki Service** - shared connection config (URL, auth, tenant ID)
7
+ - **Loki Logger** - ships structured log entries from any `@Logger`-decorated node directly to Loki
8
+ - **Loki Query** - executes a LogQL query and emits the results as Node-RED messages
6
9
 
7
- ## Usage in Node-RED
10
+ ---
8
11
 
9
- ### Installation
12
+ ## Installation
10
13
 
11
14
  Either use the **Manage Palette** option in the Node-RED editor, or run the following command in your Node-RED user directory (typically `~/.node-red`):
12
15
 
@@ -17,47 +20,119 @@ npm install @theotherwillembotha/node-red-loki
17
20
  > [!IMPORTANT]
18
21
  > **This plugin requires [`@theotherwillembotha/node-red-plugincore`](https://github.com/theotherwillembotha/nodered_plugincore) to be installed.**
19
22
  >
20
- > `node-red-plugincore` is declared as a dependency and npm will install it automatically alongside this package. However, due to a [known Node-RED limitation](https://github.com/node-red/node-red/issues/3529), packages that arrive as transitive npm dependencies are only discovered by the Node-RED runtime on the **next startup**.
23
+ > `node-red-plugincore` is declared as a dependency and npm will install it automatically. However, due to a [known Node-RED limitation](https://github.com/node-red/node-red/issues/3529), transitive npm dependencies are only discovered by the Node-RED runtime on the **next startup**.
21
24
  >
22
- > **You have two options:**
23
- > - Install [`@theotherwillembotha/node-red-plugincore`](https://flows.nodered.org/node/@theotherwillembotha/node-red-plugincore) via the palette manager or `npm install` **first**, then install this plugin — both will be available immediately without a restart.
24
- > - Install this plugin directly `node-red-plugincore` will be installed automatically alongside it. **Restart Node-RED** once and both packages will be fully loaded.
25
+ > **Two options:**
26
+ > - Install [`@theotherwillembotha/node-red-plugincore`](https://flows.nodered.org/node/@theotherwillembotha/node-red-plugincore) via the palette manager or `npm install` **first**, then install this plugin.
27
+ > - Install this plugin directly. `node-red-plugincore` installs alongside it. **Restart Node-RED once** and both packages will be fully loaded.
28
+
29
+ ---
25
30
 
26
- ### Config node
31
+ ## Nodes
27
32
 
28
- This package adds a single config node: **Loki Logger**.
33
+ ### Loki Service
29
34
 
30
- The Loki Logger config node appears in the logger selector of any node that uses the `@Logger` decorator (e.g. the Logger Node from [node-red-telemetry](https://github.com/theotherwillembotha/nodered_telemetry), or any custom node built on this framework).
35
+ Shared connection configuration referenced by both the Loki Logger and Loki Query nodes.
31
36
 
32
- #### Configuration fields
37
+ ![Loki Service node](documentation/LokiServiceNode.png)
33
38
 
34
39
  | Field | Description |
35
40
  |-------|-------------|
36
- | **Name** | Optional label for this config node |
37
- | **Host** | Hostname or IP address of your Loki instance (e.g. `loki` or `192.168.1.10`) |
38
- | **Port** | Loki HTTP port (default: `3100`) |
39
- | **Tenant ID** | Optional. Set the `X-Scope-OrgID` header for multi-tenant Loki deployments. Leave blank for single-tenant mode. |
40
- | **Level** | Minimum log level to ship: Debug, Info, Warning, or Error |
41
- | **Template** | Handlebars template that shapes each log entry. The default `message:{{msg}}` passes the raw message through. Customise to include only the fields you need (e.g. `{{msg.topic}}: {{msg.payload}}`). |
41
+ | **Name** | Display label for this config node |
42
+ | **URL** | Base URL of your Loki instance, including port (e.g. `http://loki:3100`) |
43
+ | **Tenant ID** | Optional. Sent as the `X-Scope-OrgID` header for multi-tenant deployments. Leave blank for single-tenant mode. |
44
+ | **Username** | Optional username for basic authentication |
45
+ | **Auth Token** | Optional password or token for basic authentication |
46
+
47
+ The **Test Connection** button pings the Loki instance with the current settings and reports success or failure inline; no need to save first.
48
+
49
+ ---
50
+
51
+ ### Loki Logger
52
+
53
+ A logger config node that ships log entries from any node using the `@Logger` decorator directly to Loki over the HTTP push API.
54
+
55
+ ![Loki Logger Config node](documentation/LokiLoggerConfigNode.png)
56
+
57
+ | Field | Description |
58
+ |-------|-------------|
59
+ | **Name** | Display label for this config node |
60
+ | **Level** | Minimum log level: Debug, Info, Warning, or Error |
61
+ | **Loki Service** | The Loki Service config node to use for the connection |
62
+ | **Template** | Handlebars template that shapes each log line (e.g. `message:{{{json msg}}}`) |
63
+
64
+ The Loki Logger appears in the logger selector of any node built with the plugincore `@Logger` decorator.
65
+
66
+ ---
67
+
68
+ ### Loki Query
69
+
70
+ Executes a LogQL query against Loki on demand and emits the results as Node-RED messages.
71
+
72
+ ![Loki Query node](documentation/LokiQueryNode.png)
73
+
74
+ | Field | Description |
75
+ |-------|-------------|
76
+ | **Name** | Display label for this node |
77
+ | **Loki Service** | The Loki Service config node to use for the connection |
78
+ | **Query** | LogQL query; edited in a Monaco editor with syntax highlighting and snippet completions |
79
+ | **Start** | Start of the time range. Accepts relative durations (`1h`, `30m`, `7d`) or absolute date strings |
80
+ | **End** | End of the time range. Defaults to **Now** |
81
+ | **Output Path** | Where in the output message to place each log line object. Defaults to `msg.payload` |
82
+ | **Batch Mode** | When enabled, all results are collected into a single array message. When disabled (default), one message is emitted per log line |
83
+
84
+ #### Query editor
85
+
86
+ The query field uses a Monaco editor with a custom LogQL language definition:
87
+ - Syntax highlighting for stream selectors `{app="nodered"}`, pipeline stages, metric functions, and aggregation operators
88
+ - Snippet completions for all major LogQL constructs ( trigger with `Ctrl+Space`)
89
+ - Auto-closing brackets and quotes
90
+
91
+ #### Time range
92
+
93
+ The **Start** and **End** fields accept:
94
+ - **Relative** - `1h`, `30m`, `7d`, `2w` (subtracted from now at query time)
95
+ - **Date/Time** - `2024-01-01T00:00:00Z` or any parseable date string
96
+
97
+ #### Output format
98
+
99
+ Each emitted message has the output path set to:
100
+ ```json
101
+ {
102
+ "timestamp": "2024-01-01T00:00:00.000Z",
103
+ "line": "the log message text",
104
+ "labels": { "app": "nodered", "level": "error" }
105
+ }
106
+ ```
107
+
108
+ In **Batch Mode**, a single message is emitted with the output path set to an array of the above objects.
109
+
110
+ Results are capped at **1 000 log lines** or **10 MB** of response data, whichever is reached first.
111
+
112
+ #### Message overrides
113
+
114
+ | Property | Description |
115
+ |----------|-------------|
116
+ | `msg.query` | Overrides the configured LogQL query |
117
+ | `msg.start` | Overrides the configured start time |
118
+ | `msg.end` | Overrides the configured end time |
119
+
120
+ ---
42
121
 
43
- #### Example
122
+ ## Example
44
123
 
45
- A typical setup for a single-tenant Loki instance running on the same Docker network:
124
+ A simple flow that queries Loki on demand and outputs results to the debug panel:
46
125
 
47
- - **Host:** `loki`
48
- - **Port:** `3100`
49
- - **Tenant ID:** _(blank)_
50
- - **Level:** `Info`
51
- - **Template:** `message:{{msg}}`
126
+ ![Example flow](documentation/example01.png)
52
127
 
53
- For multi-tenant deployments, set the **Tenant ID** to match your Loki organisation ID. The value is sent as the `X-Scope-OrgID` HTTP header on every push request.
128
+ A **Request** trigger fires the **Loki Query** node, which runs the configured LogQL query and passes each matching log line downstream to **debug**.
54
129
 
55
130
  ---
56
131
 
57
132
  ## Prerequisites
58
133
 
59
134
  - Node.js 18+
60
- - Node-RED 3+
135
+ - Node-RED 4+
61
136
  - A running [Grafana Loki](https://grafana.com/oss/loki/) instance reachable from your Node-RED host
62
137
 
63
138
  ---
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
4
+ const LokiService_1 = require("./loki/service/LokiService");
5
+ const LokiServiceConfigNode_1 = require("./loki/node/LokiServiceConfigNode");
4
6
  const LokiLoggerConfigNode_1 = require("./loki/node/LokiLoggerConfigNode");
7
+ const LokiQueryNode_1 = require("./loki/node/LokiQueryNode");
5
8
  new node_red_plugincore_1.NodeGenerator("./src/loki/")
9
+ .registerService(LokiService_1.LokiService)
10
+ .registerNode(LokiServiceConfigNode_1.LokiServiceConfigNode)
6
11
  .registerNode(LokiLoggerConfigNode_1.LokiLoggerConfigNode)
12
+ .registerNode(LokiQueryNode_1.LokiQueryNode)
7
13
  .generate("./build/Nodes", "./build/Plugins");
8
14
  process.exit(0);