Skip to content

Commit

Permalink
Merge pull request #1 from orijtech/retrofit-for-publishing
Browse files Browse the repository at this point in the history
all: retrofit under io.orijtech.integrations.ocjdbc
  • Loading branch information
odeke-em authored Oct 17, 2019
2 parents 8584617 + b892f08 commit e88d15d
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 39 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ apply plugin: 'maven'
apply plugin: "net.ltgt.errorprone"
apply plugin: "signing"

group = "io.opencensus.integration"
version = "0.0.2" // CURRENT_OCJDBC_VERSION
group = "io.orijtech.integrations"
version = "0.0.5" // CURRENT_OCJDBC_VERSION

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -38,7 +38,7 @@ buildscript {
}
}

def opencensusVersion = '0.16.1'
def opencensusVersion = '0.24.0'
def errorProneVersion = '2.3.1'
def findBugsJsr305Version = '3.0.2'

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "opencensus-jdbc"
rootProject.name = "ocjdbc"
16 changes: 11 additions & 5 deletions src/main/java/io/opencensus/integration/jdbc/Observability.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.stats.Aggregation;
Expand All @@ -27,6 +27,8 @@
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContextBuilder;
import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagMetadata;
import io.opencensus.tags.TagMetadata.TagTtl;
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tagger;
import io.opencensus.tags.Tags;
Expand Down Expand Up @@ -107,6 +109,8 @@ private Observability() {}
500000.0)));

static final Aggregation COUNT = Aggregation.Count.create();
static final TagMetadata TAG_METADATA_TTL_UNLIMITED =
TagMetadata.create(TagTtl.UNLIMITED_PROPAGATION);

