Search in sources :

Example 16 with TaggedMetricName

use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.

the class WavefrontYammerMetricsReporterTest method testPrependGroupName.

@Test(timeout = 1000)
public void testPrependGroupName() throws Exception {
    innerSetUp(true, null, false, false);
    // Counter
    TaggedMetricName taggedMetricName = new TaggedMetricName("group", "mycounter", "tag1", "value1", "tag2", "value2");
    Counter counter = metricsRegistry.newCounter(taggedMetricName);
    counter.inc();
    counter.inc();
    AtomicLong clock = new AtomicLong(System.currentTimeMillis());
    // Wavefront Histo
    WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group3", "myhisto", "tag1", "value1", "tag2", "value2"), clock::get);
    for (int i = 0; i < 101; i++) {
        wavefrontHistogram.update(i);
    }
    // Exploded Histo
    Histogram histogram = metricsRegistry.newHistogram(new MetricName("group2", "", "myhisto"), false);
    histogram.update(1);
    histogram.update(10);
    // Advance the clock by 1 min ...
    clock.addAndGet(60000L + 1);
    wavefrontYammerMetricsReporter.run();
    assertThat(receiveFromSocket(12, fromMetrics), containsInAnyOrder(equalTo("\"group.mycounter\" 2.0 1485224035 tag1=\"value1\" tag2=\"value2\""), equalTo("\"group2.myhisto.count\" 2.0 1485224035"), equalTo("\"group2.myhisto.min\" 1.0 1485224035"), equalTo("\"group2.myhisto.max\" 10.0 1485224035"), equalTo("\"group2.myhisto.mean\" 5.5 1485224035"), equalTo("\"group2.myhisto.sum\" 11.0 1485224035"), startsWith("\"group2.myhisto.stddev\""), equalTo("\"group2.myhisto.median\" 5.5 1485224035"), equalTo("\"group2.myhisto.p75\" 10.0 1485224035"), equalTo("\"group2.myhisto.p95\" 10.0 1485224035"), equalTo("\"group2.myhisto.p99\" 10.0 1485224035"), equalTo("\"group2.myhisto.p999\" 10.0 1485224035")));
    assertThat(receiveFromSocket(1, fromHistograms), contains(equalTo("!M 1485224035 #101 50.0 \"group3.myhisto\" tag1=\"value1\" tag2=\"value2\"")));
}
Also used : MetricName(com.yammer.metrics.core.MetricName) TaggedMetricName(com.wavefront.common.TaggedMetricName) AtomicLong(java.util.concurrent.atomic.AtomicLong) Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Counter(com.yammer.metrics.core.Counter) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) TaggedMetricName(com.wavefront.common.TaggedMetricName) Test(org.junit.Test)

Example 17 with TaggedMetricName

use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.

the class PreprocessorConfigManager method loadFromStream.

