forked from opensearch-project/query-insights-dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chenyang Ji <[email protected]>
- Loading branch information
Showing
5 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { removeQueryGroups } from './utils'; | ||
import { SearchQueryRecord } from '../../types/types'; | ||
import { MockGroups, MockQueries } from '../../test/testUtils'; | ||
|
||
const mockQueries = MockQueries(); | ||
const mockGroups = MockGroups(); | ||
describe('removeQueryGroups', () => { | ||
it('should return an empty array when input is an empty array', () => { | ||
const records: SearchQueryRecord[] = []; | ||
const result = removeQueryGroups(records); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return only records where all measurements have count equal to 1 (native queries)', () => { | ||
const records: SearchQueryRecord[] = [...mockQueries, ...mockGroups]; | ||
const result = removeQueryGroups(records); | ||
expect(result).toEqual(mockQueries); | ||
}); | ||
|
||
it('should exclude all records where all records are groups', () => { | ||
const result = removeQueryGroups(mockGroups); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should include records where all records are native queries', () => { | ||
const result = removeQueryGroups(mockQueries); | ||
expect(result).toEqual(mockQueries); | ||
}); | ||
|
||
it('should handle empty records', () => { | ||
const result = removeQueryGroups([]); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SearchQueryRecord } from '../../types/types'; | ||
|
||
export const removeQueryGroups = (records: SearchQueryRecord[]) => { | ||
return records.filter((record: SearchQueryRecord) => | ||
Object.values(record.measurements).every((measurement) => measurement.count === 1) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SearchQueryRecord } from '../types/types'; | ||
|
||
export const MockQueries = (): SearchQueryRecord[] => { | ||
return [ | ||
{ | ||
timestamp: 1726178995210, | ||
task_resource_usages: [ | ||
{ | ||
action: 'indices:data/read/search[phase/query]', | ||
taskId: 18809, | ||
parentTaskId: 18808, | ||
nodeId: 'Q36D2z_NRGKim6EZZMgi6A', | ||
taskResourceUsage: { | ||
cpu_time_in_nanos: 3612000, | ||
memory_in_bytes: 123944, | ||
}, | ||
}, | ||
{ | ||
action: 'indices:data/read/search', | ||
taskId: 18808, | ||
parentTaskId: -1, | ||
nodeId: 'Q36D2z_NRGKim6EZZMgi6A', | ||
taskResourceUsage: { | ||
cpu_time_in_nanos: 1898000, | ||
memory_in_bytes: 24176, | ||
}, | ||
}, | ||
], | ||
source: { | ||
query: { | ||
bool: { | ||
must: [ | ||
{ | ||
range: { | ||
timestamp: { | ||
from: 1726092595177, | ||
to: 1726178995177, | ||
include_lower: true, | ||
include_upper: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
], | ||
must_not: [ | ||
{ | ||
match: { | ||
indices: { | ||
query: 'top_queries*', | ||
operator: 'OR', | ||
prefix_length: 0, | ||
max_expansions: 50, | ||
fuzzy_transpositions: true, | ||
lenient: false, | ||
zero_terms_query: 'NONE', | ||
auto_generate_synonyms_phrase_query: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
], | ||
adjust_pure_negative: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
query_hashcode: '80a17984b847133b8bf5e7d5dfbfa96c', | ||
phase_latency_map: { | ||
expand: 0, | ||
query: 5, | ||
fetch: 0, | ||
}, | ||
labels: { | ||
'X-Opaque-Id': 'ae6c1170-5f98-47f4-b7fc-09ebcf574b81', | ||
}, | ||
total_shards: 1, | ||
search_type: 'query_then_fetch', | ||
node_id: 'Q36D2z_NRGKim6EZZMgi6A', | ||
indices: ['top_queries-2024.09.12'], | ||
measurements: { | ||
latency: { | ||
number: 8, | ||
count: 1, | ||
aggregationType: 'NONE', | ||
}, | ||
cpu: { | ||
number: 5510000, | ||
count: 1, | ||
aggregationType: 'NONE', | ||
}, | ||
}, | ||
}, | ||
]; | ||
}; | ||
|
||
export const MockGroups = (): SearchQueryRecord[] => { | ||
return [ | ||
{ | ||
timestamp: 1726178995210, | ||
task_resource_usages: [ | ||
{ | ||
action: 'indices:data/read/search[phase/query]', | ||
taskId: 18809, | ||
parentTaskId: 18808, | ||
nodeId: 'Q36D2z_NRGKim6EZZMgi6A', | ||
taskResourceUsage: { | ||
cpu_time_in_nanos: 3612000, | ||
memory_in_bytes: 123944, | ||
}, | ||
}, | ||
{ | ||
action: 'indices:data/read/search', | ||
taskId: 18808, | ||
parentTaskId: -1, | ||
nodeId: 'Q36D2z_NRGKim6EZZMgi6A', | ||
taskResourceUsage: { | ||
cpu_time_in_nanos: 1898000, | ||
memory_in_bytes: 24176, | ||
}, | ||
}, | ||
], | ||
source: { | ||
query: { | ||
bool: { | ||
must: [ | ||
{ | ||
range: { | ||
timestamp: { | ||
from: 1726092595177, | ||
to: 1726178995177, | ||
include_lower: true, | ||
include_upper: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
], | ||
must_not: [ | ||
{ | ||
match: { | ||
indices: { | ||
query: 'top_queries*', | ||
operator: 'OR', | ||
prefix_length: 0, | ||
max_expansions: 50, | ||
fuzzy_transpositions: true, | ||
lenient: false, | ||
zero_terms_query: 'NONE', | ||
auto_generate_synonyms_phrase_query: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
], | ||
adjust_pure_negative: true, | ||
boost: 1.0, | ||
}, | ||
}, | ||
}, | ||
query_hashcode: '80a17984b847133b8bf5e7d5dfbfa96c', | ||
phase_latency_map: { | ||
expand: 0, | ||
query: 5, | ||
fetch: 0, | ||
}, | ||
labels: { | ||
'X-Opaque-Id': 'ae6c1170-5f98-47f4-b7fc-09ebcf574b81', | ||
}, | ||
total_shards: 1, | ||
search_type: 'query_then_fetch', | ||
node_id: 'Q36D2z_NRGKim6EZZMgi6A', | ||
indices: ['top_queries-2024.09.12'], | ||
measurements: { | ||
latency: { | ||
number: 8, | ||
count: 5, | ||
aggregationType: 'NONE', | ||
}, | ||
cpu: { | ||
number: 5510000, | ||
count: 5, | ||
aggregationType: 'NONE', | ||
}, | ||
}, | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters