use of com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig in project bender by Nextdoor.
the class NestedSubstitutionTest method testNestedNested.
@Test
public void testNestedNested() throws FieldNotFoundException {
/*
* Expected output {a={b={bar=1234, static=value}}, foo2=1234}
*/
/*
* Inner nest substitutions
*/
FieldSubstitutionConfig fieldSubConfig = new FieldSubstitutionConfig("bar", Arrays.asList("foo0", "foo1", "foo2"), false, true, true);
StaticSubstitutionConfig staticSubConfig = new StaticSubstitutionConfig("static", "value", true);
/*
* Substitutions in outer nest
*/
List<SubstitutionConfig> nscInner = Arrays.asList(fieldSubConfig, staticSubConfig);
NestedSubstitutionConfig nsfInner = new NestedSubstitutionConfig("b", nscInner, true);
/*
* Substitution
*/
NestedSubstitutionConfig nsfOuter = new NestedSubstitutionConfig("a", Arrays.asList(nsfInner), true);
NestedSubstitutionFactory subFactory = new NestedSubstitutionFactory();
subFactory.setConf(nsfOuter);
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo2", "1234");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
List<Substitution> sub = Arrays.asList(subFactory.newInstance());
SubstitutionOperation op = new SubstitutionOperation(sub);
op.perform(ievent);
Map<String, Object> expectedNest2 = new HashMap<String, Object>() {
{
put("bar", "1234");
put("static", "value");
}
};
Map<String, Object> expectedNest1 = new HashMap<String, Object>() {
{
put("b", expectedNest2);
}
};
assertEquals(expectedNest1, devent.getField("a"));
assertEquals("1234", devent.getField("foo2"));
}
use of com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig in project bender by Nextdoor.
the class NestedSubstitutionTest method testBasicNested.
@Test
public void testBasicNested() throws FieldNotFoundException {
/*
* Substitutions in nest
*/
FieldSubstitutionConfig fieldSubConfig = new FieldSubstitutionConfig("bar", Arrays.asList("foo0", "foo1", "foo2"), false, true, true);
StaticSubstitutionConfig staticSubConfig = new StaticSubstitutionConfig("static", "value", true);
/*
* Nested substitution
*/
List<SubstitutionConfig> nsc = Arrays.asList(fieldSubConfig, staticSubConfig);
NestedSubstitutionFactory nsf = new NestedSubstitutionFactory();
nsf.setConf(new NestedSubstitutionConfig("a", nsc, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo2", "1234");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(Arrays.asList(nsf.newInstance()));
op.perform(ievent);
Map<String, Object> expectedNested = new HashMap<String, Object>() {
{
put("bar", "1234");
put("static", "value");
}
};
assertEquals(expectedNested, devent.getField("a"));
assertEquals("1234", devent.getField("foo2"));
}
use of com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig in project bender by Nextdoor.
the class GelfOperationFactoryTest method foo.
@Test
public void foo() {
GelfOperationConfig config = new GelfOperationConfig();
config.setSrcHostField(Arrays.asList("foo_host"));
config.setSrcShortMessageField(Arrays.asList("foo_short_message", "bar"));
config.setSrcFileField(Arrays.asList("filename"));
GelfOperationFactory factory = new GelfOperationFactory();
factory.setConf(config);
GelfOperation op = factory.newInstance();
List<SubstitutionConfig> actual = factory.getSubConfigs();
ArrayList<SubstitutionConfig> expected = new ArrayList<SubstitutionConfig>();
expected.add(new FieldSubstitutionConfig("host", Arrays.asList("foo_host"), false, true, true));
expected.add(new FieldSubstitutionConfig("file", Arrays.asList("filename"), false, false, false));
expected.add(new FieldSubstitutionConfig("short_message", Arrays.asList("foo_short_message", "bar"), false, true, true));
expected.add(new StaticSubstitutionConfig("version", "1.1", true));
Collections.sort(expected, Comparator.comparingInt(Object::hashCode));
Collections.sort(actual, Comparator.comparingInt(Object::hashCode));
assertEquals(expected, actual);
}
use of com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig in project bender by Nextdoor.
the class GelfOperationFactory method setConf.
@Override
public void setConf(AbstractConfig config) {
this.config = (GelfOperationConfig) config;
ArrayList<SubstitutionConfig> subConfigs = new ArrayList<SubstitutionConfig>();
subConfigs.add(new StaticSubstitutionConfig("version", "1.1", true));
if (this.config.getSrcHostField() != null) {
subConfigs.add(new FieldSubstitutionConfig("host", this.config.getSrcHostField(), false, true, true));
}
if (this.config.getSrcShortMessageField() != null) {
subConfigs.add(new FieldSubstitutionConfig("short_message", this.config.getSrcShortMessageField(), false, true, true));
}
if (this.config.getSrcFullMessageField() != null) {
subConfigs.add(new FieldSubstitutionConfig("full_message", this.config.getSrcFullMessageField(), false, false, true));
}
if (this.config.getSrcTimestampField() != null) {
subConfigs.add(new FieldSubstitutionConfig("timestamp", this.config.getSrcTimestampField(), false, false, true));
}
if (this.config.getSrcLevelField() != null) {
subConfigs.add(new FieldSubstitutionConfig("level", this.config.getSrcLevelField(), false, false, true));
}
if (this.config.getSrcFacilityField() != null) {
subConfigs.add(new FieldSubstitutionConfig("facility", this.config.getSrcFacilityField(), false, false, true));
}
if (this.config.getSrcLineNumberField() != null) {
subConfigs.add(new FieldSubstitutionConfig("line", this.config.getSrcLineNumberField(), false, false, true));
}
if (this.config.getSrcFileField() != null) {
subConfigs.add(new FieldSubstitutionConfig("file", this.config.getSrcFileField(), false, false, true));
}
List<Substitution> substitutions = new ArrayList<Substitution>(subConfigs.size());
SubstitutionFactoryFactory sff = new SubstitutionFactoryFactory();
for (SubstitutionConfig subConfig : subConfigs) {
try {
substitutions.add(sff.getFactory(subConfig).newInstance());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
this.substitutions = substitutions;
this.subConfigs = subConfigs;
}
Aggregations