Skip to content

Commit

Permalink
HAWKULAR-1153 Initial support enable/disable/update collection interv…
Browse files Browse the repository at this point in the history
…als (#290)

- Add command to handle new cmdgw request/response for updating metric collection intervals
  - this command will return the server-refresh indicator but will not itself activate the flag
  - this should be EAP6 compatible
- Change start command to perform everything async
  - add optional delay attribute for deferred re/start
  - add optional refresh attribute to restart with the latest runtime config
- Add ITest to ensure immutable agents block attribute update (standalone and domain)
- Update ExportJdrCommand to workaround https://issues.jboss.org/browse/WFLY-8161, which
  would break any future agent subsystem adds
- Fix bug in MonitorService start logic, need to treat RELOAD_REQUIRED and RESTART_REQUIRED like RUNNING in certain conditionals
- (from mazz) try a different approach to synchronize starting and stopping
  • Loading branch information
jshaughn authored and jmazzitelli committed Feb 19, 2017
1 parent 3af44fa commit dcc93eb
Show file tree
Hide file tree
Showing 26 changed files with 868 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public abstract static class AbstractOperationBuilder<T extends AbstractOperatio
protected final ModelNode baseNode = new ModelNode();

public T allowResourceServiceRestart() {
return operationHeader(ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART, true);
return allowResourceServiceRestart(true);
}

public T allowResourceServiceRestart(boolean allow) {
return operationHeader(ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART, allow);
}

public ModelNode build() {
Expand Down Expand Up @@ -341,6 +345,12 @@ public WriteAttributeOperationBuilder<WriteAttributeOperationBuilder<?>> writeAt
(CompositeOperationBuilder<CompositeOperationBuilder<?>>) this);
}

@SuppressWarnings("unchecked")
public ByNameOperationBuilder<ByNameOperationBuilder<?>> byNameOperation(String operationName) {
return new ByNameOperationBuilder<>(
(CompositeOperationBuilder<CompositeOperationBuilder<?>>) this, operationName);
}

}

public static class MapPutOperationBuilder<T extends MapPutOperationBuilder<?>>
Expand Down Expand Up @@ -562,6 +572,7 @@ public T childType(String childType) {
return (T) this;
}

@Override
protected StringListOperationResult<StringListOperationResult<?>> createResult(ModelNode request,
ModelNode result) {
return new StringListOperationResult<StringListOperationResult<?>>(request, result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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.
*/
package org.hawkular.agent.ws.test;

import org.hamcrest.CoreMatchers;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.ExpectedEvent;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.ExpectedEvent.ExpectedMessage;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.PatternMatcher;
import org.hawkular.dmrclient.Address;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.paths.CanonicalPath;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.dmr.ModelNode;
import org.testng.Assert;
import org.testng.annotations.Test;

import okhttp3.ws.WebSocket;

/**
* @author <a href="https://github.com/jshaughn">Jay Shaughnessy</a>
*/
public class ImmutableITest extends AbstractCommandITest {
public static final String GROUP = "ImmutableITest";

// because this test will update the agent to be immutable, it must RUN AFTER THE OTHER ITESTS!
@Test(groups = { GROUP }, dependsOnGroups = {
DatasourceCommandITest.GROUP,
ExecuteOperationCommandITest.GROUP,
ExportJdrCommandITest.GROUP,
JdbcDriverCommandITest.GROUP,
StandaloneDeployApplicationITest.GROUP,
StatisticsControlCommandITest.GROUP,
UpdateCollectionIntervalsCommandITest.GROUP
})
public void testImmutableUpdate() throws Throwable {
waitForAccountsAndInventory();

CanonicalPath wfPath = getHawkularWildFlyServerResourcePath();

try (ModelControllerClient mcc = newHawkularModelControllerClient()) {

assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/metric-set-dmr=WildFly Memory Metrics/metric-dmr=Heap Max")
.getAddressNode(),
"interval",
"1");

ModelNode agentAddress = Address.parse("/subsystem=hawkular-wildfly-agent").getAddressNode();
assertNodeAttributeEquals(mcc, agentAddress, "immutable", "${hawkular.agent.immutable:false}");
writeNodeAttribute(mcc, agentAddress, "immutable", "true");
assertNodeAttributeEquals(mcc, agentAddress, "immutable", "true");

Assert.assertTrue(waitForAgent(mcc), "Expected agent to be started.");

Resource agent = getResource(
"/traversal/f;" + hawkularFeedId + "/type=rt;"
+ "id=Hawkular%20WildFly%20Agent/rl;defines/type=r",
(r -> r.getId() != null));

String req = "UpdateCollectionIntervalsRequest={\"authentication\":" + authentication + ", "
+ "\"resourcePath\":\"" + agent.getPath().toString() + "\","
+ "\"metricTypes\":{\"WildFly Memory Metrics~Heap Max\":\"77\"}"
+ "}";
String response = ".*\"status\":\"ERROR\""
+ ".*\"message\":\"Could not perform.*Command not allowed because the agent is immutable.*";

ExpectedEvent expectedEvent = new ExpectedMessage(new PatternMatcher(response),
CoreMatchers.equalTo(WebSocket.TEXT), TestWebSocketClient.Answer.CLOSE);

try (TestWebSocketClient testClient = TestWebSocketClient.builder()
.url(baseGwUri + "/ui/ws")
.expectWelcome(req)
.expectGenericSuccess(wfPath.ids().getFeedId())
.expectMessage(expectedEvent)
.expectClose()
.build()) {
testClient.validate(10000);
}

assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/metric-set-dmr=WildFly Memory Metrics/metric-dmr=Heap Max")
.getAddressNode(),
"interval",
"1");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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.
*/
package org.hawkular.agent.ws.test;

import org.hawkular.cmdgw.ws.test.TestWebSocketClient;
import org.hawkular.dmrclient.Address;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.paths.CanonicalPath;
import org.jboss.as.controller.client.ModelControllerClient;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* @author <a href="https://github.com/jshaughn">Jay Shaughnessy</a>
*/
public class UpdateCollectionIntervalsCommandITest extends AbstractCommandITest {
public static final String GROUP = "UpdateCollectionIntervalsCommandITest";

@Test(groups = { GROUP })
public void testUpdateCollectionIntervals() throws Throwable {
waitForAccountsAndInventory();

CanonicalPath wfPath = getHawkularWildFlyServerResourcePath();

try (ModelControllerClient mcc = newHawkularModelControllerClient()) {

assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/avail-set-dmr=Server Availability/avail-dmr=Server Availability")
.getAddressNode(),
"interval",
"30");

assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/metric-set-dmr=WildFly Memory Metrics/metric-dmr=NonHeap Used")
.getAddressNode(),
"interval",
"30");

Resource agent = getResource(
"/traversal/f;" + hawkularFeedId + "/type=rt;"
+ "id=Hawkular%20WildFly%20Agent/rl;defines/type=r",
(r -> r.getId() != null));

String req = "UpdateCollectionIntervalsRequest={\"authentication\":" + authentication + ", "
+ "\"resourcePath\":\"" + agent.getPath().toString() + "\","
+ "\"metricTypes\":{\"WildFly Memory Metrics~NonHeap Used\":\"0\",\"Unknown~Metric\":\"666\"},"
+ "\"availTypes\":{\"Server Availability~Server Availability\":\"0\",\"Unknown~Avail\":\"666\"}"
+ "}";
String response = "UpdateCollectionIntervalsResponse={"
+ "\"resourcePath\":\"" + agent.getPath() + "\","
+ "\"destinationSessionId\":\"{{sessionId}}\","
+ "\"status\":\"OK\","
+ "\"message\":\"Performed [Update Collection Intervals] on a [DMR Nodes] given by Inventory path ["
+ agent.getPath() + "]\""
+ "}";

try (TestWebSocketClient testClient = TestWebSocketClient.builder()
.url(baseGwUri + "/ui/ws")
.expectWelcome(req)
.expectGenericSuccess(wfPath.ids().getFeedId())
.expectText(response, TestWebSocketClient.Answer.CLOSE)
.expectClose()
.build()) {
testClient.validate(10000);
}

// Make sure the agent reboots before executing other itests
Assert.assertTrue(waitForAgent(mcc), "Expected agent to be started.");

assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/avail-set-dmr=Server Availability/avail-dmr=Server Availability")
.getAddressNode(),
"interval",
"0");
assertNodeAttributeEquals(mcc,
Address.parse(
"/subsystem=hawkular-wildfly-agent/metric-set-dmr=WildFly Memory Metrics/metric-dmr=NonHeap Used")
.getAddressNode(),
"interval",
"0");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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.
*/
package org.hawkular.wildfly.agent.installer;

import org.hamcrest.CoreMatchers;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.ExpectedEvent;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.ExpectedEvent.ExpectedMessage;
import org.hawkular.cmdgw.ws.test.TestWebSocketClient.PatternMatcher;
import org.hawkular.dmrclient.Address;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.paths.CanonicalPath;
import org.hawkular.wildfly.agent.itest.util.AbstractITest;
import org.hawkular.wildfly.agent.itest.util.WildFlyClientConfig;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.dmr.ModelNode;
import org.testng.Assert;
import org.testng.annotations.Test;

import okhttp3.ws.WebSocket;

/**
* @author <a href="https://github.com/jshaughn">Jay Shaughnessy</a>
*/
public class DomainImmutableITest extends AbstractITest {
public static final String GROUP = "DomainImmutableITest";

// because this test will update the agent to be immutable, it must RUN AFTER THE OTHER ITESTS!
@Test(groups = { GROUP }, dependsOnGroups = {
AgentInstallerDomainITest.GROUP,
ControlDomainServersITest.GROUP,
DomainDeployApplicationITest.GROUP,
})
public void testImmutableUpdate() throws Throwable {
waitForAccountsAndInventory();

WildFlyClientConfig clientConfig = getPlainWildFlyClientConfig();
CanonicalPath wfPath = getHostController(clientConfig);

try (ModelControllerClient mcc = newPlainWildFlyModelControllerClient(clientConfig)) {

final String serverToTest = "server-one";
final String hostAgent = "/host=master/subsystem=hawkular-wildfly-agent";
final Address hostAgentAddress = Address.parse(hostAgent);
final ModelNode hostAgentNode = hostAgentAddress.getAddressNode();
final String hostAttr = hostAgent + "/metric-set-dmr=WildFly Memory Metrics/metric-dmr=Heap Max";
final Address hostAttrAddress = Address.parse(hostAttr);
final ModelNode hostAttrNode = hostAttrAddress.getAddressNode();

assertNodeAttributeEquals(mcc, hostAttrNode, "interval", "1");

assertNodeAttributeEquals(mcc, hostAgentNode, "immutable", "${hawkular.agent.immutable:false}");
writeNodeAttribute(mcc, hostAgentNode, "immutable", "true");
assertNodeAttributeEquals(mcc, hostAgentNode, "immutable", "true");

Assert.assertTrue(waitForAgent(mcc, hostAgentAddress), "Expected host agent to be started.");

Resource agent = getResource(
"/traversal/f;" + clientConfig.getFeedId() + "/type=rt;"
+ "id=Domain WildFly Server Controller/rl;defines/type=r",
(r -> r.getId().contains(serverToTest)));

String req = "UpdateCollectionIntervalsRequest={\"authentication\":" + authentication + ", "
+ "\"resourcePath\":\"" + agent.getPath().toString() + "\","
+ "\"metricTypes\":{\"WildFly Memory Metrics~Heap Max\":\"77\"}"
+ "}";
String response = ".*\"status\":\"ERROR\""
+ ".*\"message\":\"Could not perform.*Command not allowed because the agent is immutable.*";

ExpectedEvent expectedEvent = new ExpectedMessage(new PatternMatcher(response),
CoreMatchers.equalTo(WebSocket.TEXT), TestWebSocketClient.Answer.CLOSE);

try (TestWebSocketClient testClient = TestWebSocketClient.builder()
.url(baseGwUri + "/ui/ws")
.expectWelcome(req)
.expectGenericSuccess(wfPath.ids().getFeedId())
.expectMessage(expectedEvent)
.expectClose()
.build()) {
testClient.validate(10000);
}

assertNodeAttributeEquals(mcc, hostAttrNode, "interval", "1");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void configureAgent() throws Throwable {
// this update should automatically trigger an agent restart, the operation is flagged to re-read the config
writeNodeAttribute(mcc, addressActual, "interval", "0");
assertNodeAttributeEquals(mcc, addressActual, "interval", "0");

// Don't proceed with other tests until we're sure the shutdown has initiated
Thread.sleep(2000);
}

@Test(groups = { GROUP }, dependsOnMethods = { "configureAgent" })
Expand Down Expand Up @@ -189,7 +192,7 @@ private Collection<String> getDatasourceNames() {

@Test(dependsOnMethods = { "datasourcesAddedToInventory" })
public void datasourceMetricsCollected() throws Throwable {
long startTime = System.currentTimeMillis(); // limit to new metric data points
long startTime = System.currentTimeMillis();
String lastUrl = "";
int second = 1000;
int timeOutSeconds = 60;
Expand Down Expand Up @@ -231,8 +234,8 @@ public void datasourceMetricsCollected() throws Throwable {
// System.out.println("DisabledBody=" + body);
/* this should be enough to prove that the metric was not disabled */
if (body.contains("\"empty\":false")) {
String msg = String.format("Disabled Gauge gathered after [%d]s. url=[%s], data=%s",
timeOutSeconds, url, body);
String msg = String.format("Disabled Gauge gathered after [%d]ms. url=[%s], data=%s",
(System.currentTimeMillis() - startTime), url, body);
Assert.fail(msg);
}
}
Expand Down
Loading

0 comments on commit dcc93eb

Please sign in to comment.