-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console: autorequire modules suitable for administration and debugging #9986
Comments
I feel uneasy because of inconsistency between the console mode and the lua script mode. Namely, things one tried in console doesn't work in a script passed as an argument to the Tarantool. |
@sergos I agree with your point in context of some other differences. For example, #1133 is the great addition that makes the interactive mode quite similar to a Lua file code. As another example, I would like to save locals within a console session to ease copy-paste from Lua files to console. (A usual function in a Lua file has My proposal adds the difference deliberately. Moreover, the goal is to have these shortcuts for the interactive work and have them only in the interactive mode. Let's look on your doubt more precisely: consider a bad scenario. An application developer wrote some code in a console, debugged it, then copy-pasted it to a Lua file (BTW, I often write code this way). Let's assume that some of the used modules are not The copy-pasted code has the following properties:
The 'forgot to add I don't think that we add any UX problem here. And I'm sure that it makes the interactive debugging/administration more convenient. |
Feedback from @Mons: it would be good to allow to configure the list of default console upvalues. I propose the following API. local console = require('console')
-- A Lua table, filled by the modules as describe above.
console.default_upvalues
-- Refuse the autorequire for a particular module.
console.default_upvalues.fio = nil
-- Add a module to the autorequire list.
console.default_upvalues.mymodule = require('mymodule') The |
There are a lot of runtimes, where imports are omitted and implied for easiness of writing code by hand. And barely someone is annoyed when in the leetcode console they have everything imported, and while copied to the script they require additional imports. |
Fixes tarantool#9986 @TarantoolBot document Title: Interactive console now autorequires a couple of built-in modules There are built-in modules that are frequently used for administration or debugging purposes. It is convenient to have them accessible in the interactive console without extra actions. They're accessible now without a manual `require` call if the `console_session_scope_vars` compat option is set to `new` (see also tarantool/doc#4191). The list of the autorequired modules is below. * clock * compat * config * datetime * decimal * fiber * fio * fun * json * log * msgpack * popen * uuid * varbinary * yaml See tarantool#9986 for motivation behind this feature. This list forms so called initial environment for an interactive console session. The default initial environment may be adjusted by an application, for example, to include application specific administrator functions. Two public functions are added for this purpose: `console.initial_env()` and `console.set_initial_env(env)`. Example 1 (keep autorequired modules, but add one more variable): ```lua local console = require('console') -- Add myapp_info function. local initial_env = console.initial_env() initial_env.myapp_info = function() <...> end ``` Example 2 (replace the whole initial environment): ```lua local console = require('console') -- Add myapp_info function, discard the autorequired modules. console.set_initial_env({ myapp_info = function() <...> end, }) ``` The `console.set_initial_env()` call without an argument or with a `nil` argument drops the initial environment to its default. A modification of the initial environment doesn't affect existing console sessions. It affects console sessions that are created after the modification. Please, adjust the `console_session_scope_vars` compat option description and extend the built-in `console` module reference with the new functions.
Fixes tarantool#9986 @TarantoolBot document Title: Interactive console now autorequires a couple of built-in modules There are built-in modules that are frequently used for administration or debugging purposes. It is convenient to have them accessible in the interactive console without extra actions. They're accessible now without a manual `require` call if the `console_session_scope_vars` compat option is set to `new` (see also tarantool/doc#4191). The list of the autorequired modules is below. * clock * compat * config * datetime * decimal * ffi * fiber * fio * fun * json * log * msgpack * popen * uuid * varbinary * yaml See tarantool#9986 for motivation behind this feature. This list forms so called initial environment for an interactive console session. The default initial environment may be adjusted by an application, for example, to include application specific administrator functions. Two public functions are added for this purpose: `console.initial_env()` and `console.set_initial_env(env)`. Example 1 (keep autorequired modules, but add one more variable): ```lua local console = require('console') -- Add myapp_info function. local initial_env = console.initial_env() initial_env.myapp_info = function() <...> end ``` Example 2 (replace the whole initial environment): ```lua local console = require('console') -- Add myapp_info function, discard the autorequired modules. console.set_initial_env({ myapp_info = function() <...> end, }) ``` The `console.set_initial_env()` call without an argument or with a `nil` argument drops the initial environment to its default. A modification of the initial environment doesn't affect existing console sessions. It affects console sessions that are created after the modification. Please, adjust the `console_session_scope_vars` compat option description and extend the built-in `console` module reference with the new functions.
Fixes tarantool#9986 @TarantoolBot document Title: Interactive console now autorequires a couple of built-in modules There are built-in modules that are frequently used for administration or debugging purposes. It is convenient to have them accessible in the interactive console without extra actions. They're accessible now without a manual `require` call if the `console_session_scope_vars` compat option is set to `new` (see also tarantool/doc#4191). The list of the autorequired modules is below. * clock * compat * config * datetime * decimal * ffi * fiber * fio * fun * json * log * msgpack * popen * uuid * varbinary * yaml See tarantool#9986 for motivation behind this feature. This list forms so called initial environment for an interactive console session. The default initial environment may be adjusted by an application, for example, to include application specific administrator functions. Two public functions are added for this purpose: `console.initial_env()` and `console.set_initial_env(env)`. Example 1 (keep autorequired modules, but add one more variable): ```lua local console = require('console') -- Add myapp_info function. local initial_env = console.initial_env() initial_env.myapp_info = function() <...> end ``` Example 2 (replace the whole initial environment): ```lua local console = require('console') -- Add myapp_info function, discard the autorequired modules. console.set_initial_env({ myapp_info = function() <...> end, }) ``` The `console.set_initial_env()` call without an argument or with a `nil` argument drops the initial environment to its default. A modification of the initial environment doesn't affect existing console sessions. It affects console sessions that are created after the modification. Please, adjust the `console_session_scope_vars` compat option description and extend the built-in `console` module reference with the new functions.
Fixes #9986 @TarantoolBot document Title: Interactive console now autorequires a couple of built-in modules There are built-in modules that are frequently used for administration or debugging purposes. It is convenient to have them accessible in the interactive console without extra actions. They're accessible now without a manual `require` call if the `console_session_scope_vars` compat option is set to `new` (see also tarantool/doc#4191). The list of the autorequired modules is below. * clock * compat * config * datetime * decimal * ffi * fiber * fio * fun * json * log * msgpack * popen * uuid * varbinary * yaml See #9986 for motivation behind this feature. This list forms so called initial environment for an interactive console session. The default initial environment may be adjusted by an application, for example, to include application specific administrator functions. Two public functions are added for this purpose: `console.initial_env()` and `console.set_initial_env(env)`. Example 1 (keep autorequired modules, but add one more variable): ```lua local console = require('console') -- Add myapp_info function. local initial_env = console.initial_env() initial_env.myapp_info = function() <...> end ``` Example 2 (replace the whole initial environment): ```lua local console = require('console') -- Add myapp_info function, discard the autorequired modules. console.set_initial_env({ myapp_info = function() <...> end, }) ``` The `console.set_initial_env()` call without an argument or with a `nil` argument drops the initial environment to its default. A modification of the initial environment doesn't affect existing console sessions. It affects console sessions that are created after the modification. Please, adjust the `console_session_scope_vars` compat option description and extend the built-in `console` module reference with the new functions.
It is convenient to have some built-in modules accessible right after connection to the admin console (using
tt connect
) or after starting a debugging session (usingtarantool -i
).These are ones from where an admin wants to obtain state information:
compat
,fiber.info()
,config:info()
,config:get()
are such examples.fun
is often used to filter/transform such information.There are modules that implement a data type and they're used to write a value of the given type to the database:
uuid
,datetime
,decimal
,varbinary
.Also, some modules are often used in interactive experimenting:
clock.bench()
,ffi.cast()
and serializers such asjson
,yaml
,msgpack
.There are function that are useful for debugging:
fio.open(<...>):read()
,log.info()
,popen.shell()
.The proposed list of modules:
I propose to don't add these names to globals, but make them accessible only in the interactive console: a code in the Lua files still need to
require
the modules. It is easy to do after implementing console session scoped variables, see #9985.I propose to autorequire the modules in the interactive console session under the same
console_session_scope_vars
compat option.The text was updated successfully, but these errors were encountered: