-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YUNIKORN-2965] Move statedump and stack REST to debug endpoint (#992)
The REST calls to get a statedump and the stacks of the system are exposed on the wrong endpoint. They belong in /debug and not in /ws/v1. Both are for troubleshooting only and the content is not stable. Placing a 301 redirect on the old endpoints for clients to follow. The proxy build into the web UI does not proxy the debug endpoints. Closes: #992 Signed-off-by: Craig Condit <ccondit@apache.org>
- Loading branch information
1 parent
6ef347b
commit 8d139b1
Showing
4 changed files
with
209 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
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 webservice | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
|
||
"github.com/apache/yunikorn-core/pkg/metrics/history" | ||
"github.com/apache/yunikorn-core/pkg/scheduler" | ||
) | ||
|
||
func Test_RedirectDebugHandler(t *testing.T) { | ||
defer ResetIMHistory() | ||
s := NewWebApp(&scheduler.ClusterContext{}, history.NewInternalMetricsHistory(5)) | ||
s.StartWebApp() | ||
defer func(s *WebService) { | ||
err := s.StopWebApp() | ||
if err != nil { | ||
t.Fatal("failed to stop webapp") | ||
} | ||
}(s) | ||
base := "http://localhost:9080" | ||
tests := []struct { | ||
name string | ||
reqURL string | ||
redirect string | ||
}{ | ||
{"statedump", "/ws/v1/fullstatedump", "/debug/fullstatedump"}, | ||
{"stacks", "/ws/v1/stack", "/debug/stack"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
client := &http.Client{ | ||
CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
if req.URL.Path != tt.redirect { | ||
return fmt.Errorf("expected redirect to '%s' got '%s'", tt.redirect, req.URL.Path) | ||
} | ||
return nil | ||
}, | ||
} | ||
resp, err := client.Get(base + tt.reqURL) | ||
assert.NilError(t, err, "unexpected error returned") | ||
_ = resp.Body.Close() // not interested in the error | ||
assert.Equal(t, resp.StatusCode, http.StatusOK, "expected OK after redirect") | ||
}) | ||
} | ||
} | ||
|
||
func Test_RouterHandling(t *testing.T) { | ||
s := NewWebApp(&scheduler.ClusterContext{}, nil) | ||
s.StartWebApp() | ||
defer func(s *WebService) { | ||
err := s.StopWebApp() | ||
if err != nil { | ||
t.Fatal("failed to stop webapp") | ||
} | ||
}(s) | ||
base := "http://localhost:9080" | ||
client := &http.Client{} | ||
// unsupported POST | ||
resp, err := client.Post(base+"/ws/v1/clusters", "application/json; charset=UTF-8", nil) | ||
assert.NilError(t, err, "unexpected error returned") | ||
assert.Equal(t, resp.StatusCode, http.StatusMethodNotAllowed, "expected method not allowed") | ||
var body []byte | ||
body, err = io.ReadAll(resp.Body) | ||
_ = resp.Body.Close() // not interested in the error | ||
assert.NilError(t, err, "unexpected error reading body") | ||
assert.Assert(t, body != nil, "expected body with status text") | ||
resp, err = client.Head(base + "/ws/v1/clusters") | ||
assert.NilError(t, err, "unexpected error returned") | ||
body, err = io.ReadAll(resp.Body) | ||
_ = resp.Body.Close() | ||
assert.NilError(t, err, "unexpected error reading body") | ||
assert.Assert(t, body != nil, "expected body with status text") | ||
assert.Equal(t, resp.StatusCode, http.StatusMethodNotAllowed, "expected method not allowed") | ||
// get with trailing slash | ||
resp, err = client.Get(base + "/ws/v1/clusters/") | ||
assert.NilError(t, err, "unexpected error returned") | ||
_ = resp.Body.Close() | ||
assert.Equal(t, resp.StatusCode, http.StatusOK, "expected OK") | ||
// get with case difference | ||
resp, err = client.Get(base + "/ws/v1/CLUSTERS") | ||
assert.NilError(t, err, "unexpected error returned") | ||
_ = resp.Body.Close() | ||
assert.Equal(t, resp.StatusCode, http.StatusOK, "expected OK") | ||
} |