fluent-plugin-oceanbase-logs 0.1.0 → 0.1.3
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.
- checksums.yaml +4 -4
- data/LICENSE +201 -0
- data/README.md +107 -0
- data/lib/fluent/plugin/in_oceanbase_logs.rb +43 -49
- data/lib/fluent/plugin/oceanbase/logs/version.rb +1 -1
- metadata +9 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff677af2c1882b27e86cde4cbfef8ef79039f45eae20e2a7c8eebd4c2fdbd98e
|
|
4
|
+
data.tar.gz: 2fbe0571f3c1e1b840ab6714faff44e5a7396cad011c4845fb710964db9a490b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 380099690cb075af74c720a6eb147fdb5a1234b428bac1d54e1ea3a36d191f2b47b2a7962ed97ee7f5f2c9f576aad55a4cf025bba39bd8152747fdc6439242bf
|
|
7
|
+
data.tar.gz: 36cd5b13ca5fd22159451bc2c15c45c7861ad1122a62d9e95a4184c2e5e0a5f49c08183609e7767125d65330b69adf506060b9c59b228f785b641c56c41add20
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# fluent-plugin-oceanbase-logs
|
|
2
|
+
|
|
3
|
+
Fluentd **input** plugin: periodically pulls SQL diagnostics from [OceanBase Cloud](https://www.oceanbase.com/) . Each event is **one execution sample**
|
|
4
|
+
|
|
5
|
+
| `log_type` | API | Meaning |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `slow_sql` (default) | `…/slowSql` + per-`sqlId` samples | Slow SQL |
|
|
8
|
+
| `top_sql` | `…/topSql` + samples | Top SQL |
|
|
9
|
+
|
|
10
|
+
Every record includes **`ob_log_type`** (`slow_sql` or `top_sql`). With `include_metadata true` (default), records also get `ob_instance_id`, `ob_tenant_id`, and the query time window.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
| Gem | Fluentd | Ruby |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| >= 0.1.2 | >= 1.8.0 | >= 2.4 |
|
|
17
|
+
|
|
18
|
+
For **Grafana Loki** output you additionally need [fluent-plugin-grafana-loki](https://github.com/grafana/fluent-plugin-grafana-loki).
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
gem install fluent-plugin-oceanbase-logs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Preparation
|
|
27
|
+
|
|
28
|
+
1. Create an AccessKey in [OceanBase Cloud — AccessKey](https://console-cn.oceanbase.com/account/accessKey).
|
|
29
|
+
2. In the console, copy **Instance ID** and **Tenant ID**
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
### Environment variables
|
|
35
|
+
|
|
36
|
+
Typical pattern in Fluentd:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
access_key_id "#{ENV['OCEANBASE_ACCESS_KEY_ID']}"
|
|
40
|
+
access_key_secret "#{ENV['OCEANBASE_ACCESS_KEY_SECRET']}"
|
|
41
|
+
instance_id "#{ENV['OCEANBASE_INSTANCE_ID']}"
|
|
42
|
+
tenant_id "#{ENV['OCEANBASE_TENANT_ID']}"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Optional: `OCEANBASE_ENDPOINT`, `OCEANBASE_FETCH_INTERVAL`, `OCEANBASE_LOOKBACK_SECONDS`, `OCEANBASE_DB_NAME`, `OCEANBASE_SEARCH_KEYWORD`, `OCEANBASE_PROJECT_ID` — see `.env.example` and the Docker table below.
|
|
46
|
+
|
|
47
|
+
### Example: Slow SQL → JSON file
|
|
48
|
+
|
|
49
|
+
Full sample: [`example/fluentd.conf`](example/fluentd.conf).
|
|
50
|
+
|
|
51
|
+
```conf
|
|
52
|
+
<source>
|
|
53
|
+
@type oceanbase_logs
|
|
54
|
+
tag oceanbase.slow_sql
|
|
55
|
+
log_type slow_sql
|
|
56
|
+
access_key_id "#{ENV['OCEANBASE_ACCESS_KEY_ID']}"
|
|
57
|
+
access_key_secret "#{ENV['OCEANBASE_ACCESS_KEY_SECRET']}"
|
|
58
|
+
instance_id "#{ENV['OCEANBASE_INSTANCE_ID']}"
|
|
59
|
+
tenant_id "#{ENV['OCEANBASE_TENANT_ID']}"
|
|
60
|
+
endpoint api-cloud-cn.oceanbase.com
|
|
61
|
+
fetch_interval 60
|
|
62
|
+
lookback_seconds 600
|
|
63
|
+
deduplicate true
|
|
64
|
+
include_metadata true
|
|
65
|
+
<storage>
|
|
66
|
+
@type local
|
|
67
|
+
persistent true
|
|
68
|
+
path /var/log/fluentd/slow_sql_seen
|
|
69
|
+
</storage>
|
|
70
|
+
</source>
|
|
71
|
+
|
|
72
|
+
<match oceanbase.slow_sql>
|
|
73
|
+
@type file
|
|
74
|
+
path /var/log/fluentd/slow_sql
|
|
75
|
+
append true
|
|
76
|
+
<format>
|
|
77
|
+
@type json
|
|
78
|
+
</format>
|
|
79
|
+
</match>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Example: Loki + Docker Compose
|
|
83
|
+
|
|
84
|
+
Ready-made stack (Loki, Fluentd, Grafana) and a **slow_sql + top_sql**:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cp .env.example .env # fill in secrets
|
|
88
|
+
cd example/oceanbase2loki-docker && docker compose up -d
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Compose-related environment** (host `.env` or exports):
|
|
92
|
+
|
|
93
|
+
| Variable | Required | Default |
|
|
94
|
+
| --- | --- | --- |
|
|
95
|
+
| `LOKI_URL` | no | `http://loki:3100` |
|
|
96
|
+
| `OCEANBASE_ACCESS_KEY_ID` | **yes** | — |
|
|
97
|
+
| `OCEANBASE_ACCESS_KEY_SECRET` | **yes** | — |
|
|
98
|
+
| `OCEANBASE_INSTANCE_ID` | **yes** | — |
|
|
99
|
+
| `OCEANBASE_TENANT_ID` | **yes** | — |
|
|
100
|
+
| `OCEANBASE_ENDPOINT` | no | `api-cloud-cn.oceanbase.com` |
|
|
101
|
+
| `OCEANBASE_FETCH_INTERVAL` | no | `60` |
|
|
102
|
+
| `OCEANBASE_LOOKBACK_SECONDS` | no | `600` |
|
|
103
|
+
| `OCEANBASE_DB_NAME` | no | `test` |
|
|
104
|
+
| `OCEANBASE_SEARCH_KEYWORD` | no | `SELECT` |
|
|
105
|
+
| `OCEANBASE_PROJECT_ID` | no | *(unset)* |
|
|
106
|
+
|
|
107
|
+
> The bundled `fluentd-to-loki.conf` uses `record.dig` and avoids `";` / `]` patterns that break Fluentd’s config parser and `record_transformer` — keep that style if you edit it.
|
|
@@ -22,8 +22,6 @@ module Fluent::Plugin
|
|
|
22
22
|
|
|
23
23
|
config_param :log_type, :enum, list: LOG_TYPE_PATHS.keys.map(&:to_sym), default: :slow_sql,
|
|
24
24
|
desc: "Type of SQL diagnostics to collect: slow_sql or top_sql."
|
|
25
|
-
config_param :fetch_samples, :bool, default: false,
|
|
26
|
-
desc: "When true, fetch per-execution sample details for each SQL (each execution = one event)."
|
|
27
25
|
|
|
28
26
|
config_param :access_key_id, :string, secret: true,
|
|
29
27
|
desc: "OceanBase Cloud AccessKey ID."
|
|
@@ -62,7 +60,7 @@ module Fluent::Plugin
|
|
|
62
60
|
desc: "Verify SSL certificates."
|
|
63
61
|
|
|
64
62
|
config_param :deduplicate, :bool, default: true,
|
|
65
|
-
desc: "Enable deduplication."
|
|
63
|
+
desc: "Enable deduplication (by traceId)."
|
|
66
64
|
config_param :include_metadata, :bool, default: true,
|
|
67
65
|
desc: "Attach instance_id / tenant_id / log_type to each record."
|
|
68
66
|
|
|
@@ -76,6 +74,21 @@ module Fluent::Plugin
|
|
|
76
74
|
super
|
|
77
75
|
@endpoint = @endpoint.to_s.strip
|
|
78
76
|
@endpoint = 'api-cloud-cn.oceanbase.com' if @endpoint.empty?
|
|
77
|
+
|
|
78
|
+
%i[@access_key_id @access_key_secret @instance_id @tenant_id].each do |iv|
|
|
79
|
+
v = instance_variable_get(iv)
|
|
80
|
+
next unless v.is_a?(String)
|
|
81
|
+
instance_variable_set(iv, v.strip)
|
|
82
|
+
end
|
|
83
|
+
raise Fluent::ConfigError, 'access_key_id is required and cannot be empty' if @access_key_id.empty?
|
|
84
|
+
raise Fluent::ConfigError, 'access_key_secret is required and cannot be empty' if @access_key_secret.empty?
|
|
85
|
+
raise Fluent::ConfigError, 'instance_id is required and cannot be empty (e.g. set OCEANBASE_INSTANCE_ID)' if @instance_id.empty?
|
|
86
|
+
raise Fluent::ConfigError, 'tenant_id is required and cannot be empty (e.g. set OCEANBASE_TENANT_ID)' if @tenant_id.empty?
|
|
87
|
+
|
|
88
|
+
%i[@db_name @search_keyword @node_ip @filter_condition @project_id].each do |iv|
|
|
89
|
+
v = instance_variable_get(iv)
|
|
90
|
+
instance_variable_set(iv, nil) if v.is_a?(String) && v.strip.empty?
|
|
91
|
+
end
|
|
79
92
|
@api_path_segment = LOG_TYPE_PATHS[@log_type.to_s]
|
|
80
93
|
if @deduplicate
|
|
81
94
|
@seen_storage = storage_create(
|
|
@@ -123,43 +136,10 @@ module Fluent::Plugin
|
|
|
123
136
|
now = Time.now.utc
|
|
124
137
|
start_time = (now - @lookback_seconds).strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
125
138
|
end_time = now.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
126
|
-
|
|
127
|
-
if @fetch_samples
|
|
128
|
-
fetch_and_emit_samples(start_time, end_time)
|
|
129
|
-
else
|
|
130
|
-
fetch_and_emit_list(start_time, end_time)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# ---- Mode 1: emit aggregated list (one record per sqlId) ----
|
|
135
|
-
def fetch_and_emit_list(start_time, end_time)
|
|
136
|
-
response = call_list_api(start_time, end_time)
|
|
137
|
-
return unless response
|
|
138
|
-
|
|
139
|
-
records = extract_records(response)
|
|
140
|
-
return if records.nil? || records.empty?
|
|
141
|
-
|
|
142
|
-
es = Fluent::MultiEventStream.new
|
|
143
|
-
|
|
144
|
-
records.each do |record|
|
|
145
|
-
sql_id = record['sqlId']
|
|
146
|
-
next if sql_id.nil? || sql_id.empty?
|
|
147
|
-
|
|
148
|
-
if @deduplicate
|
|
149
|
-
dedup_key = :"list_#{sql_id}_#{start_time}"
|
|
150
|
-
next if @seen_storage.get(dedup_key)
|
|
151
|
-
@seen_storage.put(dedup_key, Time.now.to_i.to_s)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
record = attach_metadata(record, start_time, end_time) if @include_metadata
|
|
155
|
-
es.add(Fluent::EventTime.now, record)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
router.emit_stream(@tag, es) unless es.empty?
|
|
159
|
-
log.info "Emitted #{es.size} #{@log_type} events (#{start_time} ~ #{end_time})" if es.size > 0
|
|
139
|
+
fetch_and_emit_samples(start_time, end_time)
|
|
160
140
|
end
|
|
161
141
|
|
|
162
|
-
#
|
|
142
|
+
# Fetch list then per-execution samples (one record per trace)
|
|
163
143
|
def fetch_and_emit_samples(start_time, end_time)
|
|
164
144
|
list_response = call_list_api(start_time, end_time)
|
|
165
145
|
return unless list_response
|
|
@@ -188,6 +168,7 @@ module Fluent::Plugin
|
|
|
188
168
|
@seen_storage.put(dedup_key, Time.now.to_i.to_s)
|
|
189
169
|
end
|
|
190
170
|
|
|
171
|
+
sample['ob_log_type'] = @log_type.to_s
|
|
191
172
|
sample = attach_metadata(sample, start_time, end_time) if @include_metadata
|
|
192
173
|
|
|
193
174
|
event_time = if sample['requestTime']
|
|
@@ -229,23 +210,27 @@ module Fluent::Plugin
|
|
|
229
210
|
record.merge(
|
|
230
211
|
'ob_instance_id' => @instance_id,
|
|
231
212
|
'ob_tenant_id' => @tenant_id,
|
|
232
|
-
'ob_log_type' => @log_type.to_s,
|
|
233
213
|
'query_start_time' => start_time,
|
|
234
214
|
'query_end_time' => end_time
|
|
235
215
|
)
|
|
236
216
|
end
|
|
237
217
|
|
|
238
218
|
def extract_records(response)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
219
|
+
data = response['data']
|
|
220
|
+
return [] if data.nil?
|
|
221
|
+
|
|
222
|
+
if data.is_a?(Hash)
|
|
223
|
+
list = data['dataList']
|
|
224
|
+
return list if list.is_a?(Array)
|
|
225
|
+
return [] if list.nil? || list == []
|
|
226
|
+
elsif data.is_a?(Array)
|
|
227
|
+
return data
|
|
248
228
|
end
|
|
229
|
+
|
|
230
|
+
log.warn "Unexpected API response structure",
|
|
231
|
+
keys: response.keys, data_class: data.class.name,
|
|
232
|
+
data_keys: (data.respond_to?(:keys) ? data.keys : nil)
|
|
233
|
+
[]
|
|
249
234
|
end
|
|
250
235
|
|
|
251
236
|
# ---- API calls ----
|
|
@@ -277,7 +262,16 @@ module Fluent::Plugin
|
|
|
277
262
|
end
|
|
278
263
|
|
|
279
264
|
unless resp && resp.code.to_i == 200
|
|
280
|
-
|
|
265
|
+
code = resp&.code
|
|
266
|
+
raw = resp&.body.to_s
|
|
267
|
+
detail = nil
|
|
268
|
+
begin
|
|
269
|
+
j = JSON.parse(raw)
|
|
270
|
+
detail = j['message'] || j['errorMessage'] || j['msg']
|
|
271
|
+
rescue JSON::ParserError
|
|
272
|
+
end
|
|
273
|
+
log.error "OceanBase API HTTP #{code}",
|
|
274
|
+
message: detail, body: (raw.bytesize > 512 ? raw.byteslice(0, 512) + '...' : raw), path: path
|
|
281
275
|
return nil
|
|
282
276
|
end
|
|
283
277
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-oceanbase-logs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OceanBase Integrations
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: fluentd
|
|
@@ -66,20 +65,6 @@ dependencies:
|
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '3.0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: test-unit-rr
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
68
|
- !ruby/object:Gem::Dependency
|
|
84
69
|
name: webmock
|
|
85
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,21 +79,22 @@ dependencies:
|
|
|
94
79
|
- - "~>"
|
|
95
80
|
- !ruby/object:Gem::Version
|
|
96
81
|
version: '3.0'
|
|
97
|
-
description:
|
|
98
|
-
|
|
82
|
+
description: Fetches Slow SQL and Top SQL per-execution samples from OceanBase Cloud
|
|
83
|
+
and emits them as Fluentd events (one record per trace, dedup by traceId).
|
|
99
84
|
email:
|
|
100
85
|
- integrations@example.com
|
|
101
86
|
executables: []
|
|
102
87
|
extensions: []
|
|
103
88
|
extra_rdoc_files: []
|
|
104
89
|
files:
|
|
90
|
+
- LICENSE
|
|
91
|
+
- README.md
|
|
105
92
|
- lib/fluent/plugin/in_oceanbase_logs.rb
|
|
106
93
|
- lib/fluent/plugin/oceanbase/logs/version.rb
|
|
107
|
-
homepage: https://github.com/
|
|
94
|
+
homepage: https://github.com/sc-source/fluent-plugin-oceanbase-logs
|
|
108
95
|
licenses:
|
|
109
|
-
-
|
|
96
|
+
- Apache-2.0
|
|
110
97
|
metadata: {}
|
|
111
|
-
post_install_message:
|
|
112
98
|
rdoc_options: []
|
|
113
99
|
require_paths:
|
|
114
100
|
- lib
|
|
@@ -123,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
109
|
- !ruby/object:Gem::Version
|
|
124
110
|
version: '0'
|
|
125
111
|
requirements: []
|
|
126
|
-
rubygems_version: 3.
|
|
127
|
-
signing_key:
|
|
112
|
+
rubygems_version: 3.6.9
|
|
128
113
|
specification_version: 4
|
|
129
114
|
summary: Fluentd input plugin for OceanBase Cloud Logs
|
|
130
115
|
test_files: []
|