-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(vlogs service): fix stderr handling and improve number logic validation. #5859
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix your pull request title
httpClient := &http.Client{ | ||
Transport: &http.Transport{ | ||
// nosemgrep | ||
TLSClientConfig: &tls.Config{ | ||
//nolint:gosec | ||
InsecureSkipVerify: true, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the http default client since TLS-related configurations are not needed.
} | ||
return resp, nil | ||
} | ||
|
||
func generateReq(query *QueryParams) (*http.Request, error) { | ||
baseURL, err := url.Parse(query.Path + "/select/logsql/query") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use url joinpath to format url
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := httpClient.Do(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("HTTP req error: %v", err) | ||
return nil, fmt.Errorf("HTTP req error: %w", err) | ||
} | ||
if resp.StatusCode != http.StatusOK { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use defer body close here instead of manually closing it later.
var builder strings.Builder | ||
var item string | ||
if len(req.Time) != 0 { | ||
item = fmt.Sprintf( | ||
`{namespace="%s"} _time:%s app:="%s" | Drop _stream_id,_stream,app,job,namespace,node`, | ||
req.Namespace, | ||
req.Time, | ||
req.App, | ||
) | ||
} else { | ||
item = fmt.Sprintf(`{namespace="%s"} app:="%s" | Drop _stream_id,_stream,app,job,namespace,node`, req.Namespace, req.App) | ||
} | ||
builder.WriteString(item) | ||
v.query += builder.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant use of strings.Builder.
var builder strings.Builder | ||
builder.WriteString(req.Keyword) | ||
builder.WriteString(" ") | ||
v.query += builder.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant use of strings.Builder.
var builder strings.Builder | ||
builder.WriteString("| Drop _stream_id,_stream,app,job,namespace,node") | ||
v.query += builder.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar issue.
var builder strings.Builder | ||
if req.NumberMode == modeTrue { | ||
item := fmt.Sprintf(" | stats by (_time:1%s) count() logs_total ", req.NumberLevel) | ||
builder.WriteString(item) | ||
v.query += builder.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar issue.
scanner := bufio.NewScanner(strings.NewReader(string(body))) | ||
var logs []api.VlogsResponse | ||
|
||
uniquePods := make(map[string]struct{}) | ||
for scanner.Scan() { | ||
var entry api.VlogsResponse | ||
line := scanner.Text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a scanner.Bytes method?
Description:
Issue: Current stderr filtering logic causes user confusion due to implementation inconsistency. When users select "stderr" filter with log count limit, there are two possible behaviors:
Filter stderr logs from the latest 500 logs (current implementation)
Fetch the latest 500 stderr logs (expected behavior)
Root Cause: The stderr filter is applied after fetching logs (post-filter), while other filters like keyword search are applied before fetching (pre-filter), creating inconsistent user experience.
Proposed Solution:
Align stderr filtering logic with other filters by implementing pre-filtering
Change the order to: filter stderr logs first → then fetch 500 records