Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gaobinlong committed Aug 30, 2024
2 parents f518b2e + c11d275 commit 16d728b
Show file tree
Hide file tree
Showing 33 changed files with 1,898 additions and 118 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Workload Management] QueryGroup resource tracking framework changes ([#13897](https://github.com/opensearch-project/OpenSearch/pull/13897))
- Support filtering on a large list encoded by bitmap ([#14774](https://github.com/opensearch-project/OpenSearch/pull/14774))
- Add slice execution listeners to SearchOperationListener interface ([#15153](https://github.com/opensearch-project/OpenSearch/pull/15153))
- Make balanced shards allocator timebound ([#15239](https://github.com/opensearch-project/OpenSearch/pull/15239))
- Add allowlist setting for ingest-geoip and ingest-useragent ([#15325](https://github.com/opensearch-project/OpenSearch/pull/15325))
- Adding access to noSubMatches and noOverlappingMatches in Hyphenation ([#13895](https://github.com/opensearch-project/OpenSearch/pull/13895))
- Add support for index level max slice count setting for concurrent segment search ([#15336](https://github.com/opensearch-project/OpenSearch/pull/15336))
Expand All @@ -31,6 +32,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add concurrent search support for Derived Fields ([#15326](https://github.com/opensearch-project/OpenSearch/pull/15326))
- [Workload Management] Add query group stats constructs ([#15343](https://github.com/opensearch-project/OpenSearch/pull/15343)))
- Add runAs to Subject interface and introduce IdentityAwarePlugin extension point ([#14630](https://github.com/opensearch-project/OpenSearch/pull/14630))
- Optimize NodeIndicesStats output behind flag ([#14454](https://github.com/opensearch-project/OpenSearch/pull/14454))
- [Workload Management] Add rejection logic for co-ordinator and shard level requests ([#15428](https://github.com/opensearch-project/OpenSearch/pull/15428)))

### Dependencies
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ApiAnnotationProcessor extends AbstractProcessor {
private static final String OPENSEARCH_PACKAGE = "org.opensearch";

private final Set<Element> reported = new HashSet<>();
private final Set<Element> validated = new HashSet<>();
private final Set<AnnotatedConstruct> processed = new HashSet<>();
private Kind reportFailureAs = Kind.ERROR;

Expand All @@ -85,6 +86,8 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
);

for (var element : elements) {
validate(element);

if (!checkPackage(element)) {
continue;
}
Expand All @@ -100,6 +103,64 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
return false;
}

private void validate(Element element) {
// The element was validated already
if (validated.contains(element)) {
return;
}

validated.add(element);

final PublicApi publicApi = element.getAnnotation(PublicApi.class);
if (publicApi != null) {
if (!validateVersion(publicApi.since())) {
processingEnv.getMessager()
.printMessage(
reportFailureAs,
"The type " + element + " has @PublicApi annotation with unparseable OpenSearch version: " + publicApi.since()
);
}
}

final DeprecatedApi deprecatedApi = element.getAnnotation(DeprecatedApi.class);
if (deprecatedApi != null) {
if (!validateVersion(deprecatedApi.since())) {
processingEnv.getMessager()
.printMessage(
reportFailureAs,
"The type "
+ element
+ " has @DeprecatedApi annotation with unparseable OpenSearch version: "
+ deprecatedApi.since()
);
}
}
}

private boolean validateVersion(String version) {
String[] parts = version.split("[.-]");
if (parts.length < 3 || parts.length > 4) {
return false;
}

int major = Integer.parseInt(parts[0]);
if (major > 3 || major < 0) {
return false;
}

int minor = Integer.parseInt(parts[1]);
if (minor < 0) {
return false;
}

int patch = Integer.parseInt(parts[2]);
if (patch < 0) {
return false;
}

return true;
}

/**
* Check top level executable element
* @param executable top level executable element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,35 @@ public void testPublicApiConstructorAnnotatedInternalApi() {

assertThat(failure.diagnotics(), not(hasItem(matching(Diagnostic.Kind.ERROR))));
}

public void testPublicApiUnparseableVersion() {
final CompilerResult result = compile("PublicApiAnnotatedUnparseable.java");
assertThat(result, instanceOf(Failure.class));

final Failure failure = (Failure) result;
assertThat(failure.diagnotics(), hasSize(3));

assertThat(
failure.diagnotics(),
hasItem(
matching(
Diagnostic.Kind.ERROR,
containsString(
"The type org.opensearch.common.annotation.processor.PublicApiAnnotatedUnparseable has @PublicApi annotation with unparseable OpenSearch version: 2.x"
)
)
)
);
}

public void testPublicApiWithDeprecatedApiMethod() {
final CompilerResult result = compile("PublicApiWithDeprecatedApiMethod.java");
assertThat(result, instanceOf(Failure.class));

final Failure failure = (Failure) result;
assertThat(failure.diagnotics(), hasSize(2));

assertThat(failure.diagnotics(), not(hasItem(matching(Diagnostic.Kind.ERROR))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.common.annotation.processor;

import org.opensearch.common.annotation.PublicApi;

@PublicApi(since = "2.x")
public class PublicApiAnnotatedUnparseable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.common.annotation.processor;

import org.opensearch.common.annotation.DeprecatedApi;
import org.opensearch.common.annotation.PublicApi;

@PublicApi(since = "1.0.0")
public class PublicApiWithDeprecatedApiMethod {
@DeprecatedApi(since = "0.1.0")
public void method() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"Test set invalid search backpressure mode":

- skip:
version: "- 2.99.99"
reason: "Parsing and validation of SearchBackpressureMode does not exist in versions < 3.0"
version: "- 2.8.99"
reason: "Fixed in 2.9.0"

- do:
catch: bad_request
Expand Down
Loading

0 comments on commit 16d728b

Please sign in to comment.