OpenTSDB / opentsdb

A scalable, distributed Time Series Database.
http://opentsdb.net
GNU Lesser General Public License v2.1
5k stars 1.25k forks source link

Downsampling produces sawtooth #577

Open bobrik opened 9 years ago

bobrik commented 9 years ago

Tried to search for similar issue, but haven't found one. I'm running 2.1.0, every graph below is taken from 6h timespan.

image

image

image

image

Query looks roughly like this:

{
    "start": 1443499672980,
    "queries": [
        {
            "metric": "kafka.topics.offsets",
            "aggregator": "sum",
            "rate": true,
            "rateOptions": {
                "counter": false
            },
            "downsample": "30s-avg",
            "tags": {
                "partition": 34,
                "topic": "example"
            }
        }
    ]
}

Query result for disabled downsampling:

[
    {
        "metric": "kafka.topics.offsets",
        "tags": {
            "some": "tags"
        },
        "aggregateTags": [
            "more",
            "tags"
        ],
        "dps": {
            "1443500907": 1931447.1544715448,
            "1443501029": 1956410.7540983616,
            "1443501151": 1980583.8688524596,
            "1443501274": 1959686.243902439,
            "1443501397": 1954890.9268292682,
            "1443501519": 1987567.2131147548,
            "1443501642": 1939972.162601626,
            "1443501764": 1978435.1475409842,
            "1443501887": 1950095.6097560972,
            "1443502010": 1959686.2439024393,
            "1443502132": 1972526.163934427,
            "1443502254": 1967691.5409836073,
            "1443502377": 1975137.8211382113,
            "1443502500": 1960219.0569105688,
            "1443502622": 1978435.1475409844,
            "1443502744": 1970377.4426229515,
            "1443502867": 1967678.4390243902,
            "1443502991": 1975593.2903225804,
            "1443503113": 1992939.0163934426,
            "1443503235": 2015500.5901639352,
            "1443503358": 2003376.9105691055,
            "1443503481": 2038542.5691056908,
            "1443503604": 2003909.7235772356,
            "1443503726": 2020872.3934426233,
            "1443503848": 2023558.2950819675,
            "1443503970": 2031616.0000000002,
            "1443504093": 2005508.1626016255,
            "1443504215": 2058475.0163934433,
            "1443504338": 2039075.3821138206,
            "1443504460": 2121325.114754099,
            "1443504582": 2078887.8688524594,
            "1443504705": 2091291.056910569,
            "1443504828": 2098750.43902439,
            "1443504951": 2096086.3739837394,
            "1443505074": 2075839.4796747968,
            "1443505196": 2092854.55737705,
            "1443505318": 2079962.2295081974,
            "1443505440": 2084796.852459017,
            "1443505562": 2084796.8524590167,
            "1443505685": 2064650.4065040646,
            "1443505807": 2077411.7147807549,
            "1443505930": 2082442.0114816653,
            "1443506052": 2083185.3114754101,
            "1443506174": 2144423.868852459,
            "1443506297": 2126456.715447154,
            "1443506419": 2132068.721311476,
            "1443506665": 2138711.414634146,
            "1443506788": 2114202.016260162,
            "1443506910": 2137977.704918033,
            "1443507032": 2148184.1311475416,
            "1443507154": 2142275.1475409837,
            "1443507277": 2122194.211382114,
            "1443507399": 2152481.573770492,
            "1443507521": 2202439.3442622954,
            "1443507644": 2240478.6991869914,
            "1443507766": 2258380.3427962153,
            "1443507888": 2219091.93442623,
            "1443508011": 2231953.6910569104,
            "1443508133": 2076739.147540984,
            "1443508255": 2097152.0000000005,
            "1443508377": 2241653.5081967213,
            "1443508500": 2520992.7868591347,
            "1443508623": 2478113.300813009,
            "1443508746": 2512213.333333334,
            "1443508868": 2556441.1803278686,
            "1443508991": 2679516.6178861787,
            "1443509114": 2576150.8943089433,
            "1443509236": 2496276.9836065564,
            "1443509358": 2484459.0163934417,
            "1443509481": 2448808.5853658547,
            "1443509603": 2454914.098360655,
            "1443509725": 2411402.4918032787,
            "1443509848": 2324632.583233373,
            "1443509970": 2397997.101906992,
            "1443510094": 2375680.0000000005,
            "1443510216": 2422146.0983606554,
            "1443510339": 2400855.414634146,
            "1443510461": 2373262.6885245894,
            "1443510583": 2374337.049180327,
            "1443510706": 2387535.089430894,
            "1443510828": 2422146.0983606554,
            "1443510951": 2383272.5853658537,
            "1443511073": 2372188.3278688523,
            "1443511195": 2347478.032786885,
            "1443511318": 2349705.3658536584,
            "1443511440": 2355535.737704918,
            "1443511563": 2319867.837398374,
            "1443511685": 2334585.704918032,
            "1443511807": 2334048.5245901635,
            "1443511930": 2331056.9105691053,
            "1443512052": 2319007.475409836,
            "1443512175": 2302285.008130081,
            "1443512297": 2312561.3114754097,
            "1443512420": 2331589.723577236,
            "1443512542": 2585448.918032787,
            "1443512664": 2272272.7868852457,
            "1443512786": 2092317.377049181,
            "1443512908": 2075127.6065573778,
            "1443513031": 2286300.617886178,
            "1443513153": 2426443.540983606,
            "1443513277": 2293231.4838709673,
            "1443513399": 2166985.4426229508,
            "1443513522": 2080101.9837398373,
            "1443513644": 2141737.9672131147,
            "1443513767": 2189861.463414633,
            "1443513890": 2532460.2276422773,
            "1443514012": 2567721.9672131143,
            "1443514135": 2390731.9674796746,
            "1443514257": 2429697.194188991,
            "1443514379": 2451691.0163934417,
            "1443514502": 2567625.8861788623,
            "1443514624": 2557515.5409836066,
            "1443514747": 2535657.105691057,
            "1443514869": 2552143.7377049173,
            "1443514991": 2566647.606557377,
            "1443515114": 2525533.6585365864,
            "1443515236": 2519375.7377049173,
            "1443515358": 2593506.6229508193,
            "1443515481": 2572421.2032520333,
            "1443515603": 2581151.4754098356,
            "1443515726": 2516475.837398375,
            "1443515848": 2617679.7377049173,
            "1443515971": 2569757.1382113826,
            "1443516093": 2567721.9672131147,
            "1443516216": 2527664.9105691067,
            "1443516338": 2497351.3442622935,
            "1443516461": 2474916.422764228,
            "1443516583": 2519912.9180327863,
            "1443516705": 2799246.688524591,
            "1443516827": 2835237.7704918035,
            "1443516950": 2834032.390243902,
            "1443517073": 2850549.593495935,
            "1443517195": 2891641.704918033,
            "1443517318": 2824441.7560975603,
            "1443517440": 2783109.442089832,
            "1443517563": 2693626.376240251,
            "1443517686": 2677385.365853658,
            "1443517808": 2721355.5409836066,
            "1443517932": 2682219.354838709,
            "1443518054": 2848667.278688526,
            "1443518177": 2725338.5365853645,
            "1443518300": 2658736.910569105,
            "1443518422": 2664414.426229508,
            "1443518544": 2463508.983606557,
            "1443518667": 2385936.650406504,
            "1443518789": 2333511.3442622954,
            "1443518912": 2329991.2845528456,
            "1443519035": 2328392.845528455,
            "1443519157": 2348552.3934426224,
            "1443519280": 2345442.861788618,
            "1443519402": 2321156.196721311,
            "1443519524": 2345329.3114754097,
            "1443519646": 2305040.7868852452,
            "1443519769": 2256995.9024390243,
            "1443519891": 2197604.721311476,
            "1443520014": 2143506.7317073164,
            "1443520136": 2150332.8524590163,
            "1443520260": 2134148.129032258,
            "1443520382": 2208348.3278688528,
            "1443520504": 2185786.754098361,
            "1443520627": 2150126.6614899607,
            "1443520750": 2162687.999999999,
            "1443520872": 2184175.213114754,
            "1443520994": 2164836.7213114756,
            "1443521116": 2156241.836065574,
            "1443521240": 2120935.225806451,
            "1443521362": 2246488.1311475406,
            "1443521485": 2166950.50406504,
            "1443521607": 2165373.9016393446,
            "1443521729": 2183638.0327868853,
            "1443521852": 2143506.7317073164,
            "1443521974": 2186861.1147540985,
            "1443522096": 2176117.5081967213,
            "1443522221": 2184183.8080000007,
            "1443522343": 2198679.0819672137
        }
    }
]
manolama commented 9 years ago

