Skip to content

Commit

Permalink
Update the alert internal model (#382)
Browse files Browse the repository at this point in the history
- Updates the fields in the Alert model
- Rips out all code related to the creation and evaluation of alerts in the previous form.

For the latter change in particular, I figured that there wasn't much value in keeping the existing data and view layers around with this change in place since the interface additions would propagate into those layers and I don't intend on supporting them now anyway.
  • Loading branch information
cwbriones authored May 12, 2020
1 parent 3361091 commit 50d523f
Show file tree
Hide file tree
Showing 31 changed files with 437 additions and 3,514 deletions.
80 changes: 80 additions & 0 deletions app/com/arpnetworking/metrics/portal/alerts/AlertJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2020 Dropbox, Inc.
*
* Licensed 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 com.arpnetworking.metrics.portal.alerts;

import com.arpnetworking.metrics.portal.scheduling.Schedule;
import com.arpnetworking.metrics.portal.scheduling.impl.NeverSchedule;
import com.google.inject.Injector;
import models.internal.alerts.Alert;
import models.internal.alerts.AlertEvaluationResult;
import models.internal.scheduling.Job;

import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

/**
* A wrapper around {@code Alert} instances to allow for scheduling and evaluation of Alert queries.
*
* @author Christian Briones (cbriones at dropbox dot com)
*/
public class AlertJob implements Job<AlertEvaluationResult> {
private final Alert _alert;

/**
* Create a job from an alert.
*
* @param alert The alert that this job will evaluate.
*/
public AlertJob(final Alert alert) {
this._alert = alert;
}

@Override
public UUID getId() {
return _alert.getId();
}

@Override
public Optional<String> getETag() {
return Optional.empty();
}

@Override
public Schedule getSchedule() {
// TODO(cbriones): If the alert is enabled, this should return an interval corresponding to the smallest query period
// in that alert's query.
return NeverSchedule.getInstance();
}

@Override
public Duration getTimeout() {
return Duration.of(1, ChronoUnit.MINUTES);
}

@Override
public CompletionStage<? extends AlertEvaluationResult> execute(final Injector injector, final Instant scheduled) {
final CompletableFuture<AlertEvaluationResult> future = new CompletableFuture<>();
future.completeExceptionally(new UnsupportedOperationException("Alert execution is not implemented"));
return future;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.arpnetworking.metrics.portal.alerts;

import models.internal.Alert;
import models.internal.AlertQuery;
import models.internal.Organization;
import models.internal.QueryResult;
import models.internal.alerts.Alert;

import java.util.Optional;
import java.util.UUID;
Expand Down

This file was deleted.

Loading

0 comments on commit 50d523f

Please sign in to comment.