Skip to content

Commit

Permalink
Chore: Import only lodash submodules (#2041)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- resolves #2032 

## Description of the changes
- Import only lodash submodules

## How was this change tested?
- locally

Super cool that it reduced the size taken by lodash bundle by 70.59%
(master branch vs this)

Before:

![image](https://github.com/jaegertracing/jaeger-ui/assets/94157520/25bc9f04-c4a7-45c0-b481-0332c09fca3c)
lodash: 773.55 KB

After:

![image](https://github.com/jaegertracing/jaeger-ui/assets/94157520/54bbb26e-9804-4718-beaf-02cb382d0f62)
lodash: 227.43 KB

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Ansh Goyal <[email protected]>
  • Loading branch information
anshgoyalevil authored Dec 12, 2023
1 parent 4bdb8ac commit 46f89af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import _ from 'lodash';
import _flatten from 'lodash/flatten';
import _uniq from 'lodash/uniq';
import { Trace } from '../../../types/trace';
import { ITableSpan } from './types';

const serviceName = 'Service Name';
const operationName = 'Operation Name';

/**
* Used to get the values if no tag is picked from the first dropdown.
* Used to get the values if tag is picked from the first dropdown.
*/
function getValueTagIsPicked(tableValue: ITableSpan[], trace: Trace, nameSelectorTitle: string) {
const allSpans = trace.spans;
let availableTags = [];
let spansWithFilterTag = [];

// add all Spans with this tag key

Expand All @@ -33,32 +34,26 @@ function getValueTagIsPicked(tableValue: ITableSpan[], trace: Trace, nameSelecto
for (let j = 0; j < allSpans.length; j++) {
for (let l = 0; l < allSpans[j].tags.length; l++) {
if (nameSelectorTitle === allSpans[j].tags[l].key) {
availableTags.push(allSpans[j]);
spansWithFilterTag.push(allSpans[j]);
}
}
}
}
}
availableTags = [...new Set(availableTags)];
spansWithFilterTag = _uniq(spansWithFilterTag);

const tags = _(availableTags).map('tags').flatten().value();
let tagKeys = _(tags).map('key').uniq().value();
tagKeys = _.filter(tagKeys, function calc(o) {
return o !== nameSelectorTitle;
});
availableTags = [];
availableTags.push(serviceName);
availableTags.push(operationName);
availableTags = availableTags.concat(tagKeys);
const tags = spansWithFilterTag.map(o => o.tags);
let tagKeys = _uniq(_flatten(tags).map(o => o.key));
tagKeys = tagKeys.filter(o => o !== nameSelectorTitle);

return availableTags;
return [serviceName, operationName, ...tagKeys];
}

/**
* Used to get the values if no tag is picked from the first dropdown.
*/
function getValueNoTagIsPicked(trace: Trace, nameSelectorTitle: string) {
let availableTags = [];
const availableTags = [];
const allSpans = trace.spans;
if (nameSelectorTitle === serviceName) {
availableTags.push(operationName);
Expand All @@ -70,16 +65,14 @@ function getValueNoTagIsPicked(trace: Trace, nameSelectorTitle: string) {
availableTags.push(allSpans[i].tags[j].key);
}
}
availableTags = [...new Set(availableTags)];

return availableTags;
return _uniq(availableTags);
}

export function generateDropdownValue(trace: Trace) {
const allSpans = trace.spans;
const tags = _(allSpans).map('tags').flatten().value();
const tagKeys = _(tags).map('key').uniq().value();
const values = _.concat(serviceName, operationName, tagKeys);
const tags = _flatten(allSpans.map(o => o.tags));
const tagKeys = _uniq(tags.map(o => o.key));
const values = [serviceName, operationName, ...tagKeys];
return values;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import memoizeOne from 'memoize-one';
import * as _ from 'lodash';
import _uniq from 'lodash/uniq';
import DRange from 'drange';
import { Trace, Span } from '../../../types/trace';
import { ITableSpan } from './types';
Expand Down Expand Up @@ -115,23 +115,9 @@ function valueFirstDropdown(selectedTagKey: string, trace: Trace) {
const allSpans = trace.spans;
// all possibilities that can be displayed
if (selectedTagKey === serviceName) {
const temp = _.chain(allSpans)
.groupBy(x => x.process.serviceName)
.map((value, key) => ({ key }))
.uniq()
.value();
for (let i = 0; i < temp.length; i++) {
allDiffColumnValues.push(temp[i].key);
}
allDiffColumnValues = _uniq(allSpans.map(x => x.process.serviceName));
} else if (selectedTagKey === operationName) {
const temp = _.chain(allSpans)
.groupBy(x => x.operationName)
.map((value, key) => ({ key }))
.uniq()
.value();
for (let i = 0; i < temp.length; i++) {
allDiffColumnValues.push(temp[i].key);
}
allDiffColumnValues = _uniq(allSpans.map(x => x.operationName));
} else {
for (let i = 0; i < allSpans.length; i++) {
for (let j = 0; j < allSpans[i].tags.length; j++) {
Expand All @@ -140,7 +126,7 @@ function valueFirstDropdown(selectedTagKey: string, trace: Trace) {
}
}
}
allDiffColumnValues = [...new Set(allDiffColumnValues)];
allDiffColumnValues = _uniq(allDiffColumnValues);
}
// used to build the table
const allTableValues = [];
Expand Down Expand Up @@ -450,7 +436,7 @@ function valueSecondDropdown(
let newColumnValues = [] as any;
// if second dropdown is no tag
if (selectedTagKeySecond === serviceName || selectedTagKeySecond === operationName) {
diffNamesA = [...new Set(diffNamesA)];
diffNamesA = _uniq(diffNamesA);
newColumnValues = buildDetail(
diffNamesA,
tempArray,
Expand All @@ -470,7 +456,7 @@ function valueSecondDropdown(
}
}
}
diffNamesA = [...new Set(diffNamesA)];
diffNamesA = _uniq(diffNamesA);
newColumnValues = buildDetail(
diffNamesA,
tempArray,
Expand Down

0 comments on commit 46f89af

Please sign in to comment.