Browse Source
* Tag workflow related metrics with process definition code (workflow id) * Clean up related metrics when deleting workflow definition * Add license headers * Update related UT cases * Add an example in grafana-demo * Add related docs3.2.0-release
Eric Gao
2 years ago
committed by
GitHub
17 changed files with 507 additions and 84 deletions
@ -0,0 +1,24 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
public interface MetricsCleanUpService { |
||||||
|
|
||||||
|
void cleanUpWorkflowMetricsByDefinitionCode(String workflowDefinitionCode); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.service.impl; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.rpc.ApiRpcClient; |
||||||
|
import org.apache.dolphinscheduler.api.service.MetricsCleanUpService; |
||||||
|
import org.apache.dolphinscheduler.common.enums.NodeType; |
||||||
|
import org.apache.dolphinscheduler.common.model.Server; |
||||||
|
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||||
|
import org.apache.dolphinscheduler.remote.command.WorkflowMetricsCleanUpCommand; |
||||||
|
import org.apache.dolphinscheduler.remote.utils.Host; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
public class MetricsCleanUpServiceImpl implements MetricsCleanUpService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ApiRpcClient apiRpcClient; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private RegistryClient registryClient; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void cleanUpWorkflowMetricsByDefinitionCode(String workflowDefinitionCode) { |
||||||
|
WorkflowMetricsCleanUpCommand workflowMetricsCleanUpCommand = new WorkflowMetricsCleanUpCommand(); |
||||||
|
workflowMetricsCleanUpCommand.setProcessDefinitionCode(workflowDefinitionCode); |
||||||
|
List<Server> masterNodeList = registryClient.getServerList(NodeType.MASTER); |
||||||
|
for (Server server : masterNodeList) { |
||||||
|
try { |
||||||
|
final String host = String.format("%s:%s", server.getHost(), server.getPort()); |
||||||
|
apiRpcClient.send(Host.of(host), workflowMetricsCleanUpCommand.convert2Command()); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error( |
||||||
|
"Fail to clean up workflow related metrics on {} when deleting workflow definition {}, error message {}", |
||||||
|
server.getHost(), workflowDefinitionCode, e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.server.master.processor; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.remote.command.Command; |
||||||
|
import org.apache.dolphinscheduler.remote.command.CommandType; |
||||||
|
import org.apache.dolphinscheduler.remote.command.WorkflowMetricsCleanUpCommand; |
||||||
|
import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor; |
||||||
|
import org.apache.dolphinscheduler.server.master.metrics.ProcessInstanceMetrics; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import com.google.common.base.Preconditions; |
||||||
|
import io.netty.channel.Channel; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class WorkflowMetricsCleanUpProcessor implements NettyRequestProcessor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void process(Channel channel, Command command) { |
||||||
|
Preconditions.checkArgument(CommandType.WORKFLOW_METRICS_CLEANUP == command.getType(), |
||||||
|
String.format("invalid command type: %s", command.getType())); |
||||||
|
|
||||||
|
WorkflowMetricsCleanUpCommand workflowMetricsCleanUpCommand = |
||||||
|
JSONUtils.parseObject(command.getBody(), WorkflowMetricsCleanUpCommand.class); |
||||||
|
|
||||||
|
ProcessInstanceMetrics.cleanUpProcessInstanceCountMetricsByDefinitionCode( |
||||||
|
workflowMetricsCleanUpCommand.getProcessDefinitionCode()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.remote.command; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class WorkflowMetricsCleanUpCommand implements Serializable { |
||||||
|
|
||||||
|
private String processDefinitionCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* package request command |
||||||
|
* |
||||||
|
* @return command |
||||||
|
*/ |
||||||
|
public Command convert2Command() { |
||||||
|
Command command = new Command(); |
||||||
|
command.setType(CommandType.WORKFLOW_METRICS_CLEANUP); |
||||||
|
byte[] body = JSONUtils.toJsonByteArray(this); |
||||||
|
command.setBody(body); |
||||||
|
return command; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue