Skip to content

Commit

Permalink
support to return all loggers as well
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Dec 23, 2024
1 parent ccee9e2 commit bb612d4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,25 @@ public LoggerApi(ApiClient apiClient) {
*
* Get the logger level, return all loggers if no name specified.
* @param name The logger name. (optional)
* @param all Return all logger instances if true, otherwise return all configured loggers. (optional, default to false)
* @return LoggerInfos
* @throws ApiException if fails to make API call
*/
public LoggerInfos getLogger(String name) throws ApiException {
return this.getLogger(name, Collections.emptyMap());
public LoggerInfos getLogger(String name, Boolean all) throws ApiException {
return this.getLogger(name, all, Collections.emptyMap());
}


/**
*
* Get the logger level, return all loggers if no name specified.
* @param name The logger name. (optional)
* @param all Return all logger instances if true, otherwise return all configured loggers. (optional, default to false)
* @param additionalHeaders additionalHeaders for this call
* @return LoggerInfos
* @throws ApiException if fails to make API call
*/
public LoggerInfos getLogger(String name, Map<String, String> additionalHeaders) throws ApiException {
public LoggerInfos getLogger(String name, Boolean all, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;

// create path and map variables
Expand All @@ -83,6 +85,7 @@ public LoggerInfos getLogger(String name, Map<String, String> additionalHeaders)
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

localVarQueryParams.addAll(apiClient.parameterToPair("name", name));
localVarQueryParams.addAll(apiClient.parameterToPair("all", all));

localVarHeaderParams.putAll(additionalHeaders);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,25 @@ public LoggerApi(ApiClient apiClient) {
*
* Get the logger level, return all loggers if no name specified.
* @param name The logger name. (optional)
* @param all Return all logger instances if true, otherwise return all configured loggers. (optional, default to false)
* @return LoggerInfos
* @throws ApiException if fails to make API call
*/
public LoggerInfos getLogger(String name) throws ApiException {
return this.getLogger(name, Collections.emptyMap());
public LoggerInfos getLogger(String name, Boolean all) throws ApiException {
return this.getLogger(name, all, Collections.emptyMap());
}


/**
*
* Get the logger level, return all loggers if no name specified.
* @param name The logger name. (optional)
* @param all Return all logger instances if true, otherwise return all configured loggers. (optional, default to false)
* @param additionalHeaders additionalHeaders for this call
* @return LoggerInfos
* @throws ApiException if fails to make API call
*/
public LoggerInfos getLogger(String name, Map<String, String> additionalHeaders) throws ApiException {
public LoggerInfos getLogger(String name, Boolean all, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;

// create path and map variables
Expand All @@ -83,6 +85,7 @@ public LoggerInfos getLogger(String name, Map<String, String> additionalHeaders)
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

localVarQueryParams.addAll(apiClient.parameterToPair("name", name));
localVarQueryParams.addAll(apiClient.parameterToPair("all", all));

localVarHeaderParams.putAll(additionalHeaders);

Expand Down
7 changes: 7 additions & 0 deletions openapi/openapi-client/src/main/openapi3/master_rest_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ paths:
required: false
schema:
type: string
- name: all
in: query
description: Return all logger instances if true, otherwise return all configured loggers.
required: false
schema:
type: boolean
default: false
responses:
"200":
description: The request was successful.
Expand Down
7 changes: 7 additions & 0 deletions openapi/openapi-client/src/main/openapi3/worker_rest_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ paths:
required: false
schema:
type: string
- name: all
in: query
description: Return all logger instances if true, otherwise return all configured loggers.
required: false
schema:
type: boolean
default: false
responses:
"200":
description: The request was successful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package org.apache.celeborn.server.common.http.api.v1

import javax.ws.rs.{Consumes, GET, POST, Produces, QueryParam}
import javax.ws.rs.{Consumes, DefaultValue, GET, POST, Produces, QueryParam}
import javax.ws.rs.core.MediaType

import scala.collection.JavaConverters._

import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.media.{Content, Schema}
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -44,16 +45,27 @@ class LoggerResource extends ApiRequestContext {
schema = new Schema(implementation = classOf[LoggerInfo]))),
description = "Get the logger level, return all loggers if no name specified.")
@GET
def getLoggerLevel(@QueryParam("name") name: String): LoggerInfos = {
def getLoggerLevel(
@QueryParam("name") name: String,
@QueryParam("all") @DefaultValue("false") @Parameter(description =
"Return all logger instances if true, otherwise return all configured loggers.") all: Boolean)
: LoggerInfos = {
if (null != name) {
new LoggerInfos().addLoggersItem(
new LoggerInfo().name(name).level(LogManager.getLogger(name).getLevel.toString))
} else {
val loggerContext = LogManager.getContext(false).asInstanceOf[LoggerContext]
val loggers = loggerContext.getConfiguration.getLoggers.values().asScala.map { loggerConfig =>
new LoggerInfo().name(loggerConfig.getName).level(loggerConfig.getLevel.toString)
}.toSeq.sortBy(_.getName).asJava
new LoggerInfos().loggers(loggers)
val loggers =
if (all) {
loggerContext.getLoggers.asScala.map { logger =>
new LoggerInfo().name(logger.getName).level(logger.getLevel.toString)
}.toSeq
} else {
loggerContext.getConfiguration.getLoggers.values().asScala.map { loggerConfig =>
new LoggerInfo().name(loggerConfig.getName).level(loggerConfig.getLevel.toString)
}.toSeq
}
new LoggerInfos().loggers(loggers.sortBy(_.getName).asJava)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,45 @@ abstract class ApiV1BaseResourceSuite extends HttpTestHelper {
assert(log.isInfoEnabled)
assert(log.isDebugEnabled)

// check all loggers
val response4 = webTarget.path("loggers").request(MediaType.APPLICATION_JSON).get()
// check all configured loggers
val response4 =
webTarget.path("loggers").queryParam("all", "false").request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response4.getStatus)
val loggers = response4.readEntity(classOf[LoggerInfos]).getLoggers.asScala
assert(loggers.exists(l => l.getName == loggerName && l.getLevel == "DEBUG"))
val configuredLoggers = response4.readEntity(classOf[LoggerInfos]).getLoggers.asScala
assert(configuredLoggers.exists(l => l.getName == loggerName && l.getLevel == "DEBUG"))
// root logger
assert(loggers.exists(l => l.getName == "" && l.getLevel == "INFO"))
assert(configuredLoggers.exists(l => l.getName == "" && l.getLevel == "INFO"))

// update root logger level
// check all loggers
val response5 =
webTarget.path("loggers").queryParam("all", "true").request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response5.getStatus)
val allLoggers = response5.readEntity(classOf[LoggerInfos]).getLoggers.asScala
assert(configuredLoggers.exists(l => l.getName == loggerName && l.getLevel == "DEBUG"))
assert(allLoggers.size > configuredLoggers.size)

// update root logger level
val response6 =
webTarget.path("loggers").request(MediaType.APPLICATION_JSON).post(Entity.entity(
new LoggerInfo().name("").level("DEBUG"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response5.getStatus)
assert(HttpServletResponse.SC_OK == response6.getStatus)

// check root logger level is DEBUG
val response6 = webTarget.path("loggers")
val response7 = webTarget.path("loggers")
.queryParam("name", "")
.request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response6.getStatus)
val loggerInfo3 = response6.readEntity(classOf[LoggerInfos]).getLoggers.get(0)
assert(HttpServletResponse.SC_OK == response7.getStatus)
val loggerInfo3 = response7.readEntity(classOf[LoggerInfos]).getLoggers.get(0)
assert("" == loggerInfo3.getName)
assert(loggerInfo3.getLevel == "DEBUG")

// reset root logger level to INFO
val response7 =
val response8 =
webTarget.path("loggers").request(MediaType.APPLICATION_JSON).post(Entity.entity(
new LoggerInfo().name("").level("INFO"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response7.getStatus)
assert(HttpServletResponse.SC_OK == response8.getStatus)
}

test("thread_dump") {
Expand Down

0 comments on commit bb612d4

Please sign in to comment.