Repository navigation
Backup usage: bill each size for the time it applied, and publish the metric only on change #14310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abh1sar
wants to merge
4
commits into
apache:4.22
Choose a base branch
from
shapeblue:backup-usage-history
base: 4.22
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+676
−29
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e8cb77d
Usage: keep backup size history instead of overwriting it
abh1sar 5a64aad
Usage: do not add a second backup usage row on offering re-assign
abh1sar 48169b4
Backup: publish the backup usage metric only when it changes
abh1sar 8086034
Backup: remove the stored usage metric with its usage event atomically
abh1sar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
engine/schema/src/main/java/org/apache/cloudstack/backup/BackupUsageMetricVO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // 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.cloudstack.backup; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.GeneratedValue; | ||
| import javax.persistence.GenerationType; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.Table; | ||
| import javax.persistence.Temporal; | ||
| import javax.persistence.TemporalType; | ||
|
|
||
| import org.apache.cloudstack.api.InternalIdentity; | ||
|
|
||
| /** | ||
| * The backup usage metric last published for a VM and backup offering. | ||
| */ | ||
| @Entity | ||
| @Table(name = "backup_usage_metric") | ||
| public class BackupUsageMetricVO implements InternalIdentity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id") | ||
| private long id; | ||
|
|
||
| @Column(name = "vm_id") | ||
| private long vmId; | ||
|
|
||
| @Column(name = "backup_offering_id") | ||
| private long backupOfferingId; | ||
|
|
||
| @Column(name = "size") | ||
| private long size; | ||
|
|
||
| @Column(name = "protected_size") | ||
| private long protectedSize; | ||
|
|
||
| @Column(name = "updated") | ||
| @Temporal(value = TemporalType.TIMESTAMP) | ||
| private Date updated; | ||
|
|
||
| protected BackupUsageMetricVO() { | ||
| } | ||
|
|
||
| public BackupUsageMetricVO(long vmId, long backupOfferingId, long size, long protectedSize, Date updated) { | ||
| this.vmId = vmId; | ||
| this.backupOfferingId = backupOfferingId; | ||
| this.size = size; | ||
| this.protectedSize = protectedSize; | ||
| this.updated = updated; | ||
| } | ||
|
|
||
| @Override | ||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public long getVmId() { | ||
| return vmId; | ||
| } | ||
|
|
||
| public long getBackupOfferingId() { | ||
| return backupOfferingId; | ||
| } | ||
|
|
||
| public long getSize() { | ||
| return size; | ||
| } | ||
|
|
||
| public void setSize(long size) { | ||
| this.size = size; | ||
| } | ||
|
|
||
| public long getProtectedSize() { | ||
| return protectedSize; | ||
| } | ||
|
|
||
| public void setProtectedSize(long protectedSize) { | ||
| this.protectedSize = protectedSize; | ||
| } | ||
|
|
||
| public Date getUpdated() { | ||
| return updated; | ||
| } | ||
|
|
||
| public void setUpdated(Date updated) { | ||
| this.updated = updated; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupUsageMetricDao.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // 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.cloudstack.backup.dao; | ||
|
|
||
| import org.apache.cloudstack.backup.BackupUsageMetricVO; | ||
|
|
||
| import com.cloud.utils.db.GenericDao; | ||
|
|
||
| public interface BackupUsageMetricDao extends GenericDao<BackupUsageMetricVO, Long> { | ||
| BackupUsageMetricVO findByVmAndOffering(long vmId, long backupOfferingId); | ||
|
|
||
| int removeByVmAndOffering(long vmId, long backupOfferingId); | ||
| } |
54 changes: 54 additions & 0 deletions
54
engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupUsageMetricDaoImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // 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.cloudstack.backup.dao; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
|
|
||
| import org.apache.cloudstack.backup.BackupUsageMetricVO; | ||
|
|
||
| import com.cloud.utils.db.GenericDaoBase; | ||
| import com.cloud.utils.db.SearchBuilder; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
|
|
||
| public class BackupUsageMetricDaoImpl extends GenericDaoBase<BackupUsageMetricVO, Long> implements BackupUsageMetricDao { | ||
| private SearchBuilder<BackupUsageMetricVO> vmAndOfferingSearch; | ||
|
|
||
| @PostConstruct | ||
| protected void init() { | ||
| vmAndOfferingSearch = createSearchBuilder(); | ||
| vmAndOfferingSearch.and("vmId", vmAndOfferingSearch.entity().getVmId(), SearchCriteria.Op.EQ); | ||
| vmAndOfferingSearch.and("backupOfferingId", vmAndOfferingSearch.entity().getBackupOfferingId(), SearchCriteria.Op.EQ); | ||
| vmAndOfferingSearch.done(); | ||
| } | ||
|
|
||
| private SearchCriteria<BackupUsageMetricVO> createVmAndOfferingCriteria(long vmId, long backupOfferingId) { | ||
| SearchCriteria<BackupUsageMetricVO> sc = vmAndOfferingSearch.create(); | ||
| sc.setParameters("vmId", vmId); | ||
| sc.setParameters("backupOfferingId", backupOfferingId); | ||
| return sc; | ||
| } | ||
|
|
||
| @Override | ||
| public BackupUsageMetricVO findByVmAndOffering(long vmId, long backupOfferingId) { | ||
| return findOneBy(createVmAndOfferingCriteria(vmId, backupOfferingId)); | ||
| } | ||
|
|
||
| @Override | ||
| public int removeByVmAndOffering(long vmId, long backupOfferingId) { | ||
| return remove(createVmAndOfferingCriteria(vmId, backupOfferingId)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,15 @@ | |
| --; | ||
| -- Schema upgrade from 4.22.1.0 to 4.22.2.0 | ||
| --; | ||
|
|
||
| -- Last backup usage metric published per VM and backup offering | ||
| CREATE TABLE IF NOT EXISTS `cloud`.`backup_usage_metric` ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we hook the 4.22.2 upgrade step into the upgrade checker here? right now this table never gets made and the backup smoke test fails deleting a backup |
||
| `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', | ||
| `vm_id` bigint unsigned NOT NULL COMMENT 'VM ID', | ||
| `backup_offering_id` bigint unsigned NOT NULL COMMENT 'Backup offering ID', | ||
| `size` bigint unsigned NOT NULL COMMENT 'Backup size last published', | ||
| `protected_size` bigint unsigned NOT NULL COMMENT 'Protected size last published', | ||
| `updated` datetime NOT NULL COMMENT 'Date the metric was last published', | ||
| PRIMARY KEY (`id`), | ||
| UNIQUE KEY `uk_backup_usage_metric__vm_id__backup_offering_id` (`vm_id`, `backup_offering_id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if this fails once? the size is already saved as sent, so it never gets sent again and billing stays on the old size until it changes