mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-06 08:09:24 +00:00
### **PR Type**
Enhancement, Documentation
___
### **Description**
- Add built-in regex patterns fetch API
- Introduce GitHub data service with caching
- Handle duplicate pattern names gracefully
- UI to browse and import built-ins
___
### Diagram Walkthrough
```mermaid
flowchart LR
cfg["Config: regex_patterns_source_url"] -- used by --> ghsvc["GitHubDataService"]
ghsvc -- fetch_json/cache --> adapter["PyWhatAdapter.fetch_built_in_patterns"]
adapter -- returns --> api["GET /api/{org}/re_patterns/built-in"]
api -- consumed by --> websvc["web regexPatterns.getBuiltInPatterns()"]
websvc -- powers --> ui["BuiltInPatternsTab.vue"]
ui -- import selected --> importFlow["ImportRegexPattern.vue"]
importFlow -- create --> dbsvc["db::re_pattern::add (duplicate-safe)"]
```
<details> <summary><h3> File Walkthrough</h3></summary>
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Configuration
changes</strong></td><td><details><summary>3 files</summary><table>
<tr>
<td><strong>config.rs</strong><dd><code>Add source URL for built-in
regex patterns</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-9aeee4a74c0520daa40f9b81c7016f5b6b3254375b968dd7598e745630980d62">+6/-0</a>
</td>
</tr>
<tr>
<td><strong>mod.rs</strong><dd><code>Register built-in patterns and
reorder routes</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-02556e3f515441b5d2b6bbea7829df488beac03c4cc41309a6638ae3c0e0aec6">+2/-2</a>
</td>
</tr>
<tr>
<td><strong>mod.rs</strong><dd><code>Export github service
module</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-1b15316505c31acccb26ba66d920fdb0894567d08d2bf1e3457716d128a67b83">+1/-0</a>
</td>
</tr>
</table></details></td></tr><tr><td><strong>Enhancement</strong></td><td><details><summary>10
files</summary><table>
<tr>
<td><strong>mod.rs</strong><dd><code>New endpoint to fetch built-in
patterns and improved save response</code></dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-27d37a8738de89c81b540daa978e684caf2cf28803e1208d90cb4d42528ed28b">+103/-4</a>
</td>
</tr>
<tr>
<td><strong>re_pattern.rs</strong><dd><code>Add duplicate-safe creation
with auto-suffix names</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-0cb2bf6d550d07b66db7e325c6d44c6a598f2ac8e315bf9e168f4a1d9d6e745d">+47/-17</a>
</td>
</tr>
<tr>
<td><strong>mod.rs</strong><dd><code>Add adapters module export for
pattern formats</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-3a24aa67600735383b8b94a435974dc9b2677b6bb3f5fb502fb7d617af8bdec0">+20/-0</a>
</td>
</tr>
<tr>
<td><strong>pywhat.rs</strong><dd><code>Implement generic pattern
adapter and filters</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-9ecd12df46c16fca3984bc46122a26568db208839f904e0b216185df43e13e08">+264/-0</a>
</td>
</tr>
<tr>
<td><strong>cache.rs</strong><dd><code>Introduce in-memory cache with
eviction and stats</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-09bcde8f6abf0cbf88628e1e6e7290e9fde7655c7903569902bf28742e958326">+130/-0</a>
</td>
</tr>
<tr>
<td><strong>client.rs</strong><dd><code>Add GitHub data client with
retry and caching</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-20a335d645493f38003faf7303124a6e85c3c2dfd765e148811aebee1ebfd890">+246/-0</a>
</td>
</tr>
<tr>
<td><strong>types.rs</strong><dd><code>Define service config, errors,
and cache types</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-35becfa9ecfcd7711485f645f09a3fe2429231d0c351f0374f20f121225fbaae">+119/-0</a>
</td>
</tr>
<tr>
<td><strong>regex_pattern.ts</strong><dd><code>Add client method to
fetch built-in patterns</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-2a0b0828141d39ab0385e0941314ead1cdd2ec3ec7b3baf5fd0c42f8f010728a">+18/-0</a>
</td>
</tr>
<tr>
<td><strong>BuiltInPatternsTab.vue</strong><dd><code>New UI to search,
filter, preview, import patterns</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-0747e124429b322a69f6ae0117ec635044059bd48fb03e90b2328aa1f79b8b28">+451/-0</a>
</td>
</tr>
<tr>
<td><strong>ImportRegexPattern.vue</strong><dd><code>Integrate built-in
tab and import flow updates</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-e8e1bcb5a02311504d7d571090eab27a270aaa71cae185ad2703023e2e70a31e">+94/-36</a>
</td>
</tr>
</table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>3
files</summary><table>
<tr>
<td><strong>mod.rs</strong><dd><code>Expose GitHub service modules and
types</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-90a3518cd7c8b2a8b2a2093535b64a3dc4e6ffead41e5dca7901521e0c0ba910">+39/-0</a>
</td>
</tr>
<tr>
<td><strong>.env.example</strong><dd><code>Document regex patterns
source URL env var</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-a3046da0d15a27e89f2afe639b25748a7ad4d9290af3e7b1b6c1a5533c8f0a8c">+6/-1</a>
</td>
</tr>
<tr>
<td><strong>en.json</strong><dd><code>Add i18n strings for built-in
patterns UI</code>
</dd></td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8827/files#diff-892aa3d75ab6e129ef9116aa21bec1b9a15ba69ce5366d2a19128078c690d824">+17/-1</a>
</td>
</tr>
</table></details></td></tr></tr></tbody></table>
</details>
___
---------
Co-authored-by: sai nikhil kethe <nikhil@openobserve.ai>
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
// Copyright 2023 OpenObserve Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import http from "./http";
|
|
type PatternPayload = {
|
|
name: string;
|
|
pattern: string;
|
|
description: string;
|
|
};
|
|
const regexPatterns = {
|
|
list: (
|
|
org_identifier: string
|
|
) => {
|
|
return http().get(
|
|
`/api/${org_identifier}/re_patterns`
|
|
);
|
|
},
|
|
create: (
|
|
org_identifier: string,
|
|
payload: PatternPayload
|
|
) => {
|
|
return http().post(
|
|
`/api/${org_identifier}/re_patterns`,
|
|
payload
|
|
);
|
|
},
|
|
update: (
|
|
org_identifier: string,
|
|
id: string,
|
|
payload: any
|
|
) => {
|
|
return http().put(
|
|
`/api/${org_identifier}/re_patterns/${id}`,
|
|
payload
|
|
);
|
|
},
|
|
delete: (
|
|
org_identifier: string,
|
|
id: string,
|
|
) => {
|
|
return http().delete(
|
|
`/api/${org_identifier}/re_patterns/${id}`
|
|
);
|
|
},
|
|
test: (
|
|
org_identifier: string,
|
|
pattern: string,
|
|
test_records: Array<string>,
|
|
policy?: string,
|
|
) => {
|
|
const payload: any = { pattern, test_records };
|
|
if (policy) {
|
|
payload.policy = policy;
|
|
}
|
|
return http().post(`/api/${org_identifier}/re_patterns/test`, payload);
|
|
},
|
|
getBuiltInPatterns: (
|
|
org_identifier: string,
|
|
params?: {
|
|
search?: string;
|
|
tags?: string[];
|
|
}
|
|
) => {
|
|
const queryParams = new URLSearchParams();
|
|
if (params?.search) queryParams.append('search', params.search);
|
|
if (params?.tags) params.tags.forEach(tag => queryParams.append('tags', tag));
|
|
|
|
const queryString = queryParams.toString();
|
|
const url = `/api/${org_identifier}/re_patterns/built-in${queryString ? '?' + queryString : ''}`;
|
|
|
|
return http().get(url);
|
|
}
|
|
};
|
|
|
|
export default regexPatterns;
|