Skip to content

Commit 6a4215a

Browse files
committed
doc/rgw/lua: add info on luarocks package
* remove duplicate contexts * trim trailing spaces Signed-off-by: Yuval Lifshitz <[email protected]>
1 parent 9238442 commit 6a4215a

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

doc/radosgw/lua-scripting.rst

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ This feature allows users to assign execution context to Lua scripts. The suppor
1313
- ``background`` which will execute within a specified time interval
1414
- ``getdata`` which will execute on objects' data when objects are downloaded
1515
- ``putdata`` which will execute on objects' data when objects are uploaded
16-
- ``preRequest`` which will execute a script before each operation is performed
17-
- ``postRequest`` which will execute after each operation is performed
1816

1917
A request (pre or post) or data (get or put) context script may be constrained to operations belonging to a specific tenant's users.
2018
The request context script can also access fields in the request and modify certain fields, as well as the `Global RGW Table`_.
21-
The data context script can access the content of the object as well as the request fields and the `Global RGW Table`_.
19+
The data context script can access the content of the object as well as the request fields and the `Global RGW Table`_.
2220
All Lua language features can be used in all contexts.
2321
An execution of a script in a context can use up to 500K byte of memory. This include all libraries used by Lua, but not the memory which is managed by the RGW itself, and may be accessed from Lua.
2422
To change this default value, use the ``rgw_lua_max_memory_per_state`` configuration parameter. Note that the basic overhead of Lua with its standard libraries is ~32K bytes. To disable the limit, use zero.
@@ -30,13 +28,14 @@ By default, the execution of a Lua script is limited to a maximum runtime of 100
3028

3129
By default, all Lua standard libraries are available in the script, however, in order to allow for additional Lua modules to be used in the script, we support adding packages to an allowlist:
3230

31+
- Make sure that the ``luarocks`` package manager is installed on the host.
3332
- Adding a Lua package to the allowlist, or removing a packge from it does not install or remove it. For the changes to take affect a "reload" command should be called.
3433
- In addition all packages in the allowlist are being re-installed using the luarocks package manager on radosgw restart.
3534
- To add a package that contains C source code that needs to be compiled, use the ``--allow-compilation`` flag. In this case a C compiler needs to be available on the host
3635
- Lua packages are installed in, and used from, a directory local to the radosgw. Meaning that Lua packages in the allowlist are separated from any Lua packages available on the host.
37-
By default, this directory would be ``/tmp/luarocks/<entity name>``. Its prefix part (``/tmp/luarocks/``) could be set to a different location via the ``rgw_luarocks_location`` configuration parameter.
36+
By default, this directory would be ``/tmp/luarocks/<entity name>``. Its prefix part (``/tmp/luarocks/``) could be set to a different location via the ``rgw_luarocks_location`` configuration parameter.
3837
Note that this parameter should not be set to one of the default locations where luarocks install packages (e.g. ``$HOME/.luarocks``, ``/usr/lib64/lua``, ``/usr/share/lua``).
39-
38+
4039

4140
.. toctree::
4241
:maxdepth: 1
@@ -46,12 +45,12 @@ Script Management via CLI
4645
-------------------------
4746

4847
To upload a script:
49-
48+
5049

5150
::
5251

53-
# radosgw-admin script put --infile={lua-file-path} --context={prerequest|postrequest|background|getdata|putdata} [--tenant={tenant-name}]
54-
52+
# radosgw-admin script put --infile={lua-file-path} --context={prerequest|postrequest|background|getdata|putdata} [--tenant={tenant-name}]
53+
5554
* When uploading a script with the ``background`` context, a tenant name should not be specified.
5655

5756
::
@@ -62,14 +61,14 @@ To upload a script:
6261
To print the content of the script to standard output:
6362

6463
::
65-
64+
6665
# radosgw-admin script get --context={preRequest|postRequest|background|getdata|putdata} [--tenant={tenant-name}]
6766

6867

6968
To remove the script:
7069

7170
::
72-
71+
7372
# radosgw-admin script rm --context={preRequest|postRequest|background|getdata|putdata} [--tenant={tenant-name}]
7473

7574

@@ -371,7 +370,7 @@ Lua Code Samples
371370
- Print information on source and destination objects in case of copy:
372371

373372
.. code-block:: lua
374-
373+
375374
function print_object(object)
376375
RGWDebugLog(" Name: " .. object.Name)
377376
RGWDebugLog(" Instance: " .. object.Instance)
@@ -415,7 +414,7 @@ Lua Code Samples
415414
end
416415
else
417416
RGWDebugLog("no " .. acl_type .. " ACL in request: " .. Request.Id)
418-
end
417+
end
419418
end
420419
421420
print_acl("User")
@@ -425,7 +424,7 @@ Lua Code Samples
425424
- Use of operations log only in case of errors:
426425

427426
.. code-block:: lua
428-
427+
429428
if Request.Response.HTTPStatusCode ~= 200 then
430429
RGWDebugLog("request is bad, use ops log")
431430
rc = Request.Log()
@@ -458,7 +457,7 @@ In the ``postrequest`` context we look at the metadata:
458457
for k, v in pairs(Request.HTTP.Metadata) do
459458
RGWDebugLog("key=" .. k .. ", " .. "value=" .. v)
460459
end
461-
460+
462461
- Use modules to create Unix socket based, JSON encoded, "access log":
463462

464463
First we should add the following packages to the allowlist:
@@ -473,7 +472,7 @@ Then, run a server to listen on the Unix socket. For example, use "netcat":
473472

474473
::
475474

476-
# rm -f /tmp/socket
475+
# rm -f /tmp/socket
477476
# nc -vklU /tmp/socket
478477

479478
And last, do a restart for the radosgw and upload the following script to the ``postrequest`` context:
@@ -550,26 +549,26 @@ in the ``putdata`` context, add the following script
550549
551550
function object_entropy()
552551
local byte_hist = {}
553-
local byte_hist_size = 256
552+
local byte_hist_size = 256
554553
for i = 1,byte_hist_size do
555-
byte_hist[i] = 0
556-
end
557-
local total = 0
554+
byte_hist[i] = 0
555+
end
556+
local total = 0
558557
559558
for i, c in pairs(Data) do
560-
local byte = c:byte() + 1
561-
byte_hist[byte] = byte_hist[byte] + 1
562-
total = total + 1
563-
end
559+
local byte = c:byte() + 1
560+
byte_hist[byte] = byte_hist[byte] + 1
561+
total = total + 1
562+
end
564563
565-
entropy = 0
564+
entropy = 0
566565
567566
for _, count in ipairs(byte_hist) do
568567
if count ~= 0 then
569568
local p = 1.0 * count / total
570569
entropy = entropy - (p * math.log(p)/math.log(byte_hist_size))
571-
end
572-
end
570+
end
571+
end
573572
574573
return entropy
575574
end

0 commit comments

Comments
 (0)