private static void RunOperation(Counter counter, CounterWriteOperation op) { var timestamp = op.Timestamp == CounterWriteOperation.TimestampNow ? DateTime.UtcNow : op.Timestamp.ToDateTime(); var dims = new DimensionSpecification(op.DimensionValues); var hitCounter = counter as HitCounter; var histogramCounter = counter as HistogramCounter; if (hitCounter != null) { hitCounter.Increment(op.Value * op.Count, dims, timestamp); } else { // It would be nice to direct-inject multiple values at once, but the APIs don't currently // support this. It's a reasonable amount of work to fix this and unknown whether folks will use this // a lot at this time. for (var i = 0; i < op.Count; ++i) { histogramCounter.AddValue(op.Value, dims, timestamp); } } }
public async Task DimensionValuesAreHonored() { const string counterName = "/DimensionValues"; const string dim1 = "dim1"; const string dim2 = "dim2"; await this.dataManager.CreateHitCounter(counterName, new DimensionSet( new HashSet <Dimension>(new[] { new Dimension(dim1), new Dimension(dim2), }))); var op = new CounterWriteOperation { Value = 42 }; op.DimensionValues.Add(dim1, "867"); op.DimensionValues.Add(dim2, "5309"); var response = await this.httpClient.PostAsync(TestUtils.GetUri(this.server, RestCommands.CounterWriteCommand, counterName), CreateWriteBody(new[] { op })); Assert.AreEqual(HttpStatusCode.Accepted, response.StatusCode); var data = this.QueryCounter <HitCounter>(counterName, new DimensionSpecification { { dim1, "867" }, { dim2, "5309" } }); Assert.AreEqual(42, data.HitCount); }
private static void RunOperation(Counter counter, CounterWriteOperation op) { var timestamp = op.Timestamp == CounterWriteOperation.TimestampNow ? DateTime.UtcNow : op.Timestamp.ToDateTime(); var dims = new DimensionSpecification(op.DimensionValues); var hitCounter = counter as HitCounter; var histogramCounter = counter as HistogramCounter; if (hitCounter != null) { hitCounter.Increment(op.Value * op.Count, dims, timestamp); } else { // It would be nice to direct-inject multiple values at once, but the APIs don't currently // support this. It's a reasonable amount of work to fix this and unknown whether folks will use this // a lot at this time. for (var i = 0; i < op.Count; ++i) { histogramCounter.AddValue(op.Value, dims, timestamp); } } }