Skip to content

Commit

Permalink
Add Git build info when we build a distribution
Browse files Browse the repository at this point in the history
closes #3370
  • Loading branch information
kimchy committed Jul 24, 2013
1 parent 9fdaad1 commit 83bdefe
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 35 deletions.
56 changes: 38 additions & 18 deletions pom.xml
Expand Up @@ -45,7 +45,7 @@
</repositories>

<dependencies>
<dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
Expand Down Expand Up @@ -285,6 +285,7 @@
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

Expand Down Expand Up @@ -331,26 +332,27 @@
<jvmOutputAction>pipe,warn</jvmOutputAction>
<leaveTemporary>true</leaveTemporary>
<listeners>
<report-ant-xml mavenExtensions="true" dir="${project.build.directory}/surefire-reports" />
<report-text
showThrowable="true"
showStackTraces="true"
showOutput="onerror"
showStatusOk="false"
showStatusError="true"
showStatusFailure="true"
showStatusIgnored="true"
showSuiteSummary="true"
timestamps="false" />
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
<report-ant-xml mavenExtensions="true"
dir="${project.build.directory}/surefire-reports"/>
<report-text
showThrowable="true"
showStackTraces="true"
showOutput="onerror"
showStatusOk="false"
showStatusError="true"
showStatusFailure="true"
showStatusIgnored="true"
showSuiteSummary="true"
timestamps="false"/>
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
</listeners>
<assertions>
<enable />
<enable/>
</assertions>
<parallelism>${tests.jvms}</parallelism>
<balancers>
<execution-times>
<fileset dir="${basedir}" includes=".local-execution-hints.log" />
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
</execution-times>
</balancers>
<includes>
Expand Down Expand Up @@ -380,7 +382,8 @@
<tests.slow>${tests.slow}</tests.slow>
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
<es.transport.tcp.compress>${env.ES_TEST_COMPRESS}</es.transport.tcp.compress>
<es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}</es.action.wait_on_mapping_change>
<es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}
</es.action.wait_on_mapping_change>
<java.awt.headless>true</java.awt.headless>
</systemProperties>
</configuration>
Expand All @@ -391,9 +394,9 @@
<!-- we skip surefire to work with randomized testing above -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<version>2.15</version>
<configuration>
<skipTests>true</skipTests>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -532,6 +535,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/org/elasticsearch/Build.java
@@ -0,0 +1,80 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch;

import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.io.Streams;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;

import java.util.Properties;

/**
*/
public class Build {

public static final Build CURRENT;

static {
String hash = "NA";
String hashShort = "NA";
String timestamp = "NA";

try {
String properties = Streams.copyToStringFromClasspath("/es-build.properties");
Properties props = new Properties();
props.load(new FastStringReader(properties));
hash = props.getProperty("hash", hash);
if (!hash.equals("NA")) {
hashShort = hash.substring(0, 7);
}
String gitTimestampRaw = props.getProperty("timestamp");
if (gitTimestampRaw != null) {
timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw));
}
} catch (Exception e) {
// just ignore...
}

CURRENT = new Build(hash, hashShort, timestamp);
}

private String hash;
private String hashShort;
private String timestamp;

Build(String hash, String hashShort, String timestamp) {
this.hash = hash;
this.hashShort = hashShort;
this.timestamp = timestamp;
}

public String hash() {
return hash;
}

public String hashShort() {
return hashShort;
}

public String timestamp() {
return timestamp;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/elasticsearch/Version.java
Expand Up @@ -289,7 +289,7 @@ public String number() {
}

public static void main(String[] args) {
System.out.println("ElasticSearch Version: " + Version.CURRENT + ", JVM: " + JvmInfo.jvmInfo().version() + "(" + JvmInfo.jvmInfo().vmVersion() + ")");
System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp() + ", JVM: " + JvmInfo.jvmInfo().version());
}

@Override
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/org/elasticsearch/node/internal/InternalNode.java
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.node.internal;

import org.elasticsearch.Build;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionModule;
Expand Down Expand Up @@ -117,7 +118,9 @@ public InternalNode(Settings pSettings, boolean loadConfigSettings) throws Elast
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);

ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
logger.info("{{}}[{}]: initializing ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("version[{}], pid[{}], build[{}/{}]", Version.CURRENT, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp());

logger.info("initializing ...");

if (logger.isDebugEnabled()) {
Environment env = tuple.v2();
Expand Down Expand Up @@ -167,7 +170,7 @@ public InternalNode(Settings pSettings, boolean loadConfigSettings) throws Elast

client = injector.getInstance(Client.class);

logger.info("{{}}[{}]: initialized", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("initialized");
}

@Override
Expand All @@ -186,7 +189,7 @@ public Node start() {
}

ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: starting ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("starting ...");

// hack around dependency injection problem (for now...)
injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class));
Expand Down Expand Up @@ -216,7 +219,7 @@ public Node start() {
}
injector.getInstance(BulkUdpService.class).start();

logger.info("{{}}[{}]: started", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("started");

return this;
}
Expand All @@ -227,7 +230,7 @@ public Node stop() {
return this;
}
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: stopping ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("stopping ...");

injector.getInstance(BulkUdpService.class).stop();
if (settings.getAsBoolean("http.enabled", true)) {
Expand Down Expand Up @@ -261,7 +264,7 @@ public Node stop() {
injector.getInstance(plugin).stop();
}

logger.info("{{}}[{}]: stopped", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("stopped");

return this;
}
Expand All @@ -275,7 +278,7 @@ public void close() {
}

ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: closing ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("closing ...");

StopWatch stopWatch = new StopWatch("node_close");
stopWatch.start("bulk.udp");
Expand Down Expand Up @@ -352,7 +355,7 @@ public void close() {
CachedStreams.clear();
ThreadLocals.clearReferencesThreadLocals();

logger.info("{{}}[{}]: closed", Version.CURRENT, JvmInfo.jvmInfo().pid());
logger.info("closed");
}

@Override
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.rest.action.main;

import org.apache.lucene.util.Constants;
import org.elasticsearch.Build;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
Expand Down Expand Up @@ -77,14 +78,16 @@ public void onResponse(ClusterStateResponse response) {
builder.field("name", settings.get("name"));
}
builder.startObject("version")
.field("number", Version.CURRENT.number())
.field("snapshot_build", Version.CURRENT.snapshot)
// We use the lucene version from lucene constants since
// this includes bugfix release version as well and is already in
// the right format. We can also be sure that the format is maitained
// since this is also recorded in lucene segments and has BW compat
.field("lucene_version", Constants.LUCENE_MAIN_VERSION)
.endObject();
.field("number", Version.CURRENT.number())
.field("build_hash", Build.CURRENT.hash())
.field("build_timestamp", Build.CURRENT.timestamp())
.field("build_snapshot", Version.CURRENT.snapshot)
// We use the lucene version from lucene constants since
// this includes bugfix release version as well and is already in
// the right format. We can also be sure that the format is maitained
// since this is also recorded in lucene segments and has BW compat
.field("lucene_version", Constants.LUCENE_MAIN_VERSION)
.endObject();
builder.field("tagline", "You Know, for Search");
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/es-build.properties
@@ -0,0 +1,3 @@
version=${project.version}
hash=${buildNumber}
timestamp=${timestamp}

0 comments on commit 83bdefe

Please sign in to comment.