Skip to content

Commit 344af4a

Browse files
authored
Add ignorePrometheus Flag for integTest and docTest (#4442)
* Add ignorePrometheus flag Signed-off-by: Peng Huo <[email protected]> * support -DignorePrometheus in integTest and docTest Signed-off-by: Peng Huo <[email protected]> * Update Signed-off-by: Peng Huo <[email protected]> * Update Signed-off-by: Peng Huo <[email protected]> --------- Signed-off-by: Peng Huo <[email protected]>
1 parent e1a1bd8 commit 344af4a

File tree

7 files changed

+55
-25
lines changed

7 files changed

+55
-25
lines changed

DEVELOPER_GUIDE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ For faster local iterations, skip integration tests. ``./gradlew build -x integT
261261

262262
For integration test, you can use ``-Dtests.class`` "UT full path" to run a task individually. For example ``./gradlew :integ-test:integTest -Dtests.class="*QueryIT"``.
263263

264+
If Prometheus isn't available in your environment, you can skip downloading and starting it by adding ``-DignorePrometheus`` (or setting it to any value other than ``false``) to the command. For example ``./gradlew :integ-test:integTest -DignorePrometheus`` bypasses Prometheus setup and excludes Prometheus-specific integration tests, and ``./gradlew :doctest:doctest -DignorePrometheus`` skips the Prometheus-dependent doctest cases.
265+
264266
To run the task above for specific module, you can do ``./gradlew :<module_name>:task``. For example, only build core module by ``./gradlew :core:build``.
265267

266268
Troubleshooting

docs/dev/testing-doctest.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ For actually testing the code, the goal is to thoroughly test every case, rather
5252

5353
## 1.4 How to use doctest?
5454
### 1.4.2 How to run existing doctest?
55-
Doctest runs with project build by `./gradlew build`. You can also only run doctest by `./gradlew doctest`
55+
Doctest runs with project build by `./gradlew build`. You can also only run doctest by `./gradlew doctest`. If a Prometheus instance isn't available locally, add `-DignorePrometheus` (or set the property to any value other than `false`) to skip Prometheus setup and the Prometheus-specific doctest scenarios.
5656

5757
Make sure you don't have any OpenSearch instance running at `http://localhost:9200`
5858

5959
### 1.4.2 How to write documentation with doctest?
6060
1. If you want to add a new doc, you can add it to `docs` folder, under correct sub-folder, in `.rst` format.
6161
> **Attention**: For code examples in documentation, a Mixing usage of `cli` and `bash` in one doc is not supported yet.
6262
2. Add your new doc file path to `docs/category.json` by its category
63-
3. Run doctest `./gradlew doctest` to see if your tests can pass
63+
3. Run doctest `./gradlew doctest` (optionally with `-DignorePrometheus`) to see if your tests can pass
6464

6565
Currently, there is a `sample` folder under `docs` module to help you get started.
6666

docs/user/ppl/admin/datasources.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ PPL query for searching PROMETHEUS TABLES::
261261
+---------------+--------------+--------------------------------------------+------------+------+----------------------------------------------------+
262262

263263

264+
.. _datasources-prometheus-metadata:
265+
266+
Fetch metadata for table in Prometheus datasource
267+
=================================================
268+
269+
After a Prometheus datasource is configured, you can inspect the schema of any metric by running the ``describe`` command against the fully qualified table name. For example::
270+
271+
PPL query::
272+
273+
PPL> describe my_prometheus.prometheus_http_requests_total;
274+
fetched rows / total rows = 6/6
275+
+---------------+--------------+--------------------------------+-------------+-----------+
276+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | DATA_TYPE |
277+
|---------------+--------------+--------------------------------+-------------+-----------|
278+
| my_prometheus | default | prometheus_http_requests_total | handler | string |
279+
| my_prometheus | default | prometheus_http_requests_total | code | string |
280+
| my_prometheus | default | prometheus_http_requests_total | instance | string |
281+
| my_prometheus | default | prometheus_http_requests_total | @timestamp | timestamp |
282+
| my_prometheus | default | prometheus_http_requests_total | @value | double |
283+
| my_prometheus | default | prometheus_http_requests_total | job | string |
284+
+---------------+--------------+--------------------------------+-------------+-----------+
285+
264286
Limitations
265287
===========
266288

docs/user/ppl/cmd/describe.rst

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,7 @@ PPL query::
6767
+----------------+
6868

6969

70-
Example 3: Fetch metadata for table in prometheus dataSource
71-
=========================================================
70+
Example 3: Fetch metadata for table in Prometheus datasource
71+
============================================================
7272

73-
The example retrieves table info for ``prometheus_http_requests_total`` metric in prometheus dataSource.
74-
75-
PPL query::
76-
77-
os> describe my_prometheus.prometheus_http_requests_total;
78-
fetched rows / total rows = 6/6
79-
+---------------+--------------+--------------------------------+-------------+-----------+
80-
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | DATA_TYPE |
81-
|---------------+--------------+--------------------------------+-------------+-----------|
82-
| my_prometheus | default | prometheus_http_requests_total | handler | string |
83-
| my_prometheus | default | prometheus_http_requests_total | code | string |
84-
| my_prometheus | default | prometheus_http_requests_total | instance | string |
85-
| my_prometheus | default | prometheus_http_requests_total | @timestamp | timestamp |
86-
| my_prometheus | default | prometheus_http_requests_total | @value | double |
87-
| my_prometheus | default | prometheus_http_requests_total | job | string |
88-
+---------------+--------------+--------------------------------+-------------+-----------+
73+
See `Fetch metadata for table in Prometheus datasource <../admin/datasources.rst>`_ for more context.

doctest/build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def path = project(':').projectDir
1919
// temporary fix, because currently we are under migration to new architecture. Need to run ./gradlew run from
2020
// plugin module, and will only build ppl in it.
2121
def plugin_path = project(':doctest').projectDir
22+
String ignorePrometheusProp = System.getProperty("ignorePrometheus")
23+
boolean ignorePrometheus = ignorePrometheusProp != null && !ignorePrometheusProp.equalsIgnoreCase("false")
2224

2325
task cloneSqlCli(type: Exec) {
2426
def repoDir = new File("${project.projectDir}/sql-cli")
@@ -61,6 +63,7 @@ task startPrometheus(type: SpawnProcessTask) {
6163
command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml"
6264
ready 'TSDB started'
6365
pidLockFileName ".prom.pid.lock"
66+
onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" }
6467
}
6568

6669
//evaluationDependsOn(':')
@@ -88,6 +91,7 @@ task doctest(type: Exec, dependsOn: ['bootstrap']) {
8891
if (debug == 'true') {
8992
environment 'DOCTEST_DEBUG', 'true'
9093
}
94+
environment 'IGNORE_PROMETHEUS_DOCS', ignorePrometheus ? 'true' : 'false'
9195

9296
if (docs) {
9397
def args = ['.venv/bin/python', 'test_docs.py']
@@ -121,14 +125,17 @@ task stopPrometheus(type: KillProcessTask) {
121125
file("$projectDir/bin/prometheus").deleteDir()
122126
file("$projectDir/bin/prometheus.tar.gz").delete()
123127
}
128+
onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" }
124129
}
125130

126131
// Stop Prom AFTER Start Prom...
127132
if(getOSFamilyType() != "windows") {
128133
stopPrometheus.mustRunAfter startPrometheus
129-
startOpenSearch.dependsOn startPrometheus
130-
stopOpenSearch.finalizedBy stopPrometheus
131-
startOpenSearch.finalizedBy stopPrometheus
134+
if (!ignorePrometheus) {
135+
startOpenSearch.dependsOn startPrometheus
136+
stopOpenSearch.finalizedBy stopPrometheus
137+
startOpenSearch.finalizedBy stopPrometheus
138+
}
132139
}
133140
doctest.dependsOn startOpenSearch
134141
doctest.finalizedBy stopOpenSearch

doctest/test_docs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
}
4949

5050
DEBUG_MODE = os.environ.get('DOCTEST_DEBUG', 'false').lower() == 'true'
51+
IGNORE_PROMETHEUS_DOCS = os.environ.get('IGNORE_PROMETHEUS_DOCS', 'false').lower() == 'true'
52+
PROMETHEUS_DOC_FILES = {
53+
'user/ppl/cmd/showdatasources.rst'
54+
}
5155

5256

5357
def debug(message):
@@ -102,6 +106,13 @@ def load_categories(self, file_path):
102106
try:
103107
with open(file_path) as json_file:
104108
categories = json.load(json_file)
109+
if IGNORE_PROMETHEUS_DOCS:
110+
categories = {
111+
category: [
112+
doc for doc in docs if doc not in PROMETHEUS_DOC_FILES
113+
]
114+
for category, docs in categories.items()
115+
}
105116
debug(f"Loaded {len(categories)} categories from {file_path}")
106117
return categories
107118
except Exception as e:

integ-test/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ String bwcVersion = baseVersion + ".0";
5353
String baseName = "sqlBwcCluster"
5454
String bwcFilePath = "src/test/resources/bwc/"
5555
String calciteCodegen = "$projectDir/src/test/java/codegen/"
56+
String ignorePrometheusProp = System.getProperty("ignorePrometheus")
57+
boolean ignorePrometheus = ignorePrometheusProp != null && !ignorePrometheusProp.equalsIgnoreCase("false")
5658

5759
repositories {
5860
mavenCentral()
@@ -317,6 +319,7 @@ task startPrometheus(type: SpawnProcessTask) {
317319
}
318320
command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml"
319321
ready 'TSDB started'
322+
onlyIf { !ignorePrometheus }
320323
}
321324

322325
task stopPrometheus(type: KillProcessTask) {
@@ -459,7 +462,7 @@ integTest {
459462
}
460463

461464
dependsOn ':opensearch-sql-plugin:bundlePlugin'
462-
if(getOSFamilyType() != "windows") {
465+
if(!ignorePrometheus && getOSFamilyType() != "windows") {
463466
dependsOn startPrometheus
464467
finalizedBy stopPrometheus
465468
}
@@ -499,7 +502,7 @@ integTest {
499502
}
500503
}
501504

502-
if(getOSFamilyType() == "windows") {
505+
if(getOSFamilyType() == "windows" || ignorePrometheus) {
503506
exclude 'org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.class'
504507
exclude 'org/opensearch/sql/ppl/ShowDataSourcesCommandIT.class'
505508
exclude 'org/opensearch/sql/ppl/InformationSchemaCommandIT.class'

0 commit comments

Comments
 (0)