jstests/core/timeseries/libs/timeseries_agg_helpers.js
/**
     * Prepares two input collections with exactly the same data set. One is a time-series
     * collection and the other one is a non time-series collection.
     *
     * @param numHosts Number of different hosts to generate.
     * @param numIterations Number of measurement generation loop iterations.
     * @returns An array of a time-series collection and a non time-series collection,
     *     respectively in this order.
     */
Prepares two input collections with exactly the same data set. One is a time-series
collection and the other one is a non time-series collection.

@param numHosts Number of different hosts to generate.
@param numIterations Number of measurement generation loop iterations.
@returns An array of a time-series collection and a non time-series collection,
respectively in this order.
Prepares two input collections with exactly the same data set . One is a time - series collection and the other one is a non time - series collection . @param numHosts Number of different hosts to generate . @param numIterations Number of measurement generation loop iterations . @returns An array of a time - series collection and a non time - series collection respectively in this order .
static prepareInputCollections(numHosts, numIterations, includeIdleMeasurements = true) {
        const timeseriesCollOption = {timeseries: {timeField: "time", metaField: "tags"}};
        Random.setRandomSeed();
        const hosts = TimeseriesTest.generateHosts(numHosts);
        const testDB = TimeseriesAggTests.getTestDb();
        const inColl = testDB.getCollection("in");
        inColl.drop();
        assert.commandWorked(testDB.createCollection(inColl.getName(), timeseriesCollOption));
        const observerInColl = testDB.getCollection("observer_in");
        observerInColl.drop();
        assert.commandWorked(testDB.createCollection(observerInColl.getName()));
        const currTime = new Date();
        for (let i = 0; i < numIterations; i++) {
            for (let host of hosts) {
                const userUsage = TimeseriesTest.getRandomUsage();
                let newMeasurement = {
                    tags: host.tags,
                    time: new Date(currTime + i),
                    usage_guest: TimeseriesTest.getRandomUsage(),
                    usage_guest_nice: TimeseriesTest.getRandomUsage(),
                    usage_idle: TimeseriesTest.getRandomUsage(),
                    usage_iowait: TimeseriesTest.getRandomUsage(),
                    usage_irq: TimeseriesTest.getRandomUsage(),
                    usage_nice: TimeseriesTest.getRandomUsage(),
                    usage_softirq: TimeseriesTest.getRandomUsage(),
                    usage_steal: TimeseriesTest.getRandomUsage(),
                    usage_system: TimeseriesTest.getRandomUsage(),
                    usage_user: userUsage
                };
                assert.commandWorked(inColl.insert(newMeasurement));
                assert.commandWorked(observerInColl.insert(newMeasurement));
                if (includeIdleMeasurements && (i % 2)) {
                    let idleMeasurement = {
                        tags: host.tags,
                        time: new Date(currTime + i),
                        idle_user: 100 - userUsage
                    };
                    assert.commandWorked(inColl.insert(idleMeasurement));
                    assert.commandWorked(observerInColl.insert(idleMeasurement));
                }
            }
        }
        return [inColl, observerInColl];
    }
static prepareInputCollections ( numHosts , numIterations , includeIdleMeasurements = true ) { const timeseriesCollOption = { timeseries : { timeField : "time" , metaField : "tags" } } ; Random . setRandomSeed ( ) ; const hosts = TimeseriesTest . generateHosts ( numHosts ) ; const testDB = TimeseriesAggTests . getTestDb ( ) ; const inColl = testDB . getCollection ( "in" ) ; inColl . drop ( ) ; assert . commandWorked ( testDB . createCollection ( inColl . getName ( ) , timeseriesCollOption ) ) ; const observerInColl = testDB . getCollection ( "observer_in" ) ; observerInColl . drop ( ) ; assert . commandWorked ( testDB . createCollection ( observerInColl . getName ( ) ) ) ; const currTime = new Date ( ) ; for ( let i = 0 ; i < numIterations ; i ++ ) { for ( let host of hosts ) { const userUsage = TimeseriesTest . getRandomUsage ( ) ; let newMeasurement = { tags : host . tags , time : new Date ( currTime + i ) , usage_guest : TimeseriesTest . getRandomUsage ( ) , usage_guest_nice : TimeseriesTest . getRandomUsage ( ) , usage_idle : TimeseriesTest . getRandomUsage ( ) , usage_iowait : TimeseriesTest . getRandomUsage ( ) , usage_irq : TimeseriesTest . getRandomUsage ( ) , usage_nice : TimeseriesTest . getRandomUsage ( ) , usage_softirq : TimeseriesTest . getRandomUsage ( ) , usage_steal : TimeseriesTest . getRandomUsage ( ) , usage_system : TimeseriesTest . getRandomUsage ( ) , usage_user : userUsage } ; assert . commandWorked ( inColl . insert ( newMeasurement ) ) ; assert . commandWorked ( observerInColl . insert ( newMeasurement ) ) ; if ( includeIdleMeasurements && ( i % 2 ) ) { let idleMeasurement = { tags : host . tags , time : new Date ( currTime + i ) , idle_user : 100 - userUsage } ; assert . commandWorked ( inColl . insert ( idleMeasurement ) ) ; assert . commandWorked ( observerInColl . insert ( idleMeasurement ) ) ; } } } return [ inColl , observerInColl ] ; }
Prepares two input collections with exactly the same data set.
Prepares two input collections with exactly the same data set .
// Creates a time-series input collection. // Creates a non time-series observer input collection. // Inserts exactly the same random measurement to both inColl and observerInColl.