Skip to content

Commit

Permalink
[Multi-Region] Adding pipeline changes for Multi region load tests (#93
Browse files Browse the repository at this point in the history
…) (#94)

* multi region changes

* update version

* Pr comments

* compile ts
  • Loading branch information
venkatr21 committed May 21, 2024
1 parent a74772c commit bf30be5
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 36 deletions.
14 changes: 12 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.defaultYaml = {
description: 'Load test website home page',
testPlan: 'SampleTest.jmx',
testType: 'JMX',
engineInstances: 1,
engineInstances: 2,
subnetId: '/subscriptions/abcdef01-2345-6789-0abc-def012345678/resourceGroups/sample-rg/providers/Microsoft.Network/virtualNetworks/load-testing-vnet/subnets/load-testing',
publicIPDisabled: false,
configurationFiles: ['sampledata.csv'],
Expand All @@ -36,5 +36,15 @@ exports.defaultYaml = {
],
autoStop: { errorPercentage: 80, timeWindow: 60 },
keyVaultReferenceIdentity: '/subscriptions/abcdef01-2345-6789-0abc-def012345678/resourceGroups/sample-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/sample-identity',
keyVaultReferenceIdentityType: 'SystemAssigned'
keyVaultReferenceIdentityType: 'SystemAssigned',
regionalLoadTestConfig: [
{
region: 'eastus',
engineInstances: 1,
},
{
region: 'westus',
engineInstances: 1,
}
]
};
22 changes: 11 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function run() {
}
function getTestAPI(validate) {
return __awaiter(this, void 0, void 0, function* () {
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
let header = yield map.getTestHeader();
let testResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
Expand Down Expand Up @@ -115,7 +115,7 @@ function getTestAPI(validate) {
}
function deleteFileAPI(filename) {
return __awaiter(this, void 0, void 0, function* () {
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
let header = yield map.getTestHeader();
let delFileResult = yield util.httpClientRetries(urlSuffix, header, 'del', 3, "");
Expand All @@ -128,7 +128,7 @@ function deleteFileAPI(filename) {
}
function createTestAPI() {
return __awaiter(this, void 0, void 0, function* () {
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
var createData = map.createTestData();
let header = yield map.createTestHeader();
Expand Down Expand Up @@ -191,7 +191,7 @@ function uploadTestPlan() {
let retry = 5;
let filepath = map.getTestFile();
let filename = map.getFileName(filepath);
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
if (map.getTestKind() == util_2.TestKind.URL) {
urlSuffix = urlSuffix + ("&fileType=" + FileType.URL_TEST_CONFIG);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ function uploadConfigFile() {
if (configFiles != undefined && configFiles.length > 0) {
for (let filepath of configFiles) {
let filename = map.getFileName(filepath);
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
let headers = yield map.UploadAndValidateHeader();
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, filepath, true);
Expand All @@ -254,14 +254,14 @@ function uploadConfigFile() {
});
}
function uploadZipArtifacts() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
var _a;
let zipFiles = map.getZipFiles();
if (zipFiles != undefined && zipFiles.length > 0) {
console.log("Uploading and validating the zip artifacts");
for (let filepath of zipFiles) {
let filename = map.getFileName(filepath);
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm2023Version + "&fileType=" + FileType.ZIPPED_ARTIFACTS;
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion + "&fileType=" + FileType.ZIPPED_ARTIFACTS;
urlSuffix = baseURL + urlSuffix;
let headers = yield map.UploadAndValidateHeader();
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, filepath, true);
Expand All @@ -278,7 +278,7 @@ function uploadZipArtifacts() {
let zipInvalid = false;
let zipFailureReason = "";
while (maxAllowedTime > (new Date()) && flagValidationPending) {
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
let header = yield map.getTestHeader();
let testResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
Expand Down Expand Up @@ -324,7 +324,7 @@ function uploadPropertyFile() {
let propertyFile = map.getPropertyFile();
if (propertyFile != undefined) {
let filename = map.getFileName(propertyFile);
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm2023Version + "&fileType=" + FileType.USER_PROPERTIES;
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion + "&fileType=" + FileType.USER_PROPERTIES;
urlSuffix = baseURL + urlSuffix;
let headers = yield map.UploadAndValidateHeader();
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, propertyFile);
Expand All @@ -342,7 +342,7 @@ function createTestRun() {
return __awaiter(this, void 0, void 0, function* () {
const tenantId = map.getTenantId();
const testRunId = util.getUniqueId();
var urlSuffix = "test-runs/" + testRunId + "?tenantId=" + tenantId + "&api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "test-runs/" + testRunId + "?tenantId=" + tenantId + "&api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
const ltres = core.getInput('loadTestResource');
const runDisplayName = core.getInput('loadTestRunName');
Expand Down Expand Up @@ -378,7 +378,7 @@ function createTestRun() {
}
function getTestRunAPI(testRunId, testStatus, startTime) {
return __awaiter(this, void 0, void 0, function* () {
var urlSuffix = "test-runs/" + testRunId + "?api-version=" + util.apiConstants.tm2023Version;
var urlSuffix = "test-runs/" + testRunId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
urlSuffix = baseURL + urlSuffix;
while (!util.isTerminalTestStatus(testStatus)) {
let header = yield map.getTestRunHeader();
Expand Down
23 changes: 20 additions & 3 deletions lib/mappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var armEndpoint = "https://management.azure.com";
var tenantId = "";
var yamlFile = "";
var passFailCriteria = [];
var regionalLoadTestConfig = null;
var autoStop = null;
var kvRefId = null;
var kvRefType = null;
Expand All @@ -70,6 +71,7 @@ var splitCSVs = null;
var certificate = null;
let kind;
let publicIPDisabled = false;
;
var paramType;
(function (paramType) {
paramType["env"] = "env";
Expand Down Expand Up @@ -103,11 +105,12 @@ function createTestData() {
testId: testId,
description: testdesc,
displayName: displayName,
quickStartTest: false,
quickStartTest: false, // always quick test will be false because GH-actions doesnot support it now.
loadTestConfiguration: {
engineInstances: engineInstances,
splitAllCSVs: splitCSVs,
optionalLoadTestConfig: null
optionalLoadTestConfig: null,
regionalLoadTestConfig: regionalLoadTestConfig,
},
secrets: secretsYaml,
kind: kind,
Expand Down Expand Up @@ -209,8 +212,8 @@ function getResourceId() {
}
exports.getResourceId = getResourceId;
function getInputParams() {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
yield setEndpointAndScope();
yield getAccessToken(armTokenScope);
yamlFile = core.getInput("loadTestConfigFile");
Expand Down Expand Up @@ -296,6 +299,9 @@ function getInputParams() {
kvRefType = "UserAssigned";
kvRefId = config.keyVaultReferenceIdentity;
}
if (config.regionalLoadTestConfig != undefined) {
regionalLoadTestConfig = getMultiRegionLoadTestConfig(config.regionalLoadTestConfig);
}
getRunTimeParams();
validateTestRunParams();
if (testId === "" ||
Expand Down Expand Up @@ -653,3 +659,14 @@ function getAutoStopCriteria(autoStopInput) {
autoStop = data;
}
}
function getMultiRegionLoadTestConfig(multiRegionalConfig) {
let parsedMultiRegionConfiguration = [];
multiRegionalConfig.forEach(regionConfig => {
let data = {
region: regionConfig.region,
engineInstances: regionConfig.engineInstances,
};
parsedMultiRegionConfiguration.push(data);
});
return parsedMultiRegionConfiguration;
}
37 changes: 30 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var TestKind;
(function (TestKind) {
TestKind["URL"] = "URL";
TestKind["JMX"] = "JMX"; // default
})(TestKind = exports.TestKind || (exports.TestKind = {}));
})(TestKind || (exports.TestKind = TestKind = {}));
const validConditionList = {
'response_time_ms': ['>', '<'],
'requests_per_sec': ['>', '<'],
Expand All @@ -64,15 +64,16 @@ const validConditionList = {
};
var apiConstants;
(function (apiConstants) {
apiConstants.tm20240301previewVersion = '2024-03-01-preview';
apiConstants.tm2023Version = '2023-04-01-preview';
apiConstants.tm2022Version = '2022-11-01';
apiConstants.cp2022Version = '2022-12-01';
})(apiConstants = exports.apiConstants || (exports.apiConstants = {}));
})(apiConstants || (exports.apiConstants = apiConstants = {}));
var ManagedIdentityType;
(function (ManagedIdentityType) {
ManagedIdentityType["SystemAssigned"] = "SystemAssigned";
ManagedIdentityType["UserAssigned"] = "UserAssigned";
})(ManagedIdentityType = exports.ManagedIdentityType || (exports.ManagedIdentityType = {}));
})(ManagedIdentityType || (exports.ManagedIdentityType = ManagedIdentityType = {}));
function uploadFileData(filepath) {
try {
let filedata = fs.readFileSync(filepath);
Expand All @@ -89,8 +90,8 @@ function uploadFileData(filepath) {
}
exports.uploadFileData = uploadFileData;
const correlationHeader = 'x-ms-correlation-request-id';
function httpClientRetries(urlSuffix, header, method, retries = 1, data, isUploadCall = true) {
return __awaiter(this, void 0, void 0, function* () {
function httpClientRetries(urlSuffix_1, header_1, method_1) {
return __awaiter(this, arguments, void 0, function* (urlSuffix, header, method, retries = 1, data, isUploadCall = true) {
let httpResponse;
try {
let correlationId = `gh-actions-${getUniqueId()}`;
Expand Down Expand Up @@ -226,8 +227,8 @@ function printClientMetrics(obj) {
}
exports.printClientMetrics = printClientMetrics;
function getStatisticsFile(obj) {
var obj;
return __awaiter(this, void 0, void 0, function* () {
var obj;
let target = path.join('dropResults', "reports");
try {
var filepath = path.join('dropResults', 'results.zip');
Expand Down Expand Up @@ -321,7 +322,7 @@ function inValidEngineInstances(engines) {
return false;
}
function checkValidityYaml(givenYaml) {
var _a;
var _a, _b;
if (!isDictionary(givenYaml)) {
return { valid: false, error: `Invalid YAML syntax.` };
}
Expand Down Expand Up @@ -422,6 +423,28 @@ function checkValidityYaml(givenYaml) {
return { valid: false, error: 'Invalid value for "autoStop", for disabling auto stop use "autoStop: disable"' };
}
}
if (givenYaml.regionalLoadTestConfig) {
if (!Array.isArray(givenYaml.regionalLoadTestConfig)) {
return { valid: false, error: `The value "${givenYaml.regionalLoadTestConfig}" for regionalLoadTestConfig is invalid. Provide a valid list of region configuration for Multi-region load test.` };
}
if (givenYaml.regionalLoadTestConfig.length < 2) {
return { valid: false, error: `Multi-region load tests should contain a minimum of 2 geographic regions in the configuration.` };
}
var totalEngineCount = 0;
for (let i = 0; i < givenYaml.regionalLoadTestConfig.length; i++) {
if ((0, util_1.isNullOrUndefined)(givenYaml.regionalLoadTestConfig[i].region) || typeof givenYaml.regionalLoadTestConfig[i].region != 'string' || givenYaml.regionalLoadTestConfig[i].region == "") {
return { valid: false, error: `The value "${givenYaml.regionalLoadTestConfig[i].region}" for region in regionalLoadTestConfig is invalid. Provide a valid string.` };
}
if ((0, util_1.isNullOrUndefined)(givenYaml.regionalLoadTestConfig[i].engineInstances) || isNaN(givenYaml.regionalLoadTestConfig[i].engineInstances) || inValidEngineInstances(givenYaml.regionalLoadTestConfig[i].engineInstances)) {
return { valid: false, error: `The value "${givenYaml.regionalLoadTestConfig[i].engineInstances}" for engineInstances in regionalLoadTestConfig is invalid. The value should be an integer between 1 and 400.` };
}
totalEngineCount += givenYaml.regionalLoadTestConfig[i].engineInstances;
}
let engineInstances = (_b = givenYaml.engineInstances) !== null && _b !== void 0 ? _b : 1;
if (totalEngineCount != givenYaml.engineInstances) {
return { valid: false, error: `The sum of engineInstances in regionalLoadTestConfig should be equal to the value of totalEngineInstances "${engineInstances}" in the test configuration.` };
}
}
return { valid: true, error: "" };
}
exports.checkValidityYaml = checkValidityYaml;
Expand Down
14 changes: 12 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const defaultYaml : any =
description: 'Load test website home page',
testPlan: 'SampleTest.jmx',
testType: 'JMX',
engineInstances: 1,
engineInstances: 2,
subnetId: '/subscriptions/abcdef01-2345-6789-0abc-def012345678/resourceGroups/sample-rg/providers/Microsoft.Network/virtualNetworks/load-testing-vnet/subnets/load-testing',
publicIPDisabled: false,
configurationFiles: [ 'sampledata.csv' ],
Expand All @@ -34,5 +34,15 @@ export const defaultYaml : any =
],
autoStop: { errorPercentage: 80, timeWindow: 60 },
keyVaultReferenceIdentity: '/subscriptions/abcdef01-2345-6789-0abc-def012345678/resourceGroups/sample-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/sample-identity',
keyVaultReferenceIdentityType: 'SystemAssigned'
keyVaultReferenceIdentityType: 'SystemAssigned',
regionalLoadTestConfig: [
{
region: 'eastus',
engineInstances: 1,
},
{
region: 'westus',
engineInstances: 1,
}
]
}
Loading

0 comments on commit bf30be5

Please sign in to comment.