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

415 issue complete the funcionality of value schema file serializer #416

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
1 change: 1 addition & 0 deletions docs/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
# [Additional information](additional-information.md)
- [Contributing](contributing.md)
- [Release notes](release-notes.md)
- [Debugging](debugging.md)
32 changes: 32 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Debuging

This guide helps you debug KLoadGen in plugin mode with an IDE.

## Using IntelliJ IDEA

- Create a remote JVM configuration, should look like this:

![debug-configuration.png](images%2Fdebug-configuration.png)

- Now copy the Command line argument.

## - Windows

Open the file: `apache-jmeter-<version>\bin\jmeter.bat` whit any editor and paste the command on this 2 lines:

![debug-jmeter-bat.png](images%2Fdebug-jmeter-bat.png)


## - MacOS

Open the file: `apache-jmeter-<version>\bin\jmeter.sh` whit any editor and paste the command on this line:

![debug-jmeter-sh.png](images%2Fdebug-jmeter-sh.png)


## While Debuging

Now you can debug while you ejecute Jmeter.

Remember to create a new `kloadgen-<version>.jar` file and move it to Jmeter files, to apply
the changes you made in the code.
4 changes: 3 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Now that you know what KLoadGen is and that you are familiar with its components

You will need these tools to start using the plugin:

- JDK/JRE 11+
- JDK/JRE 11+
- (17 recommended)
- JMeter 5.4+
- (5.6.2 recommended)
- Maven

## Quickstart
Expand Down
Binary file added docs/images/debug-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/debug-jmeter-bat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/debug-jmeter-sh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>kloadgen</artifactId>

<version>5.6.8</version>
<version>5.6.9</version>

<name>KLoadGen</name>
<description>Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial
Expand Down Expand Up @@ -301,6 +301,17 @@
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
<developer>
<id>RobertoSngular</id>
<name>Roberto Riveira Veiga</name>
<email>[email protected]</email>
<organization>Sngular</organization>
<organizationUrl>https://www.sngular.com</organizationUrl>
<roles>
<role>Trainee Backend Developer</role>
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
</developers>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public SchemaRegistryConfigElementBeanInfo() {

super(SchemaRegistryConfigElement.class);

createPropertyGroup("schema_registry_config", new String[]{SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME, SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES,
SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL});
createPropertyGroup("schema_registry_config", new String[]{SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME,
SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES, SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL});

final PropertyDescriptor schemaRegistryName = property(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME);
schemaRegistryName.setPropertyEditorClass(SchemaRegistryNamePropertyEditor.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sngular.kloadgen.extractor;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -35,9 +34,8 @@ public static List<FieldValueMapping> flatPropertiesList(final ParsedSchema pars
return ExtractorFactory.getExtractor(parserSchema.schemaType()).processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
}

public static List<String> schemaTypesList(final File schemaFile, final String schemaType, final String registry) throws IOException {
return ExtractorFactory.getExtractor(schemaType).getSchemaNameList(readLineByLine(schemaFile.getPath()),
ExtractorFactory.getSchemaRegistry(registry));
public static String readSchemaFile(final String filePath) throws IOException {
return readLineByLine(filePath);
}

private static String readLineByLine(final String filePath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;

import com.sngular.kloadgen.common.SchemaRegistryEnum;
Expand Down Expand Up @@ -53,14 +52,6 @@ public static ExtractorRegistry getExtractor(final String schemaType) {
}
}

public static SchemaRegistryEnum getSchemaRegistry(final String schemaRegistryEnum) {
if (schemaRegistryEnum != null && EnumUtils.isValidEnum(SchemaRegistryEnum.class, schemaRegistryEnum.toUpperCase())) {
return SchemaRegistryEnum.valueOf(schemaRegistryEnum.toUpperCase());
} else {
throw new KLoadGenException(String.format("Schema Registry type not supported %s", schemaRegistryEnum));
}
}

public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final String subjectName) {
final Properties properties = JMeterContextService.getContext().getProperties();
final var schemaParsed = JMeterHelper.getParsedSchema(subjectName, properties);
Expand All @@ -72,14 +63,12 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
final SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());

final Object schema;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you want to go back with this change?

if (Objects.nonNull(registryName)) {
//TODO change parser
schema = switch (schemaRegistryEnum) {
case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema();
case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema();
};
attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum));
}
//TODO change parser
schema = switch (schemaRegistryEnum) {
case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema();
case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema();
};
attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum));
return Pair.of(schemaType, attributeList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public interface ExtractorRegistry<T> {
List<FieldValueMapping> processSchema(final T schema, SchemaRegistryEnum registry);

Object processSchema(final String fileContent);

List<String> getSchemaNameList(final String schema, SchemaRegistryEnum registryEnum);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.avro.AvroSchema;

public class AvroExtractor implements ExtractorRegistry<Object> {

private static Map<SchemaRegistryEnum, Extractor> schemaRegistryMap = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO,
new AvroApicurioExtractor());
private static final Map<SchemaRegistryEnum, Extractor> SCHEMA_REGISTRY_MAP = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO,
new AvroApicurioExtractor());

public final List<FieldValueMapping> processSchema(final Object schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).processSchema(schema);
return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schema);
}

