add trace starts for each object type
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"go.infratographer.com/x/events"
|
"go.infratographer.com/x/events"
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
|
||||||
)
|
)
|
||||||
@@ -58,6 +60,10 @@ func (s *service) IsOrganizationID(id gidx.PrefixedID) bool {
|
|||||||
|
|
||||||
// TouchOrganization initializes a sync for the provided organization id for relationships and memberships.
|
// TouchOrganization initializes a sync for the provided organization id for relationships and memberships.
|
||||||
func (s *service) TouchOrganization(ctx context.Context, id gidx.PrefixedID) error {
|
func (s *service) TouchOrganization(ctx context.Context, id gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "TouchOrganization", trace.WithAttributes(attribute.String("resource.id", id.String())))
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
logger := s.logger.With("organization.id", id.String())
|
logger := s.logger.With("organization.id", id.String())
|
||||||
|
|
||||||
org, err := s.metal.GetOrganizationDetails(ctx, id)
|
org, err := s.metal.GetOrganizationDetails(ctx, id)
|
||||||
@@ -89,6 +95,10 @@ func (s *service) TouchOrganization(ctx context.Context, id gidx.PrefixedID) err
|
|||||||
|
|
||||||
// DeleteOrganization deletes the provided organization id.
|
// DeleteOrganization deletes the provided organization id.
|
||||||
func (s *service) DeleteOrganization(ctx context.Context, id gidx.PrefixedID) error {
|
func (s *service) DeleteOrganization(ctx context.Context, id gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "DeleteOrganization", trace.WithAttributes(attribute.String("resource.id", id.String())))
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
err := s.publisher.PublishChange(ctx, organizationEvent, events.ChangeMessage{
|
err := s.publisher.PublishChange(ctx, organizationEvent, events.ChangeMessage{
|
||||||
SubjectID: id,
|
SubjectID: id,
|
||||||
EventType: string(events.DeleteChangeType),
|
EventType: string(events.DeleteChangeType),
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
||||||
@@ -13,6 +15,15 @@ import (
|
|||||||
// processMemberships determines the changes between what is wanted and what is live and executes on the differences.
|
// processMemberships determines the changes between what is wanted and what is live and executes on the differences.
|
||||||
// If skipDeletions is true, no deletes will be executed.
|
// If skipDeletions is true, no deletes will be executed.
|
||||||
func (s *service) processMemberships(ctx context.Context, relationships Relationships, skipDeletions bool) (int, int) {
|
func (s *service) processMemberships(ctx context.Context, relationships Relationships, skipDeletions bool) (int, int) {
|
||||||
|
ctx, span := tracer.Start(ctx, "processMemberships",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.String("resource.id", relationships.Resource.PrefixedID().String()),
|
||||||
|
attribute.Int("resource.memberships", len(relationships.Memberships)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
if len(relationships.Memberships) == 0 {
|
if len(relationships.Memberships) == 0 {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"go.infratographer.com/x/events"
|
"go.infratographer.com/x/events"
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
||||||
)
|
)
|
||||||
@@ -13,6 +15,15 @@ import (
|
|||||||
// Relationship creations use events.
|
// Relationship creations use events.
|
||||||
// Relationship deletions use the api, as delete events delete all related resources and not just the provided ones.
|
// Relationship deletions use the api, as delete events delete all related resources and not just the provided ones.
|
||||||
func (s *service) processRelationships(ctx context.Context, eventType string, relationships Relationships) int {
|
func (s *service) processRelationships(ctx context.Context, eventType string, relationships Relationships) int {
|
||||||
|
ctx, span := tracer.Start(ctx, "processRelationships",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.String("resource.id", relationships.Resource.PrefixedID().String()),
|
||||||
|
attribute.Int("resource.subject_relationships", len(relationships.SubjectRelationships)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
rlogger := s.logger.With("resource.id", relationships.Resource.PrefixedID())
|
rlogger := s.logger.With("resource.id", relationships.Resource.PrefixedID())
|
||||||
|
|
||||||
wantParentRelationship, wantSubjectRelationships := s.mapRelationWants(relationships)
|
wantParentRelationship, wantSubjectRelationships := s.mapRelationWants(relationships)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"go.infratographer.com/x/events"
|
"go.infratographer.com/x/events"
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
|
||||||
)
|
)
|
||||||
@@ -51,6 +53,10 @@ func (s *service) IsProjectID(id gidx.PrefixedID) bool {
|
|||||||
|
|
||||||
// TouchProject initializes a sync for the provided project id for relationships and memberships.
|
// TouchProject initializes a sync for the provided project id for relationships and memberships.
|
||||||
func (s *service) TouchProject(ctx context.Context, id gidx.PrefixedID) error {
|
func (s *service) TouchProject(ctx context.Context, id gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "TouchProject", trace.WithAttributes(attribute.String("resource.id", id.String())))
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
logger := s.logger.With("project.id", id.String())
|
logger := s.logger.With("project.id", id.String())
|
||||||
|
|
||||||
project, err := s.metal.GetProjectDetails(ctx, id)
|
project, err := s.metal.GetProjectDetails(ctx, id)
|
||||||
@@ -82,6 +88,10 @@ func (s *service) TouchProject(ctx context.Context, id gidx.PrefixedID) error {
|
|||||||
|
|
||||||
// DeleteProject deletes the provided project id.
|
// DeleteProject deletes the provided project id.
|
||||||
func (s *service) DeleteProject(ctx context.Context, id gidx.PrefixedID) error {
|
func (s *service) DeleteProject(ctx context.Context, id gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "DeleteProject", trace.WithAttributes(attribute.String("resource.id", id.String())))
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
err := s.publisher.PublishChange(ctx, projectEvent, events.ChangeMessage{
|
err := s.publisher.PublishChange(ctx, projectEvent, events.ChangeMessage{
|
||||||
SubjectID: id,
|
SubjectID: id,
|
||||||
EventType: string(events.DeleteChangeType),
|
EventType: string(events.DeleteChangeType),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"go.infratographer.com/x/events"
|
"go.infratographer.com/x/events"
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/metal"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/metal"
|
||||||
@@ -22,6 +23,8 @@ const (
|
|||||||
TypeUser ObjectType = "user"
|
TypeUser ObjectType = "user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var tracer = otel.Tracer("go.equinixmetal.net/infra9-metal-bridge/internal/service")
|
||||||
|
|
||||||
// DefaultPrefixMap is the default id prefix to type relationship.
|
// DefaultPrefixMap is the default id prefix to type relationship.
|
||||||
var DefaultPrefixMap = map[string]ObjectType{
|
var DefaultPrefixMap = map[string]ObjectType{
|
||||||
TypeOrganization.Prefix(): TypeOrganization,
|
TypeOrganization.Prefix(): TypeOrganization,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsUser checks the provided id has the metal user prefix.
|
// IsUser checks the provided id has the metal user prefix.
|
||||||
@@ -29,8 +31,27 @@ func (s *service) IsAssignableResource(id gidx.PrefixedID) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringIDs(ids []gidx.PrefixedID) []string {
|
||||||
|
result := make([]string, len(ids))
|
||||||
|
|
||||||
|
for i, id := range ids {
|
||||||
|
result[i] = id.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Assignuser assigns the provided users to the given resource ids.
|
// Assignuser assigns the provided users to the given resource ids.
|
||||||
func (s *service) AssignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
func (s *service) AssignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "AssignUser",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.String("user.id", userID.String()),
|
||||||
|
attribute.StringSlice("user.resource_assignments", stringIDs(resourceIDs)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
var totalResources, rolesChanged, assignmentsChanged int
|
var totalResources, rolesChanged, assignmentsChanged int
|
||||||
|
|
||||||
mlogger := s.logger.With("member.id", userID.String())
|
mlogger := s.logger.With("member.id", userID.String())
|
||||||
@@ -74,6 +95,15 @@ func (s *service) AssignUser(ctx context.Context, userID gidx.PrefixedID, resour
|
|||||||
|
|
||||||
// UnassignUser removes the assignment for the provided user id to the given resources.
|
// UnassignUser removes the assignment for the provided user id to the given resources.
|
||||||
func (s *service) UnassignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
func (s *service) UnassignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
||||||
|
ctx, span := tracer.Start(ctx, "UnassignUser",
|
||||||
|
trace.WithAttributes(
|
||||||
|
attribute.String("user.id", userID.String()),
|
||||||
|
attribute.StringSlice("user.resource_assignments", stringIDs(resourceIDs)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
for _, resourceID := range resourceIDs {
|
for _, resourceID := range resourceIDs {
|
||||||
rlogger := s.logger.With("user.id", userID, "resource.id", resourceID)
|
rlogger := s.logger.With("user.id", userID, "resource.id", resourceID)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user