Skip to content
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

[CELEBORN-1122] Metrics supports json format #2089

Closed
wants to merge 1 commit into from

Conversation

RuiQin7
Copy link
Contributor

@RuiQin7 RuiQin7 commented Nov 11, 2023

What changes were proposed in this pull request?

If the user does not use prometheus to collect monitoring metrics, but rather some other ones. Using metrics in JSON format would be more user-friendly.The PR supports JSON format for metrics.

Why are the changes needed?

Ditto.

Does this PR introduce any user-facing change?

Metrics supports JSON format

How was this patch tested?

Cluster test.

Copy link

codecov bot commented Nov 11, 2023

Codecov Report

Attention: 308 lines in your changes are missing coverage. Please review.

Comparison is base (1c7cd1b) 47.13% compared to head (af01170) 46.22%.
Report is 1 commits behind head on main.

Files Patch % Lines
...che/celeborn/common/metrics/sink/JsonServlet.scala 0.00% 252 Missing ⚠️
...apache/celeborn/common/metrics/MetricsSystem.scala 0.00% 25 Missing ⚠️
...leborn/server/common/http/HttpRequestHandler.scala 0.00% 17 Missing ⚠️
...celeborn/common/metrics/sink/AbstractServlet.scala 0.00% 9 Missing ⚠️
...leborn/common/metrics/sink/PrometheusServlet.scala 0.00% 3 Missing ⚠️
...cala/org/apache/celeborn/common/CelebornConf.scala 92.86% 1 Missing ⚠️
...rg/apache/celeborn/server/common/HttpService.scala 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2089      +/-   ##
==========================================
- Coverage   47.13%   46.22%   -0.91%     
==========================================
  Files         173      175       +2     
  Lines       11034    11336     +302     
  Branches     1011     1016       +5     
==========================================
+ Hits         5200     5239      +39     
- Misses       5494     5757     +263     
  Partials      340      340              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

sources.asScala,
jsonServletPath).asInstanceOf[JsonServlet])
}
if (kv._1 == "prometheusServlet") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else if

@RexXiong Thank you for your suggestion.


