Skip to content

Commit

Permalink
[logsearchapi] Fix bug in querying raw logs and update API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
donatello committed Mar 9, 2022
1 parent 6cf1612 commit 4cf84cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions logsearchapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ The `token` parameter is used to authenticate the request and should be equal to

Additional query parameters specify the logs to be retrieved.

| Query parameter | Value Description | Required | Default |
|----------------------|-------------------------------------------------------------------------------------------------------------------|----------|---------------------|
| `q` | `reqinfo` or `raw`. | Yes | - |
| `timeStart` | RFC3339 time or date. Examples: `2006-01-02T15:04:05.999999999Z07:00` or `2006-01-02`. | No | Current server time |
| `timeAsc`/`timeDesc` | Flag parameter (no value); either one may be specified. Specifies result ordering. | No | `timeDesc` |
| `pageSize` | Number of results to return per API call. Allows values between 10 and 1000. | No | `10` |
| `pageNo` | 0-based page number of results. | No | `0` |
| `fp` | Repeatable parameter specifying key-value match filters. See the [filter parameters](#filter-parameters) section. | No | - |
| Query parameter | Value Description | Required | Default |
|----------------------|-------------------------------------------------------------------------------------------------------------------|----------|------------|
| `q` | `reqinfo` or `raw`. | Yes | - |
| `timeStart` | RFC3339 time or date. Examples: `2006-01-02T15:04:05.999999999Z07:00` or `2006-01-02`. | No | - |
| `timeEnd` | RFC3339 time or date. Examples: `2006-01-02T15:04:05.999999999Z07:00` or `2006-01-02`. | No | - |
| `timeAsc`/`timeDesc` | Flag parameter (no value); either one may be specified. Specifies result ordering. | No | `timeDesc` |
| `pageSize` | Number of results to return per API call. Allows values between 10 and 1000. | No | `10` |
| `pageNo` | 0-based page number of results. | No | `0` |
| `fp` | Repeatable parameter specifying key-value match filters. See the [filter parameters](#filter-parameters) section. | No | - |

#### Filter Parameters

Expand Down
5 changes: 4 additions & 1 deletion logsearchapi/server/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *DBClient) Search(ctx context.Context, s *SearchQuery, w io.Writer) erro
logEventSelect QTemplate = `SELECT event_time,
log
FROM %s
WHERE %s
%s
ORDER BY event_time %s
OFFSET $1 LIMIT $2;`
reqInfoSelect QTemplate = `SELECT time,
Expand Down Expand Up @@ -332,6 +332,9 @@ func (c *DBClient) Search(ctx context.Context, s *SearchQuery, w io.Writer) erro
whereClauses = append(whereClauses, timeRangeClause)
}
whereClause := strings.Join(whereClauses, " AND ")
if len(whereClauses) == 0 {
whereClause = fmt.Sprintf("WHERE %s", whereClause)
}

q := logEventSelect.build(auditLogEventsTable.Name, whereClause, timeOrder)
rows, err := c.QueryContext(ctx, q, s.PageNumber*s.PageSize, s.PageSize)
Expand Down

0 comments on commit 4cf84cc

Please sign in to comment.