Skip to content

Commit bbccd31

Browse files
committed
Merge remote-tracking branch 'upstream/7.x' into backport/7.x/pr-83899
2 parents 622abee + 3b13e2f commit bbccd31

File tree

103 files changed

+4124
-978
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4124
-978
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"**/load-grunt-config/lodash": "^4.17.20",
9090
"**/minimist": "^1.2.5",
9191
"**/node-jose/node-forge": "^0.10.0",
92+
"**/prismjs": "1.22.0",
9293
"**/request": "^2.88.2",
9394
"**/trim": "0.0.3",
9495
"**/typescript": "4.0.2"

src/plugins/telemetry/public/services/telemetry_service.test.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,20 @@
1717
* under the License.
1818
*/
1919

20+
// ESLint disabled dot-notation we can access the private key telemetryService['http']
2021
/* eslint-disable dot-notation */
21-
const mockMomentValueOf = jest.fn();
22-
23-
jest.mock('moment', () => {
24-
return jest.fn().mockImplementation(() => {
25-
return {
26-
valueOf: mockMomentValueOf,
27-
};
28-
});
29-
});
3022

3123
import { mockTelemetryService } from '../mocks';
3224

3325
describe('TelemetryService', () => {
3426
describe('fetchTelemetry', () => {
3527
it('calls expected URL with 20 minutes - now', async () => {
36-
const timestamp = Date.now();
37-
mockMomentValueOf.mockReturnValueOnce(timestamp);
3828
const telemetryService = mockTelemetryService();
3929

4030
await telemetryService.fetchTelemetry();
4131
expect(telemetryService['http'].post).toBeCalledWith('/api/telemetry/v2/clusters/_stats', {
42-
body: JSON.stringify({ unencrypted: false, timestamp }),
32+
body: JSON.stringify({ unencrypted: false }),
4333
});
44-
expect(mockMomentValueOf).toBeCalled();
4534
});
4635
});
4736

src/plugins/telemetry/public/services/telemetry_service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import moment from 'moment';
2120
import { i18n } from '@kbn/i18n';
2221
import { CoreStart } from 'kibana/public';
2322
import { TelemetryPluginConfig } from '../plugin';
@@ -124,7 +123,6 @@ export class TelemetryService {
124123
return this.http.post('/api/telemetry/v2/clusters/_stats', {
125124
body: JSON.stringify({
126125
unencrypted,
127-
timestamp: moment().valueOf(),
128126
}),
129127
});
130128
};

src/plugins/telemetry/server/routes/telemetry_opt_in.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import moment from 'moment';
2120
import { Observable } from 'rxjs';
2221
import { take } from 'rxjs/operators';
2322
import { schema } from '@kbn/config-schema';
@@ -86,7 +85,6 @@ export function registerTelemetryOptInRoutes({
8685
}
8786

8887
const statsGetterConfig: StatsGetterConfig = {
89-
timestamp: moment().valueOf(),
9088
unencrypted: false,
9189
};
9290

src/plugins/telemetry/server/routes/telemetry_opt_in_stats.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
// @ts-ignore
2121
import fetch from 'node-fetch';
22-
import moment from 'moment';
2322

2423
import { IRouter } from 'kibana/server';
2524
import { schema } from '@kbn/config-schema';
@@ -72,7 +71,6 @@ export function registerTelemetryOptInStatsRoutes(
7271
const unencrypted = req.body.unencrypted;
7372

7473
const statsGetterConfig: StatsGetterConfig = {
75-
timestamp: moment().valueOf(),
7674
unencrypted,
7775
request: req,
7876
};

src/plugins/telemetry/server/routes/telemetry_usage_stats.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,13 @@
1717
* under the License.
1818
*/
1919

20-
import moment from 'moment';
2120
import { schema } from '@kbn/config-schema';
22-
import { TypeOptions } from '@kbn/config-schema/target/types/types';
2321
import { IRouter } from 'kibana/server';
2422
import {
2523
TelemetryCollectionManagerPluginSetup,
2624
StatsGetterConfig,
2725
} from 'src/plugins/telemetry_collection_manager/server';
2826

29-
const validate: TypeOptions<string | number>['validate'] = (value) => {
30-
if (!moment(value).isValid()) {
31-
return `${value} is not a valid date`;
32-
}
33-
};
34-
3527
export function registerTelemetryUsageStatsRoutes(
3628
router: IRouter,
3729
telemetryCollectionManager: TelemetryCollectionManagerPluginSetup,
@@ -43,16 +35,14 @@ export function registerTelemetryUsageStatsRoutes(
4335
validate: {
4436
body: schema.object({
4537
unencrypted: schema.boolean({ defaultValue: false }),
46-
timestamp: schema.oneOf([schema.string({ validate }), schema.number({ validate })]),
4738
}),
4839
},
4940
},
5041
async (context, req, res) => {
51-
const { unencrypted, timestamp } = req.body;
42+
const { unencrypted } = req.body;
5243

5344
try {
5445
const statsConfig: StatsGetterConfig = {
55-
timestamp: moment(timestamp).valueOf(),
5646
request: req,
5747
unencrypted,
5848
};

src/plugins/telemetry_collection_manager/server/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class TelemetryCollectionManagerPlugin
144144
collectionSoService: SavedObjectsServiceStart,
145145
usageCollection: UsageCollectionSetup
146146
): StatsCollectionConfig {
147-
const { timestamp, request } = config;
147+
const { request } = config;
148148

149149
const callCluster = config.unencrypted
150150
? collection.esCluster.asScoped(request).callAsCurrentUser
@@ -160,7 +160,7 @@ export class TelemetryCollectionManagerPlugin
160160
// Provide the kibanaRequest so opted-in plugins can scope their custom clients only if the request is not encrypted
161161
const kibanaRequest = config.unencrypted ? request : void 0;
162162

163-
return { callCluster, timestamp, usageCollection, esClient, soClient, kibanaRequest };
163+
return { callCluster, usageCollection, esClient, soClient, kibanaRequest };
164164
}
165165

166166
private async getOptInStats(optInStatus: boolean, config: StatsGetterConfig) {

src/plugins/telemetry_collection_manager/server/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export interface TelemetryOptInStats {
5656

5757
export interface BaseStatsGetterConfig {
5858
unencrypted: boolean;
59-
timestamp: number;
6059
request?: KibanaRequest;
6160
}
6261

@@ -76,7 +75,6 @@ export interface ClusterDetails {
7675
export interface StatsCollectionConfig {
7776
usageCollection: UsageCollectionSetup;
7877
callCluster: LegacyAPICaller;
79-
timestamp: number;
8078
esClient: ElasticsearchClient;
8179
soClient: SavedObjectsClientContract | ISavedObjectsRepository;
8280
kibanaRequest: KibanaRequest | undefined; // intentionally `| undefined` to enforce providing the parameter

test/api_integration/apis/telemetry/telemetry_local.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ export default function ({ getService }) {
5353
});
5454

5555
it('should pull local stats and validate data types', async () => {
56-
const timestamp = '2018-07-23T22:13:00Z';
57-
5856
const { body } = await supertest
5957
.post('/api/telemetry/v2/clusters/_stats')
6058
.set('kbn-xsrf', 'xxx')
61-
.send({ timestamp, unencrypted: true })
59+
.send({ unencrypted: true })
6260
.expect(200);
6361

6462
expect(body.length).to.be(1);
@@ -95,12 +93,10 @@ export default function ({ getService }) {
9593
});
9694

9795
it('should pull local stats and validate fields', async () => {
98-
const timestamp = '2018-07-23T22:13:00Z';
99-
10096
const { body } = await supertest
10197
.post('/api/telemetry/v2/clusters/_stats')
10298
.set('kbn-xsrf', 'xxx')
103-
.send({ timestamp, unencrypted: true })
99+
.send({ unencrypted: true })
104100
.expect(200);
105101

106102
const stats = body[0];
@@ -150,8 +146,6 @@ export default function ({ getService }) {
150146
});
151147

152148
describe('application usage limits', () => {
153-
const timestamp = '2018-07-23T22:13:00Z';
154-
155149
function createSavedObject() {
156150
return supertest
157151
.post('/api/saved_objects/application_usage_transactional')
@@ -182,7 +176,7 @@ export default function ({ getService }) {
182176
const { body } = await supertest
183177
.post('/api/telemetry/v2/clusters/_stats')
184178
.set('kbn-xsrf', 'xxx')
185-
.send({ timestamp, unencrypted: true })
179+
.send({ unencrypted: true })
186180
.expect(200);
187181

188182
expect(body.length).to.be(1);
@@ -233,7 +227,7 @@ export default function ({ getService }) {
233227
const { body } = await supertest
234228
.post('/api/telemetry/v2/clusters/_stats')
235229
.set('kbn-xsrf', 'xxx')
236-
.send({ timestamp, unencrypted: true })
230+
.send({ unencrypted: true })
237231
.expect(200);
238232

239233
expect(body.length).to.be(1);

test/functional/services/common/browser.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
197197
return await driver.get(url);
198198
}
199199

200+
/**
201+
* Retrieves the cookie with the given name. Returns null if there is no such cookie. The cookie will be returned as
202+
* a JSON object as described by the WebDriver wire protocol.
203+
* https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html
204+
*
205+
* @param {string} cookieName
206+
* @return {Promise<IWebDriverCookie>}
207+
*/
208+
public async getCookie(cookieName: string) {
209+
return await driver.manage().getCookie(cookieName);
210+
}
211+
200212
/**
201213
* Moves the remote environment’s mouse cursor to the specified point {x, y} which is
202214
* offset to browser page top left corner.

0 commit comments

Comments
 (0)