@@ -1359,3 +1359,103 @@ func (p *LogProject) parseEndpoint() {
13591359 p .baseURL = fmt .Sprintf ("%s%s.%s" , scheme , p .Name , host )
13601360 }
13611361}
1362+
1363+ // CreateMetricStoreV2 creates a new metric store in SLS.
1364+ func (p * LogProject ) CreateMetricStoreV2 (metricStore * MetricStore ) error {
1365+ body , err := json .Marshal (metricStore )
1366+ if err != nil {
1367+ return NewClientError (err )
1368+ }
1369+
1370+ h := map [string ]string {
1371+ "x-log-bodyrawsize" : fmt .Sprintf ("%v" , len (body )),
1372+ "Content-Type" : "application/json" ,
1373+ }
1374+
1375+ r , err := request (p , "POST" , "/metricstores" , h , body )
1376+ if err != nil {
1377+ return NewClientError (err )
1378+ }
1379+ defer r .Body .Close ()
1380+ buf , err := ioutil .ReadAll (r .Body )
1381+ if err != nil {
1382+ return readResponseError (err )
1383+ }
1384+ if r .StatusCode != http .StatusOK {
1385+ return httpStatusNotOkError (buf , r .Header , r .StatusCode )
1386+ }
1387+ return nil
1388+ }
1389+
1390+ // UpdateMetricStoreV2 updates a metric store according by name.
1391+ func (p * LogProject ) UpdateMetricStoreV2 (metricStore * MetricStore ) (err error ) {
1392+ body , err := json .Marshal (metricStore )
1393+ if err != nil {
1394+ return NewClientError (err )
1395+ }
1396+
1397+ h := map [string ]string {
1398+ "x-log-bodyrawsize" : fmt .Sprintf ("%v" , len (body )),
1399+ "Content-Type" : "application/json" ,
1400+ }
1401+ r , err := request (p , "PUT" , "/metricstores/" + metricStore .Name , h , body )
1402+ if err != nil {
1403+ return NewClientError (err )
1404+ }
1405+ defer r .Body .Close ()
1406+ buf , err := ioutil .ReadAll (r .Body )
1407+ if err != nil {
1408+ return readResponseError (err )
1409+ }
1410+ if r .StatusCode != http .StatusOK {
1411+ return httpStatusNotOkError (buf , r .Header , r .StatusCode )
1412+ }
1413+ return nil
1414+ }
1415+
1416+ // DeleteMetricStoreV2 deletes a metric store according by name.
1417+ func (p * LogProject ) DeleteMetricStoreV2 (name string ) (err error ) {
1418+ h := map [string ]string {
1419+ "x-log-bodyrawsize" : "0" ,
1420+ }
1421+
1422+ r , err := request (p , "DELETE" , "/metricstores/" + name , h , nil )
1423+ if err != nil {
1424+ return NewClientError (err )
1425+ }
1426+ defer r .Body .Close ()
1427+ buf , err := ioutil .ReadAll (r .Body )
1428+ if err != nil {
1429+ return readResponseError (err )
1430+ }
1431+ if r .StatusCode != http .StatusOK {
1432+ return httpStatusNotOkError (buf , r .Header , r .StatusCode )
1433+ }
1434+ return nil
1435+ }
1436+
1437+ // GetMetricStoreV2 returns a metric store by name.
1438+ func (p * LogProject ) GetMetricStoreV2 (name string ) (* MetricStore , error ) {
1439+ h := map [string ]string {
1440+ "x-log-bodyrawsize" : "0" ,
1441+ }
1442+
1443+ r , err := request (p , "GET" , "/metricstores/" + name , h , nil )
1444+ if err != nil {
1445+ return nil , NewClientError (err )
1446+ }
1447+ defer r .Body .Close ()
1448+ buf , err := ioutil .ReadAll (r .Body )
1449+ if err != nil {
1450+ return nil , readResponseError (err )
1451+ }
1452+ if r .StatusCode != http .StatusOK {
1453+ return nil , httpStatusNotOkError (buf , r .Header , r .StatusCode )
1454+ }
1455+
1456+ store := & MetricStore {}
1457+ if err := json .Unmarshal (buf , store ); err != nil {
1458+ return nil , invalidJsonRespError (string (buf ), r .Header , r .StatusCode )
1459+ }
1460+ return store , nil
1461+ }
0 commit comments