Skip to content

feat: Add log filters, event handling, and time validation#767

Open
NishchayRajput wants to merge 6 commits intogoharbor:mainfrom
NishchayRajput:feat/logs-filters
Open

feat: Add log filters, event handling, and time validation#767
NishchayRajput wants to merge 6 commits intogoharbor:mainfrom
NishchayRajput:feat/logs-filters

Conversation

@NishchayRajput
Copy link
Copy Markdown

@NishchayRajput NishchayRajput commented Mar 24, 2026

Description

This PR improves Harbor CLI audit-log usability by adding:

  1. Audit event-types command

    • New command: harbor logs events
  2. Convenience filters for harbor logs

    • Added flags:
      • --operation
      • --resource-type
      • --resource
      • --username
      • --from-time
      • --to-time
    • These are combined into Harbor q query syntax internally.
  3. Query/time validation helpers

    • Added internal query builder to merge existing --query/-q with convenience flags.
    • Added time normalization support for:
      • RFC3339 (2025-01-01T01:02:03Z)
      • YYYY-MM-DD HH:MM:SS
    • Validation:
      • --to-time requires --from-time.
      • --from-time without --to-time is allowed and defaults end time to current time.
  4. Unit tests for new behavior

    • Added tests for query building and time normalization/validation paths.

Parent Issue: #737

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • cmd/harbor/root/logs.go
    • Added logs events command
    • Added convenience filter flags and query composition logic
  • cmd/harbor/root/logs_test.go
    • Added tests for buildAuditLogQuery and normalizeAuditTime

@NishchayRajput
Copy link
Copy Markdown
Author

Please drop me suggestions and something I missed.

Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the Harbor CLI audit-log experience by adding a logs events subcommand, introducing convenience filter flags for harbor logs, and implementing helper logic for query building plus time normalization/validation.

Changes:

  • Added harbor logs events to list supported Harbor audit log event types (with optional client-side pagination and JSON output support).
  • Added convenience filter flags to harbor logs and composed them into Harbor q query syntax.
  • Added helper functions for audit-log query building, time normalization, and pagination summary output, plus unit tests for these helpers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/harbor/root/logs.go Adds logs events, convenience filter flags, query/time helpers, and pagination summary printing.
cmd/harbor/root/logs_test.go Adds unit tests for query building, time normalization, and event-type pagination/name helpers.
Comments suppressed due to low confidence (1)

cmd/harbor/root/logs.go:103

  • In --follow mode, buildAuditLogQuery is executed once before entering the polling loop. When --from-time is provided without --to-time, the code bakes in an op_time upper bound of “now” at startup, which prevents any newer audit logs from ever matching in subsequent polls. Consider requiring both times, or rebuilding the query (updating the to bound) on each refresh when following.
			query, err := buildAuditLogQuery(
				opts.Q,
				operationFilter,
				resourceTypeFilter,
				resourceFilter,
				usernameFilter,
				fromTimeFilter,
				toTimeFilter,
			)
			if err != nil {
				return err
			}
			opts.Q = query

			if follow {
				var interval time.Duration = 5 * time.Second
				if refreshInterval != "" {
					interval, err = time.ParseDuration(refreshInterval)
					if err != nil {
						return fmt.Errorf("invalid refresh interval: %w", err)
					}
					if interval < 500*time.Millisecond {
						return fmt.Errorf("refresh-interval must be at least 500ms (got: %v)", interval)
					}
				}
				followLogs(opts, interval)
				return nil
			}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
@qcserestipy qcserestipy requested review from qcserestipy and removed request for NucleoFusion April 1, 2026 17:42
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 57.06215% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.45%. Comparing base (60ad0bd) to head (82b39b1).
⚠️ Report is 123 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/logs.go 68.70% 41 Missing and 5 partials ⚠️
pkg/views/logs/view.go 0.00% 30 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #767      +/-   ##
=========================================
- Coverage   10.99%   8.45%   -2.54%     
=========================================
  Files         173     270      +97     
  Lines        8671   13345    +4674     
=========================================
+ Hits          953    1128     +175     
- Misses       7612   12099    +4487     
- Partials      106     118      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants