Skip to content

Commit 44de05d

Browse files
feat(gateway): Solace Log plugin (#2730)
* bootstrap solace log plugin * Apply suggestions from code review Co-authored-by: Zachary Hu <[email protected]> * add reference table --------- Co-authored-by: Zachary Hu <[email protected]>
1 parent 7bba93f commit 44de05d

File tree

13 files changed

+151
-21
lines changed

13 files changed

+151
-21
lines changed

app/_includes/plugins/logging/log-custom-fields-by-lua.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
The `custom_fields_by_lua` configuration allows for the dynamic modification of
1+
{% assign custom_fields_by_lua = include.custom_fields_by_lua %}
2+
{% assign custom_fields_by_lua_slug = include.custom_fields_by_lua_slug %}
3+
4+
The [`custom_fields_by_lua`](./reference/#schema--{{custom_fields_by_lua_slug}}) configuration allows for the dynamic modification of
25
log fields using Lua code. Below is a snippet of an example configuration that
36
removes the `route` field from the logs:
47

58
```sh
69
curl -i -X POST http://localhost:8001/plugins \
7-
...
8-
--data config.custom_fields_by_lua.route="return nil"
10+
--data config.name={{include.slug}} \
11+
--data {{custom_fields_by_lua}}.route="return nil"
912
```
1013

1114
Similarly, new fields can be added:
1215

1316
```sh
1417
curl -i -X POST http://localhost:8001/plugins \
15-
...
16-
--data config.custom_fields_by_lua.header="return kong.request.get_header('h1')"
18+
--data config.name={{include.slug}} \
19+
--data {{custom_fields_by_lua}}.header="return kong.request.get_header('h1')"
1720
```
1821

19-
### Special characters {% new_in 3.10 %}
22+
### Special characters {% unless page.name =="Solace Log"%}{% new_in 3.10 %}{% endunless %}
2023

2124
Dot characters (`.`) in the field key create nested fields. You can use a backslash `\` to escape a dot if you want to keep it in the field name.
2225

23-
For example, if you configure a field in the File Log plugin with both a regular dot and an escaped dot:
26+
For example, if you configure a field with both a regular dot and an escaped dot:
2427

2528
```sh
2629
curl -i -X POST http://localhost:8001/plugins/ \
2730
...
28-
--data config.name=file-log \
29-
--data config.custom_fields_by_lua[my_file.log\.field]="return foo"
31+
--data config.name={{page.name}} \
32+
--data {{custom_fields_by_lua}}.[my_entry.log\.field]="return foo"
3033
```
3134
The field will look like this in the log:
3235
```sh
33-
"my_file": {
36+
"my_entry": {
3437
"log.field": "foo"
3538
}
3639
```
@@ -39,19 +42,19 @@ The field will look like this in the log:
3942

4043
All logging plugins use the same table for logging.
4144
If you set `custom_fields_by_lua` in one plugin, all logging plugins that execute after that plugin will also use the same configuration.
42-
For example, if you configure fields via `custom_fields_by_lua` in [File Log](/plugins/file-log/), those same fields will appear in [Kafka Log](/plugins/kafka-log/), since File Log executes first.
45+
For example, if you configure fields via `custom_fields_by_lua` in {% unless page.name =="Syslog" %}{{page.name}}{% else %}[File Log](/plugins/file-log/){% endunless %}, those same fields will appear in [Syslog](/plugins/syslog/), since {{page.name}} executes first.
4346

4447
If you want all logging plugins to use the same configuration, we recommend using the [Pre-function](/plugins/pre-function/) plugin to call [kong.log.set_serialize_value](/gateway/pdk/reference/kong.log/#kong-log-set-serialize-value-key-value-options) so that the function is applied predictably and is easier to manage.
4548

4649
If you **don't** want all logging plugins to use the same configuration, you need to manually disable the relevant fields in each plugin.
4750

48-
For example, if you configure a field in File Log that you don't want appearing in Kafka Log, set that field to `return nil` in the Kafka Log plugin:
51+
For example, if you configure a field in File Log that you don't want appearing in {{include.name}}, set that field to `return nil` in the {{include.name}} plugin:
4952

5053
```sh
5154
curl -i -X POST http://localhost:8001/plugins/ \
5255
...
53-
--data config.name=kafka-log \
54-
--data config.custom_fields_by_lua.my_file_log_field="return nil"
56+
--data config.name={{include.slug}} \
57+
--data {{custom_fields_by_lua}}.my_file_log_field="return nil"
5558
```
5659

5760
See the [plugin execution order reference](/gateway/entities/plugin/#plugin-contexts) for more details on plugin ordering.

app/_kong_plugins/file-log/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ to physical files on slow (spinning) disks.
6767

6868
## Custom fields by Lua
6969

70-
{% include /plugins/logging/log-custom-fields-by-lua.md %}
70+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.custom_fields_by_lua' custom_fields_by_lua_slug='config-custom-fields-by-lua' name=page.name slug=page.slug %}

app/_kong_plugins/http-log/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ In contrast to other plugins that use queues, all HTTP Log plugin instances that
8585

8686
## Custom fields by Lua
8787

88-
{% include /plugins/logging/log-custom-fields-by-lua.md %}
88+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.custom_fields_by_lua' custom_fields_by_lua_slug='config-custom-fields-by-lua' name=page.name slug=page.slug %}

app/_kong_plugins/kafka-log/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When encoding request bodies, several things happen:
7272

7373
## Custom fields by Lua
7474

75-
{% include /plugins/logging/log-custom-fields-by-lua.md %}
75+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.custom_fields_by_lua' custom_fields_by_lua_slug='config-custom-fields-by-lua' name=page.name slug=page.slug %}
7676

7777
## Schema registry support {% new_in 3.11 %}
7878

app/_kong_plugins/loggly/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ Log request and response data over UDP to [Loggly](https://www.loggly.com).
5555

5656
## Custom fields by Lua
5757

58-
{% include /plugins/logging/log-custom-fields-by-lua.md %}
58+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.custom_fields_by_lua' custom_fields_by_lua_slug='config-custom-fields-by-lua' name=page.name slug=page.slug %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"3.12.0.0": [
3+
{
4+
"message": "Added Solace Log plugin.",
5+
"type": "feature",
6+
"scope": "Plugin"
7+
}
8+
]
9+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
description: 'Set up the Solace logging plugin to send logs to a Solace message broker.'
2+
3+
title: 'Enable Solace Logging'
4+
5+
weight: 900
6+
7+
requirements:
8+
- "[Solace installed](https://docs.solace.com/API/API-Developer-Guide/Installation.htm) and running"
9+
10+
config:
11+
session:
12+
host: "tcp://192.168.88.20:55555"
13+
vpn_name: "default"
14+
authentication:
15+
scheme: "BASIC"
16+
username: "admin"
17+
password: "admin"
18+
message:
19+
destinations:
20+
- name: "test"
21+
type: "QUEUE"
22+
delivery_mode: "PERSISTENT"
23+
custom_fields_by_lua:
24+
broker: 'return "solace"'
25+
26+
tools:
27+
- deck
28+
- admin-api
29+
- konnect-api
30+
- kic
31+
- terraform
32+
33+
min_version:
34+
gateway: '3.12'
35+

app/_kong_plugins/solace-log/index.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: 'Solace Log'
3+
name: 'Solace Log'
4+
5+
content_type: plugin
6+
7+
publisher: kong-inc
8+
tier: enterprise
9+
description: 'Publish request and response logs to a Solace endpoint or topic'
10+
11+
products:
12+
- gateway
13+
14+
works_on:
15+
- on-prem
16+
- konnect
17+
18+
min_version:
19+
gateway: '3.12'
20+
21+
topologies:
22+
on_prem:
23+
- hybrid
24+
- db-less
25+
- traditional
26+
konnect_deployments:
27+
- hybrid
28+
- cloud-gateways
29+
- serverless
30+
31+
tags:
32+
- logging
33+
- events
34+
- solace
35+
36+
search_aliases:
37+
- solace-log
38+
- events
39+
- event-gateway
40+
41+
icon: solace-log.png
42+
43+
categories:
44+
- logging
45+
46+
related_resources:
47+
- text: Solace Upstream plugin
48+
url: /plugins/solace-upstream/
49+
- text: Solace Consume plugin
50+
url: /plugins/solace-consume/
51+
- text: Event Gateway
52+
url: /event-gateway/
53+
---
54+
55+
Publish request and response logs in `JSON` format to a [Solace](https://solace.com/) endpoint or topic.
56+
For more information, see [Solace Event Messaging Overview](https://docs.solace.com/Messaging/messaging-overview.htm).
57+
58+
Kong also provides plugins for publishing messages to and consuming messages from Solace:
59+
* [Solace Upstream](/plugins/solace-upstream/)
60+
* [Solace Consume](/plugins/solace-consume/)
61+
62+
## Log format
63+
64+
{% include /plugins/logging/log-format.md %}
65+
66+
### Log format definitions
67+
68+
{% include /plugins/logging/json-object-log.md %}
69+
70+
## Implementation details
71+
72+
This plugin leverages the [log PDK](/gateway/pdk/reference/kong.log/) to collect and [customize](#custom-fields-by-lua) log fields.
73+
74+
The prepared log message is sent to the Solace broker via the official [Solace C API](https://docs.solace.com/API/Messaging-APIs/C-API/c-api-home.htm). The sending job is executed in a background timer context so that it doesn't block client requests.
75+
76+
If the [custom Lua code](#custom-fields-by-lua) associated with the log fields fails to execute, the relevant fields remain untouched.
77+
78+
## Custom fields by Lua
79+
80+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.message.custom_fields_by_lua' custom_fields_by_lua_slug='config-message-custom-fields-by-lua' name=page.name slug=page.slug %}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
content_type: reference
3+
---

app/_kong_plugins/syslog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ logging level severity equal to or lower than the one set in the [`config.log_le
7070
7171
## Custom fields by Lua
7272

73-
{% include /plugins/logging/log-custom-fields-by-lua.md %}
73+
{% include /plugins/logging/log-custom-fields-by-lua.md custom_fields_by_lua='config.custom_fields_by_lua' custom_fields_by_lua_slug='config-custom-fields-by-lua' name=page.name slug=page.slug %}
7474

7575
## Forwarding logs to a remote network host
7676

0 commit comments

Comments
 (0)