Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request header field Content-Type is not allowed by Access-Control-Allow-Headers. #187

Closed
Telmo opened this issue Jun 24, 2013 · 10 comments
Closed

Comments

@Telmo
Copy link

Telmo commented Jun 24, 2013

I have followed the installation instructions, I have updated config.js and used the fqdn of my ES system. I've updated the jquery.flot.time.js file since I was getting the error about it, but still I am getting no hits in the default dashboard.

going to http://myeshost:9200/logstash-2013.06.24/_search shows all the logs entries as expected.

Is there anything obvious that I am missing?

@Telmo
Copy link
Author

Telmo commented Jun 24, 2013

this query copies and pasted from the dashboard returns the correct data, but nothing is displayed:

curl -XGET http://myeshost:9200/logstash-2013.06.24/_search?pretty -d'
{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*"
        }
      },
      "filter": {
        "range": {
          "@timestamp": {
            "from": "2013-06-24T16:23:36.055Z",
            "to": "2013-06-24T22:23:36.055Z"
          }
        }
      }
    }
  },
  "highlight": {
    "fields": {},
    "fragment_size": 2147483647,
    "pre_tags": [
      "@start-highlight@"
    ],
    "post_tags": [
      "@end-highlight@"
    ]
  },
  "size": 500,
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}'

@Telmo
Copy link
Author

Telmo commented Jun 24, 2013

I think I've found the issue. I keep getting this in the javascript console:

XMLHttpRequest cannot load http://myeshost:9200/logstash-2013.06.22/_search. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

@Telmo
Copy link
Author

Telmo commented Jun 24, 2013

I have been able to reproduce this issue with Apache and Ngnix, and firefox and chrome as browsers

