Skip to content

Commit 68ace10

Browse files
committed
tidy up log levels and make a number of inlined strings constants
1 parent 52532ae commit 68ace10

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/TimeSeriesDBOutputOTLP.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on
7070
@Log
7171
public class TimeSeriesDBOutputOTLP implements NormalizedDataMessageHandler {
7272

73-
private static final long NANOS_PER_SECOND = 1_000_000_000L;
73+
private static final String OTLP_SERVICE_NAME = "IoTDBJDBC";
74+
private static final String OTLP_SCOPE_NAME = "com.oracle.demo.timg.iot.iotdbjdbc";
75+
private static final String OTLP_SCOPE_VERSION = "1.0.0";
76+
private static final String OTLP_METRIC_DESCRIPTION = "IoT normalized data value";
77+
private static final String OTLP_METRIC_UNIT = "1";
78+
private static final String OTLP_METRIC_NAME = "iot.normalized";
79+
private static final String TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_MODEL_NAME_NAME = "iot.digital_twin.model_name";
80+
private static final String TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_INSTANCE_DISPLAY_NAME_NAME = "iot.digital_twin.instance_display_name";
81+
private static final String TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_MODEL_ID_NAME = "iot.digital_twin.model_id";
7482
private final int order;
7583
private final boolean sentDataIsCompleted;
7684
private final DeviceModelInstancesCache deviceModelInstancesCache;
@@ -126,9 +134,9 @@ public String getConfig() {
126134

127135
@Override
128136
public NormalizedData[] processNormalizedData(NormalizedData normalizedData) throws Exception {
129-
NormalizedDataMetricsDataBuilder builder = new NormalizedDataMetricsDataBuilder().serviceName("IoTDBJDBC")
130-
.scope("com.oracle.demo.timg.iot.iotdbjdbc", "1.0.0")
131-
.metric("iot.normalized", "1", "IoT normalized data value").gaugeMetric(normalizedData);
137+
NormalizedDataMetricsDataBuilder builder = new NormalizedDataMetricsDataBuilder().serviceName(OTLP_SERVICE_NAME)
138+
.scope(OTLP_SCOPE_NAME, OTLP_SCOPE_VERSION)
139+
.metric(OTLP_METRIC_NAME, OTLP_METRIC_UNIT, OTLP_METRIC_DESCRIPTION).gaugeMetric(normalizedData);
132140

133141
// we want to have a few "standard" attributes (modelId and name) added beyond
134142
// it's default setup
@@ -139,13 +147,13 @@ public NormalizedData[] processNormalizedData(NormalizedData normalizedData) thr
139147

140148
String metricsDataString = mapper.writeValueAsString(metricsData);
141149
log.info(() -> "About to upload to time series db " + metricsDataString);
142-
log.info(() -> "Uploading url=" + metricsClientUrl + ", path=" + metricsPath + ", queryX=" + queryX
150+
log.fine(() -> "Uploading url=" + metricsClientUrl + ", path=" + metricsPath + ", queryX=" + queryX
143151
+ ", queryY=" + queryY);
144152
if (noUpload) {
145153
log.info("noUpload is true, skipping upload");
146154
} else {
147155
HttpResponse<String> resp = metricsClient.uploadMetrics(queryX, queryY, metricsDataString);
148-
log.info("Upload to time series DB response is " + resp.getStatus().getCode() + "("
156+
log.fine("Upload to time series DB response is " + resp.getStatus().getCode() + "("
149157
+ resp.getStatus().toString() + ") with body " + resp.getBody().orElse("No response data"));
150158
}
151159
return sentDataIsCompleted ? new NormalizedData[0] : new NormalizedData[] { normalizedData };
@@ -160,20 +168,21 @@ private void addResourceAttributes(NormalizedDataMetricsDataBuilder builder, Nor
160168
// if we have them add the model id and model name
161169
try {
162170
String modelId = deviceModelInstancesCache.getModelIdByInstanceId(instanceId, true);
163-
builder.resourceAttribute("iot.digital_twin.model_id", modelId);
164-
log.info("Added model ID resource attribute of " + modelId);
171+
builder.resourceAttribute(TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_MODEL_ID_NAME, modelId);
172+
log.finer("Added model ID resource attribute of " + modelId);
165173
String instanceDisplayName = deviceModelInstancesCache.getInstanceDisplayNameByInstanceId(instanceId, true);
166174
if (instanceDisplayName != null) {
167-
builder.resourceAttribute("iot.digital_twin.display_name", instanceDisplayName);
168-
log.info("Added instance display name of " + instanceDisplayName);
175+
builder.resourceAttribute(TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_INSTANCE_DISPLAY_NAME_NAME,
176+
instanceDisplayName);
177+
log.finer(() -> "Added instance display name of " + instanceDisplayName);
169178
} else {
170-
log.info("Can't locate instance display name for instance " + instanceId);
179+
log.info(() -> "Can't locate instance display name for instance " + instanceId);
171180
}
172181
String modelName;
173182
try {
174183
modelName = deviceModelInstancesCache.getModelNameByModelId(modelId, true);
175-
builder.resourceAttribute("iot.digital_twin.model_name", modelName);
176-
log.info("Added model name resource attribute of " + modelName);
184+
builder.resourceAttribute(TS_RESOURCE_ATTR_IOT_DIGITAL_TWIN_MODEL_NAME_NAME, modelName);
185+
log.finer(() -> "Added model name resource attribute of " + modelName);
177186
} catch (MissingModelException e) {
178187
log.severe("No model name found for modelid " + modelId);
179188
} catch (SQLException e) {

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/oauth/TimeSeriesDBOAuthTokenRetriever.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public synchronized String getToken() throws OAuthTokenRetrievalException {
114114
if ((currentToken == null) || (currentTokenRenewTime == null)
115115
|| LocalDateTime.now().isAfter(currentTokenRenewTime)) {
116116
OAuthTokenResponse atr;
117-
log.info("Retrieveing oauth token from time series DB");
117+
log.info("Retrieveing new oauth token from time series DB");
118118
try {
119119
String credentials = mapper.writeValueAsString(tsDBuserCredentials);
120120
log.fine(() -> "Setting body to " + credentials);
@@ -144,7 +144,7 @@ public synchronized String getToken() throws OAuthTokenRetrievalException {
144144
log.info("Got token details with type " + atr.getTokenType() + " and expiring in " + atr.getExpiresIn()
145145
+ " seconds");
146146
} else {
147-
log.info("Using existing token");
147+
log.finer("Using existing token");
148148
}
149149
// we have a current token and it is still valid
150150
return currentToken;

0 commit comments

Comments
 (0)