forked from apache/skywalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide thread monitor create task feature (apache#4145)
* provide thread monitor task service to create * provide thread monitor task GraphQL implements * 1. change thread monitor field names 2. fix `getThreadMonitorTaskList` query time bucket error * provide config stream processor * update submodule `query-protocol` * resolve e2e-mysql error * remove useless storage interface method. * rename `ThreadMonitorTask` to `ProfileTask` * change e2e-profile to the top level * fix profile test analyze error * remove StringUtil#isBlank. * 1. remove create profile task duration unit 2. remove GraphQL getTask list duration field 3. add `profileTaskQueryMaxSize` in `storage` -> `elasticsearch(7)` configuration, default get 200 profile task * provide e2e different storage tests * 1. fix rat check 2. remove DurationUtils.java#toSecond 3. remove ProfileTaskQueryEs7DAO * fix e2e code format error * provide es6 and es7 storage e2e tests * change e2e profile es module artifactId Co-authored-by: kezhenxu94 <[email protected]>
- Loading branch information
Showing
68 changed files
with
3,514 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...c/main/java/org/apache/skywalking/oap/server/core/profile/ProfileTaskMutationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* 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.skywalking.oap.server.core.profile; | ||
|
||
import org.apache.skywalking.apm.util.StringUtil; | ||
import org.apache.skywalking.oap.server.core.analysis.Downsampling; | ||
import org.apache.skywalking.oap.server.core.analysis.TimeBucket; | ||
import org.apache.skywalking.oap.server.core.analysis.worker.NoneStreamingProcessor; | ||
import org.apache.skywalking.oap.server.core.profile.entity.ProfileTaskCreationResult; | ||
import org.apache.skywalking.oap.server.core.query.entity.ProfileTask; | ||
import org.apache.skywalking.oap.server.core.storage.StorageModule; | ||
import org.apache.skywalking.oap.server.core.storage.profile.IProfileTaskQueryDAO; | ||
import org.apache.skywalking.oap.server.library.module.ModuleManager; | ||
import org.apache.skywalking.oap.server.library.module.Service; | ||
import org.apache.skywalking.oap.server.library.util.CollectionUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class ProfileTaskMutationService implements Service { | ||
|
||
private final ModuleManager moduleManager; | ||
private IProfileTaskQueryDAO profileTaskQueryDAO; | ||
|
||
public ProfileTaskMutationService(ModuleManager moduleManager) { | ||
this.moduleManager = moduleManager; | ||
} | ||
|
||
private IProfileTaskQueryDAO getProfileTaskDAO() { | ||
if (profileTaskQueryDAO == null) { | ||
this.profileTaskQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IProfileTaskQueryDAO.class); | ||
} | ||
return profileTaskQueryDAO; | ||
} | ||
|
||
/** | ||
* create new profile task | ||
* @param serviceId monitor service id | ||
* @param endpointName monitor endpoint name | ||
* @param monitorStartTime create fix start time task when it's bigger 0 | ||
* @param monitorDuration monitor task duration(minute) | ||
* @param minDurationThreshold min duration threshold | ||
* @param dumpPeriod dump period | ||
* @return task create result | ||
*/ | ||
public ProfileTaskCreationResult createTask(final int serviceId, final String endpointName, final long monitorStartTime, final int monitorDuration, | ||
final int minDurationThreshold, final int dumpPeriod) throws IOException { | ||
|
||
// calculate task execute range | ||
long taskStartTime = monitorStartTime > 0 ? monitorStartTime : System.currentTimeMillis(); | ||
long taskEndTime = taskStartTime + TimeUnit.MINUTES.toMillis(monitorDuration); | ||
|
||
// check data | ||
final String errorMessage = checkDataSuccess(serviceId, endpointName, taskStartTime, taskEndTime, monitorDuration, minDurationThreshold, dumpPeriod); | ||
if (errorMessage != null) { | ||
return ProfileTaskCreationResult.builder().errorReason(errorMessage).build(); | ||
} | ||
|
||
// create task | ||
final long createTime = System.currentTimeMillis(); | ||
final ProfileTaskNoneStream task = new ProfileTaskNoneStream(); | ||
task.setServiceId(serviceId); | ||
task.setEndpointName(endpointName.trim()); | ||
task.setStartTime(taskStartTime); | ||
task.setDuration(monitorDuration); | ||
task.setMinDurationThreshold(minDurationThreshold); | ||
task.setDumpPeriod(dumpPeriod); | ||
task.setCreateTime(createTime); | ||
task.setTimeBucket(TimeBucket.getRecordTimeBucket(taskEndTime)); | ||
NoneStreamingProcessor.getInstance().in(task); | ||
|
||
return ProfileTaskCreationResult.builder().id(task.id()).build(); | ||
} | ||
|
||
private String checkDataSuccess(final Integer serviceId, final String endpointName, final long monitorStartTime, final long monitorEndTime, final int monitorDuration, | ||
final int minDurationThreshold, final int dumpPeriod) throws IOException { | ||
// basic check | ||
if (serviceId == null) { | ||
return "service cannot be null"; | ||
} | ||
if (StringUtil.isEmpty(endpointName)) { | ||
return "endpoint name cannot be empty"; | ||
} | ||
if (monitorEndTime - monitorStartTime < TimeUnit.MINUTES.toMillis(1)) { | ||
return "monitor duration must greater than 1 minutes"; | ||
} | ||
if (minDurationThreshold < 0) { | ||
return "min duration threshold must greater than or equals zero"; | ||
} | ||
|
||
// check limit | ||
// The duration of the monitoring task cannot be greater than 15 minutes | ||
final long maxMonitorDurationInSec = TimeUnit.MINUTES.toSeconds(15); | ||
if (monitorDuration > maxMonitorDurationInSec) { | ||
return "The duration of the monitoring task cannot be greater than 15 minutes"; | ||
} | ||
|
||
// dump period must be greater than or equals 10 milliseconds | ||
if (dumpPeriod < 10) { | ||
return "dump period must be greater than or equals 10 milliseconds"; | ||
} | ||
|
||
// Each service can monitor up to 1 endpoints during the execution of tasks | ||
long startTimeBucket = TimeBucket.getTimeBucket(monitorStartTime, Downsampling.Second); | ||
long endTimeBucket = TimeBucket.getTimeBucket(monitorEndTime, Downsampling.Second); | ||
final List<ProfileTask> alreadyHaveTaskList = getProfileTaskDAO().getTaskList(serviceId, null, startTimeBucket, endTimeBucket, 1); | ||
if (CollectionUtils.isNotEmpty(alreadyHaveTaskList)) { | ||
// if any task time bucket in this range, means already have task, because time bucket is base on task end time | ||
return "current service already has monitor task execute at this time"; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
...re/src/main/java/org/apache/skywalking/oap/server/core/profile/ProfileTaskNoneStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.skywalking.oap.server.core.profile; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.skywalking.oap.server.core.Const; | ||
import org.apache.skywalking.oap.server.core.analysis.Stream; | ||
import org.apache.skywalking.oap.server.core.analysis.config.NoneStream; | ||
import org.apache.skywalking.oap.server.core.analysis.worker.NoneStreamingProcessor; | ||
import org.apache.skywalking.oap.server.core.source.ScopeDeclaration; | ||
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; | ||
import org.apache.skywalking.oap.server.core.storage.annotation.Column; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.PROFILE_TASK; | ||
|
||
/** | ||
* profile task database bean, use none stream | ||
* | ||
* @author MrPro | ||
*/ | ||
@Getter | ||
@Setter | ||
@ScopeDeclaration(id = PROFILE_TASK, name = "ProfileTask") | ||
@Stream(name = ProfileTaskNoneStream.INDEX_NAME, scopeId = PROFILE_TASK, builder = ProfileTaskNoneStream.Builder.class, processor = NoneStreamingProcessor.class) | ||
public class ProfileTaskNoneStream extends NoneStream { | ||
|
||
public static final String INDEX_NAME = "profile_task"; | ||
public static final String SERVICE_ID = "service_id"; | ||
public static final String ENDPOINT_NAME = "endpoint_name"; | ||
public static final String START_TIME = "start_time"; | ||
public static final String DURATION = "duration"; | ||
public static final String MIN_DURATION_THRESHOLD = "min_duration_threshold"; | ||
public static final String DUMP_PERIOD = "dump_period"; | ||
public static final String CREATE_TIME = "create_time"; | ||
|
||
@Override | ||
public String id() { | ||
return getCreateTime() + Const.ID_SPLIT + getServiceId(); | ||
} | ||
|
||
@Column(columnName = SERVICE_ID) private int serviceId; | ||
@Column(columnName = ENDPOINT_NAME) private String endpointName; | ||
@Column(columnName = START_TIME) private long startTime; | ||
@Column(columnName = DURATION) private int duration; | ||
@Column(columnName = MIN_DURATION_THRESHOLD) private int minDurationThreshold; | ||
@Column(columnName = DUMP_PERIOD) private int dumpPeriod; | ||
@Column(columnName = CREATE_TIME) private long createTime; | ||
|
||
public static class Builder implements StorageBuilder<ProfileTaskNoneStream> { | ||
|
||
@Override | ||
public ProfileTaskNoneStream map2Data(Map<String, Object> dbMap) { | ||
final ProfileTaskNoneStream record = new ProfileTaskNoneStream(); | ||
record.setServiceId(((Number)dbMap.get(SERVICE_ID)).intValue()); | ||
record.setEndpointName((String)dbMap.get(ENDPOINT_NAME)); | ||
record.setStartTime(((Number)dbMap.get(START_TIME)).longValue()); | ||
record.setDuration(((Number)dbMap.get(DURATION)).intValue()); | ||
record.setMinDurationThreshold(((Number)dbMap.get(MIN_DURATION_THRESHOLD)).intValue()); | ||
record.setDumpPeriod(((Number)dbMap.get(DUMP_PERIOD)).intValue()); | ||
record.setCreateTime(((Number)dbMap.get(CREATE_TIME)).longValue()); | ||
record.setTimeBucket(((Number)dbMap.get(TIME_BUCKET)).longValue()); | ||
return record; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> data2Map(ProfileTaskNoneStream storageData) { | ||
final HashMap<String, Object> map = new HashMap<>(); | ||
map.put(SERVICE_ID, storageData.getServiceId()); | ||
map.put(ENDPOINT_NAME, storageData.getEndpointName()); | ||
map.put(START_TIME, storageData.getStartTime()); | ||
map.put(DURATION, storageData.getDuration()); | ||
map.put(MIN_DURATION_THRESHOLD, storageData.getMinDurationThreshold()); | ||
map.put(DUMP_PERIOD, storageData.getDumpPeriod()); | ||
map.put(CREATE_TIME, storageData.getCreateTime()); | ||
map.put(TIME_BUCKET, storageData.getTimeBucket()); | ||
return map; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.