Skip to content

Commit

Permalink
Deprecated HystrixUtilizationJsonStream in favor of compositional ser…
Browse files Browse the repository at this point in the history
…ialization
  • Loading branch information
Matt Jacobs committed Jun 22, 2016
1 parent bf924aa commit 5370e7b
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet;
import com.netflix.hystrix.metric.consumer.HystrixDashboardStream;
import com.netflix.hystrix.metric.serial.SerialHystrixDashboardData;
import com.netflix.hystrix.serial.SerialHystrixDashboardData;
import rx.Observable;
import rx.functions.Func1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet;
import com.netflix.hystrix.metric.HystrixRequestEvents;
import com.netflix.hystrix.metric.HystrixRequestEventsStream;
import com.netflix.hystrix.metric.serial.SerialHystrixRequestEvents;
import com.netflix.hystrix.serial.SerialHystrixRequestEvents;
import rx.Observable;
import rx.functions.Func1;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.hystrix.config.HystrixConfiguration;
import com.netflix.hystrix.config.HystrixConfigurationStream;
import com.netflix.hystrix.metric.serial.SerialHystrixConfiguration;
import com.netflix.hystrix.serial.SerialHystrixConfiguration;
import rx.Observable;
import rx.functions.Func1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
* <li> {@link HystrixUtilizationSseServlet} for mapping a specific URL to this data as an SSE stream
* <li> Consumer of your choice that wants control over where to embed this stream
* </ul>
*
* @deprecated Instead, prefer mapping your preferred serialization on top of {@link HystrixUtilizationStream#observe()}.
*/
@Deprecated //since 1.5.4
public class HystrixUtilizationJsonStream {
private final Func1<Integer, Observable<HystrixUtilization>> streamGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.hystrix.metric.sample.HystrixUtilization;
import com.netflix.hystrix.metric.sample.HystrixUtilizationStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.hystrix.serial.SerialHystrixUtilization;
import rx.Observable;
import rx.functions.Func1;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -51,7 +49,6 @@
public class HystrixUtilizationSseServlet extends HystrixSampleSseServlet {

private static final long serialVersionUID = -7812908330777694972L;
private static final Logger logger = LoggerFactory.getLogger(HystrixUtilizationSseServlet.class);

/* used to track number of connections and throttle */
private static AtomicInteger concurrentConnections = new AtomicInteger(0);
Expand All @@ -66,12 +63,7 @@ public HystrixUtilizationSseServlet() {
super(sampleStream.map(new Func1<HystrixUtilization, String>() {
@Override
public String call(HystrixUtilization hystrixUtilization) {
try {
return HystrixUtilizationJsonStream.convertToJson(hystrixUtilization);
} catch (IOException ioe) {
logger.error("IOException creating JSON from HystrixUtilization", ioe);
return "<IOException> : " + ioe.getMessage();
}
return SerialHystrixUtilization.toJsonString(hystrixUtilization);
}
}), pausePollerThreadDelayInMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import com.netflix.hystrix.metric.HystrixRequestEventsStream;
import com.netflix.hystrix.metric.consumer.HystrixDashboardStream;
import com.netflix.hystrix.metric.sample.HystrixUtilizationStream;
import com.netflix.hystrix.metric.serial.SerialHystrixConfiguration;
import com.netflix.hystrix.metric.serial.SerialHystrixDashboardData;
import com.netflix.hystrix.metric.serial.SerialHystrixRequestEvents;
import com.netflix.hystrix.metric.serial.SerialHystrixUtilization;
import com.netflix.hystrix.serial.SerialHystrixConfiguration;
import com.netflix.hystrix.serial.SerialHystrixDashboardData;
import com.netflix.hystrix.serial.SerialHystrixRequestEvents;
import com.netflix.hystrix.serial.SerialHystrixUtilization;
import io.reactivesocket.Frame;
import io.reactivesocket.Payload;
import rx.Observable;
Expand Down
13 changes: 7 additions & 6 deletions hystrix-data-stream/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ targetCompatibility = JavaVersion.VERSION_1_6

dependencies {
compile project(':hystrix-core')

compile 'com.fasterxml.jackson.core:jackson-core:latest.release'
compile 'com.fasterxml.jackson.core:jackson-databind:latest.release'
compile 'com.fasterxml.jackson.core:jackson-annotations:latest.release'
compile 'com.fasterxml.jackson.module:jackson-module-afterburner:latest.release'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:latest.release'

//if we bump into the the 2.8.0 series, we are forced to use Java7
compile 'com.fasterxml.jackson.core:jackson-core:2.7.5'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.5'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.5'
compile 'com.fasterxml.jackson.module:jackson-module-afterburner:2.7.5'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.7.5'

testCompile 'junit:junit-dep:4.10'
testCompile 'org.mockito:mockito-all:1.9.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.metric.serial;
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.metric.serial;
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.netflix.hystrix.HystrixCircuitBreaker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.metric.serial;
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.metric.serial;
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.netflix.hystrix.ExecutionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.metric.serial;
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.config.HystrixConfiguration;
import com.netflix.hystrix.metric.sample.HystrixCommandUtilization;
import com.netflix.hystrix.metric.sample.HystrixThreadPoolUtilization;
import com.netflix.hystrix.metric.sample.HystrixUtilization;
Expand All @@ -28,6 +29,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -42,8 +44,34 @@ public static byte[] toBytes(HystrixUtilization utilization) {

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator json = cborFactory.createGenerator(bos);
JsonGenerator cbor = cborFactory.createGenerator(bos);

serializeUtilization(utilization, cbor);

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
}

public static String toJsonString(HystrixUtilization utilization) {
StringWriter jsonString = new StringWriter();

try {
JsonGenerator json = jsonFactory.createGenerator(jsonString);

serializeUtilization(utilization, json);
} catch (Exception e) {
throw new RuntimeException(e);
}

return jsonString.getBuffer().toString();
}

private static void serializeUtilization(HystrixUtilization utilization, JsonGenerator json) {
try {
json.writeStartObject();
json.writeStringField("type", "HystrixUtilization");
json.writeObjectFieldStart("commands");
Expand All @@ -64,13 +92,9 @@ public static byte[] toBytes(HystrixUtilization utilization) {
json.writeEndObject();
json.writeEndObject();
json.close();

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
}

public static HystrixUtilization fromByteBuffer(ByteBuffer bb) {
Expand Down
Loading

0 comments on commit 5370e7b

Please sign in to comment.