Skip to content

Commit

Permalink
Release to main 1.2.0 (#616)
Browse files Browse the repository at this point in the history
* log test results (#608)
* add health check to stellar observer (#602)
* stellar observer retry with exponential back-off timer (#607)
* update helm chart by exposing the metrics port to the internal network (#610)
* expose the `8082` metrics port to the internal network.
* add `deployment.annotations` to the example values.
* delete duplicate appearance of `ORG_URL` in the example values.
* updated the version string and the change log
* allow refund status to patch transaction (#618)
* fix: stop crashing when parsing response content into ErrorResponse (#612)
* separate observer deployment (#613)
* remove basic tests from release_main.yml, release_release.yml to avoid duplicating tests
  • Loading branch information
lijamie98 authored Oct 11, 2022
1 parent 48ad477 commit 92f941d
Show file tree
Hide file tree
Showing 34 changed files with 596 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/basic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
- name: Find Home Domain (Preview or Dev)
id: endpoint-finder
run: |
echo ${{github.event.pull_request.number}}
echo $PR_NUMBER
export HOME_DOMAIN=https://anchor-sep-server-dev.stellar.org
if [ ! -z "$PR_NUMBER" ]
then
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ on:
- published

jobs:
tests:
uses: ./.github/workflows/basic_tests.yml # execute the callable basic_tests.yml
# tests:
# uses: ./.github/workflows/basic_tests.yml # execute the callable basic_tests.yml

end_to_end_tests:
uses: ./.github/workflows/end_to_end_tests.yml # execute the callable end_to_end_tests.yml

build_and_push_docker_image:
needs: [tests]
# needs: [tests]
runs-on: ubuntu-latest
name: Push stellar/anchor-platform:VERSION to DockerHub
steps:
Expand All @@ -37,7 +37,7 @@ jobs:

complete:
if: always()
needs: [tests, build_and_push_docker_image]
needs: [build_and_push_docker_image]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ on:
- 'releases/**'

jobs:
tests:
uses: ./.github/workflows/basic_tests.yml # use the callable tests job to run tests
# tests:
# uses: ./.github/workflows/basic_tests.yml # use the callable tests job to run tests

build_and_push_docker_image:
needs: [tests]
# needs: [tests]
runs-on: ubuntu-latest
name: Push stellar/anchor-platform:sha to DockerHub
steps:
Expand All @@ -37,7 +37,7 @@ jobs:

complete:
if: always()
needs: [tests, build_and_push_docker_image]
needs: [build_and_push_docker_image]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0
* Add Stellar observer retries with exponential back-off timer [#607](https://github.com/stellar/java-stellar-anchor-sdk/pull/607)
* Add health check endpoint to the Stellar observer [#602](https://github.com/stellar/java-stellar-anchor-sdk/pull/602)

## 1.1.1

Update the version of Helm Chart.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.stellar.anchor.api.exception;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = false)
public class EventPublishException extends AnchorException {
public EventPublishException(String message, Exception cause) {
super(message, cause);
}

public EventPublishException(String message) {
super(message);
}
}
12 changes: 10 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ subprojects {

javadoc { options.encoding = "UTF-8" }

test { useJUnitPlatform() }
test {
useJUnitPlatform()

testLogging {
events("SKIPPED", "FAILED")
showExceptions = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
}

configurations {
Expand All @@ -110,7 +118,7 @@ subprojects {

allprojects {
group = "org.stellar.anchor-sdk"
version = "1.1.1"
version = "1.2.0"

tasks.jar {
manifest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.stellar.anchor.event;

import org.stellar.anchor.api.exception.EventPublishException;
import org.stellar.anchor.event.models.AnchorEvent;

public interface EventPublishService {
void publish(AnchorEvent event);
void publish(AnchorEvent event) throws EventPublishException;
}
17 changes: 11 additions & 6 deletions core/src/main/java/org/stellar/anchor/event/KafkaEventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import io.micrometer.core.instrument.Metrics;
import java.util.Map;
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.header.internals.RecordHeader;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.kafka.support.serializer.JsonSerializer;
import org.stellar.anchor.api.exception.EventPublishException;
import org.stellar.anchor.config.KafkaConfig;
import org.stellar.anchor.event.models.AnchorEvent;
import org.stellar.anchor.util.Log;
Expand Down Expand Up @@ -39,7 +37,7 @@ public KafkaEventService(KafkaConfig kafkaConfig) {
this.useSingleQueue = kafkaConfig.isUseSingleQueue();
}

public void publish(AnchorEvent event) {
public void publish(AnchorEvent event) throws EventPublishException {
try {
String topic;
if (useSingleQueue) {
Expand All @@ -49,7 +47,14 @@ public void publish(AnchorEvent event) {
}
ProducerRecord<String, AnchorEvent> record = new ProducerRecord<>(topic, event);
record.headers().add(new RecordHeader("type", event.getType().getBytes()));
producer.send(record);

// If the queue is offline, throw an exception
try {
producer.send(record).get();
} catch (Exception ex) {
throw new EventPublishException("Failed to publish event to Kafka.", ex);
}

Metrics.counter(
"event.published", "class", event.getClass().getSimpleName(), "type", event.getType())
.increment();
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/java/org/stellar/anchor/event/SqsEventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder;
import com.amazonaws.services.sqs.model.MessageAttributeValue;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.model.SendMessageResult;
import com.google.gson.Gson;
import io.micrometer.core.instrument.Metrics;
import java.util.Map;
import org.stellar.anchor.api.exception.EventPublishException;
import org.stellar.anchor.config.SqsConfig;
import org.stellar.anchor.event.models.AnchorEvent;
import org.stellar.anchor.util.Log;
Expand Down Expand Up @@ -57,7 +59,18 @@ public void publish(AnchorEvent event) {
new MessageAttributeValue()
.withDataType("String")
.withStringValue(event.getClass().getSimpleName()));
sqsClient.sendMessage(sendMessageRequest);
SendMessageResult sendMessageResult = sqsClient.sendMessage(sendMessageRequest);

// If the queue is offline, throw an exception
int statusCode = sendMessageResult.getSdkHttpMetadata().getHttpStatusCode();
if (statusCode < 200 || statusCode > 299) {
Log.error("failed to send message to SQS");
throw new EventPublishException(
String.format(
"Failed to publish event to AWS SQS. [StatusCode: %d] [Metadata: %s]",
statusCode, sendMessageResult.getSdkHttpMetadata().toString()));
}

Metrics.counter(
"event.published", "class", event.getClass().getSimpleName(), "type", event.getType())
.increment();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.stellar.anchor.util;

/**
* ExponentialBackoffUtil is used to do an exponential back-off, where the sleep time is doubled
* every time, until things succeed and the `resetSleepSeconds()` method is called.
*/
public class ExponentialBackoffTimer {
static final long DEFAULT_INITIAL_SLEEP_SECONDS = 1;
static final long DEFAULT_MAX_SLEEP_SECONDS = 300; // 5 minutes

final long initialSleepSeconds;
final long maxSleepSeconds;
long sleepSeconds;

public ExponentialBackoffTimer() {
this(DEFAULT_INITIAL_SLEEP_SECONDS, DEFAULT_MAX_SLEEP_SECONDS);
}

public ExponentialBackoffTimer(long initialSleepSeconds, long maxSleepSeconds) {
if (initialSleepSeconds < 1) {
throw new IllegalArgumentException(
"The formula 'initialSleepSeconds >= 1' is not being respected.");
}
this.initialSleepSeconds = initialSleepSeconds;
this.sleepSeconds = initialSleepSeconds;

if (maxSleepSeconds < initialSleepSeconds) {
throw new IllegalArgumentException(
"The formula 'maxSleepSeconds >= initialSleepSeconds' is not being respected.");
}
this.maxSleepSeconds = maxSleepSeconds;
}

public void increase() {
sleepSeconds = Long.min(sleepSeconds * 2, maxSleepSeconds);
}

public void reset() {
sleepSeconds = initialSleepSeconds;
}

public void sleep() throws InterruptedException {
Thread.sleep(sleepSeconds * 1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.stellar.anchor.util

import java.time.Instant
import java.time.temporal.ChronoUnit
import kotlin.test.assertEquals
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class ExponentialBackoffTimerTest {
@Test
fun test_constructorWithParameters() {
// validate if 'initialSleepSeconds >= 1'
var ex: IllegalArgumentException = assertThrows { ExponentialBackoffTimer(0, 0) }
assertEquals("The formula 'initialSleepSeconds >= 1' is not being respected.", ex.message)

// validate if 'maxSleepSeconds >= initialSleepSeconds'
ex = assertThrows { ExponentialBackoffTimer(1, 0) }
assertEquals(
"The formula 'maxSleepSeconds >= initialSleepSeconds' is not being respected.",
ex.message
)

// constructor with all parameters works
lateinit var exponentialBackoffTimer: ExponentialBackoffTimer
assertDoesNotThrow { exponentialBackoffTimer = ExponentialBackoffTimer(1, 2) }
assertEquals(1, exponentialBackoffTimer.initialSleepSeconds)
assertEquals(2, exponentialBackoffTimer.maxSleepSeconds)

// constructor with no parameters works
assertDoesNotThrow { exponentialBackoffTimer = ExponentialBackoffTimer() }
assertEquals(
ExponentialBackoffTimer.DEFAULT_INITIAL_SLEEP_SECONDS,
exponentialBackoffTimer.initialSleepSeconds
)
assertEquals(
ExponentialBackoffTimer.DEFAULT_MAX_SLEEP_SECONDS,
exponentialBackoffTimer.maxSleepSeconds
)
}

@Test
fun test_increase() {
val exponentialBackoffTimer = ExponentialBackoffTimer(1, 5)
assertEquals(1, exponentialBackoffTimer.sleepSeconds)

exponentialBackoffTimer.increase()
assertEquals(2, exponentialBackoffTimer.sleepSeconds)

exponentialBackoffTimer.increase()
assertEquals(4, exponentialBackoffTimer.sleepSeconds)

exponentialBackoffTimer.increase()
assertEquals(5, exponentialBackoffTimer.sleepSeconds)

exponentialBackoffTimer.increase()
assertEquals(5, exponentialBackoffTimer.sleepSeconds)
}

@Test
fun test_reset() {
val exponentialBackoffTimer = ExponentialBackoffTimer(1, 5)
exponentialBackoffTimer.increase()
assertEquals(2, exponentialBackoffTimer.sleepSeconds)

exponentialBackoffTimer.reset()
assertEquals(1, exponentialBackoffTimer.sleepSeconds)
}

@Test
fun test_sleep() {
val exponentialBackoffTimer = ExponentialBackoffTimer(1, 5)

val beforeSleep = Instant.now()
exponentialBackoffTimer.sleep()
val afterSleep = Instant.now()

assertEquals(1, ChronoUnit.SECONDS.between(beforeSleep, afterSleep))
}
}
2 changes: 1 addition & 1 deletion helm-charts/sep-service/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
sources:
- https://github.com/stellar/java-stellar-anchor-sdk
name: sep
version: 0.3.88
version: 0.3.91
41 changes: 33 additions & 8 deletions helm-charts/sep-service/example_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ deployment:
configMaps:
- name: assets
mountPath: assets
hosts:
- host: "your_anchor_domain.com"
path: /
pathType: Prefix
backend:
servicePort: "{{ .Values.service.containerPort }}"
serviceName: "{{ .Values.fullName }}-svc-{{ .Values.service.name }}"
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8082"
prometheus.io/scrape: "true"
env:
- name: STELLAR_ANCHOR_CONFIG
value: file:/config/anchor-config.yaml
Expand Down Expand Up @@ -58,6 +55,35 @@ ingress:
backend:
servicePort: "{{ .Values.service.containerPort }}"
serviceName: "{{ .Values.fullName }}-svc-{{ .Values.service.name }}"
#
# If you want to have a dedicated stellar-observer service, you need to
# uncomment the `stellarObserver` section below.
#
# Attention! If you use the stellar observer as a separate service – by setting
# `stellarObserver.enabled` flag to `true` – you must use a shared database that
# will be accessible by both deployments (sep-server and stellar-observer).
# In-memory databases won't work.
# stellarObserver:
# # This will enable the stellar-observer service as a separate deployment:
# enabled: true
# # The stellarObserver.deployment section is optional, the templates have
# # default values.
# deployment:
# port: 8083
# probePath: "/health"
# probePeriodSeconds: 15
# initialDelaySeconds: 60
# startupProbeFailureThreshold: 10
# livenessProbeFailureThreshold: 2
# ingress:
# tls:
# host: "observer.your_anchor_domain.com" # Replace this with a valid host name
# rules:
# hosts:
# - host: "observer.your_anchor_domain.com" # Replace this with a valid host name
# path: /
# pathType: Prefix
#
stellar:
toml:
#accounts: ['"GCHLHDBOKG2JWMJQBTLSL5XG6NO7ESXI2TAQKZXCXWXB5WI2X6W233PR"']
Expand All @@ -66,7 +92,6 @@ stellar:
ORG_NAME: "Stellar Development Foundation"
ORG_URL: "https://www.stellar.org"
ORG_DESCRIPTION: "Stellar Network"
ORG_URL: "https://your_org_url.png"
ORG_SUPPORT_EMAIL: "[email protected]"
anchor:
data_access:
Expand Down
Loading

0 comments on commit 92f941d

Please sign in to comment.