Skip to content

Commit

Permalink
Provide thread monitor create task feature (apache#4145)
Browse files Browse the repository at this point in the history
* 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
2 people authored and wu-sheng committed Dec 31, 2019
1 parent c5827f8 commit d38a8ea
Show file tree
Hide file tree
Showing 68 changed files with 3,514 additions and 40 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ jobs:
./mvnw -Dcheckstyle.skip -Drat.skip -T2 -Dmaven.compile.fork -Dmaven.compiler.maxmem=3072 -DskipTests clean install
./mvnw -f test/e2e/pom.xml -pl e2e-base clean install
- name: 6.x Agents & 7.x Backend
run: export E2E_VERSION=jdk8-1.3 && bash -x test/e2e/run.sh e2e-6.x-agent-7.x-oap-compatibility
run: export E2E_VERSION=jdk8-1.3 && bash -x test/e2e/run.sh e2e-6.x-agent-7.x-oap-compatibility

Profile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Set environment
run: export MAVEN_OPTS='-Dmaven.repo.local=~/.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:-UseGCOverheadLimit -Xmx3g'
- name: Compile & Install Test Codes
run: |
./mvnw checkstyle:check apache-rat:check
./mvnw -Dcheckstyle.skip -Drat.skip -T2 -Dmaven.compile.fork -Dmaven.compiler.maxmem=3072 -DskipTests clean install
./mvnw -f test/e2e/pom.xml -pl e2e-base clean install
- name: Profile Tests H2(JDK8)
run: export E2E_VERSION=jdk8-1.3 && bash -x test/e2e/run.sh e2e-profile/e2e-profile-h2-test-runner
- name: Profile Tests MySQL(JDK8)
run: export E2E_VERSION=jdk8-1.3 && bash -x test/e2e/run.sh e2e-profile/e2e-profile-mysql-test-runner
- name: Profile Tests ES6(JDK8)
run: export E2E_VERSION=jdk8-1.3 && bash -x test/e2e/run.sh e2e-profile/e2e-profile-es-test-runner
- name: Profile Tests ES7(JDK8)
run: export E2E_VERSION=jdk8-1.3 DIST_PACKAGE=apache-skywalking-apm-bin-es7.tar.gz ES_VERSION=7.4.2 && bash -x test/e2e/run.sh e2e-profile/e2e-profile-es-test-runner
2 changes: 2 additions & 0 deletions dist-material/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ storage:
# resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
# metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
# segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
# profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
# elasticsearch7:
# nameSpace: ${SW_NAMESPACE:""}
# clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
Expand All @@ -116,6 +117,7 @@ storage:
# resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
# metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
# segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
# profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
h2:
driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
Expand Down
1 change: 1 addition & 0 deletions docker/oap/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ cat <<EOT >> ${var_application_file}
resultWindowMaxSize: \${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: \${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: \${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: \${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
EOT
}

Expand Down
1 change: 1 addition & 0 deletions docs/en/setup/backend/backend-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ storage:
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ storage:
# resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
# metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
# segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
# profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
# advanced: ${SW_STORAGE_ES_ADVANCED:""}
elasticsearch7:
nameSpace: ${SW_NAMESPACE:""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.config.DownsamplingConfigService;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.query.AggregationQueryService;
import org.apache.skywalking.oap.server.core.query.AlarmQueryService;
import org.apache.skywalking.oap.server.core.query.LogQueryService;
import org.apache.skywalking.oap.server.core.query.MetadataQueryService;
import org.apache.skywalking.oap.server.core.query.MetricQueryService;
import org.apache.skywalking.oap.server.core.query.TopNRecordsQueryService;
import org.apache.skywalking.oap.server.core.query.TopologyQueryService;
import org.apache.skywalking.oap.server.core.query.TraceQueryService;
import org.apache.skywalking.oap.server.core.profile.ProfileTaskMutationService;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
Expand Down Expand Up @@ -78,12 +72,18 @@ public CoreModule() {
addRegisterService(classes);
addCacheService(classes);
addQueryService(classes);
addProfileService(classes);

classes.add(CommandService.class);

return classes.toArray(new Class[] {});
}

private void addProfileService(List<Class> classes) {
classes.add(ProfileTaskMutationService.class);
classes.add(ProfileTaskQueryService.class);
}

private void addQueryService(List<Class> classes) {
classes.add(TopologyQueryService.class);
classes.add(MetricQueryService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.skywalking.oap.server.core.cluster.*;
import org.apache.skywalking.oap.server.core.command.CommandService;
import org.apache.skywalking.oap.server.core.config.*;
import org.apache.skywalking.oap.server.core.profile.ProfileTaskMutationService;
import org.apache.skywalking.oap.server.core.oal.rt.*;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.register.service.*;
Expand Down Expand Up @@ -166,6 +167,10 @@ public CoreModuleProvider() {
this.registerServiceImplementation(AlarmQueryService.class, new AlarmQueryService(getManager()));
this.registerServiceImplementation(TopNRecordsQueryService.class, new TopNRecordsQueryService(getManager()));

// add profile service implementations
this.registerServiceImplementation(ProfileTaskMutationService.class, new ProfileTaskMutationService(getManager()));
this.registerServiceImplementation(ProfileTaskQueryService.class, new ProfileTaskQueryService(getManager()));

this.registerServiceImplementation(CommandService.class, new CommandService(getManager()));

annotationScan.registerListener(streamAnnotationListener);
Expand Down
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;
}

}
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;
}
}

}
Loading

0 comments on commit d38a8ea

Please sign in to comment.