public final ParsedSchema processSchema(final String fileContent) {
return new AvroSchema(fileContent);
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).getSchemaNameList(schema);
return SCHEMA_REGISTRY_MAP.get(registryEnum).getSchemaNameList(schema);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

public abstract class AbstractJsonExtractor {

private final JSONSchemaParser jsonSchemaParser = new JSONSchemaParser();
private static final JSONSchemaParser JSON_SCHEMA_PARSER = new JSONSchemaParser();

protected final JSONSchemaParser getSchemaParser() {
return jsonSchemaParser;
return JSON_SCHEMA_PARSER;
}

private static String extractFieldName(final String fieldName) {
Expand Down Expand Up @@ -90,9 +90,9 @@ public final List<FieldValueMapping> processField(final Field innerField, final
completeFieldList.add(builder.build());
} else if (innerField instanceof StringField) {
final FieldValueMapping.FieldValueMappingBuilder builder = FieldValueMapping
.builder()
.fieldName(innerField.getName())
.fieldType(innerField.getType());
.builder()
.fieldName(innerField.getName())
.fieldType(innerField.getType());

addConstraint(builder, ConstraintTypeEnum.REGEX, ((StringField) innerField).getRegex());
addConstraint(builder, ConstraintTypeEnum.MAXIMUM_VALUE, getSafeNumberAsString(((StringField) innerField).getMaxlength()));
Expand Down Expand Up @@ -169,9 +169,9 @@ private List<FieldValueMapping> extractArrayInternalFields(

@NotNull
private static String calculateFieldType(final String breadCrumb, final Field value) {
return value.getType()
return value.getType()
+ SchemaExtractorUtil.ARRAY_TYPE_POSTFIX
+ ((StringUtils.isNotEmpty(breadCrumb)
+ ((StringUtils.isNotEmpty(breadCrumb)
&& breadCrumb.endsWith("[]")) ? SchemaExtractorUtil.ARRAY_TYPE_POSTFIX
: (StringUtils.isNotEmpty(breadCrumb)
&& breadCrumb.endsWith("[:]")) ? "-map"
Expand Down Expand Up @@ -207,9 +207,9 @@ private List<FieldValueMapping> extractMapInternalFields(

@NotNull
private static String getFieldType(final String breadCrumb, final Field value) {
return value.getType()
+ "-map"
+ ((StringUtils.isNotEmpty(breadCrumb)
return value.getType()
+ "-map"
+ ((StringUtils.isNotEmpty(breadCrumb)
&& breadCrumb.endsWith("[:]")) ? "-map"
: (StringUtils.isNotEmpty(breadCrumb)
&& breadCrumb.endsWith("[]")) ? SchemaExtractorUtil.ARRAY_TYPE_POSTFIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.sngular.kloadgen.model.json.Field;
import com.sngular.kloadgen.model.json.Schema;

public class JsonDefaultExtractor extends AbstractJsonExtractor implements Extractor<org.everit.json.schema.Schema> {
public class JsonDefaultExtractor extends AbstractJsonExtractor implements Extractor<String> {

@Override
public final List<FieldValueMapping> processSchema(final org.everit.json.schema.Schema schema) {
public final List<FieldValueMapping> processSchema(final String schema) {

final Schema parsed = getSchemaParser().parse(schema.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.json.JsonSchema;


public class JsonExtractor implements ExtractorRegistry<Object> {
Expand All @@ -15,7 +17,11 @@ public class JsonExtractor implements ExtractorRegistry<Object> {
SchemaRegistryEnum.APICURIO, new JsonDefaultExtractor());

public final List<FieldValueMapping> processSchema(final Object schemaReceived, final SchemaRegistryEnum registryEnum) {
return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived);
return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived.toString());
}

public final ParsedSchema processSchema(final String fileContent) {
return new JsonSchema(fileContent);
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema;

public class ProtobuffExtractor implements ExtractorRegistry<Object> {

Expand All @@ -25,6 +27,10 @@ public final List<FieldValueMapping> processSchema(final Object schemaReceived,
return resultSchema;
}

public final ParsedSchema processSchema(final String fileContent) {
return new ProtobufSchema(fileContent);
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
return SCHEMA_REGISTRY_MAP.get(registryEnum).getSchemaNameList(schema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ public boolean isOptionalFieldAccordingToSchema(final String completeFieldName,
return isOptionalField(subSchema);
}

@Override
public Object getRootNode(final String rootNode) {
public final Object getRootNode(final String rootNode) {
return entity.get(rootNode);
}

Expand Down
Loading
Loading