-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ErrorClassification API for program runs
- Loading branch information
1 parent
3d1422a
commit 2245c19
Showing
5 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
cdap-proto/src/main/java/io/cdap/cdap/proto/ErrorClassificationResponse.java
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,41 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.proto; | ||
|
||
public class ErrorClassificationResponse { | ||
private final String stageName; | ||
private final String errorCategory; | ||
private final String errorReason; | ||
private final String errorMessage; | ||
private final String errorType; | ||
private final String errorCodeType; | ||
private final String errorCode; | ||
private final String supportedDocumentationUrl; | ||
|
||
public ErrorClassificationResponse(String stageName, String errorCategory, String errorReason, | ||
String errorMessage, String errorType, String errorCodeType, String errorCode, | ||
String supportedDocumentationUrl) { | ||
this.stageName = stageName; | ||
this.errorCategory = errorCategory; | ||
this.errorReason = errorReason; | ||
this.errorMessage = errorMessage; | ||
this.errorType = errorType; | ||
this.errorCodeType = errorCodeType; | ||
this.errorCode = errorCode; | ||
this.supportedDocumentationUrl = supportedDocumentationUrl; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
cdap-watchdog/src/main/java/io/cdap/cdap/logging/ErrorLogsClassifier.java
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,72 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.logging; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.spi.IThrowableProxy; | ||
import com.google.gson.Gson; | ||
import io.cdap.cdap.api.dataset.lib.CloseableIterator; | ||
import io.cdap.cdap.api.exception.ProgramFailureException; | ||
import io.cdap.cdap.common.conf.Constants.Logging; | ||
import io.cdap.cdap.logging.read.LogEvent; | ||
import io.cdap.cdap.proto.ErrorClassificationResponse; | ||
import io.cdap.http.HttpResponder; | ||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.commons.lang3.StringEscapeUtils; | ||
import org.elasticsearch.common.Strings; | ||
|
||
/** | ||
* Classifies error logs and returns {@link ErrorClassificationResponse}. | ||
*/ | ||
public class ErrorLogsClassifier { | ||
private static final Gson GSON = new Gson(); | ||
|
||
public void classify(CloseableIterator<LogEvent> logIter, HttpResponder responder) { | ||
Map<String, ErrorClassificationResponse> responseMap = new HashMap<>(); | ||
while(logIter.hasNext()) { | ||
ILoggingEvent logEvent = logIter.next().getLoggingEvent(); | ||
Map<String, String> mdc = logEvent.getMDCPropertyMap(); | ||
if (!mdc.containsKey(Logging.TAG_FAILED_STAGE)) { | ||
continue; | ||
} | ||
String stageName = mdc.get(Logging.TAG_FAILED_STAGE); | ||
String errorMessage = null; | ||
if (responseMap.containsKey(stageName)) { | ||
continue; | ||
} | ||
IThrowableProxy throwableProxy = logEvent.getThrowableProxy(); | ||
while (throwableProxy != null) { | ||
if (ProgramFailureException.class.getName().equals(throwableProxy.getClassName())) { | ||
errorMessage = throwableProxy.getMessage(); | ||
} | ||
throwableProxy = throwableProxy.getCause(); | ||
} | ||
if (!Strings.isNullOrEmpty(errorMessage)) { | ||
ErrorClassificationResponse classificationResponse = | ||
new ErrorClassificationResponse(stageName, | ||
String.format("%s-'%s'",mdc.get(Logging.TAG_ERROR_CATEGORY), stageName), | ||
mdc.get(Logging.TAG_ERROR_REASON), errorMessage, mdc.get(Logging.TAG_ERROR_TYPE), | ||
mdc.get(Logging.TAG_ERROR_CODE_TYPE), mdc.get(Logging.TAG_ERROR_CODE), | ||
mdc.get(Logging.TAG_SUPPORTED_DOC_URL)); | ||
responseMap.put(stageName, classificationResponse); | ||
} | ||
} | ||
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(responseMap.values())); | ||
} | ||
} |
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