static final View SQL_CLIENT_LATENCY_VIEW =
View.create(
Expand Down Expand Up @@ -190,13 +194,15 @@ void end() {
// Finally record the latency of the entire call,
// as well as "status": "OK" for non-error calls.
TagContextBuilder tagContextBuilder = tagger.currentBuilder();
tagContextBuilder.put(JAVA_SQL_METHOD, TagValue.create(this.method));
tagContextBuilder.put(
JAVA_SQL_METHOD, TagValue.create(this.method), TAG_METADATA_TTL_UNLIMITED);

if (recordedError == null) {
tagContextBuilder.put(JAVA_SQL_STATUS, VALUE_OK);
tagContextBuilder.put(JAVA_SQL_STATUS, VALUE_OK, TAG_METADATA_TTL_UNLIMITED);
} else {
tagContextBuilder.put(JAVA_SQL_ERROR, TagValue.create(recordedError));
tagContextBuilder.put(JAVA_SQL_STATUS, VALUE_ERROR);
tagContextBuilder.put(
JAVA_SQL_ERROR, TagValue.create(recordedError), TAG_METADATA_TTL_UNLIMITED);
tagContextBuilder.put(JAVA_SQL_STATUS, VALUE_ERROR, TAG_METADATA_TTL_UNLIMITED);
}

long totalTimeNs = System.nanoTime() - this.startTimeNs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.ResultSet;
import java.sql.SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import io.opencensus.common.Scope;
import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
Expand All @@ -21,7 +21,6 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;

import io.opencensus.integration.jdbc.Observability.TrackingOperation;
import io.opencensus.stats.Aggregation.Distribution;
import io.opencensus.stats.BucketBoundaries;
import io.opencensus.stats.Measure.MeasureDouble;
Expand All @@ -32,13 +31,16 @@
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContextBuilder;
import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagMetadata;
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tagger;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.BlankSpan;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanBuilder;
import io.opencensus.trace.Status;
import io.opencensus.trace.Tracer;
import io.orijtech.integrations.ocjdbc.Observability.TrackingOperation;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -68,7 +70,9 @@ public void setUp() {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(mockViewManager).registerView(any(View.class));
Mockito.when(mockTagger.currentBuilder()).thenReturn(mockTagContextBuilder);
Mockito.when(mockTagContextBuilder.put(any(TagKey.class), any(TagValue.class)))
Mockito.when(
mockTagContextBuilder.put(
any(TagKey.class), any(TagValue.class), any(TagMetadata.class)))
.thenReturn(mockTagContextBuilder);
Mockito.when(mockTagContextBuilder.build()).thenReturn(mockTagContext);
Mockito.when(mockStatsRecorder.newMeasureMap()).thenReturn(mockMeasureMap);
Expand Down Expand Up @@ -148,7 +152,8 @@ public void trackingOperation_withSpan() {
TrackingOperation trackingOperation =
new TrackingOperation("method", "update", mockStatsRecorder, mockTagger, mockTracer);
trackingOperation.withSpan();
Mockito.verify(mockTracer, Mockito.times(1)).spanBuilderWithExplicitParent("method", null);
Mockito.verify(mockTracer, Mockito.times(1))
.spanBuilderWithExplicitParent("method", BlankSpan.INSTANCE);
Mockito.verify(mockSpanBuilder, Mockito.times(1)).startSpan();
Mockito.verify(mockSpan, Mockito.times(1))
.putAttribute("sql", AttributeValue.stringAttributeValue("update"));
Expand All @@ -161,9 +166,15 @@ public void trackingOperation_end() {
trackingOperation.end();
Mockito.verify(mockTagger, Mockito.times(1)).currentBuilder();
Mockito.verify(mockTagContextBuilder, Mockito.times(1))
.put(eq(Observability.JAVA_SQL_METHOD), eq(TagValue.create("method")));
.put(
eq(Observability.JAVA_SQL_METHOD),
eq(TagValue.create("method")),
eq(Observability.TAG_METADATA_TTL_UNLIMITED));
Mockito.verify(mockTagContextBuilder, Mockito.times(1))
.put(eq(Observability.JAVA_SQL_STATUS), eq(Observability.VALUE_OK));
.put(
eq(Observability.JAVA_SQL_STATUS),
eq(Observability.VALUE_OK),
eq(Observability.TAG_METADATA_TTL_UNLIMITED));
Mockito.verify(mockStatsRecorder, Mockito.times(1)).newMeasureMap();
Mockito.verify(mockMeasureMap, Mockito.times(1))
.put(eq(Observability.MEASURE_LATENCY_MS), anyDouble());
Expand All @@ -180,11 +191,20 @@ public void trackingOperation_end_recordException() {
trackingOperation.end();
Mockito.verify(mockTagger, Mockito.times(1)).currentBuilder();
Mockito.verify(mockTagContextBuilder, Mockito.times(1))
.put(eq(Observability.JAVA_SQL_METHOD), eq(TagValue.create("method")));
.put(
eq(Observability.JAVA_SQL_METHOD),
eq(TagValue.create("method")),
eq(Observability.TAG_METADATA_TTL_UNLIMITED));
Mockito.verify(mockTagContextBuilder, Mockito.times(1))
.put(eq(Observability.JAVA_SQL_ERROR), eq(TagValue.create(exception.toString())));
.put(
eq(Observability.JAVA_SQL_ERROR),
eq(TagValue.create(exception.toString())),
eq(Observability.TAG_METADATA_TTL_UNLIMITED));
Mockito.verify(mockTagContextBuilder, Mockito.times(1))
.put(eq(Observability.JAVA_SQL_STATUS), eq(Observability.VALUE_ERROR));
.put(
eq(Observability.JAVA_SQL_STATUS),
eq(Observability.VALUE_ERROR),
eq(Observability.TAG_METADATA_TTL_UNLIMITED));
Mockito.verify(mockSpan, Mockito.times(1))
.setStatus(eq(Status.UNKNOWN.withDescription(exception.toString())));
Mockito.verify(mockStatsRecorder, Mockito.times(1)).newMeasureMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package io.opencensus.integration.jdbc;
package io.orijtech.integrations.ocjdbc;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.opencensus.integration.jdbc.Observability.TraceOption;
import io.orijtech.integrations.ocjdbc.Observability.TraceOption;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.EnumSet;
Expand Down

0 comments on commit e88d15d

Please sign in to comment.