Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with some pre aggregated Metrics intervals #844

Merged
merged 6 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions AutoCollection/PreAggregatedMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,21 @@ class AutoCollectPreAggregatedMetrics {
private _trackExceptionMetrics() {
for (let i = 0; i < AutoCollectPreAggregatedMetrics._exceptionCountersCollection.length; i++) {
var currentCounter = AutoCollectPreAggregatedMetrics._exceptionCountersCollection[i];
currentCounter.time = +new Date;
var intervalExceptions = (currentCounter.totalCount - currentCounter.lastTotalCount) || 0;
var elapsedMs = currentCounter.time - currentCounter.lastTime;
this._trackPreAggregatedMetric({
name: "Exceptions",
dimensions: currentCounter.dimensions,
value: intervalExceptions,
count: intervalExceptions,
aggregationInterval: elapsedMs,
metricType: Constants.MetricId.EXCEPTIONS_COUNT,
});

if (elapsedMs > 0) {
if (intervalExceptions > 0) {
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
this._trackPreAggregatedMetric({
name: "Exceptions",
dimensions: currentCounter.dimensions,
value: intervalExceptions,
count: intervalExceptions,
aggregationInterval: elapsedMs,
metricType: Constants.MetricId.EXCEPTIONS_COUNT,
});
}
}
// Set last counters
currentCounter.lastTotalCount = currentCounter.totalCount;
currentCounter.lastTime = currentCounter.time;
Expand All @@ -239,17 +243,21 @@ class AutoCollectPreAggregatedMetrics {
private _trackTraceMetrics() {
for (let i = 0; i < AutoCollectPreAggregatedMetrics._traceCountersCollection.length; i++) {
var currentCounter = AutoCollectPreAggregatedMetrics._traceCountersCollection[i];
currentCounter.time = +new Date;
var intervalTraces = (currentCounter.totalCount - currentCounter.lastTotalCount) || 0;
var elapsedMs = currentCounter.time - currentCounter.lastTime;
this._trackPreAggregatedMetric({
name: "Traces",
dimensions: currentCounter.dimensions,
value: intervalTraces,
count: intervalTraces,
aggregationInterval: elapsedMs,
metricType: Constants.MetricId.TRACES_COUNT,
});

if (elapsedMs > 0) {
if (intervalTraces > 0) {
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
this._trackPreAggregatedMetric({
name: "Traces",
dimensions: currentCounter.dimensions,
value: intervalTraces,
count: intervalTraces,
aggregationInterval: elapsedMs,
metricType: Constants.MetricId.TRACES_COUNT,
});
}
}
// Set last counters
currentCounter.lastTotalCount = currentCounter.totalCount;
currentCounter.lastTime = currentCounter.time;
Expand Down
28 changes: 12 additions & 16 deletions Tests/AutoCollection/Statsbeat.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ describe("AutoCollection/Statsbeat", () => {
const spy = sandbox.spy(statsBeat["_sender"], "send");
statsBeat.countRequest(123, "testEndpointHost", 123, true);
statsBeat.setCodelessAttach();
statsBeat.trackShortIntervalStatsbeats();
setTimeout(() => {
statsBeat.trackShortIntervalStatsbeats().then(() => {
assert.equal(spy.callCount, 2, "should call sender");
let envelope = spy.args[1][0][0];
assert.equal(envelope.name, "Statsbeat");
Expand All @@ -130,7 +129,7 @@ describe("AutoCollection/Statsbeat", () => {
assert.ok(baseData.properties["version"]);
statsBeat.enable(false);
done();
}, 10);
});
});

it("Track duration", (done) => {
Expand All @@ -139,8 +138,7 @@ describe("AutoCollection/Statsbeat", () => {
const spy = sandbox.spy(statsBeat["_sender"], "send");
statsBeat.countRequest(0, "test", 1000, true);
statsBeat.countRequest(0, "test", 500, false);
statsBeat.trackShortIntervalStatsbeats();
setImmediate(() => {
statsBeat.trackShortIntervalStatsbeats().then((error) => {
assert.equal(spy.callCount, 2, "should call sender");
let envelope = spy.args[1][0][0];
let baseData: Contracts.MetricData = envelope.data.baseData;
Expand All @@ -166,8 +164,7 @@ describe("AutoCollection/Statsbeat", () => {
statsBeat.countRetry(0, "test");
statsBeat.countThrottle(0, "test");
statsBeat.countException(0, "test");
statsBeat.trackShortIntervalStatsbeats();
setImmediate(() => {
statsBeat.trackShortIntervalStatsbeats().then(() => {
assert.equal(spy.callCount, 2, "should call sender");
let envelope = spy.args[1][0][1];
let baseData: Contracts.MetricData = envelope.data.baseData;
Expand Down Expand Up @@ -198,7 +195,7 @@ describe("AutoCollection/Statsbeat", () => {
const statsBeat: Statsbeat = new Statsbeat(config);
statsBeat.enable(true);
const spy = sandbox.spy(statsBeat["_sender"], "send");
setTimeout(() => {
setImmediate(() => {
let envelope = spy.args[0][0][0];
let baseData: Contracts.MetricData = envelope.data.baseData;
assert.equal(baseData.metrics[0].name, "Attach");
Expand All @@ -213,15 +210,15 @@ describe("AutoCollection/Statsbeat", () => {
assert.ok(baseData.properties["version"]);
statsBeat.enable(false);
done();
}, 10)
})
});

it("Track feature Statbeat", (done) => {
const statsBeat: Statsbeat = new Statsbeat(config);
statsBeat.enable(true);
statsBeat.addFeature(Constants.StatsbeatFeature.DISK_RETRY);
const spy = sandbox.spy(statsBeat["_sender"], "send");
setTimeout(() => {
setImmediate(() => {
let envelope = spy.args[0][0][2];
let baseData: Contracts.MetricData = envelope.data.baseData;
assert.equal(baseData.metrics[0].name, "Feature");
Expand All @@ -237,15 +234,15 @@ describe("AutoCollection/Statsbeat", () => {
assert.ok(baseData.properties["version"]);
statsBeat.enable(false);
done();
}, 10)
})
});

it("Track instrumentation Statbeat", (done) => {
const statsBeat: Statsbeat = new Statsbeat(config);
statsBeat.enable(true);
statsBeat.addInstrumentation(Constants.StatsbeatInstrumentation.AZURE_CORE_TRACING);
const spy = sandbox.spy(statsBeat["_sender"], "send");
setTimeout(() => {
setImmediate(() => {
let envelope = spy.args[0][0][1];
let baseData: Contracts.MetricData = envelope.data.baseData;
assert.equal(baseData.metrics[0].name, "Feature");
Expand All @@ -261,7 +258,7 @@ describe("AutoCollection/Statsbeat", () => {
assert.ok(baseData.properties["version"]);
statsBeat.enable(false);
done();
}, 10)
})
});

it("Instrumentations", () => {
Expand Down Expand Up @@ -295,8 +292,7 @@ describe("AutoCollection/Statsbeat", () => {
statsBeat.countRequest(0, "breezeFirstEndpoint", 100, true);
statsBeat.countRequest(1, "quickpulseEndpoint", 200, true);
statsBeat.countRequest(0, "breezeSecondEndpoint", 400, true);
statsBeat.trackShortIntervalStatsbeats();
setTimeout(() => {
statsBeat.trackShortIntervalStatsbeats().then(() => {
assert.equal(spy.callCount, 2, "should call sender");
let envelope = spy.args[1][0][0];
let baseData: Contracts.MetricData = envelope.data.baseData;
Expand All @@ -318,7 +314,7 @@ describe("AutoCollection/Statsbeat", () => {
assert.equal(baseData.properties["host"], "breezeSecondEndpoint");
statsBeat.enable(false);
done();
}, 100);
});
});
});
});