Hmm, I'd suspect that it's something in the aggregation that's throwing it off. Can you find out what's in the

"aggregateTags": [
            "more",
            "tags"
        ],

by isolating down to a single series, then try the 1m, 10m etc on it?

bobrik commented 9 years ago

Isolated to empty aggregateTags:

[
    {
        "metric": "kafka.topics.offsets",
        "tags": {
            "some": "tags"
        },
        "aggregateTags": [],
        "dps": {
            "1443532260": 69905.06666666667,
            "1443532380": 72089.6,
            "1443532500": 74274.13333333333,
            "1443532620": 85196.8,
            "1443532740": 83012.26666666666,
            "1443532860": 80827.73333333334,
            "1443533010": 61166.933333333334,
            "1443533130": 78643.2,
            "1443533250": 78643.2,
            "1443533370": 78643.2,
            "1443533490": 80827.73333333334,
            "1443533610": 78643.2,
            "1443533730": 78643.2,
            "1443533850": 78643.2,
            "1443533970": 78643.2,
            "1443534090": 76458.66666666667,
            "1443534210": 78643.2,
            "1443534360": 62914.56,
            "1443534480": 78643.2,
            "1443534600": 78643.2,
            "1443534720": 78643.2,
            "1443534840": 78643.2,
            "1443534960": 76458.66666666667,
            "1443535080": 83012.26666666666,
            "1443535200": 76458.66666666667,
            "1443535320": 80827.73333333334,
            "1443535470": 62914.56,
            "1443535590": 78643.2,
            "1443535710": 74274.13333333333,
            "1443535830": 74274.13333333333,
            "1443535950": 72089.6,
            "1443536070": 74274.13333333333,
            "1443536190": 78643.2,
            "1443536310": 76458.66666666667,
            "1443536430": 74274.13333333333,
            "1443536550": 76458.66666666667,
            "1443536700": 59419.306666666664,
            "1443536820": 76458.66666666667,
            "1443536940": 74274.13333333333,
            "1443537060": 76458.66666666667,
            "1443537180": 76458.66666666667,
            "1443537300": 78643.2,
            "1443537420": 76458.66666666667,
            "1443537570": 64662.18666666667,
            "1443537690": 76458.66666666667,
            "1443537810": 76458.66666666667,
            "1443537930": 76458.66666666667,
            "1443538050": 76458.66666666667,
            "1443538170": 76458.66666666667,
            "1443538290": 74274.13333333333,
            "1443538410": 76458.66666666667,
            "1443538530": 74274.13333333333,
            "1443538650": 76458.66666666667,
            "1443538770": 76458.66666666667,
            "1443538890": 76458.66666666667,
            "1443539040": 62914.56,
            "1443539160": 74274.13333333333,
            "1443539280": 74274.13333333333,
            "1443539400": 74274.13333333333,
            "1443539520": 74274.13333333333,
            "1443539640": 76458.66666666667,
            "1443539760": 74274.13333333333,
            "1443539880": 76458.66666666667,
            "1443540000": 74274.13333333333,
            "1443540120": 74274.13333333333,
            "1443540270": 61166.933333333334,
            "1443540390": 74274.13333333333,
            "1443540510": 74274.13333333333,
            "1443540630": 76458.66666666667,
            "1443540750": 78643.2,
            "1443540870": 74274.13333333333,
            "1443540990": 76458.66666666667,
            "1443541110": 76458.66666666667,
            "1443541230": 76458.66666666667,
            "1443541350": 76458.66666666667,
            "1443541470": 76458.66666666667,
            "1443541620": 61166.933333333334,
            "1443541740": 76458.66666666667,
            "1443541860": 74274.13333333333,
            "1443541980": 76458.66666666667,
            "1443542100": 76458.66666666667,
            "1443542220": 76458.66666666667,
            "1443542340": 78643.2,
            "1443542460": 78643.2,
            "1443542580": 80827.73333333334,
            "1443542700": 80827.73333333334,
            "1443542820": 80827.73333333334,
            "1443542970": 62914.56,
            "1443543090": 80827.73333333334,
            "1443543210": 78643.2,
            "1443543330": 80827.73333333334,
            "1443543450": 80827.73333333334,
            "1443543570": 78643.2,
            "1443543690": 80827.73333333334,
            "1443543810": 78643.2,
            "1443543930": 80827.73333333334,
            "1443544050": 78643.2,
            "1443544200": 64662.18666666667,
            "1443544320": 78643.2,
            "1443544440": 76458.66666666667,
            "1443544560": 80827.73333333334,
            "1443544800": 78643.2,
            "1443544920": 78643.2,
            "1443545040": 78643.2,
            "1443545160": 76458.66666666667,
            "1443545280": 78643.2,
            "1443545400": 78643.2,
            "1443545550": 62914.56,
            "1443545670": 78643.2,
            "1443545790": 76458.66666666667,
            "1443545910": 78643.2,
            "1443546030": 78643.2,
            "1443546150": 76458.66666666667,
            "1443546270": 78643.2,
            "1443546390": 74274.13333333333,
            "1443546510": 74274.13333333333,
            "1443546630": 74274.13333333333,
            "1443546750": 74274.13333333333,
            "1443546900": 57671.68,
            "1443547020": 74274.13333333333,
            "1443547140": 74274.13333333333,
            "1443547260": 72089.6,
            "1443547380": 74274.13333333333,
            "1443547500": 72089.6,
            "1443547620": 72089.6,
            "1443547740": 72089.6,
            "1443547860": 72089.6,
            "1443547980": 74274.13333333333,
            "1443548130": 57671.68,
            "1443548250": 72089.6,
            "1443548370": 72089.6,
            "1443548490": 69905.06666666667,
            "1443548610": 72089.6,
            "1443548730": 72089.6,
            "1443548850": 72089.6,
            "1443548970": 72089.6,
            "1443549090": 72089.6,
            "1443549210": 72089.6,
            "1443549330": 72089.6,
            "1443549480": 57671.68,
            "1443549600": 72089.6,
            "1443549840": 72089.6,
            "1443549960": 69905.06666666667,
            "1443550080": 72089.6,
            "1443550200": 72089.6,
            "1443550440": 70997.33333333333,
            "1443550680": 70997.33333333333,
            "1443550950": 64079.64444444444,
            "1443551070": 72089.6,
            "1443551430": 72089.6,
            "1443551550": 72089.6,
            "1443551670": 72089.6,
            "1443551790": 74274.13333333333,
            "1443551910": 72089.6,
            "1443552030": 72089.6,
            "1443552180": 57671.68,
            "1443552300": 72089.6,
            "1443552420": 72089.6,
            "1443552540": 74274.13333333333,
            "1443552660": 72089.6,
            "1443552780": 74274.13333333333,
            "1443552900": 72089.6,
            "1443553020": 72089.6,
            "1443553140": 72089.6,
            "1443553260": 72089.6,
            "1443553380": 69905.06666666667,
            "1443553530": 55924.05333333334,
            "1443553650": 72089.6,
            "1443553770": 72089.6
        }
    }
]

