grobian / carbon-c-relay

Enhanced C implementation of Carbon relay, aggregator and rewriter
Apache License 2.0
380 stars 107 forks source link

Do not prefix stats #451

Closed ssko1 closed 1 year ago

ssko1 commented 1 year ago

Is there a way to disable prefixing with the statistics construct?

When I created my own statistics construct, I expected it to override the default configuration provided by carbon-c-relay.

# my relay.conf
statistics
    submit every 10 seconds
    send to forwarder
    stop
    ;

But I end up with the configuration on boot

# printed configuration on startup
statistics
    submit every 10 seconds
    prefix with carbon.relays.myhostname
    send to forwarder
    stop
    ;
grobian commented 1 year ago

Hey, not sure if this works, but have you tried prefix with ""?

ssko1 commented 1 year ago

I did try! Quotes result in an error

[2022-10-12 18:55:29] relay.conf:13:17: empty string
[2022-10-12 18:55:29]     prefix with ""
grobian commented 1 year ago

ok, there's two ways I can think of:

statistics prefix with .;

or a bit more convoluted

statistics prefix with somethingrandom; rewrite ^somethingrandom\.(.*) into \1;

But I hope the first works for you, because then you can use the "send to".

ssko1 commented 1 year ago

Is there any insight as to why . would work? A simple test shows the following internal stats

.dispatcher1.metricsReceived 0 1665602450
.dispatcher1.metricsBlackholed 0 1665602450
.dispatcher1.metricsDiscarded 0 1665602450
.dispatcher1.wallTime_us 7 1665602450

I'm leaning a bit more into the rewrite option, but haven't tested it out yet

grobian commented 1 year ago

I had hoped that the metrics would be sanitised, hence the .. I think with current code, you can't do it other than with a rewrite rule. If that is too limited, I'll have to add some syntax to allow you to have no prefix.

ssko1 commented 1 year ago

I did some finagling and found that the following configuration

statistics
    # Every 10 seconds is required
    submit every 10 seconds
    prefix with foo
    ;

rewrite ^foo\.(.*) into \1;

match *
    send to forwarder
    stop
    ;

works. I don't see an issue with this approach, do you have any feedback? The "every 10 seconds" rule is important.

grobian commented 1 year ago

Nope, this should do it just fine.

ssko1 commented 1 year ago

Thanks for your help! I appreciate the feedback and quick response.