Skip to content

Conversation

bearslyricattack
Copy link
Member

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

Copy link
Collaborator

@dinoallo dinoallo left a 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

@bearslyricattack bearslyricattack changed the title Fix stderr handling and improve number logic validation. feat(vlogs service): fix stderr handling and improve number logic validation. Sep 8, 2025
@pull-request-size pull-request-size bot added size/L and removed size/S labels Sep 8, 2025
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Sep 9, 2025
Comment on lines 22 to 30
httpClient := &http.Client{
Transport: &http.Transport{
// nosemgrep
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: true,
},
},
}
Copy link
Member

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")
Copy link
Member

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 {
Copy link
Member

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.

Comment on lines +37 to +50
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()
Copy link
Member

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.

Comment on lines +55 to +58
var builder strings.Builder
builder.WriteString(req.Keyword)
builder.WriteString(" ")
v.query += builder.String()
Copy link
Member

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.

Comment on lines +157 to +160
var builder strings.Builder
builder.WriteString("| Drop _stream_id,_stream,app,job,namespace,node")
v.query += builder.String()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue.

Comment on lines +163 to +167
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()
Copy link
Member

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()
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants