Skip to content

Instantly share code, notes, and snippets.

@yuvalif
Created July 18, 2023 10:38
Show Gist options
  • Save yuvalif/95b8ed9ea73ab4591c59644a050e01e2 to your computer and use it in GitHub Desktop.
Save yuvalif/95b8ed9ea73ab4591c59644a050e01e2 to your computer and use it in GitHub Desktop.
  • start a vstart cluster
MON=1 OSD=1 MDS=0 MGR=0 RGW=1 ../src/vstart.sh -n -d
  • create a lua file that implemets access log and depends on cjson and socket packages
  if Request.RGWOp == "get_obj" then
    local json = require("cjson")
    local socket = require("socket")
    local unix = require("socket.unix")
    local s = assert(unix())
    E = {}
    msg = {bucket = (Request.Bucket or (Request.CopyFrom or E).Bucket).Name,
      time = Request.Time,
      operation = Request.RGWOp,
      http_status = Request.Response.HTTPStatusCode,
      error_code = Request.Response.HTTPStatus,
      object_size = Request.Object.Size,
      trans_id = Request.TransactionId}
    assert(s:connect("/tmp/socket"))
    assert(s:send(json.encode(msg).."\n"))
    assert(s:close())
  end
  • upload the file to the rgw and add required packages to allowlist
bin/radosgw-admin script put --infile test.lua --context postrequest
bin/radosgw-admin script-package add --package=lua-cjson --allow-compilation
bin/radosgw-admin script-package add --package=luasocket --allow-compilation
  • start a unix socket server to receive the access log messages
rm -f /tmp/socket
nc -vklU /tmp/socket
  • create a bucket, upload a file and then access it
aws --endpoint-url http://localhost:8000 s3 mb s3://fish
aws --endpoint-url http://localhost:8000 s3 cp myfile s3://fish/
aws --endpoint-url http://localhost:8000 s3 cp s3://fish/myfile .
  • no messages should be seen by the unix socket server, and rgw debug log should show lua error indicating that package is missing
  • call "reload"
bin/radosgw-admin script-package reload
  • access the file again
aws --endpoint-url http://localhost:8000 s3 cp s3://fish/myfile .
  • now a JSON log message should be seen in the unix socket server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment