Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blueww committed Dec 11, 2024
1 parent f7b2aba commit 39f9f0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 204 deletions.
4 changes: 0 additions & 4 deletions src/common/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ args
export default class Environment implements IEnvironment {
private flags = args.parse(process.argv);

//public ToString(): string | undefined {
// return Object.getOwnPropertyNames(this.flags).join(", ");
//}

public blobHost(): string | undefined {
return this.flags.blobHost;
}
Expand Down
224 changes: 24 additions & 200 deletions src/common/Telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class AzuriteTelemetryClient {
public static isVSC = false;

// Debug options
private static isDebug = false; // false in production, true in development
private static requestCollectPercentage = AzuriteTelemetryClient.isDebug ? 100 : 100;
private static isDebug = true; // false in production, true in development
private static requestCollectPercentage = AzuriteTelemetryClient.isDebug ? 100 : 1;
private static enableAppInsightLog = AzuriteTelemetryClient.isDebug? true : false;
private static cloudRole = AzuriteTelemetryClient.isDebug ? "AzuriteTest" : "Azurite_V1.0";
// 0 means send as soon as it's collected, use it in both debug and release mode, since set any other value will make Azurite exist slower
Expand Down Expand Up @@ -197,122 +197,34 @@ export class AzuriteTelemetryClient {
}

AzuriteTelemetryClient.requestClient.trackRequest(
{
name:reqName,
url:context.request !== undefined ? AzuriteTelemetryClient.GetRequestUri(context.request.getEndpoint()) : "",
duration:context.startTime?((new Date()).getTime() - context.startTime?.getTime()):0,
resultCode:context.response?.getStatusCode()??0,
success:(context.response?.getStatusCode() ?? 500) <= 399,
id: context.contextId, // Request ID
source: context.request?.getHeader("user-agent"), // User Agent
properties: requestProperties,
contextObjects:
{
name:reqName,
url:context.request !== undefined ? AzuriteTelemetryClient.GetRequestUri(context.request.getEndpoint()) : "",
duration:context.startTime?((new Date()).getTime() - context.startTime?.getTime()):0,
resultCode:context.response?.getStatusCode()??0,
success:(context.response?.getStatusCode() ?? 500) <= 399,
id: context.contextId, // Request ID
source: context.request?.getHeader("user-agent"), // User Agent
properties: requestProperties,
contextObjects:
{
operationId: "",
operationParentId: "",
operationName: "test",
operation_Name: "test",
appName: ""
}
});
operationId: "",
operationParentId: "",
operationName: "test",
operation_Name: "test",
appName: ""
}
});

logger.verbose(`Send ${serviceType} telemetry: ` + reqName, context.contextId === undefined ? context.contextID : context.contextId);
}
logger.verbose(`Send ${serviceType} telemetry: ` + reqName, context.contextId === undefined ? context.contextID : context.contextId);
}
catch (e)
{
logger.warn(`Fail to telemetry a ${serviceType} request, error: ` + e.message);
}
}

// public static TraceQueueRequest(context: QueueContext) {
// try{
// if (AzuriteTelemetryClient.enableTelemetry && AzuriteTelemetryClient.requestClient !== undefined)
// {
// AzuriteTelemetryClient._totalQueueRequestCount++;
// let requestProperties: { [key: string]: any } = {
// apiVersion: "v"+context.request?.getHeader("x-ms-version"),
// authorization: context.request !== undefined ? AzuriteTelemetryClient.GetRequestAuthentication(context.request.getHeader("authorization"), context.request.getQuery("sig")) : "",
// instanceID: AzuriteTelemetryClient.instanceID,
// sessionID: AzuriteTelemetryClient.sessionID,
// totalReqs:AzuriteTelemetryClient._totalQueueRequestCount,
// };
// if (context.request?.getHeader("content-length") !== undefined)
// {
// requestProperties["requestContentSize"] = context.request?.getHeader("content-length");
// }
// // Responds "content-length" Not work, as responds normally don't have "content-length" header even has body.
// AzuriteTelemetryClient.requestClient.trackRequest(
// {
// name:"Q_" + QueueOperation[context.operation??0],
// url:context.request !== undefined ? AzuriteTelemetryClient.GetRequestUri(context.request.getEndpoint()) : "",
// duration:context.startTime?((new Date()).getTime() - context.startTime?.getTime()):0,
// resultCode:context.response?.getStatusCode()??0,
// success:context.response?.getStatusCode()?.toString().startsWith("2")??false,
// id: context.contextID,
// source: context.request?.getHeader("user-agent"),
// properties: requestProperties,
// contextObjects:
// {
// operationId: "",
// operationParentId: "",
// operationName: "test",
// operation_Name: "test",
// appName: ""
// }
// });
// }
// logger.verbose('Send queue telemetry: ' + QueueOperation[context.operation??0], context.contextID);
// }
// catch (e)
// {
// logger.warn('Fail to telemetry a queue request, error: ' + e.message);
// }
// }

