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

Invert "add beats prefix" option (#5537) #5542

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public class Beats2Codec extends AbstractCodec {
private static final Logger LOG = LoggerFactory.getLogger(Beats2Codec.class);
private static final String MAP_KEY_SEPARATOR = "_";
private static final String BEATS_UNKNOWN = "unknown";
private static final String CK_BEATS_PREFIX = "beats_prefix";
private static final String CK_NO_BEATS_PREFIX = "no_beats_prefix";

private final ObjectMapper objectMapper;
private final boolean useBeatPrefix;
private final boolean noBeatsPrefix;

@Inject
public Beats2Codec(@Assisted Configuration configuration, ObjectMapper objectMapper) {
super(configuration);

this.useBeatPrefix = configuration.getBoolean(CK_BEATS_PREFIX, false);
this.noBeatsPrefix = configuration.getBoolean(CK_NO_BEATS_PREFIX, false);
this.objectMapper = requireNonNull(objectMapper);
}

Expand All @@ -79,7 +79,7 @@ public Message decode(@Nonnull RawMessage rawMessage) {

private Message parseEvent(JsonNode event) {
final String beatsType = event.path("@metadata").path("beat").asText("beat");
final String rootPath = useBeatPrefix ? beatsType : "";
final String rootPath = noBeatsPrefix ? "" : beatsType;
final String message = event.path("message").asText("-");
final String timestampField = event.path("@timestamp").asText();
final DateTime timestamp = Tools.dateTimeFromString(timestampField);
Expand Down Expand Up @@ -158,10 +158,10 @@ public ConfigurationRequest getRequestedConfiguration() {
final ConfigurationRequest configurationRequest = super.getRequestedConfiguration();

configurationRequest.addField(new BooleanField(
CK_BEATS_PREFIX,
"Add Beats type as prefix",
CK_NO_BEATS_PREFIX,
"Do not add Beats type as prefix",
false,
"Use the Beats type as prefix for each field, e. g. \"filebeat_source\"."
"Do not prefix each field with the Beats type, e. g. \"source\" -> \"filebeat_source\"."
));

return configurationRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Beats2CodecTest {

@Before
public void setUp() throws Exception {
configuration = new Configuration(Collections.singletonMap("beats_prefix", true));
configuration = new Configuration(Collections.singletonMap("no_beats_prefix", false));
codec = new Beats2Codec(configuration, objectMapper);
}

Expand All @@ -58,7 +58,7 @@ public void decodeReturnsNullIfPayloadCouldNotBeDecoded() throws Exception {

@Test
public void decodeMessagesHandlesFilebeatMessagesWithoutPrefix() throws Exception {
configuration = new Configuration(Collections.singletonMap("beats_prefix", false));
configuration = new Configuration(Collections.singletonMap("no_beats_prefix", true));
codec = new Beats2Codec(configuration, objectMapper);

final Message message = codec.decode(messageFromJson("filebeat.json"));
Expand Down