From e3cd706f36f98e90add621591c9338024a4f7da9 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Sun, 11 Aug 2024 00:10:31 +0530 Subject: [PATCH] Added integration test for snapshots metrics --- README.md | 7 +++ build.gradle | 6 +++ .../test/70_10_snapshots_metrics.yml | 50 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/yamlRestTest/resources/rest-api-spec/test/70_10_snapshots_metrics.yml diff --git a/README.md b/README.md index 3adbaa9..8826fd9 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,13 @@ To disable exporting cluster settings use: prometheus.cluster.settings: false ``` +#### Snapshot metrics + +To enable exporting snapshot metrics use: +``` +prometheus.snapshots: true +``` + #### Nodes filter Metrics include statistics about individual OpenSearch nodes. diff --git a/build.gradle b/build.gradle index d1ba583..3839c5a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import org.opensearch.gradle.PropertyNormalization import org.opensearch.gradle.test.RestIntegTestTask import java.util.regex.Matcher @@ -124,8 +125,13 @@ tasks.named("check").configure { dependsOn(integTest) } // Temporary disable task :testingConventions testingConventions.enabled = false +// Directory for snapshot repository +File repositoryDir = new File(project.buildDir, "shared-repository") + testClusters.all { numberOfNodes = 2 + // Configuring repo path for 'fs' type snapshot repository + setting 'path.repo', "${repositoryDir.absolutePath}", PropertyNormalization.IGNORE_VALUE // It seems cluster name can not be customized here. It gives an error: // Testclusters does not allow the following settings to be changed:[cluster.name] for node{::yamlRestTest-0} diff --git a/src/yamlRestTest/resources/rest-api-spec/test/70_10_snapshots_metrics.yml b/src/yamlRestTest/resources/rest-api-spec/test/70_10_snapshots_metrics.yml new file mode 100644 index 0000000..b52a0fe --- /dev/null +++ b/src/yamlRestTest/resources/rest-api-spec/test/70_10_snapshots_metrics.yml @@ -0,0 +1,50 @@ +--- +"Verify snapshots metrics enabled": + + # Create 'fs' snapshot repository + - do: + snapshot.create_repository: + repository: test_repo_get_1 + body: + type: fs + settings: + location: "test_repo_get_1_loc" + + - do: + snapshot.get_repository: { } + + - is_true: test_repo_get_1 + + # Enable snapshots metrics + - do: + cluster.put_settings: + body: + persistent: + prometheus.snapshots: "true" + flat_settings: true + + - match: { persistent: { prometheus.snapshots: "true" } } + + # Create snapshot + - do: + snapshot.create: + repository: test_repo_get_1 + snapshot: test_snapshot_1 + wait_for_completion: true + + - match: { snapshot.snapshot: test_snapshot_1 } + - match: { snapshot.state : SUCCESS } + + # Fetch and verify metrics + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + \# \s* HELP \s+ opensearch_min_snapshot_age \s+.*\n + \# \s* TYPE \s+ opensearch_min_snapshot_age \s+ gauge\n + opensearch_min_snapshot_age\{ + cluster="yamlRestTest",sm_policy="adhoc", + \}\s+\d+\.\d+\n + .*/