Skip to content

Commit

Permalink
Merge pull request #67 from DataDog/TRAIN-1429-python-logs
Browse files Browse the repository at this point in the history
Fixes python services
  • Loading branch information
arosenkranz authored Mar 5, 2024
2 parents c883986 + 9da2439 commit a7bb1ac
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ NEXT_PUBLIC_SPREE_API_HOST=http://web:4000
NEXT_PUBLIC_SPREE_CLIENT_HOST=http://localhost:4000
NEXT_PUBLIC_SPREE_IMAGE_HOST=http://localhost:4000
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=localhost
# for local development (on localhost)
NEXT_PUBLIC_ADS_PORT=7676
NEXT_PUBLIC_DISCOUNTS_PORT=2814
NEXT_PUBLIC_ADS_ROUTE="http://localhost"
NEXT_PUBLIC_DISCOUNTS_ROUTE="http://localhost"
# for labs/public use
NEXT_PUBLIC_ADS_URL_FULL="http://localhost:7676"
NEXT_PUBLIC_DISCOUNTS_URL_FULL="http://localhost:2814"

NEXT_PUBLIC_DD_APPLICATION_ID=""
NEXT_PUBLIC_DD_CLIENT_TOKEN=""
NEXT_PUBLIC_DD_SITE="datadoghq.com"
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ services:
- dbm
environment:
- FLASK_APP=dbm.py
- FLASK_DEBUG=1
- FLASK_DEBUG=0
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_HOST=postgres
Expand Down Expand Up @@ -257,7 +257,7 @@ services:
- dd-agent
environment:
- FLASK_APP=ads.py
- FLASK_DEBUG=1
- FLASK_DEBUG=0
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_HOST=postgres
Expand Down Expand Up @@ -288,7 +288,7 @@ services:
- dd-agent
environment:
- FLASK_APP=discounts.py
- FLASK_DEBUG=1
- FLASK_DEBUG=0
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_HOST=postgres
Expand Down Expand Up @@ -371,4 +371,4 @@ services:

volumes:
redis:
postgres:
postgres:
2 changes: 1 addition & 1 deletion services/ads/python/ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ddtrace import tracer
import json_log_formatter

formatter = json_log_formatter.JSONFormatter()
formatter = json_log_formatter.VerboseJSONFormatter()
json_handler = logging.StreamHandler(sys.stdout)
json_handler.setFormatter(formatter)
logger = logging.getLogger('werkzeug')
Expand Down
4 changes: 2 additions & 2 deletions services/discounts/discounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ddtrace import tracer
import json_log_formatter

formatter = json_log_formatter.JSONFormatter()
formatter = json_log_formatter.VerboseJSONFormatter()
json_handler = logging.StreamHandler(sys.stdout)
json_handler.setFormatter(formatter)
logger = logging.getLogger('werkzeug')
Expand All @@ -48,7 +48,7 @@ def filter(self, record):
record.args = tuple(map(self.strip_esc, record.args))
return 1

remove_color_filter = NoEscape()
remove_color_filter =NoEscape()
logger.addFilter(remove_color_filter)

# Hello world
Expand Down
4 changes: 3 additions & 1 deletion services/frontend/components/common/Ad/Ad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export interface AdDataResults {
function Ad() {
const [data, setData] = useState<AdDataResults | null>(null)
const [isLoading, setLoading] = useState(false)
const adsPath = `${process.env.NEXT_PUBLIC_ADS_ROUTE}:${process.env.NEXT_PUBLIC_ADS_PORT}`
const adsPath =
`${process.env.NEXT_PUBLIC_ADS_URL_FULL}` ||
`${process.env.NEXT_PUBLIC_ADS_ROUTE}:${process.env.NEXT_PUBLIC_ADS_PORT}`
const [codeFlag, setCodeFlag] = useState<boolean>(false)

const getRandomArbitrary = useCallback((min: number, max: number) => {
Expand Down
39 changes: 25 additions & 14 deletions services/frontend/components/common/Discount/Discount.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import * as React from 'react'

export interface DiscountCodeResults {
data: string | null
Expand All @@ -7,21 +7,27 @@ export interface DiscountCodeResults {
function Discount() {
const [data, setData] = React.useState<DiscountCodeResults | null>(null)
const [isLoading, setLoading] = React.useState(false)
const discountPath = `${process.env.NEXT_PUBLIC_DISCOUNTS_ROUTE}:${process.env.NEXT_PUBLIC_DISCOUNTS_PORT}`
const discountPath =
`${process.env.NEXT_PUBLIC_DISCOUNTS_URL_FULL}` ||
`${process.env.NEXT_PUBLIC_DISCOUNTS_ROUTE}:${process.env.NEXT_PUBLIC_DISCOUNTS_PORT}`

function getRandomArbitrary(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min) + min)
}

function fetchDiscountCode() {
fetch(`${discountPath}/discount`)
.then((res) => res.json())
.then((data) => {
const index = getRandomArbitrary(0, data.length);
setData(data[index]["code"])
const index = getRandomArbitrary(0, data.length)
setData(data[index]['code'])
})
.catch((e) => {
console.error(e.message)
})
.finally(() => {
setLoading(false)
})
.catch(e => { console.error(e.message) })
.finally(() => { setLoading(false) })
}

React.useEffect(() => {
Expand All @@ -30,16 +36,21 @@ function Discount() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])


return (
<div className="flex flex-row justify-center py-4 bg-primary-2 text-white">
{
isLoading ? (<span>GET FREE SHIPPING WITH DISCOUNT CODE</span>) :
!data ? (<span>GET FREE SHIPPING WITH DISCOUNT CODE <strong>STOREDOG</strong></span>) : (<span>GET FREE SHIPPING WITH DISCOUNT CODE &nbsp; <strong>{data}</strong></span>)
}
{isLoading ? (
<span>GET FREE SHIPPING WITH DISCOUNT CODE</span>
) : !data ? (
<span>
GET FREE SHIPPING WITH DISCOUNT CODE <strong>STOREDOG</strong>
</span>
) : (
<span>
GET FREE SHIPPING WITH DISCOUNT CODE &nbsp; <strong>{data}</strong>
</span>
)}
</div>
)

}

export default Discount
export default Discount

0 comments on commit a7bb1ac

Please sign in to comment.