Skip to content

Commit

Permalink
Merge pull request #90 from kyuengmanKim/develop/monitoring-items
Browse files Browse the repository at this point in the history
Develop get monitoring items api
  • Loading branch information
kyuengmanKim authored Nov 15, 2024
2 parents f151338 + ab23ff5 commit 9964240
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@
@FeignClient(name = "insight", url = "${feign.insight.url:}")
public interface InsightClient {

@GetMapping(Constants.PREFIX_V1 + Constants.PREDICTION_PATH + "/measurement")
Object getPredictionMeasurement();
@GetMapping(Constants.PREFIX_V1 + Constants.PREDICTION_PATH + "/measurement/{measurement}")
Object getPredictionSpecificMeasurement(@PathVariable String measurement);
@GetMapping(Constants.PREFIX_V1 + Constants.PREDICTION_PATH + "/options")
Object getPredictionOptions();
@PostMapping(Constants.PREFIX_V1 + Constants.PREDICTION_PATH + "/nsId/{nsId}/target/{targetId}")
Object predictMetric(@PathVariable String nsId, @PathVariable String targetId, @RequestBody Object option);
@GetMapping(Constants.PREFIX_V1 + Constants.PREDICTION_PATH + "/nsId/{nsId}/target/{targetId}/history")
Object getPredictionHistory(@PathVariable String nsId, @PathVariable String targetId, @RequestParam String measurement, @RequestParam(required = false) String start_time, @RequestParam(required = false) String end_time);

@GetMapping(Constants.PREFIX_V1 + Constants.ANOMALY_PATH + "/measurement")
Object getAnomalyDetectionMeasurement();
@GetMapping(Constants.PREFIX_V1 + Constants.ANOMALY_PATH + "/measurement/{measurement}")
Object getAnomalyDetectionSpecificMeasurement(@PathVariable String measurement);
@GetMapping(Constants.PREFIX_V1 + Constants.ANOMALY_PATH + "/options")
Object getAnomalyDetectionOptions();
@GetMapping(Constants.PREFIX_V1 + Constants.ANOMALY_PATH + "/settings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public class InsightController {
private final InsightClient insightClient;

// insight prediction
@GetMapping(Constants.PREDICTION_PATH + "/measurement")
public Object getPredictionMeasurement (){
return insightClient.getPredictionMeasurement();
}
@GetMapping(Constants.PREDICTION_PATH + "/measurement/{measurement}")
public Object getPredictionSpecificMeasurement(@PathVariable String measurement) {
return insightClient.getPredictionSpecificMeasurement(measurement);
}
@GetMapping(Constants.PREDICTION_PATH + "/options")
public Object getPredictionOptions() {
return insightClient.getPredictionOptions();
Expand All @@ -34,6 +42,14 @@ public Object getPredictionHistory(@PathVariable String nsId, @PathVariable Stri
}

// insight anomaly detection
@GetMapping(Constants.ANOMALY_PATH + "/measurement")
public Object getAnomalyDetectionMeasurement() {
return insightClient.getAnomalyDetectionMeasurement();
}
@GetMapping(Constants.ANOMALY_PATH + "/measurement/{measurement}")
public Object getAnomalyDetectionSpecificMeasurement(@PathVariable String measurement) {
return insightClient.getAnomalyDetectionSpecificMeasurement(measurement);
}
@GetMapping(Constants.ANOMALY_PATH + "/options")
public Object getAnomalyDetectionOptions() {
return insightClient.getAnomalyDetectionOptions();
Expand Down
218 changes: 218 additions & 0 deletions java-module/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,70 @@ paths:
schema:
$ref: '#/definitions/ResBodyVoid'
headers: {}
/api/o11y/insight/anomaly-detection/measurement:
get:
description: Get measurements, field lists available for the feature.
summary: GetAnomalyMeasurementList
tags:
- '[Insight] Anomaly Detection'
operationId: GetAnomalyMeasurementList
deprecated: false
produces:
- application/json
parameters: [ ]
responses:
'200':
description: Successful retrieval of anomaly detection measurements
schema:
$ref: '#/definitions/ResBodyAnomalyDetectionMeasurement'
examples:
application/json:
data:
- plugin_seq: 1
measurement: cpu
fields:
- field_key: usage_idle
unit: percent
- plugin_seq: 4
measurement: mem
fields:
- field_key: used_percent
unit: percent
rs_code: '200'
rs_msg: Success
headers: { }
/api/o11y/insight/anomaly-detection/measurement/{measurement}:
get:
description: Get Field list of specific measurement available for that feature
summary: GetAnomalyFieldListByMeasurement
tags:
- '[Insight] Anomaly Detection'
operationId: GetAnomalyFieldListByMeasurement
deprecated: false
produces:
- application/json
parameters:
- name: measurement
in: path
required: true
type: string
description: Specific Measurement.
responses:
'200':
description: Successfully retrieved anomaly detection field list of specific measurement
schema:
$ref: '#/definitions/ResBodyAnomalyDetectionSpecificMeasurement'
examples:
application/json:
data:
plugin_seq: 1
measurement: cpu
fields:
- field_key: usage_idle
unit: percent
rs_code: '200'
rs_msg: Success
headers: { }
/api/o11y/insight/anomaly-detection/options:
get:
description: Fetch the available target types, metric types, and interval options for the anomaly detection API.
Expand Down Expand Up @@ -1462,6 +1526,80 @@ paths:
schema:
$ref: '#/definitions/ResBodyVoid'
headers: {}
/api/o11y/insight/predictions/measurement:
get:
description: Get measurements, field lists available for the feature.
summary: GetPredictionMeasurementList
tags:
- '[Insight] Prediction'
operationId: GetPredictionMeasurementList
deprecated: false
produces:
- application/json
parameters: [ ]
responses:
'200':
description: Successful retrieval of prediction measurements
schema:
$ref: '#/definitions/ResBodyPredictionMeasurement'
examples:
application/json:
data:
- plugin_seq: 1
measurement: cpu
fields:
- field_key: usage_idle
unit: percent
- plugin_seq: 2
measurement: disk
fields:
- field_key: used_percent
unit: percent
- plugin_seq: 4
measurement: mem
fields:
- field_key: used_percent
unit: percent
- plugin_seq: 8
measurement: system
fields:
- field_key: load1
unit: percent
rs_code: '200'
rs_msg: Success
headers: { }
/api/o11y/insight/predictions/measurement/{measurement}:
get:
description: Get Field list of specific measurement available for that feature
summary: GetPredictionFieldListByMeasurement
tags:
- '[Insight] Prediction'
operationId: GetPredictionFieldListByMeasurement
deprecated: false
produces:
- application/json
parameters:
- name: measurement
in: path
required: true
type: string
description: Specific Measurement.
responses:
'200':
description: Successfully retrieved prediction field list of specific measurement
schema:
$ref: '#/definitions/ResBodyPredictionSpecificMeasurement'
examples:
application/json:
data:
plugin_seq: 1
measurement: cpu
fields:
- field_key: usage_idle
unit: percent
rs_code: '200'
rs_msg: Success
headers: { }
/api/o11y/insight/predictions/options:
get:
description: Fetch the available target types, metric types, and prediction range options for the prediction API.
Expand Down Expand Up @@ -2728,6 +2866,20 @@ definitions:
format: double
required:
- timestamp
AnomalyDetectionMeasurement:
title: AnomalyDetectionMeasurement
type: object
properties:
plugin_seq:
type: string
measurement:
type: string
fields:
type: array
items:
type: object
additionalProperties:
type: string
PredictionBody:
title: PredictionBody
type: object
Expand Down Expand Up @@ -2794,6 +2946,20 @@ definitions:
- target_types
- measurements
- prediction_ranges
PredictionMeasurement:
title: PredictionMeasurement
type: object
properties:
plugin_seq:
type: string
measurement:
type: string
fields:
type: array
items:
type: object
additionalProperties:
type: string
PredictionResult:
title: PredictionResult
type: object
Expand Down Expand Up @@ -2862,6 +3028,32 @@ definitions:
default: Success
required:
- data
ResBodyAnomalyDetectionMeasurement:
title: ResBodyAnomalyDetectionMeasurement
type: object
properties:
data:
type: array
items:
$ref: '#/definitions/AnomalyDetectionMeasurement'
rs_code:
type: string
default: '200'
rs_msg:
type: string
default: Success
ResBodyAnomalyDetectionSpecificMeasurement:
title: ResBodyAnomalyDetectionSpecificMeasurement
type: object
properties:
data:
$ref: '#/definitions/AnomalyDetectionMeasurement'
rs_code:
type: string
default: '200'
rs_msg:
type: string
default: Success
ResBodyPredictionHistory:
title: ResBodyPredictionHistory
type: object
Expand Down Expand Up @@ -2890,6 +3082,32 @@ definitions:
default: Success
required:
- data
ResBodyPredictionMeasurement:
title: ResBodyPredictionMeasurement
type: object
properties:
data:
type: array
items:
$ref: '#/definitions/PredictionMeasurement'
rs_code:
type: string
default: '200'
rs_msg:
type: string
default: Success
ResBodyPredictionSpecificMeasurement:
title: ResBodyPredictionSpecificMeasurement
type: object
properties:
data:
$ref: '#/definitions/PredictionMeasurement'
rs_code:
type: string
default: '200'
rs_msg:
type: string
default: Success
ResBodyPredictionResult:
title: ResBodyPredictionResult
type: object
Expand Down
44 changes: 41 additions & 3 deletions python/insight/app/api/anomaly/anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,59 @@
from app.api.anomaly.description.description import (get_options_description, get_settings_description,
post_settings_description, put_settings_description,
delete_settings_description, get_specific_settings_description,
get_history_description, post_anomaly_detection_description)
get_history_description, post_anomaly_detection_description,
get_anomaly_detection_measurements_description,
get_specific_measurement_description)
from app.api.anomaly.response.res import (ResBodyAnomalyDetectionOptions, AnomalyDetectionOptions,
ResBodyAnomalyDetectionSettings)
from app.api.anomaly.utils.utils import AnomalyService, get_db
from app.api.anomaly.utils.history import AnomalyHistoryService
from app.api.anomaly.utils.setting import AnomalySettingsService
from app.api.anomaly.response.res import ResBodyVoid, ResBodyAnomalyDetectionHistoryResponse
from app.api.anomaly.request.req import (AnomalyDetectionTargetRegistration, AnomalyDetectionTargetUpdate,
from app.api.anomaly.response.res import (ResBodyAnomalyDetectionMeasurement, ResBodyAnomalyDetectionSpecificMeasurement,
ResBodyVoid, ResBodyAnomalyDetectionHistoryResponse)
from app.api.anomaly.request.req import (GetMeasurementPath, AnomalyDetectionTargetRegistration, AnomalyDetectionTargetUpdate,
GetHistoryPathParams, GetAnomalyHistoryFilter)
from config.ConfigManager import ConfigManager
from fastapi.responses import JSONResponse

router = APIRouter()


@router.get(
path='/anomaly-detection/measurement',
description=get_anomaly_detection_measurements_description['api_description'],
responses=get_anomaly_detection_measurements_description['response'],
response_model=ResBodyAnomalyDetectionMeasurement,
operation_id="GetAnomalyMeasurementList"
)
async def get_anomaly_detection_measurements(db: Session = Depends(get_db)):
config = ConfigManager()
measurement_field_config = config.get_anomaly_config()['measurement_fields']
anomaly_setting_service = AnomalySettingsService(db=db)
result_dict = anomaly_setting_service.map_plugin_info(measurement_field_config)

return ResBodyAnomalyDetectionMeasurement(data=result_dict)


@router.get(
path='/anomaly-detection/measurement/{measurement}',
description=get_specific_measurement_description['api_description'],
responses=get_specific_measurement_description['response'],
response_model=ResBodyAnomalyDetectionSpecificMeasurement,
operation_id="GetAnomalyFieldListByMeasurement"
)
async def get_specific_measurement(
path_params: GetMeasurementPath = Depends(),
db: Session = Depends(get_db)
):
config = ConfigManager()
measurement_field_config = config.get_anomaly_config()['measurement_fields']
anomaly_setting_service = AnomalySettingsService(db=db)
result_dict = anomaly_setting_service.map_plugin_info(measurement_field_config, target_measurement=path_params)

return ResBodyAnomalyDetectionSpecificMeasurement(data=result_dict)


@router.get(
path="/anomaly-detection/options",
description=get_options_description['api_description'],
Expand Down
Loading

0 comments on commit 9964240

Please sign in to comment.