-
Notifications
You must be signed in to change notification settings - Fork 365
feat: add unified API server with debugging capabilities #2550
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
Changes from all commits
a00cc1e
abf96a4
e384cc3
2b38495
0dc2c83
8516c42
2c7bfbd
3561e6a
933befb
c6ad03f
9e48671
e1f9c52
ef5851f
324e684
2248f46
ae76e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package server | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/apache/apisix-ingress-controller/internal/provider" | ||
| ) | ||
|
|
||
| type Server struct { | ||
| server *http.Server | ||
| mux *http.ServeMux | ||
| } | ||
|
|
||
| func (s *Server) Start(ctx context.Context) error { | ||
| stop := make(chan error, 1) | ||
| go func() { | ||
| if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
| stop <- err | ||
| } | ||
| close(stop) | ||
| }() | ||
| select { | ||
| case <-ctx.Done(): | ||
| shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| return s.server.Shutdown(shutdownCtx) | ||
| case err := <-stop: | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| func (s *Server) Register(pathPrefix string, registrant provider.RegisterHandler) { | ||
| subMux := http.NewServeMux() | ||
| registrant.Register(pathPrefix, subMux) | ||
| s.mux.Handle(pathPrefix+"/", http.StripPrefix(pathPrefix, subMux)) | ||
| s.mux.HandleFunc(pathPrefix, func(w http.ResponseWriter, r *http.Request) { | ||
| http.Redirect(w, r, pathPrefix+"/", http.StatusPermanentRedirect) | ||
| }) | ||
| } | ||
|
Comment on lines
+51
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The debug server currently has no authentication mechanism, making it accessible to anyone who can reach the endpoint. Should we consider incorporating certain authentication mechanisms?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original requirement was to return simple UI friendly HTML. Adding authentication will mean adding another page for login. Maybe we can use cookie based authentication and add one more simple login html page.
@bzp2010 @ronething @AlinsRan What do you think?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's enough not to expose the port, just like the control-api.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It might be a bit different. This debug server has exposed SSL/Consumer resources, but the control-api does not.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You're right.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the only k8s native way to enable/disable this dynamically will be to use some existing CR for it. But that might be an overkill. I think we should opt for one of the two ways:
If it's okay to enable/disable this statically then I recommend the first way is good enough or else it will be overengineering. Later if use case emerges about dynamically enabling/disabling, we can spend some thought here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's exactly what I was thinking. A simple static config. However, I must confirm whether the restart required to enable this feature would disrupt the current "state". Specifically, can we guarantee consistent results based on unchanged configurations? We need to ensure that the restart does not corrupt any potentially existing in-memory state, thereby preventing the debugging of previously existing issues. For example, we sometimes encounter problems that resolve after a restart, making it impossible to analyze the root cause. Can anyone answer this question?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s not possible to guarantee the preservation of “state” across a restart. For an ingress controller, a restart is typically the last-resort mechanism to recover state, so if you need to debug live in-memory data, it will naturally no longer be available after restarting. At present, for security and simplicity reasons, we recommend keeping the debug API disabled by default and enabling it only via static configuration.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. added the boolean in static config.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The state itself isn't critical, but it would be preferable if you could confirm it doesn't impact configuration generation. The key point is |
||
|
|
||
| func NewServer(addr string) *Server { | ||
| mux := http.NewServeMux() | ||
| return &Server{ | ||
| server: &http.Server{ | ||
| Addr: addr, | ||
| Handler: mux, | ||
| }, | ||
| mux: mux, | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.