Skip to content

Commit

Permalink
Feature/linux packages (#19)
Browse files Browse the repository at this point in the history
* Linux Packages for JInsight
* Log if the Agent was initialized - fixes #13
  • Loading branch information
rshivane authored Mar 6, 2018
1 parent d827f86 commit 871c712
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.iml
.idea/
target/
dependency-reduced-pom.xml
dependency-reduced-pom.xml
pkg/build
pkg/dist
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ cache:
- '$HOME/.m2/repository'
- '$HOME/.sonar/cache'
- '$HOME/.codacy/reporter'
- '$HOME/.rpmlint/'

before_install:
- sudo apt-get install jq
- wget -O ~/.codacy/reporter/codacy-reporter-latest.jar $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r .assets[0].browser_download_url)
- |
wget -O ~/.rpmlint/rpmlint-1.9.tar.gz https://github.com/rpm-software-management/rpmlint/archive/rpmlint-1.9.tar.gz;
tar xvfz ~/.rpmlint/rpmlint-1.9.tar.gz -C ~/.rpmlint;
BUILDER=$USER sudo make install -C ~$BUILDER/.rpmlint/rpmlint-rpmlint-1.9
install:
- sudo apt-get -qq update
- sudo apt-get install -y xmlstarlet
- sudo apt-get install -y rpm python-rpm
- sudo apt-get install -y lintian
# - sudo apt-get install -y rpmlint

before_script:
- if [[ "$METRICS_VERSION" = "3.2.6" ]]; then export IS_PRIMARY_MATRIX_JOB=true; fi
Expand All @@ -69,13 +78,25 @@ script:
else
mvn verify -Denv.server.ip=127.0.0.1
fi
- make -C pkg/deb
- make -C pkg/rpm

