Change EppMetric.Builder to use @AutoValue.Builder

Getting rid of builder boilerplate makes my heart sing.  Since we can no
longer @Inject the Builder() constructor, this change adds a provider
in WhiteboxModule that calls a special builderForRequest() factory method,
which gets passed a request ID and Clock and preserves the existing
EppMetric magic that sets the start and end time for you.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132714432
This commit is contained in:
nickfelt 2016-09-09 14:09:11 -07:00 committed by Ben McIlwain
parent ceb5c2117e
commit 2537e95de5
10 changed files with 108 additions and 107 deletions

View file

@ -17,6 +17,7 @@ package google.registry.monitoring.whitebox;
import static google.registry.request.RequestParameters.extractRequiredParameter;
import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.apphosting.api.ApiProxy;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import dagger.Module;
@ -24,7 +25,9 @@ import dagger.Provides;
import dagger.multibindings.IntoMap;
import dagger.multibindings.StringKey;
import google.registry.request.Parameter;
import google.registry.util.Clock;
import java.util.UUID;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
/**
@ -33,6 +36,8 @@ import javax.servlet.http.HttpServletRequest;
@Module
public class WhiteboxModule {
private static final String REQUEST_LOG_ID = "com.google.appengine.runtime.request_log_id";
@Provides
@IntoMap
@StringKey(EppMetric.TABLE_ID)
@ -68,4 +73,17 @@ public class WhiteboxModule {
}
};
}
@Provides
@Named("requestLogId")
static String provideRequestLogId() {
return ApiProxy.getCurrentEnvironment().getAttributes().get(REQUEST_LOG_ID).toString();
}
/** Provides an EppMetric builder with the request ID and startTimestamp already initialized. */
@Provides
static EppMetric.Builder provideEppMetricBuilder(
@Named("requestLogId") String requestLogId, Clock clock) {
return EppMetric.builderForRequest(requestLogId, clock);
}
}