fix(cli): improve time parsing, interface consistency, and documentation accuracy#48
Merged
Merged
Conversation
…ion accuracy
Fixed several bugs found during user testing:
Time Parsing Improvements:
- Added RFC3339 timestamp support (e.g., "2026-02-11T08:49:36.831Z") to logs, metrics, and RUM commands
- Replaced custom time parsing functions with pkg/util.ParseTimeParam and pkg/util.ParseTimeToUnixMilli
- Now supports relative times (5m, 1h, 7d), Unix timestamps, RFC3339, and "now" keyword
- cmd/logs_simple.go: Removed duplicate parseTimeString function
- cmd/metrics.go: Removed duplicate parseTimeParam function
- cmd/rum.go: Updated to use util package for time parsing
- Updated help text to document RFC3339 support
Interface Consistency:
- Made logs --from flag optional with default "1h" (previously required)
- Logs commands now match metrics command interface pattern
- cmd/logs_simple.go: Removed MarkFlagRequired("from") for search, list, query, and aggregate commands
Documentation Fixes:
- Updated README.md to mark Traces as not implemented (was incorrectly shown as ✅)
- Updated docs/COMMANDS.md to reflect Traces placeholder status
- Directed users to use APM commands for trace data instead
APM Services Fix:
- Fixed APM services list to use filter[env] parameter format
- cmd/apm.go: Changed from params.Add("env", envFilter) to params.Add("filter[env]", envFilter)
- Now consistent with APM services stats command
Test Updates:
- cmd/logs_simple_test.go: Updated TestParseTimeString to test util.ParseTimeToUnixMilli
- Added test case for RFC3339 timestamp parsing
- cmd/metrics_test.go: Updated all test references to use util.ParseTimeParam
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed the default value for --env flag from empty string to "prod" for the apm services list command to improve usability. - cmd/apm.go: Updated apmServicesListCmd --env default from "" to "prod" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…rsing Enhanced time parsing to support natural language variations and case-insensitive formats for improved user experience. New Supported Formats: - Long forms: 5min, 5minutes, 2hr, 2hours, 3days, 1week - Plural variations: mins, hrs, days, weeks - With spaces: "5 minutes", "2 hours" - Minus prefix: -5m, -2h, -10minutes (gracefully handled) - Case-insensitive: NOW, 5MIN, 2HOURS, etc. Changes: - pkg/util/time.go: Enhanced regex to match long forms and spaces - pkg/util/time.go: Added case-insensitive matching for all formats - pkg/util/time_test.go: Added comprehensive tests for all new variations - cmd/logs_simple.go: Updated help text to document new formats All existing functionality preserved, fully backward compatible. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📊 Test Coverage ReportThreshold: 80% ✅ Coverage by Package📈 Coverage Status: ✅ PASSED - Coverage meets minimum threshold Updated for commit d7d4189 |
Changed the --env flag from having a default value to being explicitly required, as the API requires this parameter and was rejecting requests even with the default value. Changes: - cmd/apm.go: Marked --env flag as required for apm services list - cmd/apm.go: Added validation to return clear error if env is not provided - cmd/apm.go: Always add filter[env] parameter (removed conditional check) - Updated error message to guide users: "--env flag is required (e.g., --env prod)" This provides clearer feedback to users that the env parameter is mandatory for listing APM services. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added request details to error messages to help debug API parameter issues. Error messages now show the full request path and all parameters being sent. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed issue where start and end times were 0 instead of using proper defaults. The problem was that package-level variables were shared across commands and weren't being initialized with the default values. Now calculates default timestamps (1 hour ago and now) at runtime in the runAPMServicesList function if the values are 0. This fixes the "Invalid Parameter" error that was caused by sending start=0 and end=0 to the API. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed several bugs found during testing that affected usability and documentation accuracy:
--fromflag optional to match metrics behaviorChanges
Time Parsing Improvements (pkg/util/time.go:20-67, cmd/logs_simple.go, cmd/metrics.go, cmd/rum.go)
Expanded Format Support:
2026-02-11T08:49:36.831Z5m,2h,7d,5s,1w(original)5min,5minutes,2hr,2hours,3days,1week(new)mins,hrs,secs,days,weeks(new)"5 minutes","2 hours"(new)-5m,-2hgracefully handled as5m,2h(new)NOW,5MIN,2HOURSall work (new)1704067200Implementation:
pkg/util.ParseTimeParamandpkg/util.ParseTimeToUnixMilliparseTimeString()andparseTimeParam()functions from cmd/logs_simple.go and cmd/metrics.go(?i)^-?(\d+)\s*(s|sec|secs|second|seconds|m|min|mins|minute|minutes|...)Interface Consistency (cmd/logs_simple.go:560-611)
--fromflag optional with default value "1h" for all logs commands (search, list, query, aggregate)MarkFlagRequired("from")callspup logs listwithout specifying time rangeDocumentation Fixes (README.md:44, docs/COMMANDS.md:25,111)
APM Services Fixes (cmd/apm.go)
Issue 1: Filter Parameter Format
filter[env]parameter formatparams.Add("env", envFilter)toparams.Add("filter[env]", envFilter)Issue 2: Required Environment Flag
--envflag required instead of having a default valueif envFilter == "" { return error }required flag(s) "env" not setIssue 3: Timestamp Defaults
if startTime == 0 { startTime = time.Now().Add(-1 * time.Hour).Unix() }start=0&end=0to APIIssue 4: Error Messages
Request: GET /api/v2/apm/services?start=X&end=Y&filter[env]=prodTest Updates
util.ParseTimeToUnixMilliutil.ParseTimeParamTesting
Unit Tests
Manual Testing Verified
Time Parsing:
pup logs list --from "2026-02-11T08:49:36.831Z"✅pup logs list --from "5minutes"✅pup logs list --from "2 hours"✅pup logs list --from "-5m"✅pup logs list --from "NOW"✅pup logs list --from "3hrs"✅Interface Consistency:
--fromflag (uses 1h default) ✅APM Services:
Error: required flag(s) "env" not set✅filter[env]=prod✅Build
Impact
--fromflagExamples
Flexible Time Formats
APM Services
Commits
fix(cli): improve time parsing, interface consistency, and documentation accuracy- Main fixesfix(apm): set default environment filter to 'prod' for services list- Initial APM fixfeat(time): add flexible time format support with case-insensitive parsing- Enhanced time parsingfix(apm): make env filter required for services list command- Made env requiredfix(apm): add detailed error messages for services list debugging- Added debug infofix(apm): calculate default timestamps at runtime for services list- Fixed timestamp issue🤖 Generated with Claude Code