Skip to content

Commit

Permalink
fix viewer redirects (#7103) (#7120)
Browse files Browse the repository at this point in the history
  • Loading branch information
adameat authored Jul 29, 2024
1 parent 690f5e8 commit 19756b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
29 changes: 28 additions & 1 deletion ydb/core/mon/async_http_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,36 @@ class THttpMonServiceNodeRequest : public TActorBootstrapped<THttpMonServiceNode
}
}

TString RewriteLocationWithNode(const TString& response) {
NHttp::THttpParser<NHttp::THttpResponse, NHttp::TSocketBuffer> parser(response);

NHttp::THeadersBuilder headers(parser.Headers);
headers.Set("Location", TStringBuilder() << "/node/" << TActivationContext::ActorSystem()->NodeId << headers["Location"]);

NHttp::THttpRenderer<NHttp::THttpResponse, NHttp::TSocketBuffer> renderer;
renderer.InitResponse(parser.Protocol, parser.Version, parser.Status, parser.Message);
renderer.Set(headers);
if (parser.HaveBody()) {
renderer.SetBody(parser.Body); // it shouldn't be here, 30x with a body is a bad idea
}
renderer.Finish();
return renderer.AsString();
}

void Handle(NHttp::TEvHttpProxy::TEvHttpOutgoingResponse::TPtr& ev) {
TString httpResponse = ev->Get()->Response->AsString();
switch (FromStringWithDefault<int>(ev->Get()->Response->Status)) {
case 301:
case 303:
case 307:
case 308:
if (!NHttp::THeaders(ev->Get()->Response->Headers).Get("Location").starts_with("/node/")) {
httpResponse = RewriteLocationWithNode(httpResponse);
}
break;
}
auto response = std::make_unique<TEvMon::TEvMonitoringResponse>();
response->Record.SetHttpResponse(ev->Get()->Response->AsString());
response->Record.SetHttpResponse(httpResponse);
Send(Event->Sender, response.release(), 0, Event->Cookie);
PassAway();
}
Expand Down
18 changes: 9 additions & 9 deletions ydb/core/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
JsonHandlers.JsonHandlersIndex[oldPath] = JsonHandlers.JsonHandlersIndex[newPath];
}

// TODO: redirect old paths
Redirect307["/viewer/v2/json/config"] = "/viewer/config";
Redirect307["/viewer/v2/json/sysinfo"] = "/viewer/sysinfo";
Redirect307["/viewer/v2/json/pdiskinfo"] = "/viewer/pdiskinfo";
Redirect307["/viewer/v2/json/vdiskinfo"] = "/viewer/vdiskinfo";
Redirect307["/viewer/v2/json/storage"] = "/viewer/storage";
Redirect307["/viewer/v2/json/nodelist"] = "/viewer/nodelist";
Redirect307["/viewer/v2/json/tabletinfo"] = "/viewer/tabletinfo";
Redirect307["/viewer/v2/json/nodeinfo"] = "/viewer/nodeinfo";
// TODO: redirect of very old paths
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/config"] = JsonHandlers.JsonHandlersIndex["/viewer/config"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/sysinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/sysinfo"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/pdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/pdiskinfo"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/vdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/vdiskinfo"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/storage"] = JsonHandlers.JsonHandlersIndex["/viewer/storage"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodelist"] = JsonHandlers.JsonHandlersIndex["/viewer/nodelist"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/tabletinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/tabletinfo"];
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodeinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/nodeinfo"];

TWhiteboardInfo<NKikimrWhiteboard::TEvNodeStateResponse>::InitMerger();
TWhiteboardInfo<NKikimrWhiteboard::TEvBSGroupStateResponse>::InitMerger();
Expand Down

0 comments on commit 19756b2

Please sign in to comment.