Skip to content

Add ClickHouse mock harness for omclickhouse tests#125

Open
rgerhards wants to merge 3 commits intomainfrom
codex/review-omclickhouse-quality-and-testbench-coverage
Open

Add ClickHouse mock harness for omclickhouse tests#125
rgerhards wants to merge 3 commits intomainfrom
codex/review-omclickhouse-quality-and-testbench-coverage

Conversation

@rgerhards
Copy link
Owner

Summary

  • mark omclickhouse as core-supported in MODULE_METADATA
  • add a lightweight ClickHouse HTTP mock server and shell helper for the omclickhouse tests
  • convert the basic/default/limited batch tests to use the mock and skip the remaining heavy ClickHouse scripts for now

Testing

  • ./tests/clickhouse-basic.sh (fails: omclickhouse module is not built in this environment)

https://chatgpt.com/codex/tasks/task_e_68d8f660368083329ddc0158aeb3b8a8

@gemini-code-assist
Copy link

Summary of Changes

Hello @rgerhards, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure for the 'omclickhouse' module by introducing a lightweight, Python-based HTTP mock server. This mock server allows tests to verify the SQL statements generated by 'omclickhouse' without requiring a full ClickHouse instance, leading to more efficient and reliable continuous integration. Key tests have been converted to use this new harness, and the 'omclickhouse' module itself has been designated as 'core-supported' and 'mature'.

Highlights

  • Mock ClickHouse Server: A Python-based HTTP mock server (tests/clickhouse-mock-server.py) and a shell helper (tests/clickhouse-mock.sh) have been introduced to simulate ClickHouse interactions for testing purposes.
  • Test Conversion: The 'clickhouse-basic.sh', 'clickhouse-dflt-tpl.sh', and 'clickhouse-limited-batch.sh' tests have been refactored to utilize the new mock server, enabling more isolated and faster testing without a live ClickHouse instance.
  • Module Status Update: The 'omclickhouse' module is now officially marked as 'core-supported' and 'mature' in its MODULE_METADATA.yaml, reflecting its stability and importance.
  • Temporary Test Disablement: Several older, heavier ClickHouse integration tests have been temporarily disabled (marked to 'exit 77') to allow for a focused transition to the new mock-based testing approach and future rework.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mock server for ClickHouse tests, which is a great improvement for CI stability and speed. The implementation of the mock server and the test helpers is well done, and the conversion of existing tests to use this new mock infrastructure is a reasonable approach. My review includes a few suggestions to improve maintainability and code style, such as fixing indentation for consistency in tests/Makefile.am, refactoring repetitive test logic in tests/clickhouse-dflt-tpl.sh, and avoiding a global variable in the Python mock server for better encapsulation. Overall, this is a solid contribution that significantly improves the testing strategy for omclickhouse.

Comment on lines +2480 to +2483
clickhouse-basic.sh \
clickhouse-mock.sh \
clickhouse-mock-server.py \
clickhouse-load.sh \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation for the newly added files in EXTRA_DIST uses spaces, while the rest of the file appears to use tabs. For consistency and to adhere to common Makefile conventions, please use tabs for indentation.

	clickhouse-basic.sh \
	clickhouse-mock.sh \
	clickhouse-mock-server.py \
	clickhouse-load.sh \

Comment on lines +30 to +52
if ! printf '%s\n' "$ACTUAL" | grep -q "INSERT INTO rsyslog.SystemEvents"; then
echo "unexpected SQL payload: missing INSERT"
cat -n "$REQ_FILE"
error_exit 1
fi

if ! printf '%s\n' "$ACTUAL" | grep -q "VALUES (7, 20,"; then
echo "unexpected SQL payload: severity/facility mismatch"
cat -n "$REQ_FILE"
error_exit 1
fi

if ! printf '%s\n' "$ACTUAL" | grep -q "'tag'"; then
echo "unexpected SQL payload: tag missing"
cat -n "$REQ_FILE"
error_exit 1
fi

if ! printf '%s\n' "$ACTUAL" | grep -q "' msgnum:00000000:'"; then
echo "unexpected SQL payload: message mismatch"
cat -n "$REQ_FILE"
error_exit 1
fi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These consecutive grep checks on the payload are repetitive. To improve readability and maintainability, this logic could be refactored into a helper function.

For example, you could define a function after ACTUAL=$(cat "$REQ_FILE"):