@VisibleForTesting
void loadFromStream(InputStream stream) {
    totalValidRules = 0;
    totalInvalidRules = 0;
    Yaml yaml = new Yaml();
    Map<String, ReportableEntityPreprocessor> portMap = new HashMap<>();
    try {
        Map<String, Object> rulesByPort = yaml.load(stream);
        if (rulesByPort == null || rulesByPort.isEmpty()) {
            logger.warning("Empty preprocessor rule file detected!");
            logger.info("Total 0 rules loaded");
            synchronized (this) {
                this.userPreprocessorsTs = timeSupplier.get();
                this.userPreprocessors = Collections.emptyMap();
            }
            return;
        }
        for (String strPortKey : rulesByPort.keySet()) {
            // Handle comma separated ports and global ports.
            // Note: Global ports need to be specified at the end of the file, inorder to be
            // applicable to all the explicitly specified ports in preprocessor_rules.yaml file.
            List<String> strPortList = strPortKey.equalsIgnoreCase(GLOBAL_PORT_KEY) ? new ArrayList<>(portMap.keySet()) : Arrays.asList(strPortKey.trim().split("\\s*,\\s*"));
            for (String strPort : strPortList) {
                portMap.putIfAbsent(strPort, new ReportableEntityPreprocessor());
                int validRules = 0;
                // noinspection unchecked
                List<Map<String, Object>> rules = (List<Map<String, Object>>) rulesByPort.get(strPortKey);
                for (Map<String, Object> rule : rules) {
                    try {
                        requireArguments(rule, RULE, ACTION);
                        allowArguments(rule, SCOPE, SEARCH, REPLACE, MATCH, TAG, KEY, NEWTAG, NEWKEY, VALUE, SOURCE, INPUT, ITERATIONS, REPLACE_SOURCE, REPLACE_INPUT, ACTION_SUBTYPE, MAX_LENGTH, FIRST_MATCH_ONLY, ALLOW, IF);
                        String ruleName = Objects.requireNonNull(getString(rule, RULE)).replaceAll("[^a-z0-9_-]", "");
                        PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("preprocessor." + ruleName, "count", "port", strPort)), Metrics.newCounter(new TaggedMetricName("preprocessor." + ruleName, "cpu_nanos", "port", strPort)), Metrics.newCounter(new TaggedMetricName("preprocessor." + ruleName, "checked-count", "port", strPort)));
                        String scope = getString(rule, SCOPE);
                        if ("pointLine".equals(scope) || "inputText".equals(scope)) {
                            if (Predicates.getPredicate(rule) != null) {
                                throw new IllegalArgumentException("Argument [if] is not " + "allowed in [scope] = " + scope);
                            }
                            switch(Objects.requireNonNull(getString(rule, ACTION))) {
                                case "replaceRegex":
                                    allowArguments(rule, SCOPE, SEARCH, REPLACE, MATCH, ITERATIONS);
                                    portMap.get(strPort).forPointLine().addTransformer(new LineBasedReplaceRegexTransformer(getString(rule, SEARCH), getString(rule, REPLACE), getString(rule, MATCH), getInteger(rule, ITERATIONS, 1), ruleMetrics));
                                    break;
                                case "blacklistRegex":
                                case "block":
                                    allowArguments(rule, SCOPE, MATCH);
                                    portMap.get(strPort).forPointLine().addFilter(new LineBasedBlockFilter(getString(rule, MATCH), ruleMetrics));
                                    break;
                                case "whitelistRegex":
                                case "allow":
                                    allowArguments(rule, SCOPE, MATCH);
                                    portMap.get(strPort).forPointLine().addFilter(new LineBasedAllowFilter(getString(rule, MATCH), ruleMetrics));
                                    break;
                                default:
                                    throw new IllegalArgumentException("Action '" + getString(rule, ACTION) + "' is not valid or cannot be applied to pointLine");
                            }
                        } else {
                            String action = Objects.requireNonNull(getString(rule, ACTION));
                            switch(action) {
                                // Rules for ReportPoint objects
                                case "replaceRegex":
                                    allowArguments(rule, SCOPE, SEARCH, REPLACE, MATCH, ITERATIONS, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointReplaceRegexTransformer(scope, getString(rule, SEARCH), getString(rule, REPLACE), getString(rule, MATCH), getInteger(rule, ITERATIONS, 1), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "forceLowercase":
                                    allowArguments(rule, SCOPE, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointForceLowercaseTransformer(scope, getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "addTag":
                                    allowArguments(rule, TAG, VALUE, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointAddTagTransformer(getString(rule, TAG), getString(rule, VALUE), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "addTagIfNotExists":
                                    allowArguments(rule, TAG, VALUE, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointAddTagIfNotExistsTransformer(getString(rule, TAG), getString(rule, VALUE), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "dropTag":
                                    allowArguments(rule, TAG, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointDropTagTransformer(getString(rule, TAG), getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "extractTag":
                                    allowArguments(rule, TAG, "source", SEARCH, REPLACE, REPLACE_SOURCE, REPLACE_INPUT, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointExtractTagTransformer(getString(rule, TAG), getString(rule, "source"), getString(rule, SEARCH), getString(rule, REPLACE), (String) rule.getOrDefault(REPLACE_INPUT, rule.get(REPLACE_SOURCE)), getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "extractTagIfNotExists":
                                    allowArguments(rule, TAG, "source", SEARCH, REPLACE, REPLACE_SOURCE, REPLACE_INPUT, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointExtractTagIfNotExistsTransformer(getString(rule, TAG), getString(rule, "source"), getString(rule, SEARCH), getString(rule, REPLACE), (String) rule.getOrDefault(REPLACE_INPUT, rule.get(REPLACE_SOURCE)), getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "renameTag":
                                    allowArguments(rule, TAG, NEWTAG, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointRenameTagTransformer(getString(rule, TAG), getString(rule, NEWTAG), getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "limitLength":
                                    allowArguments(rule, SCOPE, ACTION_SUBTYPE, MAX_LENGTH, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new ReportPointLimitLengthTransformer(Objects.requireNonNull(scope), getInteger(rule, MAX_LENGTH, 0), LengthLimitActionType.fromString(getString(rule, ACTION_SUBTYPE)), getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "count":
                                    allowArguments(rule, SCOPE, IF);
                                    portMap.get(strPort).forReportPoint().addTransformer(new CountTransformer<>(Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "blacklistRegex":
                                    logger.warning("Preprocessor rule using deprecated syntax (action: " + action + "), use 'action: block' instead!");
                                case "block":
                                    allowArguments(rule, SCOPE, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addFilter(new ReportPointBlockFilter(scope, getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "whitelistRegex":
                                    logger.warning("Preprocessor rule using deprecated syntax (action: " + action + "), use 'action: allow' instead!");
                                case "allow":
                                    allowArguments(rule, SCOPE, MATCH, IF);
                                    portMap.get(strPort).forReportPoint().addFilter(new ReportPointAllowFilter(scope, getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                // Rules for Span objects
                                case "spanReplaceRegex":
                                    allowArguments(rule, SCOPE, SEARCH, REPLACE, MATCH, ITERATIONS, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanReplaceRegexTransformer(scope, getString(rule, SEARCH), getString(rule, REPLACE), getString(rule, MATCH), getInteger(rule, ITERATIONS, 1), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanForceLowercase":
                                    allowArguments(rule, SCOPE, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanForceLowercaseTransformer(scope, getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanAddAnnotation":
                                case "spanAddTag":
                                    allowArguments(rule, KEY, VALUE, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanAddAnnotationTransformer(getString(rule, KEY), getString(rule, VALUE), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanAddAnnotationIfNotExists":
                                case "spanAddTagIfNotExists":
                                    allowArguments(rule, KEY, VALUE, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanAddAnnotationIfNotExistsTransformer(getString(rule, KEY), getString(rule, VALUE), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanDropAnnotation":
                                case "spanDropTag":
                                    allowArguments(rule, KEY, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanDropAnnotationTransformer(getString(rule, KEY), getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanWhitelistAnnotation":
                                case "spanWhitelistTag":
                                    logger.warning("Preprocessor rule using deprecated syntax (action: " + action + "), use 'action: spanAllowAnnotation' instead!");
                                case "spanAllowAnnotation":
                                case "spanAllowTag":
                                    allowArguments(rule, ALLOW, IF);
                                    portMap.get(strPort).forSpan().addTransformer(SpanAllowAnnotationTransformer.create(rule, Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanExtractAnnotation":
                                case "spanExtractTag":
                                    allowArguments(rule, KEY, INPUT, SEARCH, REPLACE, REPLACE_INPUT, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanExtractAnnotationTransformer(getString(rule, KEY), getString(rule, INPUT), getString(rule, SEARCH), getString(rule, REPLACE), getString(rule, REPLACE_INPUT), getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanExtractAnnotationIfNotExists":
                                case "spanExtractTagIfNotExists":
                                    allowArguments(rule, KEY, INPUT, SEARCH, REPLACE, REPLACE_INPUT, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanExtractAnnotationIfNotExistsTransformer(getString(rule, KEY), getString(rule, INPUT), getString(rule, SEARCH), getString(rule, REPLACE), getString(rule, REPLACE_INPUT), getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanRenameAnnotation":
                                case "spanRenameTag":
                                    allowArguments(rule, KEY, NEWKEY, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanRenameAnnotationTransformer(getString(rule, KEY), getString(rule, NEWKEY), getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanLimitLength":
                                    allowArguments(rule, SCOPE, ACTION_SUBTYPE, MAX_LENGTH, MATCH, FIRST_MATCH_ONLY, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new SpanLimitLengthTransformer(Objects.requireNonNull(scope), getInteger(rule, MAX_LENGTH, 0), LengthLimitActionType.fromString(getString(rule, ACTION_SUBTYPE)), getString(rule, MATCH), getBoolean(rule, FIRST_MATCH_ONLY, false), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanCount":
                                    allowArguments(rule, SCOPE, IF);
                                    portMap.get(strPort).forSpan().addTransformer(new CountTransformer<>(Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanBlacklistRegex":
                                    logger.warning("Preprocessor rule using deprecated syntax (action: " + action + "), use 'action: spanBlock' instead!");
                                case "spanBlock":
                                    allowArguments(rule, SCOPE, MATCH, IF);
                                    portMap.get(strPort).forSpan().addFilter(new SpanBlockFilter(scope, getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                case "spanWhitelistRegex":
                                    logger.warning("Preprocessor rule using deprecated syntax (action: " + action + "), use 'action: spanAllow' instead!");
                                case "spanAllow":
                                    allowArguments(rule, SCOPE, MATCH, IF);
                                    portMap.get(strPort).forSpan().addFilter(new SpanAllowFilter(scope, getString(rule, MATCH), Predicates.getPredicate(rule), ruleMetrics));
                                    break;
                                default:
                                    throw new IllegalArgumentException("Action '" + getString(rule, ACTION) + "' is not valid");
                            }
                        }
                        validRules++;
                    } catch (IllegalArgumentException | NullPointerException ex) {
                        logger.warning("Invalid rule " + (rule == null ? "" : rule.getOrDefault(RULE, "")) + " (port " + strPort + "): " + ex);
                        totalInvalidRules++;
                    }
                }
                logger.info("Loaded " + validRules + " rules for port :: " + strPort);
                totalValidRules += validRules;
            }
            logger.info("Loaded Preprocessor rules for port key :: \"" + strPortKey + "\"");
        }
        logger.info("Total Preprocessor rules loaded :: " + totalValidRules);
        if (totalInvalidRules > 0) {
            throw new RuntimeException("Total Invalid Preprocessor rules detected :: " + totalInvalidRules);
        }
    } catch (ClassCastException e) {
        throw new RuntimeException("Can't parse preprocessor configuration", e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    synchronized (this) {
        this.userPreprocessorsTs = timeSupplier.get();
        this.userPreprocessors = portMap;
    }
}
Also used : HashMap(java.util.HashMap) PreprocessorUtil.getString(com.wavefront.agent.preprocessor.PreprocessorUtil.getString) TaggedMetricName(com.wavefront.common.TaggedMetricName) ArrayList(java.util.ArrayList) List(java.util.List) Yaml(org.yaml.snakeyaml.Yaml) HashMap(java.util.HashMap) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with TaggedMetricName

use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.

the class InstrumentedTaskQueueDelegate method remove.

@Override
public void remove() {
    try {
        T t = this.head == null ? delegate.peek() : head;
        long size = t == null ? 0 : t.weight();
        delegate.remove();
        head = null;
        tasksRemovedCounter.inc();
        itemsRemovedCounter.inc(size);
    } catch (IOException e) {
        Metrics.newCounter(new TaggedMetricName(prefix, "failures", tags)).inc();
        log.severe("I/O error removing task from the queue: " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Example 19 with TaggedMetricName

use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.

the class InstrumentedTaskQueueDelegate method clear.

@Override
public void clear() {
    try {
        this.head = null;
        delegate.clear();
    } catch (IOException e) {
        Metrics.newCounter(new TaggedMetricName(prefix, "failures", tags)).inc();
        log.severe("I/O error clearing queue: " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Example 20 with TaggedMetricName

use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.

the class DataDogPortUnificationHandler method handleHttpMessage.

@Override
protected void handleHttpMessage(final ChannelHandlerContext ctx, final FullHttpRequest request) throws URISyntaxException {
    StringBuilder output = new StringBuilder();
    AtomicInteger pointsPerRequest = new AtomicInteger();
    URI uri = new URI(request.uri());
    HttpResponseStatus status = HttpResponseStatus.ACCEPTED;
    String requestBody = request.content().toString(CharsetUtil.UTF_8);
    if (requestRelayClient != null && requestRelayTarget != null && request.method() == POST) {
        Histogram requestRelayDuration = Metrics.newHistogram(new TaggedMetricName("listeners", "http-relay.duration-nanos", "port", handle));
        long startNanos = System.nanoTime();
        try {
            String outgoingUrl = requestRelayTarget.replaceFirst("/*$", "") + request.uri();
            HttpPost outgoingRequest = new HttpPost(outgoingUrl);
            if (request.headers().contains("Content-Type")) {
                outgoingRequest.addHeader("Content-Type", request.headers().get("Content-Type"));
            }
            outgoingRequest.setEntity(new StringEntity(requestBody));
            if (synchronousMode) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Relaying incoming HTTP request to " + outgoingUrl);
                }
                HttpResponse response = requestRelayClient.execute(outgoingRequest);
                int httpStatusCode = response.getStatusLine().getStatusCode();
                httpStatusCounterCache.get(httpStatusCode).inc();
                if (httpStatusCode < 200 || httpStatusCode >= 300) {
                    // anything that is not 2xx is relayed as is to the client, don't process the payload
                    writeHttpResponse(ctx, HttpResponseStatus.valueOf(httpStatusCode), EntityUtils.toString(response.getEntity(), "UTF-8"), request);
                    return;
                }
            } else {
                threadpool.submit(() -> {
                    try {
                        if (logger.isLoggable(Level.FINE)) {
                            logger.fine("Relaying incoming HTTP request (async) to " + outgoingUrl);
                        }
                        HttpResponse response = requestRelayClient.execute(outgoingRequest);
                        int httpStatusCode = response.getStatusLine().getStatusCode();
                        httpStatusCounterCache.get(httpStatusCode).inc();
                        EntityUtils.consumeQuietly(response.getEntity());
                    } catch (IOException e) {
                        logger.warning("Unable to relay request to " + requestRelayTarget + ": " + e.getMessage());
                        Metrics.newCounter(new TaggedMetricName("listeners", "http-relay.failed", "port", handle)).inc();
                    }
                });
            }
        } catch (IOException e) {
            logger.warning("Unable to relay request to " + requestRelayTarget + ": " + e.getMessage());
            Metrics.newCounter(new TaggedMetricName("listeners", "http-relay.failed", "port", handle)).inc();
            writeHttpResponse(ctx, HttpResponseStatus.BAD_GATEWAY, "Unable to relay request: " + e.getMessage(), request);
            return;
        } finally {
            requestRelayDuration.update(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
        }
    }
    String path = uri.getPath().endsWith("/") ? uri.getPath() : uri.getPath() + "/";
    switch(path) {
        case "/api/v1/series/":
            try {
                status = reportMetrics(jsonParser.readTree(requestBody), pointsPerRequest, output::append);
            } catch (Exception e) {
                status = HttpResponseStatus.BAD_REQUEST;
                output.append(errorMessageWithRootCause(e));
                logWarning("WF-300: Failed to handle /api/v1/series request", e, ctx);
            }
            httpRequestSize.update(pointsPerRequest.intValue());
            writeHttpResponse(ctx, status, output, request);
            break;
        case "/api/v1/check_run/":
            if (!processServiceChecks) {
                Metrics.newCounter(new TaggedMetricName("listeners", "http-requests.ignored", "port", handle)).inc();
                writeHttpResponse(ctx, HttpResponseStatus.ACCEPTED, output, request);
                return;
            }
            try {
                reportChecks(jsonParser.readTree(requestBody), pointsPerRequest, output::append);
            } catch (Exception e) {
                status = HttpResponseStatus.BAD_REQUEST;
                output.append(errorMessageWithRootCause(e));
                logWarning("WF-300: Failed to handle /api/v1/check_run request", e, ctx);
            }
            writeHttpResponse(ctx, status, output, request);
            break;
        case "/api/v1/validate/":
            writeHttpResponse(ctx, HttpResponseStatus.OK, output, request);
            break;
        case "/intake/":
            try {
                status = processMetadataAndSystemMetrics(jsonParser.readTree(requestBody), processSystemMetrics, pointsPerRequest, output::append);
            } catch (Exception e) {
                status = HttpResponseStatus.BAD_REQUEST;
                output.append(errorMessageWithRootCause(e));
                logWarning("WF-300: Failed to handle /intake request", e, ctx);
            }
            httpRequestSize.update(pointsPerRequest.intValue());
            writeHttpResponse(ctx, status, output, request);
            break;
        default:
            writeHttpResponse(ctx, HttpResponseStatus.NO_CONTENT, output, request);
            logWarning("WF-300: Unexpected path '" + request.uri() + "', returning HTTP 204", null, ctx);
            break;
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Histogram(com.yammer.metrics.core.Histogram) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) ChannelUtils.writeHttpResponse(com.wavefront.agent.channel.ChannelUtils.writeHttpResponse) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) URI(java.net.URI) TaggedMetricName(com.wavefront.common.TaggedMetricName) ReportPoint(wavefront.report.ReportPoint) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StringEntity(org.apache.http.entity.StringEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

TaggedMetricName (com.wavefront.common.TaggedMetricName)21 IOException (java.io.IOException)6 Test (org.junit.Test)5 Counter (com.yammer.metrics.core.Counter)4 MetricName (com.yammer.metrics.core.MetricName)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Histogram (com.yammer.metrics.core.Histogram)2 WavefrontHistogram (com.yammer.metrics.core.WavefrontHistogram)2 URI (java.net.URI)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 CachingHostnameLookupResolver (com.wavefront.agent.channel.CachingHostnameLookupResolver)1 ChannelUtils.writeHttpResponse (com.wavefront.agent.channel.ChannelUtils.writeHttpResponse)1 ConnectionTrackingHandler (com.wavefront.agent.channel.ConnectionTrackingHandler)1 HealthCheckManagerImpl (com.wavefront.agent.channel.HealthCheckManagerImpl)1