Skip to content

Commit

Permalink
Fix bug where messages with PAC Origins and Spark content get disrega…
Browse files Browse the repository at this point in the history
…rded.
  • Loading branch information
ivan-p-nikolov committed Mar 12, 2020
1 parent 806405b commit 05a211c
Showing 1 changed file with 53 additions and 36 deletions.
89 changes: 53 additions & 36 deletions service/message_handler.go
Expand Up @@ -17,19 +17,23 @@ import (
)

const (
syntheticRequestPrefix = "SYNTHETIC-REQ-MON"
transactionIDHeader = "X-Request-Id"
blogsAuthority = "http://api.ft.com/system/FT-LABS-WP"
articleAuthority = "http://api.ft.com/system/FTCOM-METHODE"
videoAuthority = "http://api.ft.com/system/NEXT-VIDEO-EDITOR"
originHeader = "Origin-System-Id"
methodeOrigin = "methode-web-pub"
wordpressOrigin = "wordpress"
videoOrigin = "next-video-editor"
pacOrigin = "http://cmdb.ft.com/systems/pac"
contentTypeHeader = "Content-Type"
audioContentTypeHeader = "ft-upp-audio"
articleContentTypeHeader = "ft-upp-article"
syntheticRequestPrefix = "SYNTHETIC-REQ-MON"
transactionIDHeader = "X-Request-Id"
blogsAuthority = "http://api.ft.com/system/FT-LABS-WP"
methodeArticleAuthority = "http://api.ft.com/system/FTCOM-METHODE"
genericArticleAuthoriy = "http://api.ft.com/system/cct"
genericSparkArticleAuthoriy = "http://api.ft.com/system/spark"
videoAuthority = "http://api.ft.com/system/NEXT-VIDEO-EDITOR"
originHeader = "Origin-System-Id"
cctOrigin = "cct"
sparkOrigin = "spark"
methodeOrigin = "methode-web-pub"
wordpressOrigin = "wordpress"
videoOrigin = "next-video-editor"
pacOrigin = "http://cmdb.ft.com/systems/pac"
contentTypeHeader = "Content-Type"
audioContentTypeHeader = "ft-upp-audio"
articleContentTypeHeader = "ft-upp-article"
)

// Empty type added for older content. Placeholders - which are subject of exclusion - have type Content.
Expand Down Expand Up @@ -127,7 +131,7 @@ func (handler *MessageHandler) handleMessage(msg consumer.Message) {
logger.WithTransactionID(tid).WithUUID(uuid).Info("Processing combined post publication event")

contentType := extractContentTypeFromMsg(msg, combinedPostPublicationEvent)
if contentType == "" && msg.Headers[originHeader] != pacOrigin{
if contentType == "" && msg.Headers[originHeader] != pacOrigin {
logger.WithTransactionID(tid).WithUUID(uuid).Error("Failed to index content. Could not infer type of content")
return
}
Expand Down Expand Up @@ -159,33 +163,46 @@ func (handler *MessageHandler) handleMessage(msg consumer.Message) {
}

func extractContentTypeFromMsg(msg consumer.Message, event content.EnrichedContent) string {
var contentType string

typeHeader := msg.Headers[contentTypeHeader]
if strings.Contains(typeHeader, audioContentTypeHeader) {
contentType = AudioType
} else if strings.Contains(typeHeader, articleContentTypeHeader) {
contentType = ArticleType
} else {
for _, identifier := range event.Content.Identifiers {
if strings.HasPrefix(identifier.Authority, blogsAuthority) {
contentType = BlogType
} else if strings.HasPrefix(identifier.Authority, articleAuthority) {
contentType = ArticleType
} else if strings.HasPrefix(identifier.Authority, videoAuthority) {
contentType = VideoType
}
}
return AudioType
}
if strings.Contains(typeHeader, articleContentTypeHeader) {
return ArticleType
}
var contentType string

if contentType == "" {
origin := msg.Headers[originHeader]
if strings.Contains(origin, methodeOrigin) {
contentType = ArticleType
} else if strings.Contains(origin, wordpressOrigin) {
for _, identifier := range event.Content.Identifiers {
if strings.HasPrefix(identifier.Authority, blogsAuthority) {
contentType = BlogType
} else if strings.Contains(origin, videoOrigin) {
} else if strings.HasPrefix(identifier.Authority, methodeArticleAuthority) {
contentType = ArticleType
} else if strings.HasPrefix(identifier.Authority, videoAuthority) {
contentType = VideoType
} else if strings.HasPrefix(identifier.Authority, genericArticleAuthoriy) {
contentType = ArticleType
} else if strings.HasPrefix(identifier.Authority, genericSparkArticleAuthoriy) {
contentType = ArticleType
}
}
if contentType != "" {
return contentType
}

msgOrigin := msg.Headers[originHeader]
originMap := map[string]string{
methodeOrigin: ArticleType,
cctOrigin: ArticleType,
sparkOrigin: ArticleType,
wordpressOrigin: BlogType,
videoOrigin: VideoType,
}
for origin, contentType := range originMap {
if strings.Contains(msgOrigin, origin) {
return contentType
}
}
return contentType
}

return ""
}

0 comments on commit 05a211c

Please sign in to comment.