Generally happens once every session or two, usually by a player. Players can calculate the risk:reward ratio, and sometimes taking the attack is worth the benefit. Usually it's to get to get into melee with a ranged attacker, but often the withdraw action would work just as well (players tend to hate missing a round of attacks). Occasionally it's done as a defensive measure, to protect the spellcasters. I've even seen someone use the Dodge action against a horde, then provoke several attacks of opportunity (at disadvantage) so that they could back themselves into a corner (opening up the area for AoE and reducing incoming attacks); withdraw could have worked, but with dodge, they felt the odds of anything hitting (including on their next turn) would be too low.
When I DM, monsters tend to be tenacious, sticking with the enemies they initially engage with. If a creature is badly hurt in the middle of the melee, they may decide to take the withdraw action to get out of combat, then flee. If the combat is near the end, they will take the attacks of opportunity, then using their action to dash (otherwise, they'll never actually escape, since the party can just move adjacent and attack, unless they have a much higher speed). Above average intelligence monsters may choose to provoke an attack of opportunity, just as the PCs do.