feat(aps): add Amazon Managed Service for Prometheus workspaces (#2604)

* feat(aps): add Amazon Managed Service for Prometheus workspaces

Implements the AMP workspace lifecycle (CreateWorkspace,
DescribeWorkspace, ListWorkspaces, UpdateWorkspaceAlias,
DeleteWorkspace) plus tagging through the shared /tags/{resourceArn}
dispatcher via a TagHandler with service key aps. Previously the aps
service did not exist, so aws_prometheus_workspace could not be created
through Terraform or Pulumi at all.

Workspaces are ACTIVE from birth so the provider's create waiter
(CREATING to ACTIVE) completes on its first DescribeWorkspace poll, and
a deleted workspace answers DescribeWorkspace with the typed
ResourceNotFoundException its delete waiter matches. createdAt is
serialized as restJson1 epoch-seconds; the ListWorkspaces alias
parameter is a prefix filter, matching the provider's alias_prefix.

clientToken is accepted and ignored, kmsKeyArn is stored and echoed,
and no alertmanager/rulegroups/scraper/logging operations are included.

* refactor(aps): build ARNs via RegionResolver and parse tag ARNs with AwsArnUtils

Replaces the inlined AwsArnUtils.Arn.of + config.defaultRegion pair with
regionResolver.getRegion()/buildArn so a request signed for another
region gets an ARN and endpoint in that region, and drops the
EmulatorConfig dependency that existed only for that getter. The tag
dispatcher path now parses ARNs with AwsArnUtils.parse plus an explicit
workspace/ prefix check (the SchedulerTagHandler idiom), so a
non-workspace aps ARN fails with ValidationException instead of a
misleading workspace ResourceNotFoundException. Also makes the delete
and alias mutators void (their returns were unused) and removes a dead
DELETING status mutation.

* docs(aps): map the aps service key to managed-prometheus.md in the service matrix

The docs-check gate matches ResolvedServiceCatalog external keys against
docs/services/index.md rows by filename; aps is documented at
managed-prometheus.md, so it needs the same alias treatment as
kafka -> msk.

* fix(aps): partition workspaces by request region and align minor wire details

Review follow-ups from #2604:

- Key the workspace store by region (region::workspaceId, like
  CloudWatchLogsService's groupKey), and thread the SigV4-resolved request
  region through every lifecycle and TagHandler operation, so workspaces
  created in one region are invisible to describe/list/delete/tag calls
  served in another. Covered by unit and HTTP region-isolation tests.
- Default ListWorkspaces to pages of 100 (AWS's documented default) while
  keeping the 1000 ceiling, via Pagination's seven-argument overload.
- Strip leading/trailing blanks from aliases at create, alias update, and
  the list prefix filter, per the documented normalisation.
- Return DeleteWorkspace's 202 with an empty body instead of {}.
- Reject tag keys beginning with the reserved aws: prefix in TagResource
  with a ValidationException.

* refactor(aps): align the reserved tag-key check with sibling services

- Match the aws: prefix case-insensitively as a plain loop, the same idiom
  as FisService and BatchService, instead of a case-sensitive stream chain.
- Derive key() from keyPrefix() so the :: separator lives in one place, and
  hoist the region prefix out of the scan predicate.
- Replace the two near-identical SigV4 Authorization literals in the
  integration test with an auth(region) helper.
This commit is contained in:
Matan Baruch authored and GitHub committed 2026-08-28 10:05:42 -04:00
1 parent 29325006bb
commit 277809fb41
15 files changed
+1061

No files matched your search

@@ -0,0 +1,127 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import software.amazon.awssdk.services.amp.AmpClient;
import software.amazon.awssdk.services.amp.model.CreateWorkspaceResponse;
import software.amazon.awssdk.services.amp.model.DescribeWorkspaceResponse;
import software.amazon.awssdk.services.amp.model.ListWorkspacesResponse;
import software.amazon.awssdk.services.amp.model.ResourceNotFoundException;
import software.amazon.awssdk.services.amp.model.WorkspaceStatusCode;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("Managed Prometheus (AMP)")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class AmpTest {
private static AmpClient amp;
private static String alias;
private static String workspaceId;
private static String workspaceArn;
@BeforeAll
static void setup() {
amp = TestFixtures.ampClient();
alias = "sdk-test-workspace-" + System.currentTimeMillis();
}
@AfterAll
static void cleanup() {
if (amp != null) {
if (workspaceId != null) {
try {
amp.deleteWorkspace(r -> r.workspaceId(workspaceId));
} catch (Exception ignored) {}
}
amp.close();
}
}
@Test
@Order(1)
void createWorkspace() {
CreateWorkspaceResponse response = amp.createWorkspace(r -> r
.alias(alias)
.tags(Map.of("team", "devops")));
workspaceId = response.workspaceId();
workspaceArn = response.arn();
assertThat(workspaceId).startsWith("ws-");
assertThat(workspaceArn).contains(":aps:").contains(":workspace/" + workspaceId);
assertThat(response.status().statusCode()).isEqualTo(WorkspaceStatusCode.ACTIVE);
assertThat(response.tags()).containsEntry("team", "devops");
}
@Test
@Order(2)
void describeWorkspace() {
DescribeWorkspaceResponse response = amp.describeWorkspace(r -> r.workspaceId(workspaceId));
assertThat(response.workspace().workspaceId()).isEqualTo(workspaceId);
assertThat(response.workspace().alias()).isEqualTo(alias);
assertThat(response.workspace().arn()).isEqualTo(workspaceArn);
assertThat(response.workspace().status().statusCode()).isEqualTo(WorkspaceStatusCode.ACTIVE);
assertThat(response.workspace().prometheusEndpoint()).contains("/workspaces/" + workspaceId);
// Proves the wire timestamp is restJson1 epoch-seconds: an ISO string here fails SDK
// deserialization before any assertion runs.
assertThat(response.workspace().createdAt()).isNotNull();
assertThat(response.workspace().tags()).containsEntry("team", "devops");
}
@Test
@Order(3)
void listWorkspacesByAliasPrefix() {
ListWorkspacesResponse response = amp.listWorkspaces(r -> r.alias("sdk-test-workspace-"));
assertThat(response.workspaces())
.anySatisfy(w -> assertThat(w.workspaceId()).isEqualTo(workspaceId));
}
@Test
@Order(4)
void updateWorkspaceAlias() {
amp.updateWorkspaceAlias(r -> r.workspaceId(workspaceId).alias(alias + "-renamed"));
assertThat(amp.describeWorkspace(r -> r.workspaceId(workspaceId)).workspace().alias())
.isEqualTo(alias + "-renamed");
}
@Test
@Order(5)
void tagResourceRoundTrip() {
amp.tagResource(r -> r.resourceArn(workspaceArn).tags(Map.of("env", "test")));
assertThat(amp.listTagsForResource(r -> r.resourceArn(workspaceArn)).tags())
.containsEntry("team", "devops")
.containsEntry("env", "test");
amp.untagResource(r -> r.resourceArn(workspaceArn).tagKeys("env"));
assertThat(amp.listTagsForResource(r -> r.resourceArn(workspaceArn)).tags())
.containsEntry("team", "devops")
.doesNotContainKey("env");
}
@Test
@Order(6)
void deleteWorkspaceThenDescribeThrowsResourceNotFound() {
amp.deleteWorkspace(r -> r.workspaceId(workspaceId));
// The terraform/pulumi provider's delete waiter matches this typed exception
// (errs.IsA[*types.ResourceNotFoundException]) to treat the workspace as gone.
assertThatThrownBy(() -> amp.describeWorkspace(r -> r.workspaceId(workspaceId)))
.isInstanceOf(ResourceNotFoundException.class);
workspaceId = null;
}
}