check_payload() {
    local pattern="$1"
    local errmsg="$2"
    if ! printf '%s\n' "$ACTUAL" | grep -q -- "$pattern"; then
        echo "unexpected SQL payload: $errmsg"
        cat -n "$REQ_FILE"
        error_exit 1
    fi
}

Then, you can replace the series of if blocks with clearer, one-line calls:

check_payload "INSERT INTO rsyslog.SystemEvents" "missing INSERT"
check_payload "VALUES (7, 20," "severity/facility mismatch"
check_payload "'tag'" "tag missing"
check_payload "' msgnum:00000000:'" "message mismatch"

This makes the test's intent much clearer at a glance.

Comment on lines +85 to +86
global STORE
STORE = RequestStore(sink_dir)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a global variable for STORE is generally discouraged as it can make code harder to reason about. A better pattern here is to make the RequestStore instance a class attribute of the handler.

Here's how you can refactor it:

  1. Add a class attribute to ClickHouseMockHandler:

    class ClickHouseMockHandler(BaseHTTPRequestHandler):
        """Minimal handler that understands ClickHouse-style POSTs."""
        STORE: RequestStore
        ...
  2. In do_POST, access it via self:

    # inside do_POST at line 55
    ...
        else:
            self.STORE.store(payload)
  3. Finally, in main, initialize the class attribute instead of the global variable (replacing lines 85-86):

    ClickHouseMockHandler.STORE = RequestStore(sink_dir)

This change improves encapsulation and makes the relationship between the handler and the store explicit.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +3 to +20
clickhouse_mock_setup() {
if [ -z "$PYTHON" ]; then
echo "TESTBENCH ERROR: PYTHON variable is unset"
error_exit 100
fi

export CLICKHOUSE_MOCK_BASE="${RSYSLOG_DYNNAME}.clickhouse_mock"
export CLICKHOUSE_MOCK_SINK_DIR="${CLICKHOUSE_MOCK_BASE}/requests"
export CLICKHOUSE_MOCK_READY_FILE="${CLICKHOUSE_MOCK_BASE}/ready"
mkdir -p "$CLICKHOUSE_MOCK_SINK_DIR"

export CLICKHOUSE_MOCK_PORT="$(get_free_port)"

"$PYTHON" "${srcdir}/clickhouse-mock-server.py" \
--host 127.0.0.1 \
--port "$CLICKHOUSE_MOCK_PORT" \
--sink-dir "$CLICKHOUSE_MOCK_SINK_DIR" \
--ready-file "$CLICKHOUSE_MOCK_READY_FILE" &

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Use python3 when starting ClickHouse mock server

The new helper invokes the mock server with $PYTHON, but clickhouse-mock-server.py uses Python 3–only syntax (type annotations, http.server). The build system still calls AM_PATH_PYTHON without a version requirement, so on systems where configure picks a Python 2 interpreter the test harness will now fail with a SyntaxError before any omclickhouse tests run. Please run the server with python3 explicitly or require PYTHON to point to a Python 3 executable before calling it.

Useful? React with 👍 / 👎.

@rgerhards rgerhards force-pushed the codex/review-omclickhouse-quality-and-testbench-coverage branch from 1656b43 to cd8e139 Compare September 28, 2025 11:17
- mark omclickhouse as core-supported in MODULE_METADATA\n- add clickhouse mock server and helper so basic coverage runs without ClickHouse\n- refactor a subset of clickhouse tests to use the mock, skip remaining heavy scripts\n\nAI-Agent: ChatGPT
- duplicate essential ClickHouse scenarios into new clickhouse-mock-* scripts that use the mock server helper\n- revert the legacy clickhouse test names to exit 77 so they clearly skip without a real ClickHouse\n- hook the mock variants into the Automake harness and distribution list alongside the existing scripts\n\nAI-Agent: Codex
Fixes the module metadata YAML to satisfy linting by removing inline backticks, wrapping long strings, and using folded blocks for notes. This resolves CI syntax errors introduced when documenting the mock ClickHouse coverage.

AI-Agent: ChatGPT
@rgerhards rgerhards force-pushed the codex/review-omclickhouse-quality-and-testbench-coverage branch from cd8e139 to 91b2141 Compare September 28, 2025 14:21
@github-actions
Copy link

github-actions bot commented Sep 28, 2025

📖 Documentation Preview Ready!

Sphinx docs built and deployed for this PR.

🌐 Browse Online (Recommended):

📚 View Documentation Online →

🔗 Quick Links:


🤖 This comment was generated by the docs workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant