Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filter time and word name in get logs #1652

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/api-server/api/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class GraphqlResolvers {
}

async queryLogs(query) {
const { taskId, podName, source, nodeKind, logMode, pageNum, sort, limit } = query;
const logs = await logsQueries.getLogs({ taskId, podName, source, nodeKind, logMode, pageNum, sort, limit });
const { taskId, podName, source, nodeKind, logMode, pageNum, sort, limit, searchWord, taskTime } = query;
const logs = await logsQueries.getLogs({ taskId, podName, source, nodeKind, logMode, pageNum, sort, limit, searchWord, taskTime });
return logs;
}

Expand Down
2 changes: 1 addition & 1 deletion core/api-server/api/graphql/schemas/log-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type LogsMainType { logs: [Logs ],podStatus: String }

extend type Query {

logsByQuery(podName: String!,taskId:String,source:String,nodeKind:String,logMode:String): LogsMainType
logsByQuery(podName: String!,taskId:String,source:String,nodeKind:String,logMode:String,searchWord:String, taskTime:String): LogsMainType
}

`;
Expand Down
20 changes: 19 additions & 1 deletion core/api-server/api/task-logs/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EsLogs {
return search;
}

async getLogs({ taskId, nodeKind, podName, logMode, sort, limit, skip }) {
async getLogs({ taskId, nodeKind, podName, logMode, sort, limit, skip, searchWord, taskTime }) {
const query = [];
if (taskId) {
query.push(`meta.internal.taskId: "${taskId}"`);
Expand All @@ -56,6 +56,9 @@ class EsLogs {
query.push(searchComponent);
}
}
if (searchWord) {
query.push(`${searchWord}*`);
}

const queryString = query.join(' AND ');

Expand All @@ -78,6 +81,21 @@ class EsLogs {
}
}
};

// add range date
if (taskTime) {
body.query.bool.must.push({
range: {
'@timestamp': {
gte: taskTime,
lt: 'now/d'
}

}

});
}

const logs = await this._client.search({
index: this._index,
type: this._type,
Expand Down
10 changes: 7 additions & 3 deletions core/api-server/api/task-logs/logs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const orderBy = require('lodash.orderby');
const log = require('@hkube/logger').GetLogFromContainer();
const { logModes, podStatus } = require('@hkube/consts');
const elasticSearch = require('./es');
Expand Down Expand Up @@ -53,7 +52,10 @@ class Logs {
logMode = logModes.ALGORITHM,
pageNum = 0,
sort = sortOrder.desc,
limit = LOGS_LIMIT }) {
limit = LOGS_LIMIT,
searchWord,
taskTime
}) {
let logs = [];
const logsData = {};
try {
Expand Down Expand Up @@ -96,9 +98,11 @@ class Logs {
skip,
ageNum: pageNumber,
limit: sizeLimit,
searchWord,
taskTime
});
logs = logs.map(this._format);
logs = orderBy(logs, l => l.timestamp, sortOrder.asc);

logsData.logs = logs;
}
}
Expand Down