Skip to content

Commit

Permalink
[ISSUE #5137] update connector runtime v2 module (#5138)
Browse files Browse the repository at this point in the history
* [ISSUE #5137] update connector runtime v2 module

* fix checkStyle error
  • Loading branch information
xwm1992 authored Dec 9, 2024
1 parent 831fd72 commit 293a61e
Show file tree
Hide file tree
Showing 13 changed files with 872 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.eventmesh.common.remote.request;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString
public class ReportMonitorRequest extends BaseRemoteRequest {
private String taskID;
private String jobID;
private String address;
private String connectorStage;
private String transportType;
private long totalReqNum;
private long totalTimeCost;
private long maxTimeCost;
private long avgTimeCost;
private double tps;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.eventmesh.openconnect.api.monitor;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
public abstract class AbstractConnectorMonitor implements Monitor {

private final String taskId;
private final String jobId;
private final String ip;
private final LongAdder totalRecordNum;
private final LongAdder totalTimeCost;
protected final AtomicLong startTime;
private final AtomicLong maxTimeCost;
private long averageTime = 0;
private double tps = 0;

public AbstractConnectorMonitor(String taskId, String jobId, String ip) {
this.taskId = taskId;
this.jobId = jobId;
this.ip = ip;
this.totalRecordNum = new LongAdder();
this.totalTimeCost = new LongAdder();
this.startTime = new AtomicLong(System.currentTimeMillis());
this.maxTimeCost = new AtomicLong();
}

@Override
public synchronized void recordProcess(long timeCost) {
totalRecordNum.increment();
totalTimeCost.add(timeCost);
maxTimeCost.updateAndGet(max -> Math.max(max, timeCost));
}

@Override
public synchronized void recordProcess(int recordCount, long timeCost) {
totalRecordNum.add(recordCount);
totalTimeCost.add(timeCost);
maxTimeCost.updateAndGet(max -> Math.max(max, timeCost));
}

@Override
public synchronized void printMetrics() {
long totalRecords = totalRecordNum.sum();
long totalCost = totalTimeCost.sum();
averageTime = totalRecords > 0 ? totalCost / totalRecords : 0;
long elapsedTime = (System.currentTimeMillis() - startTime.get()) / 1000; // in seconds
tps = elapsedTime > 0 ? (double) totalRecords / elapsedTime : 0;

log.info("========== Metrics ==========");
log.info("TaskId: {}|JobId: {}|ip: {}", taskId, jobId, ip);
log.info("Total records: {}", totalRecordNum);
log.info("Total time (ms): {}", totalTimeCost);
log.info("Max time per record (ms): {}", maxTimeCost);
log.info("Average time per record (ms): {}", averageTime);
log.info("TPS: {}", tps);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.eventmesh.openconnect.api.monitor;

/**
* Monitor Interface.
* All monitors should implement this interface.
*/
public interface Monitor {
void recordProcess(long timeCost);

void recordProcess(int recordCount, long timeCost);

void printMetrics();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.eventmesh.openconnect.api.monitor;

import java.util.ArrayList;
import java.util.List;

import lombok.Getter;

public class MonitorRegistry {

@Getter
private static final List<Monitor> monitors = new ArrayList<>();

public static void registerMonitor(Monitor monitor) {
monitors.add(monitor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static void main(String[] args) {
long start = System.currentTimeMillis();
runtimeInstance.shutdown();
long end = System.currentTimeMillis();

log.info("runtime shutdown cost {}ms", end - start);
} catch (Exception e) {
log.error("exception when shutdown {}", e.getMessage(), e);
Expand Down
Loading

0 comments on commit 293a61e

Please sign in to comment.