Issue is still there with 1m, but not with bigger intervals:

image

image

image

manolama commented 9 years ago

OK, thanks, let me play around with that data set to see what's going on.

bobrik commented 9 years ago

Looks like I gave you downsampled result, here's the result for disabled downsampling:

[
    {
        "metric": "kafka.topics.offsets",
        "tags": {
            "some": "tags"
        },
        "aggregateTags": [],
        "dps": {
            "1443533381": 77353.96721311475,
            "1443533504": 78856.32520325204,
            "1443533626": 77353.96721311475,
            "1443533749": 76725.0731707317,
            "1443533871": 77353.96721311475,
            "1443533994": 76725.0731707317,
            "1443534117": 74593.82113821138,
            "1443534239": 77353.96721311475,
            "1443534362": 76725.0731707317,
            "1443534484": 77353.96721311475,
            "1443534607": 76725.0731707317,
            "1443534729": 77353.96721311475,
            "1443534852": 76725.0731707317,
            "1443534976": 73992.25806451614,
            "1443535102": 79059.30158730158,
            "1443535225": 74593.82113821138,
            "1443535347": 79502.68852459016,
            "1443535470": 76725.0731707317,
            "1443535593": 76725.0731707317,
            "1443535716": 72462.56910569106,
            "1443535838": 73056.52459016393,
            "1443535962": 69764.12903225806,
            "1443536085": 72462.56910569106,
            "1443536210": 75497.472,
            "1443536333": 74593.82113821138,
            "1443536455": 73056.52459016393,
            "1443536578": 74593.82113821138,
            "1443536702": 71878.19354838709,
            "1443536824": 75205.24590163934,
            "1443536946": 73056.52459016393,
            "1443537070": 73992.25806451614,
            "1443537192": 75205.24590163934,
            "1443537318": 74898.28571428571,
            "1443537444": 72817.77777777778,
            "1443537570": 76978.79365079365,
            "1443537692": 75205.24590163934,
            "1443537817": 73400.32,
            "1443537939": 75205.24590163934,
            "1443538061": 75205.24590163934,
            "1443538184": 74593.82113821138,
            "1443538306": 73056.52459016393,
            "1443538429": 74593.82113821138,
            "1443538552": 72462.56910569106,
            "1443538674": 75205.24590163934,
            "1443538797": 74593.82113821138,
            "1443538919": 75205.24590163934,
            "1443539042": 76725.0731707317,
            "1443539165": 72462.56910569106,
            "1443539289": 71878.19354838709,
            "1443539412": 72462.56910569106,
            "1443539535": 72462.56910569106,
            "1443539657": 75205.24590163934,
            "1443539780": 72462.56910569106,
            "1443539902": 75205.24590163934,
            "1443540026": 71878.19354838709,
            "1443540148": 73056.52459016393,
            "1443540270": 75205.24590163934,
            "1443540392": 73056.52459016393,
            "1443540515": 72462.56910569106,
            "1443540638": 74593.82113821138,
            "1443540761": 76725.0731707317,
            "1443540884": 72462.56910569106,
            "1443541006": 75205.24590163934,
            "1443541129": 74593.82113821138,
            "1443541251": 75205.24590163934,
            "1443541375": 73992.25806451614,
            "1443541498": 74593.82113821138,
            "1443541621": 74593.82113821138,
            "1443541744": 74593.82113821138,
            "1443541866": 73056.52459016393,
            "1443541989": 74593.82113821138,
            "1443542111": 75205.24590163934,
            "1443542235": 73992.25806451614,
            "1443542357": 77353.96721311475,
            "1443542481": 76106.32258064517,
            "1443542604": 78856.32520325204,
            "1443542726": 79502.68852459016,
            "1443542849": 78856.32520325204,
            "1443542972": 76725.0731707317,
            "1443543094": 79502.68852459016,
            "1443543218": 76106.32258064517,
            "1443543340": 79502.68852459016,
            "1443543464": 78220.3870967742,
            "1443543586": 77353.96721311475,
            "1443543708": 79502.68852459016,
            "1443543832": 76106.32258064517,
            "1443543955": 78856.32520325204,
            "1443544079": 76106.32258064517,
            "1443544202": 78856.32520325204,
            "1443544324": 77353.96721311475,
            "1443544447": 74593.82113821138,
            "1443544569": 79502.68852459016,
            "1443544814": 77038.23673469388,
            "1443544937": 76725.0731707317,
            "1443545060": 76725.0731707317,
            "1443545183": 74593.82113821138,
            "1443545306": 76725.0731707317,
            "1443545429": 76725.0731707317,
            "1443545551": 77353.96721311475,
            "1443545674": 76725.0731707317,
            "1443545797": 74593.82113821138,
            "1443545919": 77353.96721311475,
            "1443546042": 76725.0731707317,
            "1443546164": 75205.24590163934,
            "1443546288": 76106.32258064517,
            "1443546411": 72462.56910569106,
            "1443546533": 73056.52459016393,
            "1443546656": 72462.56910569106,
            "1443546778": 73056.52459016393,
            "1443546901": 70331.31707317074,
            "1443547025": 71878.19354838709,
            "1443547147": 73056.52459016393,
            "1443547269": 70907.80327868853,
            "1443547392": 72462.56910569106,
            "1443547514": 70907.80327868853,
            "1443547637": 70331.31707317074,
            "1443547759": 70907.80327868853,
            "1443547884": 69206.016,
            "1443548006": 73056.52459016393,
            "1443548130": 69764.12903225806,
            "1443548253": 70331.31707317074,
            "1443548375": 70907.80327868853,
            "1443548497": 68759.08196721312,
            "1443548620": 70331.31707317074,
            "1443548743": 70331.31707317074,
            "1443548866": 70331.31707317074,
            "1443548989": 70331.31707317074,
            "1443549111": 70907.80327868853,
            "1443549234": 70331.31707317074,
            "1443549356": 70907.80327868853,
            "1443549482": 68656.76190476191,
            "1443549604": 70907.80327868853,
            "1443549850": 70331.31707317074,
            "1443549972": 68759.08196721312,
            "1443550095": 70331.31707317074,
            "1443550218": 70331.31707317074,
            "1443550463": 69548.40816326531,
            "1443550708": 69548.40816326531,
            "1443550954": 70331.31707317074,
            "1443551077": 70331.31707317074,
            "1443551446": 70331.31707317074,
            "1443551568": 70907.80327868853,
            "1443551691": 70331.31707317074,
            "1443551813": 73056.52459016393,
            "1443551936": 70331.31707317074,
            "1443552059": 70331.31707317074,
            "1443552181": 70907.80327868853,
            "1443552303": 70907.80327868853,
            "1443552425": 70907.80327868853,
            "1443552548": 72462.56910569106,
            "1443552672": 69764.12903225806,
            "1443552794": 73056.52459016393,
            "1443552917": 70331.31707317074,
            "1443553039": 70907.80327868853,
            "1443553162": 70331.31707317074,
            "1443553286": 69764.12903225806,
            "1443553409": 68200.06504065041,
            "1443553531": 68759.08196721312,
            "1443553654": 70331.31707317074,
            "1443553777": 70331.31707317074,
            "1443553899": 68759.08196721312,
            "1443554023": 67650.06451612903,
            "1443554145": 70907.80327868853,
            "1443554267": 70907.80327868853,
            "1443554392": 69206.016,
            "1443554514": 70907.80327868853,
            "1443554637": 70331.31707317074,
            "1443554759": 68759.08196721312,
            "1443554882": 68200.06504065041
        }
    }
]
bobrik commented 8 years ago

I think I've found the issue. Imagine rate 1/s with the following datapoints and 1m-avg downsampler:

Calculated rate:

(119 - 1) / (12:01:00 - 12:00:00) = 118 / 60 = 1.96

We get 1.96 while the real value is 1.0. The reason for this is the way downsampler works: it fills the whole interval and runs aggregator on datapoints in this interval.

bobrik commented 8 years ago

It seems like interpolated values should be calculated at the edges of downsampling intervals before running aggregations to have nice results. In my example, the following buckets should be used:

xblitz commented 7 years ago

any news on this? I seem to have the same issues. my metric is a every growing packet loss count, so I use the rate function, but if I want to downsample (with a sum for example) well I get weird spikes

here is the raw datapoints: (we can observe a late polling at midnight raw datapoints but when downsampled it creates a spike because of how it is handled downsampled so if I try to use the rate option (with downsample) it gives me false readings: rate-downsampled