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

YARN-11726: Add logging statements for successful and unsuccessful password retrieval operation #7148

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.apache.hadoop.yarn.webapp.NotFoundException;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

Expand All @@ -61,6 +63,7 @@ public class WebAppUtils {
"ssl.server.keystore.keypassword";
public static final String HTTPS_PREFIX = "https://";
public static final String HTTP_PREFIX = "http://";
public static final Logger LOG = LoggerFactory.getLogger(WebAppUtils.class);

public static void setRMWebAppPort(Configuration conf, int port) {
String hostname = getRMWebAppURLWithoutScheme(conf);
Expand Down Expand Up @@ -509,11 +512,18 @@ static String getPassword(Configuration conf, String alias) {
char[] passchars = conf.getPassword(alias);
if (passchars != null) {
password = new String(passchars);
LOG.info("Successful password retrieval for alias: {}", alias);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think debug level will be enough here, to avoid too much log record.

Copy link
Author

Choose a reason for hiding this comment

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

I am not so sure, because when I try with DEBUG level and run the unit test the log message is not shown. I think it is override by other log level that is why I used INFO level to see it every time.

Is there a way to see a DEBUG level logs in some cases when the user wants?

}
}
catch (IOException ioe) {
password = null;
LOG.error("Unable to retrieve password for alias: {}", alias, ioe);
Copy link
Contributor

Choose a reason for hiding this comment

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

If i see well here the void error(String var1, Object var2, Object var3); called, so the 3th throwable wont be logged in this case. Also in this case two error log will be created, so maybe debug level will be also fine here.

Copy link
Author

Choose a reason for hiding this comment

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

Hello @K0K0V0K,
Thank you for your feedbacks. By default SLF4J logging will handle the Throwable as the last parameter for exception logging. Therefore, I do not need another place {} holder for it.

Copy link
Author

Choose a reason for hiding this comment

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

I tried with a DEBUG level log and log message does not appear when I run the unit test that simulate the Exception. I think it better with an ERROR level because now I changed when the password is null it log with WARN level. So when the exception happens, it will log with two log messages in two levels ERROR and WARN.

Copy link
Contributor

Choose a reason for hiding this comment

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

yup, seems you are right

}

if (password == null) {
LOG.error("Password does not exist for alias: {}", alias);
Hean-Chhinling marked this conversation as resolved.
Show resolved Hide resolved
}

return password;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.apache.hadoop.yarn.util.TestBoundedAppender;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -43,6 +44,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;

public class TestWebAppUtils {
private static final String RM1_NODE_ID = "rm1";
Expand Down Expand Up @@ -109,6 +111,15 @@ void testGetPassword() throws Exception {
assertNull(WebAppUtils.getPassword(conf, "invalid-alias"));
}

@Test
void testGetPasswordIOException() throws Exception {
Configuration mockConf = Mockito.mock(Configuration.class);

when(mockConf.getPassword("error-alias")).thenThrow(new IOException("Simulated IO error"));

assertNull(WebAppUtils.getPassword(mockConf, "error-alias"));
}

@Test
void testLoadSslConfiguration() throws Exception {
Configuration conf = provisionCredentialsForSSL();
Expand Down Expand Up @@ -186,7 +197,7 @@ protected Configuration provisionCredentialsForSSL() throws IOException,
void testAppendQueryParams() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
String targetUri = "/test/path";
Mockito.when(request.getCharacterEncoding()).thenReturn(null);
when(request.getCharacterEncoding()).thenReturn(null);
Map<String, String> paramResultMap = new HashMap<>();
paramResultMap.put("param1=x", targetUri + "?" + "param1=x");
paramResultMap
Expand All @@ -195,7 +206,7 @@ void testAppendQueryParams() throws Exception {
targetUri + "?" + "param1=x&param2=y&param3=x+y");

for (Map.Entry<String, String> entry : paramResultMap.entrySet()) {
Mockito.when(request.getQueryString()).thenReturn(entry.getKey());
when(request.getQueryString()).thenReturn(entry.getKey());
String uri = WebAppUtils.appendQueryParams(request, targetUri);
assertEquals(entry.getValue(), uri);
}
Expand All @@ -205,8 +216,8 @@ void testAppendQueryParams() throws Exception {
void testGetHtmlEscapedURIWithQueryString() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
String targetUri = "/test/path";
Mockito.when(request.getCharacterEncoding()).thenReturn(null);
Mockito.when(request.getRequestURI()).thenReturn(targetUri);
when(request.getCharacterEncoding()).thenReturn(null);
when(request.getRequestURI()).thenReturn(targetUri);
Map<String, String> paramResultMap = new HashMap<>();
paramResultMap.put("param1=x", targetUri + "?" + "param1=x");
paramResultMap
Expand All @@ -215,7 +226,7 @@ void testGetHtmlEscapedURIWithQueryString() throws Exception {
targetUri + "?" + "param1=x&amp;param2=y&amp;param3=x+y");

for (Map.Entry<String, String> entry : paramResultMap.entrySet()) {
Mockito.when(request.getQueryString()).thenReturn(entry.getKey());
when(request.getQueryString()).thenReturn(entry.getKey());
String uri = WebAppUtils.getHtmlEscapedURIWithQueryString(request);
assertEquals(entry.getValue(), uri);
}
Expand Down
Loading