Optimize get_top_operations_for_types query (#5324)

This commit is contained in:
Kamil Kisiela 2024-08-09 12:23:50 +02:00 committed by GitHub
parent b11fade2ba
commit 5d3fddf4ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 5 deletions

View file

@ -1297,7 +1297,7 @@ export class OperationsReader {
>
> {
const ORs = args.typeNames.map(
typeName => sql`( cd.coordinate = ${typeName} OR cd.coordinate LIKE ${typeName + '.%'} )`,
typeName => sql`( cdi.coordinate = ${typeName} OR cdi.coordinate LIKE ${typeName + '.%'} )`,
);
const result = await this.clickHouse.query<{
@ -1320,14 +1320,13 @@ export class OperationsReader {
${this.createFilter({
target: args.targetId,
period: args.period,
extra: [sql`cdi.coordinate NOT LIKE '%.%.%'`],
extra: [sql`cdi.coordinate NOT LIKE '%.%.%'`, sql`(${sql.join(ORs, ' OR ')})`],
namespace: 'cdi',
})}
GROUP BY cdi.hash, cdi.coordinate ORDER by total DESC, cdi.hash ASC LIMIT ${sql.raw(
String(args.limit),
)} by cdi.coordinate
) as cd
WHERE ${sql.join(ORs, ' OR ')}
)
SELECT total, hash, coordinate, ocd.name
FROM coordinates as c LEFT JOIN (

View file

@ -69,11 +69,10 @@ export class HttpClient {
return Promise.resolve(response.body);
},
error => {
span.setAttribute('http.response.status_code', error.response.statusCode);
let details: string | null = null;
if (error instanceof HTTPError) {
span.setAttribute('http.response.status_code', error.response.statusCode);
if (typeof error.response.body === 'string') {
details = error.response.body;
logger.error(details);