You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "Revolyssup (via GitHub)" <gi...@apache.org> on 2024/11/29 10:32:43 UTC
[PR] feat: support _meta.pre_function to execute custom logic before execu… [apisix]
Revolyssup opened a new pull request, #11793:
URL: https://github.com/apache/apisix/pull/11793
…tion of each phase
### Description
<!-- Please include a summary of the change and which issue is fixed. -->
<!-- Please also include relevant motivation and context. -->
Fixes # (issue)
Add pre_function to the meta of the plugin to allow some personalized code to run before all plugins run. For example, register personalized variables so that these temporary variables can be referenced and used in the plugin.
### Checklist
- [ ] I have explained the need for this PR and the problem it solves
- [ ] I have explained the changes or the new features added to this PR
- [ ] I have added tests corresponding to this change
- [ ] I have updated the documentation to reflect this change
- [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
<!--
Note
1. Mark the PR as draft until it's ready to be reviewed.
2. Always add/update tests for any changes unless you have a good reason.
3. Always update the documentation to reflect the changes made in the PR.
4. Make a new commit to resolve conversations instead of `push -f`.
5. To resolve merge conflicts, merge master instead of rebasing.
6. Use "request review" to notify the reviewer after making changes.
7. Only a reviewer can mark a conversation as resolved.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on code in PR #11793:
URL: https://github.com/apache/apisix/pull/11793#discussion_r1899571673
##########
apisix/plugin.lua:
##########
@@ -34,6 +34,9 @@ local type = type
local local_plugins = core.table.new(32, 0)
local tostring = tostring
local error = error
+-- make linter happy to avoid error: getting the Lua global "load"
Review Comment:
This is needed. The lj-releng file just added to the keywords that can be used with the ignore comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup merged PR #11793:
URL: https://github.com/apache/apisix/pull/11793
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on code in PR #11793:
URL: https://github.com/apache/apisix/pull/11793#discussion_r1897466879
##########
utils/lj-releng:
##########
@@ -0,0 +1,228 @@
+#!/usr/bin/env perl
Review Comment:
done. here is the smaller pr https://github.com/apache/apisix/pull/11862 @membphis
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on code in PR #11793:
URL: https://github.com/apache/apisix/pull/11793#discussion_r1896487756
##########
utils/lj-releng:
##########
@@ -0,0 +1,213 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Getopt::Std;
+
+my (@luas, @tests);
+
+my $hits = 0;
+my $RED = "\033[1;31m";
+my $NC = "\033[0m"; # No Color
+
+my %opts;
+getopts('Lse', \%opts) or die "Usage: lj-releng [-L] [-s] [-e] [files]\n";
+
+my $silent = $opts{s};
+my $stop_on_error = $opts{e};
+my $no_long_line_check = $opts{L};
+
+my $check_lua_ver = "luajit -v | awk '{print\$2}'| grep 2.1";
+my $output = `$check_lua_ver`;
+if ($output eq '') {
+ die "ERROR: lj-releng ONLY supports LuaJIT 2.1!\n";
+}
+
+if ($#ARGV != -1) {
+ @luas = @ARGV;
+
+} else {
+ @luas = split /\n/, `find . -name '*.lua'`;
+ if (-d 't') {
+ @tests = map glob, qw{ t/*.t t/*/*.t t/*/*/*.t };
+ }
+}
+
+for my $f (sort @luas) {
+ process_file($f);
+}
+
+for my $t (@tests) {
+ blank(qq{grep -H -n --color -E '\\--- ?(ONLY|LAST)' $t});
+}
+
+if ($hits) {
+ exit 1;
+}
+
+# p: prints a string to STDOUT appending \n
+# w: prints a string to STDERR appending \n
+# Both respect the $silent value
+sub p { print "$_[0]\n" if (!$silent) }
+sub w { warn "$_[0]\n" if (!$silent) }
+
+# blank: runs a command and looks at the output. If the output is not
+# blank it is printed (and the program dies if stop_on_error is 1)
+sub blank {
+ my ($command) = @_;
+ if ($stop_on_error) {
+ my $output = `$command`;
+ if ($output ne '') {
+ die $output;
+ }
+ } else {
+ system($command);
+ }
+}
+
+my $version;
+sub process_file {
+ my $file = shift;
+ # Check the sanity of each .lua file
+ open my $in, $file or
+ die "ERROR: Can't open $file for reading: $!\n";
+ my $found_ver;
+ while (<$in>) {
+ my ($ver, $skipping);
+ if (/(?x) (?:_VERSION|version) \s* = .*? ([\d\.]*\d+) (.*? SKIP)?/) {
+ my $orig_ver = $ver = $1;
+ $found_ver = 1;
+ $skipping = $2;
+ $ver =~ s{^(\d+)\.(\d{3})(\d{3})$}{join '.', int($1), int($2), int($3)}e;
+ print("$file: $orig_ver ($ver)\n");
+ last;
+
+ } elsif (/(?x) (?:_VERSION|version) \s* = \s* ([a-zA-Z_]\S*)/) {
+ print("$file: $1\n");
+ $found_ver = 1;
+ last;
+ }
+
+ if ($ver and $version and !$skipping) {
+ if ($version ne $ver) {
+ die "$file: $ver != $version\n";
+ }
+ } elsif ($ver and !$version) {
+ $version = $ver;
+ }
+ }
+ # if (!$found_ver) {
+ # w("WARNING: No \"_VERSION\" or \"version\" field found in `$file`.");
+ # }
+ close $in;
+
+ #p("Checking use of Lua global variables in file $file...");
+ #p("op no. line opcode args ; code");
+ my $cmd = "luajit -bL $file";
+ open $in, "$cmd|"
+ or die "cannot open output pipe for \"$cmd\": $!";
+ my @sections;
+ my $sec;
+ while (<$in>) {
+
+ #warn "line: $_";
+
+ if (/^-- BYTECODE -- \S.*?:(\d+)-\d+$/) {
+ my $def_line = $1;
+ #warn "$file: $line";
+ if (defined $sec) {
+ push @sections, $sec;
+
+ }
+ $sec = {
+ def_line => $def_line,
+ gsets => [],
+ ggets => [],
+ };
+ next;
+ }
+
+ if (/^ \d+ \s+ \[ (\d+) \] \s+ (?: \W+ \s+ )? G([GS])ET \s+ .*? ; \s+ \"([^"]+)" $/x) {
+ my ($line, $op, $name) = ($1, $2, $3);
+
+ #warn "found: $line $op $name";
+ if ($op eq 'S') {
+ push @{ $sec->{gsets} }, [$line, $name];
+ } else {
+ push @{ $sec->{ggets} }, [$line, $name];
+ }
+
+ next;
+ }
+
+ if (/^ \d+ \s+ \[ \d+ \] \s+ (G[GS]ET) \s+ $/x) {
+ die "bad $1 instruction: $_";
+ }
+ }
+ close $in;
+
+ if (defined $sec) {
+ push @sections, $sec;
+ }
+
+ my $last_idx = $#sections;
+ my $i = 0;
+ for my $sec (@sections) {
+ my $def_line = $sec->{def_line};
+
+ my $gsets = $sec->{gsets};
+ my $ggets = $sec->{ggets};
+
+ for my $gset (@$gsets) {
+ $hits++;
+ my ($line, $name) = @$gset;
+ warn "${RED}ERROR${NC}: $file: line $line: setting the Lua global ",
+ "\"$name\"\n";
+ }
+
+ if ($i == $last_idx) {
+ # being the top-level chunk
+
+ for my $gget (@$ggets) {
+ my ($line, $name) = @$gget;
+
+ if ($name =~ /^ (?: require|type|tostring|error|ngx|ndk|jit
+ |setmetatable|getmetatable|string|table|io
+ |os|print|tonumber|math|pcall|xpcall|unpack
+ |pairs|ipairs|assert|module|package
+ |coroutine|[gs]etfenv|next|rawget|rawset
+ |loadstring|dofile|collectgarbage|load
Review Comment:
`load` is added here which is not present in original lj-relang causing lint check to fail
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on code in PR #11793:
URL: https://github.com/apache/apisix/pull/11793#discussion_r1899545961
##########
apisix/plugin.lua:
##########
@@ -34,6 +34,9 @@ local type = type
local local_plugins = core.table.new(32, 0)
local tostring = tostring
local error = error
+-- make linter happy to avoid error: getting the Lua global "load"
Review Comment:
I guess this is no longer needed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "membphis (via GitHub)" <gi...@apache.org>.
membphis commented on PR #11793:
URL: https://github.com/apache/apisix/pull/11793#issuecomment-2519274623
@Revolyssup some CI test cases failed
<img width="968" alt="image" src="https://github.com/user-attachments/assets/8c2c4d7f-e411-4793-9334-da0e72d2d36e">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: support _meta.pre_function to execute custom logic before execution of each phase [apisix]
Posted by "membphis (via GitHub)" <gi...@apache.org>.
membphis commented on code in PR #11793:
URL: https://github.com/apache/apisix/pull/11793#discussion_r1896526771
##########
utils/lj-releng:
##########
@@ -0,0 +1,228 @@
+#!/usr/bin/env perl
Review Comment:
can we update the tool `utils/lj-releng` in a separate PR?
one PR for one thing
small PR is easier to review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org