-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: plugins/rename-instrumentation-middleware-to-metrics-middleware #328
Closed
admin-coderabbit
wants to merge
1
commit into
main
from
plugins/rename-instrumentation-middleware-to-metrics-middleware
+137
−78
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,40 @@ | ||
| package log | ||
|
|
||
| import "context" | ||
|
|
||
| // Logger is the default logger | ||
| type Logger interface { | ||
| // New returns a new contextual Logger that has this logger's context plus the given context. | ||
| New(ctx ...interface{}) Logger | ||
| New(ctx ...any) Logger | ||
|
|
||
| // Debug logs a message with debug level and key/value pairs, if any. | ||
| Debug(msg string, ctx ...interface{}) | ||
| Debug(msg string, ctx ...any) | ||
|
|
||
| // Info logs a message with info level and key/value pairs, if any. | ||
| Info(msg string, ctx ...interface{}) | ||
| Info(msg string, ctx ...any) | ||
|
|
||
| // Warn logs a message with warning level and key/value pairs, if any. | ||
| Warn(msg string, ctx ...interface{}) | ||
| Warn(msg string, ctx ...any) | ||
|
|
||
| // Error logs a message with error level and key/value pairs, if any. | ||
| Error(msg string, ctx ...interface{}) | ||
| Error(msg string, ctx ...any) | ||
|
|
||
| // FromContext returns a new contextual Logger that has this logger's context plus the given context. | ||
| FromContext(ctx context.Context) Logger | ||
| } | ||
|
|
||
| // PrettyLogger is used primarily to facilitate logging/user feedback for both | ||
| // the grafana-cli and the grafana backend when managing plugin installs | ||
| type PrettyLogger interface { | ||
| Successf(format string, args ...interface{}) | ||
| Failuref(format string, args ...interface{}) | ||
|
|
||
| Info(args ...interface{}) | ||
| Infof(format string, args ...interface{}) | ||
| Debug(args ...interface{}) | ||
| Debugf(format string, args ...interface{}) | ||
| Warn(args ...interface{}) | ||
| Warnf(format string, args ...interface{}) | ||
| Error(args ...interface{}) | ||
| Errorf(format string, args ...interface{}) | ||
| Successf(format string, args ...any) | ||
| Failuref(format string, args ...any) | ||
|
|
||
| Info(args ...any) | ||
| Infof(format string, args ...any) | ||
| Debug(args ...any) | ||
| Debugf(format string, args ...any) | ||
| Warn(args ...any) | ||
| Warnf(format string, args ...any) | ||
| Error(args ...any) | ||
| Errorf(format string, args ...any) | ||
| } |
This file contains 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
Oops, something went wrong.
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.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 716
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 4484
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1972
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 381
🏁 Script executed:
# Check the Logger interface definition in plugins/log cat pkg/plugins/log/ifaces.goRepository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1329
🏁 Script executed:
# Look for tests in plugins/log directory ls -la pkg/plugins/log/Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 444
🏁 Script executed:
# Check the fake.go file completely cat pkg/plugins/log/fake.goRepository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1775
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 319
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1501
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1390
🏁 Script executed:
# Check the logger_middleware.go file to see if it uses plugins/log cat pkg/services/pluginsintegration/clientmiddleware/logger_middleware.goRepository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 3623
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 431
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 100
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 3010
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 12730
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 513
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 263
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 403
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 68
🏁 Script executed:
# Let's look at the contextual_logger_middleware to see if it also calls FromContext cat pkg/services/pluginsintegration/clientmiddleware/contextual_logger_middleware.goRepository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 2842
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-grafana-mirror
Length of output: 1300
FromContextreturns a disconnectedTestLogger, breaking potential test assertions throughLoggerMiddleware.The middleware at line 60 of
logger_middleware.gocallsm.logger.FromContext(ctx).Info(...). SinceFromContextreturns a brand-newTestLoggerinstance unrelated to the one tests hold a reference to, any assertions onInfoLogs.Calls,InfoLogs.Message, etc. will never capture logs written through the middleware. The interface specifies thatFromContextshould return "a new contextual Logger that has this logger's context"—meaning it should retain context from the original logger, not disconnect entirely. While no tests currently useTestLoggerwith this middleware (only production uses real loggers), this will silently break future tests.Fix by returning the receiver:
Proposed fix
func (f *TestLogger) FromContext(_ context.Context) Logger { - return NewTestLogger() + return f }📝 Committable suggestion
🤖 Prompt for AI Agents