{"record":{"id":"55855d175188c013","repo":"apache/skywalking","slug":"current-time-bucket-is-not-in-minute-dimensionalit","errorCode":null,"errorMessage":"Current time bucket is not in minute dimensionality","messagePattern":"Current time bucket is not in minute dimensionality","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/Metrics.java","lineNumber":111,"sourceCode":"     */\n    public void setLastUpdateTimestamp(long timestamp) {\n        lastUpdateTimestamp = timestamp;\n    }\n\n    /**\n     * @param timestamp        of current time\n     * @param expiredThreshold represents the duration between last update time and the time point removing from cache.\n     * @return true means this metrics should be removed from cache.\n     */\n    public boolean isExpired(long timestamp, long expiredThreshold) {\n        return timestamp - lastUpdateTimestamp > expiredThreshold;\n    }\n\n    public long toTimeBucketInHour() {\n        if (isMinuteBucket()) {\n            return timeBucket / 100;\n        } else {\n            throw new IllegalStateException(\"Current time bucket is not in minute dimensionality\");\n        }\n    }\n\n    public long toTimeBucketInDay() {\n        if (isMinuteBucket()) {\n            return timeBucket / 10000;\n        } else if (isHourBucket()) {\n            return timeBucket / 100;\n        } else {\n            throw new IllegalStateException(\"Current time bucket is not in minute dimensionality\");\n        }\n    }\n\n    /**\n     * Always get the duration for this time bucket in minute.\n     */\n    protected long getDurationInMinute() {\n        if (isMinuteBucket()) {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/Metrics.java#L93-L129","documentation":"Metrics.toTimeBucketInHour() converts a minute-dimensionality time bucket (yyyyMMddHHmm) to the hour bucket by dividing by 100. It only supports minute buckets; if the metric's timeBucket is hour, day, or second dimensional, isMinuteBucket() is false and this IllegalStateException is thrown (the message text 'not in minute dimensionality' is slightly misleading — it means the bucket is NOT minute).","triggerScenarios":"A custom Metrics subclass or a meter function calls toTimeBucketInHour() on a metric whose timeBucket was set with TimeBucket.getTimeBucket(System.currentTimeMillis(), DownSampling.Hour) or any non-minute downsampling.","commonSituations":"Writing a custom OAL/MAL metrics function that reuses hour-level downsampling but inherits the minute-only conversion; changing a metric's DownSampling annotation from Minute to Hour while keeping the hour-conversion call.","solutions":["Ensure the metric is built on a minute time bucket (DownSampling.Minute) before calling toTimeBucketInHour(), or compute the hour bucket directly","In custom metrics code, guard with a TimeBucket.isMinuteBucket(timeBucket) check and skip/convert appropriately","Audit custom MetricFunction implementations added to the classpath for unsupported bucket conversions"],"exampleFix":"// before\nlong hourBucket = metrics.toTimeBucketInHour();\n// after (only convert when source is minute-granularity)\nlong hourBucket = TimeBucket.isMinuteBucket(timeBucket) ? timeBucket / 100 : timeBucket;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Java: check granularity before converting\nboolean isMinuteBucket(long tb) {\n    return TimeBucket.isMinuteBucket(tb); // yyyyMMddHHmm, 12 digits\n}\n// usage\nlong hourBucket = isMinuteBucket(metrics.getTimeBucket()) ? metrics.toTimeBucketInHour() : metrics.getTimeBucket();","tryCatchPattern":"Not recommended — prefer the granularity guard; if unavoidable, catch IllegalStateException and fall back to the raw timeBucket with a loud WARN.","preventionTips":["Keep metrics streams on DownSampling.Minute unless the function explicitly supports other granularities","Unit-test custom MetricFunctions with minute, hour, and day buckets","Read TimeBucket helper semantics before reusing conversion methods in custom code"],"tags":["metrics","time-bucket","downsampling","oal","core"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}