elastic/elasticsearch-metrics-reporter-java

400 On Posting to ES

Closed this issue · 12 comments

Hi,

I'm trying this out with a Spring Boot app and I have everything wired up, but I get a 400 when the reporter attempts to post to ES. I can see the template gets created on first start, but the index never gets created on first or subsequent starts. I have turned on DEBUG for ES and I am getting nothing to go on in the logs. I have also tried creating the default index "metrics" manually with no luck. Any tips or things I could try here? Latest versions of everything available. You get me going here so I can see the moving pieces and then I can bring to bear some resources on getting Kibana and custom dashboards a la Marvel clones up and running. Deal?

Thank you in advance,

Jim

hey there,

against what elasticsearch version are you running this?

Can you also post your the java code where you are setting up the configuration?

I lifted it exactly from the documentation with the exception that I'm only running one ES instance:

final MetricRegistry registry = new MetricRegistry();
ElasticsearchReporter reporter = ElasticsearchReporter.forRegistry(registry)
.hosts("localhost:9200")
.build();
reporter.start(60, TimeUnit.SECONDS);

Running against ES 1.1.0.

weird.. every error to connect to elasticsearch is supposed to trigger an exception, which in turn is logged... I should add some TRACE/DEBUG log statements for the good case, thought.

However, maybe you can just fire up a netcat or sth on port 9200 and see if any data gets sent to ES?

Also you could call reporter.report() manually to force an execution of sending stats

It is connecting, creating the template if it doesn't exist, but the index isn't created and when the reporter attempts to post is when I am seeing the 400. I'll do some tracing and see what the document that is being posted actually looks like. In the meantime, should I expect that the index is being created for me or do I need to create?

thats created for you on indexation of the first document (the reason for the index template)

does this test work for you?

    @Test
    public void foo() throws Exception {
        MetricRegistry registry = new MetricRegistry();
        registry.counter("foo").inc(20);

        ElasticsearchReporter reporter = ElasticsearchReporter.forRegistry(registry)
                .hosts("localhost:9200")
                .build();
        reporter.start(5, TimeUnit.SECONDS);

        sleep(8000);

        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName);
        TransportClient client = new TransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
        SearchResponse searchResponse = client.prepareSearch().get();
        assertThat(searchResponse.getHits().getTotalHits(), is(1l));
    }

anything different to your setup?

Yes, I got that test to work. Must be something with the way spring is wiring things up. Thank you for your help! I'll do some work on this and get back to you.

Yes, please keep me updated... You were telling you got a 400 error back, this usually means there is a client error (the client being the metrics reporter), so I would love to know whats going on.

Did you ever figure out what caused this, @jrwyatt? I suspect that we have the same problem.

@nilsga are you also running on springboot?

Can one of you maybe publish some sample app with the metrics reporter so I could take a look at that? Sounds really weird and I would be interested to dive in.

No, I'm not using springboot. But I don't think it was an error with the reporter. It was just that the report method only catches IOException, so if some other exception occur (in our case, one of the metrics threw an NPE), it is just swallowed silently as an uncaught exception in the scheduled thread and is not logged anywhere.