[feature](http) refactor version info and add new http api for get version info (#12513)

Refactor version info and add new http api for get version info
This commit is contained in:
xueweizhang
2022-09-22 10:53:04 +08:00
committed by GitHub
parent 77e423042c
commit 70ab9cb43e
10 changed files with 600 additions and 6 deletions

View File

@ -53,4 +53,5 @@ add_library(Webserver STATIC
action/check_rpc_channel_action.cpp
action/reset_rpc_channel_action.cpp
action/check_tablet_segment_action.cpp
action/version_action.cpp
)

View File

@ -0,0 +1,59 @@
// 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.
#include "http/action/version_action.h"
#include <sstream>
#include <string>
#include "gen_cpp/version.h"
#include "http/http_channel.h"
#include "http/http_headers.h"
#include "http/http_request.h"
#include "http/http_response.h"
#include "http/http_status.h"
#include "util/easy_json.h"
namespace doris {
const static std::string HEADER_JSON = "application/json";
VersionAction::VersionAction() {}
void VersionAction::handle(HttpRequest* req) {
EasyJson be_version_info;
be_version_info["msg"] = "success";
be_version_info["code"] = 0;
EasyJson data = be_version_info.Set("data", EasyJson::kObject);
EasyJson version_info = data.Set("beVersionInfo", EasyJson::kObject);
version_info["dorisBuildVersionPrefix"] = DORIS_BUILD_VERSION_PREFIX;
version_info["dorisBuildVersionMajor"] = DORIS_BUILD_VERSION_MAJOR;
version_info["dorisBuildVersionMinor"] = DORIS_BUILD_VERSION_MINOR;
version_info["dorisBuildVersionPatch"] = DORIS_BUILD_VERSION_PATCH;
version_info["dorisBuildVersionRcVersion"] = DORIS_BUILD_VERSION_RC_VERSION;
version_info["dorisBuildVersion"] = DORIS_BUILD_VERSION;
version_info["dorisBuildHash"] = DORIS_BUILD_HASH;
version_info["dorisBuildShortHash"] = DORIS_BUILD_SHORT_HASH;
version_info["dorisBuildTime"] = DORIS_BUILD_TIME;
version_info["dorisBuildInfo"] = DORIS_BUILD_INFO;
be_version_info["count"] = 0;
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
HttpChannel::send_reply(req, HttpStatus::OK, be_version_info.ToString());
}
} // end namespace doris

View File

@ -0,0 +1,39 @@
// 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.
#ifndef DORIS_BE_SRC_HTTP_ACTION_VERSION_ACTION_H
#define DORIS_BE_SRC_HTTP_ACTION_VERSION_ACTION_H
#include "http/http_handler.h"
namespace doris {
class ExecEnv;
// Get BE version info from http API.
class VersionAction : public HttpHandler {
public:
VersionAction();
virtual ~VersionAction() {};
void handle(HttpRequest* req) override;
};
} // end namespace doris
#endif // DORIS_BE_SRC_HTTP_ACTION_VERSION_ACTION_H

View File

@ -36,6 +36,7 @@
#include "http/action/tablet_migration_action.h"
#include "http/action/tablets_distribution_action.h"
#include "http/action/tablets_info_action.h"
#include "http/action/version_action.h"
#include "http/default_path_handlers.h"
#include "http/ev_http_server.h"
#include "http/http_method.h"
@ -88,6 +89,10 @@ Status HttpService::start() {
_ev_http_server->register_handler(HttpMethod::HEAD, "/api/_load_error_log",
error_log_download_action);
// Register BE version action
VersionAction* version_action = _pool.add(new VersionAction());
_ev_http_server->register_handler(HttpMethod::GET, "/api/be_version_info", version_action);
// Register BE health action
HealthAction* health_action = _pool.add(new HealthAction());
_ev_http_server->register_handler(HttpMethod::GET, "/api/health", health_action);

View File

@ -0,0 +1,99 @@
---
{
"title": "Be Version Info Action",
"language": "en"
}
---
<!--
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.
-->
# Be Version Info Action
## Request
`GET be_host:be_http_port/api/be_version_info`
## Description
Get be version info from be host.
## Path parameters
None.
## Query parameters
None.
## Request body
None.
## Response
```
{
"msg":"success",
"code":0,
"data":{
"beVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3"
}
},
"count":0
}
```
## Examples
```
GET be_host:be_http_port/api/be_version_info
Response:
{
"msg":"success",
"code":0,
"data":{
"beVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3"
}
},
"count":0
}
```

View File

@ -0,0 +1,101 @@
---
{
"title": "Fe Version Info Action",
"language": "en"
}
---
<!--
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.
-->
# Fe Version Info Action
## Request
`GET /api/fe_version_info`
## Description
Get fe version info from fe host.
## Path parameters
None.
## Query parameters
None.
## Request body
None.
## Response
```
{
"msg":"success",
"code":0,
"data":{
"feVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3",
"dorisJavaCompileVersion":"openjdk full version \"1.8.0_332-b09\""
}
},
"count":0
}
```
## Examples
```
GET /api/fe_version_info
Response:
{
"msg":"success",
"code":0,
"data":{
"feVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3",
"dorisJavaCompileVersion":"openjdk full version \"1.8.0_332-b09\""
}
},
"count":0
}
```

View File

@ -0,0 +1,99 @@
---
{
"title": "Be Version Info Action",
"language": "zh-CN"
}
---
<!--
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.
-->
# Be Version Info Action
## Request
`GET be_host:be_http_port/api/be_version_info`
## Description
用于获取be节点的版本信息。
## Path parameters
## Query parameters
## Request body
## Response
```
{
"msg":"success",
"code":0,
"data":{
"beVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3"
}
},
"count":0
}
```
## Examples
```
GET be_host:be_http_port/api/be_version_info
Response:
{
"msg":"success",
"code":0,
"data":{
"beVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3"
}
},
"count":0
}
```

View File

@ -0,0 +1,101 @@
---
{
"title": "Fe Version Info Action",
"language": "zh-CN"
}
---
<!--
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.
-->
# Fe Version Info Action
## Request
`GET /api/fe_version_info`
## Description
用于获取fe节点的版本信息。
## Path parameters
## Query parameters
## Request body
## Response
```
{
"msg":"success",
"code":0,
"data":{
"feVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3",
"dorisJavaCompileVersion":"openjdk full version \"1.8.0_332-b09\""
}
},
"count":0
}
```
## Examples
```
GET /api/fe_version_info
Response:
{
"msg":"success",
"code":0,
"data":{
"feVersionInfo":{
"dorisBuildVersionPrefix":"doris",
"dorisBuildVersionMajor":0,
"dorisBuildVersionMinor":0,
"dorisBuildVersionPatch":0,
"dorisBuildVersionRcVersion":"trunk",
"dorisBuildVersion":"doris-0.0.0-trunk",
"dorisBuildHash":"git://4b7b503d1cb3/data/doris/doris/be/../@a04f9814fe5a09c0d9e9399fe71cc4d765f8bff1",
"dorisBuildShortHash":"a04f981",
"dorisBuildTime":"Fri, 09 Sep 2022 07:57:02 UTC",
"dorisBuildInfo":"root@4b7b503d1cb3",
"dorisJavaCompileVersion":"openjdk full version \"1.8.0_332-b09\""
}
},
"count":0
}
```

View File

@ -0,0 +1,66 @@
// 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 org.apache.doris.httpv2.rest;
import org.apache.doris.common.Version;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// This class is a RESTFUL interface to get fe version info.
// It will be used in get fe version info.
// Usage:
// wget http://fe_host:fe_http_port/api/fe_version_info
@RestController
public class FeVersionInfoAction extends RestBaseController {
private static final Logger LOG = LogManager.getLogger(ProfileAction.class);
@RequestMapping(path = "/api/fe_version_info", method = RequestMethod.GET)
protected Object profile(HttpServletRequest request, HttpServletResponse response) {
executeCheckPassword(request, response);
checkGlobalAuth(ConnectContext.get().getCurrentUserIdentity(), PrivPredicate.ADMIN);
Map<String, Object> feVersionInfo = Maps.newHashMap();
feVersionInfo.put("dorisBuildVersionPrefix", Version.DORIS_BUILD_VERSION_PREFIX);
feVersionInfo.put("dorisBuildVersionMajor", Version.DORIS_BUILD_VERSION_MAJOR);
feVersionInfo.put("dorisBuildVersionMinor", Version.DORIS_BUILD_VERSION_MINOR);
feVersionInfo.put("dorisBuildVersionPatch", Version.DORIS_BUILD_VERSION_PATCH);
feVersionInfo.put("dorisBuildVersionRcVersion", Version.DORIS_BUILD_VERSION_RC_VERSION);
feVersionInfo.put("dorisBuildVersion", Version.DORIS_BUILD_VERSION);
feVersionInfo.put("dorisBuildHash", Version.DORIS_BUILD_HASH);
feVersionInfo.put("dorisBuildShortHash", Version.DORIS_BUILD_SHORT_HASH);
feVersionInfo.put("dorisBuildTime", Version.DORIS_BUILD_TIME);
feVersionInfo.put("dorisBuildInfo", Version.DORIS_BUILD_INFO);
feVersionInfo.put("dorisJavaCompileVersion", Version.DORIS_JAVA_COMPILE_VERSION);
Map<String, Object> result = Maps.newHashMap();
result.put("feVersionInfo", feVersionInfo);
return ResponseEntityBuilder.ok(result);
}
}

View File

@ -27,7 +27,13 @@
set -eo pipefail
build_version="trunk"
build_version_prefix="doris"
build_version_major=0
build_version_minor=0
build_version_patch=0
build_version_rc_version="trunk"
build_version="${build_version_prefix}-${build_version_major}.${build_version_minor}.${build_version_patch}-${build_version_rc_version}"
unset LANG
unset LC_CTYPE
@ -121,6 +127,12 @@ package org.apache.doris.common;
public class Version {
public static final String DORIS_BUILD_VERSION_PREFIX = "${build_version_prefix}";
public static final int DORIS_BUILD_VERSION_MAJOR = ${build_version_major};
public static final int DORIS_BUILD_VERSION_MINOR = ${build_version_minor};
public static final int DORIS_BUILD_VERSION_PATCH = ${build_version_patch};
public static final String DORIS_BUILD_VERSION_RC_VERSION = "${build_version_rc_version}";
public static final String DORIS_BUILD_VERSION = "${build_version}";
public static final String DORIS_BUILD_HASH = "${build_hash}";
public static final String DORIS_BUILD_SHORT_HASH = "${build_short_hash}";
@ -129,6 +141,12 @@ public class Version {
public static final String DORIS_JAVA_COMPILE_VERSION = "${java_version_str}";
public static void main(String[] args) {
System.out.println("doris_build_version_prefix: " + DORIS_BUILD_VERSION_PREFIX);
System.out.println("doris_build_version_major: " + DORIS_BUILD_VERSION_MAJOR);
System.out.println("doris_build_version_minor: " + DORIS_BUILD_VERSION_MINOR);
System.out.println("doris_build_version_patch: " + DORIS_BUILD_VERSION_PATCH);
System.out.println("doris_build_version_rc_version: " + DORIS_BUILD_VERSION_RC_VERSION);
System.out.println("doris_build_version: " + DORIS_BUILD_VERSION);
System.out.println("doris_build_hash: " + DORIS_BUILD_HASH);
System.out.println("doris_build_short_hash: " + DORIS_BUILD_SHORT_HASH);
@ -169,11 +187,17 @@ cat >"${GEN_CPP_DIR}/version.h" <<EOF
namespace doris {
#define DORIS_BUILD_VERSION "${build_version}"
#define DORIS_BUILD_HASH "${build_hash}"
#define DORIS_BUILD_SHORT_HASH "${build_short_hash}"
#define DORIS_BUILD_TIME "${build_time}"
#define DORIS_BUILD_INFO "${build_info}"
#define DORIS_BUILD_VERSION_PREFIX "${build_version_prefix}";
#define DORIS_BUILD_VERSION_MAJOR ${build_version_major};
#define DORIS_BUILD_VERSION_MINOR ${build_version_minor};
#define DORIS_BUILD_VERSION_PATCH ${build_version_patch};
#define DORIS_BUILD_VERSION_RC_VERSION "${build_version_rc_version}";
#define DORIS_BUILD_VERSION "${build_version}"
#define DORIS_BUILD_HASH "${build_hash}"
#define DORIS_BUILD_SHORT_HASH "${build_short_hash}"
#define DORIS_BUILD_TIME "${build_time}"
#define DORIS_BUILD_INFO "${build_info}"
} // namespace doris