You can call the UpdateTimeseriesMeta operation to batch update the attributes of time series metadata. A single UpdateTimeseriesMeta call supports updating the metadata of multiple time series. If the time series metadata that you want to update does not exist, the system creates the metadata.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Parameters
The timeseriesMeta parameter specifies the metadata of a time series. Each timeseriesMeta parameter consists of the timeseriesKey and attributes parameters. The following table describes the parameters.
|
Parameter |
Required |
Description |
|
timeseriesKey |
Yes |
The identifiers of the time series, which include the following items:
Important
If you are unsure of the time series identifiers, such as the metric name or data source, call the QueryTimeseriesMeta operation to retrieve time series based on filter conditions. For more information, see Retrieve time series. |
|
attributes |
Yes |
The attributes of the time series. The value consists of one or more key-value pairs of the String type. |
Example
The following sample code provides an example on how to update the attributes information of time series:
func UpdateTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
fmt.Println("[Info]: Begin to update timeseries meta!")
updateTimeseriesMetaRequest := tablestore.NewUpdateTimeseriesMetaRequest(timeseriesTableName)
timeseriesKey := tablestore.NewTimeseriesKey()
timeseriesKey.SetMeasurementName("NETWORK")
timeseriesKey.SetDataSource("127.0.0.1")
timeseriesKey.AddTag("City" , "Hangzhou")
timeseriesKey.AddTag("Region" , "Xihu")
timeseriesMeta := tablestore.NewTimeseriesMeta(timeseriesKey)
//timeseriesMeta.SetUpdateTimeInUs(96400)
timeseriesMeta.AddAttribute("NewRegion" , "Yuhang")
timeseriesMeta.AddAttribute("NewCity" , "Shanghai")
updateTimeseriesMetaRequest.AddTimeseriesMetas(timeseriesMeta)
updateTimeseriesMetaResponse , err := tsClient.UpdateTimeseriesMeta(updateTimeseriesMetaRequest)
if err != nil {
fmt.Println("[Error]: Update timeseries meta failed with error: " , err)
return
}
if len(updateTimeseriesMetaResponse.GetFailedRowResults()) > 0 {
fmt.Println("[Error]: Update timeseries meta failed row: ")
for i := 0; i < len(updateTimeseriesMetaResponse.GetFailedRowResults()); i++ {
fmt.Println("[Error]: " , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Index , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Error)
}
}
fmt.Println("[Info]: UpdateTimeseriesMetaSample finished!")
}
References
To view the updated time series attributes, you can retrieve time series. For more information, see Retrieve time series.