def sort_timeseries(timeseries):
    """
    This function is used to sort a time series by timestamp to ensure that
    there are no unordered timestamps in the time series which are artefacts of
    the collector or carbon-relay. So all Redis time series are sorted by
    timestamp before analysis.
    """
    sorted_timeseries = []
    if timeseries:
        sorted_timeseries = sorted(timeseries, key=lambda x: x[0])
        del timeseries

    return sorted_timeseries