Skip to content

Commit 9d41956

Browse files
authored
Merge branch 'main' into fix/synonyms-test-excluded-mixed-cluster
2 parents 3623259 + 5f9a9e0 commit 9d41956

File tree

1,830 files changed

+38796
-10377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,830 files changed

+38796
-10377
lines changed

.ci/init.gradle

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,3 @@
1-
import com.bettercloud.vault.VaultConfig
2-
import com.bettercloud.vault.Vault
3-
4-
initscript {
5-
repositories {
6-
mavenCentral()
7-
}
8-
dependencies {
9-
classpath 'com.bettercloud:vault-java-driver:4.1.0'
10-
}
11-
}
12-
13-
boolean USE_ARTIFACTORY = false
14-
15-
if (System.getenv('VAULT_ADDR') == null) {
16-
// When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
17-
if (System.getenv('CI') == null) {
18-
return
19-
}
20-
21-
throw new GradleException("You must set the VAULT_ADDR environment variable to use this init script.")
22-
}
23-
24-
if (System.getenv('VAULT_ROLE_ID') == null && System.getenv('VAULT_SECRET_ID') == null && System.getenv('VAULT_TOKEN') == null) {
25-
// When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
26-
if (System.getenv('CI') == null) {
27-
return
28-
}
29-
30-
throw new GradleException("You must set either the VAULT_ROLE_ID and VAULT_SECRET_ID environment variables, " +
31-
"or the VAULT_TOKEN environment variable to use this init script.")
32-
}
33-
34-
final String vaultPathPrefix = System.getenv('VAULT_ADDR') ==~ /.+vault-ci.+\.dev.*/ ? "secret/ci/elastic-elasticsearch/migrated" : "secret/elasticsearch-ci"
35-
36-
final String vaultToken = System.getenv('VAULT_TOKEN') ?: new Vault(
37-
new VaultConfig()
38-
.address(System.env.VAULT_ADDR)
39-
.engineVersion(1)
40-
.build()
41-
)
42-
.withRetries(5, 1000)
43-
.auth()
44-
.loginByAppRole("approle", System.env.VAULT_ROLE_ID, System.env.VAULT_SECRET_ID)
45-
.getAuthClientToken()
46-
47-
final Vault vault = new Vault(
48-
new VaultConfig()
49-
.address(System.env.VAULT_ADDR)
50-
.engineVersion(1)
51-
.token(vaultToken)
52-
.build()
53-
)
54-
.withRetries(5, 1000)
55-
56-
57-
if (USE_ARTIFACTORY) {
58-
final Map<String, String> artifactoryCredentials = vault.logical()
59-
.read("${vaultPathPrefix}/artifactory.elstc.co")
60-
.getData()
61-
logger.info("Using elastic artifactory repos")
62-
Closure configCache = {
63-
return {
64-
name "artifactory-gradle-release"
65-
url "https://artifactory.elstc.co/artifactory/gradle-release"
66-
credentials {
67-
username artifactoryCredentials.get("username")
68-
password artifactoryCredentials.get("token")
69-
}
70-
}
71-
}
72-
settingsEvaluated { settings ->
73-
settings.pluginManagement {
74-
repositories {
75-
maven configCache()
76-
}
77-
}
78-
}
79-
projectsLoaded {
80-
allprojects {
81-
buildscript {
82-
repositories {
83-
maven configCache()
84-
}
85-
}
86-
repositories {
87-
maven configCache()
88-
}
89-
}
90-
}
91-
}
92-
931
gradle.settingsEvaluated { settings ->
942
settings.pluginManager.withPlugin("com.gradle.develocity") {
953
settings.develocity {
@@ -98,14 +6,10 @@ gradle.settingsEvaluated { settings ->
986
}
997
}
1008

101-
1029
final String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.url')
10310
final boolean buildCachePush = Boolean.valueOf(System.getProperty('org.elasticsearch.build.cache.push', 'false'))
10411

10512
if (buildCacheUrl) {
106-
final Map<String, String> buildCacheCredentials = System.getenv("GRADLE_BUILD_CACHE_USERNAME") ? [:] : vault.logical()
107-
.read("${vaultPathPrefix}/gradle-build-cache")
108-
.getData()
10913
gradle.settingsEvaluated { settings ->
11014
settings.buildCache {
11115
local {
@@ -116,11 +20,10 @@ if (buildCacheUrl) {
11620
url = buildCacheUrl
11721
push = buildCachePush
11822
credentials {
119-
username = System.getenv("GRADLE_BUILD_CACHE_USERNAME") ?: buildCacheCredentials.get("username")
120-
password = System.getenv("GRADLE_BUILD_CACHE_PASSWORD") ?: buildCacheCredentials.get("password")
23+
username = System.getenv("GRADLE_BUILD_CACHE_USERNAME")
24+
password = System.getenv("GRADLE_BUILD_CACHE_PASSWORD")
12125
}
12226
}
12327
}
12428
}
12529
}
126-

benchmarks/src/main/java/org/elasticsearch/benchmark/vector/VectorScorerBenchmark.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class VectorScorerBenchmark {
8383

8484
RandomVectorScorer luceneDotScorerQuery;
8585
RandomVectorScorer nativeDotScorerQuery;
86+
RandomVectorScorer luceneSqrScorerQuery;
87+
RandomVectorScorer nativeSqrScorerQuery;
8688

8789
@Setup
8890
public void setup() throws IOException {
@@ -130,6 +132,8 @@ public void setup() throws IOException {
130132
}
131133
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
132134
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
135+
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
136+
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();
133137

134138
// sanity
135139
var f1 = dotProductLucene();
@@ -157,6 +161,12 @@ public void setup() throws IOException {
157161
if (q1 != q2) {
158162
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
159163
}
164+
165+
var sqr1 = squareDistanceLuceneQuery();
166+
var sqr2 = squareDistanceNativeQuery();
167+
if (sqr1 != sqr2) {
168+
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
169+
}
160170
}
161171

162172
@TearDown
@@ -217,6 +227,16 @@ public float squareDistanceScalar() {
217227
return 1 / (1f + adjustedDistance);
218228
}
219229

230+
@Benchmark
231+
public float squareDistanceLuceneQuery() throws IOException {
232+
return luceneSqrScorerQuery.score(1);
233+
}
234+
235+
@Benchmark
236+
public float squareDistanceNativeQuery() throws IOException {
237+
return nativeSqrScorerQuery.score(1);
238+
}
239+
220240
QuantizedByteVectorValues vectorValues(int dims, int size, IndexInput in, VectorSimilarityFunction sim) throws IOException {
221241
var sq = new ScalarQuantizer(0.1f, 0.9f, (byte) 7);
222242
var slice = in.slice("values", 0, in.length());

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/GitInfoPlugin.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,45 @@
1010
package org.elasticsearch.gradle.internal.conventions;
1111

1212
import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
13+
import org.elasticsearch.gradle.internal.conventions.info.GitInfoValueSource;
1314
import org.elasticsearch.gradle.internal.conventions.util.Util;
1415
import org.gradle.api.Plugin;
1516
import org.gradle.api.Project;
16-
import org.gradle.api.model.ObjectFactory;
1717
import org.gradle.api.provider.Property;
1818
import org.gradle.api.provider.Provider;
1919
import org.gradle.api.provider.ProviderFactory;
2020

21-
import javax.inject.Inject;
2221
import java.io.File;
2322

24-
class GitInfoPlugin implements Plugin<Project> {
23+
import javax.inject.Inject;
2524

26-
private ProviderFactory factory;
27-
private ObjectFactory objectFactory;
25+
public abstract class GitInfoPlugin implements Plugin<Project> {
2826

27+
private ProviderFactory factory;
2928
private Provider<String> revision;
30-
private Property<GitInfo> gitInfo;
3129

3230
@Inject
33-
GitInfoPlugin(ProviderFactory factory, ObjectFactory objectFactory) {
31+
public GitInfoPlugin(ProviderFactory factory) {
3432
this.factory = factory;
35-
this.objectFactory = objectFactory;
3633
}
3734

3835
@Override
3936
public void apply(Project project) {
40-
File rootDir = Util.locateElasticsearchWorkspace(project.getGradle());
41-
gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
42-
GitInfo.gitInfo(rootDir)
43-
));
44-
gitInfo.disallowChanges();
45-
gitInfo.finalizeValueOnRead();
46-
47-
revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "main");
37+
File rootDir = getGitRootDir(project);
38+
getGitInfo().convention(factory.of(GitInfoValueSource.class, spec -> { spec.getParameters().getPath().set(rootDir); }));
39+
revision = getGitInfo().map(info -> info.getRevision() == null ? info.getRevision() : "main");
4840
}
4941

50-
public Property<GitInfo> getGitInfo() {
51-
return gitInfo;
42+
private static File getGitRootDir(Project project) {
43+
File rootDir = project.getRootDir();
44+
if (new File(rootDir, ".git").exists()) {
45+
return rootDir;
46+
}
47+
return Util.locateElasticsearchWorkspace(project.getGradle());
5248
}
5349

50+
public abstract Property<GitInfo> getGitInfo();
51+
5452
public Provider<String> getRevision() {
5553
return revision;
5654
}

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/LicensingPlugin.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
import org.gradle.api.provider.Provider;
1616
import org.gradle.api.provider.ProviderFactory;
1717

18-
import javax.inject.Inject;
1918
import java.util.Map;
2019

20+
import javax.inject.Inject;
21+
2122
public class LicensingPlugin implements Plugin<Project> {
2223
static final String ELASTIC_LICENSE_URL_PREFIX = "https://raw.githubusercontent.com/elastic/elasticsearch/";
2324
static final String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";
@@ -33,24 +34,33 @@ public LicensingPlugin(ProviderFactory providerFactory) {
3334
@Override
3435
public void apply(Project project) {
3536
Provider<String> revision = project.getRootProject().getPlugins().apply(GitInfoPlugin.class).getRevision();
36-
Provider<String> licenseCommitProvider = providerFactory.provider(() ->
37-
isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
37+
Provider<String> licenseCommitProvider = providerFactory.provider(
38+
() -> isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
3839
);
3940

40-
Provider<String> elasticLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
41-
licenseCommit + ELASTIC_LICENSE_URL_POSTFIX);
42-
Provider<String> agplLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
43-
licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX);
41+
Provider<String> elasticLicenseURL = licenseCommitProvider.map(
42+
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + ELASTIC_LICENSE_URL_POSTFIX
43+
);
44+
Provider<String> agplLicenseURL = licenseCommitProvider.map(
45+
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX
46+
);
4447
// But stick the Elastic license url in project.ext so we can get it if we need to switch to it
4548
project.getExtensions().getExtraProperties().set("elasticLicenseUrl", elasticLicenseURL);
4649

47-
MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class).convention(
48-
providerFactory.provider(() -> Map.of(
49-
"Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
50-
"Elastic License 2.0", elasticLicenseURL.get(),
51-
"GNU Affero General Public License Version 3", agplLicenseURL.get())
50+
MapProperty<String, Provider<String>> licensesProperty = project.getObjects()
51+
.mapProperty(String.class, (Class<Provider<String>>) (Class<?>) Provider.class)
52+
.convention(
53+
providerFactory.provider(
54+
() -> Map.of(
55+
"Server Side Public License, v 1",
56+
providerFactory.provider(() -> "https://www.mongodb.com/licensing/server-side-public-license"),
57+
"Elastic License 2.0",
58+
elasticLicenseURL,
59+
"GNU Affero General Public License Version 3",
60+
agplLicenseURL
61+
)
5262
)
53-
);
63+
);
5464

5565
// Default to the SSPL+Elastic dual license
5666
project.getExtensions().getExtraProperties().set("projectLicenses", licensesProperty);

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.gradle.api.plugins.JavaLibraryPlugin;
2929
import org.gradle.api.plugins.JavaPlugin;
3030
import org.gradle.api.provider.MapProperty;
31+
import org.gradle.api.provider.Provider;
3132
import org.gradle.api.provider.ProviderFactory;
3233
import org.gradle.api.publish.PublishingExtension;
3334
import org.gradle.api.publish.maven.MavenPublication;
@@ -42,6 +43,7 @@
4243
import java.io.File;
4344
import java.util.Map;
4445
import java.util.concurrent.Callable;
46+
4547
import javax.inject.Inject;
4648

4749
public class PublishPlugin implements Plugin<Project> {
@@ -81,15 +83,15 @@ private void configurePublications(Project project) {
8183
}
8284
});
8385
@SuppressWarnings("unchecked")
84-
var projectLicenses = (MapProperty<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
86+
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
8587
publication.getPom().withXml(xml -> {
8688
var node = xml.asNode();
8789
node.appendNode("inceptionYear", "2009");
8890
var licensesNode = node.appendNode("licenses");
8991
projectLicenses.get().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
9092
Node license = licensesNode.appendNode("license");
9193
license.appendNode("name", entry.getKey());
92-
license.appendNode("url", entry.getValue());
94+
license.appendNode("url", entry.getValue().get());
9395
license.appendNode("distribution", "repo");
9496
});
9597
var developer = node.appendNode("developers").appendNode("developer");
@@ -194,7 +196,6 @@ static void configureSourcesJar(Project project) {
194196
});
195197
}
196198

197-
198199
/**
199200
* Format the generated pom files to be in a sort of reproducible order.
200201
*/

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.Iterator;
2424
import java.util.Map;
25+
import java.util.Objects;
2526
import java.util.regex.Matcher;
2627
import java.util.regex.Pattern;
2728
import java.util.stream.Collectors;
@@ -190,4 +191,15 @@ public String urlFromOrigin() {
190191
}
191192
}
192193

194+
@Override
195+
public boolean equals(Object o) {
196+
if (o == null || getClass() != o.getClass()) return false;
197+
GitInfo gitInfo = (GitInfo) o;
198+
return Objects.equals(revision, gitInfo.revision) && Objects.equals(origin, gitInfo.origin);
199+
}
200+
201+
@Override
202+
public int hashCode() {
203+
return Objects.hash(revision, origin);
204+
}
193205
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.elasticsearch.gradle.internal.conventions.info;
2+
3+
import org.gradle.api.provider.Property;
4+
import org.gradle.api.provider.ValueSource;
5+
import org.gradle.api.provider.ValueSourceParameters;
6+
import org.jetbrains.annotations.Nullable;
7+
8+
import java.io.File;
9+
10+
public abstract class GitInfoValueSource implements ValueSource<GitInfo, GitInfoValueSource.Parameters> {
11+
12+
@Nullable
13+
@Override
14+
public GitInfo obtain() {
15+
File path = getParameters().getPath().get();
16+
return GitInfo.gitInfo(path);
17+
}
18+
19+
public interface Parameters extends ValueSourceParameters {
20+
Property<File> getPath();
21+
}
22+
}

0 commit comments

Comments
 (0)