Skip to content

Commit

Permalink
Merge pull request #20 from newrelic/re-add-production-endpoint
Browse files Browse the repository at this point in the history
Re add the production endpoint
  • Loading branch information
jasonjkeller authored Aug 15, 2019
2 parents 9adc7b6 + c58de4b commit 1f3bc83
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 50 deletions.
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ The Telemetry SDK comes with tests in:.

`integration_test`
`metrics/src/test`
`telemetry/src/test`
`telemetry_components/src/test`

TODO update this section to accurately reflect expected testing guidelines.
You can run all of these tests, and verify that your code is formatted correctly by running

`./gradlew check`

## License
By contributing to Telemetry SDK, you agree that your contributions will be licensed under the [License file](LICENSE) in the root directory of this source tree.
By contributing to the Java Telemetry SDK, you agree that your contributions will be licensed under the [License file](LICENSE)
in the root directory of this source tree.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ This is the core module for sending dimensional metrics to New Relic. The librar

`com.newrelic.telemetry:metrics`

Note: in order to use these APIs, you will need to get access to the API endpoint.
Please contact `[email protected]` to request access.

You will also need an Insights Insert API Key.
In order to send metrics to New Relic, you will also need an Insights Insert API Key.
Please see [New Relic Api Keys](https://docs.newrelic.com/docs/apis/getting-started/intro-apis/understand-new-relic-api-keys#user-api-key)
for more information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.newrelic.telemetry.util.Utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -98,6 +99,12 @@ public Builder(String apiKey, HttpPoster httpPoster, MetricJsonGenerator jsonGen
this.httpPoster = httpPoster;
this.apiKey = apiKey;
this.jsonGenerator = jsonGenerator;

try {
metricsUrl = constructMetricsUrlWithHost(URI.create("https://metric-api.newrelic.com/"));
} catch (MalformedURLException e) {
throw new UncheckedIOException("Bad hardcoded URL", e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* If you wish to provide your own json implementation, an implementation of this interface must be
* provided. All of the methods must return valid JSON with properly escaped strings.
*
* <p>TODO: add links to external documentation of the json format.
* <p>TODO: add links to external documentation of the json format and APIs.
*/
public interface MetricJsonGenerator {
Logger logger = LoggerFactory.getLogger(MetricJsonGenerator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Map;
import lombok.Value;

/** TODO: javadoc me */
/** The response from the backend APIs. */
@Value
public class HttpResponse {
String body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import com.newrelic.telemetry.MetricBuffer;
import com.newrelic.telemetry.Response;
import com.newrelic.telemetry.SimpleMetricBatchSender;
import com.newrelic.telemetry.exceptions.ResponseException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.logging.Logger;
import java.util.stream.IntStream;

Expand All @@ -29,18 +28,15 @@
* <p>The exact response of the Metric API is not guaranteed for any of these edge cases. They are
* just provided as example of things that might cause issues.
*
* <p>To run this example, provide 2 command line args, the first is the URL to the metric ingest
* endpoint, and the 2nd is the Insights Insert key.
* <p>To run this example, provide a command line argument for your Insights Insert key.
*/
public class BoundaryExample {
private static final Logger logger = Logger.getLogger(BoundaryExample.class.getName());

public static void main(String[] args) throws MalformedURLException {
URI metricApiEndpoint = URI.create(args[0]);
String insightsInsertKey = args[1];
public static void main(String[] args) throws ResponseException {
String insightsInsertKey = args[0];

MetricBatchSender sender =
SimpleMetricBatchSender.builder(insightsInsertKey).uriOverride(metricApiEndpoint).build();
MetricBatchSender sender = SimpleMetricBatchSender.builder(insightsInsertKey).build();

MetricBuffer metricBuffer =
new MetricBuffer(new Attributes().put("exampleName", "BoundaryExample"));
Expand All @@ -51,12 +47,8 @@ public static void main(String[] args) throws MalformedURLException {
metricBuffer.addMetric(getWithEmojiMetricName());
metricBuffer.addMetric(getWithBasicMultilingualUnicodeMetricName());

try {
Response response = sender.sendBatch(metricBuffer.createBatch());
logger.info(response.getBody());
} catch (Exception e) {
throw new RuntimeException(e);
}
Response response = sender.sendBatch(metricBuffer.createBatch());
logger.info(response.getBody());
}

/** At publication time, this did not cause errors in ingest. */
Expand All @@ -81,7 +73,7 @@ private static Count getWithLongMetricName() {
attribs);
}

/** At publication time, this did not cause errors in ingest. */
/** At publication time, this metric failed to be ingested and caused an NrIntegrationError. */
private static Count getWithManyAttributes() {
Attributes attribs = new Attributes();
attribs.put("finder", "getWithManyAttributes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.newrelic.telemetry.MetricBatchSender;
import com.newrelic.telemetry.MetricBuffer;
import com.newrelic.telemetry.SimpleMetricBatchSender;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -38,11 +37,9 @@ public class CountExample {
private static final List<String> items = Arrays.asList("apples", "oranges", "beer", "wine");

public static void main(String[] args) throws Exception {
URI metricApiEndpoint = URI.create(args[0]);
String insightsInsertKey = args[1];
String insightsInsertKey = args[0];

MetricBatchSender sender =
SimpleMetricBatchSender.builder(insightsInsertKey).uriOverride(metricApiEndpoint).build();
MetricBatchSender sender = SimpleMetricBatchSender.builder(insightsInsertKey).build();
MetricBuffer metricBuffer = new MetricBuffer(getCommonAttributes());

for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.newrelic.telemetry.MetricBatchSender;
import com.newrelic.telemetry.MetricBuffer;
import com.newrelic.telemetry.SimpleMetricBatchSender;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -26,8 +25,7 @@
* <p>Additionally, this provides an example of using a {@code com.newrelic.telemetry.MetricBuffer}
* to hold on to metrics and send them as a batch.
*
* <p>To run this example, provide 2 command line args, the first is the URL to the metric ingest *
* endpoint, and the 2nd is the Insights Insert key.
* <p>To run this example, provide a command line argument for your Insights Insert key.
*/
public class GaugeExample {

Expand All @@ -37,11 +35,9 @@ public class GaugeExample {
Arrays.asList("bedroom", "dining_room", "living_room", "basement");

public static void main(String[] args) throws Exception {
URI metricApiEndpoint = URI.create(args[0]);
String insightsInsertKey = args[1];
String insightsInsertKey = args[0];

MetricBatchSender sender =
SimpleMetricBatchSender.builder(insightsInsertKey).uriOverride(metricApiEndpoint).build();
MetricBatchSender sender = SimpleMetricBatchSender.builder(insightsInsertKey).build();
MetricBuffer metricBuffer = new MetricBuffer(getCommonAttributes());

for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.newrelic.telemetry.MetricBuffer;
import com.newrelic.telemetry.SimpleMetricBatchSender;
import com.newrelic.telemetry.Summary;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -26,8 +25,7 @@
* <p>Additionally, this provides an example of using a {@code com.newrelic.telemetry.MetricBuffer}
* to hold on to metrics and send them as a batch.
*
* <p>To run this example, provide 2 command line args, the first is the URL to the metric ingest *
* endpoint, and the 2nd is the Insights Insert key.
* <p>To run this example, provide a command line argument for your Insights Insert key.
*/
public class SummaryExample {

Expand All @@ -37,11 +35,9 @@ public class SummaryExample {
Arrays.asList("/posts (GET)", "/comments (GET)", "/users (GET)");

public static void main(String[] args) throws Exception {
URI metricApiEndpoint = URI.create(args[0]);
String insightsInsertKey = args[1];
String insightsInsertKey = args[0];

MetricBatchSender sender =
SimpleMetricBatchSender.builder(insightsInsertKey).uriOverride(metricApiEndpoint).build();
MetricBatchSender sender = SimpleMetricBatchSender.builder(insightsInsertKey).build();
MetricBuffer metricBuffer = new MetricBuffer(getCommonAttributes());

for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.newrelic.telemetry.Summary;
import com.newrelic.telemetry.TelemetryClient;
import java.net.InetAddress;
import java.net.URI;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

Expand All @@ -26,23 +25,20 @@
*
* <p>It also demonstrates that a single MetricBatch can contain metrics of different types.
*
* <p>To run this example, provide 2 command line args, the first is the URL to the metric ingest
* endpoint, and the 2nd is the Insights Insert key.
* <p>To run this example, provide a command line argument for your Insights Insert key.
*/
public class TelemetryClientExample {

public static void main(String[] args) throws Exception {
URI metricApiEndpoint = URI.create(args[0]);
String insightsInsertKey = args[1];
String insightsInsertKey = args[0];

MetricBatchSender batchSender =
SimpleMetricBatchSender.builder(insightsInsertKey, Duration.of(10, ChronoUnit.SECONDS))
.uriOverride(metricApiEndpoint)
.build();

TelemetryClient sender = new TelemetryClient(batchSender);

Attributes commonAttributes = new Attributes().put("exampleName", "RetryingExample");
Attributes commonAttributes = new Attributes().put("exampleName", "TelemetryClientExample");
commonAttributes.put("host", InetAddress.getLocalHost().getHostName());
commonAttributes.put("appName", "testApplication");
commonAttributes.put("environment", "staging");
Expand Down

0 comments on commit 1f3bc83

Please sign in to comment.