Search in sources :

Example 6 with Attrs

use of com.netflix.zuul.Attrs in project zuul by Netflix.

the class ConnTimerTest method record.

@Test
public void record() {
    EmbeddedChannel chan = new EmbeddedChannel();
    Attrs attrs = Attrs.newInstance();
    chan.attr(Server.CONN_DIMENSIONS).set(attrs);
    Registry registry = new DefaultRegistry();
    ConnTimer timer = ConnTimer.install(chan, registry, registry.createId("foo"));
    timer.record(1000L, "start");
    timer.record(2000L, "middle");
    Attrs.newKey("bar").put(attrs, "baz");
    timer.record(4000L, "end");
    PercentileTimer meter1 = PercentileTimer.get(registry, registry.createId("foo.start-middle"));
    assertNotNull(meter1);
    assertEquals(1000L, meter1.totalTime());
    PercentileTimer meter2 = PercentileTimer.get(registry, registry.createId("foo.middle-end", "bar", "baz"));
    assertNotNull(meter2);
    assertEquals(2000L, meter2.totalTime());
    PercentileTimer meter3 = PercentileTimer.get(registry, registry.createId("foo.start-end", "bar", "baz"));
    assertNotNull(meter3);
    assertEquals(3000L, meter3.totalTime());
}
Also used : PercentileTimer(com.netflix.spectator.api.histogram.PercentileTimer) Attrs(com.netflix.zuul.Attrs) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) Test(org.junit.Test)

Example 7 with Attrs

use of com.netflix.zuul.Attrs in project zuul by Netflix.

the class ConnCounter method increment.

public void increment(String event, Attrs extraDimensions) {
    Objects.requireNonNull(event);
    Objects.requireNonNull(extraDimensions);
    if (counts.containsKey(event)) {
        // TODO(carl-mastrangelo): make this throw IllegalStateException after verifying this doesn't happen.
        logger.warn("Duplicate conn counter increment {}", event);
        return;
    }
    Attrs connDims = chan.attr(Server.CONN_DIMENSIONS).get();
    Map<String, String> dimTags = new HashMap<>(connDims.size() + extraDimensions.size());
    connDims.forEach((k, v) -> dimTags.put(k.name(), String.valueOf(v)));
    extraDimensions.forEach((k, v) -> dimTags.put(k.name(), String.valueOf(v)));
    dimTags.put("from", lastCountKey != null ? lastCountKey : "nascent");
    lastCountKey = event;
    Id id = registry.createId(metricBase.name() + '.' + event).withTags(metricBase.tags()).withTags(dimTags);
    Gauge gauge = registry.gauge(id);
    synchronized (getLock(id)) {
        double current = gauge.value();
        gauge.set(Double.isNaN(current) ? 1 : current + 1);
    }
    counts.put(event, gauge);
}
Also used : HashMap(java.util.HashMap) Attrs(com.netflix.zuul.Attrs) Id(com.netflix.spectator.api.Id) Gauge(com.netflix.spectator.api.Gauge)

Aggregations

Attrs (com.netflix.zuul.Attrs)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 Test (org.junit.Test)4 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)3 Registry (com.netflix.spectator.api.Registry)3 Gauge (com.netflix.spectator.api.Gauge)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InetAddresses (com.google.common.net.InetAddresses)1 SourceAddressChannelHandler (com.netflix.netty.common.SourceAddressChannelHandler)1 Id (com.netflix.spectator.api.Id)1 PercentileTimer (com.netflix.spectator.api.histogram.PercentileTimer)1 Server (com.netflix.zuul.netty.server.Server)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 HAProxyMessage (io.netty.handler.codec.haproxy.HAProxyMessage)1