Skip to content

Commit

Permalink
[Synthetics] Add license issued_to value in request (elastic#155600)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored and nikitaindik committed Apr 25, 2023
1 parent 79ee2c1 commit 201f0d3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ import { UptimeServerSetup } from '../legacy_uptime/lib/adapters';
import { ServiceConfig } from '../../common/config';
import axios from 'axios';
import { LocationStatus, PublicLocations } from '../../common/runtime_types';
import { LicenseGetResponse } from '@elastic/elasticsearch/lib/api/types';

const licenseMock: LicenseGetResponse = {
license: {
status: 'active',
uid: '1d34eb9f-e66f-47d1-8d24-cd60d187587a',
type: 'trial',
issue_date: '2022-05-05T14:25:00.732Z',
issue_date_in_millis: 165176070074432,
expiry_date: '2022-06-04T14:25:00.732Z',
expiry_date_in_millis: 165435270073332,
max_nodes: 1000,
max_resource_units: null,
issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
issuer: 'elasticsearch',
start_date_in_millis: -1,
},
};

jest.mock('axios', () => jest.fn());
jest.mock('@kbn/server-http-tools', () => ({
Expand Down Expand Up @@ -167,7 +185,7 @@ describe('callAPI', () => {
await apiClient.callAPI('POST', {
monitors: testMonitors,
output,
licenseLevel: 'trial',
license: licenseMock.license,
});

expect(spy).toHaveBeenCalledTimes(3);
Expand All @@ -181,7 +199,7 @@ describe('callAPI', () => {
monitor.locations.some((loc: any) => loc.id === 'us_central')
),
output,
licenseLevel: 'trial',
license: licenseMock.license,
},
'POST',
devUrl
Expand All @@ -195,7 +213,7 @@ describe('callAPI', () => {
monitor.locations.some((loc: any) => loc.id === 'us_central_qa')
),
output,
licenseLevel: 'trial',
license: licenseMock.license,
},
'POST',
'https://qa.service.elstc.co'
Expand All @@ -209,7 +227,7 @@ describe('callAPI', () => {
monitor.locations.some((loc: any) => loc.id === 'us_central_staging')
),
output,
licenseLevel: 'trial',
license: licenseMock.license,
},
'POST',
'https://qa.service.stg.co'
Expand All @@ -223,6 +241,7 @@ describe('callAPI', () => {
output,
stack_version: '8.7.0',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
Authorization: 'Basic ZGV2OjEyMzQ1',
Expand All @@ -242,6 +261,7 @@ describe('callAPI', () => {
output,
stack_version: '8.7.0',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
Authorization: 'Basic ZGV2OjEyMzQ1',
Expand All @@ -261,6 +281,7 @@ describe('callAPI', () => {
output,
stack_version: '8.7.0',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
Authorization: 'Basic ZGV2OjEyMzQ1',
Expand Down Expand Up @@ -324,7 +345,7 @@ describe('callAPI', () => {
await apiClient.callAPI('POST', {
monitors: testMonitors,
output,
licenseLevel: 'platinum',
license: licenseMock.license,
});

expect(axiosSpy).toHaveBeenNthCalledWith(1, {
Expand All @@ -333,7 +354,8 @@ describe('callAPI', () => {
is_edit: undefined,
output,
stack_version: '8.7.0',
license_level: 'platinum',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
'x-kibana-version': '8.7.0',
Expand Down Expand Up @@ -376,7 +398,7 @@ describe('callAPI', () => {
await apiClient.runOnce({
monitors: testMonitors,
output,
licenseLevel: 'trial',
license: licenseMock.license,
});

expect(axiosSpy).toHaveBeenNthCalledWith(1, {
Expand All @@ -386,6 +408,7 @@ describe('callAPI', () => {
output,
stack_version: '8.7.0',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
'x-kibana-version': '8.7.0',
Expand Down Expand Up @@ -428,7 +451,7 @@ describe('callAPI', () => {
await apiClient.syncMonitors({
monitors: testMonitors,
output,
licenseLevel: 'trial',
license: licenseMock.license,
});

expect(axiosSpy).toHaveBeenNthCalledWith(1, {
Expand All @@ -438,6 +461,7 @@ describe('callAPI', () => {
output,
stack_version: '8.7.0',
license_level: 'trial',
license_issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
},
headers: {
'x-kibana-version': '8.7.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { catchError, tap } from 'rxjs/operators';
import * as https from 'https';
import { SslConfig } from '@kbn/server-http-tools';
import { Logger } from '@kbn/core/server';
import { LicenseGetLicenseInformation } from '@elastic/elasticsearch/lib/api/types';
import { UptimeServerSetup } from '../legacy_uptime/lib/adapters';
import { sendErrorTelemetryEvents } from '../routes/telemetry/monitor_upgrade_sender';
import { MonitorFields, PublicLocations, ServiceLocationErrors } from '../../common/runtime_types';
Expand All @@ -27,7 +28,7 @@ export interface ServiceData {
};
endpoint?: 'monitors' | 'runOnce' | 'sync';
isEdit?: boolean;
licenseLevel: string;
license: LicenseGetLicenseInformation;
}

export class ServiceAPIClient {
Expand Down Expand Up @@ -142,7 +143,7 @@ export class ServiceAPIClient {

async callAPI(
method: 'POST' | 'PUT' | 'DELETE',
{ monitors: allMonitors, output, endpoint, isEdit, licenseLevel }: ServiceData
{ monitors: allMonitors, output, endpoint, isEdit, license }: ServiceData
) {
if (this.username === TEST_SERVICE_USERNAME) {
// we don't want to call service while local integration tests are running
Expand All @@ -159,7 +160,7 @@ export class ServiceAPIClient {
);
if (locMonitors.length > 0) {
const promise = this.callServiceEndpoint(
{ monitors: locMonitors, isEdit, endpoint, output, licenseLevel },
{ monitors: locMonitors, isEdit, endpoint, output, license },
method,
url
);
Expand Down Expand Up @@ -200,7 +201,7 @@ export class ServiceAPIClient {
}

async callServiceEndpoint(
{ monitors, output, endpoint = 'monitors', isEdit, licenseLevel }: ServiceData,
{ monitors, output, endpoint = 'monitors', isEdit, license }: ServiceData,
method: 'POST' | 'PUT' | 'DELETE',
baseUrl: string
) {
Expand Down Expand Up @@ -233,7 +234,8 @@ export class ServiceAPIClient {
output,
stack_version: this.stackVersion,
is_edit: isEdit,
license_level: licenseLevel,
license_level: license.type,
license_issued_to: license.issued_to,
},
headers: authHeader,
httpsAgent: this.getHttpsAgent(baseUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class SyntheticsService {
this.syncErrors = await this.apiClient.post({
monitors,
output,
licenseLevel: license.type,
license,
});
}
return this.syncErrors;
Expand All @@ -329,7 +329,7 @@ export class SyntheticsService {
monitors,
output,
isEdit,
licenseLevel: license.type,
license,
};

this.syncErrors = await this.apiClient.put(data);
Expand Down Expand Up @@ -372,7 +372,7 @@ export class SyntheticsService {
service.syncErrors = await this.apiClient.syncMonitors({
monitors,
output,
licenseLevel: license.type,
license,
});
} catch (e) {
sendErrorTelemetryEvents(service.logger, service.server.telemetry, {
Expand Down Expand Up @@ -406,7 +406,7 @@ export class SyntheticsService {
return await this.apiClient.runOnce({
monitors,
output,
licenseLevel: license.type,
license,
});
} catch (e) {
this.logger.error(e);
Expand All @@ -429,7 +429,7 @@ export class SyntheticsService {
const data = {
output,
monitors: this.formatConfigs(configs),
licenseLevel: license.type,
license,
};
return await this.apiClient.delete(data);
}
Expand All @@ -453,7 +453,7 @@ export class SyntheticsService {
const data = {
output,
monitors,
licenseLevel: license.type,
license,
};
return await this.apiClient.delete(data);
}
Expand Down

0 comments on commit 201f0d3

Please sign in to comment.