-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
health api: expose
GET /_health_report
with pipelines/*/up probe
- Loading branch information
Showing
20 changed files
with
949 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
require "logstash/api/commands/base" | ||
require_relative "hot_threads_reporter" | ||
|
||
module LogStash | ||
module Api | ||
module Commands | ||
class HealthReport < Commands::Base | ||
|
||
def all(selected_fields = []) | ||
service.agent.health_observer.report | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module LogStash | ||
module Api | ||
module Modules | ||
class HealthReport < ::LogStash::Api::Modules::Base | ||
|
||
get "/" do | ||
payload = health_report.all.then do |health_report_pojo| | ||
# The app_helper needs a ruby-hash. | ||
# Manually creating a map of properties works around the issue. | ||
{ | ||
status: health_report_pojo.status, | ||
symptom: health_report_pojo.symptom, | ||
indicators: health_report_pojo.indicators, | ||
} | ||
end | ||
|
||
respond_with(payload, {exclude_default_metadata: true}) | ||
end | ||
|
||
private | ||
|
||
def health_report | ||
@health_report ||= factory.build(:health_report) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
logstash-core/src/main/java/org/logstash/health/ApiHealthReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.logstash.health; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
@JsonSerialize(using = ApiHealthReport.JsonSerializer.class) | ||
public class ApiHealthReport { | ||
private final MultiIndicator.Report delegate; | ||
|
||
public ApiHealthReport(final MultiIndicator.Report delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
public Status getStatus() { | ||
return delegate.status(); | ||
} | ||
|
||
public String getSymptom() { | ||
return delegate.symptom(); | ||
} | ||
|
||
public Map<String, Indicator.Report> getIndicators() { | ||
return delegate.indicators(); | ||
} | ||
|
||
public static class JsonSerializer extends com.fasterxml.jackson.databind.JsonSerializer<ApiHealthReport> { | ||
@Override | ||
public void serialize(final ApiHealthReport apiHealthReport, | ||
final JsonGenerator jsonGenerator, | ||
final SerializerProvider serializerProvider) throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeObjectField("status", apiHealthReport.getStatus()); | ||
jsonGenerator.writeObjectField("symptom", apiHealthReport.getSymptom()); | ||
jsonGenerator.writeObjectField("indicators", apiHealthReport.getIndicators()); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
logstash-core/src/main/java/org/logstash/health/Diagnosis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.logstash.health; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.function.UnaryOperator; | ||
|
||
@JsonSerialize(using = Diagnosis.JsonSerializer.class) | ||
public final class Diagnosis { | ||
final String cause; | ||
final String action; | ||
final String helpUrl; | ||
|
||
private Diagnosis(final Builder builder) { | ||
this.cause = builder.cause; | ||
this.action = builder.action; | ||
this.helpUrl = builder.helpUrl; | ||
} | ||
|
||
String cause() { | ||
return cause; | ||
} | ||
String action() { | ||
return action; | ||
} | ||
String helpUrl() { | ||
return helpUrl; | ||
} | ||
|
||
static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private String cause; | ||
private String action; | ||
private String helpUrl; | ||
public synchronized Builder setCause(final String cause) { | ||
assert Objects.isNull(this.cause) : "cause has already been set"; | ||
this.cause = cause; | ||
return this; | ||
} | ||
public synchronized Builder setAction(final String action) { | ||
assert Objects.isNull(this.action) : "action has already been set"; | ||
this.action = action; | ||
return this; | ||
} | ||
public synchronized Builder setHelpUrl(final String helpUrl) { | ||
assert Objects.isNull(this.helpUrl) : "helpUrl has already been set"; | ||
this.helpUrl = helpUrl; | ||
return this; | ||
} | ||
public synchronized Builder configure(final UnaryOperator<Builder> configurator) { | ||
return configurator.apply(this); | ||
} | ||
public synchronized Diagnosis build() { | ||
return new Diagnosis(this); | ||
} | ||
} | ||
|
||
public static class JsonSerializer extends com.fasterxml.jackson.databind.JsonSerializer<Diagnosis> { | ||
@Override | ||
public void serialize(Diagnosis diagnosis, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("cause", diagnosis.cause()); | ||
jsonGenerator.writeStringField("action", diagnosis.action()); | ||
jsonGenerator.writeStringField("help_url", diagnosis.helpUrl()); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.