@Test
    public void testClusterMetricsReadWrite() {
        String dataDir = createEmptyDataDir("QuestMetricsDbReadWrite", "clusterMetrics");
        ManualClock clock = new ManualClock("2020-10-01T00:00:00");
        QuestMetricsDb db = new QuestMetricsDb(dataDir, clock);
        Instant startTime = clock.instant();

        var application1 = ApplicationId.from("t1", "a1", "i1");
        var application2 = ApplicationId.from("t1", "a2", "i1");
        var cluster1 = new ClusterSpec.Id("cluster1");
        var cluster2 = new ClusterSpec.Id("cluster2");
        db.addClusterMetrics(application1, Map.of(cluster1, new ClusterMetricSnapshot(clock.instant(), 30.0, 15.0)));
        db.addClusterMetrics(application1, Map.of(cluster2, new ClusterMetricSnapshot(clock.instant(), 60.0, 30.0)));
        clock.advance(Duration.ofMinutes(1));
        db.addClusterMetrics(application1, Map.of(cluster1, new ClusterMetricSnapshot(clock.instant(), 45.0, 22.5)));
        clock.advance(Duration.ofMinutes(1));
        db.addClusterMetrics(application2, Map.of(cluster1, new ClusterMetricSnapshot(clock.instant(), 90.0, 45.0)));

        ClusterTimeseries clusterTimeseries11 = db.getClusterTimeseries(application1, cluster1);
        assertEquals(cluster1, clusterTimeseries11.cluster());
        assertEquals(2, clusterTimeseries11.asList().size());

        ClusterMetricSnapshot snapshot111 = clusterTimeseries11.get(0);
        assertEquals(startTime, snapshot111.at());
        assertEquals(30, snapshot111.queryRate(), delta);
        assertEquals(15, snapshot111.writeRate(), delta);
        ClusterMetricSnapshot snapshot112 = clusterTimeseries11.get(1);
        assertEquals(startTime.plus(Duration.ofMinutes(1)), snapshot112.at());
        assertEquals(45, snapshot112.queryRate(), delta);
        assertEquals(22.5, snapshot112.writeRate(), delta);


        ClusterTimeseries clusterTimeseries12 = db.getClusterTimeseries(application1, cluster2);
        assertEquals(cluster2, clusterTimeseries12.cluster());
        assertEquals(1, clusterTimeseries12.asList().size());

        ClusterMetricSnapshot snapshot121 = clusterTimeseries12.get(0);
        assertEquals(startTime, snapshot121.at());
        assertEquals(60, snapshot121.queryRate(), delta);
        assertEquals(30, snapshot121.writeRate(), delta);


        ClusterTimeseries clusterTimeseries21 = db.getClusterTimeseries(application2, cluster1);
        assertEquals(cluster1, clusterTimeseries21.cluster());
        assertEquals(1, clusterTimeseries21.asList().size());

        ClusterMetricSnapshot snapshot211 = clusterTimeseries21.get(0);
        assertEquals(startTime.plus(Duration.ofMinutes(2)), snapshot211.at());
        assertEquals(90, snapshot211.queryRate(), delta);
    }
Print query rate from a real database.

How to use:

1. Download data from a production config server: rsync -az --progress cfgN.example.com:/data/vespa/storage/cfgN/opt/vespa/var/db/vespa/autoscaling /tmp/cfgN-questdb
2. Set application ID and cluster ID
3. Adjust start and end instant as necessary
4. Run test to print data
5. Output from test can be used as test input in {@link ClusterTimeseriesTest}
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDbTest.java