after_success:
- |
if [[ "$IS_PRIMARY_MATRIX_JOB" = "true" ]]; then
bash <(curl -s https://codecov.io/bash);
java -cp ~/.codacy/reporter/codacy-reporter-latest.jar com.codacy.CodacyCoverageReporter -l Java -r target/site/jacoco/jacoco.xml;
fi
- make lint -C pkg/deb
- make lint -C pkg/rpm

before_deploy:
- PACKAGE_DATE=$(git log -1 --pretty="format:%ad" $TRAVIS_TAG --date=short);
- echo $PACKAGE_DATE;
- sed -e "s/@PACKAGE_DATE@/$PACKAGE_DATE/" -e "s/@PACKAGE_VERSION@/$PACKAGE_VERSION/" -i pkg/deb/bintray-descriptor.json;
- cat pkg/deb/bintray-descriptor.json;
- sed -e "s/@PACKAGE_DATE@/$PACKAGE_DATE/" -e "s/@PACKAGE_VERSION@/$PACKAGE_VERSION/" -i pkg/rpm/bintray-descriptor.json;
- cat pkg/rpm/bintray-descriptor.json;

deploy:
- provider: script
Expand All @@ -84,3 +105,17 @@ deploy:
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
- provider: bintray
file: "pkg/deb/bintray-descriptor.json"
user: "$BINTRAY_USER"
key: "$BINTRAY_API_KEY"
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
- provider: bintray
file: "pkg/rpm/bintray-descriptor.json"
user: "$BINTRAY_USER"
key: "$BINTRAY_API_KEY"
on:
tags: true
condition: $PACKAGE_VERSION != "" && $IS_PRIMARY_MATRIX_JOB == "true" && $BINTRAY_API_KEY != ""
5 changes: 5 additions & 0 deletions pkg/common/jinsight-config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apptuit.reporting_mode=XCOLLECTOR

#apptuit.reporting_mode=API_PUT
#apptuit.access_token=PASTE_ACCESS_TOKEN_HERE
#global_tags=env:prod, data_center:us-east, micro_service:login
1 change: 1 addition & 0 deletions pkg/deb/DEBIAN/conffiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/jinsight/jinsight-config.properties
15 changes: 15 additions & 0 deletions pkg/deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Package: jinsight
Version: @PACKAGE_VERSION@-@PACKAGE_REVISION@
License: Apache-2.0
Architecture: @DEB_TARGET@
Maintainer: JInsight Maintainers <[email protected]>
Installed-Size: 1108
Depends: xcollector
Provides: jinsight
Section: utils
Priority: optional
Homepage: https://apptuit.ai/jinsight
Description: Apptuit JInsight - A Java agent to collect metrics from Java applications
Apptuit JInsight is a java agent that instruments byte code in a JVM
to transparently collect performance metrics about various sub-systems
in your application.
70 changes: 70 additions & 0 deletions pkg/deb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2017 Agilx, Inc.
#
# Licensed 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.

ifeq ($(PACKAGE_VERSION),)
PACKAGE_VERSION := 1.0.0
PACKAGE_REVISION := 0.1.SNAPSHOT
JAR_VERSION := 1.0.0-SNAPSHOT
else
JAR_VERSION := $(PACKAGE_VERSION)
PACKAGE_REVISION := 1
endif

# Our "source tree"
REPO_ROOT := ../..
WORK_DIR := $(REPO_ROOT)/pkg/build/deb
DEST_DIR := $(REPO_ROOT)/pkg/dist

# What / where do we build.
DEB_TARGET := all
BASENAME := jinsight_$(PACKAGE_VERSION)-$(PACKAGE_REVISION)
DEB := $(BASENAME)_$(DEB_TARGET).deb

all: clean deb

deb:
mkdir -p $(DEST_DIR)/
mkdir -p $(WORK_DIR)/DEBIAN/
mkdir -p $(WORK_DIR)/usr/share/java/
mkdir -p $(WORK_DIR)/etc/jinsight/

chmod -R 755 $(WORK_DIR)/*

install -m 644 $(REPO_ROOT)/target/jinsight-$(JAR_VERSION).jar $(WORK_DIR)/usr/share/java/
ln -rs $(WORK_DIR)/usr/share/java/jinsight-$(JAR_VERSION).jar $(WORK_DIR)/usr/share/java/jinsight.jar
install -m 644 $(REPO_ROOT)/pkg/common/jinsight-config.properties $(WORK_DIR)/etc/jinsight

install -m 644 DEBIAN/conffiles $(WORK_DIR)/DEBIAN/conffiles
set -e; { \
sed \
-e 's/@PACKAGE_VERSION@/$(PACKAGE_VERSION)/' \
-e 's/@DEB_TARGET@/$(DEB_TARGET)/' \
-e 's/@PACKAGE_REVISION@/$(PACKAGE_REVISION)/' \
DEBIAN/control; \
} >$(WORK_DIR)/DEBIAN/control

cd $(WORK_DIR); find . -type f ! -regex '.*?DEBIAN.*' -printf '%P ' | xargs md5sum > DEBIAN/md5sums
chmod 644 $(WORK_DIR)/DEBIAN/md5sums

sudo chown -R root:root $(WORK_DIR)
dpkg-deb -b $(WORK_DIR) $(DEST_DIR)/$(DEB)

lint:
lintian --no-tag-display-limit $(DEST_DIR)/$(DEB)

clean:
sudo rm -rf $(WORK_DIR) $(DEST_DIR)/*.deb

.PHONY: all deb clean
.SUFFIXES: .deb
26 changes: 26 additions & 0 deletions pkg/deb/bintray-descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"package": {
"name": "jinsight",
"repo": "debian",
"subject": "apptuitai"
},

"version": {
"name": "@PACKAGE_VERSION@",
"desc": "Version @PACKAGE_VERSION@",
"released": "@PACKAGE_DATE@",
"vcs_tag": "v@PACKAGE_VERSION@"
},

"files":
[
{"includePattern": "pkg/dist/(.*\\.deb)", "uploadPattern": "/pool/j/jinsight/$1",
"matrixParams": {
"deb_distribution": "stable,jessie,stretch,artful,wheezy,xenial,zesty,trusty",
"deb_component": "jinsight,main,jinsight-v0.x",
"deb_architecture": "arm64,armhf,i386,mipsel,mips,ppc64el,s390x,amd64,armel,mips64el"
}
}
],
"publish": true
}
59 changes: 59 additions & 0 deletions pkg/rpm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2017 Agilx, Inc.
#
# Licensed 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.

ifeq ($(PACKAGE_VERSION),)
PACKAGE_VERSION := 1.0.0
PACKAGE_REVISION := 0.1.SNAPSHOT
JAR_VERSION := 1.0.0-SNAPSHOT
else
JAR_VERSION := $(PACKAGE_VERSION)
PACKAGE_REVISION := 1
endif


# Our "source tree"
REPO_ROOT := $(shell pwd)/../..
WORK_DIR := $(REPO_ROOT)/pkg/build/rpm
DEST_DIR := $(REPO_ROOT)/pkg/dist/

# What / where do we build.
RPM_TARGET := noarch
BASENAME := jinsight-$(PACKAGE_VERSION)-$(PACKAGE_REVISION)
RPM := $(BASENAME).$(RPM_TARGET).rpm

all: clean rpm

rpm:
mkdir -p $(WORK_DIR)
mkdir -p $(DEST_DIR)
set -e; { \
echo "# File generated by Makefile, do not edit"; \
sed \
-e 's/@PACKAGE_VERSION@/$(PACKAGE_VERSION)/' \
-e 's/@JAR_VERSION@/$(JAR_VERSION)/' \
-e 's/@RPM_TARGET@/$(RPM_TARGET)/' \
-e 's/@PACKAGE_REVISION@/$(PACKAGE_REVISION)/' \
jinsight.spec; \
} > $(WORK_DIR)/jinsight-t.spec
rpmbuild --define "_topdir $(WORK_DIR)" -bb $(WORK_DIR)/jinsight-t.spec --target $(RPM_TARGET)
mv $(WORK_DIR)/RPMS/$(RPM_TARGET)/$(RPM) $(DEST_DIR)

lint:
rpmlint $(DEST_DIR)/$(RPM)

clean:
rm -rf $(WORK_DIR) $(DEST_DIR)/*.rpm

.PHONY: all rpm clean distclean
.SUFFIXES: .spec .rpm
20 changes: 20 additions & 0 deletions pkg/rpm/bintray-descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"package": {
"name": "jinsight",
"repo": "rpm",
"subject": "apptuitai"
},

"version": {
"name": "@PACKAGE_VERSION@",
"desc": "Version @PACKAGE_VERSION@",
"released": "@PACKAGE_DATE@",
"vcs_tag": "v@PACKAGE_VERSION@"
},

"files":
[
{"includePattern": "pkg/dist/(.*\\.rpm)", "uploadPattern": "/$1"}
],
"publish": true
}
32 changes: 32 additions & 0 deletions pkg/rpm/jinsight.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%global reporoot %{_topdir}/../../..

BuildArch: @RPM_TARGET@
Name: jinsight
Group: System/Monitoring
Version: @PACKAGE_VERSION@
Release: @PACKAGE_REVISION@
License: Apache License
Summary: Apptuit JInsight - A Java agent to collect metrics from Java applications
URL: https://apptuit.ai/jinsight
Requires: xcollector
Packager: JInsight Maintainers <[email protected]>


%description
Apptuit JInsight is a java agent that instruments byte code in a JVM
to transparently collect performance metrics about various sub-systems
in your application.

%install
mkdir -p %{buildroot}/usr/share/java/
mkdir -p %{buildroot}/etc/jinsight/
chmod -R 755 %{buildroot}/*

%{__install} -m 644 %{reporoot}/target/jinsight-@[email protected] %{buildroot}/usr/share/java/
ln -rs %{buildroot}/usr/share/java/jinsight-@[email protected] %{buildroot}/usr/share/java/jinsight.jar
%{__install} -m 644 %{reporoot}/pkg/common/jinsight-config.properties %{buildroot}/etc/jinsight


%files
/usr/share/java/
/etc/jinsight %config(noreplace)
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.

<groupId>ai.apptuit</groupId>
<artifactId>jinsight</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>JInsight</name>
Expand Down Expand Up @@ -507,6 +507,7 @@ limitations under the License.
<reportFile>${project.build.directory}/reports/license-check-results.xml</reportFile>
<excludes>
<exclude>${project.basedir}/dependency-reduced-pom.xml</exclude>
<exclude>pkg/**/*</exclude>
</excludes>
</configuration>
<executions>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/ai/apptuit/metrics/jinsight/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public static void agentmain(String agentArgs, Instrumentation instrumentation)
private static void main0(String agentArgs, Instrumentation instrumentation,
BiConsumer<String, Instrumentation> delegate) {
if (ClassLoader.getSystemResource(BTM_SCRIPTS_RESOURCE_PATH) == null) {
System.err.println("Could not load " + BTM_SCRIPTS_RESOURCE_PATH + "."
LOGGER.severe("Could not load " + BTM_SCRIPTS_RESOURCE_PATH + "."
+ "Agent will not be started.");
return;
}

try {
ConfigService.initialize();
} catch (ConfigurationException | IOException | RuntimeException e) {
System.err.println(e.getMessage());
System.err.println("Agent will not be started.");
LOGGER.severe(e.getMessage());
LOGGER.severe("Agent will not be started.");
return;
}

Expand All @@ -90,13 +90,14 @@ private static void main0(String agentArgs, Instrumentation instrumentation,

JarFile bytemanJar = createBytemanJar();
if (bytemanJar == null) {
System.err.println("Could not locate: " + BYTEMAN_JAR_RESOURCE_NAME);
System.err.println("Agent will not be started.");
LOGGER.severe("Could not locate: " + BYTEMAN_JAR_RESOURCE_NAME);
LOGGER.severe("Agent will not be started.");
return;
}

instrumentation.appendToBootstrapClassLoaderSearch(bytemanJar);
delegate.accept(agentArgs, instrumentation);
LOGGER.info("JInsight initialized. Reporting mode: "+ConfigService.getInstance().getReportingMode());
}

private static JarFile createBytemanJar() {
Expand Down
Loading

0 comments on commit 871c712

Please sign in to comment.