forked from apache/dolphinscheduler
-
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.
Merge branch 'zp-prometheus-metrics' into '3.1.9-com'
增加Prometheus指标接口 See merge request DataTech/dolphinscheduler!2
- Loading branch information
Showing
9 changed files
with
399 additions
and
1 deletion.
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
111 changes: 111 additions & 0 deletions
111
...r-api/src/main/java/org/apache/dolphinscheduler/api/controller/ServiceNodeController.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,111 @@ | ||
/* | ||
* 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.controller; | ||
|
||
import static org.apache.dolphinscheduler.api.enums.Status.SAVE_ERROR; | ||
|
||
import org.apache.dolphinscheduler.api.exceptions.ApiException; | ||
import org.apache.dolphinscheduler.api.service.ServiceNodeService; | ||
import org.apache.dolphinscheduler.api.utils.Result; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiImplicitParam; | ||
import io.swagger.annotations.ApiImplicitParams; | ||
import io.swagger.annotations.ApiOperation; | ||
|
||
/** | ||
* service node controller | ||
* @author liyou | ||
*/ | ||
@Api(tags = "SERVICE_NODE_TAG") | ||
@RestController | ||
@RequestMapping("service-node") | ||
public class ServiceNodeController extends BaseController { | ||
|
||
@Autowired | ||
private ServiceNodeService serviceNodeService; | ||
|
||
/** | ||
* query all Service Node | ||
* | ||
* @return service node map | ||
*/ | ||
@ApiOperation(value = "queryAllServiceNode", notes = "QUERY_ALL_SERVICE_NODE_NOTES") | ||
@GetMapping("queryAllServiceNode") | ||
@ResponseStatus(HttpStatus.OK) | ||
public Result queryAllServiceNode() { | ||
return serviceNodeService.queryAllServiceNode(); | ||
} | ||
|
||
/** | ||
* get Prometheus metrics address list | ||
* | ||
* @return {@code Object} | ||
*/ | ||
@ApiOperation(value = "getPrometheusMetricsAddressList", notes = "GET_PROMETHEUS_METRICS_ADDRESS_LIST_NOTES") | ||
@GetMapping("getPrometheusMetricsAddressList") | ||
@ResponseStatus(HttpStatus.OK) | ||
public Object getPrometheusMetricsAddressList() { | ||
return serviceNodeService.getPrometheusMetricsAddressList(); | ||
} | ||
|
||
/** | ||
* upsert service node | ||
* | ||
* @param name worker group name | ||
* @param addrList addr list | ||
* @return result | ||
*/ | ||
@ApiOperation(value = "upsertServiceNode", notes = "UPSERT_SERVICE_NODE_NOTES") | ||
@ApiImplicitParams({ | ||
@ApiImplicitParam(name = "name", value = "SERVICE_NAME", required = true, dataType = "String", allowableValues = "master,api,alert"), | ||
@ApiImplicitParam(name = "addrList", value = "SERVICE_ADDR_LIST", required = true, dataType = "String", example = "192.168.1.1:123,192.168.1.2:123"), | ||
}) | ||
@PostMapping() | ||
@ResponseStatus(HttpStatus.OK) | ||
@ApiException(SAVE_ERROR) | ||
public Result upsertServiceNode(@RequestParam(value = "name") String name, | ||
@RequestParam(value = "addrList") String addrList) { | ||
Map<String, Object> result = serviceNodeService.upsertServiceNode(name, addrList); | ||
return returnDataList(result); | ||
} | ||
|
||
@ApiOperation(value = "deleteServiceNode", notes = "DELETE_SERVICE_NODE_NOTES") | ||
@ApiImplicitParams({ | ||
@ApiImplicitParam(name = "name", value = "SERVICE_NAME", required = true, dataType = "String", allowableValues = "master,api,alert"), | ||
}) | ||
@DeleteMapping() | ||
@ResponseStatus(HttpStatus.OK) | ||
public Result deleteServiceNode(@RequestParam(value = "name") String name) { | ||
Map<String, Object> result = serviceNodeService.deleteServiceNode(name); | ||
return returnDataList(result); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ServiceNodeDto.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,26 @@ | ||
package org.apache.dolphinscheduler.api.dto; | ||
|
||
import java.util.Collection; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author liyou 2024-01-02 | ||
*/ | ||
public class ServiceNodeDto { | ||
|
||
@Data | ||
public static class PrometheusMetricsAddress { | ||
|
||
private Collection<String> targets; | ||
private Label labels; | ||
} | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Label { | ||
private String group; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...heduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ServiceNodeService.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,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; | ||
|
||
import org.apache.dolphinscheduler.api.utils.Result; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* service node service | ||
* | ||
* @author liyou 2023/12/29 | ||
*/ | ||
public interface ServiceNodeService { | ||
|
||
/** | ||
* queryAllServiceNode | ||
* | ||
* @return {@code Result<Object>} | ||
*/ | ||
Result<Object> queryAllServiceNode(); | ||
|
||
/** | ||
* getPrometheusMetricsAddressList | ||
* | ||
* @return {@code List<Object>} | ||
*/ | ||
List<Object> getPrometheusMetricsAddressList(); | ||
|
||
/** | ||
* upsertServiceNode | ||
* | ||
* @param serviceName serviceName | ||
* @param addressList addressList | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
Map<String, Object> upsertServiceNode(String serviceName, String addressList); | ||
|
||
/** | ||
* deleteServiceNode | ||
* | ||
* @param serviceName serviceName | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
Map<String, Object> deleteServiceNode(String serviceName); | ||
} |
80 changes: 80 additions & 0 deletions
80
...pi/src/main/java/org/apache/dolphinscheduler/api/service/impl/ServiceNodeServiceImpl.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,80 @@ | ||
package org.apache.dolphinscheduler.api.service.impl; | ||
|
||
import org.apache.dolphinscheduler.api.dto.ServiceNodeDto; | ||
import org.apache.dolphinscheduler.api.enums.Status; | ||
import org.apache.dolphinscheduler.api.service.ServiceNodeService; | ||
import org.apache.dolphinscheduler.api.utils.Result; | ||
import org.apache.dolphinscheduler.dao.entity.ServiceNode; | ||
import org.apache.dolphinscheduler.dao.mapper.ServiceNodeMapper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
|
||
/** | ||
* @author liyou 2023-12-29 | ||
*/ | ||
@Service | ||
public class ServiceNodeServiceImpl extends BaseServiceImpl implements ServiceNodeService { | ||
|
||
@Autowired | ||
private ServiceNodeMapper serviceNodeMapper; | ||
|
||
@Override | ||
public Result<Object> queryAllServiceNode() { | ||
List<ServiceNode> serviceNodes = serviceNodeMapper.queryAllServiceNode(); | ||
serviceNodes.forEach(node -> node | ||
.setAddrList(Arrays.stream(node.getAddrList().split(",")).distinct().collect(Collectors.joining(",")))); | ||
return Result.success(serviceNodes); | ||
} | ||
|
||
@Override | ||
public List<Object> getPrometheusMetricsAddressList() { | ||
List<Object> result = new ArrayList<>(); | ||
List<ServiceNode> serviceNodes = serviceNodeMapper.queryAllServiceNode(); | ||
for (ServiceNode node : serviceNodes) { | ||
ServiceNodeDto.PrometheusMetricsAddress address = new ServiceNodeDto.PrometheusMetricsAddress(); | ||
address.setTargets(Arrays.stream(node.getAddrList().split(",")).distinct().collect(Collectors.toList())); | ||
address.setLabels(new ServiceNodeDto.Label(node.getServiceName())); | ||
result.add(address); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> upsertServiceNode(String serviceName, String addressList) { | ||
Map<String, Object> result = new HashMap<>(); | ||
ServiceNode serviceNode = serviceNodeMapper | ||
.selectOne(new QueryWrapper<ServiceNode>().lambda().eq(ServiceNode::getServiceName, serviceName)); | ||
if (serviceNode != null) { | ||
serviceNode.setAddrList(addressList); | ||
serviceNodeMapper.updateById(serviceNode); | ||
} else { | ||
ServiceNode node = new ServiceNode(); | ||
node.setServiceName(serviceName); | ||
node.setAddrList(addressList); | ||
serviceNodeMapper.insert(node); | ||
} | ||
putMsg(result, Status.SUCCESS); | ||
return result; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> deleteServiceNode(String serviceName) { | ||
Map<String, Object> result = new HashMap<>(); | ||
ServiceNode serviceNode = serviceNodeMapper.selectOne(new QueryWrapper<ServiceNode>().lambda().eq(ServiceNode::getServiceName, serviceName)); | ||
if (serviceNode != null) { | ||
serviceNodeMapper.deleteById(serviceNode.getId()); | ||
} | ||
putMsg(result, Status.SUCCESS); | ||
return result; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ServiceNode.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,41 @@ | ||
/* | ||
* 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.dao.entity; | ||
|
||
import lombok.Data; | ||
|
||
import com.baomidou.mybatisplus.annotation.IdType; | ||
import com.baomidou.mybatisplus.annotation.TableId; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
|
||
/** | ||
* service node | ||
* | ||
* @author liyou 2023/12/29 | ||
*/ | ||
@TableName("t_ds_service_node") | ||
@Data | ||
public class ServiceNode { | ||
|
||
@TableId(value = "id", type = IdType.AUTO) | ||
private Integer id; | ||
|
||
private String serviceName; | ||
|
||
private String addrList; | ||
} |
38 changes: 38 additions & 0 deletions
38
...scheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ServiceNodeMapper.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,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.dolphinscheduler.dao.mapper; | ||
|
||
import org.apache.dolphinscheduler.dao.entity.ServiceNode; | ||
|
||
import java.util.List; | ||
|
||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
/** | ||
* service node mapper interface | ||
* | ||
* @author liyou 2023/12/29 | ||
*/ | ||
public interface ServiceNodeMapper extends BaseMapper<ServiceNode> { | ||
|
||
/** | ||
* query all service node | ||
* | ||
* @return worker group list | ||
*/ | ||
List<ServiceNode> queryAllServiceNode(); | ||
} |
Oops, something went wrong.