Skip to content

[ISSUE #5137] update connector runtime v2 module #5138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading