diff --git a/.gitignore b/.gitignore index 387a966..b6c7a38 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /dist/ coverage.html coverage.out + check_elasticsearch* +TODO* diff --git a/internal/client/client.go b/internal/client/client.go index 4df4f3c..a9d81af 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -32,7 +32,7 @@ func NewClient(urls []*url.URL, rt http.RoundTripper) *Client { // Perform wraps the Client's HTTP call so that we can try all given // nodes in case one node is not reachable func (c *Client) Perform(req *http.Request) (*http.Response, error) { - originalPath := req.URL.String() + originalPath := req.URL.Path for _, hostURL := range c.URLs { // For each URL take the request, prepend the URL diff --git a/internal/elasticsearch/api.go b/internal/elasticsearch/api.go index 2ef2b84..7619f7e 100644 --- a/internal/elasticsearch/api.go +++ b/internal/elasticsearch/api.go @@ -27,7 +27,7 @@ type HealthResponse struct { type SearchResponse struct { Hits SearchHits `json:"hits"` Error struct { - RootCause []ErrorRootCause `json:"root_cause"` + RootCause []ErrorRootCause `json:"root_cause,omitempty"` } } diff --git a/testdata/docker-compose.yml b/testdata/docker-compose.yml new file mode 100644 index 0000000..e1a774a --- /dev/null +++ b/testdata/docker-compose.yml @@ -0,0 +1,41 @@ +--- +services: + es01: + image: docker.io/elasticsearch:9.3.0 + container_name: es01 + environment: + - node.name=es01 + - cluster.name=check + - discovery.seed_hosts=es02,es03 + - cluster.initial_master_nodes=es01,es02,es03 + - bootstrap.memory_lock=true + - xpack.security.enabled=false + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ports: + - 9201:9200 + es02: + image: docker.io/elasticsearch:9.3.0 + container_name: es02 + environment: + - node.name=es02 + - cluster.name=check + - discovery.seed_hosts=es01,es03 + - cluster.initial_master_nodes=es01,es02,es03 + - bootstrap.memory_lock=true + - xpack.security.enabled=false + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ports: + - 9202:9200 + es03: + image: docker.io/elasticsearch:9.3.0 + container_name: es03 + environment: + - node.name=es03 + - cluster.name=check + - discovery.seed_hosts=es01,es02 + - cluster.initial_master_nodes=es01,es02,es03 + - bootstrap.memory_lock=true + - xpack.security.enabled=false + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ports: + - 9203:9200 diff --git a/testdata/generate.sh b/testdata/generate.sh new file mode 100644 index 0000000..de1d0ff --- /dev/null +++ b/testdata/generate.sh @@ -0,0 +1,14 @@ +# Generate an example doc + +URL=http://localhost:9201 + +curl -X POST -H 'Content-Type: application/json' "${URL}/msg/_doc?pipeline=example-pipeline" -d '{ + "body": "Example", + "severityNumber": 4, + "resource": { + "service.name": "node1" + }, + "attributes": { + "team": "awesome" + } +}' diff --git a/testdata/init.sh b/testdata/init.sh new file mode 100644 index 0000000..9eacfc1 --- /dev/null +++ b/testdata/init.sh @@ -0,0 +1,20 @@ +# Setup an index and a pipeline + +URL=http://localhost:9201 + +curl -s -k -X PUT -H 'Content-Type: application/json' "${URL}/_ingest/pipeline/example-pipeline" -d' +{ + "description": "My optional pipeline description", + "processors": [ + { + "set": { + "description": "My optional processor description", + "field": "my-long-field", + "value": 10 + } + } + ] +} +' + +curl -s -k -X PUT -H 'Content-Type: application/json' "${URL}/msg"