Skip to content

Commit

Permalink
feat: [SRM-16343]: updated deserializer mapping for AppD and Dynatrace (
Browse files Browse the repository at this point in the history
  • Loading branch information
n00bitax authored Dec 8, 2023
1 parent 7be875c commit d55c04c
Showing 1 changed file with 58 additions and 46 deletions.
104 changes: 58 additions & 46 deletions internal/service/platform/monitored_service/health_source_utls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ import (

func getAppDynamicsHealthSource(hs map[string]interface{}) nextgen.AppDynamicsHealthSource {
healthSource := &nextgen.AppDynamicsHealthSource{}

healthSource.ConnectorRef = hs["connectorRef"].(string)

metricDefinitions := hs["metricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.AppDMetricDefinitions, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.AppDMetricDefinitions{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
healthSource.ApplicationName = hs["applicationName"].(string)
healthSource.Feature = hs["feature"].(string)
healthSource.TierName = hs["tierName"].(string)
if hs["metricDefinitions"] != nil {
metricDefinitions := hs["metricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.AppDMetricDefinitions, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.AppDMetricDefinitions{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
healthSourceMetricDefinitions[i] = data
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
healthSourceMetricDefinitions[i] = data
healthSource.MetricDefinitions = healthSourceMetricDefinitions
}
healthSource.MetricDefinitions = healthSourceMetricDefinitions

if hs["metricPacks"] != nil {
healthSource.MetricPacks = getMetricPacks(hs, "metricPacks")
Expand Down Expand Up @@ -65,22 +68,23 @@ func getNewRelicHealthSource(hs map[string]interface{}) nextgen.NewRelicHealthSo
healthSource := &nextgen.NewRelicHealthSource{}

healthSource.ConnectorRef = hs["connectorRef"].(string)

metricDefinitions := hs["newRelicMetricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.NewRelicMetricDefinition, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.NewRelicMetricDefinition{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
if hs["newRelicMetricDefinitions"] != nil {
metricDefinitions := hs["newRelicMetricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.NewRelicMetricDefinition, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.NewRelicMetricDefinition{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
healthSourceMetricDefinitions[i] = data
}
healthSourceMetricDefinitions[i] = data
healthSource.NewRelicMetricDefinitions = healthSourceMetricDefinitions
}
healthSource.NewRelicMetricDefinitions = healthSourceMetricDefinitions

if hs["metricPacks"] != nil {
healthSource.MetricPacks = getMetricPacks(hs, "metricPacks")
Expand Down Expand Up @@ -144,24 +148,35 @@ func getDataDogHealthSource(hs map[string]interface{}) nextgen.DatadogMetricHeal

func getDynatraceHealthSource(hs map[string]interface{}) nextgen.DynatraceHealthSource {
healthSource := &nextgen.DynatraceHealthSource{}

healthSource.ConnectorRef = hs["connectorRef"].(string)

metricDefinitions := hs["metricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.DynatraceMetricDefinition, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.DynatraceMetricDefinition{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
healthSource.ServiceId = hs["serviceId"].(string)
if hs["serviceMethodIds"] != nil {
serviceMethodIds := hs["serviceMethodIds"].([]interface{})
s := make([]string, len(serviceMethodIds))
for i, v := range serviceMethodIds {
s[i] = fmt.Sprint(v)
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
healthSource.ServiceMethodIds = s
}
healthSource.ServiceName = hs["serviceName"].(string)
healthSource.Feature = hs["feature"].(string)
if hs["metricDefinitions"] != nil {
metricDefinitions := hs["metricDefinitions"].([]interface{})
healthSourceMetricDefinitions := make([]nextgen.DynatraceMetricDefinition, len(metricDefinitions))
for i, metricDefinition := range metricDefinitions {
data := nextgen.DynatraceMetricDefinition{}
metricDef, errMarshal := json.Marshal(metricDefinition)
if errMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
errUnMarshal := json.Unmarshal(metricDef, &data)
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid Health source %s", hs))
}
healthSourceMetricDefinitions[i] = data
}
healthSourceMetricDefinitions[i] = data
healthSource.MetricDefinitions = healthSourceMetricDefinitions
}
healthSource.MetricDefinitions = healthSourceMetricDefinitions

if hs["metricPacks"] != nil {
healthSource.MetricPacks = getMetricPacks(hs, "metricPacks")
Expand Down Expand Up @@ -279,9 +294,7 @@ func getAwsPrometheusHealthSource(hs map[string]interface{}) nextgen.AwsPromethe

func getNextGenHealthSource(hs map[string]interface{}) nextgen.NextGenHealthSource {
healthSource := &nextgen.NextGenHealthSource{}

healthSource.ConnectorRef = hs["connectorRef"].(string)

healthSourceParamDto := nextgen.HealthSourceParamsDto{}
healthSourceParamData, errMarshal := json.Marshal(hs["healthSourceParams"])
if errMarshal != nil {
Expand All @@ -291,7 +304,6 @@ func getNextGenHealthSource(hs map[string]interface{}) nextgen.NextGenHealthSour
if errUnMarshal != nil {
panic(fmt.Sprintf("Invalid health source param dto %s", hs))
}

queryDefinitions := hs["queryDefinitions"].([]interface{})
queryDefinitionDtos := make([]nextgen.QueryDefinition, len(queryDefinitions))
for i, queryDefinition := range queryDefinitions {
Expand Down

0 comments on commit d55c04c

Please sign in to comment.