// public static TraceTableRequest(context: TableContext) {
// try{
// if (AzuriteTelemetryClient.enableTelemetry && AzuriteTelemetryClient.requestClient !== undefined)
// {
// AzuriteTelemetryClient._totalTableRequestCount++;
// let requestProperties: { [key: string]: any } = {
// apiVersion: "v"+context.request?.getHeader("x-ms-version"),
// authorization: context.request !== undefined ? AzuriteTelemetryClient.GetRequestAuthentication(context.request.getHeader("authorization"), context.request.getQuery("sig")) : "",
// instanceID: AzuriteTelemetryClient.instanceID,
// sessionID: AzuriteTelemetryClient.sessionID,
// totalReqs:AzuriteTelemetryClient._totalTableRequestCount,
// };
// if (context.request?.getHeader("content-length") !== undefined)
// {
// requestProperties["requestContentSize"] = context.request?.getHeader("content-length");
// }
// AzuriteTelemetryClient.requestClient.trackRequest(
// {
// name:"T_" + TableOperation[context.operation??0],
// url:context.request !== undefined ? AzuriteTelemetryClient.GetRequestUri(context.request.getEndpoint()) : "",
// duration:context.startTime?((new Date()).getTime() - context.startTime?.getTime()):0,
// resultCode:context.response?.getStatusCode()??0,
// success:context.response?.getStatusCode()?.toString().startsWith("2")??false,
// id: context.contextID,
// source: context.request?.getHeader("user-agent"),
// properties: requestProperties,
// contextObjects:
// {
// operationId: "",
// operationParentId: "",
// operationName: "test",
// operation_Name: "test",
// appName: ""
// }
// });
// }
// logger.verbose('Send table telemetry: ' + TableOperation[context.operation??0], context.contextID);
// }
// catch (e)
// {
// logger.warn('Fail to telemetry a table request, error: ' + e.message);
// }
// }

public static async TraceStartEvent(serviceType: string = "") {
try{
if (AzuriteTelemetryClient.enableTelemetry && AzuriteTelemetryClient.eventClient !== undefined)
Expand All @@ -325,8 +237,8 @@ export class AzuriteTelemetryClient {
parameters: await AzuriteTelemetryClient.GetAllParameterString()
}
});
logger.verbose('Send start telemetry');
}
logger.verbose('Send start telemetry');
}
catch (e)
{
Expand All @@ -350,8 +262,8 @@ export class AzuriteTelemetryClient {
totalEgress: AzuriteTelemetryClient._totalEgressSize,
}
});
logger.verbose('Send stop telemetry');
}
logger.verbose('Send stop telemetry');
}
catch (e)
{
Expand Down Expand Up @@ -497,95 +409,7 @@ export class AzuriteTelemetryClient {
}
});
}

// if (typeof AzuriteTelemetryClient.env?.blobHost === "function" && AzuriteTelemetryClient.env?.blobHost() !== undefined && AzuriteTelemetryClient.env?.blobHost() !== "127.0.0.1")
// {
// parameters += "blobHost,";
// }
// if (typeof AzuriteTelemetryClient.env?.queueHost === "function" && AzuriteTelemetryClient.env?.queueHost() !== undefined && AzuriteTelemetryClient.env?.queueHost() !== "127.0.0.1")
// {
// parameters += "queueHost,";
// }
// if (typeof AzuriteTelemetryClient.env?.tableHost === "function" && AzuriteTelemetryClient.env?.tableHost() !== undefined && AzuriteTelemetryClient.env?.tableHost() !== "127.0.0.1")
// {
// parameters += "tableHost,";
// }
// if (typeof AzuriteTelemetryClient.env?.blobPort === "function" && AzuriteTelemetryClient.env?.blobPort() !== undefined && AzuriteTelemetryClient.env?.blobPort() !== 10000)
// {
// parameters += "blobPort,";
// }
// if (typeof AzuriteTelemetryClient.env?.queuePort === "function" && AzuriteTelemetryClient.env?.queuePort() !== undefined && AzuriteTelemetryClient.env?.queuePort() !== 10001)
// {
// parameters += "queuePort,";
// }
// if (typeof AzuriteTelemetryClient.env?.tablePort === "function" && AzuriteTelemetryClient.env?.tablePort() !== undefined && AzuriteTelemetryClient.env?.tablePort() !== 10002)
// {
// parameters += "tablePort,";
// }
// if (typeof AzuriteTelemetryClient.env?.blobKeepAliveTimeout === "function" && AzuriteTelemetryClient.env?.blobKeepAliveTimeout() !== undefined && AzuriteTelemetryClient.env?.blobKeepAliveTimeout() !== 5)
// {
// parameters += "blobKeepAliveTimeout,";
// }
// if (typeof AzuriteTelemetryClient.env?.queueKeepAliveTimeout === "function" && AzuriteTelemetryClient.env?.queueKeepAliveTimeout() !== undefined && AzuriteTelemetryClient.env?.queueKeepAliveTimeout() !== 5)
// {
// parameters += "queueKeepAliveTimeout,";
// }
// if (typeof AzuriteTelemetryClient.env?.tableKeepAliveTimeout === "function" && AzuriteTelemetryClient.env?.tableKeepAliveTimeout() !== undefined && AzuriteTelemetryClient.env?.tableKeepAliveTimeout() !== 5)
// {
// parameters += "tableKeepAliveTimeout,";
// }
// if (typeof AzuriteTelemetryClient.env?.location === "function" && (await AzuriteTelemetryClient.env?.location()) !== undefined)
// {
// parameters += "location,";
// }
// if (typeof AzuriteTelemetryClient.env?.silent === "function" && AzuriteTelemetryClient.env?.silent())
// {
// parameters += "silent,";
// }
// if (typeof AzuriteTelemetryClient.env?.loose === "function" && AzuriteTelemetryClient.env?.loose())
// {
// parameters += "loose,";
// }
// if (typeof AzuriteTelemetryClient.env?.skipApiVersionCheck === "function" && AzuriteTelemetryClient.env?.skipApiVersionCheck())
// {
// parameters += "skipApiVersionCheck,";
// }
// if (typeof AzuriteTelemetryClient.env?.disableProductStyleUrl === "function" && AzuriteTelemetryClient.env?.disableProductStyleUrl())
// {
// parameters += "disableProductStyleUrl,";
// }
// if (typeof AzuriteTelemetryClient.env?.cert === "function" && AzuriteTelemetryClient.env?.cert() !== undefined)
// {
// parameters += "cert,";
// }
// if (typeof AzuriteTelemetryClient.env?.key === "function" && AzuriteTelemetryClient.env?.key() !== undefined)
// {
// parameters += "key,";
// }
// if (typeof AzuriteTelemetryClient.env?.pwd === "function" && AzuriteTelemetryClient.env?.pwd() !== undefined)
// {
// parameters += "pwd,";
// }
// if (typeof AzuriteTelemetryClient.env?.oauth === "function" && AzuriteTelemetryClient.env?.oauth() !== undefined)
// {
// parameters += "oauth,";
// }
// if (typeof AzuriteTelemetryClient.env?.inMemoryPersistence === "function" && AzuriteTelemetryClient.env?.inMemoryPersistence())
// {
// parameters += "inMemoryPersistence,";
// }
// if (typeof AzuriteTelemetryClient.env?.extentMemoryLimit === "function" && AzuriteTelemetryClient.env?.extentMemoryLimit() !== undefined)
// {
// parameters += "extentMemoryLimit,";
// }
// if (typeof AzuriteTelemetryClient.env?.disableTelemetry === "function" && AzuriteTelemetryClient.env?.disableTelemetry())
// {
// parameters += "disableTelemetry,";
// }
// if (typeof AzuriteTelemetryClient.env?.debug === "function" && (await AzuriteTelemetryClient.env?.debug()) !== undefined)
// {
// parameters += "debug,";
// }

return parameters.endsWith(",") ? parameters.substring(0, parameters.length - 1) : parameters;
}
}

0 comments on commit 39f9f0a

Please sign in to comment.