forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Azure Monitor Exporter] Add network Statsbeat Metrics (Azure#23425)
* Implement statsbeat state and begin setting up the statsbeatMetrics. * Stub statsBeat metrics file. * Add a number of custom features to the network statsbeat and begin defining them. * Add _getAzureComputeMetadata logic. * Get successful count using he observable gauge. * Add the rest of the counts to the statsbeat metrics. * Update the getAverageDuration method. * Add statsbeatMetricHandler to manage the meter provider. * Update the statsbeatMetricsHandler exporter config. * Converge the statsbeat logic into one file, begin fixing the average request duration logic, and start outlining where statsbeat changes need to be made in the base exporter. * Fix issues with statsbeat connection and setup. * Add duration counting on success and failure requests. * Make batched observable results in Statsbeat. * Testing begin. * Remove isStatsbeat being user configurable. * Fix typo. * Address code review comments. * Remove intentionally broken test. * Fix dependencies issues and format * WIP * WIP * Manage the isStatsbeatExporter state in the baseExpoerter properly. * WIP * Update statsbeat names. * Revert pnpm-lock.yaml file. * Fix tests * Fix how attributes are created and how EU endpoints are set. * Add statsbeat tests. * Fix package.json file. * Continue work on tests. * Write all non-AzureVM tests. * Save progress on attempt to fix the Azure VM test. * Fix Azure VM http call. * Fix test for AzureVM. * Remove comments. * Clean up further comments. * Update changelog. * Remove unneded sinon import. * Fix sinon types import. * Fix import build issues. * Update sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md Co-authored-by: Hector Hernandez <[email protected]> * Fix lint issues. * Address initial code review comments. * Clean up and optimize statsbeat metrics collection logic. * Update statsbeat logic to reduce checks and improve efficiency. * Fix format. * Remove last of unnecessary check. * Create statsbeatExporter to replace use of metricExporter for statsbeat. * Improve statsbeat metric exporting logic, handle legacy statusCodes, and document statsbeatExporter. * Fix formatting. Co-authored-by: Hector Hernandez <[email protected]>
- Loading branch information
1 parent
48deccf
commit 0d72600
Showing
13 changed files
with
983 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
sdk/monitor/monitor-opentelemetry-exporter/src/export/statsbeat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { context } from "@opentelemetry/api"; | ||
import { PushMetricExporter, ResourceMetrics } from "@opentelemetry/sdk-metrics"; | ||
import { ExportResult, ExportResultCode, suppressTracing } from "@opentelemetry/core"; | ||
import { AzureMonitorExporterOptions } from "../config"; | ||
import { TelemetryItem as Envelope } from "../generated"; | ||
import { resourceMetricsToEnvelope } from "../utils/metricUtils"; | ||
import { AzureMonitorBaseExporter } from "./base"; | ||
|
||
/** | ||
* @internal | ||
* Azure Monitor Statsbeat Exporter | ||
*/ | ||
export class _AzureMonitorStatsbeatExporter | ||
extends AzureMonitorBaseExporter | ||
implements PushMetricExporter | ||
{ | ||
/** | ||
* Flag to determine if the Exporter is shutdown. | ||
*/ | ||
private _isShutdown = false; | ||
|
||
/** | ||
* Initializes a new instance of the AzureMonitorStatsbeatExporter class. | ||
* @param options - Exporter configuration | ||
*/ | ||
constructor(options: AzureMonitorExporterOptions) { | ||
super(options, true); | ||
} | ||
|
||
/** | ||
* Export Statsbeat metrics. | ||
*/ | ||
async export( | ||
metrics: ResourceMetrics, | ||
resultCallback: (result: ExportResult) => void | ||
): Promise<void> { | ||
if (this._isShutdown) { | ||
setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0); | ||
return; | ||
} | ||
|
||
let envelopes: Envelope[] = resourceMetricsToEnvelope( | ||
metrics, | ||
this._instrumentationKey, | ||
true // isStatsbeat flag passed to create a Statsbeat envelope. | ||
); | ||
// Supress tracing until OpenTelemetry Metrics SDK support it | ||
context.with(suppressTracing(context.active()), async () => { | ||
resultCallback(await this._exportEnvelopes(envelopes)); | ||
}); | ||
} | ||
|
||
/** | ||
* Shutdown AzureMonitorStatsbeatExporter. | ||
*/ | ||
public async shutdown(): Promise<void> { | ||
this._isShutdown = true; | ||
return this._shutdown(); | ||
} | ||
|
||
/** | ||
* Force flush. | ||
*/ | ||
public async forceFlush(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} |
Oops, something went wrong.