-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
861a098
commit a93faa7
Showing
5 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...2-server/src/main/java/org/graylog/plugins/formatting/units/fields/FieldUnitObtainer.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,35 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog.plugins.formatting.units.fields; | ||
|
||
import org.graylog.plugins.formatting.units.model.UnitView; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class FieldUnitObtainer { | ||
|
||
private final List<FieldUnitObtainingMethod> prioritizedMethodList = List.of(new HardcodedFieldUnitObtainingMethod()); | ||
|
||
public Optional<UnitView> obtainUnit(final String fieldName) { | ||
return prioritizedMethodList.stream() | ||
.map(fieldUnitObtainingMethod -> fieldUnitObtainingMethod.obtainUnit(fieldName)) | ||
.filter(Optional::isPresent) | ||
.findFirst() | ||
.orElse(Optional.empty()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...r/src/main/java/org/graylog/plugins/formatting/units/fields/FieldUnitObtainingMethod.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,26 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog.plugins.formatting.units.fields; | ||
|
||
import org.graylog.plugins.formatting.units.model.UnitView; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FieldUnitObtainingMethod { | ||
|
||
Optional<UnitView> obtainUnit(final String fieldName); | ||
} |
44 changes: 44 additions & 0 deletions
44
...n/java/org/graylog/plugins/formatting/units/fields/HardcodedFieldUnitObtainingMethod.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,44 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog.plugins.formatting.units.fields; | ||
|
||
import org.graylog.plugins.formatting.units.model.BaseUnitView; | ||
import org.graylog.plugins.formatting.units.model.Conversion; | ||
import org.graylog.plugins.formatting.units.model.DerivedUnit; | ||
import org.graylog.plugins.formatting.units.model.UnitView; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.graylog.plugins.formatting.units.model.Conversion.ConversionAction.DIVIDE; | ||
import static org.graylog2.plugin.Message.FIELD_GL2_ACCOUNTED_MESSAGE_SIZE; | ||
import static org.graylog2.plugin.Message.FIELD_GL2_PROCESSING_DURATION_MS; | ||
|
||
public class HardcodedFieldUnitObtainingMethod implements FieldUnitObtainingMethod { | ||
|
||
@Override | ||
public Optional<UnitView> obtainUnit(final String fieldName) { | ||
//TODO: complete list | ||
//TODO: take units from DB instead of creating from scratch | ||
return switch (fieldName) { | ||
case FIELD_GL2_PROCESSING_DURATION_MS -> | ||
Optional.of(new DerivedUnit("ms", "millisecond", "time", new Conversion(1000, DIVIDE))); | ||
case FIELD_GL2_ACCOUNTED_MESSAGE_SIZE -> Optional.of(new BaseUnitView("b", "byte", "size")); | ||
default -> Optional.empty(); | ||
}; | ||
|
||
} | ||
} |
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