Skip to content

Commit 250eb65

Browse files
authored
Merge pull request #3530 from Blargian/autogenerate_global_server_settings
Autogenerate global server settings
2 parents 6944f4c + 4b8b079 commit 250eb65

File tree

4 files changed

+132
-2
lines changed

4 files changed

+132
-2
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ Check out the GitHub docs for a refresher on [how to create a pull request](http
134134
135135
### Style guidelines
136136
137-
For style guidelines, see ["Style guide"](/contribute/style-guide.md).
137+
For documentation style guidelines, see ["Style guide"](/contribute/style-guide.md).
138+
139+
### Generating documentation from source code
140+
141+
For an overview of how reference documentation such as settings, system tables
142+
and functions are generated from the source code, see ["Generating documentation from source code"](/contribute/autogenerated-documentation-from-source.md)
138143
139144
### Tests and CI/CD {#tests-and-cicd}
140145
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Generating documentation from source code
2+
3+
A [script in our docs repo](https://github.com/ClickHouse/clickhouse-docs/blob/main/scripts/settings/autogenerate-settings.sh)
4+
extracts setting names, descriptions, default values, etc. from ClickHouse's source code.
5+
6+
## Session settings
7+
8+
Documentation for session settings are extracted from [`src/Core/Settings.cpp`](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).
9+
10+
## Format settings
11+
12+
Documentation for session settings are extracted from [`src/Core/FormatFactorySettings.h`](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/FormatFactorySettings.h).
13+
14+
## Server settings
15+
16+
Documentation for session settings are extracted from [`src/Core/ServerSettings.cpp`](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/ServerSettings.cpp).
17+
18+
Note that this file contains only a fraction of all server settings.
19+
The reason is that server settings can be nested and `system.server_settings`
20+
(which is built from `src/Core/ServerSettings.cpp`) and cannot represent nested
21+
settings.
22+
23+
Example:
24+
25+
```yaml
26+
<query_cache>
27+
<max_size_in_bytes>1073741824</max_size_in_bytes>
28+
<max_entries>1024</max_entries>
29+
<max_entry_size_in_bytes>1048576</max_entry_size_in_bytes>
30+
<max_entry_size_in_rows>30000000</max_entry_size_in_rows>
31+
</query_cache>
32+
```
33+
As a result of the above, you will find the server settings which are not found
34+
in `system.server_settings` documented in file `_server_settings_outside_source.md`
35+
36+
The auto-generation script reads these in, combines them with the ones from
37+
`system.settings` and appends the formatted settings to `settings.md`.
38+
39+
**As such, if you need to make a change to the settings you see on the
40+
[server settings](clickhouse.com/docs/operations/server-configuration-parameters/)
41+
page, you will need to check if the setting is in `system.server_settings`.
42+
If it is, then please edit the setting description in the source code documentation
43+
in [`ServerSettings.cpp`](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/ServerSettings.cpp)
44+
or else edit `_server_settings_outside_source.md`.**
45+
46+
## System tables
47+
48+
## Functions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"config": {
66
"clickhouse_repo_folders": "docs/en/development docs/en/engines docs/en/getting-started docs/en/interfaces docs/en/operations docs/en/sql-reference",
7-
"autogen_needed_files": "src/Core/FormatFactorySettings.h src/Core/Settings.cpp CHANGELOG.md"
7+
"autogen_needed_files": "src/Core/FormatFactorySettings.h src/Core/Settings.cpp CHANGELOG.md docs/en/operations/server-configuration-parameters/_server_settings_outside_source.md"
88
},
99
"scripts": {
1010
"build": "yarn copy-clickhouse-repo-docs && yarn run-markdown-linter && yarn generate-changelog && yarn autogenerate-settings && yarn autogenerate-table-of-contents && yarn build-api-doc && yarn build-swagger && yarn build-docs",

scripts/settings/autogenerate-settings.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,85 @@ SELECT prefix || (SELECT groupConcat(*) FROM main_content)
119119
INTO OUTFILE 'settings.md' TRUNCATE FORMAT LineAsString
120120
" > /dev/null || { echo "Failed to Autogenerate Core settings"; exit 1; }
121121

122+
# Auto generate global server settings
123+
./clickhouse -q "
124+
WITH
125+
server_settings_outside_source AS
126+
(
127+
SELECT
128+
arrayJoin(extractAllGroups(raw_blob, '## (\\w+)(?:\\s[^\n]+)?\n\\s+((?:[^#]|#[^#]|##[^ ])+)')) AS g,
129+
g[1] AS name,
130+
replaceRegexpAll(replaceRegexpAll(g[2], '\n(Type|Default( value)?): [^\n]+\n', ''), '^\n+|\n+$', '') AS doc
131+
FROM file('_server_settings_outside_source.md', RawBLOB)
132+
),
133+
server_settings_in_source AS
134+
(
135+
SELECT
136+
name,
137+
replaceRegexpAll(description, '(?m)^[ \t]+', '') AS description
138+
FROM system.server_settings
139+
),
140+
combined_server_settings AS
141+
(
142+
SELECT
143+
name,
144+
description
145+
FROM server_settings_in_source
146+
UNION ALL
147+
SELECT
148+
name,
149+
doc AS description
150+
FROM server_settings_outside_source
151+
),
152+
formatted_settings AS
153+
(
154+
SELECT
155+
format('## {} {}\n\n{}\n\n', name, lcase('{#'||name||'}'), description) AS formatted_text
156+
FROM combined_server_settings
157+
ORDER BY name ASC
158+
),
159+
prefix_text AS
160+
(
161+
SELECT
162+
'---
163+
description: ''This section contains descriptions of server settings i.e settings
164+
which cannot be changed at the session or query level.''
165+
keywords: [''global server settings'']
166+
sidebar_label: ''Server Settings''
167+
sidebar_position: 57
168+
slug: /operations/server-configuration-parameters/settings
169+
title: ''Server Settings''
170+
---
171+
172+
import Tabs from ''@theme/Tabs'';
173+
import TabItem from ''@theme/TabItem'';
174+
import SystemLogParameters from ''@site/docs/operations/server-configuration-parameters/_snippets/_system-log-parameters.md''
175+
176+
# Server Settings
177+
178+
This section contains descriptions of server settings. These are settings which
179+
cannot be changed at the session or query level.
180+
181+
For more information on configuration files in ClickHouse see [""Configuration Files""](/operations/configuration-files).
182+
183+
Other settings are described in the ""[Settings](/operations/settings/overview)"" section.
184+
Before studying the settings, we recommend reading the [Configuration files](/operations/configuration-files)
185+
section and note the use of substitutions (the `incl` and `optional` attributes).
186+
187+
' AS prefix_content
188+
)
189+
SELECT
190+
arrayStringConcat([
191+
(SELECT prefix_content FROM prefix_text),
192+
arrayStringConcat(groupArray(formatted_text), '')
193+
], '')
194+
FROM formatted_settings
195+
INTO OUTFILE 'server_settings.md'
196+
TRUNCATE FORMAT LineAsString" > /dev/null || { echo "Failed to Autogenerate Format settings"; exit 1; }
197+
122198
mv settings-formats.md "$root/docs/operations/settings" || { echo "Failed to move generated settings-format.md"; exit 1; }
123199
mv settings.md "$root/docs/operations/settings" || { echo "Failed to move generated settings.md"; exit 1; }
200+
mv server_settings.md "$root/docs/operations/server-configuration-parameters/settings.md" || { echo "Failed to move generated server_settings.md"; exit 1; }
124201

125202
echo "[$SCRIPT_NAME] Auto-generation of settings markdown pages completed successfully"
126203

0 commit comments

Comments
 (0)