Implementation and tests of query metrics function (#2)