@redpanda-data/docs-extensions-and-macros 4.2.5 → 4.4.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.adoc +184 -21
- package/bin/doc-tools.js +328 -0
- package/cli-utils/add-caret-external-links.py +68 -0
- package/cli-utils/beta-from-antora.js +27 -0
- package/cli-utils/generate-cluster-docs.sh +83 -0
- package/cli-utils/install-test-dependencies.sh +158 -0
- package/cli-utils/python-venv.sh +20 -0
- package/cli-utils/start-cluster.sh +53 -0
- package/docker-compose/bootstrap.yml +67 -0
- package/docker-compose/docker-compose.yml +414 -0
- package/docker-compose/generate-profiles.yaml +77 -0
- package/docker-compose/rpk-profile.yaml +24 -0
- package/docker-compose/transactions-schema.json +37 -0
- package/docker-compose/transactions.md +46 -0
- package/docker-compose/transform/README.adoc +73 -0
- package/docker-compose/transform/go.mod +5 -0
- package/docker-compose/transform/go.sum +2 -0
- package/docker-compose/transform/regex.wasm +0 -0
- package/docker-compose/transform/transform.go +122 -0
- package/docker-compose/transform/transform.yaml +33 -0
- package/extension-utils/compute-out.js +38 -0
- package/extension-utils/create-asciidoc-file.js +15 -0
- package/macros/data-template.js +591 -0
- package/package.json +21 -4
- package/tools/docusaurus-to-antora-conversion-scripts/convert-docs.sh +114 -0
- package/tools/docusaurus-to-antora-conversion-scripts/get-file-changes.sh +9 -0
- package/tools/docusaurus-to-antora-conversion-scripts/post-process-asciidoc.js +63 -0
- package/tools/docusaurus-to-antora-conversion-scripts/pre-process-markdown.js +108 -0
- package/tools/fetch-from-github.js +63 -0
- package/tools/gen-rpk-ascii.py +477 -0
- package/tools/get-console-version.js +53 -0
- package/tools/get-redpanda-version.js +53 -0
- package/tools/metrics/metrics.py +199 -0
- package/tools/metrics/requirements.txt +1 -0
- package/tools/property-extractor/Makefile +99 -0
- package/tools/property-extractor/README.adoc +206 -0
- package/tools/property-extractor/definitions.json +245 -0
- package/tools/property-extractor/file_pair.py +7 -0
- package/tools/property-extractor/json-to-asciidoc/generate_docs.py +460 -0
- package/tools/property-extractor/parser.py +224 -0
- package/tools/property-extractor/property_bag.py +4 -0
- package/tools/property-extractor/property_extractor.py +243 -0
- package/tools/property-extractor/requirements.txt +2 -0
- package/tools/property-extractor/tests/transformers_test.py +376 -0
- package/tools/property-extractor/transformers.py +397 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
package main
|
|
2
|
+
// This data transform filters records based on a customizable regex pattern.
|
|
3
|
+
// If a record's key or value
|
|
4
|
+
// (determined by an environment variable) matches the specified regex,
|
|
5
|
+
// the record is forwarded to the output.
|
|
6
|
+
// Otherwise, it is dropped.
|
|
7
|
+
//
|
|
8
|
+
// Usage:
|
|
9
|
+
// 1. Provide the following environment variables in your Docker or configuration setup:
|
|
10
|
+
// - PATTERN : (required) a regular expression that determines what you want to match.
|
|
11
|
+
// - MATCH_VALUE : (optional) a boolean to decide whether to check the record value. If false,
|
|
12
|
+
// the record key is checked. Default is false.
|
|
13
|
+
//
|
|
14
|
+
// Example environment variables:
|
|
15
|
+
// PATTERN=".*\\.edu$"
|
|
16
|
+
// MATCH_VALUE="true"
|
|
17
|
+
//
|
|
18
|
+
// Logs:
|
|
19
|
+
// This transform logs information about each record and whether it matched.
|
|
20
|
+
// The logs appear in the _redpanda.transform_logs topic, so you can debug how your records are being processed.
|
|
21
|
+
//
|
|
22
|
+
// Build instructions:
|
|
23
|
+
// go mod tidy
|
|
24
|
+
// rpk transform build
|
|
25
|
+
//
|
|
26
|
+
// For more details on building transforms with the Redpanda SDK, see:
|
|
27
|
+
// https://docs.redpanda.com/current/develop/data-transforms
|
|
28
|
+
//
|
|
29
|
+
|
|
30
|
+
import (
|
|
31
|
+
"log"
|
|
32
|
+
"os"
|
|
33
|
+
"regexp"
|
|
34
|
+
"strings"
|
|
35
|
+
|
|
36
|
+
"github.com/redpanda-data/redpanda/src/transform-sdk/go/transform"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
var (
|
|
40
|
+
re *regexp.Regexp
|
|
41
|
+
checkValue bool
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
func isTrueVar(v string) bool {
|
|
45
|
+
switch strings.ToLower(v) {
|
|
46
|
+
case "yes", "ok", "1", "true":
|
|
47
|
+
return true
|
|
48
|
+
default:
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The main() function runs only once at startup. It performs all initialization steps:
|
|
54
|
+
// - Reads and compiles the regex pattern.
|
|
55
|
+
// - Determines whether to match on the key or value.
|
|
56
|
+
// - Registers the doRegexFilter() function to process records.
|
|
57
|
+
func main() {
|
|
58
|
+
// Set logging preferences, including timestamp and UTC time.
|
|
59
|
+
log.SetPrefix("[regex-transform] ")
|
|
60
|
+
log.SetFlags(log.Ldate | log.Ltime | log.LUTC | log.Lmicroseconds)
|
|
61
|
+
|
|
62
|
+
// Start logging the transformation process
|
|
63
|
+
log.Println("Starting transform...")
|
|
64
|
+
|
|
65
|
+
// Read the PATTERN environment variable to get the regex pattern.
|
|
66
|
+
pattern, ok := os.LookupEnv("PATTERN")
|
|
67
|
+
if !ok {
|
|
68
|
+
log.Fatal("Missing PATTERN environment variable")
|
|
69
|
+
}
|
|
70
|
+
// Log the regex pattern being used.
|
|
71
|
+
log.Printf("Using PATTERN: %q\n", pattern)
|
|
72
|
+
// Compile the regex pattern for later use.
|
|
73
|
+
re = regexp.MustCompile(pattern)
|
|
74
|
+
|
|
75
|
+
// Read the MATCH_VALUE environment variable to determine whether to check the record's value.
|
|
76
|
+
mk, ok := os.LookupEnv("MATCH_VALUE")
|
|
77
|
+
checkValue = ok && isTrueVar(mk)
|
|
78
|
+
log.Printf("MATCH_VALUE set to: %t\n", checkValue)
|
|
79
|
+
|
|
80
|
+
log.Println("Initialization complete, waiting for records...")
|
|
81
|
+
|
|
82
|
+
// Listen for records to be written, calling doRegexFilter() for each record.
|
|
83
|
+
transform.OnRecordWritten(doRegexFilter)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The doRegexFilter() function executes each time a new record is written.
|
|
87
|
+
// It checks whether the record's key or value (based on MATCH_VALUE) matches the compiled regex.
|
|
88
|
+
// If it matches, the record is forwarded, if not, it's dropped.
|
|
89
|
+
func doRegexFilter(e transform.WriteEvent, w transform.RecordWriter) error {
|
|
90
|
+
// This stores the data to be checked (either the key or value).
|
|
91
|
+
var dataToCheck []byte
|
|
92
|
+
|
|
93
|
+
// Depending on the MATCH_VALUE environment variable, decide whether to check the record's key or value.
|
|
94
|
+
if checkValue {
|
|
95
|
+
// Use the value of the record if MATCH_VALUE is true.
|
|
96
|
+
dataToCheck = e.Record().Value
|
|
97
|
+
log.Printf("Checking record value: %s\n", string(dataToCheck))
|
|
98
|
+
} else {
|
|
99
|
+
// Use the key of the record if MATCH_VALUE is false.
|
|
100
|
+
dataToCheck = e.Record().Key
|
|
101
|
+
log.Printf("Checking record key: %s\n", string(dataToCheck))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// If there is no key or value to check, log and skip the record.
|
|
105
|
+
if dataToCheck == nil {
|
|
106
|
+
log.Println("Record has no key/value to check, skipping.")
|
|
107
|
+
return nil
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check if the data matches the regex pattern.
|
|
111
|
+
pass := re.Match(dataToCheck)
|
|
112
|
+
if pass {
|
|
113
|
+
// If the record matches the pattern, log and write the record to the output topic.
|
|
114
|
+
log.Printf("Record matched pattern, passing through. Key: %s, Value: %s\n", string(e.Record().Key), string(e.Record().Value))
|
|
115
|
+
return w.Write(e.Record())
|
|
116
|
+
} else {
|
|
117
|
+
// If the record does not match the pattern, log and drop the record.
|
|
118
|
+
log.Printf("Record did not match pattern, dropping. Key: %s, Value: %s\n", string(e.Record().Key), string(e.Record().Value))
|
|
119
|
+
// Do not write the record if it doesn't match the pattern.
|
|
120
|
+
return nil
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Transform metadata used by the rpk transform build command.
|
|
2
|
+
# This metadata file tells rpk:
|
|
3
|
+
# 1) The transform’s display name, which also becomes the base for the .wasm file name.
|
|
4
|
+
# 2) A brief description of what it does.
|
|
5
|
+
# 3) Defaults for environment variables.
|
|
6
|
+
# 4) Input and output topics (if you want to define them here rather than in the deploy command).
|
|
7
|
+
|
|
8
|
+
# Human-readable name of the transform. rpk transform build uses this for the generated .wasm file.
|
|
9
|
+
name: regex
|
|
10
|
+
|
|
11
|
+
description: |
|
|
12
|
+
Filters the input topic to records that only match a regular expression.
|
|
13
|
+
|
|
14
|
+
Regular expressions are implemented using Go's regexp library, which uses the syntax of RE2.
|
|
15
|
+
See the RE2 wiki for allowed syntax: https://github.com/google/re2/wiki/Syntax
|
|
16
|
+
|
|
17
|
+
Environment variables:
|
|
18
|
+
- PATTERN: The regular expression that will match against records (required).
|
|
19
|
+
- MATCH_VALUE: By default, the regex matches keys, but if set to "true", the regex matches values.
|
|
20
|
+
|
|
21
|
+
# By default, no input topic is set here. (You can set it in your deploy command if preferred.)
|
|
22
|
+
input-topic: ""
|
|
23
|
+
|
|
24
|
+
# By default, no output topic is set here. (You can set it in your deploy command if preferred.)
|
|
25
|
+
output-topic: ""
|
|
26
|
+
|
|
27
|
+
# Indicates the specific TinyGo environment used to compile your transform.
|
|
28
|
+
language: tinygo-no-goroutines
|
|
29
|
+
|
|
30
|
+
env:
|
|
31
|
+
# The PATTERN variable must be provided at deploy time.
|
|
32
|
+
# Example: --var=PATTERN=".*@example.com"
|
|
33
|
+
PATTERN: '<required>'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { posix: path } = require('node:path')
|
|
4
|
+
|
|
5
|
+
function computeOut (src) {
|
|
6
|
+
const { component, version, module: module_, family, relative } = src
|
|
7
|
+
const outRelative = family === 'page' ? relative.replace(/\.adoc$/, '.html') : relative
|
|
8
|
+
const { dir: dirname, base: basename, ext: extname, name: stem } = path.parse(outRelative)
|
|
9
|
+
const componentVersion = this.getComponentVersion(component, version)
|
|
10
|
+
const versionSegment = componentVersion
|
|
11
|
+
const outDirSegments = []
|
|
12
|
+
const moduleRootPathSegments = []
|
|
13
|
+
if (component !== 'ROOT') outDirSegments.push(component)
|
|
14
|
+
if (versionSegment) outDirSegments.push(versionSegment)
|
|
15
|
+
if (module_ !== 'ROOT') outDirSegments.push(module_)
|
|
16
|
+
const outModuleDirSegments = outDirSegments.slice()
|
|
17
|
+
if (family !== 'page') {
|
|
18
|
+
outDirSegments.push(`_${family}s`)
|
|
19
|
+
moduleRootPathSegments.push('..')
|
|
20
|
+
}
|
|
21
|
+
if (dirname) {
|
|
22
|
+
outDirSegments.push(dirname)
|
|
23
|
+
for (const _ of dirname.split('/')) moduleRootPathSegments.push('..')
|
|
24
|
+
}
|
|
25
|
+
const rootPathSegments = moduleRootPathSegments.slice()
|
|
26
|
+
for (const _ of outModuleDirSegments) rootPathSegments.push('..')
|
|
27
|
+
const outDirname = outDirSegments.join('/')
|
|
28
|
+
const result = {
|
|
29
|
+
dirname: outDirname,
|
|
30
|
+
basename,
|
|
31
|
+
path: outDirname + '/' + basename,
|
|
32
|
+
moduleRootPath: moduleRootPathSegments.length ? moduleRootPathSegments.join('/') : '.',
|
|
33
|
+
rootPath: rootPathSegments.length ? rootPathSegments.join('/') : '.',
|
|
34
|
+
}
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = computeOut
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const computeOut = require('./compute-out')
|
|
4
|
+
const { posix: path } = require('node:path')
|
|
5
|
+
|
|
6
|
+
function createAsciiDocFile (contentCatalog, file) {
|
|
7
|
+
file.mediaType = 'text/asciidoc'
|
|
8
|
+
const src = file.src
|
|
9
|
+
const out = computeOut.call(contentCatalog, src)
|
|
10
|
+
const pub = { url: '/' + out.path, moduleRootPath: out.moduleRootPath, rootPath: out.rootPath }
|
|
11
|
+
contentCatalog.removeFile((file = contentCatalog.addFile(Object.assign(file, { path: out.path, out: null, pub: pub }))))
|
|
12
|
+
return file
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = createAsciiDocFile
|