Ejemplo n.º 1
0
    def testLaterValuesDoNotOverridePrevious(self):
        stats.STATS.RegisterCounterMetric("counter")

        stats.STATS.IncrementCounter("counter")
        self.stats_store.WriteStats(process_id=self.process_id,
                                    timestamp=42,
                                    sync=True)

        stats.STATS.IncrementCounter("counter")
        self.stats_store.WriteStats(process_id=self.process_id,
                                    timestamp=43,
                                    sync=True)

        row = data_store.DB.ResolvePrefix(
            "aff4:/stats_store/some_pid",
            "",
            timestamp=data_store.DB.ALL_TIMESTAMPS,
            token=self.token)
        counters = [x for x in row if x[0] == "aff4:stats_store/counter"]
        self.assertEqual(len(counters), 2)
        counters = sorted(counters, key=lambda x: x[2])

        stored_value = stats_store.StatsStoreValue(
            value_type=stats.MetricMetadata.ValueType.INT, int_value=1)
        self.assertEqual(
            counters[0],
            ("aff4:stats_store/counter", stored_value.SerializeToString(), 42))
        stored_value = stats_store.StatsStoreValue(
            value_type=stats.MetricMetadata.ValueType.INT, int_value=2)
        self.assertEqual(
            counters[1],
            ("aff4:stats_store/counter", stored_value.SerializeToString(), 43))
Ejemplo n.º 2
0
    def testIntGaugeValuesAreWrittenToDataStore(self):
        stats.STATS.RegisterGaugeMetric("int_gauge", int)
        stats.STATS.SetGaugeValue("int_gauge", 4242)

        self.stats_store.WriteStats(process_id=self.process_id, timestamp=42)

        row = data_store.DB.ResolvePrefix("aff4:/stats_store/some_pid",
                                          "",
                                          token=self.token)
        counter = [x for x in row if x[0] == "aff4:stats_store/int_gauge"]
        self.assertTrue(counter)

        stored_value = stats_store.StatsStoreValue(
            value_type=stats.MetricMetadata.ValueType.INT, int_value=4242)
        self.assertEqual(counter[0], ("aff4:stats_store/int_gauge",
                                      stored_value.SerializeToString(), 42))
Ejemplo n.º 3
0
    def testCountersAreWrittenToDataStore(self):
        stats.STATS.RegisterCounterMetric("counter")
        stats.STATS.IncrementCounter("counter")

        self.stats_store.WriteStats(process_id=self.process_id,
                                    timestamp=42,
                                    sync=True)

        row = data_store.DB.ResolvePrefix("aff4:/stats_store/some_pid",
                                          "",
                                          token=self.token)
        counter = [x for x in row if x[0] == "aff4:stats_store/counter"]
        self.assertTrue(counter)

        stored_value = stats_store.StatsStoreValue(
            value_type=stats.MetricMetadata.ValueType.INT, int_value=1)
        self.assertEqual(
            counter[0],
            ("aff4:stats_store/counter", stored_value.SerializeToString(), 42))