arjunashok commented on code in PR #249: URL: https://github.com/apache/cassandra-sidecar/pull/249#discussion_r2291748091
########## server-common/src/main/java/org/apache/cassandra/sidecar/common/server/utils/CompactionStatsConverter.java: ########## @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.common.server.utils; + +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.cassandra.sidecar.common.response.CompactionStatsResponse; +import org.apache.cassandra.sidecar.common.response.data.ActiveCompactionEntry; +import org.apache.cassandra.sidecar.common.server.data.ActiveCompactionEntryData; +import org.apache.cassandra.sidecar.common.server.data.CompactionStatsData; + +/** + * Converter class for converting between data objects and API response objects for compaction stats + */ +public final class CompactionStatsConverter +{ + /** + * Private constructor to prevent instantiation + */ + private CompactionStatsConverter() + { + // utility class + } + + /** + * Converts CompactionStatsData to CompactionStatsResponse + * + * @param data the data object to convert + * @return the API response object + */ + public static CompactionStatsResponse toResponse(CompactionStatsData data) + { + if (data == null) + { + return null; Review Comment: Do we want to return null here, or fail-fast with a non-200 response code? ########## server-common/src/main/java/org/apache/cassandra/sidecar/common/server/utils/CompactionStatsConverter.java: ########## @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.common.server.utils; + +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.cassandra.sidecar.common.response.CompactionStatsResponse; +import org.apache.cassandra.sidecar.common.response.data.ActiveCompactionEntry; +import org.apache.cassandra.sidecar.common.server.data.ActiveCompactionEntryData; +import org.apache.cassandra.sidecar.common.server.data.CompactionStatsData; + +/** + * Converter class for converting between data objects and API response objects for compaction stats + */ +public final class CompactionStatsConverter +{ + /** + * Private constructor to prevent instantiation + */ + private CompactionStatsConverter() + { + // utility class + } + + /** + * Converts CompactionStatsData to CompactionStatsResponse + * + * @param data the data object to convert + * @return the API response object + */ + public static CompactionStatsResponse toResponse(CompactionStatsData data) + { + if (data == null) + { + return null; + } + + CompactionStatsResponse.CompletedCompactionsRate responseRate = null; + if (data.completedCompactionsRate() != null) Review Comment: Likewise, in which scenario do you foresee these stats being null? If it is valid for them to be null for non-error scenarios, eg when there are no compactions ongoing, we should be more explicit about that in the API response. In your implementation the current behavior is that we return the metrics that we have available (success w/ partial response). I'm wondering if we should fail-fast instead. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

