Skip to content

feat: add openfunction plugin#7634

Merged
spacewander merged 79 commits into
apache:masterfrom
jackkkkklee:master
Sep 2, 2022
Merged

feat: add openfunction plugin#7634
spacewander merged 79 commits into
apache:masterfrom
jackkkkklee:master

Conversation

@jackkkkklee

Copy link
Copy Markdown
Contributor

Description

support openfunction serverless platform
implement proposal #7404

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 first)

@jackkkkklee jackkkkklee changed the title add openfunction plugin feat: add openfunction plugin Aug 9, 2022
Comment thread apisix/plugins/openfunction.lua Outdated
end


function _M.access(conf, ctx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And code in init.lua, you can refer to azure-function for the detail.

Comment thread ci/init-plugin-test-service.sh Outdated
}

set_container_registry_secret() {
REGISTRY_SERVER=https://index.docker.io/v1/ REGISTRY_USER=apisixtestaccount123 REGISTRY_PASSWORD=apisixtestaccount

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use this? We can push the docker images through kind load docker-image.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part of the openfuction building lifecycle, pushing the image to a registry, needs it.Will it be better to build locally to avoid this part?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should avoid exposing your secrets here. By the way, is this for building openfunction itself or the function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure,for the function.
I 'll avoid it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a lighter way (using less runtime memory) to run these services? I'm worried that running these services will again fill up the memory of the server where github action is running CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan is to just run the function locally in docker with the image I created by openfunction platform previously,which doesn't need to install many services. I'll update it after test.

Comment thread docs/en/latest/plugins/openfunction.md Outdated
Comment thread docs/en/latest/plugins/openfunction.md Outdated

## Enabling the Plugin

Before configuring the Plugin, you need to have OpenFunction running. The example below shows OpenFunction installed in Helm:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also give a link to the installation page of OpenFunction.

Comment thread docs/en/latest/plugins/openfunction.md Outdated
Comment thread apisix/plugins/openfunction.lua Outdated
@tokers

tokers commented Aug 11, 2022

Copy link
Copy Markdown
Contributor

@jackkkkklee Please make the CI pass. Thanks!

Comment thread docs/en/latest/plugins/openfunction.md Outdated
Comment thread docs/en/latest/plugins/openfunction.md Outdated
Comment thread apisix/plugins/openfunction.lua Outdated
local function request_processor(conf, ctx, params)
local headers = params.headers or {}
-- setting authorization headers if not already set
if not headers["Authorization"] and conf.authorization

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the header here need to be lower-case? And we need a test case that the user-specific Authorization header has higher priority.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminding.
Lower-case for headers is needed if you mean the local param 'headers', or you mean the header of docs above?

Test case added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local param headers.

Comment thread apisix/plugins/openfunction.lua Outdated
local function request_processor(conf, ctx, params)
local headers = params.headers or {}
-- setting authorization headers if not already set
if not headers["Authorization"] and conf.authorization

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local param headers.

Comment thread ci/init-plugin-test-service.sh Outdated
docker exec -i vault sh -c "VAULT_TOKEN='root' VAULT_ADDR='http://0.0.0.0:8200' vault secrets enable -path=kv -version=1 kv"

# prepare openfunction env
docker pull apisixtestaccount123/sample-go-func:v1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if OpenFunction releases some sample functions 🤔.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do, but the functions just print the URI of request, which doesn't meet my test cases(e.g. test body, test headers). Therefore, I just fork and change their functions a little bit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we expose the Dockerfile for apisixtestaccount123/sample-go-func:v1?
My concern is that when we want to make updates based on this image later, then it will be difficult for us to do so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ‘ll add local function building process latter,then we just need to update the code of repositories.

@jackkkkklee

Copy link
Copy Markdown
Contributor Author

@tokers Could you please rerun ”CI / build (ubuntu-20.04, linux_openresty, t/node t/pubsub t/router t/script t/stream-node t/utils t/w... (pull_request) Failing after 17m...“?

@tzssangglass

Copy link
Copy Markdown
Member

Could you please rerun ”CI / build (ubuntu-20.04, linux_openresty, t/node t/pubsub t/router t/script t/stream-node t/utils t/w... (pull_request) Failing after 17m...“?

done

@jackkkkklee
jackkkkklee requested a review from tokers August 30, 2022 04:51
tokers
tokers previously approved these changes Aug 30, 2022
Comment thread ci/init-plugin-test-service.sh Outdated

# prepare vault kv engine
docker exec -i vault sh -c "VAULT_TOKEN='root' VAULT_ADDR='http://0.0.0.0:8200' vault secrets enable -path=kv -version=1 kv"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to touch this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No,we don't . I just run the function image in the dockerfile . And I ’ll discard the change in this file .

Comment thread docs/en/latest/plugins/openfunction.md Outdated
@jackkkkklee
jackkkkklee requested a review from tokers September 1, 2022 08:04
@spacewander
spacewander merged commit 47187fa into apache:master Sep 2, 2022
hongbinhsu pushed a commit to fitphp/apix that referenced this pull request Sep 10, 2022
* upstream/master: (214 commits)
  feat: set constants.apisix_lua_home for used by plugins (apache#7893)
  fix: response-rewrite plugin might cause Apache AIPSIX hanging (apache#7836)
  test: sleep 1 second in t/cli/test_upstream_mtls.sh (apache#7889)
  fix: reload once when log rotate (apache#7869)
  change: move etcd conf under deployment (apache#7860)
  fix: plugin metadata missing v3 adapter call (apache#7877)
  docs: add ClickHouse and Elasticsearch loggers. (apache#7848)
  docs(plugin): refactor limit-conn.md (apache#7857)
  feat: call `destroy` method when Nginx exits (apache#7866)
  feat: Add ability to inject headers via prefix to otel traces (apache#7822)
  docs(plugin): refactor proxy-cache.md (apache#7858)
  fix: don't enable passive healthcheck by default (apache#7850)
  feat: add openfunction plugin (apache#7634)
  fix(zipkin): send trace IDs with a reject sampling decision (apache#7833)
  fix: Change opentelemetry's span kind to server (apache#7830)
  docs(hmac-auth): additional details for generating signing_string (apache#7816)
  docs: correct the test-nginx description (apache#7818)
  docs: add docs of workflow plugin (apache#7813)
  docs(FAQ): add how to detect APISIX alive status (apache#7812)
  feat: add elasticsearch-logger (apache#7643)
  ...
Liu-Junlin pushed a commit to Liu-Junlin/apisix that referenced this pull request Nov 4, 2022
Co-authored-by: Alex Zhang <[email protected]>
Co-authored-by: 罗泽轩 <[email protected]>
Co-authored-by: Fei Han <[email protected]>
Co-authored-by: LCW <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants