From 8cfbee1e11122bfe4991dcbbbc391470006963fa Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Tue, 18 May 2021 13:42:57 +0100 Subject: [PATCH] Chore: Remove md5 dependency and use uuid/v5 instead (#34192) --- package.json | 4 +-- .../datasource/loki/live_streams.test.ts | 2 +- .../loki/result_transformer.test.ts | 32 +++++++++---------- .../datasource/loki/result_transformer.ts | 6 ++-- yarn.lock | 28 +--------------- 5 files changed, 23 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 39ab9210aac..815609294ba 100644 --- a/package.json +++ b/package.json @@ -105,12 +105,11 @@ "@types/hoist-non-react-statics": "3.3.1", "@types/is-hotkey": "0.1.1", "@types/jest": "26.0.15", - "@types/jsurl": "^1.2.28", "@types/jquery": "3.3.38", + "@types/jsurl": "^1.2.28", "@types/lodash": "4.14.149", "@types/logfmt": "^1.2.1", "@types/lru-cache": "^5.1.0", - "@types/md5": "^2.1.33", "@types/mousetrap": "1.6.3", "@types/node": "13.7.0", "@types/papaparse": "5.2.0", @@ -264,7 +263,6 @@ "lodash": "4.17.21", "logfmt": "^1.3.2", "lru-cache": "^5.1.1", - "md5": "^2.2.1", "memoize-one": "5.1.1", "moment": "2.29.1", "moment-timezone": "0.5.33", diff --git a/public/app/plugins/datasource/loki/live_streams.test.ts b/public/app/plugins/datasource/loki/live_streams.test.ts index 249a3758e64..8a8cc9e2c89 100644 --- a/public/app/plugins/datasource/loki/live_streams.test.ts +++ b/public/app/plugins/datasource/loki/live_streams.test.ts @@ -48,7 +48,7 @@ describe('Live Stream Tests', () => { expect(last).toEqual({ ts: '2019-08-28T20:50:40.118Z', tsNs: '1567025440118944705', - id: '8c50d09800ce8dda69a2ff25405c9f65_A', + id: '25d81461-a66f-53ff-98d5-e39515af4735_A', line: 'Kittens', labels: { filename: '/var/log/sntpc.log' }, }); diff --git a/public/app/plugins/datasource/loki/result_transformer.test.ts b/public/app/plugins/datasource/loki/result_transformer.test.ts index fc9095c4f57..4b9df9457e0 100644 --- a/public/app/plugins/datasource/loki/result_transformer.test.ts +++ b/public/app/plugins/datasource/loki/result_transformer.test.ts @@ -72,10 +72,10 @@ describe('loki result transformer', () => { expect(data[0].fields[1].labels!['foo']).toEqual('bar'); expect(data[0].fields[0].values.get(0)).toEqual('2020-01-24T09:19:22.021Z'); expect(data[0].fields[1].values.get(0)).toEqual(streamResult[0].values[0][1]); - expect(data[0].fields[2].values.get(0)).toEqual('2b431b8a98b80b3b2c2f4cd2444ae6cb'); + expect(data[0].fields[2].values.get(0)).toEqual('4b79cb43-81ce-52f7-b1e9-a207fff144dc'); expect(data[1].fields[0].values.get(0)).toEqual('2020-01-24T09:19:22.031Z'); expect(data[1].fields[1].values.get(0)).toEqual(streamResult[1].values[0][1]); - expect(data[1].fields[2].values.get(0)).toEqual('75d73d66cff40f9d1a1f2d5a0bf295d0'); + expect(data[1].fields[2].values.get(0)).toEqual('73d144f6-57f2-5a45-a49c-eb998e2006b1'); }); it('should always generate unique ids for logs', () => { @@ -102,18 +102,18 @@ describe('loki result transformer', () => { const data = streamResultWithDuplicateLogs.map((stream) => ResultTransformer.lokiStreamResultToDataFrame(stream)); - expect(data[0].fields[2].values.get(0)).toEqual('65cee200875f58ee1430d8bd2e8b74e7'); - expect(data[0].fields[2].values.get(1)).toEqual('65cee200875f58ee1430d8bd2e8b74e7_1'); - expect(data[0].fields[2].values.get(2)).not.toEqual('65cee200875f58ee1430d8bd2e8b74e7_2'); - expect(data[0].fields[2].values.get(3)).toEqual('65cee200875f58ee1430d8bd2e8b74e7_2'); - expect(data[1].fields[2].values.get(0)).not.toEqual('65cee200875f58ee1430d8bd2e8b74e7_3'); + expect(data[0].fields[2].values.get(0)).toEqual('b48fe7dc-36aa-5d37-bfba-087ef810d8fa'); + expect(data[0].fields[2].values.get(1)).toEqual('b48fe7dc-36aa-5d37-bfba-087ef810d8fa_1'); + expect(data[0].fields[2].values.get(2)).not.toEqual('b48fe7dc-36aa-5d37-bfba-087ef810d8fa_2'); + expect(data[0].fields[2].values.get(3)).toEqual('b48fe7dc-36aa-5d37-bfba-087ef810d8fa_2'); + expect(data[1].fields[2].values.get(0)).not.toEqual('b48fe7dc-36aa-5d37-bfba-087ef810d8fa_3'); }); it('should append refId to the unique ids if refId is provided', () => { const data = streamResult.map((stream) => ResultTransformer.lokiStreamResultToDataFrame(stream, false, 'B')); expect(data.length).toBe(2); - expect(data[0].fields[2].values.get(0)).toEqual('2b431b8a98b80b3b2c2f4cd2444ae6cb_B'); - expect(data[1].fields[2].values.get(0)).toEqual('75d73d66cff40f9d1a1f2d5a0bf295d0_B'); + expect(data[0].fields[2].values.get(0)).toEqual('4b79cb43-81ce-52f7-b1e9-a207fff144dc_B'); + expect(data[1].fields[2].values.get(0)).toEqual('73d144f6-57f2-5a45-a49c-eb998e2006b1_B'); }); }); @@ -172,7 +172,7 @@ describe('loki result transformer', () => { line: 't=2020-02-12T15:04:51+0000 lvl=info msg="Starting Grafana" logger=server version=6.7.0-pre commit=6f09bc9fb4 branch=issue-21929 compiled=2020-02-11T20:43:28+0000', labels: { filename: '/var/log/grafana/grafana.log' }, - id: '19e8e093d70122b3b53cb6e24efd6e2d', + id: '07f0607c-04ee-51bd-8a0c-fc0f85d37489', }); }); @@ -205,12 +205,12 @@ describe('loki result transformer', () => { data.refId = 'C'; ResultTransformer.appendResponseToBufferedData(tailResponse, data); - expect(data.get(0).id).toEqual('870e4d105741bdfc2c67904ee480d4f3_C'); - expect(data.get(1).id).toEqual('870e4d105741bdfc2c67904ee480d4f3_1_C'); - expect(data.get(2).id).toEqual('707e4ec2b842f389dbb993438505856d_C'); - expect(data.get(3).id).toEqual('78f044015a58fad3e257a855b167d85e_C'); - expect(data.get(4).id).toEqual('870e4d105741bdfc2c67904ee480d4f3_2_C'); - expect(data.get(5).id).toEqual('707e4ec2b842f389dbb993438505856d_1_C'); + expect(data.get(0).id).toEqual('75e72b25-8589-5f99-8d10-ccb5eb27c1b4_C'); + expect(data.get(1).id).toEqual('75e72b25-8589-5f99-8d10-ccb5eb27c1b4_1_C'); + expect(data.get(2).id).toEqual('3ca99d6b-3ab5-5970-93c0-eb3c9449088e_C'); + expect(data.get(3).id).toEqual('ec9bea1d-70cb-556c-8519-d5d6ae18c004_C'); + expect(data.get(4).id).toEqual('75e72b25-8589-5f99-8d10-ccb5eb27c1b4_2_C'); + expect(data.get(5).id).toEqual('3ca99d6b-3ab5-5970-93c0-eb3c9449088e_1_C'); }); }); diff --git a/public/app/plugins/datasource/loki/result_transformer.ts b/public/app/plugins/datasource/loki/result_transformer.ts index 5aefb9ecf29..503a77e5195 100644 --- a/public/app/plugins/datasource/loki/result_transformer.ts +++ b/public/app/plugins/datasource/loki/result_transformer.ts @@ -1,5 +1,5 @@ import { capitalize, groupBy, isEmpty } from 'lodash'; -import md5 from 'md5'; +import { v5 as uuidv5 } from 'uuid'; import { of } from 'rxjs'; import { @@ -38,6 +38,8 @@ import { LokiStats, } from './types'; +const UUID_NAMESPACE = '6ec946da-0f49-47a8-983a-1d76d17e7c92'; + /** * Transforms LokiStreamResult structure into a dataFrame. Used when doing standard queries and newer version of Loki. */ @@ -155,7 +157,7 @@ export function appendResponseToBufferedData(response: LokiTailResponse, data: M function createUid(ts: string, labelsString: string, line: string, usedUids: any, refId?: string): string { // Generate id as hashed nanosecond timestamp, labels and line (this does not have to be unique) - let id = md5(`${ts}_${labelsString}_${line}`); + let id = uuidv5(`${ts}_${labelsString}_${line}`, UUID_NAMESPACE); // Check if generated id is unique // If not and we've already used it, append it's count after it diff --git a/yarn.lock b/yarn.lock index efa24af9f53..bcfcbbf38d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4440,13 +4440,6 @@ resolved "https://registry.yarnpkg.com/@types/marked/-/marked-1.1.0.tgz#53509b5f127e0c05c19176fcf1d743a41e00ff19" integrity sha512-j8XXj6/l9kFvCwMyVqozznqpd/nk80krrW+QiIJN60Uu9gX5Pvn4/qPJ2YngQrR3QREPwmrE1f9/EWKVTFzoEw== -"@types/md5@^2.1.33": - version "2.1.33" - resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.1.33.tgz#8c8dba30df4ad0e92296424f08c4898dd808e8df" - integrity sha512-8+X960EtKLoSblhauxLKy3zzotagjoj3Jt1Tx9oaxUdZEPIBl+mkrUz6PNKpzJgkrKSN9YgkWTA29c0KnLshmA== - dependencies: - "@types/node" "*" - "@types/mdast@^3.0.0": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.3.tgz#2d7d671b1cd1ea3deb306ea75036c2a0407d2deb" @@ -7220,11 +7213,6 @@ chardet@^0.7.0: resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== -charenc@~0.0.1: - version "0.0.2" - resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" - integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc= - check-more-types@^2.24.0: version "2.24.0" resolved "https://registry.yarnpkg.com/check-more-types/-/check-more-types-2.24.0.tgz#1420ffb10fd444dcfc79b43891bbfffd32a84600" @@ -8159,11 +8147,6 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" -crypt@~0.0.1: - version "0.0.2" - resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" - integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs= - crypto-browserify@^3.11.0: version "3.12.0" resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec" @@ -12661,7 +12644,7 @@ is-boolean-object@^1.0.1, is-boolean-object@^1.1.0: dependencies: call-bind "^1.0.0" -is-buffer@^1.1.5, is-buffer@~1.1.1: +is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== @@ -14834,15 +14817,6 @@ md5.js@^1.3.4: inherits "^2.0.1" safe-buffer "^5.1.2" -md5@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9" - integrity sha1-U6s41f48iJG6RlMp6iP6wFQBJvk= - dependencies: - charenc "~0.0.1" - crypt "~0.0.1" - is-buffer "~1.1.1" - mdast-squeeze-paragraphs@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/mdast-squeeze-paragraphs/-/mdast-squeeze-paragraphs-4.0.0.tgz#7c4c114679c3bee27ef10b58e2e015be79f1ef97"