Anal glands are emptied when the dog poops. When a dog poops, there is usually the last "squeeze", which is a fluid that comes out of their colon. Anal glands were once used for marking their territory. It's common for smaller breeds, and the elderly to have anal gland problems, due to muscles not being strong enough.
Diet does have effect on the anal glands. A high fiber diet is a good place to start. The firmness of the stool makes the dog push harder, which releases the fluid from these glands. Anal glands are two small sacs located at the left and right side of the colon.
Groomers express them from the outside, while the vet does them internally. If your dog scoots along your floor, licks under their tail, or has a smelly rear, their anal glands possibly need to be expressed.