I've added the following to the location /

  location / {
    add_header 'Access-Control-Allow-Origin' 'http://<myeshost>:9200 http://<myeshost-cname>:9200';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'Content-Type,Accept';

per http://adminsgoodies.com/cross-origin-resource-sharing-cors-with-nginx-chrome/

But didn't solve the issue, if interested this are all the javascript errors I get:

TypeError: Property 'scrollTo' of object [object global] is not a function
    at g (http://<myeshost>/common/lib/angular.min.js:29:217)
    at Object.e.$eval (http://<myeshost>/common/lib/angular.min.js:87:39)
    at Object.e.$digest (http://<myeshost>/common/lib/angular.min.js:84:474)
    at Object.e.$apply (http://<myeshost>/common/lib/angular.min.js:87:198)
    at http://<myeshost>/common/lib/angular.min.js:15:270
    at Object.d [as invoke] (http://<myeshost>/common/lib/angular.min.js:26:272)
    at Object.rb [as bootstrap] (http://<myeshost>/common/lib/angular.min.js:15:191)
    at HTMLDocument.<anonymous> (http://<myeshost>/js/app.js:64:13)
    at k (http://<myeshost>/common/lib/jquery-1.8.0.min.js:2:16961)
    at Object.l.add [as done] (http://<myeshost>/common/lib/jquery-1.8.0.min.js:2:17246) angular.min.js:60
(anonymous function) angular.min.js:60
(anonymous function) angular.min.js:50
e.$digest angular.min.js:84
e.$apply angular.min.js:87
(anonymous function) angular.min.js:15
d angular.min.js:26
rb angular.min.js:15
(anonymous function) app.js:64
k jquery-1.8.0.min.js:2
l.add jquery-1.8.0.min.js:2
p.fn.p.ready jquery-1.8.0.min.js:2
(anonymous function) app.js:62
x LAB.min.js:5
U LAB.min.js:5
S.j LAB.min.js:5
I LAB.min.js:5
(anonymous function) LAB.min.js:5
a.onload.a.onreadystatechange
OPTIONS http://<myeshost>:9200/logstash-2013.06.24/_search Request header field Content-Type is not allowed by Access-Control-Allow-Headers. angular.min.js:98
(anonymous function) angular.min.js:98
n angular.min.js:95
l angular.min.js:93
l.(anonymous function) angular.min.js:96
ejs.client.post elastic-angular-client.js:52
doSearch elastic.min.js:4
$scope.get_data module.js:156
$scope.set_time module.js:257
(anonymous function) module.js:75
(anonymous function) services.js:65
e.$broadcast angular.min.js:88
broadcast services.js:27
(anonymous function) module.js:220
i angular.min.js:76
(anonymous function) angular.min.js:76
e.$eval angular.min.js:87
e.$digest angular.min.js:84
e.$apply angular.min.js:87
e angular.min.js:94
p angular.min.js:97
v.onreadystatechange
XMLHttpRequest cannot load http://<myeshost>:9200/logstash-2013.06.24/_search. Request header field Content-Type is not allowed by Access-Control-Allow-Headers. 

hope that helps to narrow down the issue

@Telmo
Copy link
Author

Telmo commented Jun 27, 2013

debug info from firefox shows a different issue:

Error: results.hits is undefined $scope.get_data/<@https://myeshost/panels/table/module.js:176
 Nc/e/j.promise.then/i@https://myeshost/common/lib/angular.min.js:76 
Nc/g/<.then/<@https://myeshost/common/lib/angular.min.js:76 
e.prototype.$eval@https://myeshost/common/lib/angular.min.js:87 
e.prototype.$digest@https://myeshost/common/lib/angular.min.js:84 
e.prototype.$apply@https://myeshost/common/lib/angular.min.js:87
e@https://myeshost/common/lib/angular.min.js:94 
p@https://myeshost/common/lib/angular.min.js:97
Xc/</v.onreadystatechange@https://myeshost/common/lib/angular.min.js:98

Here is my config.js

/*

elasticsearch:  URL to your elasticsearch server. You almost certainly don't
                want 'http://localhost:9200' here. Even if Kibana and ES are on
                the same host
kibana_index:   The default ES index to use for storing Kibana specific object
                such as stored dashboards
modules:        Panel modules to load. In the future these will be inferred
                from your initial dashboard, though if you share dashboards you
                will probably need to list them all here

If you need to configure the default dashboard, please see dashboards/default

*/
var config = new Settings(
{
  // By default this will attempt to reach ES at the same host you have
  // elasticsearch installed on. You probably want to set it to the FQDN of your
  // elasticsearch host
  elasticsearch:    "http://"+window.location.hostname+":9200",
//  elasticsearch:    "http://myeshost:9200",
//   elasticsearch: 'http://localhost:9200',
  kibana_index:     "kibana-int",
  modules:          ['histogram','map','pie','table','stringquery','sort',
                    'timepicker','text','fields','hits','dashcontrol',
                    'column','derivequeries','trends','bettermap'],
  }
);

I can access elasticsearch from my browser and I can see the elasticsearch data. I can also see it with Kibana2

I have enable/disabled the other options for eleasticsearch with the same result.

@Telmo
Copy link
Author

Telmo commented Jul 1, 2013

inspecting the header shows that its "correct"

HTTP/1.1 200 OK
Date: Mon, 01 Jul 2013 22:28:36 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Mon, 24 Jun 2013 22:56:55 GMT
ETag: "6d1cb-9cf-4dfee5438fbec"
Accept-Ranges: bytes
Content-Length: 2511
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Connection: close
Content-Type: text/html; charset=UTF-8

I am really out of places to look

@rashidkpc
Copy link
Contributor

I'm a bit puzzled why you're getting back Apache as the server with a curl request to http://myeshost:9200/logstash-2013.06.22/_search. Are you sure you're curling the right thing? You don't mention anything about using a proxy?

@Telmo
Copy link
Author

Telmo commented Jul 8, 2013

that't the header for the Kibana instance running under apache

The one for the elasticsearch query looks like:

Request URL:http://<myeshost>:9200/logstash-2013.07.08/_search
Request Method:GET
Status Code:200 OK
-- Request Headers
GET /logstash-2013.07.08/_search HTTP/1.1
Host: <myeshost>:9200
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
-- Response Header
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
Content-Length: 2801

a sample of the data returned:

{
took: 5,
timed_out: false,
_shards: {
total: 5,
successful: 5,
failed: 0
},
hits: {
total: 11,
max_score: 1,
hits: [
{
_index: "logstash-2013.07.08",
_type: "fluentd",
_id: "Bf2nDdlpS9mZdKU8wJLDgg",
_score: 1,
_source: {
host: "edited",
ident: "ntpd",
pid: "1749",
message: "synchronized to edited, stratum 3",
tag: "system",
@timestamp: "2013-07-08T15:52:33+00:00"
}
},

@Telmo
Copy link
Author

Telmo commented Jul 8, 2013

I am running Kibana and elasticsearch both on CentOS 6.1
Apache version is 2.2.15
ElasticSearch version is 0.19.5
Kibana was a pull from Master on Jun 24th

@rashidkpc
Copy link
Contributor

Ah, that would be why. Elasticsearch 0.19.5 does not supply the right CORS headers. I believe 0.19.12 does, but really you should upgrade to at least 0.20.6 which is the latest logstash supports. If you move to the elasticsearch_http output you can use 0.90.2 which comes with huge memory improvements

@Telmo
Copy link
Author

Telmo commented Jul 9, 2013

that was the issue, you may want to specify some minimun requirements somewhere, this thing almost drove me mad ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants