git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #74055 from tfc/nixos-test-port-prometheus

nixos/prometheus: Port prometheus test to python

commit3e3918d02ab6b06e96d57b3cca3fe5d08c1afc85 authorRobin Gloster <mail@glob.in> dateSun 24 Nov 2019, 21:59 (7 years ago) parente315f34e20e124
1 file changed+42−36
nixos/tests/prometheus.nix+42−36
nixos/tests/prometheus.nix+42−36
@@ -31,7 +31,7 @@ let
3131 };
3232 };
3333
34−in import ./make-test.nix {
34+in import ./make-test-python.nix {
3535 name = "prometheus";
3636
3737 nodes = {
@@ -173,67 +173,73 @@ in import ./make-test.nix {
173173 testScript = { nodes, ... } : ''
174174 # Before starting the other machines we first make sure that our S3 service is online
175175 # and has a bucket added for thanos:
176− $s3->start;
177− $s3->waitForUnit("minio.service");
178− $s3->waitForOpenPort(${toString minioPort});
179− $s3->succeed(
180− "mc config host add minio " .
181− "http://localhost:${toString minioPort} ${s3.accessKey} ${s3.secretKey} S3v4");
182− $s3->succeed("mc mb minio/thanos-bucket");
176+ s3.start()
177+ s3.wait_for_unit("minio.service")
178+ s3.wait_for_open_port(${toString minioPort})
179+ s3.succeed(
180+ "mc config host add minio "
181+ + "http://localhost:${toString minioPort} "
182+ + "${s3.accessKey} ${s3.secretKey} S3v4",
183+ "mc mb minio/thanos-bucket",
184+ )
183185
184186 # Now that s3 has started we can start the other machines:
185− $prometheus->start;
186− $query->start;
187− $store->start;
187+ for machine in prometheus, query, store:
188+ machine.start()
188189
189190 # Check if prometheus responds to requests:
190− $prometheus->waitForUnit("prometheus.service");
191− $prometheus->waitForOpenPort(${toString queryPort});
192− $prometheus->succeed("curl -s http://127.0.0.1:${toString queryPort}/metrics");
191+ prometheus.wait_for_unit("prometheus.service")
192+ prometheus.wait_for_open_port(${toString queryPort})
193+ prometheus.succeed("curl -s http://127.0.0.1:${toString queryPort}/metrics")
193194
194195 # Let's test if pushing a metric to the pushgateway succeeds:
195− $prometheus->waitForUnit("pushgateway.service");
196− $prometheus->succeed(
197− "echo 'some_metric 3.14' | " .
198− "curl --data-binary \@- http://127.0.0.1:${toString pushgwPort}/metrics/job/some_job");
196+ prometheus.wait_for_unit("pushgateway.service")
197+ prometheus.succeed(
198+ "echo 'some_metric 3.14' | "
199+ + "curl --data-binary \@- "
200+ + "http://127.0.0.1:${toString pushgwPort}/metrics/job/some_job"
201+ )
199202
200203 # Now check whether that metric gets ingested by prometheus.
201204 # Since we'll check for the metric several times on different machines
202205 # we abstract the test using the following function:
203206
204207 # Function to check if the metric "some_metric" has been received and returns the correct value.
205− local *Machine::waitForMetric = sub {
206− my ($self) = @_;
207− $self->waitUntilSucceeds(
208− "curl -sf 'http://127.0.0.1:${toString queryPort}/api/v1/query?query=some_metric' " .
209− "| jq '.data.result[0].value[1]' | grep '\"3.14\"'");
210− };
208+ def wait_for_metric(machine):
209+ return machine.wait_until_succeeds(
210+ "curl -sf 'http://127.0.0.1:${toString queryPort}/api/v1/query?query=some_metric' | "
211+ + "jq '.data.result[0].value[1]' | grep '\"3.14\"'"
212+ )
213+
211214
212− $prometheus->waitForMetric;
215+ wait_for_metric(prometheus)
213216
214217 # Let's test if the pushgateway persists metrics to the configured location.
215− $prometheus->waitUntilSucceeds("test -e /var/lib/prometheus-pushgateway/metrics");
218+ prometheus.wait_until_succeeds("test -e /var/lib/prometheus-pushgateway/metrics")
216219
217220 # Test thanos
218− $prometheus->waitForUnit("thanos-sidecar.service");
221+ prometheus.wait_for_unit("thanos-sidecar.service")
219222
220223 # Test if the Thanos query service can correctly retrieve the metric that was send above.
221− $query->waitForUnit("thanos-query.service");
222− $query->waitForMetric;
224+ query.wait_for_unit("thanos-query.service")
225+ wait_for_metric(query)
223226
224227 # Test if the Thanos sidecar has correctly uploaded its TSDB to S3, if the
225228 # Thanos storage service has correctly downloaded it from S3 and if the Thanos
226229 # query service running on $store can correctly retrieve the metric:
227− $store->waitForUnit("thanos-store.service");
228− $store->waitForMetric;
230+ store.wait_for_unit("thanos-store.service")
231+ wait_for_metric(store)
229232
230− $store->waitForUnit("thanos-compact.service");
233+ store.wait_for_unit("thanos-compact.service")
231234
232235 # Test if the Thanos bucket command is able to retrieve blocks from the S3 bucket
233236 # and check if the blocks have the correct labels:
234− $store->succeed(
235− "thanos bucket ls" .
236− " --objstore.config-file=${nodes.store.config.services.thanos.store.objstore.config-file}" .
237− " --output=json | jq .thanos.labels.some_label | grep 'required by thanos'");
237+ store.succeed(
238+ "thanos bucket ls "
239+ + "--objstore.config-file=${nodes.store.config.services.thanos.store.objstore.config-file} "
240+ + "--output=json | "
241+ + "jq .thanos.labels.some_label | "
242+ + "grep 'required by thanos'"
243+ )
238244 '';
239245}