You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at a time.
Prerequisites
Time series data is written to the time series table. For more information, see Write time series data.
A TimeseriesClient instance is initialized. For more information, see Initialize an OTSClient instance.
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. You can use the following parameters to specify the identifiers of a time series:
Important If you are not sure about information of the time series that you want to query, such as the metric name and data source, you can call the QueryTimeseriesMeta operation to retrieve time series based on various 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. |
Examples
The following sample code provides an example on how to updates the attributes of a 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!")
}
FAQ
References
For more information about the API operation, see UpdateTimeseriesMeta.
To view the updated attributes of a time series, you can retrieve time series. For more information, see Retrieve time series.