Skip to content
Closed
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
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.benchmark.ingest;

import org.elasticsearch.index.VersionType;
import org.elasticsearch.ingest.IngestDocument;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Fork(1)
@Warmup(iterations = 3)
@Measurement(iterations = 5)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class FieldAccessBenchmark {

IngestDocument ingestDocument = createIngestDocument(4);

@Benchmark
public void dotNotationAccess(Blackhole blackhole) {
blackhole.consume(ingestDocument.getFieldValue("level1.level2.level3.level4", String.class));
}

@Benchmark
public void dottedFieldAccess(Blackhole blackhole) {
// printPaths(ingestDocument.getSource(), new ArrayList<>());
blackhole.consume(ingestDocument.getAllFieldValues("level1.level2.level3.level4", String.class));
}

@SuppressWarnings("unchecked")
private static void printPaths(Map<String, Object> source, ArrayList<String> path) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
path.add(entry.getKey());
if (entry.getValue() instanceof Map) {
printPaths((Map<String, Object>) entry.getValue(), path);
} else {
System.out.println(String.join("|", path));
}
path.removeLast();
}
}

public static IngestDocument createIngestDocument(int maxDepth) {
if (maxDepth < 1) {
throw new IllegalArgumentException("Depth must be at least 1");
}

// create a path with the given depth
StringBuilder path = new StringBuilder("level1");
for (int i = 2; i <= maxDepth; i++) {
path.append(".level").append(i);
}
Map<String, Object> source = new HashMap<>();
generatePermutations(source, path.toString(), 0);
return new IngestDocument("index", "id", 1L, "routing", VersionType.INTERNAL, source);
}

private static void generatePermutations(Map<String, Object> parentNode, String path, int startIndex) {
int nextDot = path.indexOf('.', startIndex);
if (nextDot > 0) {
// Consider the next dot as a path separator and generate paths recursively for the rest of the path
String key = path.substring(0, nextDot);
Map<String, Object> child = new HashMap<>();
parentNode.put(key, child);
generatePermutations(child, path.substring(nextDot + 1), 0);

// Consider the next dot as part of the path element's name
generatePermutations(parentNode, path, nextDot + 1);
} else {
parentNode.put(path, "value" + nextDot * path.length());
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it seems relevant to this PR to have changes to this file. Can you tidy this up, please?

Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.12.1
8.12.1
22 changes: 22 additions & 0 deletions modules/ingest-ecs/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

esplugin {
description = 'Ingest processor that applies ECS namespacing'
classname ='org.elasticsearch.ingest.ecs.EcsNamespacingPlugin'
}

restResources {
restApi {
include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest'
}
}

14 changes: 14 additions & 0 deletions modules/ingest-ecs/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module org.elasticsearch.ingest.ecs {
requires org.elasticsearch.base;
requires org.elasticsearch.server;
requires org.elasticsearch.xcontent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.ingest.ecs;

import org.elasticsearch.ingest.Processor;
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.Plugin;

import java.util.Map;

public class EcsNamespacingPlugin extends Plugin implements IngestPlugin {

@Override
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
return Map.of(EcsNamespacingProcessor.TYPE, new EcsNamespacingProcessor.Factory());
}
}
Loading