Skip to content

Commit

Permalink
Merge pull request #105 from IBMStreams/develop
Browse files Browse the repository at this point in the history
1.7.1
  • Loading branch information
markheger authored Dec 8, 2017
2 parents d9f206b + c85120a commit dfa43ea
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 27 deletions.
10 changes: 5 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@
</target>
<!-- Targets to build releases -->
<target name="release" depends="clean,all">
<exec executable="make" failonerror="true" dir="${microservices}">
<mkdir dir="${tmp}" />
<exec executable="make" failonerror="true" dir="${microservices}">
<arg value="-f" />
<arg value="Makefile" />
<arg value="all" />
<arg value="release" />
</exec>
<exec executable="make" failonerror="true" dir="${microservices}">
<arg value="-f" />
<arg value="Makefile" />
<arg value="make-doc" />
</exec>
<mkdir dir="${tmp}" />
<arg value="clean" />
</exec>
<!-- Create the time stamp -->
<tstamp />
<!-- Extract info from the toolkit's info.xml -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ use com.ibm.streamsx.monitoring.jmx::ConnectionNotification;
*
* @param iamTokenEndpoint
* Specifies IAM token endpoint. Relevant for IAM authentication case only. If parameter is not set, then the public endpoint is used: https://iam.bluemix.net/oidc/token
*
* @param timeOut
* Specifies the number of seconds during which no duplicate of a tuple is emitted.
* If this parameter is not specified, the default value is `5.0` seconds (5 seconds).
* Identical tuples, which are separated by more than **timeOut** seconds, are seen on the output port.
*/
public composite JobStatusMonitor (output stream<JobStatusNotification> OutStream, stream<ConnectionNotification> ConnectionNotificationStream) {

Expand All @@ -55,8 +60,9 @@ public composite JobStatusMonitor (output stream<JobStatusNotification> OutStrea
expression<rstring> $connectionURL: ""; // optional, if not set, then domain settings are used, where the PE is running
expression<rstring> $domainId: ""; // optional, if not set, then domain settings are used, where the PE is running
expression<rstring> $sslOption: ""; // optional, if not set, then domain settings are used, where the PE is running
expression<rstring> $iamApiKey: getSubmissionTimeValue("iamApiKey", ""); // optional, if user and password are set
expression<rstring> $iamTokenEndpoint: getSubmissionTimeValue("iamTokenEndpoint", ""); // optional, used when iamApiKey is set only
expression<rstring> $iamApiKey: ""; // optional, if user and password are set
expression<rstring> $iamTokenEndpoint: ""; // optional, used when iamApiKey is set only
expression<float64> $timeOut: 5.0;

graph

Expand All @@ -80,7 +86,7 @@ public composite JobStatusMonitor (output stream<JobStatusNotification> OutStrea

stream<I> OutStream = DeDuplicate(Notifications as I) {
param
timeOut: 5.0;
timeOut: $timeOut;
key: notifyType, domainId, instanceId, jobId, jobName, resource, peId, peHealth, peStatus;
}

Expand Down
2 changes: 1 addition & 1 deletion com.ibm.streamsx.monitoring/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ by toolkit with their namespaces as prefixes.
**streamtool submitjob** command or by using Streams Studio.
]]></info:description>
<info:version>1.7.0</info:version>
<info:version>1.7.1</info:version>
<info:requiredProductVersion>4.1.0.0</info:requiredProductVersion>
</info:identity>
<info:dependencies/>
Expand Down
6 changes: 6 additions & 0 deletions microservices/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ all:
make -C $$dir || exit 1; \
done

release:
for dir in $(shell ls -d -1 */); do\
make release -C $$dir || exit 1; \
done


clean: clean-doc
for dir in $(shell ls -d -1 */); do\
make -C $$dir clean || exit 1; \
Expand Down
13 changes: 3 additions & 10 deletions microservices/MetricsIngestService/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ clean:
$(SPLC) -C -M $(SPL_MAIN_COMPOSITE)
rm -rf $(TO_BE_DELETED)

configure:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
streamtool mkappconfig --property connectionURL=`streamtool getjmxconnect` --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration

configure-json:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
streamtool mkappconfig --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) --property filterDocument=`cat etc/MetricsSource_MonitorOperatorMetrics.json | perl -e 'my @content = <STDIN>; my $$str = join("", @content); $$str =~ s/\s//g; print $$str;'` com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration

configure-none:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
release: all
-mkdir ../../tmp
cp $(OUTPUT_DIR)/*.sab ../../tmp

14 changes: 7 additions & 7 deletions microservices/MetricsMonitorService/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ clean:
rm -rf $(TO_BE_DELETED)

configure:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
streamtool mkappconfig --property connectionURL=`streamtool getjmxconnect` --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration

configure-json:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
streamtool mkappconfig --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) --property filterDocument=`cat etc/MetricsSource_MonitorOperatorMetrics.json | perl -e 'my @content = <STDIN>; my $$str = join("", @content); $$str =~ s/\s//g; print $$str;'` com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration
streamtool mkappconfig --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) --property thresholdDocument=`cat etc/sample.json | perl -e 'my @content = <STDIN>; my $$str = join("", @content); $$str =~ s/\s//g; print $$str;'` com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration

configure-none:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.metrics.MetricsSource.ApplicationConfiguration
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration

release: all
-mkdir ../../tmp
cp $(OUTPUT_DIR)/*.sab ../../tmp

Empty file.
83 changes: 83 additions & 0 deletions tests/spl-test/MetricsMonitor/test_microservices/Main.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// ****************************************************************************
// * Copyright (C) 2017, International Business Machines Corporation *
// * All rights reserved. *
// ****************************************************************************
//

use com.ibm.streamsx.topology.topic::Subscribe;
use com.ibm.streamsx.json::*;

/**
* Create the custom application metrics. The function is usable in the state
* logic of an operator.
*/
stateful boolean createMetrics() {
createCustomMetric("inc", "The incrementing number.", Sys.Counter, 0l);
return true;
}

/**
* This test application subscribes the topic of the MetricsMonitor microservice
*
* @param metricsMonitorTopic
* Specifies the topic of the MetricsMonitor microservice
*
*/
composite Main {
param
expression<rstring> $metricsMonitorTopic : getSubmissionTimeValue("metricsMonitorTopic", "streamsx/monitoring/metrics/alerts");

graph

stream<Json> JsonMonitor = Subscribe() {
param
topic: $metricsMonitorTopic;
streamType: Json;
}

(stream <rstring result> SaveDone1) as Validator = Custom(JsonMonitor as I) {
logic
state: {
mutable boolean done1Sent = false;
}
onTuple I: {
printStringLn((rstring)I);
if (!done1Sent) {
submit({result="TEST_RESULT_PASS"}, SaveDone1);
submit(Sys.WindowMarker, SaveDone1);
done1Sent = true;
}
}
}

() as Done1 = FileSink(SaveDone1 as I) {
param file: "done_1"; format: csv; flush: 1u; quoteStrings : false; writePunctuations: false; closeMode: punct; moveFileToDirectory: dataDirectory()+"/..";
}

/*
* The Beacon generates incrementing.
*/
stream<int64 incrementingNumber> Numbers as O = Beacon() {
param period: 0.5;
output O:
incrementingNumber = (int64)IterationCount();
}

/*
* The Custom stores the received numbers in metrics.
*/
() as Storage = Custom(Numbers as I) {
logic
state: {
boolean created = createMetrics();
}
onTuple I: {
setCustomMetricValue("inc", I.incrementingNumber);
}
}
}




53 changes: 53 additions & 0 deletions tests/spl-test/MetricsMonitor/test_microservices/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (C) 2017, International Business Machines Corporation.
# All Rights Reserved.

.PHONY: build all clean distributed

SPLC_FLAGS = -a
OUTPUT_DIR = output
ifeq ($(STREAMS_INSTALL),)
$(error error: environment variable STREAMS_INSTALL has to be set)
endif
STREAMSX_MONITORING_TOOLKIT ?=../../../../com.ibm.streamsx.monitoring
SPLC = $(STREAMS_INSTALL)/bin/sc
STREAMSX_JSON_TOOLKIT ?=$(STREAMS_INSTALL)/toolkits/com.ibm.streamsx.json
STREAMSX_TOPOLOGY_TOOLKIT ?=$(STREAMS_INSTALL)/toolkits/com.ibm.streamsx.topology
SPL_PATH = $(STREAMSX_MONITORING_TOOLKIT):$(STREAMSX_JSON_TOOLKIT):$(STREAMSX_TOPOLOGY_TOOLKIT)

SPLC_FLAGS += -t $(SPL_PATH)
SPL_DATA_DIR = ./data

SPL_CMD_ARGS ?=
SPL_MAIN_COMPOSITE = Main

MICROSERVICES_DIR =../../../../microservices

build: distributed

all: clean build
cd $(MICROSERVICES_DIR); make -f Makefile all

distributed:
$(SPLC) $(SPLC_FLAGS) -M $(SPL_MAIN_COMPOSITE) $(SPL_CMD_ARGS) --data-directory $(SPL_DATA_DIR) --output-directory=$(OUTPUT_DIR)

clean:
$(SPLC) $(SPLC_FLAGS) -C -M $(SPL_MAIN_COMPOSITE)
rm -rf $(OUTPUT_DIR)

configure:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration
streamtool mkappconfig --property user=$(JMX_USER) --property password=$(JMX_PASSWORD) --property thresholdDocument=`cat etc/microservices.json | perl -e 'my @content = <STDIN>; my $$str = join("", @content); $$str =~ s/\s//g; print $$str;'` com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration

configure-none:
-streamtool rmappconfig --noprompt com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration

start-monitor:
streamtool submitjob $(MICROSERVICES_DIR)/MetricsIngestService/output/com.ibm.streamsx.monitoring.service.MetricsIngestService.sab --jobname microserviceMetrics -P applicationConfigurationName=com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration
streamtool submitjob $(MICROSERVICES_DIR)/MetricsMonitorService/output/com.ibm.streamsx.monitoring.service.MetricsMonitorService.sab --jobname microserviceMonitor -P applicationConfigurationName=com.ibm.streamsx.monitoring.microservices.ApplicationConfiguration
streamtool submitjob output/Main.sab --jobname testMicroservices

stop-monitor:
streamtool canceljob --jobnames microserviceMetrics --collectlogs
streamtool canceljob --jobnames microserviceMonitor --collectlogs
streamtool canceljob --jobnames testMicroservices --collectlogs

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done*
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"metricName":"inc",
"thresholds":
{
"value":">100"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest
import os
import testharness as th

class MetricsMonitorMicroservicesTest(unittest.TestCase):

result_file_1 = "done_1"

@classmethod
def setUpClass(cls):
try:
os.environ["JMX_USER"]
os.environ["JMX_PASSWORD"]
except KeyError:
print ("ERROR: Please set the environment variables JMX_USER and JMX_PASSWORD")
raise

def setUp(self):
os.chdir(os.path.dirname(os.path.abspath(__file__)))
th.remove_f(self.result_file_1)
th.remove_files("StreamsLogsJob*.tgz")

def tearDown(self):
os.chdir(os.path.dirname(os.path.abspath(__file__)))
th.remove_f(self.result_file_1)
th.stop_monitor()
th.rm_app_config()

def test_distributed(self):
os.chdir(os.path.dirname(os.path.abspath(__file__)))

th.create_app_config()
th.make_applications()
th.start_monitor()
th.wait_for_file(self.result_file_1)
err = th.test_result_file(self.result_file_1)
self.assertEqual(err, 0)


if __name__ == '__main__':
unittest.main()

13 changes: 12 additions & 1 deletion tests/spl-test/build.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<project name="streamsx.monitoring.spl.tests" default="test" basedir=".">

<property environment="env" />
<property name="microservices" location="../../microservices" />

<target name="clean" depends="cleantemp,cleantestprojects">
<target name="clean" depends="cleantemp,cleantestprojects,cleanmicroservices">
</target>

<target name="cleantemp">
Expand All @@ -21,6 +22,7 @@
<dirset dir="JobStatusMonitor" includes="test*"/>
<dirset dir="LogSource" includes="test*"/>
<dirset dir="MetricsSource" includes="test*"/>
<dirset dir="MetricsMonitor" includes="test*"/>
</subant>
</target>

Expand All @@ -33,6 +35,15 @@
</exec>
</target>

<target name="cleanmicroservices">
<exec executable="make" failonerror="true" dir="${microservices}">
<arg value="-f" />
<arg value="Makefile" />
<arg value="clean" />
</exec>
</target>


<target name="init">
<fail unless="env.JMX_USER" message="Please set environment variables JMX_USER and JMX_PASSWORD for the user name and password for JMX connection."/>
<fail unless="env.JMX_PASSWORD" message="Please set environment variables JMX_USER and JMX_PASSWORD for the user name and password for JMX connection."/>
Expand Down

0 comments on commit dfa43ea

Please sign in to comment.