Search in sources :

Example 1 with StaticSubstitutionConfig

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"));
}
Also used : FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) HashMap(java.util.HashMap) InternalEvent(com.nextdoor.bender.InternalEvent) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) FieldSubstitution(com.nextdoor.bender.operation.substitution.field.FieldSubstitution) StaticSubstitution(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution) MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) Test(org.junit.Test)

Example 2 with StaticSubstitutionConfig

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"));
}
Also used : FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) HashMap(java.util.HashMap) InternalEvent(com.nextdoor.bender.InternalEvent) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) Test(org.junit.Test)

Example 3 with StaticSubstitutionConfig

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);
}
Also used : StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) GelfOperationConfig(com.nextdoor.bender.operation.gelf.GelfOperationConfig) GelfOperation(com.nextdoor.bender.operation.gelf.GelfOperation) ArrayList(java.util.ArrayList) GelfOperationFactory(com.nextdoor.bender.operation.gelf.GelfOperationFactory) SubstitutionConfig(com.nextdoor.bender.operation.substitution.SubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) Test(org.junit.Test)

Example 4 with StaticSubstitutionConfig

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;
}
Also used : StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) Substitution(com.nextdoor.bender.operation.substitution.Substitution) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) ArrayList(java.util.ArrayList) SubstitutionConfig(com.nextdoor.bender.operation.substitution.SubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) SubstitutionFactoryFactory(com.nextdoor.bender.operation.substitution.SubstitutionFactoryFactory)

Aggregations

FieldSubstitutionConfig (com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig)4 StaticSubstitutionConfig (com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig)4 Test (org.junit.Test)3 InternalEvent (com.nextdoor.bender.InternalEvent)2 SubstitutionConfig (com.nextdoor.bender.operation.substitution.SubstitutionConfig)2 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GelfOperation (com.nextdoor.bender.operation.gelf.GelfOperation)1 GelfOperationConfig (com.nextdoor.bender.operation.gelf.GelfOperationConfig)1 GelfOperationFactory (com.nextdoor.bender.operation.gelf.GelfOperationFactory)1 Substitution (com.nextdoor.bender.operation.substitution.Substitution)1 SubstitutionFactoryFactory (com.nextdoor.bender.operation.substitution.SubstitutionFactoryFactory)1 ContextSubstitution (com.nextdoor.bender.operation.substitution.context.ContextSubstitution)1 FieldSubstitution (com.nextdoor.bender.operation.substitution.field.FieldSubstitution)1 MetadataSubstitution (com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution)1 RegexSubstitution (com.nextdoor.bender.operation.substitution.regex.RegexSubstitution)1 StaticSubstitution (com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution)1