umustafi commented on code in PR #3843:
URL: https://github.com/apache/gobblin/pull/3843#discussion_r1417796232
##########
gobblin-metrics-libs/gobblin-metrics-base/src/main/java/org/apache/gobblin/metrics/event/EventSubmitter.java:
##########
@@ -204,4 +222,74 @@ public static void submit(Optional<EventSubmitter>
submitter, String name, Map<S
public TimingEvent getTimingEvent(String name) {
return new TimingEvent(this, name);
}
+
+ public List<Tag<?>> getTags() {
+ return this.metricContext.isPresent() ?
+ this.metricContext.get().getTags() :
+ null;
+ }
+
+ /**
+ * Serializer for jackson that does its best to serialize a {@link
EventSubmitter} from a json representation.
+ * NOTE: Due to the nested bidirectional nature of the {@link
org.apache.gobblin.metrics.InnerMetricContext} and
+ * usage of {@link Gauge} this is not a perfect serialization but it is
sufficient for passing important monitoring
+ * like original Azkaban flow name and gobblin job id
+ */
+ public static class Serializer extends StdSerializer<EventSubmitter> {
+ public static final String CLASS_KEY = "class";
+ public Serializer() {
+ this(null);
+ }
+
+ public Serializer(Class<EventSubmitter> t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(EventSubmitter value, JsonGenerator jgen,
SerializerProvider provider)
+ throws IOException {
+ jgen.writeStartObject();
+ jgen.writeStringField("callerClass", value.getTags().stream().filter(tag
-> tag.getKey().equals(
+ CLASS_KEY)).findAny().map(tag ->
String.valueOf(tag.getValue())).orElse(getClass().getName()));
+ jgen.writeStringField("namespace", value.getNamespace());
+ jgen.writeObjectField("tags", value.getTags());
+ jgen.writeEndObject();
+ }
+ }
+
+ public static class Deserializer extends StdDeserializer<EventSubmitter> {
+ public Deserializer() {
+ this(null);
+ }
+
+ public Deserializer(Class<EventSubmitter> t) {
+ super(t);
+ }
+
+ @Override
+ public EventSubmitter deserialize(JsonParser jp, DeserializationContext
ctxt)
+ throws IOException {
+ JsonNode node = jp.getCodec().readTree(jp);
+
+ String namespace = node.get("namespace").asText();
+ ObjectMapper objectMapper = new ObjectMapper();
+ JavaType type =
objectMapper.getTypeFactory().constructCollectionType(List.class, Tag.class);
+ List<Tag<?>> tags = objectMapper.readValue(node.get("tags").toString(),
type);
+
+ String callerClassStr = node.get("callerClass").asText();
Review Comment:
let's make these keys into variables to re-use in serialize/deserialize
##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/workflows/helloworld/GreetingWorkflowImpl.java:
##########
@@ -41,16 +50,19 @@ public class GreetingWorkflowImpl implements
GreetingWorkflow {
*
* The activity options that were defined above are passed in as a
parameter.
*/
- private final FormatActivity activity =
Workflow.newActivityStub(FormatActivity.class, options);
+ private final FormatActivity formatActivity =
Workflow.newActivityStub(FormatActivity.class, options);
+ private final GobblinTrackingEventActivity timerActivity =
Workflow.newActivityStub(GobblinTrackingEventActivity.class, options);
// This is the entry point to the Workflow.
@Override
- public String getGreeting(String name) {
-
+ public String getGreeting(String name, EventSubmitter eventSubmitter) {
/**
- * If there were other Activity methods they would be orchestrated
here or from within other Activities.
- * This is a blocking call that returns only after the activity has
completed.
+ * Example of the {@link TemporalEventTimer.Factory} invoking child
activity for instrumentation.
*/
- return activity.composeGreeting(name);
+ TemporalEventTimer.Factory timerFactory = new
TemporalEventTimer.Factory(timerActivity, eventSubmitter);
+ try (TemporalEventTimer timer = timerFactory.get("getGreetingTime")) {
+ LOG.info("Executing getGreeting");
Review Comment:
add information about which flow this is to be able to track this on a per
flow basis
##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/workflows/timing/TemporalEventTimer.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.gobblin.temporal.workflows.timing;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import io.temporal.workflow.Workflow;
+
+import org.apache.gobblin.metrics.event.EventSubmitter;
+import org.apache.gobblin.metrics.event.GobblinEventBuilder;
+import org.apache.gobblin.metrics.event.TimingEvent;
+import
org.apache.gobblin.temporal.workflows.trackingevent.activity.GobblinTrackingEventActivity;
+
+
+/**
+ * Boiler plate for tracking elapsed time of events that is compatible with
{@link Workflow}
+ * by using activities to record time
+ */
+public class TemporalEventTimer implements EventTimer {
+ private final GobblinTrackingEventActivity trackingEventActivity;
+ private final EventSubmitter eventSubmitter;
+ private final GobblinEventBuilder eventBuilder;
+
+ private Instant startTime;
+
+ private TemporalEventTimer(GobblinTrackingEventActivity
trackingEventActivity, EventSubmitter eventSubmitter, GobblinEventBuilder
eventBuilder) {
+ this.trackingEventActivity = trackingEventActivity;
+ this.eventBuilder = eventBuilder;
+ this.eventSubmitter = eventSubmitter;
+ this.startTime = getCurrentTime();
+ }
+
+ @Override
+ public void close() {
+ close(getCurrentTime());
+ }
+
+ private void close(Instant endTime) {
+ this.eventBuilder.addMetadata(EventSubmitter.EVENT_TYPE,
TimingEvent.METADATA_TIMING_EVENT);
+ this.eventBuilder.addMetadata(TimingEvent.METADATA_START_TIME,
Long.toString(this.startTime.toEpochMilli()));
Review Comment:
is this not added upon start or construction? if not, why is that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]