(ctx context.Context, cfg *monitor_dto.SaveMonitorConfig)
| 1207 | } |
| 1208 | |
| 1209 | func (m *imlMonitorConfig) SaveMonitorConfig(ctx context.Context, cfg *monitor_dto.SaveMonitorConfig) (*monitor_dto.MonitorConfig, error) { |
| 1210 | clusterId := cluster.DefaultClusterID |
| 1211 | _, err := m.clusterService.Get(ctx, clusterId) |
| 1212 | if err != nil { |
| 1213 | return nil, err |
| 1214 | } |
| 1215 | |
| 1216 | data, _ := json.Marshal(cfg.Config) |
| 1217 | err = driver.Check(cfg.Driver, string(data)) |
| 1218 | if err != nil { |
| 1219 | return nil, err |
| 1220 | } |
| 1221 | |
| 1222 | executor, err := driver.CreateExecutor(cfg.Driver, string(data)) |
| 1223 | if err != nil { |
| 1224 | return nil, err |
| 1225 | } |
| 1226 | err = executor.Init(ctx) |
| 1227 | if err != nil { |
| 1228 | return nil, err |
| 1229 | } |
| 1230 | clusters, err := m.clusterService.ListByClusters(ctx, clusterId) |
| 1231 | if err != nil { |
| 1232 | return nil, err |
| 1233 | } |
| 1234 | version := time.Now().Format("20060102150405") |
| 1235 | id := fmt.Sprintf("%s_influxdb", clusterId) |
| 1236 | for _, c := range clusters { |
| 1237 | err := m.dynamicClient(ctx, c.Uuid, "influxdbv2", func(client gateway.IDynamicClient) error { |
| 1238 | pubCfg := &gateway.DynamicRelease{ |
| 1239 | BasicItem: &gateway.BasicItem{ |
| 1240 | ID: id, |
| 1241 | Description: "", |
| 1242 | Version: version, |
| 1243 | MatchLabels: map[string]string{ |
| 1244 | "module": "monitor", |
| 1245 | }, |
| 1246 | }, |
| 1247 | Attr: map[string]interface{}{ |
| 1248 | "org": cfg.Config["org"], |
| 1249 | "token": cfg.Config["token"], |
| 1250 | "url": cfg.Config["addr"], |
| 1251 | "bucket": "apinto", |
| 1252 | "scopes": []string{"monitor"}, |
| 1253 | }, |
| 1254 | } |
| 1255 | return client.Online(ctx, pubCfg) |
| 1256 | }) |
| 1257 | if err != nil { |
| 1258 | return nil, err |
| 1259 | } |
| 1260 | |
| 1261 | } |
| 1262 | |
| 1263 | err = m.monitorService.Save(ctx, &monitor.SaveMonitor{ |
| 1264 | Cluster: clusterId, |
| 1265 | Driver: cfg.Driver, |
| 1266 | Config: string(data), |
nothing calls this directly
no test coverage detected