private def updateInnerMetrics(absSource: AbstractSource, metricData: MetricData): Unit = {
innerMetrics.synchronized {
if (innerMetrics.size() >= absSource.metricsCapacity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if condition meet, can we directly return? as remove and add new metricData seems useless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if condition meet, can we directly return? as remove and add new metricData seems useless

@RexXiong Thank you for your suggestion. I have resubmitted, please help me review it again.


import com.codahale.metrics.MetricRegistry
import io.netty.channel.ChannelHandler.Sharable
import org.apache.hadoop.shaded.com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no other comments on this pr except this import as it from shaded dependency, WDYT @waitinfuture @pan3793 @FMX @cfmcgrady

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no other comments on this pr except this import as it from shaded dependency, WDYT @waitinfuture @pan3793 @FMX @cfmcgrady

@RexXiong Thank you for your suggestion. I reimport the jackson package,and the version from hadoop 3.2.4.

pom.xml Outdated
@@ -96,6 +96,8 @@
<zstd-jni.version>1.5.2-1</zstd-jni.version>
<kubernetes-client.version>6.7.0</kubernetes-client.version>
<rocksdbjni.version>8.5.3</rocksdbjni.version>
<jackson.version>2.10.5</jackson.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why choose such a low version

Copy link
Contributor Author

@RuiQin7 RuiQin7 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why choose such a low version

@pan3793
The version of org.apache.hadoop.shaded.*.jackson comes from Hadoop 3.2.4 now. In order to reduce its impact on the original framework. I directly import the jackson 2.10.5 from Hadoop 3.2.4.

@pan3793
Copy link
Member

pan3793 commented Nov 28, 2023

please update the LICENSE and NOTICE since it introduces the new dependencies, also, fix sbt building system

@RuiQin7
Copy link
Contributor Author

RuiQin7 commented Nov 30, 2023

please update the LICENSE and NOTICE since it introduces the new dependencies, also, fix sbt building system

@pan3793 Thank you. I have updated newer version , and fixed sbt building system. Please help me review it again.

@@ -56,6 +56,8 @@ object Dependencies {
val ratisVersion = "2.5.1"
val roaringBitmapVersion = "0.9.32"
val rocksdbJniVersion = "8.5.3"
val jacksonVersion = "2.15.3"
val paranamerVersion = "2.8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we don't need to manage paranamerVersion explicitly, let's simply delegate it to jackson

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we don't need to manage paranamerVersion explicitly, let's simply delegate it to jackson

Thank you. I remove it.

import org.apache.celeborn.common.metrics.source.{AbstractSource, NamedCounter, NamedGauge, NamedHistogram, NamedTimer, Source}

object JsonConverter {
val mapper = new ObjectMapper() with ClassTagExtensions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess user may preview the json using browser, maybe we can print the pretty json string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess user may preview the json using browser, maybe we can print the pretty json string.

@pan3793
Thank you. For users, they may preview the json using browser, but for metrics collection, we prefer to use a compact format. I can add the celeborn.metrics.json.pretty.enabled to control whether to enable pretty and default value true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configurable SGTM, though I think the overhead is quite nit

val servletHttpRequestHandler = servletHttpRequestHandlers.find(servlet =>
uri == servlet.getServletPath())
if (servletHttpRequestHandler.nonEmpty) {
servletHttpRequestHandler.get.handleRequest(uri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update it for JSON?

res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update it for JSON?

res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8")

Thank you. You are right. I update it.

@RuiQin7 RuiQin7 force-pushed the CELEBORN-1122 branch 3 times, most recently from b6b3685 to 381b8ba Compare December 1, 2023 12:30
mapper.writeValueAsString(value)
}

def toJsonWithPretty(value: ArrayBuffer[Any]): String = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def toJsonWithPretty(value: ArrayBuffer[Any]): String = {
def toPrettyJson(value: Any): String = {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I update it.

val mapper = new ObjectMapper() with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)

def toJson(value: ArrayBuffer[Any]): String = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def toJson(value: ArrayBuffer[Any]): String = {
def toJson(value: Any): String = {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I update it.

com.fasterxml.jackson.module:jackson-module-scala
com.fasterxml.jackson.core:jackson-databind
com.fasterxml.jackson.core:jackson-annotations
com.fasterxml.jackson.core:jackson-core
Copy link
Member

@pan3793 pan3793 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LICENSE-binary reflects the final content of the binary release tarball, so the paranamer should be retained here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LICENSE-binary reflects the final content of the binary release tarball, so the parameter should be retained here.

what is the parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, the paranamer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, the paranamer

I have added it. Please review it again.

hadoop-client-api/3.3.6//hadoop-client-api-3.3.6.jar
hadoop-client-runtime/3.3.6//hadoop-client-runtime-3.3.6.jar
guava/14.0.1//guava-14.0.1.jar
hadoop-client-api/3.2.4//hadoop-client-api-3.2.4.jar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase master and regenerate this files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I update it.

@RuiQin7 RuiQin7 force-pushed the CELEBORN-1122 branch 2 times, most recently from 47956ed to 1d9caba Compare December 2, 2023 09:38
Copy link
Contributor

@RexXiong RexXiong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, cc @pan3793 @cfmcgrady

@@ -47,21 +47,34 @@ class HttpRequestHandler(
val uri = req.uri()
val (path, parameters) = HttpUtils.parseUri(uri)
val msg = HttpUtils.handleRequest(service, path, parameters)
val response = msg match {
val textType = "text/plain; charset=UTF-8"
val jsonType = "application/json; charset=UTF-8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val jsonType = "application/json; charset=UTF-8"
val jsonType = "application/json"

https://www.rfc-editor.org/rfc/rfc8259.html

Note: No "charset" parameter is defined for this registration.
Adding one really has no effect on compliant recipients.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I update it.

Copy link
Member

@pan3793 pan3793 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except for one minor thing

Copy link
Contributor

@cfmcgrady cfmcgrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except a nit

Comment on lines 55 to 64
val servletHttpRequestHandler = servletHttpRequestHandlers.find(servlet =>
uri == servlet.getServletPath())
servletHttpRequestHandler match {
case Some(handler) => handler match {
case jsonHandler: JsonHttpRequestHandler =>
(jsonHandler.handleRequest(uri), jsonType)
case _ => (handler.handleRequest(uri), textType)
}
case _ => (s"Unknown path $uri!", textType)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
val servletHttpRequestHandler = servletHttpRequestHandlers.find(servlet =>
uri == servlet.getServletPath())
servletHttpRequestHandler match {
case Some(handler) => handler match {
case jsonHandler: JsonHttpRequestHandler =>
(jsonHandler.handleRequest(uri), jsonType)
case _ => (handler.handleRequest(uri), textType)
}
case _ => (s"Unknown path $uri!", textType)
}
servletHttpRequestHandlers.find(servlet => uri == servlet.getServletPath())
.map {
case jsonHandler: JsonHttpRequestHandler =>
(jsonHandler.handleRequest(uri), jsonType)
case handler: ServletHttpRequestHandler =>
(handler.handleRequest(uri), textType)
}.getOrElse((s"Unknown path $uri!", textType))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I update it.

@RexXiong
Copy link
Contributor

RexXiong commented Dec 6, 2023

Thank you all @suizhe007 @pan3793 @cfmcgrady, merge to main(v0.4.0)

@RexXiong RexXiong closed this in 04a1e90 Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants