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

Handle and log error when a DB instance cannot be found #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
18 changes: 14 additions & 4 deletions src/main/java/com/airbnb/billow/AWSDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.amazonaws.services.identitymanagement.model.User;
import com.amazonaws.services.rds.AmazonRDSClient;
import com.amazonaws.services.rds.model.DBInstance;
import com.amazonaws.services.rds.model.DBInstanceNotFoundException;
import com.amazonaws.services.rds.model.DescribeDBInstancesRequest;
import com.amazonaws.services.rds.model.DescribeDBInstancesResult;
import com.amazonaws.services.rds.model.ListTagsForResourceRequest;
Expand Down Expand Up @@ -103,10 +104,19 @@ public class AWSDatabase {
ListTagsForResourceRequest tagsRequest = new ListTagsForResourceRequest()
.withResourceName(arnGenerator.rdsARN(regionName, instance));

ListTagsForResourceResult tagsResult = client.listTagsForResource(tagsRequest);

rdsBuilder.putAll(regionName, new RDSInstance(instance, tagsResult.getTagList()));

try {
ListTagsForResourceResult tagsResult = client.listTagsForResource(tagsRequest);

rdsBuilder.putAll(regionName, new RDSInstance(instance, tagsResult.getTagList()));
} catch(DBInstanceNotFoundException e) {
// It is possible for an instance to disappear between when we got the list of instances and
// when we go to find the instance's tags.
log.warn("Unable to find RDS instance '" +
Copy link
Contributor

Choose a reason for hiding this comment

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

So the traditional way to log a message with an exception with Slf4j is:

log.warn("message", exception);

That way the logger will, depending on configuration, provide a stacktrace (usually compacted), and/or the exception message, and/or the exception class (usually all of those, and it will do that as it walks up the causality chain so nicely provided by Java exceptions).

Instead of building your string with + (which javac will internally convert to invocations of a StringBuilder constructor if few enough, a constructor then a few appends otherwise), it's best to use the logger's string formatting support. The idea there is that if a log message won't be printed anyway (eg because the log level is disabled), it'll avoid unnecessary work. Stupid example:

log.warn("foo {} baz", "bar", exception);

Essentially, {} in the message format will consume parameters, and the last parameter that's an exception shouldn't be consumed by the message format as the logger will deal with it as it sees fit.

instance.getDBInstanceIdentifier() +
"', last known status was '" +
instance.getDBInstanceStatus() +
"'. Exception: " + e.toString());
}
}
rdsRequest.setMarker(result.getMarker());
} while (result.getMarker() != null);
Expand Down